:root {
  --bg: #e9f0f2;
  --card: #ffffff;
  --ink: #0e1e25;
  --muted: #4f6470;
  --faint: #74888f;
  --line: #d3dee2;
  --line-soft: #e2e9ec;
  --accent: #0b5563;
  --accent-hover: #083e48;
  --accent-ink: #08424d;
  --soft: #d5e8eb;
  --tint: #eef4f5;
  --tint-2: #f2f6f7;
  --remove: #b4470f;
  --warn-bg: #fff6ee;
  --warn-ink: #a13d0b;
  --danger: #a8321f;
  --ok: #1e7a4c;
  --ok-ink: #1e6b45;
  --radius: 18px;
  --shadow: 0 12px 28px rgba(14, 30, 37, 0.18);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Figtree", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}
body.sheet-open { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.45; }
:focus-visible { outline: 3px solid #5aa6b4; outline-offset: 2px; }
h1, h2, h3, p { margin: 0; }
svg { display: block; flex: none; }

.app {
  max-width: 600px;
  margin: 0 auto;
  min-height: 100vh;
  padding: max(16px, env(safe-area-inset-top)) 20px calc(120px + env(safe-area-inset-bottom));
}
.loading { display: flex; align-items: center; justify-content: center; gap: 12px; min-height: 60vh; color: var(--muted); }
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 3px solid var(--soft); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.test-banner {
  display: flex; align-items: center; gap: 10px; margin-bottom: 14px; padding: 10px 10px 10px 14px;
  border-radius: 14px; background: #fff1cc; color: #5c4300; font-size: 13px; border: 1px solid #ecd48a;
}
.test-banner span { flex: 1; }
.test-banner button { height: 36px; padding: 0 12px; border-radius: 10px; border: 0; background: #5c4300; color: #fff; font-weight: 700; font-size: 13px; }

/* ---------- top ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 38px; height: 38px; border-radius: 11px; background: var(--accent); color: #fff; display: grid; place-items: center; }
.brand strong { display: block; font-size: 16px; font-weight: 700; }
.sync { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ok-ink); }
.sync::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.sync.saving { color: var(--muted); } .sync.saving::before { background: #c9a227; animation: pulse 0.9s ease-in-out infinite alternate; }
.sync.error { color: var(--danger); } .sync.error::before { background: var(--danger); }
.sync.loading { color: var(--muted); } .sync.loading::before { background: var(--faint); }
@keyframes pulse { to { opacity: 0.3; } }

.icon-btn {
  width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--card);
  display: grid; place-items: center; color: var(--ink); text-decoration: none; flex: none;
}
.icon-btn:hover { background: var(--tint); }
.page-title { font-size: 28px; line-height: 1.15; font-weight: 800; letter-spacing: -0.02em; margin: 20px 0 16px; }

.search {
  display: flex; align-items: center; gap: 10px; height: 50px; padding: 0 8px 0 16px;
  border-radius: 14px; background: var(--card); border: 1px solid var(--line);
}
.search:focus-within { border-color: var(--accent); }
.search input { flex: 1; min-width: 0; border: 0; outline: none; background: transparent; font-size: 16px; }
.search .clear[hidden] { display: none; }
body:has(.pending) #toast-root { bottom: calc(170px + env(safe-area-inset-bottom)); }
body:has(.submit-bar) #toast-root { bottom: calc(150px + env(safe-area-inset-bottom)); }
.search .clear { width: 36px; height: 36px; border: 0; border-radius: 10px; background: var(--tint); display: grid; place-items: center; }

/* ---------- freezer map ---------- */
.map { display: flex; gap: 12px; align-items: flex-start; margin: 20px 0 22px; }
.cabinet { flex: 1 1 0; min-width: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.map-head { display: flex; justify-content: space-between; align-items: baseline; padding: 0 2px 4px; }
.map-head strong { font-size: 14px; }
.map-head span, .muted-sm { font-size: 12px; color: var(--muted); }
.drawer-btn {
  height: 36px; display: flex; align-items: center; gap: 8px; padding: 0 8px 0 4px; border-radius: 9px;
  background: var(--tint-2); border: 1.5px solid transparent; text-align: left; width: 100%;
}
.drawer-btn:hover { border-color: var(--line); }
.drawer-btn .num { width: 24px; height: 24px; flex: none; border-radius: 6px; display: grid; place-items: center; font-size: 12px; font-weight: 700; background: #fff; color: #2b4651; border: 1px solid #c3d2d7; }
.drawer-btn .lbl { flex: 1; min-width: 0; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drawer-btn.empty .lbl { color: var(--faint); }
.side { width: 132px; display: flex; flex-direction: column; gap: 12px; flex: none; }
.chest-btn {
  height: 150px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--card); padding: 12px;
  display: flex; flex-direction: column; justify-content: space-between; text-align: left;
}
.chest-btn:hover { background: var(--tint-2); }
.chest-btn strong { font-size: 14px; }
.chest-shape { height: 48px; border-radius: 10px 10px 6px 6px; border: 2px solid #9db5bc; background: #f0f5f6; display: grid; place-items: center; font-size: 12px; color: var(--muted); }
.last-change { border-radius: var(--radius); background: var(--soft); padding: 12px; display: flex; flex-direction: column; gap: 3px; border: 0; text-align: left; width: 100%; }
.last-change span { font-size: 12px; color: #2b4651; }
.last-change strong { font-size: 14px; }

/* ---------- groups / rows ---------- */
.groups { display: flex; flex-direction: column; gap: 20px; }
.group { display: flex; flex-direction: column; gap: 8px; scroll-margin-top: 16px; }
.group-head { display: flex; justify-content: space-between; align-items: baseline; padding: 0 4px; }
.group-head h2 { font-size: 17px; font-weight: 700; }
.group-head span { font-size: 13px; color: var(--muted); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row { display: flex; align-items: center; gap: 8px; padding: 10px 12px 10px 4px; }
.row + .row { border-top: 1px solid var(--line-soft); }
.row-main { flex: 1; min-width: 0; border: 0; background: transparent; text-align: left; padding: 4px 4px 4px 12px; border-radius: 10px; display: flex; flex-direction: column; gap: 2px; }
.row-main:hover { background: var(--tint-2); }
.row-name { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-also { font-size: 12px; color: var(--accent); font-weight: 600; }
.qty { width: 34px; flex: none; text-align: center; font-size: 17px; font-weight: 700; }
.qty.zero { color: var(--faint); }
.step {
  width: 44px; height: 44px; flex: none; border-radius: 12px; display: grid; place-items: center;
  border: 1px solid var(--line); background: var(--card); color: var(--remove);
}
.step.plus { border-color: transparent; background: var(--soft); color: var(--accent); }
.step:hover { filter: brightness(0.96); }
.step.big { width: 56px; height: 56px; border-radius: 16px; }
.empty-state { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty-state strong { display: block; color: var(--ink); font-size: 17px; margin-bottom: 4px; }
.result-count { font-size: 14px; color: var(--muted); margin: 18px 4px 0; }

.fab-wrap {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  padding: 36px 20px calc(20px + env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, rgba(233, 240, 242, 0), var(--bg) 45%);
  pointer-events: none;
}
.fab-wrap > * { pointer-events: auto; max-width: 560px; margin: 0 auto; }
.primary {
  width: 100%; height: 56px; border: 0; border-radius: 16px; background: var(--accent); color: #fff;
  font-size: 17px; font-weight: 700; display: flex; align-items: center; justify-content: center; gap: 10px;
}
.primary:hover:not(:disabled) { background: var(--accent-hover); }
.primary.fab { box-shadow: 0 8px 20px rgba(11, 85, 99, 0.28); }
.primary.remove { background: var(--remove); }
.primary.remove:hover:not(:disabled) { background: #973b0c; }
.primary.danger { background: var(--danger); }
.secondary {
  height: 52px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); color: var(--ink);
  font-size: 15px; font-weight: 700; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 0 16px;
}
.secondary:hover:not(:disabled) { background: var(--tint); }
.secondary.remove { color: var(--remove); }
.link-btn { border: 0; background: transparent; color: var(--accent); font-weight: 600; font-size: 14px; min-height: 44px; padding: 0 4px; }
.link-btn.danger { color: var(--danger); }
.footer-note { text-align: center; font-size: 12px; color: var(--faint); margin-top: 28px; }

/* ---------- item view ---------- */
.subhead { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.subhead .crumb { font-size: 13px; color: var(--muted); text-align: center; flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.item-title { font-size: 28px; line-height: 1.15; font-weight: 800; letter-spacing: -0.02em; margin-top: 16px; overflow-wrap: anywhere; }
.item-meta { font-size: 15px; color: var(--muted); margin-top: 6px; }
.hero {
  margin-top: 18px; padding: 18px; border-radius: var(--radius); background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.hero small { display: block; font-size: 13px; color: #c4dde2; }
.hero strong { display: block; font-size: 30px; font-weight: 800; line-height: 1.15; }
.pills { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; min-width: 0; }
.pill { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: rgba(255, 255, 255, 0.16); max-width: 170px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.section { margin-top: 22px; display: flex; flex-direction: column; gap: 10px; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; padding: 0 4px; gap: 8px; }
.section-head h2 { font-size: 17px; font-weight: 700; }
.section-head span { font-size: 13px; color: var(--muted); }
.portion { display: flex; align-items: center; gap: 10px; padding: 12px 12px 12px 14px; }
.portion + .portion { border-top: 1px solid var(--line-soft); }
.portion.changed { background: var(--warn-bg); }
.place-badge {
  width: 44px; height: 44px; flex: none; border-radius: 10px; background: var(--tint); border: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1;
}
.place-badge small { font-size: 9px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.place-badge strong { font-size: 16px; font-weight: 800; margin-top: 2px; }
.place-badge.chest strong { font-size: 11px; }
.portion-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.portion-info strong { font-size: 15px; font-weight: 600; line-height: 1.25; overflow-wrap: anywhere; }
.portion-info span { font-size: 13px; color: var(--muted); }
.portion.changed .portion-info span { color: var(--warn-ink); }
.add-row {
  width: 100%; height: 52px; border: 0; border-top: 1px solid var(--line-soft); background: var(--card); color: var(--accent);
  font-size: 15px; font-weight: 600; display: flex; align-items: center; justify-content: center; gap: 8px;
}
.add-row:only-child { border-top: 0; }
.add-row:hover { background: var(--tint-2); }
.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.fact {
  width: 100%; min-height: 52px; padding: 0 14px 0 16px; border: 0; background: var(--card);
  display: flex; align-items: center; gap: 10px; text-align: left;
}
.fact + .fact { border-top: 1px solid var(--line-soft); }
.fact:hover { background: var(--tint-2); }
.fact span:first-child { flex: 1; font-size: 15px; }
.fact span:nth-child(2) { font-size: 15px; color: var(--muted); max-width: 55%; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fact .unset { color: var(--faint) !important; }
.log { display: flex; flex-direction: column; gap: 10px; padding: 0 4px; }
.log-row { display: flex; gap: 10px; align-items: baseline; font-size: 14px; }
.log-row .d { width: 38px; flex: none; font-weight: 700; }
.log-row .d.plus { color: var(--ok-ink); } .log-row .d.minus { color: var(--remove); } .log-row .d.neutral { color: var(--muted); }
.log-row .t { flex: 1; min-width: 0; }
.log-row .t small { display: block; color: var(--muted); font-size: 12px; }
.log-row time { font-size: 12px; color: var(--muted); flex: none; }
.hint { font-size: 14px; color: var(--muted); padding: 0 4px; }

.pending {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; padding: 0 12px calc(16px + env(safe-area-inset-bottom));
}
.pending-inner {
  max-width: 576px; margin: 0 auto; padding: 14px 14px 14px 18px; border-radius: var(--radius); background: var(--ink); color: #fff;
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px; box-shadow: var(--shadow);
}
.pending-text { flex: 1 1 180px; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.pending-text small { font-size: 12px; color: #a8bec4; }
.pending-text strong { font-size: 15px; font-weight: 600; }
.pending-actions { display: flex; gap: 8px; margin-left: auto; }
.pending button { height: 44px; padding: 0 14px; border-radius: 12px; font-size: 14px; font-weight: 700; }
.pending .ghost { border: 1px solid #36515a; background: transparent; color: #fff; }
.pending .solid { border: 0; background: #fff; color: var(--ink); padding: 0 18px; }
.pending label { flex-basis: 100%; display: flex; gap: 10px; align-items: center; font-size: 14px; color: #dbe6e9; min-height: 32px; }
.pending input { width: 20px; height: 20px; accent-color: #7cc2cf; margin: 0; }

/* ---------- forms / add view ---------- */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.panel + .panel { margin-top: 14px; }
.step-head { display: flex; align-items: center; gap: 10px; }
.step-num { width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 13px; font-weight: 700; display: grid; place-items: center; flex: none; }
.step-head h2 { font-size: 17px; font-weight: 700; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; color: var(--muted); }
.input, .select, .textarea {
  width: 100%; min-height: 50px; padding: 0 14px; border-radius: 12px; border: 1.5px solid var(--line); background: #fff; font-size: 16px; outline: none;
}
.textarea { padding: 12px 14px; min-height: 80px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); }
.field-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.match { border-radius: 12px; background: var(--soft); padding: 12px 14px; display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.match div { flex: 1 1 160px; display: flex; flex-direction: column; gap: 2px; }
.match strong { font-size: 14px; color: var(--accent-ink); }
.match span { font-size: 13px; color: #2b4651; }
.match button { height: 44px; padding: 0 14px; border-radius: 12px; border: 0; background: var(--accent); color: #fff; font-size: 14px; font-weight: 700; }
.segment { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; padding: 4px; border-radius: 14px; background: var(--tint); }
.segment button { height: 44px; border-radius: 10px; border: 0; background: transparent; font-size: 15px; font-weight: 600; color: var(--muted); }
.segment button[aria-pressed="true"] { background: #fff; color: var(--ink); font-weight: 700; box-shadow: 0 1px 3px rgba(14, 30, 37, 0.12); }
.drawer-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.drawer-tile {
  height: 64px; border-radius: 12px; background: var(--tint-2); border: 2px solid transparent;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.drawer-tile strong { font-size: 18px; font-weight: 800; }
.drawer-tile span { font-size: 11px; color: var(--muted); }
.drawer-tile:hover { border-color: var(--line); }
.drawer-tile[aria-pressed="true"] { background: var(--soft); border-color: var(--accent); }
.drawer-tile[aria-pressed="true"] span { color: var(--accent-ink); }
.drawer-tile:disabled { opacity: 0.4; }
.stepper { display: flex; align-items: center; gap: 12px; }
.stepper .value { flex: 1; height: 56px; border-radius: 16px; background: var(--tint); display: flex; align-items: center; justify-content: center; gap: 6px; }
.stepper .value strong { font-size: 30px; font-weight: 800; line-height: 1; }
.stepper .value span { font-size: 15px; color: var(--muted); }
.stepper .step { color: var(--ink); }
.stepper .step.plus { color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { height: 40px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--line); background: #fff; font-size: 14px; font-weight: 600; }
.chip.sm { height: 36px; padding: 0 14px; font-size: 13px; }
.chip[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }
.chip:hover:not([aria-pressed="true"]) { background: var(--tint); }
details.panel { padding: 0; gap: 0; }
details.panel > summary { list-style: none; cursor: pointer; padding: 16px; display: flex; align-items: center; justify-content: space-between; font-weight: 700; font-size: 15px; }
details.panel > summary::-webkit-details-marker { display: none; }
details.panel > summary span { font-size: 13px; font-weight: 400; color: var(--muted); }
details.panel[open] > summary svg { transform: rotate(180deg); }
details.panel .details-body { padding: 0 16px 16px; display: flex; flex-direction: column; gap: 12px; }
.submit-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; background: #fff; border-top: 1px solid var(--line);
  padding: 14px 20px calc(18px + env(safe-area-inset-bottom));
}
.submit-bar > div { max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; gap: 10px; }
.summary { font-size: 14px; color: #2b4651; text-align: center; }
.summary strong { color: var(--ink); }

/* ---------- sheets ---------- */
.backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(14, 30, 37, 0.5); display: flex; align-items: flex-end; justify-content: center; animation: fade 0.15s ease-out; }
.sheet {
  width: 100%; max-width: 600px; max-height: 92vh; overflow-y: auto; background: #fff; border-radius: 24px 24px 0 0;
  padding: 10px 20px calc(24px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 18px;
  animation: up 0.2s ease-out;
}
@media (min-width: 700px) {
  .backdrop { align-items: center; }
  .sheet { border-radius: 24px; max-height: 86vh; padding-bottom: 24px; }
}
@keyframes up { from { transform: translateY(24px); opacity: 0.6; } }
@keyframes fade { from { opacity: 0; } }
.grabber { align-self: center; width: 40px; height: 5px; border-radius: 3px; background: #c3d2d7; flex: none; }
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.sheet-head small { display: block; font-size: 13px; color: var(--muted); }
.sheet-head h2 { font-size: 24px; font-weight: 800; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.sheet .icon-btn { background: var(--tint); border: 0; }
.sheet-label { font-size: 15px; font-weight: 700; }
.options { display: flex; flex-direction: column; gap: 8px; }
.option {
  min-height: 56px; display: flex; align-items: center; gap: 12px; padding: 8px 14px; border-radius: 14px;
  border: 1.5px solid var(--line); background: #fff; cursor: pointer;
}
.option:has(input:checked) { background: var(--soft); border-color: var(--accent); }
.option input { width: 20px; height: 20px; margin: 0; accent-color: var(--accent); flex: none; }
.option .o-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.option .o-main strong { font-size: 15px; font-weight: 600; line-height: 1.25; overflow-wrap: anywhere; }
.option .o-main span { font-size: 13px; color: var(--muted); }
.option .o-side { font-size: 14px; color: #2b4651; flex: none; }
.result { border-radius: 16px; background: var(--tint); padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; }
.result.warn { background: var(--warn-bg); }
.result small { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.result strong { font-size: 16px; font-weight: 700; }
.result span { font-size: 14px; color: #2b4651; }
.result label, .check { display: flex; align-items: center; gap: 10px; font-size: 14px; min-height: 44px; }
.result input, .check input { width: 20px; height: 20px; margin: 0; accent-color: var(--accent); flex: none; }
.confirm-text { color: var(--muted); font-size: 15px; }
.history-list { display: flex; flex-direction: column; }
.history-list .log-row { padding: 12px 0; border-top: 1px solid var(--line-soft); }
.history-list .log-row:first-child { border-top: 0; }

/* ---------- toast ---------- */
#toast-root { position: fixed; left: 0; right: 0; bottom: calc(96px + env(safe-area-inset-bottom)); z-index: 60; display: flex; justify-content: center; padding: 0 16px; pointer-events: none; }
.toast {
  pointer-events: auto; max-width: 560px; width: 100%; background: var(--ink); color: #fff; border-radius: 14px; padding: 10px 10px 10px 16px;
  display: flex; align-items: center; gap: 12px; box-shadow: var(--shadow); font-size: 15px; animation: up 0.2s ease-out;
}
.toast span { flex: 1; }
.toast button { height: 40px; padding: 0 14px; border-radius: 10px; border: 0; background: rgba(255, 255, 255, 0.14); color: #fff; font-weight: 700; font-size: 14px; }
.toast.error { background: var(--danger); }

@media (max-width: 360px) {
  .side { width: 112px; }
  .app { padding-left: 14px; padding-right: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; scroll-behavior: auto !important; }
}
