/* Family Meal Planner — mobile-first styles */
:root {
  color-scheme: light;
  --bg: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f2f1ed;
  --text: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --border: rgba(11,11,11,0.10);
  --gridline: #e1e0d9;
  --accent: #1baf7a;       /* veggie / primary green */
  --accent-dark: #199e70;
  --protein: #2a78d6;      /* protein blue */
  --money: #4a3aa7;        /* violet for spend */
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --radius: 14px;
  --radius-sm: 9px;
  --tap: 48px;
  --shadow: 0 1px 2px rgba(11,11,11,0.06), 0 4px 16px rgba(11,11,11,0.05);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232322;
  --text: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --border: rgba(255,255,255,0.12);
  --gridline: #2c2c2a;
  --accent: #199e70;
  --accent-dark: #1baf7a;
  --protein: #3987e5;
  --money: #9085e9;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #e66767;
  --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 4px 16px rgba(0,0,0,0.3);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    color-scheme: dark;
    --bg: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232322;
    --text: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --border: rgba(255,255,255,0.12);
    --gridline: #2c2c2a;
    --accent: #199e70;
    --accent-dark: #1baf7a;
    --protein: #3987e5;
    --money: #9085e9;
    --critical: #e66767;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

#app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-title { font-size: 18px; font-weight: 700; }

.icon-btn {
  width: var(--tap);
  height: var(--tap);
  border: none;
  background: transparent;
  font-size: 20px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
}
.icon-btn:active { background: var(--surface-2); }

.view-host {
  flex: 1;
  overflow-y: auto;
  padding: 12px 12px calc(var(--tap) + 28px);
  -webkit-overflow-scrolling: touch;
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  border: none;
  background: transparent;
  padding: 8px 2px 6px;
  font-size: 11px;
  color: var(--text-muted);
  min-height: var(--tap);
  cursor: pointer;
}
.nav-btn .nav-icon { font-size: 20px; }
.nav-btn.active { color: var(--accent); font-weight: 700; }

/* Cards & sections */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 4px 2px 8px;
}
.row { display: flex; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }

h1, h2, h3 { margin: 0 0 6px; }
p { margin: 0 0 8px; color: var(--text-secondary); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--tap);
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); color: #fff; border-color: transparent; }
.btn.protein { background: var(--protein); color: #fff; border-color: transparent; }
.btn.danger { background: var(--critical); color: #fff; border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn.sm { min-height: 38px; padding: 6px 12px; font-size: 13px; }
.fab {
  position: fixed;
  right: 18px;
  bottom: calc(var(--tap) + 34px);
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 26px;
  border: none;
  box-shadow: var(--shadow);
  z-index: 15;
  cursor: pointer;
}

/* Forms */
label { display: block; font-size: 13px; font-weight: 600; color: var(--text-secondary); margin: 10px 0 4px; }
input[type="text"], input[type="number"], input[type="date"], select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.field-row { display: flex; gap: 8px; }
.field-row > * { flex: 1; }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--tap);
  padding: 4px 0;
}
.checkbox-row input[type="checkbox"] { width: 24px; height: 24px; flex-shrink: 0; accent-color: var(--accent); }

/* Tags & chips */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
}
.chip.active { background: var(--accent); color: #fff; border-color: transparent; }
.chip.small { font-size: 11px; padding: 3px 8px; }
.tag-organic { background: #eef6f0; color: var(--accent-dark); border-color: transparent; }
:root[data-theme="dark"] .tag-organic, body:has(#app.dark) .tag-organic { background: rgba(25,158,112,0.18); color: #4fd39a; }

/* Recipe card */
.recipe-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.recipe-card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.recipe-emoji { font-size: 28px; line-height: 1; }
.recipe-name { font-size: 16px; font-weight: 700; margin: 0; }
.recipe-meta { font-size: 12.5px; color: var(--text-secondary); margin-top: 2px; }
.recipe-stats { display: flex; gap: 12px; margin-top: 8px; font-size: 12.5px; }
.stat-pill { display: flex; align-items: center; gap: 4px; color: var(--text-secondary); }
.fav-btn { background: none; border: none; font-size: 22px; cursor: pointer; padding: 4px; color: var(--text-muted); }
.fav-btn.active { color: var(--warning); }
.dismiss-btn { background: none; border: none; font-size: 17px; cursor: pointer; padding: 4px; color: var(--text-muted); opacity: 0.55; }
.dismiss-btn.active { color: var(--critical); opacity: 1; }

/* Progress bars */
.progress-wrap { background: var(--surface-2); border-radius: 999px; height: 14px; overflow: hidden; border: 1px solid var(--border); }
.progress-fill { height: 100%; border-radius: 999px; transition: width 0.3s ease; }
.progress-label { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--text-secondary); margin-top: 4px; }

.ring-row { display: flex; gap: 16px; justify-content: space-around; text-align: center; }
.ring { position: relative; width: 92px; height: 92px; }
.ring svg { transform: rotate(-90deg); }
.ring-value { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; flex-direction: column; }
.ring-value b { font-size: 16px; }
.ring-value span { font-size: 10px; color: var(--text-muted); }
.ring-label { font-size: 12.5px; color: var(--text-secondary); margin-top: 6px; font-weight: 600; }

/* Planner grid */
.week-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.day-block { margin-bottom: 10px; }
.day-header { font-weight: 700; font-size: 14px; margin: 8px 2px 6px; display: flex; justify-content: space-between; align-items: center; }
.day-header .day-date { color: var(--text-muted); font-weight: 500; font-size: 12px; }
.slot-row { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px; margin-bottom: 6px; min-height: var(--tap); }
.slot-label { width: 68px; font-size: 12px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; flex-shrink: 0; }
.slot-content { flex: 1; font-size: 14px; display: flex; align-items: center; gap: 6px; min-width: 0; }
.slot-content .empty { color: var(--text-muted); }
.slot-content .recipe-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slot-clear { background: none; border: none; color: var(--text-muted); font-size: 18px; cursor: pointer; padding: 6px; flex-shrink: 0; }

/* Grocery list */
.grocery-cat { margin-bottom: 14px; }
.grocery-cat-title { font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--accent-dark); margin: 6px 2px; }
.grocery-item { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px; margin-bottom: 6px; }
.grocery-item.checked .item-name { text-decoration: line-through; color: var(--text-muted); }
.item-name { flex: 1; font-size: 14.5px; min-width: 0; }
.item-qty { font-size: 12px; color: var(--text-muted); }
.item-price { width: 74px; }
.item-price input { min-height: 36px; padding: 4px 8px; font-size: 14px; text-align: right; }

/* Tabs (sub-nav within a view) */
.subtabs { display: flex; gap: 6px; margin-bottom: 12px; overflow-x: auto; padding-bottom: 2px; }
.subtab { flex-shrink: 0; padding: 8px 14px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); font-size: 13.5px; font-weight: 600; color: var(--text-secondary); cursor: pointer; min-height: 38px; }
.subtab.active { background: var(--accent); color: #fff; border-color: transparent; }

/* Modal */
.modal-root { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,0.45); display: flex; align-items: flex-end; }
.modal-root[hidden] { display: none; }
.modal-sheet {
  background: var(--bg);
  width: 100%;
  max-height: 92dvh;
  border-radius: 18px 18px 0 0;
  padding: 14px 16px calc(env(safe-area-inset-bottom) + 16px);
  overflow-y: auto;
  animation: slideUp 0.22s ease;
}
@keyframes slideUp { from { transform: translateY(24px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; position: sticky; top: 0; background: var(--bg); padding: 4px 0 8px; }
.modal-title { font-size: 17px; font-weight: 700; }
.close-btn { background: var(--surface-2); border: none; width: 36px; height: 36px; border-radius: 50%; font-size: 16px; cursor: pointer; color: var(--text); }

.empty-state { text-align: center; padding: 32px 16px; color: var(--text-muted); }
.empty-state .big { font-size: 36px; margin-bottom: 8px; }

/* Toasts */
#toastHost { position: fixed; bottom: calc(var(--tap) + 20px); left: 0; right: 0; display: flex; flex-direction: column; align-items: center; z-index: 60; pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 13.5px; margin-top: 6px; opacity: 0; transform: translateY(6px); transition: all 0.2s ease; box-shadow: var(--shadow); }
.toast.show { opacity: 1; transform: translateY(0); }

/* Recipe picker list inside modal */
.picker-item { display: flex; align-items: center; gap: 10px; padding: 10px 6px; border-bottom: 1px solid var(--border); cursor: pointer; }
.picker-item:active { background: var(--surface-2); }

/* Ingredient editor rows */
.ingredient-row { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px; margin-bottom: 8px; background: var(--surface-2); }
.ingredient-row .row { margin-bottom: 6px; }
.remove-ing { background: none; border: none; color: var(--critical); font-size: 13px; font-weight: 700; cursor: pointer; padding: 6px; }

/* Bar chart (spend trend) */
.bar-chart { display: flex; align-items: flex-end; gap: 8px; height: 130px; padding: 8px 4px 0; border-bottom: 1px solid var(--gridline); }
.bar-chart-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; }
.bar-chart-bar { width: 100%; max-width: 28px; border-radius: 4px 4px 0 0; background: var(--money); min-height: 2px; }
.bar-chart-label { font-size: 10px; color: var(--text-muted); margin-top: 4px; }

.legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-secondary); margin-top: 8px; flex-wrap: wrap; }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 4px; }

.helper-text { font-size: 12px; color: var(--text-muted); margin-top: -2px; margin-bottom: 8px; }

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

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

@media (min-width: 640px) {
  .view-host { padding-left: 24px; padding-right: 24px; max-width: 640px; margin: 0 auto; width: 100%; }
  .modal-sheet { max-width: 640px; margin: 0 auto; border-radius: 18px; }
  .modal-root { align-items: center; }
}
