:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #111827;
  --muted: #5b6472;
  --border: #d5d9e0;
  --primary: #1f5fd1;
  --primary-text: #ffffff;
  --danger: #c62828;
  --danger-soft: #fde8e8;
  --ok: #1b7f3b;
  --ok-soft: #e3f4e8;
  --warn: #a45f00;
  --warn-soft: #fff2db;
  --chip-on: #1f5fd1;
  --bar: #1f5fd1;
  --top: #1f2a37;
  --top-text: #ffffff;
  --radius: 14px;
  --tap: 56px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141a; --surface: #182029; --surface-2: #212b36; --text: #e8edf3; --muted: #9aa5b3;
    --border: #2e3a47; --primary: #4c8dff; --primary-text: #08111f; --danger: #ff6b6b; --danger-soft: #3a1c1f;
    --ok: #4cc777; --ok-soft: #15301f; --warn: #ffb547; --warn-soft: #36290f; --chip-on: #4c8dff; --bar: #4c8dff;
    --top: #0b1016; --top-text: #e8edf3; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f141a; --surface: #182029; --surface-2: #212b36; --text: #e8edf3; --muted: #9aa5b3;
  --border: #2e3a47; --primary: #4c8dff; --primary-text: #08111f; --danger: #ff6b6b; --danger-soft: #3a1c1f;
  --ok: #4cc777; --ok-soft: #15301f; --warn: #ffb547; --warn-soft: #36290f; --chip-on: #4c8dff; --bar: #4c8dff;
  --top: #0b1016; --top-text: #e8edf3; color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(68px + env(safe-area-inset-bottom));
  overscroll-behavior-y: contain;
}
button, input, select, textarea { font: inherit; color: inherit; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  background: var(--top); color: var(--top-text);
}
.topbar h1 { flex: 1; margin: 0; font-size: 19px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { background: none; border: 0; color: inherit; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 10px; }
.sync-pill {
  display: flex; align-items: center; gap: 6px; border: 0; border-radius: 999px;
  padding: 6px 12px; background: rgba(255,255,255,.12); color: inherit; font-size: 14px; font-weight: 600;
}
.sync-pill .dot { width: 9px; height: 9px; border-radius: 50%; background: #9aa5b3; }
.sync-pill.ok .dot { background: #4cc777; }
.sync-pill.pending .dot { background: #ffb547; }
.sync-pill.offline .dot { background: #ff6b6b; }

main { padding: 14px 16px 24px; max-width: 720px; margin: 0 auto; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 10px; color: var(--muted); text-decoration: none; font-size: 12px; font-weight: 600;
}
.tabbar svg { width: 24px; height: 24px; }
.tabbar a.active { color: var(--primary); }

h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 22px 0 8px; }
h2:first-child { margin-top: 4px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.stack > * + * { margin-top: 10px; }
.row { display: flex; gap: 10px; align-items: center; }
.row > .grow { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.center { text-align: center; }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); width: 100%; padding: 0 18px;
  border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface); font-weight: 650; font-size: 17px; cursor: pointer;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.big { min-height: 72px; font-size: 19px; }
.btn.slim { min-height: 44px; font-size: 15px; width: auto; }
.btn svg { width: 24px; height: 24px; flex: none; }
.btn[disabled] { opacity: .5; }

label.field { display: block; }
label.field > span { display: block; font-size: 14px; color: var(--muted); margin: 0 0 4px 2px; font-weight: 600; }
input.input, textarea.input, select.input {
  width: 100%; min-height: 50px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface-2); font-size: 17px;
}
textarea.input { min-height: 80px; resize: vertical; }
input.input:focus, textarea.input:focus { outline: 2px solid var(--primary); outline-offset: 1px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 48px; padding: 8px 14px; border-radius: 999px; border: 2px solid var(--border);
  background: var(--surface); font-weight: 600; font-size: 16px;
}
.chip.on { background: var(--chip-on); border-color: var(--chip-on); color: var(--primary-text); }
.seg { display: flex; gap: 8px; }
.seg .chip { flex: 1; border-radius: 12px; }
.seg .chip.on.low { background: var(--ok); border-color: var(--ok); color: #fff; }
.seg .chip.on.medium { background: var(--warn); border-color: var(--warn); color: #fff; }
.seg .chip.on.high { background: var(--danger); border-color: var(--danger); color: #fff; }
.seg .chip.on.match { background: var(--ok); border-color: var(--ok); color: #fff; }
.seg .chip.on.mismatch { background: var(--danger); border-color: var(--danger); color: #fff; }

.list { display: flex; flex-direction: column; gap: 10px; }
.item {
  display: block; text-decoration: none; color: inherit;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px;
}
.item .t { font-weight: 650; font-size: 17px; }
.item .s { color: var(--muted); font-size: 14px; margin-top: 2px; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.badge { font-size: 13px; font-weight: 650; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }

.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.thumb { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--surface-2); border: 1px solid var(--border); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .x {
  position: absolute; top: 4px; right: 4px; width: 30px; height: 30px; border-radius: 50%;
  border: 0; background: rgba(0,0,0,.6); color: #fff; font-size: 18px; line-height: 1;
}
.thumb .pending { position: absolute; left: 4px; bottom: 4px; width: 10px; height: 10px; border-radius: 50%; background: #ffb547; box-shadow: 0 0 0 2px #0006; }
.add-thumb { display: grid; place-items: center; aspect-ratio: 1; border-radius: 10px; border: 2px dashed var(--border); background: none; color: var(--muted); font-weight: 650; font-size: 14px; }

.label-shot { width: 100%; max-height: 220px; object-fit: contain; border-radius: 12px; background: var(--surface-2); display: block; }

.issue-card { border-left: 5px solid var(--danger); }
.issue-card.low { border-left-color: var(--ok); }
.issue-card.medium { border-left-color: var(--warn); }

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.tile .v { font-size: 28px; font-weight: 750; font-variant-numeric: tabular-nums; }
.tile .l { font-size: 13px; color: var(--muted); font-weight: 600; }
.bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row .lbl { display: flex; justify-content: space-between; font-size: 15px; margin-bottom: 4px; gap: 8px; }
.bar-row .lbl b { font-variant-numeric: tabular-nums; }
.bar-track { height: 10px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--bar); border-radius: 6px; }

.pin-wrap { max-width: 340px; margin: 6vh auto 0; text-align: center; }
.pin-dots { display: flex; justify-content: center; gap: 14px; margin: 18px 0 24px; }
.pin-dots i { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--muted); }
.pin-dots i.on { background: var(--text); border-color: var(--text); }
.pinpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.pinpad button { height: 68px; border-radius: 16px; border: 1px solid var(--border); background: var(--surface); font-size: 26px; font-weight: 600; }

.sticky-actions { position: sticky; bottom: calc(76px + env(safe-area-inset-bottom)); margin-top: 16px; }

.lightbox { position: fixed; inset: 0; background: #000e; z-index: 50; display: grid; place-items: center; padding: 12px; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }

#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: 12px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 60; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.empty { text-align: center; color: var(--muted); padding: 28px 8px; }
.type-edit { display: flex; gap: 6px; align-items: center; }
.type-edit input.input { min-height: 46px; }
.type-edit .icon-btn { color: var(--muted); width: 40px; height: 40px; border: 1px solid var(--border); background: var(--surface); }
.type-edit.off input { text-decoration: line-through; opacity: .6; }
