/* BHD Part Tracker. Built for gloves, sunlight and one thumb: big targets, strong contrast, status always shown as colour AND words. */
:root {
  --bg: #f2ede6;
  --surface: #fbf8f3;
  --surface-2: #e9e2d7;
  --ink: #0d1b3e;
  --muted: #5a6277;
  --line: #d9d0c2;
  --accent: #a8632c;
  --accent-ink: #ffffff;
  --navy: #0d1b3e;
  --on-navy: #f2ede6;
  --ok: #17703f;
  --ok-bg: #d6efdf;
  --warn: #8a5a00;
  --warn-bg: #fbe8bd;
  --bad: #a3231b;
  --bad-bg: #f8d4d0;
  --focus: #2f6fb0;
  --shadow: 0 1px 2px rgba(13,27,62,.08), 0 6px 18px rgba(13,27,62,.07);
  --font: 'Hanken Grotesk', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --display: 'Lora', Georgia, 'Times New Roman', serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a1126; --surface: #121b36; --surface-2: #1b2646; --ink: #f2ede6; --muted: #a2abc2; --line: #28345a;
    --accent: #d9904f; --accent-ink: #1b1005; --navy: #060b1a; --on-navy: #f2ede6;
    --ok: #66d197; --ok-bg: #12301f; --warn: #f0c45b; --warn-bg: #36290a; --bad: #ff8b82; --bad-bg: #3b1512; --focus: #7db3ec;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.35); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0a1126; --surface: #121b36; --surface-2: #1b2646; --ink: #f2ede6; --muted: #a2abc2; --line: #28345a;
  --accent: #d9904f; --accent-ink: #1b1005; --navy: #060b1a; --on-navy: #f2ede6;
  --ok: #66d197; --ok-bg: #12301f; --warn: #f0c45b; --warn-bg: #36290a; --bad: #ff8b82; --bad-bg: #3b1512; --focus: #7db3ec;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.35); color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.4 var(--font); -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
h1, h2, h3 { font-family: var(--display); margin: 0; letter-spacing: -.01em; text-wrap: balance; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
.muted { color: var(--muted); }
.tnum { font-variant-numeric: tabular-nums; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

#app { min-height: 100%; display: flex; flex-direction: column; }
#print-root { display: none; }

/* ---------- shell */
.top { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; background: var(--navy); color: var(--on-navy); display: flex; align-items: center; gap: 10px; padding: 10px 16px; }
.brand { display: grid; gap: 0; min-width: 0; margin-right: auto; }
.brand b { font-family: var(--display); font-size: 1.1rem; white-space: nowrap; }
.brand span { font-size: .78rem; opacity: .75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lang { display: flex; gap: 2px; flex: 0 0 auto; }
.lang button { border: 2px solid transparent; background: transparent; border-radius: 10px; width: 44px; height: 44px; padding: 0; display: grid; place-items: center; opacity: .55; }
.lang button[aria-pressed="true"] { opacity: 1; border-color: var(--on-navy); }
.lang svg { width: 28px; height: 19px; border-radius: 3px; display: block; box-shadow: 0 0 0 1px rgba(0,0,0,.3); }
.login .lang { justify-self: end; }
.login .lang button[aria-pressed="true"] { border-color: var(--ink); }
.pill { border: 1px solid rgba(242,237,230,.35); background: transparent; color: inherit; border-radius: 999px; padding: 6px 12px; font-size: .82rem; font-weight: 700; display: inline-flex; align-items: center; gap: 6px; min-height: 36px; }
.pill i { width: 9px; height: 9px; border-radius: 50%; background: #5bd38b; display: inline-block; }
.pill.off i { background: #f0b34a; }
.pill.off { border-color: #f0b34a; }
main { flex: 1; width: 100%; max-width: 760px; margin: 0 auto; padding: 14px 16px calc(92px + env(safe-area-inset-bottom, 0px)); }
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--surface); border-top: 1px solid var(--line); display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px)); gap: 4px; }
.tabs button { border: 0; background: transparent; border-radius: 12px; padding: 8px 4px 6px; display: grid; justify-items: center; gap: 2px; font-size: .74rem; font-weight: 700; color: var(--muted); min-height: 56px; }
.tabs button svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs button[aria-current="page"] { color: var(--ink); background: var(--surface-2); }
.tabs button[aria-current="page"] svg { stroke: var(--accent); }

/* ---------- controls */
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 12px 16px; font-weight: 700; min-height: 48px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-align: center; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.dark { background: var(--navy); color: var(--on-navy); border-color: var(--navy); }
.btn.big { min-height: 60px; font-size: 1.1rem; width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.small { min-height: 38px; padding: 6px 12px; font-size: .88rem; }
.field { display: grid; gap: 4px; font-size: .82rem; font-weight: 700; color: var(--muted); min-width: 0; }
.field input, .field select, input.text, select.text { width: 100%; min-height: 48px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-weight: 500; font-size: 1rem; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.row > * { flex: 1 1 140px; min-width: 0; }
.stack { display: grid; gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px; box-shadow: var(--shadow); min-width: 0; }
.chip { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 3px 10px 3px 8px; font-size: .78rem; font-weight: 800; background: color-mix(in srgb, var(--c, #888) 18%, var(--surface)); color: var(--ink); border: 1px solid color-mix(in srgb, var(--c, #888) 55%, transparent); white-space: nowrap; }
.chip::before { content: ''; width: 9px; height: 9px; border-radius: 50%; background: var(--c, #888); border: 1px solid rgba(0,0,0,.25); }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--c); border: 1px solid rgba(0,0,0,.3); display: inline-block; flex: none; }

/* ---------- scan view */
.modes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.modes button { border: 2px solid var(--line); background: var(--surface); border-radius: 14px; padding: 8px 2px; text-align: center; min-height: 56px; display: grid; gap: 4px; align-content: center; justify-items: center; }
.modes button b { font-size: .86rem; line-height: 1.1; }
.modes button small { display: none; }
.modes button[aria-pressed="true"] { border-color: var(--c); background: color-mix(in srgb, var(--c) 16%, var(--surface)); box-shadow: inset 0 0 0 1px var(--c); }
.modes button .dot { margin: 0; width: 14px; height: 14px; }
.ctx { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ctx .field { font-size: .74rem; }
.ctx .field select, .ctx .field input { min-height: 44px; padding: 8px 10px; }
.ctx .field.wide { grid-column: 1 / -1; }

.result { border-radius: 18px; padding: 16px; border: 2px solid var(--line); background: var(--surface); min-height: 104px; display: grid; gap: 3px; align-content: center; transition: background .12s, border-color .12s; }
.result .t { font-weight: 800; letter-spacing: .02em; font-size: .95rem; text-transform: uppercase; }
.result .code { font-size: clamp(2rem, 10vw, 3rem); font-weight: 800; line-height: 1; letter-spacing: -.02em; overflow-wrap: anywhere; }
.result .d { font-size: .98rem; }
.result.ok { background: var(--ok-bg); border-color: var(--ok); }
.result.ok .t { color: var(--ok); }
.result.warn { background: var(--warn-bg); border-color: var(--warn); }
.result.warn .t { color: var(--warn); }
.result.bad { background: var(--bad-bg); border-color: var(--bad); }
.result.bad .t { color: var(--bad); }
.result.idle .code { font-size: 1.3rem; font-family: var(--display); font-weight: 600; }
.result .thumb { width: 100%; max-height: 180px; object-fit: contain; border-radius: 10px; background: #000; margin-top: 6px; }
.result .meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.cam { position: relative; border-radius: 18px; overflow: hidden; background: #000; aspect-ratio: 4 / 3; max-height: 44vh; width: 100%; border: 2px solid var(--line); }
.cam video { width: 100%; height: 100%; object-fit: cover; display: block; }
.cam .reticle { position: absolute; inset: 14% 14%; border-radius: 18px; pointer-events: none; box-shadow: 0 0 0 9999px rgba(0,0,0,.28); border: 3px solid rgba(255,255,255,.9); }
.cam .msg { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; gap: 10px; padding: 20px; color: #fff; background: rgba(6,11,26,.8); }
.cam .msg[hidden] { display: none; }
.cam .tools { position: absolute; right: 8px; bottom: 8px; display: flex; gap: 8px; }
.cam .tools .pill { background: rgba(6,11,26,.7); color: #fff; }
.cam.flash-ok { border-color: var(--ok); } .cam.flash-warn { border-color: var(--warn); } .cam.flash-bad { border-color: var(--bad); }

.recent { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.recent li { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; padding: 10px 12px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); }
.recent .tone { width: 10px; height: 36px; border-radius: 5px; background: var(--ok); }
.recent .tone.warn { background: var(--warn); } .recent .tone.bad { background: var(--bad); }
.recent b { font-size: 1.05rem; }
.recent small { color: var(--muted); display: block; }
.matches { display: grid; gap: 6px; }
.matches button { display: grid; grid-template-columns: 1fr auto; gap: 8px; text-align: left; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 10px 12px; min-height: 52px; align-items: center; }

/* ---------- dashboard */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.tiles .tile:first-child { grid-column: 1 / -1; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.tile b { display: block; font-size: 1.9rem; line-height: 1.05; font-weight: 800; }
.tile span { font-size: .82rem; color: var(--muted); font-weight: 700; }
.tile::before { content: ''; display: block; width: 28px; height: 5px; border-radius: 3px; background: var(--c, var(--line)); margin-bottom: 8px; }
.bar { display: flex; height: 16px; border-radius: 8px; overflow: hidden; background: var(--surface-2); border: 1px solid var(--line); }
.bar i { display: block; height: 100%; background: var(--c); min-width: 0; }
.bar i + i { border-left: 1px solid var(--surface); }
.villa-row { display: grid; gap: 6px; width: 100%; text-align: left; border: 1px solid var(--line); background: var(--surface); border-radius: 14px; padding: 12px; }
.villa-row .head { display: flex; align-items: center; gap: 4px 8px; flex-wrap: wrap; }
.villa-row .head b { font-size: 1.05rem; }
.villa-row .head span { margin-left: auto; font-weight: 700; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .8rem; font-weight: 700; color: var(--muted); }
.legend span { display: inline-flex; gap: 6px; align-items: center; }
.sec-table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.sec-table th { text-align: left; font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding: 6px 8px; }
.sec-table td { padding: 8px; border-top: 1px solid var(--line); vertical-align: middle; }
.sec-table td:first-child { max-width: 46vw; overflow-wrap: anywhere; }
.scroll-x { overflow-x: auto; }
.feed { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: .9rem; }
.feed li { display: grid; grid-template-columns: 5.2em 1fr; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); }

/* ---------- parts list + sheet */
.list { display: grid; gap: 6px; }
.part { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; text-align: left; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 10px 12px; min-height: 56px; width: 100%; }
.part .c { font-size: 1.15rem; font-weight: 800; overflow-wrap: anywhere; }
.part small { color: var(--muted); display: block; }
.part input[type=checkbox] { width: 24px; height: 24px; accent-color: var(--accent); }
.part.sel { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }
.sheet-bg { position: fixed; inset: 0; background: rgba(6,11,26,.55); z-index: 40; display: grid; align-items: end; }
.sheet { background: var(--bg); border-radius: 22px 22px 0 0; padding: 16px 16px calc(20px + env(safe-area-inset-bottom, 0px)); max-height: 92%; overflow: auto; width: 100%; max-width: 760px; margin: 0 auto; display: grid; gap: 12px; }
.sheet .big-code { font-size: 3rem; font-weight: 800; line-height: 1; overflow-wrap: anywhere; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: .95rem; }
.kv dt { color: var(--muted); font-weight: 700; } .kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: .9rem; }
.timeline li { padding-left: 14px; border-left: 3px solid var(--line); }
.timeline li.ok { border-color: var(--ok); } .timeline li.bad { border-color: var(--bad); } .timeline li.warn { border-color: var(--warn); }
.sticky-bar { position: sticky; bottom: calc(76px + env(safe-area-inset-bottom, 0px)); display: flex; gap: 8px; padding: 10px; border-radius: 14px; background: var(--navy); color: var(--on-navy); align-items: center; justify-content: space-between; box-shadow: var(--shadow); }

/* ---------- labels preview */
.preview { display: grid; gap: 12px; }
.lbl-wrap { overflow-x: auto; }

/* ---------- login */
.login { max-width: 420px; margin: 0 auto; padding: 8vh 16px; display: grid; gap: 14px; }
.login h1 { font-size: 2rem; }
.err { color: var(--bad); font-weight: 700; min-height: 1.4em; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(86px + env(safe-area-inset-bottom, 0px)); background: var(--navy); color: var(--on-navy); padding: 10px 16px; border-radius: 12px; font-weight: 700; z-index: 60; max-width: 92%; box-shadow: var(--shadow); }
.banner { border-radius: 12px; padding: 10px 12px; font-weight: 600; }
.banner.warn { background: var(--warn-bg); color: var(--warn); border: 1px solid var(--warn); }
.banner.bad { background: var(--bad-bg); color: var(--bad); border: 1px solid var(--bad); }
.banner.ok { background: var(--ok-bg); color: var(--ok); border: 1px solid var(--ok); }

/* ---------- label artwork (screen + print), sized in millimetres: 92 × 45 mm */
.lbl { width: 92mm; height: 45mm; border: .3mm solid #0d1b3e; background: #fff; color: #000; display: flex; position: relative; overflow: hidden; font-family: 'Hanken Grotesk', Arial, Helvetica, sans-serif; break-inside: avoid; }
.lbl .band { width: 9mm; flex: none; background: var(--c); display: grid; place-items: center; border-right: .3mm solid rgba(0,0,0,.5); }
.lbl .band span { writing-mode: vertical-rl; transform: rotate(180deg); font-size: 3.4mm; font-weight: 800; letter-spacing: .5mm; color: var(--bc, #000); text-transform: uppercase; }
.lbl .txt { flex: 1; min-width: 0; padding: 2.4mm 2mm 2mm 3mm; display: flex; flex-direction: column; justify-content: space-between; }
.lbl .proj { font-size: 2.45mm; font-weight: 700; text-transform: uppercase; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lbl .comp { font-size: 3.2mm; font-weight: 500; line-height: 1.15; max-height: 7.4mm; overflow: hidden; }
.lbl .code { font-weight: 800; line-height: 1; letter-spacing: -.1mm; white-space: nowrap; }
.lbl .note { font-size: 2.6mm; color: #222; line-height: 1.2; max-height: 6mm; overflow: hidden; }
.lbl .qr { width: 33mm; flex: none; display: grid; align-content: center; justify-items: center; gap: 1mm; padding: 2mm 2mm 2mm 0; }
.lbl .qr svg { width: 29mm; height: 29mm; display: block; }
.lbl .qr .id { font-size: 3mm; font-weight: 800; letter-spacing: .3mm; font-family: ui-monospace, Menlo, Consolas, monospace; }

@media print {
  @page { size: A4; margin: 8mm; }
  html, body { background: #fff !important; height: auto; }
  #app, .toast { display: none !important; }
  #print-root { display: block !important; }
  #print-root .sheet-page { display: grid; grid-template-columns: 92mm 92mm; grid-auto-rows: 45mm; gap: 0 4mm; row-gap: 2mm; justify-content: center; break-after: page; }
  #print-root .sheet-page:last-child { break-after: auto; }
  .lbl { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
@media (min-width: 640px) { .tiles { grid-template-columns: repeat(5, 1fr); } .tiles .tile:first-child { grid-column: auto; } }
