:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef2f5;
  --ink: #17232c;
  --muted: #5d6d7a;
  --line: #d9e0e6;
  --accent: #1d5f7a;
  --accent-ink: #ffffff;
  --accent-soft: #dcebf1;
  --warn: #9a6a00;
  --warn-soft: #fff3d6;
  --err: #a8321f;
  --err-soft: #fde6e1;
  --ok: #2f7a4a;
  --ok-soft: #e1f2e7;
  --c0: #7a8794; --c1: #3f8f5a; --c2: #c79a1e; --c3: #d0612b; --c4: #b3261e;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 32, 44, .06), 0 4px 14px rgba(16, 32, 44, .05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f161b; --surface: #172129; --surface-2: #1d2a33; --ink: #e5edf2; --muted: #93a4b1; --line: #2b3a45;
    --accent: #5fb2d3; --accent-ink: #062431; --accent-soft: #19394a; --warn: #f0c35a; --warn-soft: #3a2f12;
    --err: #ff8f7a; --err-soft: #43201a; --ok: #6fcf93; --ok-soft: #173a25; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f161b; --surface: #172129; --surface-2: #1d2a33; --ink: #e5edf2; --muted: #93a4b1; --line: #2b3a45;
  --accent: #5fb2d3; --accent-ink: #062431; --accent-soft: #19394a; --warn: #f0c35a; --warn-soft: #3a2f12;
  --err: #ff8f7a; --err-soft: #43201a; --ok: #6fcf93; --ok-soft: #173a25; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 var(--font); -webkit-text-size-adjust: 100%; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .6em; }
h1 { font-size: 1.45rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
.boot { padding: 40px; color: var(--muted); }

/* Шапка и навигация */
.top { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line); }
.top-row { display: flex; align-items: center; gap: 12px; padding: 10px 16px; max-width: 1280px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; text-decoration: none; color: var(--ink); white-space: nowrap; }
.brand img { width: 28px; height: 28px; }
.crumb { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1; }
.save-state { font-size: .85rem; color: var(--muted); white-space: nowrap; }
.tabs { display: flex; gap: 2px; overflow-x: auto; padding: 0 12px; max-width: 1280px; margin: 0 auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { border: 0; background: none; padding: 10px 12px; border-bottom: 3px solid transparent; color: var(--muted); cursor: pointer; white-space: nowrap; font-weight: 600; }
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.tab .badge { margin-left: 4px; }

main { max-width: 1280px; margin: 0 auto; padding: 18px 16px 80px; }
.grid { display: grid; gap: 14px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card + .card { margin-top: 14px; }
.card h2 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.hint { background: var(--accent-soft); border-radius: 8px; padding: 10px 12px; font-size: .9rem; }

/* Кнопки и поля */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); padding: 8px 14px; border-radius: 8px; cursor: pointer; font-weight: 600; text-decoration: none; color: var(--ink); min-height: 38px; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--err); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.big { padding: 12px 18px; font-size: 1.05rem; min-height: 48px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.rec { background: var(--err); border-color: var(--err); color: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .75; } }
label.f { display: grid; gap: 4px; font-size: .85rem; color: var(--muted); }
input[type=text], input[type=number], input[type=date], input[type=password], input:not([type]), select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 8px 10px; color: var(--ink); min-height: 38px;
}
textarea { min-height: 110px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.form .wide { grid-column: 1 / -1; }

/* Таблицы */
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
th { background: var(--surface-2); font-weight: 600; white-space: nowrap; position: sticky; top: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td input, td select { min-height: 32px; padding: 4px 6px; }
tr.group-row td { background: var(--surface-2); font-weight: 700; }
td.over { color: var(--err); font-weight: 700; }

/* Ведомость */
.defects { width: 100%; }
.defects td.cat { width: 52px; }
.defects td.cat select { padding: 4px 2px; text-align: center; }
.defects textarea { min-height: 38px; padding: 6px 8px; font-size: .9rem; resize: none; overflow: hidden; }
.defects .pos { width: 38px; color: var(--muted); }
.defects .act { width: 92px; white-space: nowrap; }
.cat-dot { display: inline-block; min-width: 22px; padding: 1px 6px; border-radius: 10px; color: #fff; font-size: .8rem; font-weight: 700; text-align: center; }
.c0 { background: var(--c0); } .c1 { background: var(--c1); } .c2 { background: var(--c2); } .c3 { background: var(--c3); } .c4 { background: var(--c4); }
.thumbs { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.thumbs img { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); cursor: zoom-in; }

@media (max-width: 760px) {
  .defects thead { display: none; }
  .defects, .defects tbody, .defects tr, .defects td { display: block; width: 100%; }
  .defects tr { border: 1px solid var(--line); border-radius: 8px; margin: 10px 0; padding: 8px; background: var(--surface); }
  .defects tr.group-row { border: 0; background: transparent; padding: 8px 0 0; }
  .defects td { border: 0; padding: 4px 0; }
  .defects td.cat { display: inline-block; width: 24%; }
  .defects td.cat::before { content: attr(data-l); font-size: .75rem; color: var(--muted); display: block; }
  .defects td[data-label]::before { content: attr(data-label); display: block; font-size: .75rem; color: var(--muted); }
  .defects .act { width: auto; }
}

/* Оценка */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.kpi { background: var(--surface-2); border-radius: 10px; padding: 12px; }
.kpi .v { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .l { font-size: .8rem; color: var(--muted); }
.kpi.main { background: var(--accent); color: var(--accent-ink); }
.kpi.main .l { color: inherit; opacity: .85; }
pre.calc { background: var(--surface-2); padding: 12px; border-radius: 8px; white-space: pre-wrap; font: .88rem/1.55 var(--mono); margin: 0; }

/* Проверки */
.check { display: flex; gap: 8px; padding: 8px 10px; border-radius: 8px; margin: 6px 0; font-size: .92rem; }
.check.error { background: var(--err-soft); }
.check.warn { background: var(--warn-soft); }
.check.info { background: var(--surface-2); }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 10px; font-size: .75rem; font-weight: 700; text-align: center; background: var(--err); color: #fff; }
.badge.warn { background: var(--warn); color: #000; }

/* Полевой режим */
.field-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.draft { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin: 10px 0; background: var(--surface); display: grid; gap: 8px; min-width: 0; }
.draft > * { min-width: 0; }
.draft select { max-width: 100%; }
label.f { min-width: 0; }
.draft .src { font-size: .82rem; color: var(--muted); font-style: italic; }
.draft .cats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.conf { font-size: .78rem; padding: 1px 8px; border-radius: 10px; background: var(--surface-2); color: var(--muted); }
.conf.low { background: var(--warn-soft); color: var(--warn); }

/* Схема, фото */
.scheme-box { overflow-x: auto; background: #fff; border-radius: 8px; border: 1px solid var(--line); padding: 8px; }
.scheme-box svg { display: block; max-width: none; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.photo { background: var(--surface-2); border-radius: 10px; overflow: hidden; display: grid; }
.photo img { width: 100%; aspect-ratio: 4/3; object-fit: cover; cursor: zoom-in; }
.photo .meta { padding: 8px; display: grid; gap: 6px; font-size: .85rem; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: grid; place-items: center; z-index: 50; cursor: zoom-out; }
.lightbox img { max-width: 96vw; max-height: 92vh; }

/* Объекты */
.proj { display: grid; gap: 4px; text-decoration: none; color: var(--ink); cursor: pointer; }
.proj:hover { border-color: var(--accent); }
.proj .t { font-weight: 700; }

/* Вход */
.login { max-width: 380px; margin: 12vh auto; padding: 0 16px; }
.login .card { display: grid; gap: 12px; }

/* План (markdown) */
.md h1 { font-size: 1.5rem; } .md h2 { margin-top: 1.4em; } .md table { margin: 10px 0; }
.md pre { background: var(--surface-2); padding: 12px; border-radius: 8px; overflow-x: auto; font: .8rem/1.4 var(--mono); }
.md td, .md th { white-space: normal; }

#toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 60; max-width: calc(100% - 32px); }
#toast.show { opacity: 1; }
.sticky-bar { position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--line); padding: 10px 0; margin-top: 12px; }
@media print { .top, .tabs, .btn { display: none !important; } }

/* Инструкция */
.help-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 14px; align-items: start; }
.help-toc { position: sticky; top: 120px; display: grid; gap: 2px; max-height: calc(100vh - 140px); overflow: auto; }
.help-toc a { text-decoration: none; padding: 4px 6px; border-radius: 6px; font-size: .92rem; }
.help-toc a:hover { background: var(--accent-soft); }
.help-body h2 { scroll-margin-top: 120px; border-top: 1px solid var(--line); padding-top: 18px; }
.help-body code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: .88em; }
@media (max-width: 760px) { .help-layout { grid-template-columns: 1fr; } .help-toc { position: static; max-height: none; } }

/* Чек-лист объекта */
.checklist { padding: 12px 16px; }
.steps { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.step { display: grid; grid-template-columns: auto 1fr; column-gap: 6px; align-items: center; text-decoration: none; color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: .9rem; min-width: 0; }
.step small { grid-column: 2; color: var(--muted); font-size: .75rem; }
.step span { color: var(--muted); font-weight: 700; }
.step.done { background: var(--ok-soft); border-color: transparent; }
.step.done span { color: var(--ok); }

/* Тур */
.tour-veil { position: fixed; inset: 0; background: rgba(8, 16, 22, .55); z-index: 70; pointer-events: none; }
.tour-veil.hole { inset: auto; background: transparent; border-radius: 10px; box-shadow: 0 0 0 4000px rgba(8, 16, 22, .55), 0 0 0 3px var(--accent); transition: all .2s; }
.tour-tip { position: fixed; z-index: 71; width: min(380px, calc(100vw - 24px)); background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 12px; padding: 16px; box-shadow: 0 12px 40px rgba(0, 0, 0, .3); }
.tour-tip.center { left: 50%; top: 50%; transform: translate(-50%, -50%); }
.tour-tip h3 { margin: 4px 0 6px; }
.tour-tip p { margin: 0 0 12px; font-size: .95rem; }

/* 3D-модель */
.b3d { position: relative; height: min(70vh, 640px); min-height: 360px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); background: #dfe9f1; touch-action: none; }
.b3d canvas { display: block; }
.b3d-labels { position: absolute; inset: 0; pointer-events: none; }
.b3d-labels span { position: absolute; left: 0; top: 0; font: 700 11px/1 var(--font); color: #10202b; background: rgba(255,255,255,.85); border-radius: 8px; padding: 2px 5px; transform-origin: 0 0; white-space: nowrap; }
