/* ==========================================================================
   Carb Calculator — stylesheet
   Extracted from index.html and extended for Firebase-backed CRUD, recipe
   calc, history, and FAB nav. All colors go through CSS variables so the
   light/dark themes stay in one place.
   ========================================================================== */

:root {
  --bg: #f7f7f8;
  --card: #ffffff;
  --border: #e3e3e8;
  --text: #1a1a1f;
  --muted: #6b6b74;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --total: #0f766e;
  --net: #7c3aed;
  --protein: #a855f7;
  --protein-soft: #f3e8ff;
  --fat: #f59e0b;
  --fat-soft: #fef3c7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 12px rgba(0,0,0,.04);
  --shadow-lg: 0 4px 8px rgba(0,0,0,.06), 0 16px 32px rgba(0,0,0,.08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f12;
    --card: #1a1a20;
    --border: #2a2a33;
    --text: #f2f2f5;
    --muted: #9a9aa4;
    --accent: #60a5fa;
    --accent-soft: #1e3a8a;
    --total: #5eead4;
    --net: #c4b5fd;
    --protein: #d8b4fe;
    --protein-soft: #3b1e5a;
    --fat: #fbbf24;
    --fat-soft: #3a2e10;
    --danger: #f87171;
    --danger-soft: #3b1515;
    --warn: #fbbf24;
    --warn-soft: #3a2e10;
  }
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px; line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}

/* ---------- Header ---------- */
.header-wrap {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  border-bottom: 1px solid transparent;
  transition: border-color .2s, box-shadow .2s;
}
.header-wrap.compact {
  border-bottom-color: var(--border);
  box-shadow: 0 2px 8px rgba(0,0,0,.04);
}
header {
  padding: 20px 16px 14px;
  max-width: 1000px; margin: 0 auto;
  transition: padding .2s;
}
.header-wrap.compact header { padding: 8px 16px; }
.header-row {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 4px;
}
header h1 {
  margin: 0; font-size: 1.5rem; font-weight: 600; flex: 1;
  transition: max-height .2s, margin .2s, opacity .15s;
  overflow: hidden;
}
header p {
  margin: 0 0 12px; color: var(--muted); font-size: .9rem;
  transition: max-height .2s, margin .2s, opacity .15s;
  overflow: hidden;
}
.header-wrap.compact header h1,
.header-wrap.compact header p {
  max-height: 0; margin: 0; opacity: 0;
  pointer-events: none;
}

.offline-chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: .72rem; font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--warn-soft);
  color: var(--warn);
  text-transform: uppercase; letter-spacing: .05em;
  white-space: nowrap;
}
.offline-chip::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: var(--warn);
  display: inline-block;
}
.offline-chip[hidden] { display: none; }

.auth-chip {
  font-size: .78rem;
  padding: 6px 10px;
  min-height: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 999px;
  white-space: nowrap;
}
.auth-chip.authed {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: transparent;
}
.auth-chip.unverified {
  background: var(--warn-soft);
  color: var(--warn);
  border-color: transparent;
}

/* ---------- Search ---------- */
.search {
  display: flex; align-items: center; gap: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 10px;
  box-shadow: var(--shadow);
  transition: border-color .15s, box-shadow .15s;
}
.search:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent), var(--shadow);
}
.search svg { flex-shrink: 0; color: var(--muted); }
.search input#search {
  flex: 1; width: auto;
  border: none; background: transparent;
  padding: 12px 0;
  font: inherit; color: var(--text);
  text-align: left;
  min-width: 0;
  transition: padding .2s, font-size .2s;
}
.header-wrap.compact .search input#search { padding: 8px 0; font-size: .95rem; }
.header-wrap.compact .search { padding: 0 8px; }
.search input#search:focus { outline: none; }
.search input#search::placeholder { color: var(--muted); }
.search input#search::-webkit-search-cancel-button { display: none; }
#search-clear {
  flex-shrink: 0;
  min-height: 0;
  padding: 4px 8px;
  font-size: 1.1rem; line-height: 1;
  color: var(--muted);
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}
#search-clear:hover { background: var(--bg); color: var(--text); }

/* ---------- Main / layout ---------- */
main { max-width: 1000px; margin: 0 auto; padding: 8px 16px 150px; }
.hidden { display: none !important; }
.no-results {
  text-align: center;
  color: var(--muted);
  font-style: italic;
  padding: 32px 16px;
}
.cat {
  margin: 22px 0 8px;
  font-size: .78rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted);
}

.view-head {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 0 8px;
  flex-wrap: wrap;
}
.view-head h2 {
  margin: 0; font-size: 1.25rem; font-weight: 600; flex: 1; min-width: 0;
}
.view-head .subtle { color: var(--muted); font-size: .88rem; flex-basis: 100%; margin: 0; }
.view-head .btn-primary { min-height: 40px; }

.btn-primary {
  background: var(--accent); color: #fff;
  border: 1px solid transparent;
  font-weight: 600;
}
.btn-primary:hover { filter: brightness(1.05); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.btn-ghost {
  background: transparent; border-color: var(--border);
  color: var(--text);
}
.btn-danger {
  background: var(--danger-soft); color: var(--danger);
  border-color: transparent;
}
.btn-danger:hover { background: var(--danger); color: #fff; }

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 48px 16px;
  background: var(--card);
  border: 1px dashed var(--border);
  border-radius: 12px;
  margin-top: 10px;
}
.empty-state p { margin: 0 0 12px; }

/* ---------- Calculator table ---------- */
table {
  width: 100%;
  border-collapse: separate; border-spacing: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
thead th {
  text-align: left;
  font-size: .78rem; font-weight: 600;
  color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em;
  padding: 10px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
tbody td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr.estimate { box-shadow: inset 4px 0 0 var(--warn); }

.food-name-wrap { display: flex; flex-direction: column; gap: 6px; min-width: 150px; }
.food-name { font-weight: 500; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
a.info, span.info {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: .72rem; font-weight: 700; font-style: italic;
  text-decoration: none;
  border: 1px solid transparent;
  flex-shrink: 0;
}
a.info:hover { background: var(--accent); color: #fff; }
a.info:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
span.info.est { background: var(--warn-soft); color: var(--warn); cursor: help; font-style: normal; }
.est-badge {
  font-size: .68rem; font-weight: 600;
  padding: 2px 7px; border-radius: 999px;
  background: var(--warn-soft); color: var(--warn);
  text-transform: uppercase; letter-spacing: .04em;
}

.state-tag {
  display: inline-block; font-size: .68rem; font-weight: 600;
  padding: 2px 7px; border-radius: 999px;
  background: var(--bg); color: var(--muted);
  border: 1px solid var(--border);
  text-transform: uppercase; letter-spacing: .04em;
}
.toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; background: var(--bg); }
.toggle button {
  font: inherit; font-size: .72rem; font-weight: 600;
  padding: 4px 10px; min-height: 0;
  border: none; border-radius: 0;
  background: transparent; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em;
  cursor: pointer;
}
.toggle button.on { background: var(--accent); color: #fff; }
.toggle button:hover:not(.on) { background: var(--accent-soft); color: var(--accent); }

.ref { font-variant-numeric: tabular-nums; font-size: .88rem; line-height: 1.5; min-width: 150px; }
.ref .row { display: flex; justify-content: space-between; gap: 10px; }
.ref .lbl { color: var(--muted); }
.ref .num { color: var(--text); font-weight: 600; }
.ref .num.t { color: var(--total); }
.ref .num.n { color: var(--net); }

input[type="text"], input[type="number"], input[type="email"], input[type="password"] {
  width: 96px; padding: 9px 10px; font: inherit;
  color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px;
  text-align: right; font-variant-numeric: tabular-nums;
}
input[type="email"], input[type="password"] { text-align: left; width: 100%; }
textarea {
  width: 100%; padding: 9px 10px; font: inherit;
  color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px;
  resize: vertical; min-height: 64px;
}
select {
  font: inherit;
  padding: 9px 10px;
  color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px;
}
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent);
}

.result { font-variant-numeric: tabular-nums; font-size: .92rem; white-space: nowrap; }
.result .t { color: var(--total); font-weight: 600; }
.result .n { color: var(--net); font-weight: 600; }
.result .sep { color: var(--muted); margin: 0 6px; }
.result.zero { color: var(--muted); }
.result.zero .t, .result.zero .n { color: var(--muted); font-weight: 400; }

@media (max-width: 640px) {
  table, thead, tbody, tr, td { display: block; }
  thead { display: none; }
  table { background: transparent; border: none; box-shadow: none; }
  tbody tr {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 10px;
    padding: 12px 14px;
    box-shadow: var(--shadow);
  }
  tbody tr.estimate { border-left: 4px solid var(--warn); box-shadow: var(--shadow); }
  tbody td { border: none; padding: 3px 0; }
  td.col-input { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
  td.col-input::before { content: "Grams:"; color: var(--muted); font-size: .85rem; }
  input[type="text"] { flex: 1; width: auto; }
  td.col-result { margin-top: 6px; }
}

/* ---------- Footer ---------- */
footer {
  position: fixed; left: 0; right: 0; bottom: 0;
  background: var(--card);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 16px rgba(0,0,0,.06);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  z-index: 10;
}
footer[hidden] { display: none; }
.foot-inner {
  max-width: 1000px; margin: 0 auto;
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px;
}
.totals { flex: 1 1 auto; font-variant-numeric: tabular-nums; min-width: 200px; }
.totals .lbl { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; display: block; }
.totals .val { font-size: 1.05rem; }
.totals .t { color: var(--total); font-weight: 700; }
.totals .n { color: var(--net); font-weight: 700; }
.totals .sep { color: var(--muted); margin: 0 8px; }

button {
  font: inherit; font-weight: 500;
  padding: 10px 14px; min-height: 44px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card); color: var(--text);
  cursor: pointer;
}
button:hover { filter: brightness(1.05); }
button:active { transform: translateY(1px); }

/* ---------- Trail modal (existing) ---------- */
.trail-wrap {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  display: none;
  align-items: flex-end; justify-content: center;
  z-index: 20;
}
.trail-wrap.open { display: flex; }
.trail {
  background: var(--card);
  width: 100%; max-width: 720px;
  max-height: 85vh; overflow: auto;
  border-radius: 14px 14px 0 0;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  border: 1px solid var(--border);
}
@media (min-width: 720px) {
  .trail-wrap { align-items: center; }
  .trail { border-radius: 14px; }
}
.trail h2 { margin: 0 0 10px; font-size: 1.1rem; }
.trail .close { float: right; margin: -4px -4px 0 0; }
.trail pre {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .86rem;
  background: var(--bg);
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  overflow-x: auto;
  white-space: pre;
  margin: 0;
}
.trail .empty { color: var(--muted); font-style: italic; padding: 8px 0; }

.trail-head {
  display: flex; align-items: center; gap: 8px;
  margin: 0 0 14px;
}
.trail-head h2 { margin: 0; font-size: 1.1rem; flex: 1; }
.trail-head .btn-copy {
  font-size: .85rem;
  padding: 8px 12px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid transparent;
}
.trail-head .btn-copy.copied {
  background: var(--total);
  color: #fff;
}
.trail-head .close {
  float: none; margin: 0;
  background: transparent;
  color: var(--muted);
  padding: 6px 10px;
}

/* Wider modal for the trail/calculation view. */
.trail-modal {
  max-width: 560px;
  padding: 18px;
}
.trail-modal .modal-head {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 14px;
}
.trail-modal .modal-head h2 {
  margin: 0; font-size: 1.05rem; font-weight: 600; flex: 1; min-width: 0;
}
.trail-modal .modal-foot {
  display: flex; justify-content: flex-end; gap: 8px;
  margin-top: 14px;
}
#btn-save-trail.saved {
  background: var(--total);
  color: #fff;
  border-color: transparent;
}
#btn-save-trail[hidden] { display: none; }

/* Hero: total + net carbs, the two big numbers. */
.trail-hero {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}
.stat-tile {
  padding: 16px 18px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg);
}
.stat-tile .lbl {
  display: block;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}
.stat-tile .val {
  display: block;
  font-size: 2.25rem;
  font-weight: 700;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
}
.stat-tile .unit {
  font-size: 1rem;
  font-weight: 600;
  margin-left: 2px;
  color: var(--muted);
}
.stat-tile.total {
  background: color-mix(in srgb, var(--total) 12%, var(--card));
  border-color: color-mix(in srgb, var(--total) 35%, var(--border));
}
.stat-tile.total .val { color: var(--total); }
.stat-tile.net {
  background: color-mix(in srgb, var(--net) 12%, var(--card));
  border-color: color-mix(in srgb, var(--net) 35%, var(--border));
}
.stat-tile.net .val { color: var(--net); }
.stat-tile.protein {
  background: color-mix(in srgb, var(--protein) 10%, var(--card));
  border-color: color-mix(in srgb, var(--protein) 30%, var(--border));
}
.stat-tile.protein .val { color: var(--protein); }
.stat-tile.fat {
  background: color-mix(in srgb, var(--fat) 12%, var(--card));
  border-color: color-mix(in srgb, var(--fat) 35%, var(--border));
}
.stat-tile.fat .val { color: var(--fat); }

/* Secondary macros: small, de-emphasized row under the hero. */
.hero-macros {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  padding: 8px 4px 0;
  margin-bottom: 16px;
  font-size: .85rem;
}
.hero-macros[hidden] { display: none; }
.hero-macros .m {
  display: inline-flex; align-items: baseline; gap: 6px;
}
.hero-macros .m .k {
  color: var(--muted);
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  font-weight: 600;
}
.hero-macros .m .v {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--text);
}
.hero-macros .m-protein .v { color: var(--protein); }
.hero-macros .m-fat .v     { color: var(--fat); }

/* Items header (visible above the always-shown ingredient list). */
.trail-items-head {
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 2px 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
.trail-items-head[hidden] { display: none; }

/* Ingredients list: always visible, no dropdown needed. */
.trail-items {
  list-style: none;
  padding: 0;
  margin: 0 0 4px;
}
.trail-items[hidden] { display: none; }
.trail-items li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 2px;
  border-bottom: 1px solid var(--border);
  font-size: .94rem;
}
.trail-items li:last-child { border-bottom: none; }
.trail-items li.missing { background: color-mix(in srgb, var(--danger) 6%, transparent); }
.trail-items .item-name { flex: 1; min-width: 0; line-height: 1.3; }
.trail-items .item-name strong { font-weight: 600; }
.trail-items .item-meta {
  color: var(--muted);
  font-size: .78rem;
  display: block;
  margin-top: 2px;
}
.trail-items .item-net {
  font-variant-numeric: tabular-nums;
  color: var(--net);
  font-weight: 700;
  white-space: nowrap;
  font-size: .95rem;
}
.trail-items .est-tag {
  display: inline-block;
  font-size: .65rem;
  color: var(--warn);
  background: var(--warn-soft);
  padding: 1px 6px;
  border-radius: 999px;
  margin-left: 6px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  vertical-align: middle;
}

/* Collapsed details: detailed calculation steps live here. */
.trail-steps {
  margin-top: 12px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}
.trail-steps[hidden] { display: none; }
.trail-steps summary {
  cursor: pointer;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  padding: 6px 2px;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
  user-select: none;
}
.trail-steps summary:hover { color: var(--text); }
.trail-steps summary::-webkit-details-marker { display: none; }
.trail-steps summary::before {
  content: "▸";
  display: inline-block;
  font-size: .8rem;
  transition: transform .15s;
}
.trail-steps[open] summary::before { transform: rotate(90deg); }
.trail-steps pre {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .82rem;
  background: var(--bg);
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  overflow-x: auto;
  white-space: pre;
  margin: 8px 0 0;
}

@media (max-width: 360px) {
  .stat-tile { padding: 14px 14px; }
  .stat-tile .val { font-size: 1.85rem; }
}

/* ---------- FAB + nav menu ---------- */
.fab-wrap {
  position: fixed;
  right: 16px;
  bottom: calc(84px + env(safe-area-inset-bottom));
  z-index: 30;
  display: flex; flex-direction: column; align-items: flex-end; gap: 10px;
  pointer-events: none;
}
footer[hidden] ~ .fab-wrap { bottom: calc(16px + env(safe-area-inset-bottom)); }
.fab {
  pointer-events: auto;
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--accent); color: #fff;
  border: none;
  box-shadow: var(--shadow-lg);
  font-size: 1.6rem; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  transition: transform .2s;
}
.fab[aria-expanded="true"] { transform: rotate(45deg); }
.fab-menu {
  pointer-events: auto;
  display: none;
  flex-direction: column;
  gap: 6px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px;
  box-shadow: var(--shadow-lg);
  min-width: 200px;
}
.fab-menu.open { display: flex; }
.fab-menu button {
  text-align: left;
  background: transparent;
  border: none;
  min-height: 40px;
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--text);
  font-weight: 500;
}
.fab-menu button:hover { background: var(--bg); }
.fab-menu button.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.fab-menu .sep {
  height: 1px; background: var(--border); margin: 4px 6px;
}
.fab-backdrop {
  position: fixed; inset: 0;
  background: transparent;
  z-index: 29;
  display: none;
}
.fab-backdrop.open { display: block; }

/* ---------- Auth modal ---------- */
.modal-wrap {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  display: none;
  align-items: center; justify-content: center;
  z-index: 40;
  padding: 16px;
}
.modal-wrap.open { display: flex; }
.modal {
  background: var(--card);
  width: 100%; max-width: 420px;
  border-radius: 14px;
  padding: 20px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
}
.modal h2 { margin: 0 0 4px; font-size: 1.15rem; }
.modal p.sub { margin: 0 0 14px; color: var(--muted); font-size: .9rem; }
.modal .field { margin-bottom: 12px; }
.modal .field label {
  display: block;
  font-size: .78rem; font-weight: 600;
  color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em;
  margin-bottom: 4px;
}
.modal .actions {
  display: flex; gap: 8px; justify-content: flex-end;
  margin-top: 14px;
}
.modal .err {
  color: var(--danger); font-size: .85rem;
  margin: 8px 0 0;
  min-height: 1em;
}

.confirm-wrap {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  display: none;
  align-items: center; justify-content: center;
  z-index: 50;
  padding: 16px;
}
.confirm-wrap.open { display: flex; }
.confirm {
  background: var(--card);
  width: 100%; max-width: 380px;
  border-radius: 14px;
  padding: 20px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
}
.confirm h3 { margin: 0 0 4px; font-size: 1.05rem; }
.confirm p { margin: 0 0 14px; color: var(--muted); font-size: .9rem; }
.confirm .actions {
  display: flex; gap: 8px; justify-content: flex-end;
}

/* ---------- List views (ingredients, recipes, history) ---------- */
.list {
  display: flex; flex-direction: column; gap: 8px;
  margin-top: 10px;
}
.list-row {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.list-row .main-col {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; gap: 3px;
}
.list-row .main-col .title {
  font-weight: 600;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.list-row .main-col .meta {
  color: var(--muted); font-size: .82rem;
}
.list-row .actions {
  display: flex; gap: 6px; flex-shrink: 0;
}
.list-row .actions button {
  min-height: 36px; padding: 6px 10px; font-size: .85rem;
}
.list-row.clickable { cursor: pointer; }
.list-row.clickable:hover { border-color: var(--accent); }

.lock-chip {
  font-size: .65rem; font-weight: 600;
  padding: 2px 7px; border-radius: 999px;
  background: var(--bg); color: var(--muted);
  border: 1px solid var(--border);
  text-transform: uppercase; letter-spacing: .04em;
}
.source-chip {
  font-size: .65rem; font-weight: 600;
  padding: 2px 7px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
  text-transform: uppercase; letter-spacing: .04em;
}
.missing-chip {
  font-size: .65rem; font-weight: 600;
  padding: 2px 7px; border-radius: 999px;
  background: var(--danger-soft); color: var(--danger);
  text-transform: uppercase; letter-spacing: .04em;
}

/* ---------- Forms (ingredient, recipe) ---------- */
.form-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--shadow);
  margin-top: 12px;
}
.form-card .field {
  margin-bottom: 14px;
}
.form-card .field label {
  display: block;
  font-size: .78rem; font-weight: 600;
  color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em;
  margin-bottom: 5px;
}
.form-card .field input[type="text"],
.form-card .field input[type="number"],
.form-card .field input[type="email"],
.form-card .field input[type="password"],
.form-card .field select,
.form-card .field textarea {
  width: 100%;
  text-align: left;
}
.form-card .row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
@media (max-width: 480px) {
  .form-card .row-2 { grid-template-columns: 1fr; }
}
.form-actions {
  display: flex; gap: 8px; flex-wrap: wrap;
  margin-top: 12px;
}
.form-actions .spacer { flex: 1; }

.inline-hint { color: var(--muted); font-size: .82rem; margin-top: 6px; }
.inline-err  { color: var(--danger); font-size: .85rem; margin-top: 6px; min-height: 1em; }

.forms-editor {
  display: flex; flex-direction: column; gap: 10px;
  margin-top: 6px;
}
.form-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}
.form-block-head {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 10px;
}
.form-block-head input[type="text"] {
  flex: 1; text-align: left;
}
.form-block-head .btn-remove {
  min-height: 36px; padding: 4px 10px;
  font-size: .82rem;
  background: transparent;
  color: var(--danger);
  border-color: var(--border);
}
.nutri-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}
@media (max-width: 560px) {
  .nutri-grid { grid-template-columns: repeat(2, 1fr); }
}
.nutri-grid .cell label {
  display: block;
  font-size: .7rem; font-weight: 600;
  color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em;
  margin-bottom: 3px;
}
.nutri-grid .cell input { width: 100%; }

.fdc-bar {
  display: flex; gap: 8px; align-items: center; margin-bottom: 8px;
  flex-wrap: wrap;
}
.fdc-bar input { flex: 1; min-width: 140px; text-align: left; }
.fdc-bar .btn { min-height: 40px; white-space: nowrap; }
.fdc-status {
  font-size: .82rem; color: var(--muted);
  margin-top: 6px; min-height: 1em;
}
.fdc-status.err { color: var(--danger); }
.fdc-status.ok  { color: var(--total); }

/* ---------- Recipe form line items ---------- */
.lines {
  display: flex; flex-direction: column; gap: 8px;
  margin-top: 6px;
}
.line {
  display: grid;
  grid-template-columns: auto 1fr auto auto auto;
  gap: 6px;
  align-items: center;
  padding: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.line .type-tog button {
  padding: 4px 8px;
  font-size: .7rem;
  min-height: 32px;
}
.line .line-main { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.line select, .line input[type="text"] { width: 100%; text-align: left; }
.line input.grams { width: 72px; text-align: right; }
.line .btn-remove {
  min-height: 36px; padding: 4px 10px;
  background: transparent; color: var(--danger);
  border-color: var(--border); font-size: .82rem;
}
.line.missing { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 6%, var(--bg)); }

@media (max-width: 520px) {
  .line {
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "type    remove"
      "main    main"
      "grams   grams";
  }
  .line .type-tog { grid-area: type; }
  .line .line-main { grid-area: main; }
  .line input.grams { grid-area: grams; width: 100%; text-align: right; }
  .line .btn-remove { grid-area: remove; }
}

.scratch-banner {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  margin: 10px 0 0;
  background: var(--warn-soft);
  color: var(--warn);
  border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent);
  border-radius: 10px;
  font-size: .88rem;
  font-weight: 600;
}
.scratch-banner .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--warn); flex-shrink: 0;
}

/* ---------- Recipe calc view ---------- */
.calc-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}
@media (max-width: 420px) {
  .calc-inputs { grid-template-columns: 1fr; }
}
.calc-inputs .field label {
  display: block;
  font-size: .78rem; font-weight: 600;
  color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em;
  margin-bottom: 5px;
}
.calc-inputs input { width: 100%; text-align: right; }

.calc-result {
  margin-top: 14px;
}
.calc-line-list {
  margin-top: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.calc-line-list .row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  align-items: center;
  font-size: .9rem;
}
.calc-line-list .row:last-child { border-bottom: none; }
.calc-line-list .row .name { min-width: 0; display: flex; flex-direction: column; }
.calc-line-list .row .name .meta { color: var(--muted); font-size: .78rem; }
.calc-line-list .row .g { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.calc-line-list .row .net { color: var(--net); font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.calc-line-list .row.missing { background: color-mix(in srgb, var(--danger) 6%, var(--card)); }

/* ---------- History view ---------- */
.history-row .main-col .macros {
  display: flex; gap: 12px; flex-wrap: wrap;
  font-size: .82rem; color: var(--muted); font-variant-numeric: tabular-nums;
  margin-top: 4px;
}
.history-row .main-col .macros .t { color: var(--total); font-weight: 600; }
.history-row .main-col .macros .n { color: var(--net); font-weight: 600; }
.history-row .main-col .macros .p { color: var(--protein); font-weight: 600; }
.history-row .main-col .macros .f { color: var(--fat); font-weight: 600; }

/* ---------- Ingredient picker (datalist-like simple dropdown) ---------- */
.ing-pick { position: relative; }
.ing-pick input { width: 100%; text-align: left; }
.ing-pick-menu {
  position: absolute;
  z-index: 2;
  left: 0; right: 0; top: 100%;
  max-height: 240px; overflow: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-top: 4px;
  box-shadow: var(--shadow-lg);
  display: none;
}
.ing-pick-menu.open { display: block; }
.ing-pick-menu button {
  display: block; width: 100%;
  text-align: left;
  background: transparent; border: none;
  padding: 8px 10px;
  font-size: .92rem;
  border-radius: 0;
  min-height: 0;
}
.ing-pick-menu button:hover,
.ing-pick-menu button.hl { background: var(--bg); }
.ing-pick-menu .cat-lbl {
  font-size: .7rem; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em;
  padding: 6px 10px 2px;
}
.ing-pick-menu .empty { padding: 10px; color: var(--muted); font-style: italic; font-size: .88rem; }

/* ---------- Auth tabs + modal extras ---------- */
.auth-tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin: 4px 0 16px;
}
.auth-tab {
  flex: 1;
  background: transparent;
  border: none;
  padding: 9px 10px;
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  min-height: 0;
  transition: background .12s, color .12s;
}
.auth-tab:hover { color: var(--text); }
.auth-tab.active {
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow);
}

.auth-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
}
.auth-forgot {
  padding: 6px 8px;
  font-size: .85rem;
  color: var(--muted);
  min-height: 0;
}
.auth-forgot:hover { color: var(--accent); }
.auth-forgot[hidden] { display: none; }

.auth-hint {
  margin-top: 10px;
  font-size: .82rem;
  color: var(--muted);
}

.field-err {
  color: var(--danger);
  background: var(--danger-soft);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: .85rem;
  margin-top: 4px;
}
.field-err[hidden] { display: none; }
.field-info {
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: .85rem;
  margin-top: 4px;
}
.field-info[hidden] { display: none; }

/* ---------- Top-of-screen toast ---------- */
.app-toast {
  position: fixed;
  top: env(safe-area-inset-top, 0);
  left: 0; right: 0;
  z-index: 45;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top, 0));
  background: var(--accent-soft);
  color: var(--text);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: .9rem;
}
.app-toast[hidden] { display: none; }
.app-toast.toast-warn {
  background: var(--warn-soft);
  color: var(--text);
}
.app-toast-msg {
  flex: 1;
  min-width: 0;
  line-height: 1.35;
}
.app-toast-action {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 7px 12px;
  font: inherit;
  font-weight: 600;
  font-size: .85rem;
  cursor: pointer;
  min-height: 0;
  white-space: nowrap;
}
.app-toast-action[hidden] { display: none; }
.app-toast-action--secondary {
  background: transparent;
  color: var(--accent);
  border: 1px solid currentColor;
}
.app-toast.toast-warn .app-toast-action { background: var(--warn); }
.app-toast.toast-warn .app-toast-action--secondary { background: transparent; color: var(--warn); }
.app-toast-close {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 1.3rem;
  line-height: 1;
  padding: 4px 8px;
  cursor: pointer;
  min-height: 0;
}
.app-toast-close:hover { color: var(--text); }
