/* ══════════════════════════════════════════════════════════════════════════
   NutriLog — Material Design 2 theme
   https://m2.material.io  ·  light + dark (follows the OS setting)
   ══════════════════════════════════════════════════════════════════════════ */

/* ── FONTS (self-hosted) ─────────────────────────────────────────────────── */
@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url(../fonts/roboto-latin.woff2) format('woff2');
}
@font-face {
  font-family: 'Roboto Mono';
  font-style: normal;
  font-weight: 400 500;
  font-display: swap;
  src: url(../fonts/roboto-mono-latin.woff2) format('woff2');
}
@font-face {
  font-family: 'Material Icons';
  font-style: normal;
  font-weight: 400;
  font-display: block;
  src: url(../fonts/material-icons.woff2) format('woff2');
}

/* ── THEME TOKENS ────────────────────────────────────────────────────────── */
:root {
  color-scheme: light;

  --primary:         #2E7D32;   /* Green 800 */
  --primary-variant: #1B5E20;   /* Green 900 */
  --on-primary:      #FFFFFF;
  --secondary:       #FFAB00;   /* Amber A700 */
  --on-secondary:    #000000;
  --background:      #F5F5F5;
  --surface:         #FFFFFF;
  --surface-1:       #FFFFFF;   /* elevated surfaces — overlays only matter in dark */
  --surface-2dp:     #FFFFFF;
  --surface-4:       #FFFFFF;
  --surface-8:       #FFFFFF;
  --surface-24:      #FFFFFF;
  --on-surface:      rgba(0,0,0,.87);
  --on-surface-med:  rgba(0,0,0,.60);
  --on-surface-dis:  rgba(0,0,0,.38);
  --divider:         rgba(0,0,0,.12);
  --outline:         rgba(0,0,0,.24);
  --track:           rgba(46,125,50,.16);
  --error:           #B00020;
  --error-tint:      rgba(176,0,32,.08);
  --warn:            #EF6C00;
  --success:         #2E7D32;
  --success-tint:    rgba(46,125,50,.10);
  --appbar-bg:       var(--primary);
  --appbar-fg:       var(--on-primary);
  --field-bg:        rgba(0,0,0,.04);
  --field-bg-hover:  rgba(0,0,0,.07);
  --field-line:      rgba(0,0,0,.42);
  --selected:        rgba(46,125,50,.12);
  --hover:           rgba(0,0,0,.04);
  --chip-bg:         rgba(0,0,0,.08);
  --primary-text:    var(--primary);
  --scrim:           rgba(0,0,0,.32);
  --snackbar-bg:     #333333;
  --snackbar-fg:     rgba(255,255,255,.87);
  --snackbar-action: #FFD54F;

  --shadow-1:  0 2px 1px -1px rgba(0,0,0,.2), 0 1px 1px 0 rgba(0,0,0,.14), 0 1px 3px 0 rgba(0,0,0,.12);
  --shadow-2:  0 3px 1px -2px rgba(0,0,0,.2), 0 2px 2px 0 rgba(0,0,0,.14), 0 1px 5px 0 rgba(0,0,0,.12);
  --shadow-4:  0 2px 4px -1px rgba(0,0,0,.2), 0 4px 5px 0 rgba(0,0,0,.14), 0 1px 10px 0 rgba(0,0,0,.12);
  --shadow-6:  0 3px 5px -1px rgba(0,0,0,.2), 0 6px 10px 0 rgba(0,0,0,.14), 0 1px 18px 0 rgba(0,0,0,.12);
  --shadow-8:  0 5px 5px -3px rgba(0,0,0,.2), 0 8px 10px 1px rgba(0,0,0,.14), 0 3px 14px 2px rgba(0,0,0,.12);
  --shadow-16: 0 8px 10px -5px rgba(0,0,0,.2), 0 16px 24px 2px rgba(0,0,0,.14), 0 6px 30px 5px rgba(0,0,0,.12);
  --shadow-24: 0 11px 15px -7px rgba(0,0,0,.2), 0 24px 38px 3px rgba(0,0,0,.14), 0 9px 46px 8px rgba(0,0,0,.12);

  --font: 'Roboto', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'Roboto Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --radius: 4px;
  --appbar-h: 56px;
  --drawer-w: 256px;

  /* Legacy aliases — page scripts write these into inline styles. */
  --bg:         var(--background);
  --surface-2:  var(--field-bg);
  --border:     var(--divider);
  --text:       var(--on-surface);
  --muted:      var(--on-surface-med);
  --accent:     var(--primary);
  --accent-dim: var(--selected);
  --green:      var(--success);
  --red:        var(--error);
  --r:          var(--radius);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;

    --primary:         #A5D6A7;   /* Green 200 — desaturated for dark */
    --primary-variant: #81C784;
    --on-primary:      #000000;
    --secondary:       #FFD54F;   /* Amber 300 */
    --on-secondary:    #000000;
    --background:      #121212;
    --surface:         #121212;
    --surface-1:       #1E1E1E;   /* 1dp — 5% white overlay */
    --surface-2dp:     #222222;
    --surface-4:       #272727;
    --surface-8:       #2E2E2E;
    --surface-24:      #383838;
    --on-surface:      rgba(255,255,255,.87);
    --on-surface-med:  rgba(255,255,255,.60);
    --on-surface-dis:  rgba(255,255,255,.38);
    --divider:         rgba(255,255,255,.12);
    --outline:         rgba(255,255,255,.24);
    --track:           rgba(165,214,167,.18);
    --error:           #CF6679;
    --error-tint:      rgba(207,102,121,.12);
    --warn:            #FFB74D;
    --success:         #A5D6A7;
    --success-tint:    rgba(165,214,167,.12);
    --appbar-bg:       var(--surface-4);
    --appbar-fg:       rgba(255,255,255,.87);
    --field-bg:        rgba(255,255,255,.06);
    --field-bg-hover:  rgba(255,255,255,.09);
    --field-line:      rgba(255,255,255,.50);
    --selected:        rgba(165,214,167,.16);
    --hover:           rgba(255,255,255,.05);
    --chip-bg:         rgba(255,255,255,.10);
    --scrim:           rgba(0,0,0,.50);
    --snackbar-bg:     #E0E0E0;
    --snackbar-fg:     rgba(0,0,0,.87);
    --snackbar-action: #2E7D32;
  }
}

/* ── BASE ────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--background);
  color: var(--on-surface);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.43;
  letter-spacing: .25px;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--primary-text); }
img { max-width: 100%; }
strong, b { font-weight: 500; }

.material-icons {
  font-family: 'Material Icons';
  font-weight: normal;
  font-style: normal;
  font-size: 24px;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  display: inline-block;
  white-space: nowrap;
  word-wrap: normal;
  direction: ltr;
  font-feature-settings: 'liga';
  -webkit-font-feature-settings: 'liga';
  -webkit-font-smoothing: antialiased;
  user-select: none;
  flex-shrink: 0;
}
.material-icons.md-18 { font-size: 18px; }
.material-icons.md-20 { font-size: 20px; }
.material-icons.md-36 { font-size: 36px; }
.material-icons.md-48 { font-size: 48px; }

/* ── TYPOGRAPHY ──────────────────────────────────────────────────────────── */
.h4        { font-size: 34px; font-weight: 400; letter-spacing: .25px; line-height: 1.15; }
.h5        { font-size: 24px; font-weight: 400; letter-spacing: 0; line-height: 1.25; }
.h6        { font-size: 20px; font-weight: 500; letter-spacing: .15px; line-height: 1.3; }
.subtitle1 { font-size: 16px; font-weight: 400; letter-spacing: .15px; }
.subtitle2 { font-size: 14px; font-weight: 500; letter-spacing: .1px; }
.body1     { font-size: 16px; letter-spacing: .5px; line-height: 1.5; }
.body2     { font-size: 14px; letter-spacing: .25px; line-height: 20px; color: var(--on-surface-med); }
.caption   { font-size: 12px; letter-spacing: .4px; color: var(--on-surface-med); }
.overline  { font-size: 10px; font-weight: 500; letter-spacing: 1.5px; text-transform: uppercase; color: var(--on-surface-med); line-height: 16px; }
.mono      { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.text-primary { color: var(--primary-text); }
.text-error   { color: var(--error); }
.text-warn    { color: var(--warn); }
.text-muted   { color: var(--on-surface-med); }

/* Page header block inside <main> */
.page-title    { font-size: 24px; font-weight: 400; line-height: 1.25; margin-bottom: 4px; }
.page-subtitle { font-size: 14px; color: var(--on-surface-med); letter-spacing: .25px; margin-bottom: 16px; }
.section-head  { font-size: 10px; font-weight: 500; letter-spacing: 1.5px; text-transform: uppercase; color: var(--on-surface-med); margin: 24px 4px 8px; line-height: 16px; }
p.section-head { margin: 20px 0 10px; }

/* ── TOP APP BAR ─────────────────────────────────────────────────────────── */
.app-header {
  position: sticky; top: 0; z-index: 100;
  background: var(--appbar-bg); color: var(--appbar-fg);
  box-shadow: var(--shadow-4);
  padding-top: env(safe-area-inset-top);
}
.top-app-bar {
  height: var(--appbar-h);
  display: flex; align-items: center;
  padding: 0 4px;
}
.top-app-bar .title {
  flex: 1; min-width: 0;
  font-size: 20px; font-weight: 500; letter-spacing: .15px;
  padding-left: 12px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.top-app-bar .brand {
  display: none; align-items: center; gap: 12px;
  width: calc(var(--drawer-w) - 4px); padding-left: 12px;
  font-size: 20px; font-weight: 500; letter-spacing: .15px;
  color: inherit; text-decoration: none;
}
.top-app-bar .btn { color: inherit; }
.top-app-bar .btn:hover { background: rgba(255,255,255,.12); }

/* ── ICON BUTTON ─────────────────────────────────────────────────────────── */
.icon-btn {
  width: 48px; height: 48px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: none; border: none; color: inherit; cursor: pointer;
  text-decoration: none; flex-shrink: 0;
  transition: background .15s;
  -webkit-appearance: none;
}
.icon-btn:hover { background: var(--hover); }
.app-header .icon-btn:hover { background: rgba(255,255,255,.12); }
.icon-btn.sm { width: 36px; height: 36px; }
.icon-btn.sm .material-icons { font-size: 20px; }
.icon-btn.muted { color: var(--on-surface-med); }

/* ── NAVIGATION DRAWER ───────────────────────────────────────────────────── */
.drawer {
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 300;
  width: var(--drawer-w); max-width: calc(100vw - 56px);
  background: var(--surface-24);
  box-shadow: var(--shadow-16);
  padding: calc(8px + env(safe-area-inset-top)) 8px 8px;
  transform: translateX(-105%);
  transition: transform .25s cubic-bezier(.4,0,.2,1);
  overflow-y: auto;
}
.drawer.open { transform: none; }
.drawer-head { padding: 16px 8px 12px; display: flex; align-items: center; gap: 12px; color: var(--primary-text); }
.drawer-head .h6 { color: var(--on-surface); }
.drawer-item {
  height: 40px; border-radius: var(--radius);
  display: flex; align-items: center; gap: 32px;
  padding: 0 8px; margin-bottom: 4px;
  font-size: 14px; font-weight: 500; letter-spacing: .25px;
  color: var(--on-surface); text-decoration: none;
  transition: background .15s;
}
button.drawer-item { width: 100%; border: none; background: none; font-family: inherit; cursor: pointer; text-align: left; }
.drawer-item .material-icons { color: var(--on-surface-med); }
.drawer-item:hover { background: var(--hover); }
.drawer-item.active { background: var(--selected); color: var(--primary-text); }
.drawer-item.active .material-icons { color: var(--primary-text); }
.drawer hr { border: none; border-top: 1px solid var(--divider); margin: 8px 0; }
.drawer-scrim {
  position: fixed; inset: 0; z-index: 250;
  background: var(--scrim);
  opacity: 0; pointer-events: none;
  transition: opacity .25s;
}
.drawer-scrim.open { opacity: 1; pointer-events: auto; }

/* ── LAYOUT ──────────────────────────────────────────────────────────────── */
main {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px calc(96px + env(safe-area-inset-bottom));
}
main.wide { max-width: 1200px; }

@media (min-width: 1024px) {
  .drawer {
    top: calc(var(--appbar-h) + env(safe-area-inset-top));
    z-index: 50;
    transform: none;
    box-shadow: none;
    background: var(--surface);
    border-right: 1px solid var(--divider);
    padding-top: 8px;
  }
  .drawer { z-index: 150; }   /* above the header's tab row, which starts after it */
  .app-header .tabs { margin-left: var(--drawer-w); }
  .app-header .tab { flex: 0 0 auto; min-width: 112px; }
  .drawer .drawer-head, .drawer-scrim, .nav-toggle { display: none; }
  .top-app-bar .brand { display: flex; }
  .top-app-bar .title { padding-left: 16px; }
  .app-shell { margin-left: var(--drawer-w); }
  main { padding: 24px 24px 96px; }
}

/* ── CARD ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface-1);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  padding: 16px;
  margin-bottom: 16px;
}
.card.flush { padding: 0; }
.card-header { padding: 16px 16px 0; display: flex; align-items: center; gap: 8px; }
.card-header .h6 { flex: 1; min-width: 0; }
.card-body { padding: 16px; }
.card-actions {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
  padding: 8px; min-height: 52px;
}
.card-actions .spacer { flex: 1; }
.card-actions.bordered { border-top: 1px solid var(--divider); }

/* ── BUTTONS ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; min-width: 64px; padding: 0 16px;
  border: none; border-radius: var(--radius);
  font-family: var(--font); font-size: 14px; font-weight: 500;
  letter-spacing: 1.25px; text-transform: uppercase; line-height: 1;
  white-space: nowrap; text-decoration: none; cursor: pointer;
  background: transparent; color: var(--primary-text);
  transition: background .15s, box-shadow .15s, opacity .15s;
  -webkit-appearance: none;
}
.btn .material-icons { font-size: 18px; margin-left: -4px; }
.btn:hover { background: var(--selected); }
.btn:disabled { opacity: .38; cursor: default; pointer-events: none; box-shadow: none; }
.btn-text      { padding: 0 8px; }
.btn-primary,
.btn-contained { background: var(--primary); color: var(--on-primary); box-shadow: var(--shadow-2); }
.btn-primary:hover,
.btn-contained:hover { background: var(--primary); box-shadow: var(--shadow-4); filter: brightness(1.06); }
.btn-secondary,
.btn-outlined  { border: 1px solid var(--outline); padding: 0 15px; }
.btn-outlined.active,
.btn-secondary.active { background: var(--selected); border-color: var(--primary); }
.btn-muted     { color: var(--on-surface-med); }
.btn-muted:hover { background: var(--hover); }
.btn-danger    { color: var(--error); }
.btn-danger:hover { background: var(--error-tint); }
.btn-full      { width: 100%; }
.btn-lg        { height: 48px; font-size: 15px; }

/* ── FAB ─────────────────────────────────────────────────────────────────── */
.fab {
  position: fixed; z-index: 90;
  right: 16px; bottom: calc(16px + env(safe-area-inset-bottom));
  height: 48px; padding: 0 20px 0 16px; border-radius: 24px;
  display: inline-flex; align-items: center; gap: 12px;
  background: var(--secondary); color: var(--on-secondary);
  font-family: var(--font); font-size: 14px; font-weight: 500;
  letter-spacing: 1.25px; text-transform: uppercase;
  text-decoration: none;
  box-shadow: var(--shadow-6);
  transition: box-shadow .15s, transform .1s;
}
.fab:hover  { box-shadow: var(--shadow-8); }
.fab:active { transform: scale(.97); }
@media (min-width: 1024px) { .fab { right: 24px; bottom: 24px; } }

/* ── TEXT FIELDS (filled) ────────────────────────────────────────────────── */
/* Markup: <div class="field"><label>…</label><input …></div>. The label floats
   at the top of the filled container; the bottom line thickens on focus. */
.field {
  position: relative;
  background: var(--field-bg);
  border-radius: var(--radius) var(--radius) 0 0;
  margin-bottom: 16px;
  transition: background .15s;
}
.field:hover { background: var(--field-bg-hover); }
.field::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: 0;
  height: 1px; background: var(--field-line);
  transition: height .15s, background .15s;
}
.field:focus-within::after { height: 2px; background: var(--primary); }
.field > label {
  position: absolute; top: 7px; left: 12px; right: 12px;
  font-size: 12px; font-weight: 400; letter-spacing: .4px;
  color: var(--on-surface-med);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  pointer-events: none;
  text-transform: none; margin: 0;
}
.field:focus-within > label { color: var(--primary-text); }
.field > label .opt { color: var(--on-surface-dis); }
.field > input,
.field > textarea,
.field > select {
  display: block; width: 100%;
  background: transparent; border: none; border-radius: 0;
  color: var(--on-surface);
  font-family: var(--font); font-size: 16px; letter-spacing: .15px;
  padding: 25px 12px 7px;
  min-height: 56px;
  outline: none;
  -webkit-appearance: none;
}
.field > textarea { resize: vertical; min-height: 88px; line-height: 1.45; }
.field > input[type=number] { font-family: var(--mono); }
.field > input::placeholder,
.field > textarea::placeholder { color: var(--on-surface-dis); }
.field.accent::after { height: 2px; background: var(--secondary); }
.field.dense > input { min-height: 48px; padding: 21px 10px 5px; font-size: 15px; }
.field.dense > label { top: 5px; left: 10px; font-size: 11px; }
.helper { font-size: 12px; letter-spacing: .4px; color: var(--on-surface-med); margin: -12px 12px 16px; }

/* Bare inputs (search boxes, inline editors) get a filled look too. */
input.input,
.input-row > input,
.input-row > textarea {
  width: 100%; height: 48px;
  background: var(--field-bg);
  border: none; border-bottom: 1px solid var(--field-line);
  border-radius: var(--radius) var(--radius) 0 0;
  color: var(--on-surface);
  font-family: var(--font); font-size: 16px; letter-spacing: .15px;
  padding: 0 12px;
  outline: none;
  -webkit-appearance: none;
  transition: border-color .15s, background .15s;
}
input.input:focus,
.input-row > input:focus { border-bottom: 2px solid var(--primary); }
.input-row { display: flex; gap: 8px; align-items: center; }
.input-row > input { flex: 1; min-width: 0; }
.input-row > .btn { flex-shrink: 0; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0 8px; }
@media (max-width: 420px) {
  .grid-3 { grid-template-columns: 1fr 1fr; }
}

/* ── CHIPS ───────────────────────────────────────────────────────────────── */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 12px; border-radius: 16px;
  background: var(--chip-bg); color: var(--on-surface);
  font-family: var(--font); font-size: 14px; letter-spacing: .25px;
  border: none; white-space: nowrap; cursor: default;
  text-decoration: none;
  -webkit-appearance: none;
}
button.chip, a.chip { cursor: pointer; transition: background .15s; }
button.chip:hover, a.chip:hover { filter: brightness(.96); }
.chip .material-icons { font-size: 18px; margin-left: -4px; color: var(--on-surface-med); }
.chip.selected { background: var(--selected); color: var(--primary-text); }
.chip.selected .material-icons { color: var(--primary-text); }
.chip.sm { height: 24px; padding: 0 8px; border-radius: 12px; font-size: 12px; letter-spacing: .4px; }
.chip.outlined { background: transparent; border: 1px solid var(--outline); }
.chip-set { display: flex; flex-wrap: wrap; gap: 8px; }
.chip .count { font-family: var(--mono); font-size: 12px; color: var(--on-surface-med); }
.chip.selected .count { color: inherit; }

/* ── LINEAR PROGRESS ─────────────────────────────────────────────────────── */
.progress { height: 4px; border-radius: 2px; background: var(--track); overflow: hidden; }
.progress > div { height: 100%; background: var(--primary); border-radius: inherit; transition: width .3s; }
.progress.warn > div { background: var(--warn); }
.progress.over > div { background: var(--error); }
.progress.low  > div { background: var(--on-surface-dis); }

/* Goal bar: the track spans 0 → --scale% of the goal, with a faint band marking
   the in-range zone (--zone-from/--zone-to) and a tick at 100%. */
.goal-bar { position: relative; height: 8px; border-radius: 4px; background: var(--track); overflow: hidden; }
.goal-bar .zone { position: absolute; top: 0; bottom: 0; background: var(--success-tint); box-shadow: inset 1px 0 var(--success), inset -1px 0 var(--success); opacity: .9; }
.goal-bar .tick { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--success); opacity: .6; }
.goal-bar .fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: inherit; background: var(--warn); transition: width .3s; }
.goal-bar.in   .fill { background: var(--success); }
.goal-bar.over .fill { background: var(--error); }
.goal-under { color: var(--warn); }
.goal-in    { color: var(--success); }
.goal-over  { color: var(--error); }

/* ── LISTS ───────────────────────────────────────────────────────────────── */
.list { list-style: none; }
.list-item {
  display: flex; align-items: center; gap: 16px;
  min-height: 72px; padding: 8px 16px;
  position: relative;
}
.list-item + .list-item { border-top: 1px solid var(--divider); }
.list-item.clickable { cursor: pointer; transition: background .15s; }
.list-item.clickable:hover { background: var(--hover); }
.list-item .avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--selected); color: var(--primary-text);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; overflow: hidden;
}
.list-item .avatar img { width: 100%; height: 100%; object-fit: cover; }
.list-item .text { flex: 1; min-width: 0; }
.list-item .primary { font-size: 16px; letter-spacing: .15px; line-height: 1.4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .secondary { font-size: 14px; letter-spacing: .25px; color: var(--on-surface-med); line-height: 1.4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .meta { text-align: right; flex-shrink: 0; }
.list-subheader { height: 48px; display: flex; align-items: center; padding: 0 16px; font-size: 14px; font-weight: 500; color: var(--primary-text); }

/* ── EXPANSION PANEL (<details>) ─────────────────────────────────────────── */
details.expansion > summary {
  list-style: none; cursor: pointer; user-select: none;
  display: flex; align-items: center; gap: 12px;
  min-height: 48px; padding: 0 16px;
  font-size: 15px; letter-spacing: .15px; color: var(--on-surface);
}
details.expansion > summary::-webkit-details-marker { display: none; }
details.expansion > summary .t { flex: 1; min-width: 0; }
details.expansion > summary .chev { color: var(--on-surface-med); transition: transform .2s; }
details.expansion[open] > summary .chev { transform: rotate(180deg); }
details.expansion > .expansion-body { padding: 0 16px 12px; }
details.expansion + details.expansion,
.card > details.expansion:not(:first-child) { border-top: 1px solid var(--divider); }

/* Plain <details> (e.g. inline "Ingredients" reveals) */
details:not(.expansion) > summary { cursor: pointer; color: var(--on-surface-med); }

/* ── BANNER ──────────────────────────────────────────────────────────────── */
.banner { background: var(--surface-1); border-radius: var(--radius); box-shadow: var(--shadow-1); padding: 16px 8px 8px 16px; margin-bottom: 16px; }
.banner-row { display: flex; gap: 16px; align-items: flex-start; padding-right: 8px; }
.banner-icon {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--primary); color: var(--on-primary);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.banner-text { flex: 1; min-width: 0; padding-top: 2px; color: var(--on-surface); }
.banner-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* ── TABS (in the app bar) ───────────────────────────────────────────────── */
.tabs {
  display: flex; overflow-x: auto; scrollbar-width: none;
  background: var(--appbar-bg); color: var(--appbar-fg);
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 1 0 auto; min-width: 84px; height: 72px; padding: 0 12px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  background: none; border: none; color: inherit; cursor: pointer;
  font-family: var(--font); font-size: 13px; font-weight: 500;
  letter-spacing: 1.25px; text-transform: uppercase;
  opacity: .74; position: relative;
  transition: opacity .15s, background .15s;
  -webkit-appearance: none;
}
.tab:hover { opacity: 1; background: rgba(255,255,255,.08); }
.tab.active { opacity: 1; }
.tab.active::after { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: var(--secondary); }

/* ── SNACKBAR ────────────────────────────────────────────────────────────── */
.snackbar {
  position: fixed; z-index: 400;
  left: 50%; bottom: calc(80px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  width: calc(100% - 16px); max-width: 560px;
  min-height: 48px; padding: 6px 8px 6px 16px;
  display: flex; align-items: center; gap: 8px;
  background: var(--snackbar-bg); color: var(--snackbar-fg);
  border-radius: var(--radius); box-shadow: var(--shadow-6);
  font-size: 14px; letter-spacing: .25px;
  opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.snackbar.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.snackbar .msg { flex: 1; }
.snackbar .btn { color: var(--snackbar-action); }
.snackbar.error .msg::before { content: 'error'; font-family: 'Material Icons'; font-size: 20px; vertical-align: -5px; margin-right: 8px; color: #FF8A80; }

/* ── DIALOG ──────────────────────────────────────────────────────────────── */
.dialog-scrim {
  position: fixed; inset: 0; z-index: 500;
  background: var(--scrim);
  display: none; align-items: center; justify-content: center; padding: 24px;
}
.dialog-scrim.open { display: flex; }
.dialog {
  background: var(--surface-24); color: var(--on-surface);
  border-radius: var(--radius); box-shadow: var(--shadow-24);
  width: 100%; max-width: 440px; max-height: 100%; overflow: auto;
}
.dialog-title { font-size: 20px; font-weight: 500; letter-spacing: .15px; padding: 20px 24px 8px; }
.dialog-content { padding: 0 24px 16px; color: var(--on-surface-med); font-size: 16px; letter-spacing: .5px; line-height: 1.5; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 8px; }

/* ── MENU ────────────────────────────────────────────────────────────────── */
.menu-anchor { position: relative; }
.menu {
  position: absolute; right: 0; top: 100%; z-index: 150;
  min-width: 140px; padding: 8px 0;
  background: var(--surface-8); border-radius: var(--radius); box-shadow: var(--shadow-8);
  display: none;
}
.menu.open { display: block; }
.menu-item {
  display: flex; align-items: center; gap: 16px; width: 100%;
  height: 44px; padding: 0 16px;
  background: none; border: none; cursor: pointer; text-decoration: none;
  font-family: var(--font); font-size: 15px; letter-spacing: .15px; color: var(--on-surface);
  text-align: left;
}
.menu-item:hover { background: var(--hover); }
.menu-item .material-icons { font-size: 20px; color: var(--on-surface-med); }
.menu-item.danger, .menu-item.danger .material-icons { color: var(--error); }

/* ── ALERTS (inline, non-transient) ──────────────────────────────────────── */
.alert {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px 16px; border-radius: var(--radius);
  margin-bottom: 16px; font-size: 14px;
}
.alert::before { font-family: 'Material Icons'; font-size: 20px; line-height: 1; }
.alert-success { background: var(--success-tint); color: var(--success); }
.alert-success::before { content: 'check_circle'; }
.alert-error   { background: var(--error-tint); color: var(--error); }
.alert-error::before { content: 'error'; }

/* ── MISC ────────────────────────────────────────────────────────────────── */
hr.divider { border: none; border-top: 1px solid var(--divider); margin: 16px 0; }
.empty-state { text-align: center; padding: 32px 16px; color: var(--on-surface-med); }
.empty-state .material-icons { font-size: 48px; color: var(--on-surface-dis); margin-bottom: 8px; }

.spinner {
  width: 16px; height: 16px;
  border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block; vertical-align: -3px;
  opacity: .8;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Status line under a tool (scan, barcode, …); scripts inject coloured spans. */
.api-status { text-align: center; font-size: 13px; letter-spacing: .25px; margin-top: 12px; min-height: 20px; color: var(--on-surface-med); }
.api-status:empty { margin-top: 0; min-height: 0; }

/* Tiny "source" tag (scan / barcode / …) */
.log-source {
  display: inline-flex; align-items: center;
  height: 20px; padding: 0 8px; border-radius: 10px;
  background: var(--chip-bg); color: var(--on-surface-med);
  font-family: var(--font); font-size: 11px; letter-spacing: .4px;
  text-decoration: none; white-space: nowrap;
}
a.log-source:hover { color: var(--primary-text); background: var(--selected); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation-duration: 0s !important; }
}
