:root {
  --bg: #fbf8f2;
  --card: #ffffff;
  --ink: #3a3630;
  --muted: #948d7d;
  --sage: #8aab8f;
  --sage-dark: #5f7d63;
  /* Solid-background pairing for --sage-dark: a handful of spots (the
     "Shared"/category tag pills, the allergen-match category tag, the
     button hover fill) put white text directly on this color, so it can't
     be lightened for dark-mode readability the way the same color used AS
     text can. This token stays fixed across both themes so those three
     spots always keep enough contrast with their white text. */
  --sage-solid: #5f7d63;
  --blush: #f4d7d6;
  --blush-dark: #c98685;
  --butter: #f3e3a6;
  --butter-dark: #b89a3c;
  --border: #e6ded0;
  --warn-bg: #fdf3e3;
  --warn-border: #e3c589;
  --warn-ink: #6b4f1e;
  --danger: #b9564f;
  /* Soft mint tint (hover states, selected rows, avatar-placeholder bg) and
     the plain white-ish surfaces (input fields, secondary buttons) each get
     their own token so dark mode can swap them without touching every rule
     that uses them. */
  --tint: #f6faf6;
  --input-bg: #fffefb;
  --surface: #ffffff;
  --btn-secondary-hover: #f2f8f2;
}

/* ---------- Dark mode ---------- */
/* Toggled from Settings (js/app.js applyTheme()), persisted in
   localStorage per-device. Brand accent colors (--sage, --blush, --butter,
   --danger, --sage-solid) stay the same in both themes -- they're already
   tuned to work with white button text; only the "page surface" tokens
   below change, plus --sage-dark, which doubles as body-copy/heading text
   color and needs to lighten for contrast against a dark background. */
:root[data-theme="dark"] {
  --bg: #211f1b;
  --card: #2b2823;
  --ink: #efe8db;
  --muted: #b3a890;
  --sage-dark: #9fcaa4;
  --border: #3c3830;
  --warn-bg: #3a2f1c;
  --warn-border: #6b5527;
  --warn-ink: #f0d9a0;
  --tint: #33362f;
  --input-bg: #2b2823;
  --surface: #2b2823;
  --btn-secondary-hover: #343029;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: "Playfair Display", Georgia, "Segoe UI", serif;
  background: var(--bg);
  color: var(--ink);
  padding-bottom: 40px;
  transition: background-color 0.15s ease, color 0.15s ease;
}

#app { max-width: 780px; margin: 0 auto; padding: 0 16px; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 4px 10px;
}

.topbar .brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--sage-dark);
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  font-family: inherit;
}

.topbar .brand svg { width: 26px; height: 26px; }
.topbar .brand img.brand-mark {
  height: 44px;
  width: auto;
  display: block;
}
/* App title: an elegant flowing script -- set apart from the
   section-heading serif used everywhere else. Script fonts read smaller
   than their font-size, so this needs to run larger than the plain
   1.15rem the button itself is set at. Parisienne only ships a single
   (regular) weight, so no font-weight override here -- a browser-faked
   bold would distort its calligraphic strokes. */
.topbar .brand span {
  font-family: "Parisienne", cursive;
  font-size: 2.1rem;
  font-weight: 400;
}

.icon-btn {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--sage-dark);
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover { background: var(--butter); border-color: var(--butter-dark); }

/* ---------- Home grid ---------- */
.home-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin: 10px 0 20px;
}

.home-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 22px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  text-align: center;
  font-weight: 600;
  color: var(--ink);
  box-shadow: 0 2px 6px rgba(58, 46, 38, 0.05);
}
.home-box:hover { border-color: var(--sage); background: var(--tint); }
.home-box svg { width: 40px; height: 40px; color: var(--sage-dark); }
.home-box.blush svg { color: var(--blush-dark); }
.home-box.butter svg { color: var(--butter-dark); }

.quick-links {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.quick-link {
  flex: 1;
  min-width: 150px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--sage-dark);
}
.quick-link svg { width: 20px; height: 20px; }
.quick-link:hover { background: var(--tint); }

/* ---------- Page header / back nav ---------- */
.page-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 6px 0 16px;
}
.back-btn {
  background: none;
  border: none;
  color: var(--sage-dark);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 2px 6px;
  line-height: 1;
}
.page-header h1 {
  margin: 0;
  font-size: 1.3rem;
  color: var(--sage-dark);
}

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  margin-bottom: 16px;
  box-shadow: 0 2px 6px rgba(58, 46, 38, 0.05);
}
.card h2 {
  margin-top: 0;
  font-size: 1.05rem;
  color: var(--sage-dark);
  border-bottom: 2px solid var(--border);
  padding-bottom: 8px;
}

label { font-weight: 600; font-size: 0.88rem; display: block; margin-bottom: 4px; }

input[type=text], input[type=number], textarea, select {
  font-family: inherit;
  font-size: 0.95rem;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--ink);
  width: 100%;
}
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--sage);
  outline-offset: 1px;
}

.row-flex { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 10px; }
.field { display: flex; flex-direction: column; }
textarea { min-height: 70px; resize: vertical; }

#ingredient-rows { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.ing-row {
  display: grid;
  grid-template-columns: 64px 100px 1fr 30px;
  gap: 6px;
  align-items: center;
}
.ing-header {
  display: grid;
  grid-template-columns: 64px 100px 1fr 30px;
  gap: 6px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  margin-bottom: 2px;
}
.remove-btn {
  background: none; border: none; color: var(--danger);
  font-size: 1.2rem; cursor: pointer; line-height: 1; padding: 0;
}

button.btn {
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  background: var(--sage);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  cursor: pointer;
}
button.btn:hover { background: var(--sage-solid); }
button.btn.secondary {
  background: var(--surface);
  color: var(--sage-dark);
  border: 1px solid var(--sage);
}
button.btn.secondary:hover { background: var(--btn-secondary-hover); }
button.btn.danger { background: var(--danger); }
button.btn.danger:hover { background: #93433d; }
button.btn svg { width: 15px; height: 15px; vertical-align: -3px; margin-right: 3px; }

.scaled-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px dashed var(--border);
  font-size: 0.95rem;
}
.scaled-row:last-child { border-bottom: none; }
.scaled-amt { font-weight: 700; color: var(--sage-dark); }

.temp-widget { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.temp-field { display: flex; align-items: center; gap: 6px; }
.temp-field input { width: 90px; }

.temp-ref-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.temp-ref-table th, .temp-ref-table td {
  text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border);
}
.temp-ref-table th { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; }

.allergen-checks { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 14px; }
.allergen-checks label { font-weight: 500; display: flex; align-items: center; gap: 6px; margin: 0; }

.allergen-results-box .match {
  background: var(--tint);
  border: 1px solid var(--sage);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
}
.allergen-results-box .match .ing-name { font-weight: 700; color: var(--sage-dark); }
.allergen-results-box .match .cat-tag {
  display: inline-block; font-size: 0.68rem; text-transform: uppercase;
  background: var(--sage-solid); color: #fff; border-radius: 4px; padding: 1px 6px; margin-left: 6px;
}
.allergen-results-box .match .sub-amount { font-weight: 700; color: var(--sage-dark); margin-top: 4px; }
.allergen-results-box .match .sub-options { margin: 4px 0 0; padding-left: 20px; }
.allergen-results-box .match .sub-options li { margin-bottom: 2px; }
.allergen-results-box .match .sub-note { margin-top: 6px; font-size: 0.85rem; }

.disclaimer {
  margin-top: 14px;
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.82rem;
  color: var(--warn-ink);
}

.hint { font-size: 0.8rem; color: var(--muted); margin-top: -4px; margin-bottom: 12px; }
.muted-msg { color: var(--muted); font-style: italic; }

.recipe-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
}
.recipe-card:hover { border-color: var(--sage); }
.recipe-card.selected { border-color: var(--sage); background: var(--tint); }
.recipe-card .rc-title { font-weight: 700; color: var(--ink); }
.recipe-card .rc-meta { font-size: 0.82rem; color: var(--muted); }

/* Small inline pill — the "Shared" badge on your own recipe cards, and the
   category badge on Community Recipes cards. */
.tag {
  display: inline-block;
  font-size: 0.68rem;
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: var(--sage-solid);
  color: #fff;
  border-radius: 4px;
  padding: 1px 6px;
  margin-left: 6px;
}

.recipe-actions { display: flex; gap: 8px; margin-top: 14px; }

/* Simple radio-style choice list used to pick a saved recipe */
.pick-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.pick-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
}
.pick-item.selected { border-color: var(--sage); background: var(--tint); }

@media (max-width: 420px) {
  .home-grid { grid-template-columns: 1fr 1fr; }
  .ing-row, .ing-header { grid-template-columns: 56px 84px 1fr 26px; }
}

/* ---------- Profile: avatar + friends/family admin panel ---------- */
.icon-btn img.avatar-img {
  width: 100%; height: 100%; border-radius: 50%; object-fit: cover;
}
.avatar-row { display: flex; align-items: center; gap: 16px; margin-bottom: 14px; }
.avatar-preview {
  width: 84px; height: 84px; border-radius: 50%; object-fit: cover;
  border: 1px solid var(--border); background: var(--tint); flex-shrink: 0;
}
.avatar-preview.placeholder {
  display: flex; align-items: center; justify-content: center;
  color: var(--sage-dark);
}
.avatar-preview.placeholder svg { width: 36px; height: 36px; }

.grant-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--tint);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  margin-bottom: 8px;
  font-size: 0.9rem;
}
.grant-row .remove-btn { font-size: 1rem; }

.grant-avatar {
  width: 30px; height: 30px; border-radius: 50%; object-fit: cover;
  border: 1px solid var(--border); background: var(--surface); flex-shrink: 0;
}
.grant-avatar.placeholder {
  display: flex; align-items: center; justify-content: center;
  color: var(--sage-dark);
}
.grant-avatar.placeholder svg { width: 15px; height: 15px; }

.grant-preview-card {
  display: flex;
  gap: 12px;
  align-items: center;
  background: var(--tint);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin: 10px 0;
}
.grant-preview-avatar {
  width: 56px; height: 56px; border-radius: 50%; object-fit: cover;
  border: 1px solid var(--border); background: var(--surface); flex-shrink: 0;
}
.grant-preview-avatar.placeholder {
  display: flex; align-items: center; justify-content: center;
  color: var(--sage-dark);
}
.grant-preview-avatar.placeholder svg { width: 26px; height: 26px; }
.grant-preview-details { flex: 1; min-width: 0; }
.grant-preview-details .grant-preview-username { font-weight: 700; color: var(--sage-dark); }
.grant-preview-details p { margin: 2px 0 0; font-size: 0.85rem; color: var(--muted); }

.link-btn {
  background: none;
  border: none;
  color: var(--sage-dark);
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
  margin-top: 8px;
  font-family: inherit;
}
.link-btn:hover { color: var(--sage); }

/* Lightweight heading for a subsection that isn't its own card, e.g.
   "Or use a saved recipe" under the Scale/Allergen "convert your own"
   sections. */
.section-label {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  margin: 18px 4px 8px;
}

/* ---------- Recipe Creator: grocery checklist ---------- */
.grocery-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  border-bottom: 1px dashed var(--border);
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 400;
}
.grocery-row:last-child { border-bottom: none; }
.grocery-row input[type=checkbox] {
  width: 18px; height: 18px; flex-shrink: 0; accent-color: var(--sage);
}
.grocery-row.have .grocery-text { text-decoration: line-through; color: var(--muted); }

/* ---------- Meal Planning: week navigation ---------- */
.week-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.week-nav .link-btn { margin-top: 0; }
.week-label { font-weight: 700; color: var(--sage-dark); font-size: 0.92rem; }

/* ---------- Recipe folders (Main Courses / Desserts / Sides / Appetizers) ---------- */
.category-pills { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 4px; }
.category-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 8px 14px;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
}
.category-pill svg { width: 16px; height: 16px; }
.category-pill:hover { border-color: var(--sage); }
.category-pill.selected { border-color: var(--sage); background: var(--tint); color: var(--sage-dark); }

/* ---------- Settings: dark mode toggle ---------- */
.theme-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0;
}
.theme-switch {
  position: relative;
  width: 48px;
  height: 27px;
  flex-shrink: 0;
  background: var(--border);
  border: none;
  border-radius: 14px;
  cursor: pointer;
  padding: 0;
}
.theme-switch::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 21px; height: 21px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
  transition: transform 0.15s ease;
}
.theme-switch.on { background: var(--sage); }
.theme-switch.on::after { transform: translateX(21px); }

/* ---------- Recipe photos ---------- */
.recipe-photo-thumb {
  width: 44px; height: 44px; border-radius: 8px; object-fit: cover;
  border: 1px solid var(--border); flex-shrink: 0; margin-right: 10px;
}
.recipe-card { position: relative; }
.recipe-card > div:first-child { display: flex; align-items: center; min-width: 0; }
.recipe-card > div:first-child > div:last-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.recipe-photo-preview {
  width: 100%; max-width: 320px; max-height: 200px; object-fit: cover;
  border-radius: 10px; border: 1px solid var(--border); display: block; margin-top: 10px;
}
.recipe-detail-photo {
  width: 100%; max-height: 260px; object-fit: cover;
  border-radius: 12px; border: 1px solid var(--border); margin-bottom: 14px; display: block;
}

/* ---------- Friends & Family / shared inbox, admin report rows ---------- */
.list-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  background: var(--tint);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 8px;
  font-size: 0.9rem;
}
.list-row .list-row-main { min-width: 0; }
.list-row .list-row-title { font-weight: 700; color: var(--ink); }
.list-row .list-row-meta { font-size: 0.78rem; color: var(--muted); }
.list-row .list-row-actions { display: flex; gap: 6px; flex-shrink: 0; }
.list-row .list-row-actions .btn { padding: 6px 10px; font-size: 0.8rem; }

/* ---------- Print: only the recipe content shows, everything else is
   hidden. #print-area is built and filled just before window.print() is
   called, then cleared again afterward. ---------- */
#print-area { display: none; }
@media print {
  body > *:not(#print-area) { display: none !important; }
  #print-area {
    display: block !important;
    color: #000;
    font-family: "Playfair Display", Georgia, serif;
  }
  #print-area h1 { margin-bottom: 2px; }
  #print-area .print-meta { color: #555; margin-bottom: 14px; }
  #print-area h2 { margin-top: 18px; margin-bottom: 6px; }
  #print-area ul, #print-area ol { padding-left: 22px; }
  #print-area li { margin-bottom: 4px; }
}
