:root {
  --bg: #f4f5f7; --card: #ffffff; --text: #111827; --muted: #4b5563; --line: #d1d5db;
  --primary: #1d4ed8; --primary-text: #ffffff; --accent: #b45309;
  --ok: #166534; --ok-bg: #dcfce7; --soon: #854d0e; --soon-bg: #fef08a; --over: #991b1b; --over-bg: #fecaca;
  --none: #374151; --none-bg: #e5e7eb; --danger: #b91c1c;
  --radius: 16px; --tap: 56px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220; --card: #172033; --text: #f3f4f6; --muted: #aab4c3; --line: #2c3a52;
    --primary: #3b82f6; --primary-text: #ffffff; --accent: #fbbf24;
    --ok: #86efac; --ok-bg: #14532d; --soon: #fde68a; --soon-bg: #713f12; --over: #fecaca; --over-bg: #7f1d1d;
    --none: #d1d5db; --none-bg: #374151; --danger: #f87171;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 18px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
a { color: var(--primary); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.app-header {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
  background: var(--bg); padding: calc(8px + env(safe-area-inset-top)) 12px 8px; border-bottom: 1px solid var(--line);
  min-height: 64px;
}
.app-header h1 { font-size: 1.3rem; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  min-width: var(--tap); min-height: var(--tap); border: 0; border-radius: 14px; background: transparent;
  color: var(--text); font-size: 1.6rem; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:active { background: var(--line); }
main { padding: 12px 14px 24px; max-width: 640px; margin: 0 auto; outline: none; }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; min-height: 64px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-decoration: none; color: var(--muted); font-size: .85rem; font-weight: 600; gap: 2px;
}
.tabbar a.active { color: var(--primary); }
.tabbar .ti { font-size: 1.4rem; }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: var(--tap);
  padding: 12px 16px; border-radius: 14px; border: 2px solid var(--line); background: var(--card); color: var(--text);
  font: inherit; font-weight: 700; cursor: pointer; text-decoration: none; text-align: center;
}
.btn:active { filter: brightness(.9); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.big { min-height: 84px; font-size: 1.35rem; border-radius: 18px; }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.small { width: auto; min-height: 48px; padding: 8px 14px; }
.btn[disabled] { opacity: .5; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.stack > * + * { margin-top: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.muted { color: var(--muted); }
.small { font-size: .9rem; }
.center { text-align: center; }
.note { font-size: .9rem; color: var(--muted); padding: 10px 12px; border-left: 4px solid var(--accent); background: var(--card); border-radius: 8px; }

/* list */
.item {
  display: flex; gap: 12px; align-items: center; text-decoration: none; color: inherit;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; min-height: 84px;
}
.item:active { filter: brightness(.92); }
.item .ico { font-size: 2rem; width: 44px; text-align: center; }
.item .main { flex: 1; min-width: 0; }
.item .name { font-weight: 700; font-size: 1.15rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .dates { font-size: .92rem; color: var(--muted); }
.badge {
  display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: .85rem; font-weight: 800; white-space: nowrap;
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.soon { background: var(--soon-bg); color: var(--soon); }
.badge.over { background: var(--over-bg); color: var(--over); }
.badge.none { background: var(--none-bg); color: var(--none); }
.list-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 4px 0 14px; }
.empty { text-align: center; padding: 28px 8px; }
.empty .big-ico { font-size: 3.5rem; }

/* item screen */
.date-card .label { font-size: 1rem; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.date-card .big { font-size: 1.75rem; font-weight: 800; line-height: 1.2; margin-top: 2px; }
.date-card .rel { font-size: 1.2rem; font-weight: 600; margin-top: 2px; }
.date-card.status-over { border-color: var(--danger); border-width: 2px; }
.hist { list-style: none; margin: 0; padding: 0; }
.hist li { padding: 10px 0; border-top: 1px solid var(--line); }
.hist li:first-child { border-top: 0; }
.hist .h1 { font-weight: 700; }
.hist .h2 { color: var(--muted); font-size: .92rem; }
h2.section { font-size: 1.05rem; margin: 18px 2px 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* forms */
label { display: block; font-weight: 700; margin: 12px 0 4px; }
input[type=text], input[type=date], input[type=number], input[type=url], select, textarea {
  width: 100%; min-height: var(--tap); font: inherit; padding: 10px 12px; border: 2px solid var(--line); border-radius: 12px;
  background: var(--bg); color: var(--text);
}
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chip { min-height: 44px; padding: 6px 14px; border-radius: 999px; border: 2px solid var(--line); background: var(--card); color: var(--text); font: inherit; font-weight: 700; cursor: pointer; }
.err { color: var(--danger); font-weight: 700; margin: 8px 0 0; }

dialog {
  width: min(94vw, 480px); border: 0; border-radius: 20px; padding: 18px; background: var(--card); color: var(--text);
  box-shadow: 0 10px 40px rgba(0,0,0,.45);
}
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h2 { margin-bottom: 4px; }
dialog .row { margin-top: 16px; }

/* scanner */
.viewfinder { position: relative; border-radius: var(--radius); overflow: hidden; background: #000; aspect-ratio: 3/4; }
.viewfinder video { width: 100%; height: 100%; object-fit: cover; display: block; }
.viewfinder .frame { position: absolute; inset: 18% 14%; border: 4px solid rgba(255,255,255,.9); border-radius: 18px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); pointer-events: none; }
.viewfinder .msg { position: absolute; left: 0; right: 0; bottom: 0; padding: 10px; text-align: center; background: rgba(0,0,0,.65); color: #fff; font-weight: 600; }

/* sticker */
.sticker-wrap { display: flex; justify-content: center; }
.sticker {
  background: #fff; color: #000; padding: 4%; text-align: center; border: 2px dashed #9ca3af; border-radius: 6px;
  width: min(100%, 340px); font-size: 17px;
}
.sticker svg { width: 100%; height: auto; display: block; }
.sticker .s-name { font-weight: 800; font-size: 1.2em; line-height: 1.15; margin-top: 4%; word-break: break-word; }
.sticker .s-id { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 1em; letter-spacing: .08em; margin-top: 2%; }
.sticker .s-sub { font-size: .65em; color: #374151; margin-top: 2%; }
.seg { display: flex; gap: 8px; }
.seg button { flex: 1; }
.seg button[aria-pressed=true] { background: var(--primary); border-color: var(--primary); color: #fff; }

.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: #111827; color: #fff; padding: 12px 18px; border-radius: 999px; font-weight: 700; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; z-index: 50; max-width: 92vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; word-break: break-all; }

/* print: only the sticker, at a physical size */
@page { margin: 0.4in; }
@media print {
  .no-print, .app-header, .tabbar, .toast { display: none !important; }
  body { background: #fff; padding: 0; }
  main { padding: 0; max-width: none; }
  .print-hide { display: none !important; }
  .sticker-wrap { display: block; }
  .sticker { border: 0.5pt dashed #888; border-radius: 0; width: 3in; font-size: 14pt; break-inside: avoid; }
  .sticker[data-size="2"] { width: 2in; font-size: 9.5pt; }
  .sticker[data-size="3"] { width: 3in; font-size: 14pt; }
}

/* v2: sticker type header, quick-add, mileage */
.sticker .s-type {
  font-weight: 900; font-size: 1.15em; letter-spacing: .06em; text-align: center; line-height: 1.1;
  padding: 0 0 3% 0; margin-bottom: 3%; border-bottom: 3px solid #000;
}
.sticker .s-type .s-ico { font-size: 1.1em; }
#mileage-card .row { align-items: stretch; }
#mileage-card input { flex: 1 1 auto; min-width: 0; }
.chips + label { margin-top: 12px; }

/* v3: boxes / drawer contents */
.sticker .s-type { white-space: nowrap; }
.sticker .s-type .lbl-short { display: none; }
.sticker .s-type.has-short .lbl-long.tight { font-size: .8em; letter-spacing: 0; }
.sticker[data-size="2"] .s-type.has-short .lbl-long { display: none; }
.sticker[data-size="2"] .s-type.has-short .lbl-short { display: inline; }
input[type=search] {
  width: 100%; min-height: var(--tap); font: inherit; padding: 10px 12px; border: 2px solid var(--line); border-radius: 12px; background: var(--card); color: var(--text);
}
.box-loc { font-size: 1.15rem; font-weight: 700; }
.box-counts { font-size: 1.6rem; font-weight: 800; margin-top: 4px; }
.qa-row { display: flex; gap: 8px; }
.qa-row #qa-name { flex: 1 1 auto; min-width: 0; }
.qa-row #qa-qty { flex: 0 0 76px; width: 76px; text-align: center; }
.qa-row .btn { flex: 0 0 auto; width: auto; min-width: 84px; }
.clist { list-style: none; margin: 0; padding: 0; }
.cline { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); min-height: 64px; }
.cline:first-child { border-top: 0; }
.cl-main { flex: 1; min-width: 0; cursor: pointer; padding: 4px 0; }
.cl-name { font-weight: 700; font-size: 1.1rem; word-break: break-word; }
.cl-qty { font-weight: 800; color: var(--primary); margin-left: 4px; }
.cl-note { color: var(--muted); font-size: .9rem; word-break: break-word; }
.cl-toggle { min-width: 64px; min-height: 48px; border-radius: 12px; border: 2px solid var(--line); background: var(--bg); color: var(--text); font: inherit; font-weight: 800; cursor: pointer; }
.cl-toggle[aria-pressed=true] { background: var(--soon-bg); color: var(--soon); border-color: var(--soon); }
.cline.out .cl-name { text-decoration: line-through; opacity: .7; }
.cl-del { min-width: 48px; min-height: 48px; border-radius: 12px; border: 0; background: transparent; color: var(--danger); font-size: 1.3rem; cursor: pointer; }
.cl-del:active { background: var(--line); }
label.chk { display: flex; align-items: center; gap: 10px; min-height: var(--tap); }
label.chk input { width: 26px; height: 26px; }
#box-photo { width: 100%; max-height: 360px; object-fit: contain; border-radius: 12px; background: #000; }
.section-in { font-size: 1.05rem; }
.hits { list-style: none; margin: 6px 0 0; padding: 0; font-size: .95rem; }
.hits .hit { padding: 1px 0; }
.out-tag { color: var(--soon); background: var(--soon-bg); border-radius: 6px; padding: 0 5px; font-size: .75rem; }
.item { flex-wrap: nowrap; }
.printsheet { background: #fff; color: #000; border-radius: 8px; padding: 16px; border: 1px solid var(--line); }
.ps-title { font-size: 1.6rem; margin: 0 0 4px; }
.ps-loc { font-weight: 700; }
.ps-meta { color: #444; font-size: .9rem; margin-bottom: 10px; }
.ps-table { width: 100%; border-collapse: collapse; }
.ps-table th { text-align: left; border-bottom: 2px solid #000; font-size: .85rem; padding: 4px 6px; }
.ps-table td { border-bottom: 1px solid #bbb; padding: 7px 6px; vertical-align: top; }
.ps-chk { width: 2.2em; font-size: 1.2em; }
.ps-qty { width: 2.5em; font-weight: 700; }
.ps-out td { color: #666; text-decoration: line-through; }
@media print {
  .printsheet { border: 0; padding: 0; border-radius: 0; font-size: 12pt; }
  .ps-title { font-size: 20pt; }
  .ps-table tr { break-inside: avoid; }
}

/* make the [hidden] attribute always win over component display rules (.btn etc.) */
[hidden] { display: none !important; }
