/* Stocked — household inventory PWA.
   Design tokens follow the validated reference palette: chart-surface /
   page-plane pairs, ink hierarchy, blue accent stepped per mode, and the
   fixed status palette (warning is never used without an icon + label). */

:root {
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --ink-3: #898781;
  --hairline: #e1e0d9;
  --border: rgba(11, 11, 11, 0.1);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-wash: rgba(42, 120, 214, 0.1);
  --good: #006300;
  --warning: #b97900;
  --warning-wash: rgba(250, 178, 25, 0.16);
  --critical: #d03b3b;
  --critical-wash: rgba(208, 59, 59, 0.1);
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.05), 0 4px 16px rgba(11, 11, 11, 0.06);
  --radius: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #242423;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --ink-3: #898781;
    --hairline: #2c2c2a;
    --border: rgba(255, 255, 255, 0.1);
    --accent: #3987e5;
    --accent-ink: #ffffff;
    --accent-wash: rgba(57, 135, 229, 0.18);
    --good: #0ca30c;
    --warning: #fab219;
    --warning-wash: rgba(250, 178, 25, 0.14);
    --critical: #e66767;
    --critical-wash: rgba(230, 103, 103, 0.14);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--page);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body { min-height: 100dvh; }

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px calc(32px + env(safe-area-inset-bottom));
}

button { font: inherit; color: inherit; }

/* ---------------------------------------------------------------- header */

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0 16px;
}
.topbar .brand {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), #1c5cab);
  display: grid; place-items: center;
  color: #fff; font-size: 15px;
  flex: none;
}
.topbar .spacer { flex: 1; }

.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 12px;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  font-size: 18px;
  cursor: pointer;
}
.icon-btn:active { background: var(--surface-2); }

.back-row {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 0 14px;
}
.back-btn {
  border: none; background: none; cursor: pointer;
  color: var(--accent); font-size: 16px; font-weight: 600;
  padding: 8px 8px 8px 0;
  display: flex; align-items: center; gap: 4px;
}

/* ------------------------------------------------------------ stat tiles */

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}
.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 14px 12px;
  box-shadow: var(--shadow);
}
.stat-tile .label {
  font-size: 12px;
  color: var(--ink-2);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stat-tile .value {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.stat-tile .value.warn { color: var(--warning); }
.stat-tile .sub { font-size: 11px; color: var(--ink-3); margin-top: 2px; }

/* --------------------------------------------------------------- section */

.section-head {
  display: flex; align-items: baseline; gap: 8px;
  margin: 22px 0 10px;
}
.section-head h2 {
  font-size: 15px; font-weight: 600; margin: 0;
  color: var(--ink-2);
  text-transform: none;
}
.section-head .spacer { flex: 1; }
.section-head .link {
  border: none; background: none; cursor: pointer;
  color: var(--accent); font-size: 14px; font-weight: 600; padding: 0;
}

/* -------------------------------------------------------------- locations */

.loc-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.loc-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 14px;
  text-align: left;
  cursor: pointer;
  display: flex; flex-direction: column; gap: 8px;
}
.loc-card:active { background: var(--surface-2); }
.loc-card .emoji { font-size: 30px; line-height: 1; }
.loc-card .name { font-weight: 600; font-size: 16px; }
.loc-card .meta { font-size: 13px; color: var(--ink-2); }
.loc-card .low-chip { margin-top: 2px; }

.add-loc {
  border: 1.5px dashed var(--hairline);
  background: none;
  border-radius: var(--radius);
  padding: 16px 14px;
  color: var(--ink-2);
  font-size: 15px; font-weight: 600;
  cursor: pointer;
  display: grid; place-items: center;
  min-height: 110px;
}

/* --------------------------------------------------------------- search */

.search-row { position: relative; margin-bottom: 6px; }
.search-row input {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 14px;
  padding: 12px 14px 12px 40px;
  font-size: 16px;
  color: var(--ink);
  outline: none;
}
.search-row input:focus { border-color: var(--accent); }
.search-row .mag {
  position: absolute; left: 13px; top: 50%; transform: translateY(-50%);
  color: var(--ink-3); font-size: 15px; pointer-events: none;
}

/* ------------------------------------------------------------ item rows */

.item-list { display: flex; flex-direction: column; gap: 8px; }
.item-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px 10px;
  box-shadow: var(--shadow);
}
.thumb {
  width: 52px; height: 52px;
  border-radius: 10px;
  background: var(--surface-2);
  object-fit: cover;
  flex: none;
  display: grid; place-items: center;
  font-size: 22px;
  color: var(--ink-3);
  overflow: hidden;
}
.item-row .info { flex: 1; min-width: 0; }
.item-row .name {
  font-weight: 600; font-size: 15px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.item-row .meta { font-size: 12px; color: var(--ink-2); margin-top: 2px; }

.low-chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 600;
  color: var(--warning);
  background: var(--warning-wash);
  border-radius: 999px;
  padding: 2px 8px;
}
.out-chip { color: var(--critical); background: var(--critical-wash); }

/* stepper */
.stepper { display: flex; align-items: center; gap: 2px; flex: none; }
.stepper button {
  width: 40px; height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 20px; font-weight: 600;
  cursor: pointer;
  color: var(--ink);
}
.stepper button:disabled { opacity: 0.35; cursor: default; }
.stepper button:active:not(:disabled) { background: var(--accent-wash); }
.stepper .qty {
  min-width: 36px; text-align: center;
  font-size: 17px; font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------- action screen */

.tag-hero {
  text-align: center;
  padding: 26px 0 10px;
}
.tag-hero .emoji { font-size: 56px; }
.tag-hero h1 { font-size: 26px; margin: 10px 0 4px; letter-spacing: -0.02em; }
.tag-hero .meta { color: var(--ink-2); font-size: 14px; }

.task-buttons {
  display: flex; flex-direction: column; gap: 10px;
  margin: 22px 0;
}
.task-btn {
  display: flex; align-items: center; gap: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  font-size: 17px; font-weight: 600;
  cursor: pointer;
  text-align: left;
}
.task-btn:active { background: var(--surface-2); }
.task-btn .glyph {
  width: 44px; height: 44px; border-radius: 12px;
  display: grid; place-items: center;
  font-size: 21px;
  flex: none;
}
.task-btn .sub { display: block; font-size: 13px; font-weight: 400; color: var(--ink-2); margin-top: 2px; }
.glyph.add { background: var(--accent-wash); }
.glyph.remove { background: var(--critical-wash); }
.glyph.view { background: var(--surface-2); }

.primary-btn {
  width: 100%;
  border: none;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 14px;
  padding: 14px;
  font-size: 16px; font-weight: 600;
  cursor: pointer;
}
.primary-btn:disabled { opacity: 0.5; }
.ghost-btn {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 14px;
  padding: 13px;
  font-size: 15px; font-weight: 600;
  cursor: pointer;
}
.danger-text { color: var(--critical); }

/* ------------------------------------------------------------ photo grid */

.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
@media (min-width: 480px) { .photo-grid { grid-template-columns: repeat(4, 1fr); } }

.photo-cell {
  position: relative;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 14px;
  overflow: hidden;
  cursor: pointer;
  padding: 0;
  aspect-ratio: 1 / 1;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
}
.photo-cell img, .photo-cell .ph {
  width: 100%; flex: 1;
  object-fit: cover;
  background: var(--surface-2);
  display: grid; place-items: center;
  font-size: 30px; color: var(--ink-3);
  min-height: 0;
}
.photo-cell .cap {
  font-size: 12px; font-weight: 600;
  padding: 6px 8px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: var(--surface);
  text-align: left;
}
.photo-cell .cap .sub { display: block; font-weight: 400; color: var(--ink-2); font-size: 11px; }
.photo-cell .badge {
  position: absolute; top: 6px; right: 6px;
  min-width: 26px; height: 26px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 13px; font-weight: 700;
  display: grid; place-items: center;
  padding: 0 7px;
  border: 2px solid var(--surface);
}
.photo-cell.selected { outline: 2.5px solid var(--accent); outline-offset: -1px; }
.photo-cell.new-item { border-style: dashed; box-shadow: none; background: none; }
.photo-cell.new-item .ph { background: none; color: var(--accent); }
.photo-cell.new-item .cap { background: none; color: var(--accent); text-align: center; }

/* picker footer (sticky confirm bar) */
.picker-bar {
  position: sticky;
  bottom: 0;
  margin: 16px -16px calc(-32px - env(safe-area-inset-bottom));
  padding: 12px 16px calc(14px + env(safe-area-inset-bottom));
  background: var(--page);
  border-top: 1px solid var(--hairline);
}

/* -------------------------------------------------------------- activity */

.activity { display: flex; flex-direction: column; }
.activity .entry {
  display: flex; gap: 10px; align-items: baseline;
  padding: 9px 2px;
  border-bottom: 1px solid var(--hairline);
  font-size: 14px;
}
.activity .entry:last-child { border-bottom: none; }
.activity .entry[data-undo] { cursor: pointer; }
.activity .entry[data-undo]:active { background: var(--surface-2); }
.activity .entry.undone .what { text-decoration: line-through; opacity: 0.55; }
.activity .delta { font-weight: 700; font-variant-numeric: tabular-nums; flex: none; width: 34px; text-align: right; }
.activity .delta.pos { color: var(--good); }
.activity .delta.neg { color: var(--critical); }
.activity .what { flex: 1; min-width: 0; color: var(--ink); }
.activity .what .who { color: var(--ink-2); }
.activity .when { color: var(--ink-3); font-size: 12px; flex: none; }

.empty {
  text-align: center;
  color: var(--ink-2);
  padding: 34px 20px;
  font-size: 14px;
  line-height: 1.5;
}
.empty .big { font-size: 40px; display: block; margin-bottom: 10px; }

/* ---------------------------------------------------------------- sheets */

.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade 0.15s ease;
}
.sheet {
  width: 100%; max-width: 640px;
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  padding: 10px 20px calc(24px + env(safe-area-inset-bottom));
  animation: rise 0.2s ease;
  max-height: 88dvh;
  overflow-y: auto;
}
.sheet .grip {
  width: 40px; height: 4px; border-radius: 4px;
  background: var(--hairline);
  margin: 4px auto 14px;
}
.sheet h3 { margin: 0 0 14px; font-size: 18px; letter-spacing: -0.01em; }
@keyframes rise { from { transform: translateY(40px); opacity: 0.6; } }
@keyframes fade { from { opacity: 0; } }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.field input, .field select {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--page);
  border-radius: 12px;
  padding: 12px;
  font-size: 16px;
  color: var(--ink);
  outline: none;
}
.field input:focus { border-color: var(--accent); }

.emoji-row { display: flex; gap: 6px; flex-wrap: wrap; }
.emoji-row button {
  width: 44px; height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--page);
  font-size: 21px;
  cursor: pointer;
}
.emoji-row button.selected { border-color: var(--accent); background: var(--accent-wash); }

.photo-pick {
  display: flex; align-items: center; gap: 12px;
}
.photo-pick .preview {
  width: 72px; height: 72px;
  border-radius: 14px;
  background: var(--surface-2);
  object-fit: cover;
  display: grid; place-items: center;
  font-size: 26px; color: var(--ink-3);
  overflow: hidden;
  flex: none;
}
.photo-pick .btns { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.photo-pick .btns .ghost-btn { padding: 9px; font-size: 14px; }

/* big qty stepper inside sheet */
.big-stepper {
  display: flex; align-items: center; justify-content: center; gap: 18px;
  margin: 18px 0 20px;
}
.big-stepper button {
  width: 62px; height: 62px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 30px; font-weight: 600;
  cursor: pointer;
  color: var(--ink);
}
.big-stepper button:active:not(:disabled) { background: var(--accent-wash); }
.big-stepper button:disabled { opacity: 0.35; }
.big-stepper .qty {
  font-size: 46px; font-weight: 650;
  min-width: 84px; text-align: center;
  letter-spacing: -0.02em;
}
.sheet .item-head { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.sheet .item-head .name { font-size: 17px; font-weight: 650; }
.sheet .item-head .meta { font-size: 13px; color: var(--ink-2); margin-top: 2px; }

/* --------------------------------------------------------------- scanner */

.scan-btn {
  display: flex; align-items: center; gap: 12px;
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  font-size: 16px; font-weight: 600;
  cursor: pointer;
  text-align: left;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.scan-btn:active { background: var(--surface-2); }
.scan-btn .glyph { letter-spacing: -2px; font-size: 14px; display: grid; place-items: center; border-radius: 10px; flex: none; }
.scan-btn .sub { flex-basis: 100%; margin-left: 46px; margin-top: -8px; font-size: 13px; font-weight: 400; color: var(--ink-2); }

.scan-box {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  background: #000;
  aspect-ratio: 4 / 3;
  margin-bottom: 12px;
}
.scan-box video {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.scan-line {
  position: absolute; left: 8%; right: 8%; top: 50%;
  height: 2px;
  background: rgba(255, 80, 80, 0.85);
  border-radius: 2px;
  box-shadow: 0 0 8px rgba(255, 80, 80, 0.7);
}
.scan-status {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  color: #fff;
  font-size: 14px; font-weight: 500;
  text-align: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.55);
}
.scan-manual { display: flex; gap: 8px; align-items: stretch; }
.scan-manual input {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--page);
  border-radius: 12px;
  padding: 11px 12px;
  font-size: 15px;
  color: var(--ink);
  outline: none;
  min-width: 0;
}
.scan-manual input:focus { border-color: var(--accent); }
.scan-manual .mini-btn { font-size: 15px; padding: 0 16px; }

/* ------------------------------------------------ category heads & loc chips */

.cat-head {
  font-size: 12px; font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-3);
  margin: 14px 2px 6px;
}
.loc-chips { display: inline-flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
.loc-chip {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px; font-weight: 600;
  color: var(--ink-2);
  cursor: pointer;
}
.loc-chip:active { background: var(--accent-wash); }

/* ------------------------------------------------------- quick re-add strip */

.quick-label {
  font-size: 12px; font-weight: 600;
  color: var(--ink-2);
  margin: 2px 2px 6px;
}
.quick-strip {
  display: flex; gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 6px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.quick-strip::-webkit-scrollbar { display: none; }
.quick-chip {
  flex: none;
  display: flex; align-items: center; gap: 7px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 5px 12px 5px 5px;
  font-size: 13px; font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow);
  max-width: 190px;
}
.quick-chip:active { background: var(--surface-2); }
.quick-chip img, .quick-chip .ph {
  width: 28px; height: 28px;
  border-radius: 999px;
  object-fit: cover;
  background: var(--surface-2);
  display: grid; place-items: center;
  font-size: 14px;
  flex: none;
}
.quick-chip .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* -------------------------------------------------------- duplicate warn */

.dup-warn {
  border: 1px solid var(--border);
  background: var(--warning-wash);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 12px;
}

/* ---------------------------------------------------------------- toast */

#toast-root {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom));
  left: 50%; transform: translateX(-50%);
  z-index: 100;
  display: flex; flex-direction: column; gap: 8px;
  width: min(92vw, 420px);
  pointer-events: none;
}
.toast {
  background: var(--ink);
  color: var(--page);
  border-radius: 12px;
  padding: 11px 16px;
  font-size: 14px; font-weight: 500;
  box-shadow: var(--shadow);
  animation: rise 0.2s ease;
  text-align: center;
}

/* ---------------------------------------------------------------- login */

.login-wrap {
  min-height: 70dvh;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 18px;
  text-align: center;
}
.login-wrap .brand-mark { width: 58px; height: 58px; border-radius: 16px; font-size: 28px; }
.login-wrap input {
  font-size: 26px; text-align: center; letter-spacing: 8px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--ink);
  padding: 12px;
  width: 220px;
  outline: none;
}

/* --------------------------------------------------------------- settings */

.settings-list { display: flex; flex-direction: column; gap: 8px; }
.settings-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
}
.settings-row .grow { flex: 1; min-width: 0; }
.settings-row .name { font-weight: 600; font-size: 15px; }
.settings-row .meta { font-size: 12px; color: var(--ink-2); margin-top: 2px; word-break: break-all; }
.settings-row .mini-btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 13px; font-weight: 600;
  cursor: pointer;
  flex: none;
}
.note { font-size: 13px; color: var(--ink-2); line-height: 1.5; margin: 10px 2px; }
.note code {
  background: var(--surface-2);
  padding: 1px 5px; border-radius: 5px;
  font-size: 12px;
}
