/* FridgeFriend web companion - phase 1 (view only, 2026-11-06).
   Mobile-first, no framework, matches the Android app's visual language:
   Azure accent, card rows, days-left coloring. */

:root {
  --primary: #0b57d0;
  --primary-container: #d3e3fd;
  --on-primary-container: #041e49;
  --surface: #ffffff;
  --surface-dim: #f3f6fc;
  --outline: #c4c7c5;
  --text: #1f1f1f;
  --text-variant: #5f6368;
  --ok: #1e8e3e;
  --warn: #ea8600;
  --bad: #d93025;
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  /* Reserve the scrollbar gutter ALWAYS (user 2026-11-17): without it the
     centered .view jumps sideways whenever the scrollbar appears/disappears
     - on tab switches (long inventory vs short tabs) and when a modal dialog
     opens (html.modal-open sets overflow:hidden, which removes the bar).
     No-op on iOS (overlay scrollbars take no space). */
  scrollbar-gutter: stable;
  background: var(--surface-dim);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  /* Notch-friendly standalone app */
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.view { max-width: 640px; margin: 0 auto; padding: 16px; }

/* user 2026-11-29 (round 2 fix): #app starts flush at the scrollport top - with
   padding-top:16px the sticky header sat 16px down and slid up on the first
   pixels of scroll before pinning ("moves a bit before it stops"). The header
   carries its own top padding instead (counted in --hdr-h). */
#app.view { padding-top: 0; }
.hidden { display: none !important; }

/* ---- Login ---- */

.login-card {
  margin-top: 15vh;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 32px 24px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .12);
}

.login-card h1 { margin: 0 0 4px; font-size: 28px; }
.subtitle { margin: 0 0 24px; color: var(--text-variant); }

form { display: grid; gap: 12px; }
label { font-size: 14px; color: var(--text-variant); }

input {
  font-size: 16px; /* 16px+ prevents iOS zoom-on-focus */
  padding: 12px 14px;
  border: 1px solid var(--outline);
  border-radius: 12px;
  background: var(--surface);
}

button {
  font-size: 16px;
  padding: 12px 16px;
  border: none;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
}

button:active { opacity: .8; }

/* Notification bell: subtle when off, Azure when subscribed. */
#push.on { background: var(--primary); color: #fff; }

.hint { margin-top: 20px; font-size: 13px; color: var(--text-variant); }

/* ---- App header ---- */

/* user 2026-11-29 (round 2): the WHOLE header (fridge name + right icons) is
   sticky too - the inventory topline sticks right below it at --hdr-h (set
   from JS = live header height, so font/zoom changes are handled) */
#app > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  /* user 2026-11-29 (round 2 fix): margin-bottom:0 - a margin between the two
     sticky elements made the topline slide a few px before pinning; spacing
     lives in padding (inside offsetHeight, so --hdr-h stays exact) */
  margin-bottom: 0;
  position: sticky; top: 0; z-index: 6;
  background: var(--surface);
  padding: 8px 0 10px;
  border-bottom: 1px solid var(--surface-dim);
}

header h1 { font-size: 24px; margin: 0; }

/* Refresh feedback (user 2026-11-09): the button spins while the
   fetch runs - a visible "something is happening" instead of just
   the sync-age line quietly resetting. */
#refresh.spin {
  animation: ffspin .6s linear infinite;
}
@keyframes ffspin {
  to { transform: rotate(360deg); }
}

/* Press-and-hold color feedback (user 2026-11-10): solid primary while
   the pointer is down, back to standard on release. */
#refresh.pressing {
  background: var(--primary);
  color: #fff;
}

/* Sync-in-progress indicator next to the status text (pulsing dot). */
.sync-age.syncing::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--primary);
  animation: ffpulse .8s ease-in-out infinite;
}
@keyframes ffpulse {
  50% { opacity: .25; }
}

.header-actions { display: flex; gap: 8px; }

/* Search box (2026-11-09) */
.search {
  width: 100%;
  margin: 4px 0 10px;
  font-size: 15px;
  padding: 9px 12px;
  border: 1px solid var(--outline);
  border-radius: 12px;
  background: var(--surface);
}

/* Add-dialog scan hint sits tight under the camera frame (user 2026-11-14:
   the "Product found" status line was removed - the flash over the frame
   is the read feedback now). */
#add-scan-hint { margin: 2px 0 0; }
#add-dlg .photo-area { margin-bottom: 0; }
/* An empty hint line must not take up space (user 2026-11-14). */
#add-hint:empty { display: none; }
/* Tighter name -> quantity gap (user 2026-11-14). */
#add-dlg .name-label { margin-bottom: 2px; }
/* Name row: input + nutriscore badge (user 2026-11-14: the full colored
   A-E icon as in the app, shown when a scan matches a product that has
   one, sitting inline with the name field). */
.name-row { display: flex; align-items: center; gap: 8px; }
/* Clear-✕ at the end of a name row (user 2026-11-14): one-tap wipe of
   the text box; hidden while the box is empty. */
.clear-x {
  flex: 0 0 auto;
  border: none;
  background: transparent;
  color: var(--text-variant);
  font-size: 15px;
  line-height: 1;
  padding: 6px;
  cursor: pointer;
}
/* margin-top: 0 - the generic dialog input's 4px top margin pushed the
   input down inside the row, making the badge look shifted up (user
   2026-11-14). */
.name-row input { flex: 1 1 auto; min-width: 0; margin-top: 0; }
/* Expiry row + OCR "Scan date" button (user 2026-11-16) */
.date-row { display: flex; align-items: center; gap: 8px; }
.date-row input { flex: 1 1 auto; min-width: 0; margin-top: 0; }
.mini-btn {
  flex: 0 0 auto;
  border: 1px solid var(--outline);
  background: var(--primary-container);
  color: var(--on-primary-container);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
}
.nutriscore {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 800;
  font-size: 18px;
}
.nutriscore.a { background: #038141; }
.nutriscore.b { background: #85bb2f; }
.nutriscore.c { background: #fecb00; color: #3a3a3a; }
.nutriscore.d { background: #ee8100; }
.nutriscore.e { background: #e63e11; }

/* About dialog */
.about-toggle { display: flex; gap: 8px; align-items: center; font-size: 14px; margin: 10px 0; }
#about-dlg .meta { margin: 4px 0; }
#about-dlg h2 { margin-top: 0; }

.header-actions button {
  background: var(--primary-container);
  color: var(--on-primary-container);
  font-size: 18px;
  padding: 8px 12px;
  border-radius: 12px;
}

.meta { margin: 4px 0 12px; font-size: 13px; color: var(--text-variant); }

/* ---- Item list ---- */

.item-list { display: grid; gap: 8px; }

/* ---- Announcements (2026-11-10) ---- */

.messages { display: grid; gap: 8px; margin-bottom: 12px; }
.msg-banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 14px;
  border: 1px solid var(--outline);
  background: var(--surface);
}
.msg-banner.msg-info { border-left: 4px solid var(--primary); }
.msg-banner.msg-warning { border-left: 4px solid var(--warn); background: rgba(234, 134, 0, .08); }
.msg-banner.msg-critical { border-left: 4px solid var(--bad); background: var(--bad-container); }
.msg-text { flex: 1; }
.msg-text a { color: var(--primary); }
.msg-dismiss {
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-variant);
  font-size: 14px;
  padding: 2px 6px;
  border-radius: 8px;
}
.msg-dismiss:hover { color: var(--text); }

.item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface);
  border-radius: var(--radius);
  /* Compact rows (matches the Android app): more items per screen. */
  padding: 8px 12px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .10);
}

/* Text block fills ALL space between thumbnail and badge (user
   2026-11-09): without flex:1 it sized to its content and left a gap
   before the badge - long names wrapped to 2-3 lines while unused
   width sat idle. min-width:0 lets it actually shrink; overflow-wrap
   handles unbroken long words. */
.item .text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.item .name { font-size: 16px; font-weight: 500; }
.item .qty { font-size: 13px; color: var(--text-variant); margin-top: 2px; }

.badge {
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  white-space: nowrap;
}

/* Traffic-light ROW tints (user design 2026-11-06): the whole item
   box carries the zone color - soft enough to sit behind text all day,
   strong enough to read the fridge state at a glance. The badge itself
   is transparent black text on top of the row tint. */
.item.zone-ok   { background: #e2f5e6; }
.item.zone-warn { background: #fdf3d2; }
.item.zone-bad  { background: #fde5e2; }
.item.zone-none { background: var(--surface); }

.badge { color: #000; }

/* ---- States ---- */

.empty { text-align: center; color: var(--text-variant); margin-top: 32px; }
.error { color: var(--bad); font-size: 14px; }

/* Phase 1.5: thumbnails + OFF enrichment. */
.item .thumb {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  object-fit: cover;
  background: #dde3ec;
  flex-shrink: 0;
}
.item .brand { color: var(--text-variant); }
.nscore {
  /* inline-flex centering + nowrap + overflow hidden: a multi-char value
     ("UNKNOWN" from OFF) used to wrap into two lines and spill white text
     outside the colored box (user 2026-11-14); app.js now also sends only
     a single A-E letter. */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  margin-left: 6px;
  border-radius: 4px;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  flex-shrink: 0;
  box-sizing: border-box;
  /* the glyph sat ~1px too high with pure flex centering (user 2026-11-14) */
  padding-top: 1px;
  vertical-align: middle;
}

/* Sync-age staleness: amber past 30 min, red past an hour. */
.sync-age { margin-bottom: 0; font-weight: 600; }
.sync-age.stale-warn { color: #b45309; }
.sync-age.stale-bad { color: #b91c1c; }

/* Edit dialog (phase 1.5b). */
.item { cursor: pointer; }
dialog {
  border: 1px solid #d5dbe5;
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .18);
  padding: 20px 24px;
  /* FIXED width, never fit-content: the qty row (stepper + chips) has a
     larger min-content width than a phone screen, so a fit-content
     dialog overflowed horizontally - the grams chip and the date
     field's calendar icon were clipped at the right edge and the whole
     dialog could be swiped sideways (found live 2026-11-05). */
  width: min(92vw, 360px);
  box-sizing: border-box;
}
dialog::backdrop { background: rgba(0, 0, 0, .35); }
/* Pinned dialog action bar (user 2026-11-14, the Android lesson): an open
   dialog is a flex column capped at 92dvh - .dlg-body scrolls, .dlg-actions
   stays visible at the bottom, so Save/Cancel can never hide below the
   fold (the compacting-only fix from 2026-11-07 was not enough). */
dialog[open] {
  display: flex;
  flex-direction: column;
  max-height: 92vh;
  max-height: 92dvh;
}
dialog[open] form {
  display: flex;
  flex-direction: column;
  /* Same 12px gap the form had as a grid (form { display: grid; gap: 12px })
     - without it the flex column drops the gap and the qty-label's -8px
     margin-bottom overlaps the stepper (user 2026-11-14). */
  gap: 12px;
  flex: 1 1 auto;
  min-height: 0;
}
/* The wrapper owns positioning so the edge fades can be absolute children
   of it WITHOUT scrolling away with the content (abs-pos children of the
   scroller itself scroll along - the 2026-11-14 first version had exactly
   that bug, which is why the top fade never showed). The wrapper is
   full-bleed: negative margins cancel the dialog's 20px/24px padding, so
   the scroll area and the fades span the full dialog width. */
.dlg-scrollwrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  margin: -20px -24px 0;
}
.dlg-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 20px 24px 0;
  /* native scrollbar hidden (overlay-only on phones, sits inside the
     padding) - the edge fades below are the cue instead;
     overscroll-behavior:contain stops scroll chaining to the page */
  scrollbar-width: none;
  overscroll-behavior: contain;
}
.dlg-body::-webkit-scrollbar { display: none; }
/* While any modal dialog is open, the page behind must not scroll (user
   2026-11-14: swiping over the dialog's fixed parts scrolled the list). */
html.modal-open, html.modal-open body { overflow: hidden; }
/* Edge fades (user 2026-11-14 "new paradigm"): a soft gradient at the cut
   edge, stronger toward the edge - bottom fade while more content exists
   below, top fade once scrolled (the user always starts at the top, so no
   cue is shown there initially). Classic pattern (iOS edge indicators /
   Material scroll shadows). 44px tall. */
.scroll-fade {
  position: absolute;
  left: 0;
  right: 0;
  height: 44px;
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s linear;
  z-index: 2;
}
/* Grayscale (user 2026-11-14: azure read as "colored", gray reads as a pure
   shadow cue - easy to revert to rgba(11,87,208,.16) if it looks too weak). */
.scroll-fade-top {
  top: 0;
  background: linear-gradient(to bottom, rgba(0, 0, 0, .15), rgba(0, 0, 0, 0));
}
.scroll-fade-bottom {
  bottom: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, .15), rgba(0, 0, 0, 0));
}
.scroll-fade.on { opacity: 1; }
/* Two very small solid down-arrows at the sides of the bottom gradient,
   close to the cutoff line (user 2026-11-14). CSS triangles, shown
   together with the bottom fade. */
.scroll-arrow {
  position: absolute;
  bottom: 4px;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 7px solid rgba(0, 0, 0, .5);
  opacity: 0;
  transition: opacity .15s linear;
}
.scroll-arrow.left { left: 12px; }
.scroll-arrow.right { right: 12px; }
.scroll-fade-bottom.on .scroll-arrow { opacity: 1; }
/* NOTE (user 2026-11-14): the main inventory list intentionally has NO
   permanent scroll cue - the page scrolls with the body and the browser's
   own (transient) scrollbar is enough there. Viewport fades were tried and
   removed again; dialogs keep the edge fades above. */
/* The form USED to be this grid (form { display: grid; gap: 12px }) - since
   the pinned-actions change the fields live inside .dlg-body, which is a
   plain block container: block layout COLLAPSES margins, so
   label.qty-label's -8px margin-bottom became a real overlap of the
   stepper (user 2026-11-14, still present after gap:12px on the form).
   Replicate the grid here so the original spacing math applies again. */
form .dlg-body {
  display: grid;
  gap: 12px;
}
dialog[open] .dlg-actions {
  flex: 0 0 auto;
}
dialog h2 { margin: 0 0 12px; font-size: 18px; }
dialog label {
  display: block;
  margin-bottom: 10px;
  font-size: 13px;
  color: var(--text-variant);
}
/* Bare "Quantity" label: it is its own grid row, so the form's 12px
   grid gap PLUS the 10px label margin-bottom gave a 22px gap to the
   stepper - vs 4px for Name (whose input is nested inside its label,
   one grid item). Negative margin lands it on the same 4px (user
   2026-11-07). */
dialog label.qty-label {
  margin-bottom: -8px;
}
dialog input, dialog select {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px;
  font-size: 15px;
  border: 1px solid #c4ccda;
  border-radius: 8px;
  box-sizing: border-box;
}
.dlg-actions {
  /* Two explicit rows (user 2026-11-05), deterministic in every
     browser - a single wrapped flex row split 3+1 on desktop and 2+2
     on Android depending on each engine's shrinking rules. */
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 14px;
}
.dlg-row {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  /* user 2026-12-03: the join-dialog bottom row holds 4 controls (Scan QR,
     Image, Add, Cancel) - wrap instead of stretching one control unnaturally */
  flex-wrap: wrap;
  align-items: center;
}
/* user 2026-12-03: QR pickers (login card + add-fridge dialog) - button-like
 * label wrapping a hidden <input type=file>, never stretched by the flex row.
 * The input itself must be display:none (NOT the hidden attribute): iOS Safari
 * still renders the native "Choose file / No file chosen" widget otherwise,
 * which left-anchored a wide box in the row (user screenshot 2026-12-03). */
.qr-pick {
  display: inline-block;
  flex: 0 0 auto;
  /* user 2026-12-03: same box as a real button (was visibly smaller) */
  padding: 12px 16px;
  border: 1px solid var(--line, #ccc);
  border-radius: 12px;
  cursor: pointer;
  font-size: 16px;
}
.qr-pick input[type="file"] {
  display: none !important;
}
.dlg-row > * {
  flex: 0 0 auto;
}
/* secondary (outline) button variant for the QR pickers */
button.secondary, .qr-pick.secondary {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--primary);
}
/* user 2026-12-03: QR row sits directly ABOVE the invitation field, left aligned */
.qr-row {
  display: flex;
  gap: 8px;
  justify-content: flex-start;
  margin: 0 0 12px;
}
/* user 2026-12-03: Scan QR (a <button>) and Image (a .qr-pick label) must be
 * pixel-identical: buttons are border-box by UA default, labels are not -
 * pin identical metrics + box-sizing on both */
.qr-row > * {
  box-sizing: border-box;
  margin: 0;
  padding: 12px 16px;
  font-size: 16px;
  line-height: 1.2;
  border-radius: 12px;
  min-height: 48px;
}
/* a bit of air between the name field and the Add/Cancel bottom row */
#add-fridge-dlg .dlg-row {
  margin-top: 16px;
}
/* user 2026-12-03: inline live-camera QR preview inside login/add-fridge */
.qr-cam-box video {
  width: 100%;
  max-height: 38vh;
  border-radius: 8px;
  background: #000;
  margin-top: 12px;
}
.dlg-row:first-child {
  justify-content: space-between;
}
.dlg-actions .danger {
  margin-right: auto;
  background: #fde5e2;
  color: #b91c1c;
  border: 1px solid #f5b5b0;
}
.dlg-actions .primary {
  background: var(--primary, #0b57d0);
  color: #fff;
  border: none;
}
.dlg-actions button {
  cursor: pointer;
  flex-shrink: 1;
  /* One shape for ALL dialog action buttons (user 2026-11-09): the
     global button rule is 12px radius / 12px 16px padding (that is
     why Cancel looked right), while the per-color rules below had
     drifted to 8px radius / 8px padding - Cancel looked rounded, the
     others squarish and shorter. This unifies radius and height; the
     color rules keep only colors. */
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
}

/* Quantity stepper (phase 1.5b): pieces step 1, grams step 100. */
.qty-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.stepper {
  display: flex;
  gap: 6px;
  align-items: center;
}
.unit-chips {
  display: flex;
  gap: 6px;
}
.unit-chips .chip {
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid #c4ccda;
  background: #fff;
  /* Same global-button trap: without this the UNSELECTED chip's text was
     white on white (only the .on chip, which sets its own color, showed
     text - found live 2026-11-05). */
  color: #1f2937;
  font-size: 13px;
  cursor: pointer;
}
.unit-chips .chip.on {
  background: #e8f0fe;
  border-color: #0b57d0;
  color: #0b57d0;
  font-weight: 600;
}
.stepper input {
  width: 90px !important;
  margin-top: 0 !important;
  text-align: center;
}
.stepper button {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid #c4ccda;
  background: #fff;
  /* The GLOBAL button rule sets color:#fff AND padding:12px 16px - the
     color made the glyphs invisible, the padding squeezed them
     off-center in the 36px circle (both found live 2026-11-05). */
  color: #1f2937;
  padding: 0;
  font-size: 18px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  cursor: pointer;
  flex-shrink: 0;
}
.dlg-actions .consumed {
  background: #e2f5e6;
  color: #1b5e20;
  border: 1px solid #a5d6a7;
}
.dlg-actions .danger { margin-right: 0; }

/* Add dialog (phase 1.5c): live camera view + captured preview.
   The file input is hidden - it is only the getUserMedia fallback. */
.photo-area {
  margin-bottom: 8px;
  /* Label line removed (user 2026-11-07) - when the camera is idle
     (fallback state) the area collapses to just the Photo button. */
}
.photo-area video,
.photo-area img {
  /* Reduced and centered (user 2026-11-07): with the label line gone
     the full-width frame dominated the dialog. Capped height + capped
     width, centered - enough to frame the item, not the whole show. */
  width: min(100%, 280px);
  max-height: 170px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid #c4ccda;
  display: block;
  margin: 0 auto 6px;
  background: #000;
}
/* Add-dialog wrappers own the centering of the frame box so the overlays
   below (scan flash, clear X) can anchor to it (user 2026-11-14). The
   base .photo-area video/img rule above still covers the edit dialog. */
.cam-wrap,
.preview-wrap {
  position: relative;
  width: min(100%, 280px);
  margin: 0 auto 6px;
}

/* Scan tab (user 2026-12-04): full-width live camera frame, but with the SAME
   vertical/horizontal ratio as the Add dialog's camera box (280x170) - wider
   is fine, taller-than-wide is not (user 2026-12-04: the 60vh-capped frame was
   far too big). aspect-ratio keeps the box at 280:170 at any width. */
.scan-wrap video {
  width: 100%;
  aspect-ratio: 280 / 170;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid #c4ccda;
  background: #000;
  display: block;
  margin-bottom: 8px;
}
/* Scan tab (user 2026-12-04): the tab is a full inline scan-and-add form,
   tit-for-tat with the Add dialog - the dialog-scoped label/input metrics do
   not apply outside <dialog>, so replicate them for the scan form. */
.scan-cam { position: relative; }
#tab-scan label { display: block; margin-bottom: 10px; }
#tab-scan label > input {
  display: block;
  width: 100%;
  margin-top: 4px;
  box-sizing: border-box;
}
#tab-scan label.qty-label { margin-bottom: -8px; }
/* the date input sits in a flex .date-row with the clear-X - the label>input
   width:100% rule above must not stretch it out of the row */
#tab-scan .date-row input { flex: 1 1 auto; min-width: 0; width: auto; margin-top: 0; }
#tab-scan .name-label { margin-bottom: 2px; }
#tab-scan #scan-hint:empty { display: none; }
#tab-scan .dlg-row { justify-content: flex-end; }
.cam-wrap video,
.preview-wrap img { width: 100%; margin: 0; }
/* Transient read confirmation rendered OVER the camera frame (user
   2026-11-14): the eyes are on the viewfinder, so the "barcode read"
   result flashes there - green when the product matched, plain dark
   when the barcode is unknown. */
#add-scan-flash,
#scan-scan-flash {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 8px;
  border-radius: 8px;
  background: rgba(0, 0, 0, .6);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
}
#add-scan-flash.ok,
#scan-scan-flash.ok { background: rgba(46, 125, 50, .88); }
.photo-btns {
  justify-content: center;
}
#add-photo-clear,
#scan-photo-clear {
  position: absolute;
  top: 4px;
  right: 4px;
  border: 1px solid #f5b5b0;
  background: #fde5e2;
  color: #b91c1c;
}
/* Name-box scan states (user 2026-11-14): green check when a scan filled
   the name from a known product; amber border when the barcode read but
   is unknown, so the name still needs typing. Cleared on manual edit. */
#add-dlg label.scan-hit::before,
#tab-scan label.scan-hit::before { content: '\2713  '; color: #2e7d32; font-weight: 700; }
#add-dlg input.scan-hit,
#tab-scan input.scan-hit { border-color: #2e7d32; }
#add-dlg input.scan-warn,
#tab-scan input.scan-warn { border-color: #e6911e; }
/* Add dialog lower line: Cancel left, "Add with photo" + "Add" right
   (the generic .dlg-row:first-child space-between would center the
   middle button; user wants app-style two-save-path layout). */
#add-dlg .dlg-row {
  justify-content: flex-end;
}
#add-dlg #add-cancel {
  margin-right: auto;
}

/* ---- Bottom tab bar + tab pages (user 2026-11-17) ---- */

#app { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }

#tabbar {
  position: fixed;
  bottom: 0;
  /* Align with the CONTENT box, not the .view box: .view is max-width 640px
     with 16px padding, so the bar is inset 16px per side (user 2026-11-17:
     it stuck out ~16px left/right of the item list). */
  left: 16px;
  right: 16px;
  margin: 0 auto;
  max-width: 608px; /* 640 - 2*16 */
  display: flex;
  /* Pale azure bar; only the ACTIVE tab gets the strong azure block
     (user 2026-11-17 - whole-bar azure made the focused tab hard to see). */
  background: #dce7fb;
  border-top: 1px solid var(--outline);
  height: calc(56px + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 40;
}
.tab-btn {
  flex: 1;
  min-width: 0; /* let the label shrink instead of overflowing the bar edge */
  border: none;
  background: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 0 2px;
  color: rgba(11, 87, 208, .72); /* azure-ish, not too pale */
  font-size: 11px;
  cursor: pointer;
  position: relative;
}
/* user 2026-12-04 (OnePlus Nord 2 / Firefox: the rightmost tab's label was
   clipped at the bar edge): truncate, never wrap - the same rule as the
   Android tab bar (2026-11-15). */
.tab-lb {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tab-btn.active { background: var(--primary); color: #fff; font-weight: 700; }
.tab-ic { font-size: 20px; line-height: 1; }
.tab-badge {
  position: absolute;
  top: 3px;
  right: calc(50% - 24px);
  background: var(--bad);
  color: #fff;
  border-radius: 10px;
  font-size: 10px;
  padding: 1px 5px;
  min-width: 16px;
  text-align: center;
}
.tabpage { padding-bottom: 8px; }

/* ---- Recipes tab (azure tiles like the Android app, user 2026-11-17) ---- */

.recipes-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.recipes-head h2 { margin: 8px 0; font-size: 20px; }
.recipe-card {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #def0ff; /* ~ lerp(white, #C9E6FF AzurePrimaryContainer, 0.6) */
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 8px;
  cursor: pointer;
  /* same lit-from-above gradient outline as the Android tiles */
  box-shadow: inset 0 2px 0 rgba(83, 83, 83, .08), inset 0 -2px 0 rgba(83, 83, 83, .28);
}
.star-btn { border: none; background: none; font-size: 20px; color: var(--text-variant); cursor: pointer; padding: 0 2px; }
.star-btn.on { color: #f9ab00; }
.recipe-title { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recipe-gen { display: grid; gap: 8px; margin: 12px 0; }
.recipe-steps { padding-left: 20px; }
.recipe-steps li { margin-bottom: 6px; }
details { margin: 12px 0; }
summary { cursor: pointer; font-weight: 600; }
.hist-day { margin: 8px 0 8px 12px; }

/* ---- Shopping tab (soft yellow-brown cards like the Android app, user 2026-11-17) ---- */

.shop-add { display: flex; gap: 8px; margin: 8px 0 12px; }
.shop-add input { flex: 1; }
.shop-card {
  display: flex;
  gap: 4px;
  align-items: flex-start;
  background: #f0e7d6; /* ~ lerp(white, #C89B5A, 0.40) - matches the Android tint */
  border-radius: 12px;
  padding: 4px 12px;
  margin-bottom: 8px;
  box-shadow: inset 0 2px 0 rgba(83, 83, 83, .08), inset 0 -2px 0 rgba(83, 83, 83, .28);
}
.shop-card.checked .shop-name { color: var(--text-variant); } /* gray, no strikethrough (user 2026-11-17) */
.shop-check { margin-top: 10px; width: 20px; height: 20px; flex: none; }
.shop-main { flex: 1; min-width: 0; }
.shop-line { display: flex; align-items: center; gap: 6px; min-height: 32px; cursor: pointer; }
.shop-name { flex: 1; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.shop-chev { color: var(--text-variant); font-size: 14px; }
.shop-drag {
  color: var(--text-variant);
  font-size: 18px;
  cursor: grab;
  padding: 4px;
  user-select: none;
  touch-action: none; /* the list must not scroll while dragging the handle */
}
.shop-card.dragging { position: relative; z-index: 5; opacity: .92; box-shadow: 0 6px 16px rgba(0, 0, 0, .18); }
.shop-meta .meta { margin: 2px 0; }
.shop-actions { margin-top: 4px; }

/* ---- Messages tab ---- */

.msg-banner.dismissed { opacity: .55; }
#messages-list .msg-banner { margin-bottom: 8px; }

/* ---- Inventory top line: search + Add item button on one row (user 2026-11-17) ---- */
.inv-topline {
  display: flex; gap: 8px; align-items: center; margin: 0 0 6px;
  /* user 2026-11-29: sticky - search + Add item stay reachable while the
     item list scrolls (opaque background + z-index so rows don't show through).
     Round 2: sticks BELOW the sticky header at --hdr-h instead of top:0 */
  position: sticky; top: var(--hdr-h, 56px); z-index: 5;
  background: var(--surface);
  padding: 6px 0;
  border-bottom: 1px solid var(--surface-dim);
}
.inv-topline .search { flex: 1; margin: 0; }
.inv-topline #add { flex: none; white-space: nowrap; }

/* Active tab label stands out: bold white text (user 2026-11-17) */
.tab-btn.active .tab-lb { font-weight: 800; }

/* ---- Fridge switching (user 2026-11-29) ---- */
.fridge-h { margin: 0; }
.fridge-name-btn {
  background: none; border: none; padding: 0; font: inherit; color: inherit;
  cursor: default; text-align: left;
}
.fridge-name-btn.switchable { cursor: pointer; text-decoration: underline dotted; }
.fridge-pill {
  display: flex; align-items: center; gap: 8px; width: 100%;
  margin: 6px 0; padding: 10px 14px;
  border-radius: 999px; border: 1px solid var(--outline);
  background: var(--surface); color: var(--text);
  cursor: pointer; font-size: 15px;
}
.fridge-pill.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.fridge-pill-name { flex: 1; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fridge-pill-x { flex: none; padding: 2px 6px; border-radius: 999px; opacity: .75; }
.fridge-pill-x:hover { opacity: 1; background: rgba(0,0,0,.08); }
.fridge-pill.active .fridge-pill-x:hover { background: rgba(255,255,255,.2); }
