/* ==========================================================================
   Pantry — homeBuddy's fridge door
   Vanilla CSS, no build step, no remote assets. Ledger's sibling: same
   primitives (tokens, 44px taps, dock/toasts, skeletons), but light-first —
   this page gets opened in a bright kitchen, not in bed — and one accent
   axis instead of two: TIME. Everything color-coded here answers a single
   question, "how long has this got?": red past / amber soon / green fine.
   Nothing else is allowed to be red, amber or green.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Tokens
   -------------------------------------------------------------------------- */

:root {
  --bg:        #fbfaf7;
  --surface:   #ffffff;
  --surface-2: #f1efe9;
  --surface-3: #e8e5dd;
  --line:      #e6e3db;
  --line-strong: #cfcabe;

  --text:   #1d1d1f;
  --text-2: #4d4d52;
  --muted:  #79797f;

  /* the time axis */
  --good:      #2f7d33;
  --good-bg:   #e4f2e2;
  --warn:      #a35208;
  --warn-bg:   #fbecd9;
  --danger:    #a02020;
  --danger-bg: #f9e4e2;

  --accent:    #2f7d33;   /* the house green doubles as the action color */

  /* What shared/ui.css draws with. White ink on the green in both schemes;
     the dock only has the home indicator to clear (no tab bar here). */
  --on-accent: #fff;
  --shadow:    rgba(0, 0, 0, .22);
  --dock-bottom: calc(var(--safe-b) + 14px);

  --focus: #1f6feb;

  --radius:    14px;
  --radius-sm: 10px;
  --tap:       44px;

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);

  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui,
          "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #141613;
    --surface:   #1d201c;
    --surface-2: #252923;
    --surface-3: #2e332c;
    --line:      #2c302a;
    --line-strong: #434a40;

    --text:   #f0f1ee;
    --text-2: #b4b8b0;
    --muted:  #8b9087;

    --good:      #7cc981;
    --good-bg:   #1d3320;
    --warn:      #e8a35c;
    --warn-bg:   #3a2a14;
    --danger:    #e07a72;
    --danger-bg: #3c1c1a;

    --accent: #6fbf73;
  }
}

/* --------------------------------------------------------------------------
   2. Reset / base
   -------------------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

html {
  background: var(--bg);
  overscroll-behavior-y: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.45;
  touch-action: manipulation;             /* kills the 300ms tap delay */
  -webkit-tap-highlight-color: transparent;
}

/* An author `display` beats the UA's [hidden]{display:none} — the lesson
   Ledger's stylesheet learned three times. Once, globally. */
[hidden] { display: none !important; }

h1, h2, h3, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }

/* 16px minimum on anything typable, or iOS Safari zooms the page. */
input, select { font-size: 16px; }

/* :focus-visible is shared/ui.css's — one ring on both pages. */

.num { font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------------------
   3. Frame
   -------------------------------------------------------------------------- */

.app-header {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: baseline; gap: 10px;
  padding: calc(var(--safe-t) + 10px) calc(var(--safe-r) + 16px) 8px calc(var(--safe-l) + 16px);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
}
.app-title { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
.app-aside { margin-left: auto; font-size: 12px; color: var(--muted); }

.view {
  max-width: 640px; margin: 0 auto;
  padding: 12px calc(var(--safe-r) + 16px)
           calc(var(--safe-b) + 110px)     /* room for the FAB */
           calc(var(--safe-l) + 16px);
}

/* .msg / .section-head are shared/page.css's — one look on every page. */

.footnote { margin: 26px 2px 0; font-size: 12.5px; line-height: 1.5; color: var(--muted); }

/* --------------------------------------------------------------------------
   4. Summary strip: counts that are also filters
   -------------------------------------------------------------------------- */

/* The pill strip itself (.state-pills / .state-pill and the per-state tints)
   is shared/page.css's; only this page's layout around it stays here. */

.summary { margin-bottom: 4px; }

.search-wrap { position: relative; display: flex; margin-top: 8px; }
.search {
  flex: 1 1 auto; min-height: var(--tap);
  padding: 0 38px 0 14px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-size: 16px;                        /* iOS zoom guard */
  -webkit-appearance: none; appearance: none;
}
.search::placeholder { color: var(--muted); }
.search-clear {
  position: absolute; right: 2px; top: 0; bottom: 0;
  width: 40px; border: 0; background: transparent; color: var(--muted);
  font-size: 20px; cursor: pointer; touch-action: manipulation;
}

/* --------------------------------------------------------------------------
   5. Item cards
   -------------------------------------------------------------------------- */

/* .items / .card / .badge and their internals are shared/page.css's — the hub
   deals the same cards. Only this page's own furniture stays below. */

/* Category chip = a real <select> dressed as a chip, so the native picker
   does the heavy lifting. A drawn ▾ caret (inline SVG, no remote asset) plus
   the pill border give it a visible "tap me" affordance — otherwise it reads
   as static text and nobody discovers they can recategorize. Dashed when
   unset: that's work-to-do, not a value. */
.cat-chip {
  max-width: 140px; min-height: 26px;
  padding: 2px 22px 2px 10px;
  border: 1px solid var(--line-strong); border-radius: 999px;
  background-color: var(--surface-2); color: var(--text-2);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5l5-5' fill='none' stroke='%2379797f' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 9px 6px;
  font-size: 11.5px; font-weight: 600;
  -webkit-appearance: none; appearance: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  cursor: pointer;
}
.cat-chip.cat-unset { border-style: dashed; background-color: transparent; color: var(--muted); }
/* The caret's stroke lives inside a data URI, which can't read CSS vars —
   restate it with the dark scheme's muted ink so it isn't dimmer than meant. */
@media (prefers-color-scheme: dark) {
  .cat-chip {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5l5-5' fill='none' stroke='%238b9087' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E");
  }
}

/* Buttons come from shared/ui.css. The deltas below are deliberate, not
   drift: this page's buttons sit inside dense cards, so they run a step
   tighter and smaller than Ledger's, and their labels never wrap. Both
   rules restated (in .btn-then-.btn-sm order, which the cascade needs)
   so the delta reads as one block. */
.btn { padding: 0 13px; font-size: 13.5px; white-space: nowrap; }
.btn-sm { padding: 0 11px; font-size: 13px; }

/* Closed (eaten/tossed) rows: dimmed, struck, no badge column. */
.muted .card { opacity: .6; }
.card .done { text-decoration: line-through; }
.status-word { text-transform: uppercase; font-size: 10.5px; font-weight: 700; letter-spacing: .05em; }

/* A row that failed to save flashes back rather than silently reverting. */
.rollback { animation: rollback .6s ease-out; }
@keyframes rollback {
  0%, 100% { background: var(--surface); }
  30%      { background: var(--danger-bg); }
}
@media (prefers-reduced-motion: reduce) { .rollback { animation: none; } }

/* --------------------------------------------------------------------------
   6. Buy-again cards
   -------------------------------------------------------------------------- */

.buy-list { display: flex; flex-direction: column; gap: 8px; }
.buy-card {
  display: flex; align-items: center; gap: 11px;
  background: var(--surface); border: 1px dashed var(--line-strong);
  border-radius: var(--radius); padding: 10px 12px;
}
.buy-card .main { flex: 1 1 auto; min-width: 0; }
.buy-card .name { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.buy-card .meta { margin-top: 2px; font-size: 12px; color: var(--muted); }

/* --------------------------------------------------------------------------
   7. Recently eaten / tossed — <details> does the collapsing
   -------------------------------------------------------------------------- */

#closed-details { margin-top: 26px; }
.closed-summary {
  display: flex; align-items: center; gap: 8px;
  min-height: var(--tap); padding: 0 2px;
  font-size: 13px; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--muted);
  cursor: pointer; touch-action: manipulation;
  list-style: none; -webkit-user-select: none; user-select: none;
}
.closed-summary::-webkit-details-marker { display: none; }
.closed-summary b { font-weight: 750; color: var(--text-2); }
/* Drawn chevron, not a glyph (font-fallback tofu). Rotates when open. */
.closed-summary .chev {
  width: 8px; height: 8px; flex: none;
  border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: rotate(-45deg); transition: transform .15s ease;
  margin-bottom: 2px;
}
#closed-details[open] .closed-summary .chev { transform: rotate(45deg); }
#closed { margin-top: 4px; }

/* --------------------------------------------------------------------------
   8. States: skeleton, empty
   -------------------------------------------------------------------------- */

/* .skel + shimmer are shared/ui.css's; the skeleton SHAPES (.skel-card,
   .skel-line, the width helpers) and the .empty block are shared/page.css's. */

/* --------------------------------------------------------------------------
   9. Toasts (Ledger's dock, minus the tab bar underneath)
   -------------------------------------------------------------------------- */

/* The dock and toast stack are shared/ui.css's (Ledger's, minus the tab bar
   underneath — --dock-bottom in the tokens says so), and @keyframes rise
   comes with them; the add-form below borrows it. */

/* --------------------------------------------------------------------------
   10. Add: FAB + inline form
   -------------------------------------------------------------------------- */

.fab {
  position: fixed; z-index: 60;
  right: calc(var(--safe-r) + 18px); bottom: calc(var(--safe-b) + 18px);
  width: 56px; height: 56px; border-radius: 50%;
  border: 0; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 22px rgba(0,0,0,.28);
  cursor: pointer; touch-action: manipulation;
}
.fab svg { width: 24px; height: 24px; fill: currentColor; transition: transform .15s ease; }
.fab[aria-expanded="true"] svg { transform: rotate(45deg); }
.fab:active { filter: brightness(.92); transform: scale(.96); }
@media (prefers-reduced-motion: reduce) { .fab svg { transition: none; } }

.add-form {
  position: fixed; z-index: 58;
  left: calc(var(--safe-l) + 12px); right: calc(var(--safe-r) + 12px);
  bottom: calc(var(--safe-b) + 84px);      /* clears the FAB */
  max-width: 480px; margin-left: auto;
  padding: 14px;
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: 16px;
  box-shadow: 0 14px 40px rgba(0,0,0,.30);
  animation: rise .18s ease-out;
}
@media (prefers-reduced-motion: reduce) { .add-form { animation: none; } }
.add-title { font-size: 15px; font-weight: 700; margin-bottom: 10px; }
.field {
  width: 100%; min-height: var(--tap); padding: 0 12px;
  background: var(--surface-2); border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); font-size: 16px;
  -webkit-appearance: none; appearance: none;
}
select.field {
  /* Inline SVG caret — no remote image. */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5l5-5' fill='none' stroke='%2379797f' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 12px 8px;
  padding-right: 32px;
}
.add-row { display: flex; gap: 8px; margin-top: 8px; }
.add-row .field { min-width: 0; }
.add-actions { display: flex; gap: 8px; margin-top: 12px; }
.add-actions .btn { flex: 1 1 0; }

/* --------------------------------------------------------------------------
   11. Wider screens — secondary, but not broken
   -------------------------------------------------------------------------- */

@media (min-width: 700px) {
  /* Header gutters track the centered 640px column below. */
  .app-header {
    padding-left: max(calc(var(--safe-l) + 16px), calc(50% - 320px));
    padding-right: max(calc(var(--safe-r) + 16px), calc(50% - 320px));
  }
  .dock { left: 50%; right: auto; transform: translateX(-50%); width: 460px; }
  .fab { right: max(calc(var(--safe-r) + 18px), calc(50% - 320px + 18px)); }
}
