:root {
  --bg: #f4f5f7; --panel: #fff; --line: #d9dde3; --line-strong: #b9c0ca; --cell: #e4e7eb;
  --text: #1d2330; --muted: #6b7482; --accent: #1f6feb; --accent-d: #1858c0; --accent-bg: #e8f0fe;
  --err: #d1242f; --err-bg: #fff0f0; --ro: #f1f3f6; --row-hover: #f8fafc; --warn: #d4a72c;
  --ok: #1a7f37;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.4 "Segoe UI", Roboto, Arial, sans-serif; }
[hidden] { display: none !important; }
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 20px; margin: 0; font-weight: 600; }
h2 { font-size: 16px; margin: 0 0 10px; font-weight: 600; }

/* ---------- header ---------- */
header { display: flex; align-items: center; gap: 8px; padding: 0 16px; height: 52px; background: #1d2330; color: #fff;
         position: sticky; top: 0; z-index: 20; }
.brand { font-weight: 700; font-size: 16px; margin-right: 16px; letter-spacing: .3px; }
nav { display: flex; gap: 2px; }
nav a { color: #c9d1dc; padding: 8px 12px; border-radius: 6px; }
nav a:hover { background: #2b3342; color: #fff; }
nav a.on { background: #2f3b52; color: #fff; }
.who { color: #c9d1dc; font-size: 13px; margin-right: 6px; white-space: nowrap; }
.badge { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 10px; background: #e7eaee; color: #3b4250; vertical-align: 1px; }
header .badge { background: #3a465c; color: #dfe6f0; }
.badge.admin { background: #fde2e1; color: #9a1b1f; }
.badge.user { background: #dcebff; color: #1b4f9c; }
.badge.client { background: #dff3e4; color: #1a6b33; }
.st { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 10px; background: #eef0f3; white-space: nowrap; }
.st0 { background: #dcebff; color: #1b4f9c; }
.st1 { background: #fff1c2; color: #7a5500; }
.st2 { background: #dff3e4; color: #1a6b33; }
.st3 { background: #e9e4f7; color: #4b3a8c; }
.st4 { background: #f1f1f1; color: #777; text-decoration: line-through; }
select.st { border: 1px solid transparent; cursor: pointer; font-size: 12px; }

/* ---------- controls ---------- */
button, .btn { font: inherit; border-radius: 6px; padding: 7px 14px; cursor: pointer; border: 1px solid var(--line-strong);
               background: #fff; color: var(--text); white-space: nowrap; display: inline-block; }
button:hover, .btn:hover { background: #f0f2f5; }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--accent-d); }
button.danger { color: var(--err); }
button.danger:hover { background: var(--err-bg); border-color: var(--err); }
button.ghost { background: transparent; border-color: transparent; color: #c9d1dc; }
button.ghost:hover { background: #2b3342; color: #fff; }
button.sm { padding: 4px 9px; font-size: 13px; }
button.icon { border: none; background: none; color: var(--muted); padding: 2px 6px; font-size: 16px; line-height: 1; }
button.icon:hover { color: var(--err); }
input, select, textarea { font: inherit; color: var(--text); }
.field { border: 1px solid var(--line-strong); border-radius: 6px; padding: 6px 8px; background: #fff; }
.field:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(31,111,235,.15); }
label.lbl { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 13px; }
label.chk { display: flex; align-items: center; gap: 6px; color: var(--text); cursor: pointer; }

/* ---------- layout ---------- */
main { padding: 16px; max-width: 1500px; margin: 0 auto; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.panel-pad { padding: 14px 16px; }
.head-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.filters .field { min-width: 0; }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; }
.tabs button.on { background: var(--accent-bg); border-color: var(--accent); color: var(--accent-d); font-weight: 600; }

/* ---------- tables ---------- */
.tbl-wrap { overflow: auto; }
table.grid { border-collapse: separate; border-spacing: 0; width: 100%; }
table.grid th { position: sticky; top: 0; background: #fafbfc; z-index: 2; padding: 8px 6px; border-bottom: 2px solid var(--line-strong);
                font-weight: 600; font-size: 13px; text-align: left; white-space: nowrap; }
table.grid td { border-bottom: 1px solid var(--line); padding: 4px 6px; vertical-align: middle; }
table.grid tbody tr:hover td { background: var(--row-hover); }
table.list tbody tr { cursor: pointer; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.idx { color: var(--muted); text-align: right; width: 40px; }
td.acts { white-space: nowrap; text-align: right; }
td.acts button { margin-left: 4px; }
.empty-row td { text-align: center; color: var(--muted); padding: 30px; cursor: default; }

/* ---------- order editor ---------- */
.ed-head { display: grid; grid-template-columns: minmax(200px, 1fr) minmax(200px, 1.5fr) auto auto; gap: 12px; align-items: end; padding: 14px 16px;
           border-bottom: 1px solid var(--line); }
.ed-grid td input, .ed-grid td select { width: 100%; border: 1px solid var(--cell); border-radius: 4px; padding: 5px 6px; background: transparent; }
.ed-grid td input:hover { border-color: var(--line-strong); }
.ed-grid td input:focus { outline: none; border-color: var(--accent); background: #fff; box-shadow: 0 0 0 2px rgba(31,111,235,.15); }
.ed-grid td input.n { text-align: right; font-variant-numeric: tabular-nums; }
.ed-grid td input[readonly] { background: var(--ro); color: var(--muted); }
.ed-grid td input::placeholder { color: transparent; }
.ed-grid td input:focus::placeholder { color: #a3aab5; }
.ed-grid.ro td input { border-color: transparent; background: transparent; color: var(--text); }
.ed-grid.ro td input.combo { background-image: none; }
.invalid { border-color: var(--err) !important; background: var(--err-bg) !important; }
.cbx { display: flex; align-items: center; gap: 4px; }
.cbx img.sel { width: 28px; height: 28px; object-fit: cover; border-radius: 4px; border: 1px solid var(--line); flex: none; background: #fff; cursor: zoom-in; }
input.combo { padding-right: 22px !important; cursor: text;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%236b7482'/%3E%3C/svg%3E") no-repeat right 8px center !important; }
input.combo:focus { background-color: #fff !important; }
input.combo.stale { border-color: var(--warn); }
.ed-foot { padding: 10px 14px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; border-top: 1px solid var(--line); }

/* ---------- dropdown with thumbnails ---------- */
.dd { position: fixed; z-index: 50; display: none; background: #fff; border: 1px solid var(--line-strong); border-radius: 6px;
      box-shadow: 0 8px 24px rgba(0,0,0,.15); max-height: 340px; overflow-y: auto; padding: 4px 0; }
.dd-it { display: flex; align-items: center; gap: 8px; padding: 4px 10px; cursor: pointer; white-space: nowrap; }
.dd-it.act { background: var(--accent-bg); }
.dd-it .th { width: 36px; height: 36px; flex: none; border-radius: 4px; background: #f0f2f5; object-fit: cover; border: 1px solid var(--line); }
.dd-it .th.none { display: inline-block; }
.dd-it mark { background: #ffe58a; color: inherit; padding: 0; border-radius: 2px; }
.dd .note { color: var(--muted); padding: 6px 10px; font-size: 13px; }
.preview { position: fixed; z-index: 60; display: none; background: #fff; border: 1px solid var(--line-strong); border-radius: 8px;
           box-shadow: 0 8px 24px rgba(0,0,0,.18); padding: 8px; width: 236px; pointer-events: none; }
.preview img { width: 220px; height: 220px; object-fit: contain; display: block; background: #f7f8fa; border-radius: 4px; }
.preview .cap { font-size: 12px; color: var(--muted); margin-top: 6px; white-space: normal; }

/* ---------- catalog admin ---------- */
.cat-grid td input { width: 100%; border: 1px solid transparent; border-radius: 4px; padding: 5px 6px; background: transparent; }
.cat-grid td input:hover { border-color: var(--cell); }
.cat-grid td input:focus { outline: none; border-color: var(--accent); background: #fff; }
.cat-grid td input.saved { border-color: var(--ok); }
.cat-grid img.th { width: 40px; height: 40px; object-fit: cover; border-radius: 4px; border: 1px solid var(--line); display: block; background: #f0f2f5; cursor: zoom-in; }
.cat-grid .noimg { width: 40px; height: 40px; border-radius: 4px; border: 1px dashed var(--line-strong); display: block; }
.import-box { border: 1px dashed var(--line-strong); border-radius: 8px; padding: 14px; margin-bottom: 14px; background: #fbfcfd; }
.map-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; margin: 10px 0; }
.prev-tbl { font-size: 13px; }
.prev-tbl td, .prev-tbl th { padding: 4px 8px; border-bottom: 1px solid var(--line); text-align: left; max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prev-tbl th.hl { background: var(--accent-bg); }

/* ---------- login ---------- */
.login { max-width: 360px; margin: 10vh auto; }
.login .panel { padding: 24px; display: flex; flex-direction: column; gap: 12px; }
.login h1 { text-align: center; margin-bottom: 4px; }
.login .field { width: 100%; }
.err-text { color: var(--err); font-size: 13px; min-height: 18px; }

/* ---------- modal & toast ---------- */
.modal { position: fixed; inset: 0; background: rgba(20,24,33,.45); z-index: 70; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-box { background: #fff; border-radius: 10px; padding: 20px; width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 12px;
             box-shadow: 0 12px 40px rgba(0,0,0,.25); }
.modal-box .field { width: 100%; }
.modal-box .btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.msg { position: fixed; right: 20px; bottom: 20px; max-width: 440px; padding: 12px 16px; border-radius: 8px; z-index: 80;
       background: #1d2330; color: #fff; box-shadow: 0 6px 24px rgba(0,0,0,.2); display: none; white-space: pre-line; }
.msg.err { background: var(--err); }

@media (max-width: 800px) {
  main { padding: 8px; }
  header { flex-wrap: wrap; height: auto; padding: 6px 8px; }
  .who { display: none; }
  .ed-head { grid-template-columns: 1fr; }
}

/* ---------- стоимость ---------- */
td.price { white-space: nowrap; color: var(--text); font-variant-numeric: tabular-nums; padding-right: 10px; }
td.price[data-c="sum"] { font-weight: 600; }
.totals { display: flex; gap: 10px; }
.tot-box { display: flex; flex-direction: column; align-items: flex-end; padding: 6px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fafbfc; min-width: 130px; }
.tot-box b { font-size: 17px; font-variant-numeric: tabular-nums; white-space: nowrap; }
tfoot tr.tot td { border-top: 2px solid var(--line-strong); font-weight: 600; padding: 8px 6px; background: #fafbfc; position: sticky; bottom: 0; }

/* ---------- группы клиентов ---------- */
.badge.grp { background: #fff1c2; color: #7a5500; }
.groups-layout { display: grid; grid-template-columns: minmax(360px, 1fr) minmax(420px, 1.3fr); gap: 16px; align-items: start; }
.groups-layout .filters { align-items: center; }
@media (max-width: 1000px) { .groups-layout { grid-template-columns: 1fr; } }

/* ---------- пароли и блокировка ---------- */
.pw-row { display: flex; gap: 6px; }
.pw-row .field { flex: 1; min-width: 0; }
.mono { font-family: Consolas, "Courier New", monospace; letter-spacing: 1px; font-size: 15px; }
.badge.lock { background: #fde2e1; color: #9a1b1f; margin-top: 3px; }

/* ---------- позиция ---------- */
td.pos { width: 64px; }
.ed-grid td input.posn { text-align: center; width: 56px; font-variant-numeric: tabular-nums; }
.ed-grid td input.posn.auto { color: var(--muted); }
.ed-grid td input.posn.dup { border-color: var(--err); background: var(--err-bg); color: var(--err); }

/* ---------- автовыход ---------- */
.idle-bar { position: fixed; top: 60px; left: 50%; transform: translateX(-50%); z-index: 90; display: flex; align-items: center; gap: 12px;
            background: #fff8e1; border: 1px solid var(--warn); color: #6b4e00; padding: 10px 14px; border-radius: 8px;
            box-shadow: 0 6px 24px rgba(0,0,0,.18); max-width: calc(100vw - 32px); }
.settings { max-width: 640px; display: flex; flex-direction: column; gap: 10px; }

/* ---------- виды фасадов ---------- */
.dd-it .kind { margin-left: auto; font-size: 11px; padding: 1px 7px; border-radius: 10px; background: #eef0f3; color: #3b4250; flex: none; }
.dd-it .kind.k-painted { background: #fde8f3; color: #8a1c5a; }
.dd-it .kind.k-radius { background: #e3f2fd; color: #0d5b9c; }
.dd-it .kind.k-cornice { background: #efe9dc; color: #6b4e1f; }
.ed-grid td input.fixed { background: var(--ro) !important; color: var(--muted); border-color: transparent !important; }
.ed-grid input.combo.free { background-image: none !important; padding-right: 6px !important; font-style: italic; }

/* ---------- статусы ---------- */
select.st { border: 1px solid rgba(0,0,0,.08); border-radius: 10px; padding: 2px 6px; font-size: 12px; cursor: pointer; }
select.field.st-field { font-weight: 600; }
.st-colors { display: flex; flex-wrap: wrap; gap: 10px 18px; }
.st-color { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.st-color input[type=color] { width: 36px; height: 28px; border: 1px solid var(--line-strong); border-radius: 6px; padding: 1px; background: #fff; cursor: pointer; }
[data-recall] button { border-color: var(--warn); background: #fff8e1; }
[data-until] { font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---------- логотипы ---------- */
.brand img.logo { width: 36px; height: 36px; object-fit: contain; display: block; background: transparent; }
.login-brand { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.login-brand h1 { text-align: center; }
img.logo-lg { width: 96px; height: 96px; object-fit: contain; display: block; }
img.logo-ed { width: 40px; height: 40px; object-fit: contain; }
.logo-row { display: flex; gap: 14px; align-items: flex-start; }
.logo-prev { width: 96px; height: 96px; flex: none; border: 1px solid var(--line); border-radius: 8px; display: flex; align-items: center; justify-content: center; text-align: center;
  background: repeating-conic-gradient(#eef0f3 0% 25%, #fff 0% 50%) 50% / 16px 16px; }
.logo-prev img { width: 100%; height: 100%; object-fit: contain; }
.logo-actions { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
/* ---------- дилер ---------- */
button.star { font-size: 18px; font-weight: 700; padding: 4px 12px; line-height: 1; }
button.star.on { background: #fff1c2; border-color: var(--warn); }
.dl-cell { display: flex; gap: 6px; align-items: center; }
.dl-btn.on { background: #fff8e1; border-color: var(--warn); font-weight: 600; }
.dl-link { word-break: break-all; }
.modal-box textarea, .settings textarea { width: 100%; resize: vertical; }

.dom-grid { display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px; align-items: end; }
@media (max-width: 700px) { .dom-grid { grid-template-columns: 1fr; } }

.dd .dd-grp { position: sticky; top: -4px; z-index: 1; background: #f4f5f7; color: var(--muted); font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .4px; padding: 5px 10px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }

/* ---------- окно просмотра изображения ---------- */
.lightbox { position: fixed; inset: 0; z-index: 95; background: rgba(20,24,33,.6); display: flex; align-items: center; justify-content: center; padding: 16px; }
.lb-box { background: #fff; border-radius: 10px; box-shadow: 0 16px 48px rgba(0,0,0,.35); max-width: min(92vw, 1100px); max-height: 92vh; display: flex; flex-direction: column; overflow: hidden; }
.lb-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px 10px 16px; border-bottom: 1px solid var(--line); }
.lb-title { font-weight: 600; }
.lb-close { font-size: 24px !important; }
.lb-img { position: relative; display: flex; align-items: center; justify-content: center; min-width: 280px; min-height: 200px; padding: 12px;
  background: repeating-conic-gradient(#f1f3f6 0% 25%, #fff 0% 50%) 50% / 20px 20px; overflow: auto; }
.lb-img img { display: block; max-width: calc(min(92vw, 1100px) - 24px); max-height: calc(92vh - 90px); object-fit: contain; }
.lb-load { position: absolute; }
.cbx img.sel { cursor: pointer; }
