:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1c2330;
  --muted: #6b7484;
  --line: #e2e5ea;
  --accent: #2357d6;
  --accent-soft: #e8eefc;
  --ok: #1f9d55;
  --ok-soft: #e4f5ea;
  --warn: #b7791f;
  --warn-soft: #fbf1df;
  --bad: #c53030;
  --bad-soft: #fbe6e6;
  --best: #eaf7ee;
  --radius: 8px;
  --top-h: 52px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c; --surface: #1c2027; --text: #e6e9ee; --muted: #9099a8; --line: #2d333d;
    --accent: #6d95ff; --accent-soft: #23304d; --ok: #48c27a; --ok-soft: #1d3326; --warn: #e0a64a;
    --warn-soft: #3a2f1c; --bad: #f07272; --bad-soft: #3d2222; --best: #1d3326;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
h2 { font-size: 18px; margin: 18px 0 10px; }
h3 { font-size: 15px; margin: 18px 0 8px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; }
.num { text-align: right; white-space: nowrap; }
.warn { color: var(--warn); }
.error, .bad-text { color: var(--bad); }

button, .btn {
  font: inherit; border: 1px solid var(--accent); background: var(--accent); color: #fff; border-radius: 6px;
  padding: 6px 12px; cursor: pointer; text-decoration: none; display: inline-block;
}
button:disabled { opacity: .5; cursor: default; }
button.ghost, .btn.ghost { background: transparent; color: var(--accent); }
button.danger { color: var(--bad); border-color: var(--bad); }
input, select { font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; }
input[type=checkbox] { padding: 0; }
.chk { display: inline-flex; gap: 6px; align-items: center; white-space: nowrap; }

/* шапка */
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 20px; padding: 0 20px; height: 52px;
  background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { font-weight: 600; white-space: nowrap; }
.brand .muted { font-weight: 400; font-size: 12px; }
#tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
#tabs a { padding: 6px 12px; border-radius: 6px; text-decoration: none; color: var(--text); white-space: nowrap; }
#tabs a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.who { display: flex; gap: 6px; align-items: center; white-space: nowrap; font-size: 13px; }
.who .tag { margin: 0; }
.small-btn { padding: 3px 8px; font-size: 12px; }
body.engineer .admin-only { display: none !important; }

/* вход */
.login-screen { display: none; position: fixed; inset: 0; z-index: 50; background: var(--bg); align-items: center; justify-content: center; padding: 16px; }
body.logged-out .login-screen { display: flex; }
body.logged-out .top, body.logged-out main { visibility: hidden; }
.login-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 28px;
  display: flex; flex-direction: column; gap: 12px; }
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0; }
.login-card label, .dialog-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.login-card #setupFields, .login-card #setupFields2 { display: flex; flex-direction: column; gap: 12px; }
.login-card [hidden] { display: none !important; }
.login-card button { padding: 9px; }
.error:empty { display: none; }
dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--text); padding: 22px; width: min(360px, 92vw); }
dialog::backdrop { background: rgba(0,0,0,.35); }
.dialog-form { display: flex; flex-direction: column; gap: 10px; }
.dialog-form h3 { margin: 0; }
#usersTable .actions { white-space: nowrap; text-align: right; }
.pill { display: inline-block; min-width: 18px; padding: 0 6px; border-radius: 9px; background: var(--accent-soft); color: var(--accent);
  font-size: 11px; text-align: center; }
.pill:empty { display: none; }

/* раскладка */
.view { display: none; }
.view.active { display: flex; }
.view.single .content { max-width: 1400px; margin: 0 auto; }
.content { flex: 1; min-width: 0; padding: 12px 20px 40px; }
.cats { width: 260px; flex-shrink: 0; padding: 12px 8px 12px 16px; border-right: 1px solid var(--line); height: calc(100vh - var(--top-h));
  overflow-y: auto; position: sticky; top: var(--top-h); }
.cat { display: flex; justify-content: space-between; gap: 8px; padding: 5px 8px; border-radius: 6px; cursor: pointer; color: var(--text); text-decoration: none; }
.cat:hover { background: var(--accent-soft); }
.cat.active { background: var(--accent); color: #fff; }
.cat.top { font-weight: 500; margin-top: 2px; }
.cat.sub { padding-left: 22px; font-size: 13px; }
.cat.unc { color: var(--warn); }
.cat .n { color: inherit; opacity: .6; font-size: 12px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; }
.filters #q { flex: 1; min-width: 240px; }
.crumbs { color: var(--muted); font-size: 12px; margin: 4px 0 8px; }
.bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 8px 0; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.panel h3 { margin-top: 0; }
.ok-panel { border-color: var(--ok); background: var(--ok-soft); }
.two { display: grid; grid-template-columns: 1fr 1.4fr; gap: 16px; align-items: start; }

/* таблицы */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.panel .table-wrap { border: 0; }
table.grid { width: 100%; border-collapse: collapse; }
.grid th, .grid td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.grid thead th { position: sticky; top: 0; background: var(--surface); font-weight: 600; font-size: 12px; color: var(--muted); white-space: nowrap; }
.grid th[data-sort] { cursor: pointer; user-select: none; }
.grid th.sorted { color: var(--accent); }
.grid th.sorted::after { content: " ↑"; }
.grid th.sorted.desc::after { content: " ↓"; }
.grid th.num { text-align: right; }
#catalogTable tbody tr { cursor: pointer; }
#catalogTable tbody tr:hover, .sim tr:hover { background: var(--accent-soft); }
.grid td.name { min-width: 280px; }
.grid .c-chk { width: 28px; }
.grid tr.best td, .grid td.best { background: var(--best); }
.grid.compact th, .grid.compact td { padding: 5px 8px; }
.grid tfoot td { font-weight: 600; border-top: 2px solid var(--line); }
.empty { text-align: center; color: var(--muted); padding: 30px !important; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: center; padding: 12px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--line); vertical-align: middle; }
.dot.ok { background: var(--ok); }
.tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 10px; background: var(--line); color: var(--muted); margin-top: 3px; }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.bad { background: var(--bad-soft); color: var(--bad); }

/* сравнение */
.compare th:first-child { width: 160px; color: var(--muted); font-weight: 500; }
.compare thead th { vertical-align: top; color: var(--text); min-width: 180px; }
.compare tr.hl td, .compare tr.hl th { border-bottom: 2px solid var(--line); }
.compare .x { float: right; padding: 0 6px; border: 0; }

/* спецификация и загрузка */
.drop { display: block; border: 2px dashed var(--line); border-radius: var(--radius); padding: 22px; text-align: center; cursor: pointer;
  background: var(--surface); margin-bottom: 14px; }
.drop span { display: block; margin-top: 4px; font-size: 12px; }
.drop.over, .drop:hover { border-color: var(--accent); background: var(--accent-soft); }
.spec-controls { display: flex; gap: 18px; flex-wrap: wrap; align-items: stretch; }
.spec-controls .drop { flex: 1; min-width: 280px; margin: 0; }
.params { display: flex; flex-direction: column; gap: 8px; justify-content: center; }
.params label:not(.chk) { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); }
.params input[type=number] { width: 120px; }
table.spec select { max-width: 260px; margin-top: 4px; display: block; }
table.spec td { font-size: 13px; }
.form-row { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 10px; }
.form-row label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.form-row label b { color: var(--text); font-size: 14px; padding: 6px 0; }
.mapping th { min-width: 160px; color: var(--text) !important; font-weight: 500 !important; }
.mapping select { width: 100%; margin: 4px 0 2px; }
.mapping th.pending { background: var(--warn-soft); }
.mapping th.pending select { border-color: var(--warn); }
.mapping th.skipped .col-head { color: var(--muted); text-decoration: line-through; }
.note { padding: 10px 12px; border-radius: 6px; background: var(--accent-soft); margin: 4px 0; }
.ok-note { background: var(--ok-soft); }
.questions { border-color: var(--warn); }
.questions h3 { margin: 0; }
.q { display: grid; grid-template-columns: minmax(180px, 1.1fr) minmax(200px, 1.4fr) auto; gap: 12px; align-items: center;
  padding: 10px 0; border-top: 1px solid var(--line); }
.q-act { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.q-act select { max-width: 170px; }
.vendor-disc { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 6px 16px; margin-top: 8px; }
.vendor-disc label { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 13px; }
.vendor-disc input { width: 80px; }
.sections { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 4px 16px; margin-top: 8px; }
.sections .chk { white-space: normal; }
details summary { cursor: pointer; color: var(--accent); }
.tag.eol { background: var(--bad-soft); color: var(--bad); }
.offer-extra { font-size: 11px; color: var(--muted); }
.issue pre { white-space: pre-wrap; word-break: break-word; max-height: 360px; overflow: auto; background: var(--bg);
  padding: 8px; border-radius: 6px; }
.issue.resolved { opacity: .65; }
.issue p { margin: 6px 0; }
.checks { list-style: none; padding: 0; margin: 12px 0 0; display: flex; gap: 18px; flex-wrap: wrap; }
.checks .ok { color: var(--ok); }
.checks .bad { color: var(--bad); }
@media (max-width: 900px) { .q { grid-template-columns: 1fr; } .q-act { justify-content: flex-start; } }

/* структура */
#catTree details { padding: 4px 0; border-bottom: 1px solid var(--line); }
#catTree summary { cursor: pointer; }
#catTree ul { margin: 6px 0; padding-left: 22px; }
.ren { border-bottom: 1px dashed var(--muted); cursor: text; }
.unc { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.sugg { text-align: right; min-width: 200px; }
.rates { display: flex; flex-wrap: wrap; gap: 14px; }
.rates label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); }
.rates input { width: 120px; }

/* карточка */
.drawer-bg { position: fixed; inset: 0; background: rgba(0,0,0,.25); opacity: 0; pointer-events: none; transition: opacity .15s; z-index: 20; }
.drawer-bg.open { opacity: 1; pointer-events: auto; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(820px, 100vw); background: var(--surface); z-index: 21; overflow-y: auto;
  padding: 18px 22px 40px; transform: translateX(100%); transition: transform .18s; box-shadow: -6px 0 24px rgba(0,0,0,.12); }
.drawer.open { transform: none; }
.drawer-head { display: flex; justify-content: space-between; gap: 12px; }
.drawer-head h2 { margin: 4px 0; }
.edit-cat { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; padding: 10px; }
.edit-cat input { flex: 1; min-width: 160px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(80px); background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 8px; transition: transform .2s; z-index: 30; }
.toast.show { transform: translateX(-50%); }
.toast.bad { background: var(--bad); color: #fff; }

/* узкий экран: вкладки уходят во вторую строку шапки */
@media (max-width: 1250px) {
  :root { --top-h: 92px; }
  .brand .muted { display: none; }
  .top { flex-wrap: wrap; height: auto; min-height: 52px; padding: 8px 20px; row-gap: 6px; }
  #tabs { order: 3; flex-basis: 100%; }
  .who { margin-left: auto; }
}
@media (max-width: 900px) {
  .view.active { flex-direction: column; }
  .cats { width: auto; height: auto; position: static; border-right: 0; border-bottom: 1px solid var(--line); max-height: 220px; }
  .two { grid-template-columns: 1fr; }
  .top { flex-wrap: wrap; height: auto; padding: 8px 16px; gap: 8px; }
  .content { padding: 12px 16px 40px; }
}
