:root {
  --bg: #FBF7F2;
  --surface: #FFFFFF;
  --ink: #2B2118;
  --muted: #7A6B5D;
  --line: #E8DED2;
  --brand: #C2410C;
  --brand-ink: #FFFFFF;
  --brand-soft: #FDEBDD;
  --ok: #2F7D4F;
  --ok-soft: #E4F4EA;
  --warn: #9A6700;
  --warn-soft: #FFF3CC;
  --bad: #B42318;
  --bad-soft: #FDE7E4;
  --chip: #F3E9DD;
  --shadow: 0 1px 2px rgba(43, 33, 24, .08), 0 4px 12px rgba(43, 33, 24, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17120E; --surface: #221B15; --ink: #F3EBE2; --muted: #A8998A; --line: #3A2F26;
    --brand: #F0743A; --brand-ink: #1A0F08; --brand-soft: #3A2316;
    --ok: #5CC48A; --ok-soft: #173225; --warn: #E3B341; --warn-soft: #3A2E10;
    --bad: #F07167; --bad-soft: #3B1A17; --chip: #2E251D;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #17120E; --surface: #221B15; --ink: #F3EBE2; --muted: #A8998A; --line: #3A2F26;
  --brand: #F0743A; --brand-ink: #1A0F08; --brand-soft: #3A2316;
  --ok: #5CC48A; --ok-soft: #173225; --warn: #E3B341; --warn-soft: #3A2E10;
  --bad: #F07167; --bad-soft: #3B1A17; --chip: #2E251D;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
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, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
  padding-bottom: calc(68px + env(safe-area-inset-bottom));
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }

.top {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  padding: calc(12px + env(safe-area-inset-top)) 16px 10px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  border-bottom: 1px solid var(--line);
}
.top h1 { font-size: 22px; letter-spacing: -.01em; }
.top-extra { color: var(--muted); font-size: 14px; text-align: right; }

main { padding: 16px; max-width: 640px; margin: 0 auto; }
.loading { color: var(--muted); text-align: center; padding: 48px 0; }

/* bottom nav */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  flex: 1; border: 0; background: none; padding: 8px 2px 7px; min-height: 56px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--muted); font-size: 11.5px; cursor: pointer;
}
.tabs button svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round; }
.tabs button[aria-current="page"] { color: var(--brand); font-weight: 600; }

/* controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); font-weight: 600; cursor: pointer;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.danger { color: var(--bad); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn.block { display: flex; width: 100%; }
.btn[disabled] { opacity: .5; cursor: default; }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%; min-height: 46px; padding: 8px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface);
}
.field input:focus, .field select:focus, .field textarea:focus, .btn:focus-visible, .tabs button:focus-visible,
.chip:focus-visible, .card.tap:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 1px;
}
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.spacer { height: 12px; }

/* cards & chips */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 14px; box-shadow: var(--shadow);
}
.card.tap { cursor: pointer; width: 100%; text-align: left; display: block; }
.card + .card { margin-top: 10px; }
.card h3 { font-size: 16px; line-height: 1.3; }
.card .meta { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px;
  background: var(--chip); font-size: 13px; border: 0; color: var(--ink);
}
button.chip { cursor: pointer; min-height: 32px; }
.chip.on { background: var(--brand); color: var(--brand-ink); }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; margin: 0 -16px; padding-inline: 16px;
  scrollbar-width: none; }
.chips.scroll::-webkit-scrollbar { display: none; }

.item { display: flex; align-items: center; gap: 12px; }
.item .grow { flex: 1; min-width: 0; }
.item .name { font-weight: 600; overflow-wrap: anywhere; }
.item .qty { color: var(--muted); font-size: 14px; }
.item .acts { display: flex; gap: 8px; }

.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
  margin: 20px 2px 8px; }
.empty { text-align: center; padding: 36px 8px; color: var(--muted); }
.empty h2 { color: var(--ink); font-size: 18px; margin-bottom: 6px; }
.notice { border-radius: 12px; padding: 10px 12px; font-size: 14px; background: var(--warn-soft); color: var(--warn); }
.notice.bad { background: var(--bad-soft); color: var(--bad); }
.notice.ok { background: var(--ok-soft); color: var(--ok); }
.search { position: sticky; top: calc(58px + env(safe-area-inset-top)); z-index: 4; background: var(--bg);
  padding: 4px 0 10px; }

/* log */
.log { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); align-items: baseline; }
.log:last-child { border-bottom: 0; }
.log .sign { font-weight: 700; width: 18px; text-align: center; }
.log .sign.in { color: var(--ok); }
.log .sign.out { color: var(--bad); }
.log .grow { flex: 1; min-width: 0; }
.log time { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* sheet */
.overlay { position: fixed; inset: 0; z-index: 20; background: rgba(20, 12, 6, .5);
  display: flex; align-items: flex-end; justify-content: center; }
.overlay[hidden] { display: none; }
.sheet {
  width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--bg); border-radius: 20px 20px 0 0; padding: 18px 16px calc(20px + env(safe-area-inset-bottom));
}
.sheet h2 { font-size: 20px; margin-bottom: 4px; }
.sheet-head { display: flex; justify-content: space-between; align-items: start; gap: 12px; margin-bottom: 12px; }
.x { border: 0; background: var(--chip); border-radius: 999px; width: 36px; height: 36px; font-size: 18px;
  cursor: pointer; flex: none; }
.sheet ul, .sheet ol { padding-left: 20px; margin: 6px 0; }
.sheet li { margin: 4px 0; }
.sheet ol li { margin: 8px 0; }

.suggest { display: flex; flex-wrap: wrap; gap: 8px; margin: -6px 0 14px; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 30; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.spin { width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--brand);
  border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation-duration: 2s; } .toast { transition: none; } }

@supports (height: 100dvh) { .sheet { max-height: 92dvh; } body { min-height: 100dvh; } }
