/* Black & gold — the same palette as the landing page (css/landing.css):
   near-black #030303 surfaces, graphite #2c2c2e for raised cards and
   lines, and gold #ffdb89 as the single accent (buttons, focus, active
   tab, highlights). Danger/success stay semantic red/green on purpose:
   they signal state (low stock, errors), not brand. */
:root {
  --bg: #030303;
  --bg-elevated: #0e0e0f;
  --bg-card: #18181a;
  --border: #2c2c2e;
  --border-light: #3a3a3d;
  --text: #f4f1ee;
  --text-dim: #a39d98;
  --text-faint: #87827d;
  --accent: #ffdb89;
  --accent-hover: #ffe5a8;
  --accent-light: #ffe7b3;
  --accent-soft: rgba(255, 219, 137, 0.13);
  --on-accent: #030303;
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.14);
  --success: #34d399;
  --success-soft: rgba(52, 211, 153, 0.12);
  --hover-lift: rgba(255, 255, 255, 0.07);
  --hover-line: rgba(255, 255, 255, 0.1);
  --accent-line: rgba(255, 219, 137, 0.38);
  --skel-base: #1d1d1f;
  --skel-shine: rgba(255, 255, 255, 0.06);
  --clip-tint: rgba(255, 255, 255, 0.3);
  --radius: 10px;
  --radius-lg: 14px;
  font-size: 16px;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f4f1ea;
  --bg-elevated: #fbfaf6;
  --bg-card: #ffffff;
  --border: #e2ddd2;
  --border-light: #d3cdc0;
  --text: #1f2026;
  --text-dim: #5d616a;
  --text-faint: #60636a;
  --accent: #26282f;
  --accent-hover: #3b3e47;
  --accent-light: #34363f;
  --accent-soft: rgba(38, 40, 47, 0.07);
  --on-accent: #f7f4ee;
  --danger: #bd2a2a;
  --danger-soft: rgba(189, 42, 42, 0.09);
  --success: #00714a;
  --success-soft: rgba(0, 123, 80, 0.1);
  --hover-lift: rgba(0, 0, 0, 0.05);
  --hover-line: rgba(0, 0, 0, 0.08);
  --accent-line: rgba(38, 40, 47, 0.22);
  --skel-base: #ebe7de;
  --skel-shine: rgba(255, 255, 255, 0.75);
  --clip-tint: rgba(255, 255, 255, 0.16);
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* Applied to <body> while any dialog (#modal or #detail-modal) is open —
   showModal() alone stops clicks reaching the page behind it but not
   scroll/touch, so the background could still scroll underneath. */
body.body-scroll-locked {
  overflow: hidden;
  touch-action: none;
}

button, input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

/* Instant press feedback on every tappable control — the fastest possible
   confirmation that a tap registered, before whatever it triggers finishes. */
button:active, .card:active, .card-row:active, [role="button"]:active {
  opacity: 0.7;
  transition: opacity 0.1s ease;
}

:is(button, a, input, textarea, select, [tabindex]):focus-visible {
  outline: 2px solid var(--accent-light);
  outline-offset: 2px;
}
.card:focus-visible, .card-row:focus-visible {
  outline: 2px solid var(--accent-light);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Author `display` rules (.btn-icon, .link-btn, …) beat the UA stylesheet's
   [hidden] rule, so hidden buttons like Sign out and Clear filters stayed
   visible. One global rule instead of a per-class [hidden] each time. */
[hidden] { display: none !important; }

/* ─── Top bar ─────────────────────────────────────────────────────────── */
.topbar {
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: 20px;
  max-width: 1180px;
  margin: 0 auto;
  padding: 12px 20px;
}

.brand {
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.tabs {
  position: relative;
  display: flex;
  gap: 4px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
}

/* Sits behind the tab buttons and slides/resizes itself to the active one
   (see app.js moveTabIndicator) instead of each tab just snapping its own
   background on/off — one continuous pill reads as "this moved", not
   "this turned off, that turned on". */
.tab-indicator {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  border-radius: 999px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  z-index: 0;
  pointer-events: none;
  transform-origin: left center;
  opacity: 0;
}

/* Below ~700px, brand + business switcher + settings + alert pill alone can
   exceed the width available — .tabs (flex:1) then gets squeezed to
   nothing and the nav effectively disappears instead of just scrolling.
   Wrapping puts tabs on their own full-width row where they can always
   fall back to horizontal scroll instead of vanishing. */
@media (max-width: 700px) {
  .topbar-inner { flex-wrap: wrap; row-gap: 8px; }
  .tabs { order: 3; flex: 1 1 100%; }
  /* Brand + switcher + settings + alert pill overflowed a 375px screen. */
  .topbar-right { margin-left: auto; min-width: 0; flex-wrap: wrap; justify-content: flex-end; row-gap: 8px; }
}

.tab {
  position: relative;
  z-index: 1;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-dim);
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

/* rgba white, not a --bg-* token: those are near-identical to the header's
   own background, so the pill all but disappeared and only the brighter
   text color signaled anything happened. A translucent white lift reads
   as a clear pill against any dark surface it sits on. */
.tab:hover { background: var(--hover-lift); border-color: var(--hover-line); color: var(--text); }

/* The pill background itself now comes from .tab-indicator sliding behind
   the tabs — .tab.active only needs to recolor its own text/icon. */
.tab.active {
  background: transparent;
  color: var(--accent-light);
}
.tab.active:hover { background: var(--hover-lift); }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.auth-user-email {
  font-size: 0.82rem;
  color: var(--text-faint);
  white-space: nowrap;
}

.alert-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid rgba(248, 113, 113, 0.35);
  padding: 6px 12px;
  min-height: 32px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.alert-pill svg { flex-shrink: 0; }
.alert-pill[hidden] { display: none; }
.alert-pill::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--danger);
  flex-shrink: 0;
  animation: pulse-dot 1.4s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.7); }
}

/* ─── Auth ────────────────────────────────────────────────────────────── */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.auth-screen[hidden] { display: none; }

.auth-form {
  width: 100%;
  max-width: 360px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 24px;
}

.auth-brand {
  font-size: 1.4rem;
  margin-bottom: 4px;
}

#age-gate .auth-form { display: grid; gap: 12px; max-width: 360px; }
#age-gate .auth-form h1, #age-gate .auth-form p { margin: 0; }
.auth-form h1 {
  font-size: 1.1rem;
  margin: 0 0 4px;
}

.auth-form .hint {
  margin: 0 0 20px;
}

.auth-form .field {
  margin-bottom: 14px;
}

.auth-submit {
  width: 100%;
  margin-top: 6px;
}

.auth-error {
  color: var(--danger);
  background: var(--danger-soft);
  border: 1px solid rgba(248, 113, 113, 0.35);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.85rem;
  margin: 0 0 14px;
}

.auth-success {
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent-hover);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.85rem;
  margin: 0 0 14px;
}

.link-btn {
  display: block;
  margin: 14px auto 0;
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 0.82rem;
  text-decoration: underline;
  cursor: pointer;
  padding: 4px;
}
.link-btn:hover { color: var(--text); }

/* ─── Layout ──────────────────────────────────────────────────────────── */
main#app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px;
}

.panel { display: none; }
.panel.active { display: block; animation: panel-in 0.22s cubic-bezier(0.25, 0.8, 0.4, 1); }

@keyframes panel-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.panel-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.section-title {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
  flex: 1;
}

.discover-intro {
  margin-top: -8px;
  margin-bottom: 20px;
}
.discover-intro-inline { margin: 0; flex: 1; }

.discover-section { margin-bottom: 28px; }

.discover-heading {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin: 0 0 12px;
}

.discover-heading-ready { color: var(--success); }
.discover-heading-almost { color: var(--accent-light); }

.discover-view { display: none; }
.discover-view.active { display: block; animation: panel-in 0.22s cubic-bezier(0.25, 0.8, 0.4, 1); }

.subtabs {
  display: flex;
  gap: 4px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
  width: fit-content;
}

.subtab {
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 7px 16px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 500;
  font-size: 0.88rem;
  transition: background 0.15s, color 0.15s;
}
.subtab:hover { color: var(--text); }
.subtab.active { background: var(--accent); color: var(--on-accent); }

.search-wrap { flex: 1; }

.search-wrap input {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  color: var(--text);
  outline: none;
}

.search-wrap input:focus { border-color: var(--accent); }

.filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}

.filter-select {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  color: var(--text);
  font-size: 0.85rem;
  outline: none;
  cursor: pointer;
}
.filter-select:focus { border-color: var(--accent); }

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

/* Grid items default to min-width: auto, which lets their content (a long
   supplier name/email in a .row-sub, for instance) push the column wider
   than the grid track instead of wrapping — this is what actually
   constrains them to their column. */
.split-col { min-width: 0; }

@media (max-width: 820px) {
  .split { grid-template-columns: 1fr; }
}

/* ─── Buttons ─────────────────────────────────────────────────────────── */
.btn {
  border: none;
  border-radius: var(--radius);
  padding: 10px 16px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, transform 0.05s;
}
.btn:active { transform: scale(0.97); }

.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border-light);
}
.btn-secondary:hover { border-color: var(--accent); }

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--text); }

.btn-danger { background: transparent; color: var(--danger); border: 1px solid rgba(248,113,113,0.3); }
.btn-danger:hover { background: var(--danger-soft); }

.btn-sm { padding: 6px 10px; font-size: 0.82rem; border-radius: 8px; }

/* Icon-only variant of any .btn color (primary/ghost/danger) — square
   padding instead of the text button's horizontal padding, content
   centered. Used wherever a universally-recognizable icon (save, cancel,
   delete, sign out, clear) replaces a text label. */
.btn-icon {
  padding: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn-icon.btn-sm { padding: 6px; }

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 6px;
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { color: var(--text); background: var(--bg-card); }

.card-price-actions { display: flex; align-items: center; gap: 6px; }

.add-to-inv-btn, .log-pour-btn {
  border: 1px solid var(--border);
  background: var(--bg);
  min-width: 34px;
  min-height: 34px;
  padding: 4px;
}
.add-to-inv-btn:hover, .log-pour-btn:hover { color: var(--text); background: var(--bg-card); border-color: var(--text-dim); }

/* ─── Cards ───────────────────────────────────────────────────────────── */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}

.stack { display: flex; flex-direction: column; gap: 10px; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.08s;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.card:hover { border-color: var(--accent-light); }
.card:active { transform: scale(0.99); }

.card.low-stock {
  border-color: rgba(248, 113, 113, 0.5);
  background: linear-gradient(180deg, var(--danger-soft), var(--bg-card) 40%);
}

.card-media {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  background: radial-gradient(120% 120% at 50% 30%, var(--bg-card) 0%, var(--bg-elevated) 75%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  overflow: hidden;
}
/* Only the emoji fallback needs breathing room — a photo fills the box
   edge to edge, or the gradient background shows through as a border. */
.card-media:not(:has(img)) { padding: 10px; }
.card-media img { width: 100%; height: 100%; object-fit: cover; display: block; }

.card-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.card-title { font-weight: 700; font-size: 1rem; }

.card-subtitle {
  font-size: 0.8rem;
  color: var(--text-faint);
  line-height: 1.4;
}

.card-history {
  font-size: 0.78rem;
  color: var(--text-faint);
  line-height: 1.4;
  font-style: italic;
  border-top: 1px solid var(--border-light);
  padding-top: 6px;
  margin-top: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-price-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  /* Pushed to the card's bottom edge regardless of how many lines the
     subtitle/history text above it take up, so price pills line up across
     a row of cards instead of trailing right after whatever text ends. */
  margin-top: auto;
}

.pill-price {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  color: var(--text);
  font-weight: 700;
  font-size: 0.82rem;
  padding: 6px 12px;
  border-radius: 999px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--accent);
  border: none;
  color: var(--on-accent);
  font-weight: 700;
  font-size: 0.82rem;
  padding: 7px 14px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  min-height: 36px;
  transition: background 0.15s;
}
.pill-btn:hover { background: var(--accent-hover); }
.pill-btn.pill-btn-outline {
  background: transparent;
  border: 1px solid var(--border-light);
  color: var(--text);
}
.pill-btn.pill-btn-outline:hover { border-color: var(--accent); }

.badge {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 3px 7px;
  border-radius: 6px;
  background: var(--bg-elevated);
  color: var(--text-faint);
  white-space: nowrap;
}

.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-accent { background: var(--accent-soft); color: var(--accent-light); }

.badge, .cost-line {
  font-variant-numeric: tabular-nums;
}

.card-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  gap: 12px;
  cursor: pointer;
}
.card-row:hover { border-color: var(--accent-light); }

.row-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.row-title { font-weight: 600; font-size: 0.95rem; }
.row-sub { font-size: 0.8rem; color: var(--text-dim); }

.low-stock-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--danger-soft);
  border: 1px solid rgba(248, 113, 113, 0.35);
  color: var(--danger);
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 14px;
  font-size: 0.88rem;
  font-weight: 500;
}
.low-stock-banner[hidden] { display: none; }

.empty-state {
  color: var(--text-faint);
  text-align: center;
  padding: 40px 20px;
  font-size: 0.9rem;
}

/* Mascot portrait on the main empty lists (one per screen; the "no match" and
   secondary empties stay text-only so two never show at once). Pure CSS, so no
   markup changes; shown only when the paragraph itself is visible. */
#inventory-empty::before, #recipes-empty::before, #discover-empty::before,
#ideas-empty::before, #suppliers-empty::before, #orders-empty::before {
  content: "";
  display: block;
  width: 88px;
  height: 98px;
  margin: 0 auto 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: #2a2d2e url(/images/mascot-bust.webp) center / cover no-repeat;
}

/* ─── Modal ───────────────────────────────────────────────────────────── */
dialog#modal {
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  color: var(--text);
  padding: 0;
  width: min(560px, 92vw);
  max-height: 88vh;
  opacity: 1;
  transform: scale(1);
  transition: opacity 0.16s cubic-bezier(0.34, 1.3, 0.64, 1), transform 0.16s cubic-bezier(0.34, 1.3, 0.64, 1),
    overlay 0.16s allow-discrete, display 0.16s allow-discrete;
}
dialog#modal:not([open]) {
  opacity: 0;
  transform: scale(0.96);
}
@starting-style {
  dialog#modal[open] {
    opacity: 0;
    transform: scale(0.96);
  }
}

dialog#modal::backdrop {
  background: rgba(3, 3, 3, 0.72);
  backdrop-filter: blur(2px);
  opacity: 1;
  transition: opacity 0.16s ease, overlay 0.16s allow-discrete, display 0.16s allow-discrete;
}
@starting-style {
  dialog#modal[open]::backdrop { opacity: 0; }
}

.modal-form {
  display: flex;
  flex-direction: column;
  max-height: 88vh;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}

.modal-head h3 { margin: 0; font-size: 1.05rem; }

.modal-body {
  padding: 16px 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
}

/* ─── Recipe detail page ──────────────────────────────────────────────── */
/* Landscape on anything roomy enough for it: a fixed photo pane on the
   left, a scrollable info pane on the right, so looking something up never
   forces a scroll past the photo first. Narrow/short viewports fall back
   to the original stacked layout below (see .detail-split breakpoint). */
dialog.detail-dialog {
  position: relative;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  color: var(--text);
  padding: 0;
  width: min(860px, 94vw);
  height: min(560px, 86vh);
  max-height: 86vh;
  overflow: hidden;
  opacity: 1;
  transform: scale(1);
  transition: opacity 0.16s cubic-bezier(0.34, 1.3, 0.64, 1), transform 0.16s cubic-bezier(0.34, 1.3, 0.64, 1),
    overlay 0.16s allow-discrete, display 0.16s allow-discrete;
}
dialog.detail-dialog:not([open]) { opacity: 0; transform: scale(0.96); }
@starting-style {
  dialog.detail-dialog[open] { opacity: 0; transform: scale(0.96); }
}
dialog.detail-dialog::backdrop {
  background: rgba(3, 3, 3, 0.72);
  backdrop-filter: blur(2px);
  opacity: 1;
  transition: opacity 0.16s ease, overlay 0.16s allow-discrete, display 0.16s allow-discrete;
}
@starting-style {
  dialog.detail-dialog[open]::backdrop { opacity: 0; }
}

#detail-body {
  height: 100%;
  overflow: hidden;
}

.detail-close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  background: rgba(3, 3, 3, 0.6);
  backdrop-filter: blur(4px);
  color: #fff;
}
.detail-close:hover { background: rgba(3, 3, 3, 0.8); }

.detail-split {
  display: flex;
  height: 100%;
  min-height: 0;
}

.detail-hero {
  position: relative;
  flex: 0 0 42%;
  width: 42%;
  height: 100%;
  background: radial-gradient(120% 120% at 50% 30%, var(--bg-card) 0%, var(--bg-elevated) 75%);
}
.detail-hero img { width: 100%; height: 100%; object-fit: cover; display: block; }
.detail-hero-fallback {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 4rem;
}

.detail-panel {
  flex: 1 1 auto;
  min-width: 0;
  overflow-y: auto;
}

/* Below this, the photo loses too much width to read well as a side pane —
   stack it on top instead and let the whole dialog scroll, same as before. */
@media (max-width: 680px), (max-height: 560px) {
  dialog.detail-dialog {
    width: min(480px, 92vw);
    height: auto;
    max-height: 88vh;
  }
  #detail-body { height: auto; max-height: 88vh; overflow-y: auto; }
  .detail-split { flex-direction: column; height: auto; }
  .detail-hero { flex-basis: auto; width: 100%; aspect-ratio: 1 / 1; height: auto; }
  .detail-panel { overflow-y: visible; }
}

.detail-badge-float {
  position: absolute;
  top: 14px;
  left: 14px;
  background: rgba(3, 3, 3, 0.72);
  backdrop-filter: blur(6px);
  border-radius: 10px;
  padding: 8px 12px;
  color: #fff;
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}
.detail-badge-value { font-weight: 700; font-size: 1rem; }
.detail-badge-label { font-size: 0.7rem; opacity: 0.8; }

.detail-badge-corner {
  position: absolute;
  bottom: 14px;
  right: 14px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  backdrop-filter: blur(6px);
}

.detail-info { padding: 16px 18px 4px; }
.detail-title { margin: 0 0 4px; font-size: 1.3rem; }
.detail-subtitle { margin: 0; color: var(--text-dim); font-size: 0.9rem; }

.detail-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.detail-stat {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-dim);
  font-size: 0.85rem;
}
.detail-stat svg { color: var(--accent-light); flex-shrink: 0; }

.detail-section { padding: 14px 18px; border-top: 1px solid var(--border); }
.detail-section h3 {
  margin: 0 0 8px;
  font-size: 0.78rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.detail-text { margin: 0; color: var(--text-dim); font-size: 0.9rem; line-height: 1.5; }
.detail-text-history { font-style: italic; }

.detail-ingredient-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.detail-ingredient-list li {
  display: flex;
  justify-content: space-between;
  font-size: 0.88rem;
}
.detail-ingredient-list li span:last-child { color: var(--text-faint); font-variant-numeric: tabular-nums; }

.detail-actions { padding: 14px 18px 18px; display: flex; gap: 10px; }
.detail-actions .btn { flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }

/* ─── Form fields ─────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 5px; }
/* Author styles always beat the UA stylesheet's [hidden] rule, even at
   equal specificity — without this, a hidden .field (like the sign-up
   form's confirm-password/consent fields when in sign-in mode) stays
   visible because .field's own `display: flex` above wins instead. */
.field[hidden] { display: none; }
.field label { font-size: 0.8rem; color: var(--text-dim); font-weight: 500; }

.field input, .field textarea, .field select {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 9px 11px;
  outline: none;
  width: 100%;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.field input:focus, .field textarea:focus, .field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.field textarea { resize: vertical; min-height: 70px; }

.field-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.field-row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }

/* ─── Stepper (amount +/− control) ───────────────────────────────────── */
.stepper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 999px;
  padding: 4px;
}
.stepper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.stepper-btn {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: var(--bg-elevated);
  color: var(--text-dim);
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, color 0.15s ease;
}
.stepper-btn:hover { background: var(--accent-soft); color: var(--accent-light); }
.stepper-btn:active { transform: scale(0.88); }
.stepper-btn:disabled { opacity: 0.4; cursor: default; transform: none; }

.stepper-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  padding: 0;
  text-align: center;
  font-size: 1.05rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
/* Hide the native up/down spinner — the pill's own +/− buttons replace it. */
.stepper-input::-webkit-outer-spin-button,
.stepper-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.stepper-input[type="number"] { -moz-appearance: textfield; appearance: textfield; }

@media (max-width: 480px) {
  .field-row, .field-row-3 { grid-template-columns: 1fr; }
}

.ingredient-row, .item-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr auto;
  gap: 8px;
  align-items: center;
}

@media (max-width: 480px) {
  .ingredient-row, .item-row { grid-template-columns: 1fr; }
}

.subhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 4px;
}
.subhead h4 { margin: 0; font-size: 0.85rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.03em; }

.hint { font-size: 0.78rem; color: var(--text-faint); }
.scope-label { margin: -8px 0 14px; }

.business-switcher {
  min-width: 140px;
  max-width: 180px;
}
@media (max-width: 700px) {
  .business-switcher { min-width: 0; max-width: 140px; }
}

.cost-line {
  display: flex;
  justify-content: space-between;
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  border-radius: 8px;
  padding: 10px 12px;
  font-weight: 600;
  color: var(--accent-light);
}

/* ─── Toast ───────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  opacity: 0;
  pointer-events: none;
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  font-size: 0.88rem;
  font-weight: 600;
  max-width: calc(100vw - 32px);
  z-index: 100;
  transition: opacity 0.2s cubic-bezier(0.34, 1.3, 0.64, 1), transform 0.2s cubic-bezier(0.34, 1.3, 0.64, 1);
}
.toast:not([hidden]) { display: flex; align-items: center; gap: 8px; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast svg { flex-shrink: 0; }
.toast.has-action { pointer-events: auto; }
.toast-action {
  flex-shrink: 0;
  margin-left: 6px;
  padding: 4px 12px;
  border: 1px solid currentColor;
  border-radius: 999px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
}
.toast-action:hover:not(:disabled) { background: rgba(255, 255, 255, 0.1); }
.toast-action:disabled { opacity: 0.5; cursor: default; }
.toast-error { background: var(--danger-soft); border-color: rgba(248, 113, 113, 0.35); color: var(--danger); }
.toast-success { background: var(--success-soft); border-color: rgba(52, 211, 153, 0.35); color: var(--success); }

.status-tag {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 6px;
}
.status-draft { background: var(--bg-elevated); color: var(--text-faint); }
.status-sent { background: var(--accent-soft); color: var(--accent-light); }
.status-received { background: var(--success-soft); color: var(--success); }

/* ─── Standalone legal pages (privacy.html, terms.html) ──────────────── */
.legal {
  max-width: 720px;
  margin: 0 auto;
  padding: 48px 24px 80px;
  line-height: 1.6;
}
.legal h1 { margin-bottom: 4px; }
.legal .updated { color: var(--text-faint); font-size: 0.85rem; margin-bottom: 32px; }
.legal h2 { margin-top: 32px; font-size: 1.1rem; }
.legal a { color: var(--accent); }
.legal .back { display: inline-block; margin: 0 0 24px; }

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

.auth-consent-label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--text-dim);
  cursor: pointer;
}
.auth-consent-label input[type="checkbox"] {
  margin-top: 2px;
  flex-shrink: 0;
}

/* ─── Theme switch (js/theme.js) ──────────────────────────────────────── */
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.settings-danger { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.settings-account-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.settings-row-label { display: grid; gap: 2px; }
.settings-row-label strong { font-size: 0.9rem; font-weight: 600; }
.settings-row-label span { font-size: 0.8rem; color: var(--text-dim); }
.theme-switch {
  position: relative;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  border: 1px solid var(--border-light);
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
  overflow: hidden;
  transition: border-color 0.2s, background 0.2s;
}
.theme-switch:hover { border-color: var(--accent); }
.theme-switch svg {
  grid-area: 1 / 1;
  transition: transform 0.5s cubic-bezier(0.34, 1.4, 0.64, 1), opacity 0.3s ease;
}
/* dark: moon showing, sun spun away; light: the reverse */
.theme-switch .ts-sun { transform: rotate(-90deg) scale(0); opacity: 0; }
.theme-switch .ts-moon { transform: rotate(0) scale(1); opacity: 1; }
:root[data-theme="light"] .theme-switch .ts-sun { transform: rotate(0) scale(1); opacity: 1; }
:root[data-theme="light"] .theme-switch .ts-moon { transform: rotate(90deg) scale(0); opacity: 0; }

/* The theme change itself: the new theme grows out of the switch as a
   circle (View Transitions; browsers without it just swap instantly). */
::view-transition-old(root),
::view-transition-new(root) { animation: none; mix-blend-mode: normal; }

/* ─── Shimmer skeletons — placeholders while lists load ───────────────── */
.skel {
  position: relative;
  display: block;
  overflow: hidden;
  border-radius: 6px;
  background: var(--skel-base);
}
.skel::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, transparent 20%, var(--skel-shine) 50%, transparent 80%);
  transform: translateX(-100%);
  animation: skel-shimmer 1.5s ease-in-out infinite;
}
@keyframes skel-shimmer { to { transform: translateX(100%); } }
.skel-card { cursor: default; pointer-events: none; }
.skel-card:hover { border-color: var(--border); }
.skel-media { width: 100%; aspect-ratio: 1 / 1; border-radius: 12px; }
.skel-line { height: 12px; }
.skel-line--lg { height: 16px; }
.skel-w40 { width: 40%; }
.skel-w45 { width: 45%; }
.skel-w60 { width: 60%; }
.skel-w70 { width: 70%; }
.skel-avatar { width: 36px; height: 36px; border-radius: 999px; flex-shrink: 0; }
.skel-rowline { display: flex; align-items: center; gap: 12px; }
.skel-rowline > div { flex: 1; display: grid; gap: 8px; }

/* ─── Clipped hover circle on primary buttons (js/clip.js) ────────────── */
.clip-host { position: relative; overflow: hidden; isolation: isolate; }
.clip-circle {
  position: absolute;
  top: 0;
  left: 0;
  /* Behind the label (negative z-index inside the button's isolated
     stacking context) and a plain lighter tint, so the button brightens
     under the cursor instead of inverting its colours. */
  z-index: -1;
  border-radius: 50%;
  background: var(--clip-tint);
  pointer-events: none;
  transform: scale(0);
  will-change: transform;
}

/* ─── Button feedback (js/feedback.js) ────────────────────────────────────
   The button's own content and the feedback icon share one grid cell and
   swap with a scale + blur, so the button never changes size. */
.fb { display: inline-grid; place-items: center; }
.fb > .fb-idle, .fb > .fb-face {
  grid-area: 1 / 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: inherit;
  transition: opacity 0.22s ease, transform 0.32s cubic-bezier(0.34, 1.5, 0.64, 1), filter 0.22s ease;
}
.fb > .fb-face { opacity: 0; transform: scale(0.4); filter: blur(4px); pointer-events: none; }
.fb[data-fb] > .fb-idle { opacity: 0; transform: scale(0.4); filter: blur(4px); }
.fb[data-fb] > .fb-face { opacity: 1; transform: scale(1); filter: blur(0); }
.fb[data-fb="ok"] { color: var(--success); }
.btn-primary.fb[data-fb="ok"] { color: var(--on-accent); }
.fb[data-fb="err"] { color: var(--danger); }
.btn-primary.fb[data-fb="err"] { background: var(--danger); color: #fff; }

.fb-ico-busy { animation: fb-spin 0.7s linear infinite; }
.fb-ico-ok path, .fb-ico-err path { stroke-dasharray: 1; stroke-dashoffset: 1; animation: fb-draw 0.38s cubic-bezier(0.65, 0, 0.35, 1) 0.06s forwards; }
.fb-ico-err path + path { animation-delay: 0.16s; }
.fb-shake { animation: fb-shake 0.42s cubic-bezier(0.36, 0.07, 0.19, 0.97); }
@keyframes fb-spin { to { transform: rotate(360deg); } }
@keyframes fb-draw { to { stroke-dashoffset: 0; } }
@keyframes fb-shake {
  15%, 85% { transform: translateX(-1px); }
  30%, 70% { transform: translateX(3px); }
  45%, 55% { transform: translateX(-4px); }
  50% { transform: translateX(4px); }
}

/* ─── Count-up money figures (js/countup.js) ──────────────────────────── */
.count-up { font-variant-numeric: tabular-nums; display: inline-block; transition: filter 0.4s ease; }
.count-up.is-counting { filter: blur(0.4px); }

/* Pinch-zoom is allowed (no maximum-scale in the viewport meta), so stop
   iOS Safari auto-zooming into any field under 16px when it's tapped. */
@media (pointer: coarse) {
  input, select, textarea { font-size: max(16px, 1em) !important; }
}

.auth-guest-link { display: block; margin-top: 10px; text-align: center; font-size: 13px; color: var(--text-muted, inherit); text-decoration: underline; text-underline-offset: 3px; }
.settings-export { flex-wrap: wrap; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.settings-export-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.guest-bar { display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap; padding: 8px 20px; background: var(--bg-elevated); border-bottom: 1px solid var(--border); font-size: 0.85rem; color: var(--text-dim); text-align: center; }
.guest-bar[hidden] { display: none; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.settings-help { flex-wrap: wrap; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.settings-links { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.app-footer { max-width: 1180px; margin: 48px auto 0; padding: 20px 20px 32px; border-top: 1px solid var(--border); color: var(--text-dim); font-size: 0.8rem; }
.app-footer p { margin: 0 0 6px; }
.app-footer a { color: var(--text-dim); text-decoration: underline; }
.app-footer a:hover { color: var(--text); }
.settings-account { padding-bottom: 16px; margin-bottom: 4px; border-bottom: 1px solid var(--border); }

/* Selling price / margin line on recipe cards and the recipe detail page */
.card-margin { color: var(--text); font-weight: 500; }
.detail-margin { margin: 8px 0 0; font-size: 0.9rem; color: var(--text-dim); }
