/* ══════════════════════════════════════════════
   Family Cookbook — styles
   Theming via CSS variables; user prefs set on <html> by settings.js
   ══════════════════════════════════════════════ */

:root {
  --accent: #c4573a;
  --accent-soft: #f6e3dc;
  --bg: #faf6f0;
  --card: #ffffff;
  --ink: #33302b;
  --ink-soft: #7a7368;
  --line: #e8e1d6;
  --star: #e8a33d;
  --danger: #b3402e;
  --ok: #3d7a4f;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(60, 50, 30, 0.08), 0 4px 14px rgba(60, 50, 30, 0.06);
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: var(--font-body);
}

html[data-theme="dark"] {
  --bg: #201d19;
  --card: #2b2723;
  --ink: #ece7de;
  --ink-soft: #a89f92;
  --line: #3d3831;
  --accent-soft: #45322b;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 4px 14px rgba(0, 0, 0, 0.25);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
}

h1, h2, h3 { font-family: var(--font-display); line-height: 1.2; }
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--ink-soft); }
.small { font-size: 0.85rem; }
.center { text-align: center; }

/* ── Top bar ── */
.topbar {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0.7rem 1.2rem;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 50;
  flex-wrap: wrap;
}
.brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  text-decoration: none;
  color: var(--ink);
  white-space: nowrap;
}
.nav { display: flex; gap: 0.25rem; flex-wrap: wrap; }
.nav a {
  text-decoration: none;
  color: var(--ink-soft);
  padding: 0.35rem 0.75rem;
  border-radius: 8px;
  font-weight: 500;
}
.nav a:hover { background: var(--accent-soft); color: var(--ink); }
.nav a.active { background: var(--accent); color: #fff; }
.topbar-right { margin-left: auto; }
.whoami { color: var(--ink-soft); font-size: 0.9rem; }

.sync-banner {
  background: #fdf3d7;
  color: #6b5410;
  padding: 0.5rem 1.2rem;
  font-size: 0.9rem;
  border-bottom: 1px solid #eadfb7;
}
html[data-theme="dark"] .sync-banner { background: #46401f; color: #e8d99a; border-color: #5a5228; }
.sync-banner a { color: inherit; font-weight: 600; }

.view { max-width: 1080px; margin: 0 auto; padding: 1.5rem 1.2rem 4rem; }
.footer {
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.8rem;
  padding: 1rem;
  border-top: 1px solid var(--line);
}

/* ── Login ── */
.login-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}
.login-card {
  background: var(--card);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 2.2rem 2rem;
  width: 100%;
  max-width: 380px;
}
.login-emoji { font-size: 3rem; text-align: center; }
.pulse { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }
.login-card h1 { text-align: center; margin: 0.4rem 0 0.2rem; font-size: 1.5rem; }
.login-sub { text-align: center; color: var(--ink-soft); margin-top: 0; }
.login-card label { display: block; font-weight: 600; font-size: 0.85rem; margin: 0.9rem 0 0.25rem; }
.login-card input {
  width: 100%;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 1rem;
  background: var(--bg);
  color: var(--ink);
}
.login-error { color: var(--danger); text-align: center; font-size: 0.9rem; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  padding: 0.5rem 1rem;
  border-radius: 9px;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 0.25rem 0.6rem; font-size: 0.85rem; }
.btn-block { width: 100%; margin-top: 1rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Cards / general ── */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}
.card h2 { margin-top: 0; }

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.page-head h1 { margin: 0; font-size: 1.6rem; }
.page-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ── Recipe list ── */
.toolbar {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 1.2rem;
}
.toolbar input[type="search"], .toolbar select {
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 9px;
  font-size: 0.95rem;
  background: var(--card);
  color: var(--ink);
  font-family: inherit;
}
.toolbar input[type="search"] { flex: 1; min-width: 180px; }

.recipe-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 1rem;
}
.recipe-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  cursor: pointer;
  text-decoration: none;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  transition: transform 0.12s ease;
}
.recipe-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.recipe-card-img {
  height: 140px;
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  overflow: hidden;
}
.recipe-card-img img { width: 100%; height: 100%; object-fit: cover; }
.recipe-card-body { padding: 0.7rem 0.85rem 0.85rem; flex: 1; display: flex; flex-direction: column; gap: 0.25rem; }
.recipe-card-body h3 { margin: 0; font-size: 1.02rem; }
.recipe-card-meta { color: var(--ink-soft); font-size: 0.8rem; display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: auto; }

.stars { color: var(--star); letter-spacing: 1px; white-space: nowrap; }
.stars .off { color: var(--line); }
.stars-interactive span { cursor: pointer; font-size: 1.5rem; }

.tag {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--ink);
  border-radius: 999px;
  padding: 0.05rem 0.6rem;
  font-size: 0.75rem;
  font-weight: 600;
}

/* ── Recipe detail ── */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
@media (max-width: 760px) { .detail-grid { grid-template-columns: 1fr; } }

.gallery-main {
  width: 100%;
  aspect-ratio: 4/3;
  border-radius: var(--radius);
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 4rem;
  overflow: hidden;
}
.gallery-main img { width: 100%; height: 100%; object-fit: cover; }
.gallery-thumbs { display: flex; gap: 0.5rem; margin-top: 0.5rem; flex-wrap: wrap; }
.gallery-thumbs img {
  width: 64px; height: 64px; object-fit: cover;
  border-radius: 8px; cursor: pointer; border: 2px solid transparent;
}
.gallery-thumbs img.active { border-color: var(--accent); }

.servings-ctl {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.2rem 0.4rem;
}
.servings-ctl button {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: none;
  background: var(--accent-soft);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  color: var(--ink);
}
.servings-ctl input {
  width: 52px;
  text-align: center;
  border: none;
  background: transparent;
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
  font-family: inherit;
}

.ingredients-list { list-style: none; padding: 0; margin: 0.5rem 0; }
.ingredients-list li {
  padding: 0.4rem 0.2rem;
  border-bottom: 1px dashed var(--line);
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
}
.ingredients-list .qty { font-weight: 700; color: var(--accent); min-width: 5.5rem; }
.steps-list { padding-left: 0; list-style: none; counter-reset: step; margin: 0.5rem 0; }
.steps-list li {
  counter-increment: step;
  display: flex;
  gap: 0.75rem;
  padding: 0.55rem 0;
  border-bottom: 1px dashed var(--line);
  align-items: baseline;
}
.steps-list li::before {
  content: counter(step);
  flex: 0 0 1.7rem;
  height: 1.7rem;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--ink);
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
}
.steps-list li.done { opacity: 0.45; text-decoration: line-through; }

/* awkward scaled amounts (e.g. 2½ eggs) get flagged for the chef */
.ing-warn .qty {
  background: #fdf3d7;
  color: #8a6100;
  border-radius: 6px;
  padding: 0 0.35rem;
  cursor: help;
}
html[data-theme="dark"] .ing-warn .qty { background: #46401f; color: #e8d99a; }

.meta-row { display: flex; gap: 1.2rem; flex-wrap: wrap; color: var(--ink-soft); font-size: 0.9rem; margin: 0.5rem 0 1rem; }

/* ── Forms ── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem 1.2rem; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }
.field { display: flex; flex-direction: column; gap: 0.25rem; }
.field.wide { grid-column: 1 / -1; }
.field label { font-weight: 600; font-size: 0.85rem; }
.field input, .field select, .field textarea {
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--bg);
  color: var(--ink);
}
.field textarea { min-height: 110px; resize: vertical; }
.field .hint { font-size: 0.78rem; color: var(--ink-soft); }

.ing-row {
  display: grid;
  grid-template-columns: 1.1rem 4.5rem 6.5rem 1fr 1fr 2rem;
  gap: 0.4rem;
  margin-bottom: 0.4rem;
  align-items: center;
}
@media (max-width: 640px) { .ing-row { grid-template-columns: 1.1rem 3.5rem 5rem 1fr 2rem; } .ing-row .ing-note { display: none; } }
.ing-sec {
  display: grid;
  grid-template-columns: 1.1rem 1fr 2rem;
  gap: 0.4rem;
  align-items: center;
  margin: 0.6rem 0 0.4rem;
}
.ing-sec .sec-name {
  padding: 0.4rem 0.5rem;
  border: 1px dashed var(--accent);
  border-radius: 7px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  font-family: inherit;
  min-width: 0;
}
.ing-sec .rm { border: none; background: none; color: var(--danger); font-size: 1.1rem; cursor: pointer; padding: 0; }
.drag { cursor: grab; color: var(--ink-soft); user-select: none; font-size: 0.9rem; letter-spacing: -2px; }
.dragging { opacity: 0.45; }
.ingredients-list .ing-sec-head {
  font-weight: 700;
  color: var(--accent);
  border-bottom: 2px solid var(--accent-soft);
  padding-top: 0.7rem;
}
.ing-row input {
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 0.9rem;
  font-family: inherit;
  background: var(--bg);
  color: var(--ink);
  min-width: 0;
}
.ing-row .rm {
  border: none; background: none; color: var(--danger);
  font-size: 1.1rem; cursor: pointer; padding: 0;
}

/* ── Meal plan ── */
.week-nav { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 1rem; }
.week-nav h2 { margin: 0; font-size: 1.15rem; }
.plan-table { width: 100%; border-collapse: collapse; }
.plan-table th, .plan-table td {
  border: 1px solid var(--line);
  padding: 0.45rem;
  vertical-align: top;
  text-align: left;
  font-size: 0.88rem;
}
.plan-table th { background: var(--accent-soft); }
.plan-table td { min-width: 120px; background: var(--card); }
.plan-day { font-weight: 700; white-space: nowrap; }
.plan-day .small { font-weight: 400; }
.meal-chip {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--accent-soft);
  border-radius: 7px;
  padding: 0.2rem 0.45rem;
  margin-bottom: 0.3rem;
  font-size: 0.82rem;
}
.meal-chip a { text-decoration: none; color: var(--ink); font-weight: 600; flex: 1; }
.meal-chip .rm { border: none; background: none; cursor: pointer; color: var(--ink-soft); padding: 0; }
.add-meal {
  border: 1px dashed var(--line);
  background: none;
  color: var(--ink-soft);
  border-radius: 7px;
  padding: 0.15rem 0.5rem;
  font-size: 0.8rem;
  cursor: pointer;
  width: 100%;
}
.add-meal:hover { border-color: var(--accent); color: var(--accent); }
.plan-scroll { overflow-x: auto; }

/* ── Shopping list ── */
.shop-group h3 { margin: 1rem 0 0.3rem; font-size: 1rem; color: var(--accent); }
.shop-item { display: flex; align-items: center; gap: 0.6rem; padding: 0.3rem 0; border-bottom: 1px dashed var(--line); }
.shop-item input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }
.shop-item.checked label { text-decoration: line-through; opacity: 0.45; }
.shop-item label { flex: 1; cursor: pointer; }
.shop-item .qty { font-weight: 700; color: var(--accent); }
.shop-item .rm { border: none; background: none; color: var(--ink-soft); cursor: pointer; font-size: 1rem; }
.shop-add { display: flex; gap: 0.5rem; margin-top: 0.8rem; }
.shop-add input { flex: 1; padding: 0.45rem 0.6rem; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); font-family: inherit; }

/* ── Lightbox (full-size media viewer) ── */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(15, 12, 8, 0.92);
  z-index: 150;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
}
.lightbox .lb-media {
  max-width: 92vw;
  max-height: 92vh;
  object-fit: contain;
  border-radius: 8px;
  cursor: default;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
}
.lightbox .lb-close {
  position: absolute;
  top: 14px;
  right: 18px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 42px;
  height: 42px;
  font-size: 1.2rem;
  cursor: pointer;
}
.lightbox .lb-close:hover { background: rgba(255, 255, 255, 0.28); }
.lightbox .lb-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 46px;
  height: 46px;
  font-size: 1.6rem;
  cursor: pointer;
}
.lightbox .lb-nav:hover { background: rgba(255, 255, 255, 0.28); }
.lightbox .lb-prev { left: 14px; }
.lightbox .lb-next { right: 14px; }

.vid-thumb {
  width: 64px;
  height: 64px;
  border-radius: 8px;
  background: #000;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  cursor: pointer;
  border: 2px solid transparent;
}
.vid-thumb.active { border-color: var(--accent); }

/* ── Segmented toggle (family / just me) ── */
.seg {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 9px;
  overflow: hidden;
}
.seg button {
  border: none;
  background: var(--card);
  color: var(--ink-soft);
  padding: 0.45rem 0.85rem;
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
.seg button.on { background: var(--accent); color: #fff; }

/* ── Cost estimator ── */
.cost-row {
  display: grid;
  grid-template-columns: 1.4rem minmax(9rem, 1fr) 4.2rem 5rem 5.2rem 5.5rem 3.6rem;
  gap: 0.4rem;
  align-items: center;
  padding: 0.35rem 0;
  border-bottom: 1px dashed var(--line);
}
.cost-row .row-btns { display: inline-flex; gap: 0.15rem; }
.cost-row .gear {
  border: none;
  background: none;
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 0.95rem;
  padding: 0;
}
.cost-row .gear.gear-set { color: var(--accent); }
.cost-row input:not([type="checkbox"]) {
  padding: 0.35rem 0.45rem;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 0.9rem;
  font-family: inherit;
  background: var(--bg);
  color: var(--ink);
  min-width: 0;
  width: 100%;
}
.cost-row input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }
.cost-row .rm { border: none; background: none; color: var(--ink-soft); cursor: pointer; }
.cost-head { font-weight: 700; font-size: 0.82rem; color: var(--ink-soft); border-bottom: 1px solid var(--line); }
@media (max-width: 640px) {
  .cost-row { grid-template-columns: 1.2rem 1fr 3.4rem 3.6rem 4.2rem 3.4rem; }
  .cost-row > span.small, .cost-head > span.small { display: none; }
}

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(30, 25, 18, 0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 90;
  padding: 1rem;
}
.modal {
  background: var(--card);
  border-radius: 14px;
  box-shadow: var(--shadow);
  max-width: 560px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 1.4rem;
}
.modal h2 { margin-top: 0; font-size: 1.2rem; }

/* ── Toasts ── */
.toast-container { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 0.5rem; }
.toast {
  background: var(--ink);
  color: var(--bg);
  padding: 0.6rem 1.1rem;
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-size: 0.92rem;
  animation: toast-in 0.25s ease;
}
.toast.error { background: var(--danger); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ── Settings ── */
.swatches { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.swatch {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid transparent; cursor: pointer;
}
.swatch.active { border-color: var(--ink); }

.settings-row { display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap; margin: 0.6rem 0; }
.settings-row label { font-weight: 600; min-width: 8rem; }

/* ── Import preview ── */
.preview-item {
  display: flex; gap: 0.7rem; align-items: flex-start;
  border: 1px solid var(--line); border-radius: 10px;
  padding: 0.7rem; margin-bottom: 0.6rem;
}
.preview-item input[type="checkbox"] { margin-top: 0.3rem; width: 18px; height: 18px; accent-color: var(--accent); }
.spinner {
  display: inline-block; width: 18px; height: 18px;
  border: 3px solid var(--accent-soft); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ══════════ Print ══════════ */
.print-root { display: none; }
@media print {
  body > *:not(.print-root) { display: none !important; }
  body { background: #fff; color: #000; }
  .print-root { display: block; font-size: 11pt; }
  .print-cover { text-align: center; padding-top: 30vh; page-break-after: always; }
  .print-cover h1 { font-size: 34pt; margin-bottom: 0.2em; }
  .print-toc { page-break-after: always; }
  .print-toc h2 { font-size: 16pt; }
  .print-toc li { margin: 0.15em 0; }
  .print-recipe { page-break-before: always; }
  .print-recipe h2 { font-size: 18pt; border-bottom: 2px solid #999; padding-bottom: 4pt; }
  .print-recipe img { max-width: 3.2in; max-height: 2.6in; object-fit: cover; border-radius: 6pt; float: right; margin: 0 0 8pt 12pt; }
  .print-recipe .pr-meta { color: #555; font-size: 9.5pt; margin-bottom: 8pt; }
  .print-recipe h3 { font-size: 12pt; margin: 10pt 0 4pt; }
  .print-recipe ul, .print-recipe ol { margin: 0; padding-left: 1.3em; }
  .print-recipe li { margin: 2pt 0; }
}
