/* ZODML Fieldwork – shared styles for the phone app and supervisor page.
   Layout: one narrow column on phones (thumb-first, big tap targets), wider grid on the supervisor page.
   System fonts on purpose: the app must work offline on low-cost Android phones, so no web fonts. */
:root {
  --bg: #f3f5f4;
  --card: #ffffff;
  --ink: #15232b;
  --muted: #59686f;
  --line: #d6dddd;
  --primary: #0d5c5a;
  --primary-ink: #ffffff;
  --primary-soft: #dcecea;
  --accent: #f0b400;
  --good: #1d7a43;
  --good-soft: #def2e5;
  --warn: #9a5b00;
  --warn-soft: #fbedd3;
  --bad: #b3261e;
  --bad-soft: #f9dedc;
  --band-red: #c62828;
  --band-yellow: #f2c200;
  --band-blue: #1565c0;
  --band-green: #2e7d32;
  --shadow: 0 1px 2px rgba(15, 35, 43, .08), 0 4px 14px rgba(15, 35, 43, .06);
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Roboto Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1719; --card: #172327; --ink: #e6eeee; --muted: #9db0b3; --line: #2b3b40;
    --primary: #4fb3ac; --primary-ink: #06201f; --primary-soft: #183836; --accent: #f5c33b;
    --good: #5cc98a; --good-soft: #173826; --warn: #f0b25a; --warn-soft: #3a2a12; --bad: #f2867f; --bad-soft: #3d1a18;
    --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 16px/1.45 var(--font); -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
h1, h2, h3 { line-height: 1.2; margin: 0; text-wrap: balance; }
h1 { font-size: 1.35rem; } h2 { font-size: 1.12rem; } h3 { font-size: 1rem; }
p { margin: 0; }
a { color: var(--primary); }
small, .muted { color: var(--muted); }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.num { font-variant-numeric: tabular-nums; }

.wrap { max-width: 640px; margin: 0 auto; padding: 12px max(16px, env(safe-area-inset-left)) 96px max(16px, env(safe-area-inset-right)); display: grid; gap: 14px; }
.topbar { position: sticky; top: 0; z-index: 20; background: var(--primary); color: var(--primary-ink);
  padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  display: flex; align-items: center; gap: 10px; }
.topbar h1 { font-size: 1.05rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .back { background: none; border: 0; color: inherit; font-size: 1.5rem; padding: 0 8px 0 0; cursor: pointer; line-height: 1; }
.topbar .pill { background: rgba(255,255,255,.16); color: inherit; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; gap: 10px; box-shadow: var(--shadow); }
.card.flat { box-shadow: none; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 0; }
.stack { display: grid; gap: 8px; }
.label { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }

button, .btn { font: inherit; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  min-height: 46px; padding: 10px 16px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; font-weight: 600; }
button:focus-visible, .btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }
.btn-primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn-danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--primary); }
.btn-block { width: 100%; }
button:disabled { opacity: .5; cursor: default; }
.btn-small { min-height: 36px; padding: 6px 12px; font-size: .9rem; }

input, select, textarea { font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; width: 100%; min-height: 46px; }
textarea { min-height: 84px; resize: vertical; }
.field { display: grid; gap: 6px; }
.field > span { font-weight: 600; font-size: .95rem; }
.field .req { color: var(--bad); }
.invalid input, .invalid .seg, .invalid select { border-color: var(--bad); box-shadow: 0 0 0 1px var(--bad); }

/* segmented choices / chips */
.seg { display: flex; flex-wrap: wrap; gap: 6px; border-radius: 10px; }
.chip { min-height: 40px; padding: 8px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); font-weight: 600; font-size: .92rem; }
.chip[aria-pressed="true"] { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.chip.band { padding-left: 10px; }
.chip.band::before { content: ""; width: 12px; height: 12px; border-radius: 50%; background: var(--c, var(--line)); display: inline-block; border: 1px solid rgba(0,0,0,.15); }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: .8rem; font-weight: 700; background: var(--primary-soft); color: var(--primary); white-space: nowrap; }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }

/* home tiles */
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.tile { text-align: left; display: grid; justify-content: stretch; gap: 4px; align-content: start; justify-items: start; min-height: 96px; padding: 14px; border-radius: var(--radius); background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow); }
.tile b { font-size: 1rem; }
.tile small { font-weight: 500; }
.tile.hero { grid-column: 1 / -1; background: var(--primary); color: var(--primary-ink); border-color: var(--primary); min-height: 84px; }
.tile.hero small { color: inherit; opacity: .85; }
.tile .code { font-family: var(--mono); font-size: .78rem; opacity: .7; }

/* sync bar */
.sync { display: flex; align-items: center; gap: 10px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--good); flex: none; }
.dot.wait { background: var(--accent); } .dot.off { background: var(--muted); } .dot.err { background: var(--bad); }

/* scanner */
.scanner { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 4 / 3; max-height: 46vh; width: 100%; }
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanner .frame { position: absolute; left: 10%; right: 10%; top: 30%; bottom: 30%; border: 3px solid var(--accent); border-radius: 10px; box-shadow: 0 0 0 2000px rgba(0,0,0,.28); pointer-events: none; }
.scanner .frame.photo { top: 6%; bottom: 6%; left: 8%; right: 8%; border-style: dashed; }
.scanner .hint { position: absolute; left: 0; right: 0; bottom: 8px; text-align: center; color: #fff; font-size: .9rem; text-shadow: 0 1px 2px #000; padding: 0 12px; }
.scanner .cam-tools { position: absolute; top: 8px; right: 8px; display: flex; gap: 6px; }
.scanner .cam-tools button { min-height: 38px; background: rgba(0,0,0,.5); color: #fff; border-color: rgba(255,255,255,.3); padding: 6px 10px; }
.scanner .msg { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; text-align: center; padding: 20px; }
.shutter { width: 72px; height: 72px; border-radius: 50%; border: 5px solid #fff; background: var(--accent); position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); padding: 0; min-height: 0; }

.counter { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.counter div { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.counter b { display: block; font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.counter small { font-size: .78rem; }

.stepper { display: flex; align-items: center; gap: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--card); }
.stepper button { border: 0; border-radius: 0; min-width: 46px; font-size: 1.3rem; }
.stepper input { border: 0; border-radius: 0; text-align: center; width: 64px; font-weight: 700; padding: 8px 4px; }

/* lists */
.list { display: grid; gap: 0; }
.item { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); background: none; border-left: 0; border-right: 0; border-bottom: 0; border-radius: 0; text-align: left; min-height: 56px; width: 100%; font-weight: 400; }
.item:first-child { border-top: 0; }
.item .thumb { width: 38px; height: 52px; border-radius: 4px; background: var(--primary-soft); flex: none; object-fit: cover; display: grid; place-items: center; font-size: .65rem; color: var(--muted); }
.item .txt { flex: 1; min-width: 0; display: grid; }
.item .txt b, .item .txt small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* sheet (bottom drawer) */
.sheet-back { position: fixed; inset: 0; background: rgba(5, 15, 18, .45); z-index: 40; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-height: 92vh; overflow-y: auto; background: var(--bg); border-radius: 18px 18px 0 0;
  padding: 14px max(16px, env(safe-area-inset-left)) calc(16px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-right)); display: grid; gap: 12px; box-shadow: 0 -8px 30px rgba(0,0,0,.25); }
.sheet .inner { max-width: 640px; margin: 0 auto; width: 100%; min-width: 0; display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }
.sheet .pill, .bookhead .pill { white-space: normal; }
.bookhead .grow > * { overflow-wrap: anywhere; }
.sheet .grab { width: 44px; height: 5px; background: var(--line); border-radius: 3px; margin: 0 auto; }
.bookhead { display: flex; gap: 12px; align-items: flex-start; }
.bookhead img, .bookhead .nocover { width: 64px; height: 92px; object-fit: cover; border-radius: 6px; background: var(--primary-soft); flex: none; display: grid; place-items: center; font-size: .7rem; color: var(--muted); text-align: center; }
.bookhead .grow { flex: 1; min-width: 0; display: grid; gap: 4px; }
.sticky-actions { position: sticky; bottom: calc(-16px - env(safe-area-inset-bottom)); background: var(--bg); padding: 10px 0 calc(6px + env(safe-area-inset-bottom)); display: flex; gap: 10px; border-top: 1px solid var(--line); }
.sticky-actions > * { flex: 1; }
details > summary { cursor: pointer; font-weight: 600; color: var(--primary); padding: 6px 0; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: "+ "; }
details[open] > summary::before { content: "– "; }
.photo-prev { width: 100%; max-height: 220px; object-fit: contain; background: #000; border-radius: 8px; }

.toast { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 12px; z-index: 60; font-weight: 600; max-width: calc(100% - 32px); box-shadow: var(--shadow); }
.toast.bad { background: var(--bad); color: #fff; }
.notice { padding: 10px 12px; border-radius: 10px; background: var(--primary-soft); color: var(--ink); font-size: .93rem; }
.notice.warn { background: var(--warn-soft); }
.notice.bad { background: var(--bad-soft); }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px max(16px, env(safe-area-inset-left)); }
.login .card { width: 100%; max-width: 380px; padding: 22px; gap: 16px; }
.pin { font-size: 1.8rem; letter-spacing: .4em; text-align: center; font-family: var(--mono); }
.brand { display: flex; gap: 10px; align-items: center; }
.brand .mark { width: 40px; height: 40px; border-radius: 10px; background: var(--primary); color: var(--primary-ink); display: grid; place-items: center; font-weight: 800; font-size: .8rem; letter-spacing: .02em; }

@media (prefers-reduced-motion: no-preference) {
  .sheet { animation: up .18s ease-out; }
  @keyframes up { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
}
.scanner .frame.photo ~ .hint { top: 10px; bottom: auto; right: 90px; text-align: left; }
