/* ---------- tokens ---------- */
:root {
  --bg: #faf2f5;
  --surface: #ffffff;
  --surface-2: #efece0;
  --text: #22302a;
  --text-muted: #5c6b61;
  --primary: #2f5d50;
  --primary-hover: #244a40;
  --primary-tint: #e5efe9;
  --accent: #c98a3b;
  --accent-tint: #f7ead4;
  --border: #e2ddc9;
  --danger: #a5432b;
  --danger-tint: #f6e4dd;
  --heading: #9c3159;
  --heading-tint: #f7e5ec;
  --brand-color: #7a1f3a;
  --shadow: 0 1px 2px rgba(34, 48, 42, 0.06), 0 4px 14px rgba(34, 48, 42, 0.07);
  --radius: 12px;
  --font-display: "Century Gothic", CenturyGothic, AppleGothic, "URW Gothic", Futura, -apple-system, "Segoe UI", sans-serif;
  --font-body: "Century Gothic", CenturyGothic, AppleGothic, "URW Gothic", Futura, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #170f13;
    --surface: #1b2119;
    --surface-2: #232b21;
    --text: #eae7d9;
    --text-muted: #a3ac9c;
    --primary: #74c19b;
    --primary-hover: #8fd2ae;
    --primary-tint: #1c2c25;
    --accent: #e3a75c;
    --accent-tint: #2c2418;
    --border: #2b3327;
    --danger: #e08a6d;
    --danger-tint: #2f2019;
    --heading: #d9789a;
    --heading-tint: #2f1c25;
    --brand-color: #e08aa8;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 600; text-wrap: balance; margin: 0 0 0.4em; color: var(--heading); }
h1 { font-size: 1.9rem; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.1rem; }
p { margin: 0 0 0.8em; color: var(--text); }
a { color: var(--primary); }
button, input, textarea, select { font-family: inherit; font-size: 1rem; color: inherit; }
input, textarea, select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55em 0.7em;
  width: 100%;
}
input:focus, textarea:focus, select:focus, button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}
label { display: block; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 0.3em; font-weight: 600; }
.field { margin-bottom: 1rem; }
.numeric { font-variant-numeric: tabular-nums; }

button { cursor: pointer; border: none; border-radius: 8px; padding: 0.6em 1em; font-weight: 600; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface-2); color: var(--text); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: var(--danger-tint); color: var(--danger); }
.btn-danger:hover { filter: brightness(0.95); }
.btn-ghost { background: transparent; color: var(--text-muted); padding: 0.4em 0.6em; }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-icon { padding: 0.5em; border-radius: 8px; background: transparent; color: var(--text-muted); }
.btn-icon:hover { background: var(--surface-2); color: var(--text); }
.btn-block { width: 100%; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- app shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

.auth-shell {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.5rem;
}
.auth-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 2rem 1.75rem;
}
.auth-card .brand { display: flex; }

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.brand {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  padding: 0 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--brand-color);
  text-decoration: none;
}
.brand:hover { opacity: 0.8; }
.user-greeting {
  padding: 0 0.5rem;
  margin: -0.8rem 0 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.65rem 0.8rem;
  border-radius: 8px;
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
}
.nav-link .nav-icon { width: 1.4em; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.nav-link .nav-icon svg { width: 19px; height: 19px; }
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--primary-tint); color: var(--primary); }

.main-area { flex: 1; min-width: 0; padding-bottom: 5rem; }
.main-inner { max-width: 980px; margin: 0 auto; padding: 2rem 1.5rem; }

.mobile-topbar { display: none; }
.bottom-tabs { display: none; }

@media (max-width: 860px) {
  .sidebar { display: none; }
  .mobile-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.9rem 1.1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
  }
  .mobile-topbar .brand { margin: 0; font-size: 1.15rem; }
  .main-inner { padding: 1.25rem 1rem 1rem; }
  .bottom-tabs {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 0.4rem 0.3rem calc(0.4rem + env(safe-area-inset-bottom));
    z-index: 20;
  }
  .bottom-tabs .nav-link {
    flex: 1;
    flex-direction: column;
    gap: 0.15rem;
    font-size: 0.68rem;
    text-align: center;
    padding: 0.4rem 0.2rem;
    border-radius: 10px;
  }
  .bottom-tabs .nav-icon { width: auto; margin: 0 auto; }
  .bottom-tabs .nav-icon svg { width: 22px; height: 22px; }
}

/* ---------- top bar within pages ---------- */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.page-header .actions { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.search-row { display: flex; gap: 0.6rem; margin-bottom: 1rem; }
.search-row input { max-width: 340px; }

.category-row { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.chip {
  background: var(--surface); border: 1px solid var(--border); color: var(--text-muted);
  font-size: 0.82rem; font-weight: 600; padding: 0.4em 0.85em; border-radius: 999px;
}
.chip:hover { border-color: var(--primary); color: var(--text); }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip .count { opacity: 0.7; font-weight: 400; }

/* ---------- recipe grid ---------- */
.recipe-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.1rem;
}
@media (min-width: 640px) {
  .recipe-grid { grid-template-columns: repeat(4, 1fr); }
}
.category-section { margin-bottom: 2.25rem; }
.category-section:last-child { margin-bottom: 0; }
.category-heading {
  display: flex; align-items: baseline; gap: 0.6rem;
  margin-bottom: 1rem; padding-bottom: 0.5rem; border-bottom: 1px solid var(--border);
}
.category-heading-count {
  font-family: var(--font-body); font-size: 0.8rem; font-weight: 600;
  color: var(--heading); background: var(--heading-tint); padding: 0.15em 0.6em; border-radius: 999px;
}
.recipe-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  text-decoration: none;
  color: var(--text);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  transition: transform 0.12s ease;
}
.recipe-card:hover { transform: translateY(-2px); }
.recipe-card .thumb {
  aspect-ratio: 4 / 3;
  background: var(--surface-2) center/cover no-repeat;
  display: flex; align-items: center; justify-content: center;
  font-size: 2.2rem;
  color: var(--text-muted);
}
.recipe-card .body { padding: 0.85rem 0.95rem 1rem; display: flex; flex-direction: column; gap: 0.35rem; flex: 1; }
.recipe-card h3 { font-size: 0.95rem; margin: 0; color: var(--brand-color); }
.recipe-card .meta { font-size: 0.8rem; color: var(--text-muted); display: flex; gap: 0.6rem; flex-wrap: wrap; }
.tag-row { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: auto; padding-top: 0.4rem; }
.tag {
  background: var(--heading-tint);
  color: var(--heading);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.2em 0.6em;
  border-radius: 999px;
  letter-spacing: 0.02em;
}

.empty-state {
  text-align: center;
  padding: 3.5rem 1rem;
  color: var(--text-muted);
}
.empty-state .icon { font-size: 2.5rem; margin-bottom: 0.6rem; }

/* ---------- recipe detail ---------- */
.recipe-hero {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 1.5rem;
  margin-bottom: 1.75rem;
}
.recipe-hero .thumb {
  border-radius: var(--radius);
  aspect-ratio: 4/3;
  background: var(--surface-2) center/cover no-repeat;
  display: flex; align-items: center; justify-content: center;
  font-size: 2.5rem; color: var(--text-muted);
}
@media (max-width: 640px) {
  .recipe-hero { grid-template-columns: 1fr; }
  .recipe-hero .thumb { aspect-ratio: 16/9; }
}
.recipe-meta-line { color: var(--text-muted); display: flex; gap: 1rem; flex-wrap: wrap; font-size: 0.9rem; margin-bottom: 0.6rem; }
.recipe-title { color: var(--brand-color); font-size: 1.65rem; }

.detail-grid { display: grid; grid-template-columns: 300px 1fr; gap: 2rem; align-items: start; }
@media (max-width: 760px) { .detail-grid { grid-template-columns: 1fr; } }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.35rem;
  box-shadow: var(--shadow);
}
.panel + .panel { margin-top: 1.25rem; }

.scale-row { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 1rem; }
.scale-row .stepper { display: flex; align-items: center; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.scale-row .stepper button { background: var(--surface-2); border-radius: 0; padding: 0.4em 0.7em; }
.scale-row .stepper span { padding: 0 0.9em; font-weight: 700; min-width: 2.6em; text-align: center; font-variant-numeric: tabular-nums; }

.ingredient-list { list-style: none; margin: 0; padding: 0; }
.ingredient-list li {
  display: flex; align-items: center; gap: 0.6rem; padding: 0.5rem 0; border-bottom: 1px dashed var(--border);
  font-size: 0.95rem;
}
.ingredient-list li:last-child { border-bottom: none; }
.ingredient-list .qty { font-weight: 700; min-width: 4.5em; font-variant-numeric: tabular-nums; color: var(--primary); }
.ingredient-list .ing-name { flex: 1; }
.ingredient-list .add-to-shop {
  flex-shrink: 0; width: 1.7rem; height: 1.7rem; border-radius: 6px;
  background: var(--surface-2); color: var(--text-muted); font-size: 1rem; line-height: 1; padding: 0;
}
.ingredient-list .add-to-shop:hover { background: var(--primary-tint); color: var(--primary); }
.ingredient-list .add-to-shop.added { background: var(--primary); color: #fff; }

.step-list { list-style: none; margin: 0; padding: 0; counter-reset: step; }
.step-list li {
  display: flex; gap: 1rem; padding: 1.1rem 0; border-bottom: 1px solid var(--border);
}
.step-list li:last-child { border-bottom: none; }
.step-list li > span:last-child { font-size: 1.02rem; line-height: 1.65; padding-top: 0.15rem; }
.step-list .num {
  counter-increment: step;
  flex-shrink: 0;
  width: 2.1rem; height: 2.1rem; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.95rem; font-variant-numeric: tabular-nums;
}
.step-list .num::before { content: counter(step); }

.nutri-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.75rem; }
@media (max-width: 500px) { .nutri-grid { grid-template-columns: repeat(2, 1fr); } }
.nutri-item { text-align: center; background: var(--surface-2); border-radius: 8px; padding: 0.7rem 0.4rem; }
.nutri-item .val { font-size: 1.15rem; font-weight: 700; color: var(--primary); font-variant-numeric: tabular-nums; }
.nutri-item .lbl { font-size: 0.72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }

.portion-field {
  background: var(--accent-tint); border: 1px solid var(--accent); border-radius: 10px;
  padding: 0.85rem 0.9rem; margin-bottom: 1rem;
}
.portion-field label { color: var(--accent); }
.portion-field input {
  font-size: 1.15rem; font-weight: 700; border-color: var(--accent);
}

.nutrition-suggestions {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 30;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  margin-top: 0.3rem; max-height: 260px; overflow-y: auto; box-shadow: var(--shadow);
}
.nutrition-suggestions:empty { display: none; }
.suggestion {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  padding: 0.55rem 0.75rem; cursor: pointer; border-bottom: 1px solid var(--border); font-size: 0.88rem;
}
.suggestion:last-child { border-bottom: none; }
.suggestion:hover { background: var(--surface-2); }
.suggestion .s-name { flex: 1; }
.suggestion .s-brand { color: var(--text-muted); font-size: 0.82rem; }
.suggestion .s-cal { flex-shrink: 0; font-weight: 700; color: var(--primary); white-space: nowrap; }
.suggestion .s-basis { font-weight: 400; color: var(--text-muted); }

/* ---------- forms ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }
.dynamic-row { display: flex; gap: 0.5rem; margin-bottom: 0.5rem; align-items: center; }
.dynamic-row input { flex: 1; }
.dynamic-row .qty-input { max-width: 90px; flex: none; }
.dynamic-row .unit-input { max-width: 100px; flex: none; }

.step-row { align-items: flex-start; margin-bottom: 0.75rem; }
.step-row .step-num {
  flex-shrink: 0; margin-top: 0.55rem;
  width: 1.9rem; height: 1.9rem; border-radius: 50%;
  background: var(--primary); color: #fff; font-weight: 700; font-size: 0.85rem;
  display: flex; align-items: center; justify-content: center; font-variant-numeric: tabular-nums;
}
.step-row textarea {
  flex: 1; resize: none; overflow: hidden; min-height: 2.7rem; line-height: 1.5;
}
.step-row .btn-icon { margin-top: 0.3rem; }
.add-row-btn { margin-top: 0.3rem; }
.image-upload {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
  color: var(--text-muted);
  cursor: pointer;
  position: relative;
}
.image-upload img { max-height: 140px; border-radius: 8px; margin-top: 0.5rem; }
.image-upload input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.form-actions { display: flex; gap: 0.7rem; margin-top: 1.5rem; position: sticky; bottom: 0; background: var(--bg); padding: 1rem 0; }

/* ---------- planner ---------- */
.week-nav { display: flex; align-items: center; gap: 0.8rem; margin-bottom: 1.2rem; }
.week-nav .range { font-weight: 700; font-family: var(--font-display); font-size: 1.15rem; }
.planner-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 0.7rem; }
@media (max-width: 900px) { .planner-grid { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); } }
.day-col { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.75rem; display: flex; flex-direction: column; gap: 0.5rem; }
.day-col.is-today { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.day-col .day-label { font-weight: 700; font-size: 0.85rem; display: flex; justify-content: space-between; color: var(--text-muted); }
.day-col .day-label .num { color: var(--text); font-family: var(--font-display); font-size: 1.1rem; }
.meal-slot { border-radius: 8px; padding: 0.5rem 0.55rem; background: var(--surface-2); font-size: 0.82rem; }
.meal-slot .slot-label { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); font-weight: 700; margin-bottom: 0.3rem; }
.meal-slot .assigned { display: flex; align-items: center; justify-content: space-between; gap: 0.4rem; background: var(--primary-tint); color: var(--primary); border-radius: 6px; padding: 0.35rem 0.5rem; font-weight: 600; margin-bottom: 0.3rem; }
.meal-slot .assigned button { background: none; padding: 0.1em 0.3em; color: var(--primary); }
.meal-slot .add-btn { width: 100%; background: transparent; border: 1px dashed var(--border); color: var(--text-muted); font-size: 0.78rem; padding: 0.35rem; }
.meal-slot .add-btn:hover { border-color: var(--primary); color: var(--primary); }

/* ---------- shopping list ---------- */
.shopping-add { display: flex; gap: 0.5rem; margin-bottom: 1.25rem; }
.shopping-add input { flex: 1; }
.shop-list { list-style: none; margin: 0; padding: 0; }
.shop-list li {
  display: flex; align-items: center; gap: 0.8rem;
  padding: 0.7rem 0.2rem; border-bottom: 1px solid var(--border);
}
.shop-list li.checked .item-name { text-decoration: line-through; color: var(--text-muted); }
.shop-list .checkbox {
  width: 1.35rem; height: 1.35rem; border-radius: 6px; border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0; background: var(--surface);
}
.shop-list li.checked .checkbox { background: var(--primary); border-color: var(--primary); color: #fff; }
.shop-list .item-name { flex: 1; }
.shop-list .item-qty { color: var(--text-muted); font-size: 0.88rem; font-variant-numeric: tabular-nums; }
.section-label { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); font-weight: 700; margin: 1.4rem 0 0.5rem; }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20, 26, 20, 0.45);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 1rem;
}
.modal {
  background: var(--surface); border-radius: var(--radius); padding: 1.5rem;
  width: 100%; max-width: 440px; max-height: 85vh; overflow-y: auto; box-shadow: var(--shadow);
}
.modal .recipe-pick { display: flex; align-items: center; gap: 0.7rem; padding: 0.55rem 0.4rem; border-radius: 8px; cursor: pointer; }
.modal .recipe-pick:hover { background: var(--surface-2); }
.modal .recipe-pick .thumb-sm { width: 44px; height: 44px; border-radius: 6px; background: var(--surface-2) center/cover no-repeat; flex-shrink: 0; display: flex; align-items: center; justify-content: center; color: var(--text-muted); }
.modal .form-actions {
  position: static; background: var(--surface); margin-top: 1.25rem; padding: 1rem 0 0;
  border-top: 1px solid var(--border);
}

.toast {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 0.7em 1.2em; border-radius: 999px;
  font-size: 0.9rem; font-weight: 600; z-index: 100; box-shadow: var(--shadow);
}
@media (max-width: 860px) { .toast { bottom: 5.5rem; } }

.share-text {
  white-space: pre-wrap; font-family: ui-monospace, monospace; font-size: 0.82rem;
  background: var(--surface-2); border-radius: 8px; padding: 0.9rem; max-height: 40vh; overflow-y: auto;
}

@media print {
  .sidebar, .bottom-tabs, .mobile-topbar, .form-actions, .page-header .actions, .scale-row .stepper { display: none !important; }
  .app-shell { display: block; }
  .panel { box-shadow: none; border: 1px solid #ccc; }
}
