/* ============================================================
 * Home Meal Planner — styles
 * Palette: Tangerine Dream (accent) · Jungle Teal (primary) ·
 * Deep Space Blue (ink) · Celadon · Mint Cream (bg). Font: Montserrat.
 * ============================================================ */
:root {
  --bg:        #f6f7f8;   /* clean off-white */
  --surface:   #ffffff;
  --surface-2: #eef0f2;   /* neutral light panel */
  --ink:       #183446;   /* Deep Space Blue */
  --muted:     #647a84;   /* muted blue-gray */
  --line:      #dce8d4;   /* soft green border */
  --primary:   #498467;   /* Jungle Teal */
  --primary-d: #3a6b53;
  --accent:    #f79256;   /* Tangerine Dream (accent) */
  --accent-d:  #e87d3c;
  --celadon:   #b2d3a8;   /* Celadon */
  --celadon-2: #cfe4c8;
  --danger:    #c0392b;
  --radius:    14px;
  --shadow:    0 1px 2px rgba(24,52,70,.05), 0 6px 20px rgba(24,52,70,.07);
  --font:      'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Layout ---------- */
.app-header {
  position: sticky; top: 0; z-index: 20;
  background: rgba(246,247,248,.92);
  backdrop-filter: saturate(1.2) blur(8px);
  border-bottom: 1px solid var(--line);
}
.app-header .bar {
  max-width: 1040px; margin: 0 auto; padding: 14px 20px;
  display: flex; align-items: center; gap: 18px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 1.15rem; }
.brand .logo { font-size: 1.5rem; }
.brand-logo { height: 54px; width: auto; display: block; }
.brand-text { display: inline-flex; align-items: center; gap: 8px; }
@media (max-width: 620px) { .brand-logo { height: 44px; } }
.nav { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.nav button {
  border: 0; background: transparent; color: var(--muted);
  font: inherit; font-weight: 500; padding: 8px 14px; border-radius: 10px; cursor: pointer;
}
.nav button:hover { background: var(--surface-2); color: var(--ink); }
.nav button.active { background: var(--primary); color: #fff; }
.nav button.soon { opacity: .5; cursor: not-allowed; }
.nav button.soon::after { content: ' · soon'; font-size: .72em; }

main { max-width: 1040px; margin: 0 auto; padding: 26px 20px 80px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  border: 1px solid transparent; border-radius: 10px; padding: 9px 16px;
  font: inherit; font-weight: 600; cursor: pointer; transition: transform .04s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-d); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-ghost { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: transparent; color: var(--danger); border-color: transparent; }
.btn-danger:hover { background: #fbeae8; }
.btn-sm { padding: 6px 11px; font-size: .85rem; }
.btn-icon { padding: 6px 9px; }

/* ---------- Page header row ---------- */
.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.page-head h1 { margin: 0; font-size: 1.5rem; }
.page-head .spacer { margin-left: auto; }
.page-sub { color: var(--muted); font-size: .92rem; margin: -12px 0 20px; }
/* On the planner the sub-line follows the week box, where the negative top
   margin above would crowd it — push it clear of the box instead. */
.weekbar + .page-sub { margin-top: 30px; }

/* ---------- Toolbar (search/filter) ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; align-items: center; }
.input, .select, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; outline: none;
}
.input:focus, .select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(47,125,79,.12); }
.search { flex: 1; min-width: 200px; }

/* ---------- Recipe cards ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; cursor: pointer; transition: transform .08s ease, box-shadow .08s ease;
  display: flex; flex-direction: column; gap: 10px;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 4px 8px rgba(42,38,34,.07), 0 14px 30px rgba(42,38,34,.09); }
.card h3 { margin: 0; font-size: 1.1rem; }
.card .meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card .count { color: var(--muted); font-size: .85rem; margin-top: auto; }

/* ---------- Badges & chips ---------- */
.badge {
  display: inline-block; font-size: .72rem; font-weight: 600; letter-spacing: .02em;
  padding: 3px 9px; border-radius: 999px; text-transform: capitalize;
}
.badge.breakfast { background: #fdeadb; color: #b5581f; }
.badge.lunch     { background: #e6f0e0; color: #3a6b53; }
.badge.dinner    { background: #dbe6ec; color: #183446; }
.chip {
  display: inline-block; font-size: .74rem; color: var(--muted);
  background: var(--surface-2); border-radius: 999px; padding: 2px 9px;
}
.tag-est { color: var(--accent); font-weight: 600; }

/* ---------- Editor ---------- */
.editor { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; }
.field { margin-bottom: 18px; }
.field label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
.field .hint { color: var(--muted); font-weight: 400; font-size: .82rem; }
.field .input, .field .select, .field textarea { width: 100%; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.ing-table { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.ing-row {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) 68px 120px 184px 30px;
  gap: 8px; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line);
}
.ing-row:last-child { border-bottom: 0; }
.ing-row .flags { display: flex; gap: 10px; align-items: center; font-size: .8rem; color: var(--muted); white-space: nowrap; }
.ing-row .flags label { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }
.ing-row input[type="text"], .ing-row input[type="number"] { width: 100%; padding: 7px 9px; }
.ing-row .vg { grid-column: 1 / -1; margin-top: -2px; }
.ing-head { background: var(--surface-2); font-size: .78rem; color: var(--muted); font-weight: 600; }
.ing-head .flags { color: var(--muted); }
.linkbtn { background: none; border: 0; color: var(--primary); font: inherit; font-size: .72rem; font-weight: 600; cursor: pointer; padding: 1px 2px; text-decoration: underline; white-space: nowrap; }
.linkbtn:hover { color: var(--primary-d); }

.editor-actions { display: flex; gap: 10px; margin-top: 22px; align-items: center; }
.editor-actions .spacer { margin-left: auto; }

/* ---------- Empty & misc ---------- */
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.empty .big { font-size: 2.4rem; margin-bottom: 8px; }
.mode-flag {
  font-size: .74rem; color: var(--muted); border: 1px solid var(--line);
  border-radius: 999px; padding: 2px 10px; background: var(--surface);
}
.mode-flag.local b { color: var(--accent); }
.mode-flag.server b { color: var(--primary); }
.mode-flag.warn { border-color: var(--danger); background: #fbeae8; color: var(--danger); cursor: help; }
.mode-flag.warn b { color: var(--danger); }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 10px;
  box-shadow: var(--shadow); font-size: .9rem; z-index: 50; opacity: 0; transition: opacity .2s;
}
.toast.show { opacity: 1; }

.divider { height: 1px; background: var(--line); margin: 22px 0; border: 0; }

/* Ingredient manager table */
/* inline add-forms (replace window.prompt, which browsers can suppress) */
.inline-form {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--primary); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 14px;
}
.inline-form-title { font-weight: 700; font-size: .9rem; color: var(--primary); margin-right: 4px; }
.inline-form .input { flex: 1; min-width: 160px; }

/* bottom-of-page store manager (Ingredients) */
.stores-panel { margin-top: 34px; padding-top: 20px; border-top: 1px solid var(--line); }
.stores-panel-head { font-weight: 700; font-size: .95rem; color: var(--ink); margin-bottom: 6px; }
.store-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); margin-bottom: 8px;
}
.store-row-main { flex: 1; display: flex; align-items: baseline; gap: 10px; min-width: 140px; }
.store-row-name { font-weight: 600; }
.store-row-url { color: var(--muted); font-size: .8rem; }
.store-row-warn { color: var(--danger); font-size: .82rem; font-weight: 600; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.list-table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; min-width: 620px; }
.list-table th, .list-table td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); font-size: .92rem; }
.list-table th { background: var(--surface-2); color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
.list-table tr:last-child td { border-bottom: 0; }
.list-table input { width: 100%; padding: 6px 8px; }
.aisle-empty { color: var(--accent); font-style: italic; }
.aisle-empty::placeholder { color: var(--accent); opacity: .7; }

/* ---------- aisle-context switcher (Ingredients) ---------- */
.context-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.ctx {
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  font: inherit; font-weight: 600; font-size: .85rem; padding: 6px 13px; border-radius: 999px; cursor: pointer;
}
.ctx:hover { background: var(--surface-2); color: var(--ink); }
.ctx.on { background: var(--primary); color: #fff; border-color: var(--primary); }
.ctx.add { color: var(--accent-d); border-style: dashed; }

/* ---------- Planner ---------- */
.weekbar {
  display: flex; align-items: center; gap: 12px; margin-bottom: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; width: fit-content;
}
.weekbar-label { text-align: center; min-width: 190px; }
.wk-range { font-weight: 600; }
.wk-tag { font-size: .72rem; color: var(--accent-d); font-weight: 600; }

/* calendar: responsive grid of day cards */
.calendar { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; margin-top: 32px; }
.day-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px;
  display: flex; flex-direction: column; gap: 8px; min-height: 120px;
}
.day-card.today { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(247,146,86,.14); }
.day-card.unscheduled { margin-top: 16px; }
.day-head { display: flex; align-items: baseline; gap: 8px; border-bottom: 1px solid var(--line); padding-bottom: 7px; }
.day-name { font-weight: 700; font-size: .95rem; }
.day-date { color: var(--muted); font-size: .8rem; }
.day-today { margin-left: auto; font-size: .66rem; font-weight: 700; text-transform: uppercase; color: var(--accent-d); letter-spacing: .04em; }
.day-meals { display: flex; flex-direction: column; gap: 8px; }
.day-empty { color: var(--muted); font-size: .82rem; font-style: italic; padding: 4px 0; }

.meal-card { background: var(--surface-2); border-radius: 9px; padding: 9px 10px; display: flex; flex-direction: column; gap: 7px; }
.meal-top { display: flex; align-items: center; gap: 7px; }
.meal-name { font-weight: 600; font-size: .92rem; line-height: 1.25; }
.meal-bottom { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.serv-mini { display: flex; align-items: center; gap: 5px; }
.serv-input { width: 50px; padding: 4px 6px; font: inherit; border: 1px solid var(--line); border-radius: 7px; text-align: center; background: var(--surface); }
.serv-input:focus { border-color: var(--primary); outline: none; }
.day-move { font: inherit; font-size: .8rem; padding: 4px 6px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); color: var(--muted); }
.add-meal {
  font: inherit; font-size: .85rem; padding: 7px 9px; border: 1px dashed var(--line); border-radius: 8px;
  background: var(--surface); color: var(--primary); font-weight: 600; cursor: pointer; margin-top: auto;
}
.add-meal:hover { border-color: var(--primary); background: var(--surface-2); }
.g-staple { font-size: .68rem; color: var(--muted); background: var(--surface-2); border-radius: 999px; padding: 1px 8px; margin-left: 6px; text-transform: uppercase; letter-spacing: .03em; }

/* ---------- Grocery list ---------- */
.store-picker { display: flex; align-items: center; gap: 8px; }
.grocery { margin-top: 8px; }
.aisle-group { margin-bottom: 22px; }
.aisle-title {
  font-size: .82rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  color: var(--primary); padding-bottom: 6px; margin-bottom: 6px; border-bottom: 2px solid var(--celadon);
}
.aisle-items { display: flex; flex-direction: column; }
.grocery-row {
  display: flex; align-items: center; gap: 13px; padding: 10px 6px; border-bottom: 1px solid var(--line); cursor: pointer;
  border-radius: 8px; transition: background-color .15s ease;
}
.grocery-row:last-child { border-bottom: 0; }
.grocery-row input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--primary); flex: none; }
.grocery-row.checked { background: var(--surface-2); }
.grocery-row.checked .g-main { opacity: .45; text-decoration: line-through; }
.g-main { flex: 1; display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.g-name { font-weight: 500; }
.g-qty { color: var(--muted); font-size: .9rem; }
.g-est { color: var(--accent-d); font-weight: 700; }
.g-opt { color: var(--muted); font-size: .82rem; font-style: italic; }
.g-from { color: var(--muted); font-size: .75rem; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.g-side { display: flex; align-items: center; gap: 10px; flex: none; }
select.g-store { padding: 4px 8px; font-size: .8rem; min-width: 92px; }
.grocery-section { margin-bottom: 6px; }
.store-header {
  font-size: .95rem; font-weight: 700; color: var(--ink);
  margin: 18px 0 4px; padding: 6px 0; border-bottom: 2px solid var(--primary);
}
.grocery-section:first-child .store-header { margin-top: 0; }
.btn-disabled, .btn:disabled { opacity: .5; cursor: default; pointer-events: none; }

.extra-bar { display: flex; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.extra-bar .input:first-child { flex: 1; min-width: 200px; }

/* ---------- Ad Scan ---------- */
.notice { background: #fef6ec; border: 1px solid #f6d9b8; color: #8a5a25; border-radius: 10px; padding: 12px 14px; margin-bottom: 18px; font-size: .9rem; }
.notice.error { background: #fbeae8; border-color: #eecac6; color: var(--danger); }
.file-input { display: block; margin-bottom: 10px; }
.ad-preview { border: 1px dashed var(--line); border-radius: 10px; padding: 10px; min-height: 60px; display: flex; align-items: center; justify-content: center; background: var(--surface-2); }
.ad-preview img { max-width: 100%; max-height: 320px; border-radius: 8px; }
.sale-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.sale-chip { background: var(--celadon-2); color: var(--primary-d); border-radius: 999px; padding: 4px 12px; font-size: .82rem; font-weight: 600; }

.scan-result { margin-top: 8px; }
.sugg-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 14px; }
.sugg-head { display: flex; align-items: center; gap: 10px; }
.sugg-head h3 { margin: 0; font-size: 1.12rem; }
.sugg-cost { color: var(--accent-d); font-weight: 700; font-size: .9rem; }
.sugg-why { color: var(--muted); margin: 8px 0; font-size: .92rem; }
.sugg-uses { font-size: .82rem; color: var(--primary-d); margin-bottom: 8px; }
.sugg-uses span { font-weight: 600; }
.sugg-ings { margin: 8px 0; padding-left: 20px; font-size: .9rem; }
.sugg-ings li { margin: 2px 0; }
.sugg-steps { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; font-size: .88rem; white-space: pre-wrap; }

@media (max-width: 620px) {
  .ing-row { grid-template-columns: 1fr 1fr; }
  .ing-row .flags { grid-column: 1 / -1; }
  .row-2 { grid-template-columns: 1fr; }
  .g-from { display: none; }
  .weekbar-label { min-width: 130px; }
}

/* planner: a day that's reached the 4-meal limit */
.day-full {
  text-align: center; font-size: .8rem; font-weight: 600; color: var(--muted);
  background: var(--surface-2); border: 1px dashed var(--line); border-radius: 8px; padding: 7px;
}
/* grocery: add-item bar hint spans the full row */
.extra-hint { flex-basis: 100%; margin-top: 2px; }

/* grocery: an item removed from this week's list (shown only via "Show removed") */
.grocery-row.removed { opacity: .5; }
.grocery-row.removed .g-name { text-decoration: line-through; }
.g-restore { color: var(--primary); }
/* the add-item bar now sits at the top of the list */
.extra-bar { margin-top: 0; margin-bottom: 22px; }
