:root {
  --bg: #fff8f2;
  --surface: #fffdfb;
  --ink: #352638;
  --muted: #766a75;
  --brand: #5b2b55;
  --brand-2: #d36c52;
  --accent: #f7e1d7;
  --line: #eadbd4;
  --warn: #95620b;
  --warn-bg: #fff1cf;
  --danger: #a33f4b;
  --danger-bg: #fde9ec;
  --good: #2e7165;
  --good-bg: #e4f3ef;
  --gold: #e4b64c;
  --shadow: 0 14px 35px rgba(91, 43, 85, .10);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { color-scheme: light; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
}
button, input, select { font: inherit; }
button { cursor: pointer; }

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  padding: 28px clamp(18px, 4vw, 56px);
  background: linear-gradient(135deg, #4a2147 0%, #7a365d 55%, #b85c52 100%);
  color: white;
}
.app-header h1 { margin: 2px 0 6px; font-size: clamp(28px, 4vw, 44px); }
.subtle { margin: 0; opacity: .82; }
.eyebrow { margin: 0; font-size: 12px; letter-spacing: .12em; font-weight: 800; text-transform: uppercase; }

.shell { width: min(1180px, calc(100% - 28px)); margin: 24px auto 64px; }
.summary-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.summary-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  box-shadow: var(--shadow);
}
.summary-card span { color: var(--muted); font-size: 14px; }
.summary-card strong { display: block; font-size: 31px; margin: 5px 0; }
.summary-card small { color: var(--muted); }

.tabs {
  display: flex;
  gap: 6px;
  margin: 24px 0 14px;
  overflow-x: auto;
  padding-bottom: 3px;
}
.tab {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  padding: 11px 16px;
  border-radius: 999px;
  white-space: nowrap;
}
.tab.active { background: var(--brand); color: white; border-color: var(--brand); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 16px;
  margin: 14px 0;
}
.section-heading h2 { margin: 0 0 4px; }
.section-heading p { margin: 0; color: var(--muted); }
.filters, .inventory-toolbar { display: flex; gap: 10px; flex-wrap: wrap; }
select, input[type="search"], input[type="number"], input[type="text"], input[type="date"] {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: white;
  padding: 10px 12px;
  color: var(--ink);
}

.meal-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.meal-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 13px;
}
.meal-card-top { display: flex; justify-content: space-between; gap: 14px; }
.meal-card h3 { margin: 2px 0 5px; font-size: 21px; }
.badge-row { display: flex; flex-wrap: wrap; gap: 7px; }
.badge {
  display: inline-flex;
  align-items: center;
  padding: 5px 8px;
  border-radius: 999px;
  background: #f5ece7;
  color: #644d5c;
  font-size: 12px;
  font-weight: 700;
}
.badge.good { background: var(--good-bg); color: var(--good); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.match-ring {
  width: 62px; height: 62px; border-radius: 50%; flex: 0 0 auto;
  display: grid; place-items: center;
  background: conic-gradient(var(--brand-2) var(--match), #f0e4de 0);
  position: relative;
}
.match-ring::after { content: ""; position: absolute; inset: 7px; background: white; border-radius: 50%; }
.match-ring strong { position: relative; z-index: 1; font-size: 14px; }
.macro-row { display: flex; gap: 18px; color: var(--muted); font-size: 14px; }
.macro-row strong { color: var(--ink); }
.card-actions { display: flex; gap: 8px; margin-top: auto; }

.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 13px;
  font-weight: 750;
  text-decoration: none;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
}
.btn-primary { background: var(--brand); color: white; }
.btn-secondary { background: var(--accent); color: var(--brand); }
.btn-ghost { background: transparent; color: inherit; border-color: currentColor; opacity: .9; }
.btn-small { padding: 7px 9px; font-size: 13px; }
.app-header .btn-ghost { color: white; }

.inventory-toolbar { margin-bottom: 12px; }
.inventory-toolbar input { flex: 1; min-width: 220px; }
.inventory-quick-status { display: none; }
.table-wrap { overflow-x: auto; background: white; border: 1px solid var(--line); border-radius: 14px; }
.data-table { width: 100%; border-collapse: collapse; min-width: 760px; }
.data-table th, .data-table td { text-align: left; padding: 12px 13px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.data-table th { background: #f7ebe6; font-size: 13px; }
.data-table tr:last-child td { border-bottom: none; }
.qty-controls { display: inline-flex; align-items: center; gap: 6px; }
.qty-controls button { width: 28px; height: 28px; border: 1px solid var(--line); background: white; border-radius: 7px; }
.status-pill { display: inline-flex; padding: 5px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.status-pill.good { background: var(--good-bg); color: var(--good); }
.status-pill.warn { background: var(--warn-bg); color: var(--warn); }
.status-pill.danger { background: var(--danger-bg); color: var(--danger); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.row-actions button { border: 1px solid var(--line); background: white; border-radius: 8px; padding: 7px 9px; }

.shopping-list { display: grid; gap: 10px; }
.shopping-item {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: center;
  background: white;
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 13px;
}
.shopping-item small { display: block; color: var(--muted); margin-top: 3px; }
.empty-state { padding: 32px; text-align: center; background: white; border: 1px dashed #d5bdb2; border-radius: 14px; color: var(--muted); }

.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.settings-card { background: white; border: 1px solid var(--line); border-radius: 16px; padding: 18px; }
.settings-card h2 { margin-top: 0; }
.settings-card label:not(.check-line) { display: grid; gap: 6px; margin: 12px 0; }
.check-line { display: flex; gap: 9px; align-items: flex-start; margin: 11px 0; }
.hint { color: var(--muted); font-size: 13px; }
.button-stack { display: flex; gap: 8px; flex-wrap: wrap; }
.file-btn input { display: none; }

dialog { border: none; border-radius: 18px; padding: 0; width: min(560px, calc(100% - 28px)); box-shadow: 0 30px 90px rgba(74, 33, 71, .28); }
dialog::backdrop { background: rgba(53, 38, 56, .55); }
.dialog-card { padding: 20px; display: grid; gap: 13px; }
.dialog-card.wide { width: min(760px, 100%); }
.dialog-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; }
.dialog-head h2 { margin: 0; }
.icon-btn { border: 0; background: #f5e9e4; border-radius: 50%; width: 34px; height: 34px; font-size: 22px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dialog-card label:not(.check-line) { display: grid; gap: 6px; }
#productServingSizeWrap[hidden] { display: none !important; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 5px; }
.ingredient-list { display: grid; gap: 8px; margin: 12px 0 18px; }
.ingredient-line { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.ingredient-line.missing { color: var(--danger); }
.instructions { padding-left: 20px; }
.instructions li { margin-bottom: 8px; }

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  background: #4a2147;
  color: white;
  padding: 12px 15px;
  border-radius: 10px;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: .2s ease;
  max-width: 330px;
  box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translateY(0); }
.mobile-nav { display: none; }
.smart-action-buttons { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.measurement-pair {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.measurement-pair legend { padding: 0; margin-bottom: 6px; }
.mobile-more-link {
  width: 100%;
  padding: 15px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 750;
}

@media (max-width: 780px) {
  body { padding-bottom: calc(78px + env(safe-area-inset-bottom)); }
  .app-header { align-items: flex-start; flex-direction: column; }
  .summary-grid { grid-template-columns: 1fr; }
  .meal-grid, .settings-grid { grid-template-columns: 1fr; }
  .section-heading { align-items: flex-start; flex-direction: column; }
  .filters { width: 100%; }
  .filters select { flex: 1; }
  .two-col { grid-template-columns: 1fr; }
  .shopping-item { grid-template-columns: 1fr; }
  .tabs { display: none; }
  .mobile-nav {
    position: fixed;
    z-index: 40;
    left: 0;
    right: 0;
    bottom: 0;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    padding: 7px 6px calc(7px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--surface) 96%, transparent);
    border-top: 1px solid var(--line);
    box-shadow: 0 -8px 24px rgba(53, 38, 56, .12);
  }
  .mobile-tab {
    min-width: 0;
    min-height: 52px;
    border: 0;
    border-radius: 11px;
    background: transparent;
    color: var(--muted);
    display: grid;
    place-items: center;
    align-content: center;
    gap: 2px;
  }
  .mobile-tab span { font-size: 18px; line-height: 1; }
  .mobile-tab small { font-size: 11px; font-weight: 750; }
  .mobile-tab.active { background: var(--brand); color: white; }
  .toast { bottom: calc(82px + env(safe-area-inset-bottom)); left: 14px; right: 14px; max-width: none; }

  .inventory-quick-status {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    margin: 10px 0 12px;
  }
  .inventory-quick-status span {
    flex: 1 0 auto;
    padding: 9px 11px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: white;
    color: var(--muted);
    font-size: 13px;
  }
  .inventory-quick-status strong { color: var(--ink); }
  .inventory-toolbar { position: sticky; top: 0; z-index: 8; padding: 9px 0; background: var(--bg); }
  .inventory-toolbar input, .inventory-toolbar select { flex: 1 1 100%; width: 100%; }
  .table-wrap { overflow: visible; border: 0; background: transparent; }
  .data-table { display: block; min-width: 0; }
  .data-table thead { display: none; }
  .data-table tbody { display: grid; gap: 12px; }
  .data-table tr.inventory-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "name status"
      "amount amount"
      "location date"
      "actions actions";
    gap: 10px 12px;
    padding: 15px;
    border: 1px solid var(--line);
    border-radius: 15px;
    background: white;
    box-shadow: var(--shadow);
  }
  .data-table td { border: 0; padding: 0; min-width: 0; }
  .inventory-name { grid-area: name; }
  .inventory-status { grid-area: status; justify-self: end; }
  .inventory-amount { grid-area: amount; padding-top: 4px !important; }
  .inventory-location { grid-area: location; }
  .inventory-date { grid-area: date; text-align: right; }
  .inventory-actions { grid-area: actions; padding-top: 4px !important; border-top: 1px solid var(--line) !important; }
  .inventory-location::before, .inventory-date::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 3px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 750;
    text-transform: uppercase;
    letter-spacing: .06em;
  }
  .inventory-actions .row-actions { justify-content: flex-start; flex-wrap: wrap; padding-top: 10px; }
  .inventory-empty-row, .inventory-empty-row td { display: block; width: 100%; }
}


.staple-note { color: var(--muted); font-size: 13px; }
.tab.active { box-shadow: 0 5px 14px rgba(91,43,85,.18); }
.summary-card:first-child { border-top: 4px solid var(--brand-2); }
.summary-card:nth-child(2) { border-top: 4px solid var(--gold); }
.summary-card:nth-child(3) { border-top: 4px solid var(--good); }

.purchase-total {
  background: #fff3df;
  border: 1px solid #efd6a8;
  color: #6e4d1f;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 14px;
}
.purchase-total strong { font-size: 18px; color: var(--ink); }

/* v0.4 usability additions */
.btn:disabled,
.btn.is-disabled {
  cursor: not-allowed;
  background: #d8d0d5;
  border-color: #d8d0d5;
  color: #766d75;
  opacity: 1;
  box-shadow: none;
}

.cook-status {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--danger-bg);
  border: 1px solid #efc4ca;
  color: var(--danger);
  border-radius: 12px;
  padding: 11px 12px;
  margin-top: 10px;
  font-size: 14px;
}
.cook-status.good {
  background: var(--good-bg);
  border-color: #c5e2da;
  color: var(--good);
}

.substitute-box {
  margin: 8px 0 12px 24px;
  padding: 10px 12px;
  background: #fff5e8;
  border: 1px solid #efd8b9;
  border-radius: 10px;
}
.substitute-box strong { display: block; margin-bottom: 6px; }
.substitute-actions { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 7px; }
.substitute-note { color: var(--muted); font-size: 13px; margin: 3px 0 0; }
.substitution-change {
  background: #f6eef6;
  border: 1px solid #dfcce0;
  color: var(--brand);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 8px 0;
  font-size: 14px;
}

.today-list { display: grid; gap: 12px; }
.today-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.today-card.undone { opacity: .62; box-shadow: none; }
.today-card h3 { margin: 2px 0 6px; }
.today-meta { display: flex; gap: 14px; flex-wrap: wrap; color: var(--muted); font-size: 13px; }
.today-actions { display: flex; gap: 7px; flex-wrap: wrap; justify-content: flex-end; }
.history-status {
  display: inline-flex;
  padding: 4px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  margin-left: 7px;
}
.history-status.active { background: var(--good-bg); color: var(--good); }
.history-status.undone { background: #eee8ec; color: var(--muted); }
.history-edit-preview {
  background: #fff3df;
  border: 1px solid #efd6a8;
  border-radius: 10px;
  padding: 11px 12px;
  margin: 0;
}

@media (max-width: 780px) {
  .today-card { grid-template-columns: 1fr; }
  .today-actions { justify-content: flex-start; }
  .dialog-actions { flex-wrap: wrap; }
}

/* v0.5 editable amounts + freshness */
.meal-amount-editor { display: grid; gap: 10px; margin: 10px 0 14px; }
.amount-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.amount-row:last-child { border-bottom: 0; }
.amount-name { min-width: 0; }
.amount-name strong { display: block; }
.amount-name small { color: var(--muted); }
.amount-controls { display: flex; align-items: center; gap: 6px; }
.amount-controls input {
  width: 92px;
  text-align: right;
  padding: 9px 10px;
}
.amount-controls .unit-label { min-width: 42px; color: var(--muted); font-size: 13px; }
.step-btn {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--brand);
  font-weight: 800;
}
.step-btn:hover { border-color: var(--brand); }
.amount-row.over-stock { background: var(--danger-bg); margin-inline: -8px; padding-inline: 8px; border-radius: 10px; }
.amount-row.over-stock .amount-name small { color: var(--danger); }
.live-nutrition {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  background: #fff3df;
  border: 1px solid #efd6a8;
  border-radius: 12px;
  padding: 11px 12px;
  margin: 10px 0;
}
.live-nutrition strong { font-size: 18px; }
.meal-editor-toolbar { display: flex; justify-content: space-between; gap: 10px; align-items: center; flex-wrap: wrap; margin: 10px 0; }
.actual-ingredients { margin-top: 8px; }
.actual-ingredients summary { cursor: pointer; color: var(--brand); font-weight: 700; font-size: 13px; }
.actual-ingredients ul { margin: 8px 0 0 18px; padding: 0; color: var(--muted); font-size: 13px; }
.actual-ingredients li { margin: 3px 0; }
.check-line.compact { padding: 0; font-size: 13px; white-space: nowrap; }
.today-toolbar-actions { align-items: center; }
.freshness-badge.today { background: #fff0d7; color: #865415; }
.freshness-badge.soon { background: var(--warn-bg); color: var(--warn); }
.freshness-badge.fresh { background: var(--good-bg); color: var(--good); }

@media (max-width: 620px) {
  .amount-row { grid-template-columns: 1fr; gap: 8px; }
  .amount-controls { justify-content: flex-start; }
  .amount-controls input { width: 100px; }
}


/* v0.6 concise recipe guidance */
.seasoning-amount {
  color: var(--brand);
  font-weight: 800;
  font-size: 12px;
}
.instructions li {
  margin-bottom: 7px;
  line-height: 1.4;
}

/* v0.8 guided cooking mode */
.cooking-card {
  width: min(650px, 100%);
  gap: 16px;
}
.cooking-progress-wrap { display: grid; gap: 7px; }
.cooking-progress-track {
  height: 9px;
  border-radius: 999px;
  background: #efe4e0;
  overflow: hidden;
}
.cooking-progress-bar {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--brand-2), var(--brand));
  transition: width .25s ease;
}
.cooking-progress-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}
.parallel-note {
  background: #fff3df;
  border: 1px solid #efd6a8;
  color: #6e4d1f;
  border-radius: 12px;
  padding: 11px 13px;
  line-height: 1.4;
}
.cooking-step-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
  box-shadow: var(--shadow);
}
.cooking-step-card h3 { margin: 4px 0 10px; font-size: 24px; }
.cooking-step-text { margin: 0; line-height: 1.55; font-size: 17px; }
.timer-panel {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.timer-display {
  font-variant-numeric: tabular-nums;
  font-size: clamp(42px, 10vw, 64px);
  line-height: 1;
  font-weight: 850;
  letter-spacing: -.04em;
  color: var(--brand);
  margin-bottom: 14px;
}
.timer-display.done { color: var(--good); }
.timer-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.cooking-nav {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}
.cooking-safety-note { margin: -2px 0 0; }
.cooking-finished {
  text-align: center;
  padding: 12px 0;
}
.cooking-finished h3 { margin-bottom: 8px; }
.cooking-finished .finish-icon {
  width: 60px;
  height: 60px;
  margin: 0 auto 12px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--good-bg);
  color: var(--good);
  font-size: 30px;
  font-weight: 900;
}
@media (max-width: 620px) {
  .cooking-nav { flex-direction: column-reverse; }
  .cooking-nav .btn { width: 100%; }
  .timer-actions .btn { flex: 1; }
}
.active-timers {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.active-timer-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 10px;
  border-radius: 999px;
  background: #f6eef6;
  border: 1px solid #dfcce0;
  color: var(--brand);
  font-size: 13px;
  font-weight: 750;
}
.active-timer-chip.done { background: var(--good-bg); border-color: #c5e2da; color: var(--good); }


/* v0.9 smart planner */
.smart-planner-card {
  background: linear-gradient(135deg, #fff8f3 0%, #f7edf4 100%);
  border: 1px solid #dcc6d4;
  border-radius: 20px;
  padding: 18px;
  margin: 14px 0 20px;
  box-shadow: var(--shadow);
}
.smart-planner-copy h2 { margin: 2px 0 6px; }
.smart-planner-copy p:last-child { margin: 0; color: var(--muted); max-width: 860px; }
.smart-planner-controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}
.smart-planner-controls label { display: grid; gap: 6px; font-size: 13px; font-weight: 700; }
.smart-planner-controls select { width: 100%; }
.smart-planner-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
}
.smart-recommendation { margin-top: 14px; }
.smart-recommendation-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: center;
  background: white;
  border: 1px solid var(--line);
  border-left: 5px solid var(--gold);
  border-radius: 14px;
  padding: 15px;
}
.smart-recommendation-card h3 { margin: 2px 0 5px; font-size: 20px; }
.smart-recommendation-meta { display: flex; gap: 14px; flex-wrap: wrap; color: var(--muted); font-size: 13px; margin-top: 8px; }
.smart-recommendation-meta strong { color: var(--ink); }
.smart-why { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.smart-reason {
  display: inline-flex;
  padding: 5px 8px;
  border-radius: 999px;
  background: #f6eef6;
  color: var(--brand);
  font-size: 12px;
  font-weight: 750;
}
.badge.smart { background: #fff0cf; color: #765112; }
.meal-card.smart-build { border-color: #e4c77b; }
.smart-fit-note { color: var(--muted); font-size: 13px; margin: -2px 0 0; }

@media (max-width: 900px) {
  .smart-planner-controls { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 580px) {
  .smart-planner-controls { grid-template-columns: 1fr; }
  .smart-planner-footer, .smart-recommendation-card { grid-template-columns: 1fr; display: grid; }
}


/* v0.10 recommendation intelligence */
.smart-recommendation-list { display: grid; gap: 12px; }
.smart-recommendation-list .smart-recommendation-card:first-child {
  border-left-width: 6px;
  box-shadow: 0 8px 24px rgba(64, 31, 55, 0.08);
}
.smart-priority-note {
  margin-bottom: 12px;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff8e9;
  color: var(--ink);
  font-size: 13px;
}
.smart-after-note { margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.smart-after-note strong { color: var(--ink); }


/* v1.0 product polish and diverse recommendations */
.version-badge {
  display: inline-flex;
  align-items: center;
  margin-left: 8px;
  padding: 3px 7px;
  border: 1px solid rgba(255,255,255,.45);
  border-radius: 999px;
  font-size: 10px;
  letter-spacing: .08em;
  vertical-align: 1px;
}
.smart-planner-card {
  background: linear-gradient(135deg, #fffaf6 0%, #f9f0f6 100%);
}
.smart-recommendation-card.smart-best { border-left-color: var(--gold); }
.smart-recommendation-card.smart-quick { border-left-color: var(--good); }
.smart-recommendation-card.smart-different { border-left-color: var(--brand-2); }
.smart-recommendation-card .eyebrow { color: var(--brand); }
.smart-recommendation-card.smart-quick .eyebrow { color: var(--good); }
.smart-recommendation-card.smart-different .eyebrow { color: var(--brand-2); }

/* v1.1 — custom recipes and ingredient nutrition database */
.recipe-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 10px;
  margin-bottom: 16px;
}
.my-recipe-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.my-recipe-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.my-recipe-card h3 { margin: 3px 0 7px; font-size: 20px; }
.my-recipe-card .recipe-card-macros {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
  margin: 9px 0;
}
.my-recipe-card .recipe-card-macros strong { color: var(--ink); }
.recipe-builder-dialog { max-width: 920px; }
.recipe-builder-dialog textarea { width: 100%; resize: vertical; }
.builder-section-head {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 12px;
  margin-top: 18px;
  margin-bottom: 8px;
}
.builder-section-head h3 { margin: 0 0 3px; }
.builder-section-head p { margin: 0; }
.recipe-builder-rows { display: grid; gap: 8px; }
.recipe-builder-row {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) 130px 95px auto;
  gap: 8px;
  align-items: center;
  padding: 9px;
  background: #fffaf7;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.recipe-builder-row.staple-row { grid-template-columns: minmax(0, 1.5fr) minmax(150px, .8fr) auto; }
.recipe-builder-row select, .recipe-builder-row input { width: 100%; }
.recipe-builder-unit {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  padding-left: 4px;
}
.recipe-builder-remove {
  border: 0;
  background: transparent;
  color: var(--danger);
  font-weight: 800;
  cursor: pointer;
  padding: 8px;
}
.recipe-nutrition-preview {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin: 16px 0 8px;
}
.recipe-nutrition-preview > div {
  background: #fff7ef;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  display: grid;
  gap: 3px;
}
.recipe-nutrition-preview span { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
.recipe-nutrition-preview strong { font-size: 17px; }
.builder-warning {
  background: #fff4dd;
  border: 1px solid #ead09e;
  color: #72531a;
  border-radius: 10px;
  padding: 9px 11px;
  margin: 8px 0 14px;
}
.nutrition-details {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: #fffaf7;
}
.nutrition-details summary { cursor: pointer; font-weight: 800; }
.hint-inline { color: var(--muted); font-weight: 500; font-size: 12px; }
.nutrition-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin: 10px 0;
}
.nutrition-grid label { font-size: 12px; }
.inline-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.nutrition-ready { color: var(--good); font-weight: 700; }
.nutrition-missing { color: var(--warn); font-weight: 700; }
.serving-control {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  white-space: nowrap;
}
.serving-control select { min-width: 86px; }
.meal-editor-toolbar.v11 { align-items: center; }
.save-smart-note {
  border: 1px solid #dcc6d4;
  background: #fbf1f8;
  border-radius: 12px;
  padding: 10px 12px;
  margin: 12px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

@media (max-width: 800px) {
  .my-recipe-grid { grid-template-columns: 1fr; }
  .recipe-toolbar { grid-template-columns: 1fr; }
  .recipe-nutrition-preview { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .nutrition-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .recipe-builder-row { grid-template-columns: 1fr 100px 70px auto; }
}
@media (max-width: 560px) {
  .recipe-builder-row, .recipe-builder-row.staple-row { grid-template-columns: 1fr; }
  .recipe-builder-remove { justify-self: start; }
  .builder-section-head { align-items: start; flex-direction: column; }
  .recipe-nutrition-preview { grid-template-columns: 1fr 1fr; }
  .nutrition-grid { grid-template-columns: 1fr 1fr; }
}

/* v1.2 — packaged products & barcode workflow */
.product-dialog { max-width: 880px; }
.product-section {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  margin: 14px 0;
  background: color-mix(in srgb, var(--surface) 92%, var(--accent));
}

/* v1.3 — first-run setup */
.onboarding-dialog { max-width: 780px; }
.estimate-panel {
  margin-top: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg);
}
.estimate-panel .hint:first-child { margin-top: 0; }
.onboarding-actions { justify-content: space-between; }
body.onboarding-active main,
body.onboarding-active .app-header { filter: blur(1px); pointer-events: none; user-select: none; }

@media (max-width: 680px) {
  .onboarding-actions { align-items: stretch; }
  .onboarding-actions .btn { width: 100%; }
}
.product-section-head { margin-bottom: 12px; }
.product-section-head strong { display: block; font-size: 1rem; }
.product-section-head small { display: block; margin-top: 3px; color: var(--muted); }
.barcode-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto;
  gap: 10px;
  align-items: end;
}
.three-col {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.inline-field { display: flex; align-items: center; gap: 8px; }
.inline-field input { flex: 1; }
.product-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 5px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .03em;
  background: var(--accent);
  color: var(--brand);
}
.product-meta { display: block; margin-top: 4px; color: var(--muted); font-size: .78rem; }
.scanner-dialog { width: min(620px, calc(100vw - 28px)); }
.scanner-frame {
  position: relative;
  min-height: 280px;
  background: #111;
  border-radius: 16px;
  overflow: hidden;
}
#barcodeVideo { width: 100%; min-height: 280px; object-fit: cover; display: block; }
.scanner-guide {
  position: absolute;
  left: 10%; right: 10%; top: 35%; height: 30%;
  border: 2px solid rgba(255,255,255,.9);
  border-radius: 12px;
  box-shadow: 0 0 0 999px rgba(0,0,0,.18);
  pointer-events: none;
}
.local-library-note {
  border-left: 4px solid var(--accent);
  padding: 10px 12px;
  background: var(--accent);
  border-radius: 8px;
}
@media (max-width: 760px) {
  .barcode-row, .three-col { grid-template-columns: 1fr; }
}

/* v1.2.1 — dialog usability bugfix */
dialog {
  max-height: calc(100dvh - 24px);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}
#productDialog { width: min(900px, calc(100vw - 28px)); }
#recipeDialog { width: min(940px, calc(100vw - 28px)); }
#mealDialog, #cookingDialog { width: min(800px, calc(100vw - 28px)); }
.dialog-card { min-width: 0; }
.dialog-card input:not([type="checkbox"]):not([type="radio"]),
.dialog-card select,
.dialog-card textarea {
  width: 100%;
  min-width: 0;
}
.dialog-head {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  padding-block: 4px 8px;
}
.icon-btn { flex: 0 0 auto; }
.barcode-row > *, .two-col > *, .three-col > * { min-width: 0; }
@media (max-width: 620px) {
  dialog { width: calc(100vw - 16px); max-height: calc(100dvh - 16px); }
  .dialog-card { padding: 16px; }
  .two-col, .three-col, .barcode-row { grid-template-columns: 1fr; }
}


/* v1.4.1 — friend-test data controls */
.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: white;
}
.btn-danger:hover { filter: brightness(.96); }
.data-privacy-card {
  border-color: #e4c7cb;
  background: color-mix(in srgb, var(--surface) 94%, var(--danger-bg));
}
.data-privacy-card p { line-height: 1.5; }


/* v1.4.2 — selectable colour themes */
.appearance-card label { display: grid; gap: 6px; margin: 12px 0; }
.theme-preview {
  display: grid;
  grid-template-columns: repeat(4, 34px);
  gap: 7px;
  margin: 10px 0 4px;
}
.theme-preview span {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line);
}
.theme-preview-default span:nth-child(1) { background: #5b2b55; }
.theme-preview-default span:nth-child(2) { background: #d36c52; }
.theme-preview-default span:nth-child(3) { background: #f7e1d7; }
.theme-preview-default span:nth-child(4) { background: #fff8f2; }
.theme-preview-sage span:nth-child(1) { background: #315f55; }
.theme-preview-sage span:nth-child(2) { background: #8eaa8b; }
.theme-preview-sage span:nth-child(3) { background: #e1eadf; }
.theme-preview-sage span:nth-child(4) { background: #f7f4ec; }
.theme-preview-dark span:nth-child(1) { background: #b98ab5; }
.theme-preview-dark span:nth-child(2) { background: #d18a78; }
.theme-preview-dark span:nth-child(3) { background: #353038; }
.theme-preview-dark span:nth-child(4) { background: #171519; }

html[data-theme="sage"] {
  --bg: #f7f4ec;
  --surface: #fffdf8;
  --ink: #26332f;
  --muted: #68766f;
  --brand: #315f55;
  --brand-2: #b56e55;
  --accent: #e1eadf;
  --line: #d8dfd5;
  --warn: #8a610f;
  --warn-bg: #fff0c9;
  --danger: #9c4850;
  --danger-bg: #fbeaec;
  --good: #356f5c;
  --good-bg: #e0f0e9;
  --gold: #d3aa4d;
  --shadow: 0 14px 35px rgba(49, 95, 85, .10);
}
html[data-theme="sage"] .app-header {
  background: linear-gradient(135deg, #214c43 0%, #3f7567 55%, #819d7d 100%);
}
html[data-theme="sage"] .smart-planner-card {
  background: linear-gradient(135deg, #fffdf7 0%, #edf3ea 100%);
  border-color: #ccd9ca;
}
html[data-theme="sage"] .smart-reason,
html[data-theme="sage"] .active-timer-chip,
html[data-theme="sage"] .substitution-change { background: #edf3ea; border-color: #ccd9ca; }
html[data-theme="sage"] .data-privacy-card { border-color: #ddc9c9; }

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #171519;
  --surface: #242127;
  --ink: #f4eef2;
  --muted: #b9adb5;
  --brand: #b98ab5;
  --brand-2: #d18a78;
  --accent: #3a3038;
  --line: #4b434a;
  --warn: #efc66e;
  --warn-bg: #3c311b;
  --danger: #f0a6ad;
  --danger-bg: #40252b;
  --good: #83cbb9;
  --good-bg: #1d3731;
  --gold: #dfbb68;
  --shadow: 0 14px 35px rgba(0, 0, 0, .28);
}
html[data-theme="dark"] body { background: var(--bg); color: var(--ink); }
html[data-theme="dark"] .app-header {
  background: linear-gradient(135deg, #18161b 0%, #30262f 55%, #493038 100%);
}
html[data-theme="dark"] .summary-card,
html[data-theme="dark"] .meal-card,
html[data-theme="dark"] .settings-card,
html[data-theme="dark"] .shopping-item,
html[data-theme="dark"] .table-wrap,
html[data-theme="dark"] .empty-state,
html[data-theme="dark"] .today-card,
html[data-theme="dark"] .my-recipe-card,
html[data-theme="dark"] .smart-recommendation-card,
html[data-theme="dark"] .cooking-step-card,
html[data-theme="dark"] .mobile-more-link {
  background: var(--surface);
  color: var(--ink);
}
html[data-theme="dark"] .data-table th { background: #302a31; }
html[data-theme="dark"] .data-table tr.inventory-row { background: var(--surface); }
html[data-theme="dark"] select,
html[data-theme="dark"] input[type="search"],
html[data-theme="dark"] input[type="number"],
html[data-theme="dark"] input[type="text"],
html[data-theme="dark"] input[type="date"],
html[data-theme="dark"] input[type="email"],
html[data-theme="dark"] textarea {
  background: #1e1b20;
  color: var(--ink);
  border-color: var(--line);
}
html[data-theme="dark"] .dialog-head,
html[data-theme="dark"] .dialog-card { background: var(--surface); color: var(--ink); }
html[data-theme="dark"] .icon-btn,
html[data-theme="dark"] .row-actions button,
html[data-theme="dark"] .qty-controls button,
html[data-theme="dark"] .step-btn { background: #302a31; color: var(--ink); border-color: var(--line); }
html[data-theme="dark"] .match-ring::after { background: var(--surface); }
html[data-theme="dark"] .smart-planner-card {
  background: linear-gradient(135deg, #242127 0%, #302831 100%);
  border-color: var(--line);
}
html[data-theme="dark"] .recipe-builder-row,
html[data-theme="dark"] .nutrition-details,
html[data-theme="dark"] .product-section,
html[data-theme="dark"] .recipe-nutrition-preview > div { background: #2b272d; border-color: var(--line); }
html[data-theme="dark"] .purchase-total,
html[data-theme="dark"] .history-edit-preview,
html[data-theme="dark"] .parallel-note,
html[data-theme="dark"] .smart-priority-note,
html[data-theme="dark"] .live-nutrition,
html[data-theme="dark"] .substitute-box { background: #3a3022; border-color: #5e4e31; color: #f1d8a4; }
html[data-theme="dark"] .cook-status { background: var(--danger-bg); border-color: #634047; }
html[data-theme="dark"] .cook-status.good { background: var(--good-bg); border-color: #31594f; }
html[data-theme="dark"] .substitution-change,
html[data-theme="dark"] .smart-reason,
html[data-theme="dark"] .active-timer-chip { background: #342c35; border-color: #524553; color: #d6acd1; }
html[data-theme="dark"] .cooking-progress-track { background: #39333a; }
html[data-theme="dark"] .local-library-note { background: #342c35; }
html[data-theme="dark"] .data-privacy-card { background: #2d2529; border-color: #5a4148; }
html[data-theme="dark"] .mobile-nav { background: color-mix(in srgb, var(--surface) 96%, transparent); }
html[data-theme="dark"] .inventory-toolbar { background: var(--bg); }

/* v1.4.3 — clearer target estimates and unmistakable demo mode */
.demo-mode-banner {
  margin: 0 0 14px;
  padding: 12px 14px;
  border: 1px solid var(--warn);
  border-radius: 13px;
  background: var(--warn-bg);
  color: var(--ink);
  line-height: 1.45;
  font-size: 14px;
}
.demo-mode-banner strong { color: var(--warn); }
