/* Перевірка збірки — mobile-first.
   Палітра в дусі трекера часу: теплий темний фон, гірчичний акцент, шавлія, бірюза, іржа. */
:root {
  --bg: #1d1b18;
  --bg-2: #262320;
  --surface: #2c2925;
  --surface-2: #35312c;
  --line: #4a4036;
  --text: #f1ebdf;
  --muted: #a99f90;
  --accent: #dcab45;
  --accent-ink: #231c0b;
  --ok: #94b08c;
  --ok-bg: rgba(148, 176, 140, .16);
  --warn: #dcab45;
  --warn-bg: rgba(220, 171, 69, .16);
  --info: #4aa3a3;
  --danger: #d2693f;
  --danger-bg: rgba(210, 105, 63, .16);
  --radius: 14px;
  --tap: 52px;
  --nav-h: 64px;
  --shadow: 0 6px 24px rgba(0, 0, 0, .35);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3eee4;
    --bg-2: #ebe4d6;
    --surface: #fffdf8;
    --surface-2: #f7f1e5;
    --line: #d8cdb9;
    --text: #2a241b;
    --muted: #6f6556;
    --accent: #b8841c;
    --accent-ink: #fffaf0;
    --ok: #4e7a47;
    --ok-bg: rgba(78, 122, 71, .14);
    --warn: #96690c;
    --warn-bg: rgba(184, 132, 28, .16);
    --info: #2a7f7f;
    --danger: #b4471c;
    --danger-bg: rgba(180, 71, 28, .12);
    --shadow: 0 6px 24px rgba(60, 40, 10, .15);
    color-scheme: light;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 130px; scroll-padding-bottom: 190px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .75rem; }
a { color: var(--accent); }
code { background: var(--surface-2); padding: .1em .4em; border-radius: 6px; font-size: .9em; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .02em; }
.ico { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 3px solid var(--info); outline-offset: 2px; border-radius: 8px; }

/* ---------- оболонка ---------- */
.shell { min-height: 100vh; min-height: 100dvh; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(8px + var(--safe-t)) 16px 8px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 700; min-width: 0; }
.brand span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-mark { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); flex: none; }
.brand-mark svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.topbar-user { display: flex; align-items: center; gap: 4px; min-width: 0; }
.who { color: var(--muted); font-size: .9rem; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { display: grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 12px; background: transparent; color: var(--muted); cursor: pointer; }
.icon-btn:hover { background: var(--surface); color: var(--text); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(3, 1fr);
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: var(--bg-2);
  border-top: 1px solid var(--line);
}
.nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: .78rem; font-weight: 600;
}
.nav a svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav a[aria-current="page"] { color: var(--accent); }
.nav a[aria-current="page"] svg { stroke-width: 2.2; }

.page { padding: 16px 16px calc(var(--nav-h) + var(--safe-b) + 24px); max-width: 1180px; margin: 0 auto; }
.page.has-actions { padding-bottom: calc(var(--nav-h) + var(--safe-b) + 96px); }
.loading { color: var(--muted); text-align: center; padding: 48px 0; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); font-size: .9rem; margin-top: 4px; }

/* ---------- базові компоненти ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.card > h2, .card > h3 { margin-bottom: 12px; }
.stack > * + * { margin-top: 12px; }
.sp { margin-top: 16px; }
.row-flex { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface-2); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  touch-action: manipulation;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; }
.btn.sm { min-height: 40px; padding: 0 12px; font-size: .9rem; border-radius: 10px; }
.btn.block { display: flex; width: 100%; }
.btn-icon { width: 44px; min-height: 44px; padding: 0; }
.btn-icon.sm { width: 40px; min-height: 40px; }
.btn-icon:disabled { opacity: .3; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: .85rem; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
input[type=text], input[type=password], input[type=search], input[type=date], select, textarea, input:not([type]) {
  width: 100%; min-height: var(--tap); padding: 10px 14px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px;
  font: inherit; font-size: 1rem;
}
textarea { min-height: 100px; resize: vertical; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 36px; }
input:disabled, select:disabled { opacity: .7; }
.form-error { color: var(--danger); background: var(--danger-bg); border-radius: 10px; padding: 10px 12px; margin: 0 0 12px; }
.hint { font-size: .88rem; color: var(--muted); margin-top: 8px; }
.hint.warn { color: var(--warn); }
.hint a { font-weight: 600; }

/* сегментований вибір типу робіт */
.seg { display: grid; gap: 8px; }
.seg label { position: relative; display: block; }
.seg input { position: absolute; opacity: 0; inset: 0; }
.seg span {
  display: flex; align-items: center; min-height: var(--tap); padding: 8px 14px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px; font-weight: 600; cursor: pointer;
}
.seg input:checked + span { border-color: var(--accent); background: var(--warn-bg); color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.seg input:focus-visible + span { outline: 3px solid var(--info); outline-offset: 2px; }
.seg input:disabled + span { opacity: .7; cursor: default; }

.badge { display: inline-flex; align-items: center; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 700; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }
.badge.info { background: rgba(74, 163, 163, .16); color: var(--info); }

.bar { display: block; height: 8px; border-radius: 99px; background: var(--bg); overflow: hidden; border: 1px solid var(--line); }
.bar-fill { display: block; height: 100%; background: var(--ok); border-radius: 99px; transition: width .2s; }

.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty .btn { margin-top: 8px; }

/* ---------- сторінка перевірки ---------- */
.check-layout { display: block; }
.side { margin-bottom: 8px; }
.summary { position: relative; }
.summary .numbers { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 8px; font-size: .9rem; }
.summary .numbers strong { font-size: 1.4rem; }
.summary .rest { color: var(--muted); font-size: .85rem; margin-top: 8px; }
.summary .rest.bad { color: var(--warn); }

.drafts { display: grid; gap: 8px; }
.draft { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); color: inherit; text-decoration: none; min-height: 60px; }
.draft .grow strong { display: block; }
.draft .progress-txt { color: var(--muted); font-size: .85rem; white-space: nowrap; }

.cat { margin-bottom: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: clip; }
.cat > summary { list-style: none; display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 56px; padding: 10px 16px; cursor: pointer; font-weight: 700; position: sticky; top: calc(61px + var(--safe-t)); background: var(--surface); z-index: 2; border-bottom: 1px solid transparent; border-radius: calc(var(--radius) - 1px) calc(var(--radius) - 1px) 0 0; }
.cat[open] > summary { border-bottom-color: var(--line); }
.cat > summary::-webkit-details-marker { display: none; }
.cat > summary .cnt { color: var(--muted); font-weight: 600; font-size: .9rem; white-space: nowrap; }
.cat > summary .cnt.full { color: var(--ok); }
.cat > summary::after { content: ""; width: 10px; height: 10px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); margin-left: 4px; flex: none; transition: transform .15s; }
.cat[open] > summary::after { transform: rotate(-135deg); }

.item { position: relative; display: flex; align-items: flex-start; gap: 14px; min-height: 60px; padding: 14px 16px; cursor: pointer; border-top: 1px solid var(--line); }
.item:first-of-type { border-top: 0; }
.item input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.item .box { flex: none; width: 30px; height: 30px; margin-top: 0; border: 2px solid var(--muted); border-radius: 9px; display: grid; place-items: center; background: var(--bg); transition: background .1s, border-color .1s; }
.item .box svg { width: 20px; height: 20px; fill: none; stroke: var(--accent-ink); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; opacity: 0; }
.item input:checked ~ .box { background: var(--ok); border-color: var(--ok); }
.item input:checked ~ .box svg { opacity: 1; }
.item input:focus-visible ~ .box { outline: 3px solid var(--info); outline-offset: 2px; }
.item .txt { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.item .txt b { font-weight: 600; display: block; }
.item .txt small { display: block; color: var(--muted); margin-top: 2px; font-size: .88rem; }
.item input:checked ~ .txt b { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--line); }
.item .tag { flex: none; align-self: center; }
.item .box.on { background: var(--ok); border-color: var(--ok); }
.item .box.on svg { opacity: 1; }
.item.missing { background: var(--danger-bg); }
.item.missing .box { border-color: var(--danger); }
.item.hide { display: none; }
.item.ro { cursor: default; }
.item.ro .box { cursor: default; }

.actions-bar {
  position: fixed; left: 0; right: 0; z-index: 25;
  bottom: calc(var(--nav-h) + var(--safe-b));
  display: flex; gap: 10px; padding: 10px 16px;
  background: color-mix(in srgb, var(--bg-2) 94%, transparent);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
}
.actions-bar .btn { flex: 1 1 0; min-height: 52px; }
.toolbar { display: flex; gap: 8px; align-items: center; justify-content: space-between; margin: 0 0 12px; flex-wrap: wrap; }
.switch { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; font-size: .92rem; color: var(--muted); }
.switch input { width: 22px; height: 22px; accent-color: var(--accent); }

/* ---------- історія ---------- */
.search { position: relative; }
.search .ico { position: absolute; left: 14px; top: 15px; color: var(--muted); }
.search input { padding-left: 46px; }
.filters { margin: 12px 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.filters > summary { list-style: none; display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 52px; padding: 8px 16px; cursor: pointer; font-weight: 600; }
.filters > summary::-webkit-details-marker { display: none; }
.filters .fbody { padding: 4px 16px 12px; display: grid; gap: 0 12px; grid-template-columns: 1fr; }
.filters .fbody .field { margin-bottom: 12px; }
.filters .fbody .actions { display: flex; gap: 8px; }

.list { display: grid; gap: 10px; }
.entry { display: block; padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); color: inherit; text-decoration: none; }
.entry:hover { border-color: var(--muted); }
.entry .l1 { display: flex; justify-content: space-between; gap: 8px; align-items: center; margin-bottom: 4px; }
.entry .serial { font-weight: 700; font-size: 1.05rem; overflow-wrap: anywhere; }
.entry .meta { color: var(--muted); font-size: .88rem; display: flex; flex-wrap: wrap; gap: 2px 12px; }
.entry .l3 { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.entry .l3 .bar { flex: 1; }
.entry .l3 .txt { font-size: .85rem; color: var(--muted); white-space: nowrap; }
.entry-wrap { position: relative; }
.entry-wrap .redo { position: absolute; right: 8px; bottom: 6px; }

/* ---------- деталі ---------- */
.kv { display: grid; grid-template-columns: 1fr; gap: 10px; }
.kv > div { min-width: 0; }
.kv dt { color: var(--muted); font-size: .8rem; font-weight: 600; margin-bottom: 2px; }
.kv dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
dl.kv { margin: 0; }
.view-cat h3 { padding: 14px 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 8px; }
.view-cat h3 .cnt { font-weight: 600; color: var(--muted); font-size: .9rem; }
.view-cat .item { cursor: default; }

/* ---------- налаштування ---------- */
.tabs { display: flex; gap: 6px; overflow-x: auto; margin: 0 -16px 16px; padding: 0 16px 4px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { flex: none; min-height: 46px; padding: 0 16px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; }
.tabs button[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.rowitem { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; padding: 10px 0; border-top: 1px solid var(--line); }
.rowitem:first-child { border-top: 0; }
.rowitem .grow { flex: 1 1 200px; }
.rowitem .grow b { display: block; overflow-wrap: anywhere; }
.rowitem .grow .sub { color: var(--muted); font-size: .84rem; overflow-wrap: anywhere; }
.rowitem .acts { display: flex; gap: 4px; flex: none; margin-left: auto; }
.rowitem.inactive .grow b { color: var(--muted); }
.catcard { padding: 0; overflow: hidden; }
.catcard > .head { display: flex; align-items: center; gap: 6px; padding: 10px 12px 10px 16px; background: var(--surface-2); border-bottom: 1px solid var(--line); }
.catcard > .head h3 { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.catcard > summary { list-style: none; cursor: pointer; min-height: 56px; }
.catcard > summary::after { content: ""; width: 10px; height: 10px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); margin: 0 6px 4px 4px; flex: none; transition: transform .15s; }
.catcard[open] > summary::after { transform: rotate(-135deg); margin-bottom: 0; margin-top: 6px; }
.cat-tools { padding: 10px 0 4px; }
.catcard > summary::-webkit-details-marker { display: none; }
.catcard > .body { padding: 4px 12px 12px 16px; }
.addrow { display: flex; gap: 8px; margin-bottom: 14px; }
.addrow input { flex: 1 1 auto; min-width: 0; }
.checks { display: grid; gap: 4px; margin-bottom: 14px; }
.checks label { display: flex; align-items: center; gap: 12px; min-height: 46px; padding: 4px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); cursor: pointer; }
.checks input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.checks.models { max-height: 220px; overflow-y: auto; }
.legend { font-size: .85rem; font-weight: 600; color: var(--muted); margin: 0 0 6px; }

/* ---------- діалог ---------- */
dialog.dlg { width: min(560px, 100vw - 24px); max-height: calc(100dvh - 24px); padding: 0; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
dialog.dlg::backdrop { background: rgba(0, 0, 0, .6); }
.dlg-form { display: flex; flex-direction: column; max-height: calc(100dvh - 24px); }
.dlg-title { padding: 18px 20px 0; }
.dlg-body { padding: 14px 20px; overflow-y: auto; }
.dlg-foot { display: flex; gap: 10px; padding: 12px 20px calc(16px + var(--safe-b)); border-top: 1px solid var(--line); justify-content: flex-end; }
.dlg-foot .btn { flex: 1 1 0; }

/* ---------- повідомлення ---------- */
.toasts { position: fixed; left: 12px; right: 12px; z-index: 100; bottom: calc(var(--nav-h) + var(--safe-b) + 80px); display: grid; gap: 8px; justify-items: center; pointer-events: none; }
.toast { pointer-events: auto; max-width: 560px; padding: 12px 16px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); box-shadow: var(--shadow); font-weight: 600; animation: pop .2s; }
.toast.ok { border-color: var(--ok); }
.toast.err { border-color: var(--danger); background: var(--danger-bg); backdrop-filter: blur(6px); }
.toast.out { opacity: 0; transition: opacity .35s; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

/* ---------- вхід / встановлення ---------- */
body.auth { display: grid; place-items: center; min-height: 100dvh; padding: 16px; }
.auth-card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 28px 22px; }
.auth-card h1 { margin-bottom: 4px; }
.auth-logo { width: 56px; height: 56px; display: grid; place-items: center; border-radius: 16px; background: var(--accent); color: var(--accent-ink); margin-bottom: 16px; }
.auth-logo svg { width: 32px; height: 32px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.auth-card form { margin-top: 18px; }

/* ---------- ширші екрани ---------- */
@media (min-width: 640px) {
  .filters .fbody { grid-template-columns: 1fr 1fr; }
  .kv { grid-template-columns: repeat(2, 1fr); }
  .toasts { bottom: 24px; }
}

@media (min-width: 900px) {
  :root { --nav-w: 220px; }
  .topbar { padding-left: 20px; padding-right: 20px; }
  .nav {
    top: 61px; bottom: 0; right: auto; width: var(--nav-w);
    height: auto; padding: 16px 12px; grid-template-columns: 1fr; grid-auto-rows: 52px; align-content: start; gap: 4px;
    border-top: 0; border-right: 1px solid var(--line);
  }
  .nav a { flex-direction: row; justify-content: flex-start; gap: 12px; padding: 0 14px; border-radius: 12px; font-size: 1rem; }
  .nav a[aria-current="page"] { background: var(--surface); }
  .page, .page.has-actions { margin-left: var(--nav-w); max-width: none; padding: 24px 32px 48px; }
  .page > * { max-width: 1180px; }
  .cat > summary { top: 61px; }
  html { scroll-padding-top: 130px; scroll-padding-bottom: 40px; }

  .check-layout { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 24px; align-items: start; }
  .side { position: sticky; top: 85px; }
  .actions-bar { position: static; padding: 0; background: none; border: 0; backdrop-filter: none; flex-direction: column; }
  .actions-bar .btn { flex: none; }
  .toolbar { margin-top: 0; }
  .list { grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); }
  .toasts { left: var(--nav-w); }
  .dlg-foot .btn { flex: 0 0 auto; min-width: 130px; }
}

@media (min-width: 1280px) {
  .page > * { max-width: 1320px; }
  .view-cols { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 24px; align-items: start; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

@media print {
  .nav, .topbar, .actions-bar, .toasts, .btn { display: none !important; }
  .page { margin: 0; padding: 0; }
  body { background: #fff; color: #000; }
}
