/* КП — интерфейс. Сначала телефон (360 px), потом шире. */
:root {
  --bg: #eef1f4;
  --surface: #ffffff;
  --ink: #17212b;
  --muted: #5e6b78;
  --line: #d4dbe2;
  --blue: #1f5fa8;        /* синька чертежа: основное действие, ссылки */
  --blue-soft: #e4edf8;
  --signal: #f2b705;      /* сигнальный жёлтый: не посчитано, внимание */
  --signal-soft: #fff4cc;
  --red: #b8361f;
  --red-soft: #fbe6e1;
  --green: #2e7d4f;
  --green-soft: #e2f2e8;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11171d; --surface: #1a222b; --ink: #e8edf2; --muted: #9aa8b5; --line: #2e3a46;
    --blue: #6aa5ea; --blue-soft: #1d2f45; --signal: #f2c230; --signal-soft: #3a3214;
    --red: #ef7a62; --red-soft: #3d2019; --green: #6cc191; --green-soft: #183126;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 var(--font);
  font-variant-numeric: tabular-nums;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; line-height: 1.25; margin: 0 0 4px; font-weight: 650; }
h2 { font-size: 16px; margin: 20px 0 8px; font-weight: 650; }
h3 { font-size: 15px; margin: 14px 0 6px; font-weight: 600; }
p { margin: 6px 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { text-align: right; white-space: nowrap; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* каркас */
.top {
  position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 8px; padding: 8px 12px; min-height: 52px;
}
.top .title { flex: 1; min-width: 0; }
.top .title b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .title span { display: block; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back { font-size: 22px; padding: 4px 8px; margin-left: -6px; color: var(--ink); }
main { max-width: 1100px; margin: 0 auto; padding: 12px 12px 120px; }
nav.bottom {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; background: var(--surface);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
nav.bottom a { flex: 1; text-align: center; padding: 10px 4px 8px; font-size: 12px; color: var(--muted); }
nav.bottom a.on { color: var(--blue); font-weight: 600; }
nav.bottom a .ico { display: block; font-size: 18px; line-height: 1.1; }

/* элементы */
button, .btn {
  font: inherit; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 8px; padding: 9px 14px; min-height: 40px; cursor: pointer; display: inline-flex;
  align-items: center; gap: 6px; text-decoration: none;
}
button:hover, .btn:hover { border-color: var(--muted); text-decoration: none; }
button.primary, .btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; font-weight: 600; }
button.danger { color: var(--red); }
button.ghost { border-color: transparent; background: transparent; }
button:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; min-width: 0; }

label.f { display: block; margin: 10px 0; }
label.f > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 3px; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface); width: 100%; border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 10px; min-height: 40px;
}
input:focus, select:focus, textarea:focus { border-color: var(--blue); outline: none; box-shadow: 0 0 0 3px var(--blue-soft); }
input[readonly], textarea[readonly], select:disabled, input:disabled { background: var(--bg); }
textarea { min-height: 0; resize: vertical; line-height: 1.4; }
input[type=checkbox], input[type=radio] { width: 18px; height: 18px; min-height: 0; padding: 0; flex: none; accent-color: var(--blue); }
label.item { cursor: pointer; }
input.num-in { text-align: right; }
.hint { font-size: 12px; color: var(--muted); margin-top: 3px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 10px; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin: 10px 0; }
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.item { display: flex; gap: 10px; align-items: center; padding: 11px 12px; border-top: 1px solid var(--line); color: var(--ink); }
.item:first-child { border-top: 0; }
a.item:hover, .item.click:hover { background: var(--bg); text-decoration: none; cursor: pointer; }
.item .main { flex: 1; min-width: 0; }
.item .main b { font-weight: 600; }
.item .sub { font-size: 13px; color: var(--muted); }
.empty { padding: 18px 12px; color: var(--muted); }

.badge { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 99px; background: var(--bg); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.badge.blue { background: var(--blue-soft); color: var(--blue); border-color: transparent; }
.badge.green { background: var(--green-soft); color: var(--green); border-color: transparent; }
.badge.signal { background: var(--signal-soft); color: var(--ink); border-color: var(--signal); }
.badge.red { background: var(--red-soft); color: var(--red); border-color: transparent; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: transparent; }
.dot.st-incomplete { background: var(--signal); }
.dot.st-error { background: var(--red); }
.dot.st-off { background: var(--line); }
.dot.st-empty { border: 1.5px solid var(--line); }

.note { border-left: 3px solid var(--signal); background: var(--signal-soft); padding: 8px 10px; border-radius: 6px; margin: 8px 0; font-size: 14px; }
.note.red { border-color: var(--red); background: var(--red-soft); }
.note.green { border-color: var(--green); background: var(--green-soft); }
.note ul { margin: 4px 0 0; padding-left: 18px; }

.tabs { display: flex; gap: 2px; overflow-x: auto; border-bottom: 1px solid var(--line); margin: 0 -12px 10px; padding: 0 12px; background: var(--surface); position: sticky; top: 52px; z-index: 15; }
.tabs a { padding: 10px 12px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.on { color: var(--ink); border-color: var(--blue); font-weight: 600; text-decoration: none; }

/* дерево СДР */
.crumbs { font-size: 13px; color: var(--muted); margin: 2px 0 8px; display: flex; flex-wrap: wrap; gap: 2px 4px; }
.crumbs a { color: var(--muted); }
.crumbs a:last-child { color: var(--ink); font-weight: 600; }
.sdr { font-size: 12px; color: var(--muted); min-width: 34px; flex: none; }
.node .main b { font-weight: 500; }
.node.group .main b { font-weight: 650; }
.node .val { text-align: right; white-space: nowrap; font-weight: 600; }
.node .val small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.node .cols { display: none; }
.node .more { padding: 6px 8px; min-height: 34px; border: 0; background: transparent; color: var(--muted); font-size: 18px; }
.nodehead { display: flex; gap: 12px; align-items: flex-end; justify-content: space-between; margin-bottom: 8px; }
.nodehead .big { font-size: 22px; font-weight: 650; white-space: nowrap; }

/* основная надпись — сводка цены внизу экрана редакции (как штамп чертежа) */
.stamp {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; background: var(--surface);
  border-top: 2px solid var(--ink); display: grid; grid-template-columns: 1fr 1fr 0.8fr; padding-bottom: env(safe-area-inset-bottom);
}
.stamp > div { padding: 6px 10px 7px; border-left: 1px solid var(--ink); min-width: 0; }
.stamp > div:first-child { border-left: 0; }
.stamp span { display: block; font-size: 11px; color: var(--muted); }
.stamp b { display: block; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stamp .low b { color: var(--red); }
.stamp .save { position: absolute; right: 8px; top: -22px; font-size: 12px; background: var(--surface); border: 1px solid var(--line); border-bottom: 0; border-radius: 6px 6px 0 0; padding: 1px 8px; color: var(--muted); }

/* модальное окно / нижний лист */
.sheet-bg { position: fixed; inset: 0; background: rgba(10, 20, 30, .45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--surface); width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto; border-radius: 14px 14px 0 0; padding: 14px 14px calc(18px + env(safe-area-inset-bottom)); }
.sheet .sheet-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.sheet .sheet-head h2 { margin: 0; flex: 1; }
.menu button { width: 100%; justify-content: flex-start; border: 0; border-top: 1px solid var(--line); border-radius: 0; }
.menu button:first-child { border-top: 0; }

.calcline { display: flex; justify-content: space-between; padding: 8px 0; border-top: 1px dashed var(--line); }
.calcline b { font-size: 17px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 14px; }
.kv > :nth-child(odd) { color: var(--muted); }
.kv > :nth-child(even) { text-align: right; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.chip { font-size: 13px; padding: 3px 4px 3px 10px; border-radius: 99px; background: var(--blue-soft); color: var(--ink); display: inline-flex; align-items: center; gap: 4px; }
.chip button { min-height: 0; padding: 0 6px; border: 0; background: transparent; color: var(--muted); }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: 84px; background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 8px; z-index: 60; max-width: 90vw; }

table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th, table.t td { border-bottom: 1px solid var(--line); padding: 6px 6px; text-align: left; vertical-align: top; }
table.t th { color: var(--muted); font-weight: 500; font-size: 13px; }
table.t td.num, table.t th.num { text-align: right; }

.login { max-width: 360px; margin: 12vh auto 0; padding: 0 16px; }
.login h1 { font-size: 26px; margin-bottom: 18px; }
.login .mark { width: 44px; height: 6px; background: var(--ink); margin-bottom: 18px; box-shadow: 0 10px 0 var(--signal); }

@media (min-width: 760px) {
  main { padding: 18px 20px 120px; }
  .sheet-bg { align-items: center; }
  .sheet { border-radius: 14px; }
  .node .cols { display: flex; gap: 16px; color: var(--muted); font-size: 13px; }
  .node .cols span { min-width: 90px; text-align: right; }
  .stamp { left: 50%; transform: translateX(-50%); max-width: 760px; border: 2px solid var(--ink); border-bottom: 0; border-radius: 8px 8px 0 0; }
  nav.bottom { display: none; }
  .top .nav { display: flex; gap: 14px; }
}
@media (max-width: 759px) { .top .nav { display: none; } }
@media (prefers-reduced-motion: no-preference) {
  .sheet { animation: up .18s ease-out; }
  @keyframes up { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
}
