:root {
  --accent: #1f3a5f; --accent-2: #2d5a8c; --accent-soft: #e8eef6;
  --bg: #f4f6f9; --surface: #ffffff; --surface-2: #f8fafc; --line: #dde3ea; --line-2: #eef1f5;
  --text: #1d2430; --muted: #5b6675; --faint: #8a94a3;
  --ok: #1e7b4d; --ok-soft: #e4f4ea; --warn: #9a6200; --warn-soft: #fdf2dc; --bad: #b3261e; --bad-soft: #fbe9e7;
  --radius: 10px; --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --accent: #8fb3e0; --accent-2: #a9c6ea; --accent-soft: #1d2a3a;
    --bg: #0f1419; --surface: #171d24; --surface-2: #1c232b; --line: #2b3440; --line-2: #222a33;
    --text: #e6ebf1; --muted: #a3adba; --faint: #778291;
    --ok: #62c38f; --ok-soft: #16301f; --warn: #e2b04a; --warn-soft: #33290f; --bad: #f08a80; --bad-soft: #3a1b18;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent-2); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -0.01em; }
h1 { font-size: 22px; } h2 { font-size: 17px; } h3 { font-size: 14px; }
.muted { color: var(--muted); } .faint { color: var(--faint); } .num { font-variant-numeric: tabular-nums; text-align: right; }
.hidden { display: none !important; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 20; height: 52px; display: flex; align-items: center; gap: 14px; padding: 0 16px;
  background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); text-decoration: none; font-size: 15px; }
.top-title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.top-title b { color: var(--text); }
.top-actions { display: flex; align-items: center; gap: 10px; }
.save-state { font-size: 12px; color: var(--faint); }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 550; text-decoration: none; color: var(--text); white-space: nowrap; }
.btn:hover { border-color: var(--faint); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.primary { color: #0f1419; } }
.btn.primary:hover { filter: brightness(1.1); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--accent-soft); }
.btn.danger { color: var(--bad); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.icon { width: 30px; padding: 0; height: 30px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* home */
.wrap { max-width: 1120px; margin: 0 auto; padding: 22px 16px 80px; }
.home-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; justify-content: space-between; margin-bottom: 16px; }
.home-head p { margin: 4px 0 0; color: var(--muted); }
.search { width: 100%; max-width: 340px; height: 36px; border: 1px solid var(--line); border-radius: 8px; padding: 0 12px; background: var(--surface); }
.cases { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; margin-top: 12px; }
.case-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 6px; text-decoration: none; color: inherit; }
.case-card:hover { border-color: var(--accent-2); }
.case-card .row1 { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.case-card .reg { font-weight: 700; font-size: 15px; letter-spacing: .02em; }
.case-card .amt { font-weight: 650; font-variant-numeric: tabular-nums; }
.case-card .meta { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
  background: var(--accent-soft); color: var(--accent-2); }
.chip.ok { background: var(--ok-soft); color: var(--ok); } .chip.warn { background: var(--warn-soft); color: var(--warn); } .chip.bad { background: var(--bad-soft); color: var(--bad); }
.empty { text-align: center; padding: 48px 16px; border: 1px dashed var(--line); border-radius: var(--radius); color: var(--muted); background: var(--surface); }
.empty h2 { color: var(--text); margin-bottom: 6px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 8px 0 4px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.stat b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }

/* editor */
.editor { display: grid; grid-template-columns: 208px minmax(0, 1fr) 270px; gap: 18px; max-width: 1440px; margin: 0 auto; padding: 16px; align-items: start; }
.nav { position: sticky; top: 68px; display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 8px; color: var(--text); text-decoration: none; font-weight: 500; }
.nav a:hover { background: var(--accent-soft); }
.nav a.on { background: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .nav a.on { color: #0f1419; } }
.nav .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--line); margin-left: auto; flex: none; }
.nav .dot.ok { background: var(--ok); } .nav .dot.bad { background: var(--bad); }
.nav .n { width: 18px; font-size: 11.5px; color: var(--faint); font-variant-numeric: tabular-nums; }
.nav a.on .n { color: inherit; opacity: .8; }
.pane { min-width: 0; }
.pane-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.pane-foot { display: flex; justify-content: space-between; margin-top: 16px; }
.group { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.group > h3 { margin-bottom: 12px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 14px; }
.f { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.f.s2 { grid-column: span 2; } .f.s3 { grid-column: 1 / -1; }
.f label { font-size: 12.5px; font-weight: 550; color: var(--muted); }
.f label .req { color: var(--bad); margin-left: 2px; }
.f .hint { font-size: 11.5px; color: var(--faint); }
.f input, .f select, .f textarea, .cell input, .cell select {
  width: 100%; min-height: 36px; border: 1px solid var(--line); border-radius: 7px; padding: 6px 10px; background: var(--surface-2); }
.f textarea { resize: vertical; min-height: 60px; line-height: 1.45; }
.f input:focus, .f select:focus, .f textarea:focus, .cell input:focus, .cell select:focus, .search:focus {
  outline: 2px solid color-mix(in srgb, var(--accent-2) 55%, transparent); outline-offset: 0; border-color: var(--accent-2); background: var(--surface); }
.f.missing input, .f.missing textarea, .f.missing select { border-color: color-mix(in srgb, var(--bad) 60%, var(--line)); }
.f input.upper { text-transform: uppercase; }
.f input[type="color"] { padding: 2px; height: 36px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface-2); width: fit-content; max-width: 100%; }
.seg button { border: 0; background: transparent; padding: 0 12px; height: 34px; cursor: pointer; font-weight: 550; color: var(--muted); white-space: nowrap; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .seg button.on { color: #0f1419; } }

/* summary rail */
.rail { position: sticky; top: 68px; display: flex; flex-direction: column; gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.card h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 8px; }
.kvs { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; font-size: 13px; }
.kvs span:nth-child(odd) { color: var(--muted); }
.kvs span:nth-child(even) { text-align: right; font-variant-numeric: tabular-nums; }
.kvs .tot { font-weight: 700; color: var(--text) !important; font-size: 15px; padding-top: 6px; border-top: 1px solid var(--line); margin-top: 4px; }
.net-big { font-size: 26px; font-weight: 750; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.miss { list-style: none; padding: 0; margin: 0; font-size: 13px; display: flex; flex-direction: column; gap: 3px; max-height: 190px; overflow: auto; }
.miss li::before { content: "•"; color: var(--bad); margin-right: 6px; }

/* data tables (parts / labour) */
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
table.data { border-collapse: separate; border-spacing: 0; width: 100%; min-width: 980px; font-size: 13px; }
table.data th { position: sticky; top: 0; background: var(--surface-2); text-align: left; font-size: 11.5px; font-weight: 650; color: var(--muted);
  padding: 8px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; z-index: 1; }
table.data td { padding: 3px 4px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data tfoot td { background: var(--surface-2); font-weight: 650; padding: 8px 6px; border-top: 1px solid var(--line); }
table.data .cell input, table.data .cell select { min-height: 32px; padding: 4px 7px; border-color: transparent; background: transparent; }
table.data .cell input:hover, table.data .cell select:hover { border-color: var(--line); }
table.data .cell input.n { text-align: right; font-variant-numeric: tabular-nums; }
table.data td.idx { color: var(--faint); width: 30px; text-align: center; font-size: 12px; }
table.data td.out { text-align: right; font-variant-numeric: tabular-nums; padding-right: 10px; white-space: nowrap; }
table.data tr.allowed td.out.base { color: var(--ok); font-weight: 650; }
table.data tr.rejected td { color: var(--faint); }
table.data tr.rejected .cell input { color: var(--muted); }
table.data td.act { width: 64px; white-space: nowrap; }
.dec { font-weight: 600; }
.dec.replace, .dec.disposal { color: var(--ok); } .dec.repair { color: var(--warn); } .dec.na { color: var(--bad); }
.tbl-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; margin: 10px 0; }
.legend { font-size: 12px; color: var(--muted); }
.totals-strip { display: flex; flex-wrap: wrap; gap: 8px 18px; font-size: 13px; margin-top: 10px; }
.totals-strip b { font-variant-numeric: tabular-nums; }

/* photos & docs */
.drop { border: 1.5px dashed var(--line); border-radius: var(--radius); padding: 18px; text-align: center; background: var(--surface); color: var(--muted); }
.drop.over { border-color: var(--accent-2); background: var(--accent-soft); }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-top: 12px; }
.ph { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.ph img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: var(--surface-2); display: block; }
.ph .ph-b { padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.ph input { width: 100%; height: 30px; border: 1px solid var(--line); border-radius: 6px; padding: 0 8px; background: var(--surface-2); font-size: 12.5px; }
.ph .ph-a { display: flex; gap: 4px; justify-content: space-between; align-items: center; }
.docs { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.doc { display: grid; grid-template-columns: 34px minmax(0, 1fr) 220px auto; gap: 10px; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; }
.doc .ico { width: 34px; height: 34px; border-radius: 7px; background: var(--accent-soft); color: var(--accent-2); display: grid; place-items: center; font-size: 11px; font-weight: 700; }
.doc .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc select { height: 32px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-2); padding: 0 6px; }

/* output */
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.check { display: flex; gap: 8px; align-items: center; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.pdf-frame { width: 100%; height: 78vh; border: 1px solid var(--line); border-radius: var(--radius); background: #525659; margin-top: 12px; }
.alert { padding: 10px 12px; border-radius: 8px; font-size: 13px; }
.alert.bad { background: var(--bad-soft); color: var(--bad); } .alert.ok { background: var(--ok-soft); color: var(--ok); } .alert.warn { background: var(--warn-soft); color: var(--warn); }
.imgslot { display: flex; align-items: center; gap: 10px; }
.imgslot img { max-height: 56px; max-width: 140px; border: 1px solid var(--line); border-radius: 6px; background: #fff; padding: 3px; }

/* dialog & toast */
dialog { border: 1px solid var(--line); border-radius: 12px; padding: 0; width: min(560px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(15, 20, 25, .45); }
dialog .dh { padding: 16px 18px 6px; } dialog .db { padding: 6px 18px 12px; } dialog .df { padding: 12px 18px 16px; display: flex; justify-content: flex-end; gap: 8px; }
dialog textarea { width: 100%; min-height: 180px; border: 1px solid var(--line); border-radius: 8px; padding: 8px; font: 12.5px/1.4 var(--mono); background: var(--surface-2); }
.choice { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice button { text-align: left; padding: 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); cursor: pointer; }
.choice button:hover { border-color: var(--accent-2); }
.choice b { display: block; margin-bottom: 4px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none; transition: .2s;
  background: #1d2430; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 13.5px; z-index: 50; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translateX(-50%); }

/* wide mode: grids get the full width, summary becomes a bottom bar */
.editor.wide { grid-template-columns: 208px minmax(0, 1fr); padding-bottom: 90px; }
.editor.wide .rail { position: fixed; left: 0; right: 0; bottom: 0; top: auto; z-index: 15; flex-direction: row; gap: 0; }
.editor.wide .rail .card { flex: 1; border-radius: 0; border-width: 1px 0 0; box-shadow: 0 -4px 14px rgba(0,0,0,.06); display: flex; align-items: center; gap: 22px; padding: 10px 24px; }
.editor.wide .rail .card h3, .editor.wide .rail .miss-card { display: none; }
.editor.wide .rail .kvs { display: flex; gap: 18px; margin: 0 !important; flex-wrap: wrap; }
.editor.wide .rail .kvs span:nth-child(odd)::after { content: ":"; }
.editor.wide .rail .card > a { width: auto !important; margin: 0 0 0 auto !important; }
.rail .net-big { white-space: nowrap; }
table.data select { text-overflow: ellipsis; }

/* responsive */
@media (max-width: 1180px) {
  .editor { grid-template-columns: 196px minmax(0, 1fr); }
  .rail { position: fixed; left: 0; right: 0; bottom: 0; top: auto; z-index: 15; flex-direction: row; gap: 0; }
  .rail .card { flex: 1; border-radius: 0; border-width: 1px 0 0; box-shadow: 0 -4px 14px rgba(0,0,0,.06); display: flex; align-items: center; gap: 16px; padding: 10px 16px; }
  .rail .card h3, .rail .kvs, .rail .miss-card, .editor.wide .rail .kvs { display: none; }
  .rail .card > a { width: auto !important; margin: 0 0 0 auto !important; }
  .rail .net-big { font-size: 20px; }
  .editor { padding-bottom: 90px; }
}
@media (max-width: 760px) {
  .editor { grid-template-columns: 1fr; padding: 0 12px 96px; gap: 10px; }
  .nav { position: sticky; top: 52px; z-index: 10; flex-direction: row; overflow-x: auto; background: var(--bg); padding: 8px 0; margin: 0 -12px; padding-inline: 12px; scrollbar-width: none; }
  .nav a { white-space: nowrap; padding: 6px 10px; }
  .nav .dot { margin-left: 2px; }
  .nav .n { display: none; }
  .grid { grid-template-columns: 1fr 1fr; }
  .f.s2 { grid-column: 1 / -1; }
  .doc { grid-template-columns: 34px minmax(0, 1fr) auto; }
  .doc select { grid-column: 2 / -1; }
  .top-title { display: none; }
  .choice { grid-template-columns: 1fr; }
  .rail .card { gap: 10px; }
}
@media (max-width: 420px) { .grid { grid-template-columns: 1fr; } }
@media print { .topbar, .nav, .rail { display: none; } }
.logo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.logo-tile { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 12px 8px; border: 1.5px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer; color: #1d2430; font-size: 12px; font-weight: 550; }
.logo-tile img { height: 64px; max-width: 120px; object-fit: contain; }
.logo-tile.on { border-color: var(--accent-2); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-2) 25%, transparent); }

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 14px; }
.filters select, .filters input[type=date] { height: 36px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); padding: 0 8px; }
.filters .search { flex: 1 1 260px; }
#userChip { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; }
#userChip img { width: 26px; height: 26px; border-radius: 50%; }
.login { max-width: 420px; margin: 12vh auto; text-align: center; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 28px 24px; box-shadow: var(--shadow); }
.login img { width: 84px; }
.sync { font-size: 12px; color: var(--faint); }

.stat.bad b { color: var(--bad); } .stat.warn b { color: var(--warn); }
.ins-table { margin-top: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; }
.ins-table summary { cursor: pointer; font-weight: 600; font-size: 13px; }
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(230px, 1fr); gap: 10px; overflow-x: auto; margin-top: 12px; padding-bottom: 8px; }
.bcol { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 140px; }
.bhead { padding: 9px 10px; font-weight: 650; font-size: 12.5px; display: flex; justify-content: space-between; border-bottom: 1px solid var(--line); }
.bhead span { color: var(--faint); }
.blist { padding: 8px; display: flex; flex-direction: column; gap: 8px; flex: 1; min-height: 60px; }
.bcard { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; text-decoration: none; color: inherit; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 3px; }
.bcard .row1 { display: flex; justify-content: space-between; gap: 6px; align-items: center; }
.bcard .meta { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sortable-ghost { opacity: .4; }
.todo { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.todo-item { display: grid; grid-template-columns: 110px 1fr auto; gap: 10px; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; text-decoration: none; color: inherit; }
.notes { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.note { border-left: 3px solid var(--accent-2); background: var(--surface-2); padding: 8px 10px; border-radius: 0 8px 8px 0; }
.todo-add { display: flex; gap: 8px; flex-wrap: wrap; }
.todo-add input { height: 34px; border: 1px solid var(--line); border-radius: 7px; padding: 0 10px; background: var(--surface-2); }
.todo-add input:first-child { flex: 1 1 240px; }
@media (max-width: 760px) { .todo-item { grid-template-columns: 1fr; } .board { grid-auto-columns: 80%; } }
