:root {
  --bg: #f3f5f4;
  --card: #ffffff;
  --ink: #17211d;
  --muted: #65736d;
  --line: #dfe5e2;
  --field: #f7f9f8;
  --brand: #0f5d4a;
  --brand-ink: #ffffff;
  --brand-soft: #e3f1ec;
  --good: #0c7a43;
  --good-soft: #e2f4ea;
  --bad: #c0362c;
  --bad-soft: #fbe9e7;
  --warn: #9a6200;
  --warn-soft: #fdf2d8;
  --radius: 14px;
  --nav-h: 58px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111615;
    --card: #1b2220;
    --ink: #e9efec;
    --muted: #98a6a0;
    --line: #2d3734;
    --field: #232c29;
    --brand: #2fa585;
    --brand-ink: #06241c;
    --brand-soft: #1d3530;
    --good: #55c98a;
    --good-soft: #17352a;
    --bad: #f0786d;
    --bad-soft: #3b201d;
    --warn: #e6b450;
    --warn-soft: #3a2f16;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 96px);
}

button, input, select, textarea { font: inherit; color: inherit; }

.top {
  background: var(--brand);
  color: var(--brand-ink);
  padding: 14px 16px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.top h1 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.top-sub { font-size: 13px; opacity: 0.85; white-space: nowrap; }

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

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}
.card > h2 {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.hint { color: var(--muted); font-size: 13px; margin: 8px 0 0; }
.notice {
  background: var(--warn-soft);
  color: var(--warn);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 14px;
  margin: 10px 0 0;
}

/* ---------- fields ---------- */

label.f { display: block; min-width: 0; }
label.f > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }

input[type="text"], input[type="date"], input[type="password"], select, textarea {
  width: 100%;
  min-width: 0;
  height: 46px;
  padding: 0 12px;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
}
textarea { height: auto; min-height: 70px; padding: 10px 12px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
input.num { text-align: right; font-weight: 600; }
input[readonly] { background: transparent; border-style: dashed; }
input.bad { border-color: var(--bad); background: var(--bad-soft); }
input.unsure { border-color: var(--warn); background: var(--warn-soft); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  font-weight: 600;
  cursor: pointer;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.soft { background: var(--brand-soft); border-color: transparent; color: var(--brand); }
.btn.danger { color: var(--bad); }
.btn.block { width: 100%; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn svg { width: 20px; height: 20px; flex: none; }
.icon-btn {
  width: 34px; height: 34px; border: 0; background: transparent; color: var(--muted);
  border-radius: 8px; font-size: 20px; line-height: 1; cursor: pointer; flex: none;
}
.icon-btn:hover { background: var(--field); color: var(--bad); }
.row-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }

/* ---------- nozzle lines ---------- */

.line { border-top: 1px solid var(--line); padding: 12px 0; }
.line:first-of-type { border-top: 0; padding-top: 0; }
.line-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.line-head b { font-size: 16px; white-space: nowrap; }
.line-head select { height: 36px; width: auto; flex: 1; min-width: 0; padding: 0 8px; }
.line-out { display: flex; justify-content: space-between; margin-top: 8px; font-size: 14px; color: var(--muted); }
.line-out strong { color: var(--ink); }
.line-out .err { color: var(--bad); font-weight: 600; }

/* ---------- cash table ---------- */

.cash { display: grid; grid-template-columns: 56px minmax(0, 96px) 1fr; gap: 8px 10px; align-items: center; }
.cash .den { font-weight: 600; }
.cash .amt { text-align: right; color: var(--muted); font-size: 15px; }
.cash input { height: 42px; }
.stack { display: grid; gap: 10px; margin-top: 12px; }

/* ---------- summary ---------- */

.sum-row { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; }
.sum-row span:first-child { color: var(--muted); }
.sum-row.total { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 12px; font-weight: 700; }
.sum-row.total span:first-child { color: var(--ink); }
.diff-box { margin-top: 12px; border-radius: 12px; padding: 14px; text-align: center; background: var(--field); }
.diff-box .lbl { font-size: 13px; color: var(--muted); letter-spacing: 0.04em; text-transform: uppercase; }
.diff-box .val { font-size: 30px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.2; }
.diff-box.good { background: var(--good-soft); }
.diff-box.good .val { color: var(--good); }
.diff-box.bad { background: var(--bad-soft); }
.diff-box.bad .val { color: var(--bad); }

.photos { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.photos a { display: block; width: 64px; height: 64px; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); }
.photos img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ---------- sticky save bar ---------- */

.savebar {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
  background: var(--card);
  border-top: 1px solid var(--line);
  padding: 10px 16px;
  z-index: 5;
}
.savebar-in { max-width: 568px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
.savebar .mini { flex: 1; min-width: 0; }
.savebar .mini small { display: block; color: var(--muted); font-size: 12px; }
.savebar .mini b { font-size: 18px; white-space: nowrap; }
.savebar .mini b.good { color: var(--good); }
.savebar .mini b.bad { color: var(--bad); }

/* ---------- bottom tabs ---------- */

.tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card);
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  z-index: 6;
}
.tabs[hidden] { display: none; }
.tabs button { border: 0; background: transparent; font-weight: 600; color: var(--muted); cursor: pointer; }
.tabs button.on { color: var(--brand); box-shadow: inset 0 3px 0 var(--brand); }

/* ---------- history ---------- */

.day { margin-bottom: 16px; }
.day-head { display: flex; justify-content: space-between; align-items: baseline; padding: 0 4px 6px; font-size: 14px; color: var(--muted); }
.day-head b { color: var(--ink); font-size: 15px; }
.shift-item {
  width: 100%; text-align: left; display: block; cursor: pointer;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 8px;
}
.shift-item .r1 { display: flex; justify-content: space-between; gap: 10px; font-weight: 700; }
.shift-item .r2 { display: flex; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 14px; margin-top: 4px; }
.pill { border-radius: 999px; padding: 2px 10px; font-size: 14px; font-weight: 700; white-space: nowrap; }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.zero { background: var(--field); color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }

/* ---------- settings ---------- */

.set-row { display: grid; grid-template-columns: 1fr 120px 34px; gap: 8px; align-items: center; margin-bottom: 8px; }
.set-row.nz { grid-template-columns: 90px 1fr 34px; }

/* ---------- modal & toast ---------- */

.modal {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(0, 0, 0, 0.5);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal[hidden] { display: none; }
.sheet {
  background: var(--card);
  width: 100%; max-width: 600px; max-height: 92vh; overflow: auto;
  border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
}
.sheet h3 { margin: 0 0 4px; font-size: 18px; }
.sheet .shot { width: 100%; max-height: 240px; object-fit: contain; background: #000; border-radius: 10px; margin: 12px 0 10px; display: block; }
.read-row { display: grid; grid-template-columns: 74px 1fr 34px; gap: 8px; align-items: end; margin-bottom: 8px; }
.sheet-actions { display: grid; grid-template-columns: 1fr 2fr; gap: 10px; margin-top: 14px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 86px);
  background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 600;
  z-index: 30; max-width: calc(100vw - 32px); text-align: center;
}
.toast[hidden] { display: none; }

.login { max-width: 340px; margin: 12vh auto 0; text-align: center; }
.login input { text-align: center; font-size: 22px; letter-spacing: 0.3em; margin: 14px 0; }

.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2.5px solid currentColor; border-right-color: transparent;
  animation: spin 0.7s linear infinite; flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } }
