/* ===== CSS Variables ===== */
:root {
  --accent: #4f7942;
  --accent-dark: #3a5e30;
  --accent-light: #e8f0e6;
  --danger: #c0392b;
  --danger-dark: #a93226;
  --text: #1a1a1a;
  --text-muted: #6b7280;
  --border: #e2e8f0;
  --bg: #f7f8fa;
  --surface: #ffffff;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.10), 0 2px 4px rgba(0,0,0,0.06);
  --radius: 10px;
  --radius-sm: 6px;
  --header-height: 60px;
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}
a { color: inherit; text-decoration: none; }
button { cursor: pointer; font: inherit; }
input, select, textarea { font: inherit; }

/* ===== Login ===== */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}
.login-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 2.5rem;
  width: 100%;
  max-width: 380px;
  text-align: center;
}
.login-logo { margin-bottom: 1rem; }
.login-card h1 { font-size: 1.6rem; font-weight: 700; margin-bottom: 0.4rem; }
.login-subtitle { color: var(--text-muted); margin-bottom: 1.5rem; font-size: 0.95rem; }
.login-card .form-group { text-align: left; margin-bottom: 1rem; }

/* ===== Header ===== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: var(--header-height);
  box-shadow: var(--shadow-sm);
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 1.5rem;
}
.header-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--accent-dark);
  flex-shrink: 0;
}
.brand-name { display: none; }
@media (min-width: 480px) { .brand-name { display: inline; } }
.app-nav {
  display: flex;
  gap: 0.25rem;
  flex: 1;
}
.nav-link {
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.nav-link:hover { background: var(--accent-light); color: var(--accent-dark); }
.nav-link.active { background: var(--accent-light); color: var(--accent-dark); font-weight: 600; }
.logout-form { flex-shrink: 0; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 0.9rem;
  border: none;
  transition: background 0.15s, opacity 0.15s, box-shadow 0.15s;
  line-height: 1;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--accent-dark); }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: #d4dce8; }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--bg); color: var(--text); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover:not(:disabled) { background: var(--danger-dark); }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.82rem; }
.btn-full { width: 100%; }
.btn-icon {
  background: transparent;
  border: none;
  padding: 0.3rem;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  transition: background 0.15s, color 0.15s;
}
.btn-icon:hover { background: var(--bg); color: var(--text); }
.btn-icon.btn-icon--danger:hover { color: var(--danger); }

/* ===== Forms ===== */
.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 0.35rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.form-row { display: flex; gap: 1rem; }
.form-row .form-group { flex: 1; }
.flex-2 { flex: 2 !important; }
.flex-1 { flex: 1 !important; }
input[type="text"],
input[type="number"],
input[type="date"],
input[type="password"],
select,
textarea {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s;
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 121, 66, 0.12);
}
input.invalid, select.invalid { border-color: var(--danger); }
.field-error { display: block; font-size: 0.78rem; color: var(--danger); margin-top: 0.25rem; min-height: 1em; }
.error-msg {
  background: #fdf0ef;
  border: 1px solid #f5c6c2;
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.9rem;
  font-size: 0.88rem;
  margin-bottom: 0.75rem;
}
textarea { resize: vertical; min-height: 80px; }

/* ===== Main layout ===== */
.app-main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}
.page { display: none; }
.page.active { display: block; }
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}
.page-header h2 { font-size: 1.5rem; font-weight: 700; }

/* ===== Recipe cards ===== */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}
.recipe-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  transition: box-shadow 0.15s;
}
.recipe-card:hover { box-shadow: var(--shadow-md); }
.recipe-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
}
.recipe-card-title {
  font-size: 1rem;
  font-weight: 600;
  flex: 1;
  min-width: 0;
  word-break: break-word;
}
.recipe-card-actions { display: flex; gap: 0.2rem; flex-shrink: 0; }
.recipe-card-meta {
  font-size: 0.82rem;
  color: var(--text-muted);
}
.recipe-card-ingredients {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}
.recipe-card-ingredients ul {
  margin: 0.3rem 0 0 1rem;
  list-style: disc;
}
.recipe-card-ingredients li { margin-bottom: 0.1rem; }
.ingredient-count {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-style: italic;
}
.recipe-notes-preview {
  font-size: 0.82rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  padding-top: 0.5rem;
  margin-top: 0.25rem;
  white-space: pre-wrap;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

/* ===== Ingredient rows in recipe form ===== */
.ingredients-section { margin-top: 0.5rem; margin-bottom: 1rem; }
.ingredients-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}
.ingredients-header label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0;
}
.ingredient-rows { display: flex; flex-direction: column; gap: 0.5rem; }
.ingredient-row {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
}
.ingredient-row .ing-name { flex: 3; min-width: 0; }
.ingredient-row .ing-qty { flex: 1.2; min-width: 60px; }
.ingredient-row .ing-unit { flex: 1.5; min-width: 70px; }
.ingredient-row .ing-remove { flex-shrink: 0; margin-top: 0.3rem; }
.no-ingredients {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.88rem;
  padding: 1rem 0;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-sm);
}

/* ===== Meal plan ===== */
.range-bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.range-btn-group {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.range-btn {
  background: var(--surface);
  border: none;
  border-right: 1px solid var(--border);
  padding: 0.45rem 1rem;
  font-size: 0.88rem;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
}
.range-btn:last-child { border-right: none; }
.range-btn:hover { background: var(--bg); color: var(--text); }
.range-btn.active { background: var(--accent-light); color: var(--accent-dark); font-weight: 600; }
.range-label {
  font-size: 0.88rem;
  color: var(--text-muted);
}

/* Calendar picker */
.calendar-body { padding: 1rem 1.5rem 0.5rem; }
.cal-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}
.cal-month-title { font-weight: 600; font-size: 1rem; }
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}
.cal-day-header {
  text-align: center;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: 0.4rem 0;
}
.cal-day {
  text-align: center;
  padding: 0.5rem 0.25rem;
  font-size: 0.88rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  user-select: none;
  transition: background 0.1s;
}
.cal-day:hover { background: var(--bg); }
.cal-day--empty { cursor: default; pointer-events: none; }
.cal-today { font-weight: 700; color: var(--accent); }
.cal-range-start,
.cal-range-end {
  background: var(--accent) !important;
  color: white !important;
  border-radius: var(--radius-sm);
}
.cal-in-range {
  background: var(--accent-light);
  color: var(--accent-dark);
  border-radius: 0;
}
.cal-range-start { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.cal-range-end { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.cal-range-start.cal-range-end { border-radius: var(--radius-sm) !important; }
.cal-instruction {
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
  padding: 0.75rem 0 0.25rem;
  min-height: 2.5rem;
}

.meal-plan-list { display: flex; flex-direction: column; gap: 1.25rem; }
.day-group { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: hidden; }
.day-group-header {
  background: var(--accent-light);
  padding: 0.4rem 0.75rem 0.4rem 1rem;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--accent-dark);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.meal-entry {
  display: flex;
  align-items: center;
  padding: 0.75rem 1rem;
  gap: 1rem;
  border-bottom: 1px solid var(--border);
}
.meal-entry:last-child { border-bottom: none; }
.meal-slot-badge {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 0.2rem 0.65rem;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}
.meal-recipe-name { flex: 1; font-weight: 500; min-width: 0; word-break: break-word; }
.meal-serves { font-size: 0.82rem; color: var(--text-muted); flex-shrink: 0; }
.meal-entry-actions { display: flex; gap: 0.2rem; flex-shrink: 0; }

/* ===== Shopping list ===== */

/* Mode toggle */
.mode-toggle {
  display: flex;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1.5px solid var(--border);
  flex-shrink: 0;
}
.mode-btn {
  padding: 0.35rem 0.85rem;
  font-size: 0.82rem;
  font-weight: 500;
  background: var(--surface);
  color: var(--text-muted);
  border: none;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.mode-btn + .mode-btn { border-left: 1.5px solid var(--border); }
.mode-btn.active { background: var(--accent); color: white; }
.mode-btn:hover:not(.active) { background: var(--accent-light); color: var(--accent-dark); }

/* Add Item row */
.shopping-add-row {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 1rem;
}

/* Autocomplete */
.autocomplete-wrapper {
  position: relative;
  flex: 1;
  min-width: 0;
}
.autocomplete-wrapper input { width: 100%; }
.autocomplete-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1.5px solid var(--accent);
  border-top: none;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  box-shadow: var(--shadow-md);
  z-index: 60;
  max-height: 220px;
  overflow-y: auto;
}
.autocomplete-item {
  padding: 0.45rem 0.8rem;
  font-size: 0.88rem;
  cursor: pointer;
}
.autocomplete-item:hover,
.autocomplete-item.active { background: var(--accent-light); color: var(--accent-dark); }

/* Action bar */
.shopping-action-bar {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.added-items-footer { margin: 0.75rem 0 1rem; }

/* Section label between merged items and plan list */
.shopping-section-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  padding: 0.75rem 0 0.3rem;
}

/* Green cross badge on manually added items */
.manual-added-badge {
  flex-shrink: 0;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
}

/* Recipe card Quick List button */
.recipe-card-ql {
  margin-top: auto;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}
.recipe-ql-btn { width: 100%; justify-content: center; }

/* Recipe view toggle group */
.view-toggle-group {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.view-toggle-btn {
  background: var(--surface);
  border: none;
  padding: 0.35rem 0.55rem;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.view-toggle-btn:first-child { border-right: 1px solid var(--border); }
.view-toggle-btn:hover { background: var(--bg); color: var(--text); }
.view-toggle-btn.active { background: var(--accent-light); color: var(--accent-dark); }

/* Recipe list view */
.recipe-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.recipe-list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  gap: 1rem;
  transition: background 0.1s;
}
.recipe-list-row:last-child { border-bottom: none; }
.recipe-list-row:hover { background: var(--surface-hover, var(--bg)); }
.recipe-list-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.95rem;
}

.shopping-controls { margin-bottom: 1.5rem; }
.date-range-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow-sm);
}
.date-range-controls label {
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.date-range-controls input[type="date"] {
  width: auto;
  padding: 0.4rem 0.6rem;
  font-size: 0.88rem;
}
.shopping-list { display: flex; flex-direction: column; gap: 1rem; }
.shopping-category {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.shopping-category-header {
  background: var(--accent-light);
  padding: 0.6rem 1rem;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--accent-dark);
  border-bottom: 1px solid var(--border);
}
.shopping-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.shopping-item:last-child { border-bottom: none; }
.shopping-item:hover { background: var(--bg); }
.shopping-item input[type="checkbox"] {
  width: 1.1rem;
  height: 1.1rem;
  cursor: pointer;
  accent-color: var(--accent);
  flex-shrink: 0;
}
.shopping-item-name { flex: 1; font-size: 0.92rem; }
.shopping-item-qty {
  font-size: 0.88rem;
  color: var(--text-muted);
  white-space: nowrap;
}
.shopping-item.checked .shopping-item-name {
  text-decoration: line-through;
  color: var(--text-muted);
}
.shopping-item-name.has-tooltip { position: relative; cursor: default; }
.shopping-item-name.has-tooltip:hover { color: var(--accent-dark); }
.ing-tooltip {
  display: none;
  position: absolute;
  left: 0;
  top: calc(100% + 4px);
  background: #1a1a1a;
  color: white;
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
  white-space: nowrap;
  z-index: 50;
  box-shadow: var(--shadow-md);
  pointer-events: none;
}
.ing-tooltip ul { list-style: none; margin: 0; padding: 0; }
.ing-tooltip li { padding: 0.1rem 0; }
.ing-tooltip li + li { border-top: 1px solid rgba(255,255,255,0.1); padding-top: 0.2rem; margin-top: 0.1rem; }
.shopping-item-name.has-tooltip:hover .ing-tooltip { display: block; }

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 2rem 1rem;
  overflow-y: auto;
}
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(2px);
}
.modal-content {
  position: relative;
  z-index: 1;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 640px;
  margin: auto;
}
.modal-content--sm { max-width: 440px; }
.modal-content--xs { max-width: 360px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem 1rem;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1.1rem; font-weight: 700; }
.modal-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--text-muted);
  padding: 0.2rem 0.4rem;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}
.modal-close:hover { background: var(--bg); color: var(--text); }
form { padding: 1.25rem 1.5rem 0; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1rem 1.5rem 1.25rem;
  margin-top: 0.5rem;
}
.modal-footer--generate {
  justify-content: center;
  padding-bottom: 0;
  margin-top: 1rem;
  border-top: 1px solid var(--border);
}
.confirm-message {
  padding: 0.5rem 1.5rem 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1a1a1a;
  color: white;
  padding: 0.65rem 1.25rem;
  border-radius: 99px;
  font-size: 0.88rem;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 999;
  white-space: nowrap;
  max-width: calc(100vw - 3rem);
  text-align: center;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.error { background: var(--danger); }

/* ===== Empty states ===== */
.empty-state {
  text-align: center;
  padding: 3rem 2rem;
  color: var(--text-muted);
}
.empty-state-icon { font-size: 3rem; margin-bottom: 0.75rem; opacity: 0.5; }
.empty-state h3 { font-size: 1.1rem; font-weight: 600; margin-bottom: 0.4rem; color: var(--text); }
.empty-state p { font-size: 0.9rem; margin-bottom: 1.25rem; }

/* ===== Responsive ===== */
@media (max-width: 600px) {
  .app-main { padding: 1rem; }
  .form-row { flex-direction: column; gap: 0; }
  .header-inner { gap: 0.5rem; padding: 0 0.75rem; }
  /* Nav scrolls horizontally so all links stay accessible without cramping */
  .app-nav {
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    flex-shrink: 1;
    min-width: 0;
  }
  .app-nav::-webkit-scrollbar { display: none; }
  .nav-link { padding: 0.4rem 0.6rem; font-size: 0.82rem; white-space: nowrap; }
  .logout-form { flex-shrink: 0; }
  .ingredient-row .ing-name { flex: 2; }
  .cards-grid { grid-template-columns: 1fr; }
  .date-range-controls { flex-direction: column; align-items: flex-start; }
  .modal { padding: 0; align-items: flex-end; }
  .modal-content { border-radius: var(--radius) var(--radius) 0 0; max-width: 100%; }
  /* Add-user / add-unit forms wrap on narrow screens */
  .units-add-row { flex-wrap: wrap; }
  .units-add-row input { min-width: 0; }
}

/* ===== Settings ===== */
.settings-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.5rem;
  max-width: 560px;
}
.settings-section-header {
  list-style: none;
  cursor: pointer;
  padding: 0.25rem 0;
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}
.settings-section-header::-webkit-details-marker { display: none; }
.settings-section-header::before {
  content: '▶';
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-top: 0.4rem;
  flex-shrink: 0;
  transition: transform 0.15s;
}
details[open] > .settings-section-header::before { content: '▼'; }
.settings-section-header:hover h3 { color: var(--accent); }
.settings-section-header h3 { font-size: 1.05rem; font-weight: 700; margin-bottom: 0.3rem; }
.settings-section-desc { font-size: 0.85rem; color: var(--text-muted); }
.settings-section-body { margin-top: 0.75rem; }
details.settings-section + details.settings-section { margin-top: 1.5rem; }
.units-add-row {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 1rem;
}
.units-add-row input { flex: 1; }
.units-list {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.unit-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0.85rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.unit-row:last-child { border-bottom: none; }
.unit-row:hover { background: var(--bg); }
.unit-label { flex: 1; font-size: 0.92rem; }
.unit-edit-input { flex: 1; padding: 0.3rem 0.5rem; font-size: 0.92rem; }
.unit-actions { display: flex; gap: 0.3rem; align-items: center; flex-shrink: 0; }
.settings-empty { color: var(--text-muted); font-size: 0.88rem; padding: 0.5rem 0; }
.settings-error { color: var(--danger); font-size: 0.88rem; }
.slot-order-btns { display: flex; flex-direction: column; gap: 1px; flex-shrink: 0; }
.slot-order-btn {
  background: none;
  border: none;
  padding: 0 0.15rem;
  font-size: 0.55rem;
  line-height: 1.2;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.1s;
}
.slot-order-btn:hover:not(:disabled) { color: var(--accent-dark); }
.slot-order-btn:disabled { opacity: 0.2; cursor: default; }

/* ===== Admin ===== */

/* Section header with minimise button */
.admin-section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.admin-section-header > div:first-child { flex: 1; min-width: 0; }
.admin-section-header h3 { font-size: 1.05rem; font-weight: 700; margin-bottom: 0.3rem; }

.section-minimize-btn {
  flex-shrink: 0;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 1.7rem;
  height: 1.7rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.section-minimize-btn:hover { background: var(--bg); color: var(--text); }

.admin-section.collapsed .settings-section-body { display: none; }
.admin-section.collapsed .admin-section-header { margin-bottom: 0; }

/* ToDo items */
.todo-filter-bar {
  display: flex;
  gap: 0.375rem;
  margin-bottom: 0.75rem;
}

.todo-add-form {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  margin-bottom: 1rem;
}
.todo-form-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}
.todo-form-row .form-group { margin-bottom: 1rem; }
.todo-form-actions {
  display: flex;
  gap: 0.5rem;
}

.todo-item {
  border-bottom: 1px solid var(--border);
  padding: 0.65rem 0;
}
.todo-item:first-child { border-top: 1px solid var(--border); }
.todo-item--complete .todo-item-title { text-decoration: line-through; color: var(--text-muted); }
.todo-item--wont-do  .todo-item-title { text-decoration: line-through; color: var(--text-muted); opacity: 0.6; }

.todo-item-main {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
}
.todo-item-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.todo-item-title { font-size: 0.92rem; font-weight: 500; word-break: break-word; }
.todo-item-notes { font-size: 0.82rem; color: var(--text-muted); white-space: pre-wrap; word-break: break-word; }
.todo-gh-link { font-size: 0.78rem; font-weight: 400; color: var(--text-muted); margin-left: 0.4rem; text-decoration: none; }
.todo-gh-link:hover { text-decoration: underline; }

/* Status button */
.todo-status-btn {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  line-height: 1;
  flex-shrink: 0;
  margin-top: 0.1rem;
}
.todo-status {
  display: inline-block;
  width: 1.3rem;
  height: 1.3rem;
  text-align: center;
  line-height: 1.3rem;
  font-size: 0.95rem;
  border-radius: 50%;
  font-weight: 600;
}
.todo-status--incomplete { color: var(--text-muted); border: 1.5px solid var(--border); }
.todo-status--complete   { color: var(--accent-dark); background: var(--accent-light); }
.todo-status--wont-do    { color: var(--danger); background: #fdf0ef; }

/* Priority badge */
.todo-priority {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.3rem;
  height: 1.3rem;
  border-radius: var(--radius-sm);
  font-size: 0.72rem;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 0.1rem;
}
.todo-priority--h { background: #fde8e8; color: #c0392b; }
.todo-priority--m { background: #fef3e2; color: #b45309; }
.todo-priority--l { background: var(--bg);  color: var(--text-muted); border: 1px solid var(--border); }

/* Inline edit form */
.todo-edit-form {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.85rem;
  margin-top: 0.65rem;
}

.role-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.1rem 0.45rem;
  border-radius: 99px;
  margin-left: 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  vertical-align: middle;
}
.role-badge--admin { background: var(--accent-light); color: var(--accent-dark); }
.role-badge--user  { background: var(--bg); color: var(--text-muted); border: 1px solid var(--border); }
.admin-role-select { padding: 0.25rem 0.4rem; font-size: 0.82rem; width: auto; border-radius: var(--radius-sm); }

/* ===== Recipe search bar ===== */
.recipe-search-bar {
  margin-bottom: 1rem;
}
.recipe-search-bar input[type="text"] {
  width: 100%;
  box-sizing: border-box;
}

/* ===== Tags ===== */
.tag-filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  align-items: center;
}
.tag-filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.3rem 0.75rem;
  border-radius: 99px;
  font-size: 0.82rem;
  font-weight: 500;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  user-select: none;
}
.tag-filter-chip:hover { background: var(--accent-light); color: var(--accent-dark); border-color: var(--accent-light); }
.tag-filter-chip.active { background: var(--accent); color: white; border-color: var(--accent); }

.recipe-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.15rem;
}
.recipe-tag-chip {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 99px;
  font-size: 0.74rem;
  font-weight: 500;
  background: var(--accent-light);
  color: var(--accent-dark);
}

.tag-input-area {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  padding: 0.4rem 0.6rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: text;
  transition: border-color 0.15s;
  min-height: 2.4rem;
}
.tag-input-area:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,121,66,0.12); }
.tag-input-area input {
  border: none;
  outline: none;
  padding: 0;
  min-width: 100px;
  flex: 1;
  box-shadow: none;
  font-size: 0.9rem;
}
.tag-input-area input:focus { border: none; box-shadow: none; }
.selected-tags { display: contents; }
.selected-tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.15rem 0.5rem 0.15rem 0.65rem;
  border-radius: 99px;
  font-size: 0.8rem;
  font-weight: 500;
  background: var(--accent);
  color: white;
  white-space: nowrap;
}
.selected-tag-chip button {
  background: none;
  border: none;
  color: rgba(255,255,255,0.8);
  padding: 0;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
}
.selected-tag-chip button:hover { color: white; }

/* ===== Print ===== */
@media print {
  .app-header, .shopping-controls, .shopping-add-row, .shopping-action-bar,
  #addedItemsSection, .page-header .btn,
  #page-recipes, #page-mealplan { display: none !important; }
  #page-shopping { display: block !important; }
  body { background: white; }
  .app-main { padding: 0; max-width: 100%; }
  .page-header { margin-bottom: 1rem; }
  .page-header h2 { font-size: 1.3rem; }
  .shopping-category { box-shadow: none; border: 1px solid #ccc; margin-bottom: 0.75rem; }
  .shopping-category-header { background: #f0f0f0; print-color-adjust: exact; }
  .shopping-item { padding: 0.4rem 0.75rem; }
  .shopping-item input[type="checkbox"] { print-color-adjust: exact; }
  .toast, .modal { display: none !important; }
}

/* ===== Recipe card image ===== */
.recipe-card-image {
  margin: -1.25rem -1.25rem 0.5rem;
  border-radius: var(--radius) var(--radius) 0 0;
  overflow: hidden;
  aspect-ratio: 16/9;
  background: var(--bg);
}
.recipe-card-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ===== Recipe card URL ===== */
.recipe-card-url {
  font-size: 0.78rem;
}
.recipe-card-url a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.recipe-card-url a:hover { color: var(--accent-dark); }

/* ===== Recipe card instructions preview ===== */
.recipe-instructions-preview {
  font-size: 0.82rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  padding-top: 0.5rem;
  margin-top: 0.25rem;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
}
.recipe-instructions-preview h3 {
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 0.15rem;
}
.recipe-instructions-preview ul,
.recipe-instructions-preview ol {
  margin-left: 1.2rem;
}

/* ===== Rich text editor ===== */
.rich-editor-wrap {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.rich-editor-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(79,121,66,0.15);
}
.rich-editor-toolbar {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  background: var(--bg);
  padding: 0.25rem;
  flex-wrap: wrap;
}
.rich-btn {
  background: none;
  border: 1px solid transparent;
  border-radius: 4px;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.1s, border-color 0.1s;
}
.rich-btn:hover { background: var(--surface); border-color: var(--border); }
.rich-btn:active { background: var(--accent-light); }
.rich-editor {
  border: none;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  padding: 0.5rem 0.65rem;
  min-height: 120px;
  background: transparent;
  font-size: 0.95rem;
  line-height: 1.6;
  outline: none;
  overflow-y: auto;
  display: block;
  width: 100%;
  box-sizing: border-box;
}
.rich-editor:empty::before {
  content: attr(data-placeholder);
  color: var(--text-muted);
  pointer-events: none;
}
.rich-editor h3 { font-size: 0.95rem; font-weight: 600; margin-bottom: 0.25rem; }
.rich-editor ul, .rich-editor ol { margin-left: 1.4rem; }
.rich-editor li { margin-bottom: 0.1rem; }
.rich-editor p { margin-bottom: 0.25rem; }

/* ===== Recipe image section in form ===== */
.recipe-image-section {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.recipe-image-preview {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.recipe-image-preview img {
  width: 80px;
  height: 60px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.recipe-image-upload-btn {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
}

/* ===== Recipe Category Groups ===== */
.recipe-category-group {
  margin-bottom: 1.5rem;
}
.recipe-category-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  user-select: none;
  margin-bottom: 0.75rem;
}
.recipe-category-header:hover { background: var(--surface-hover, var(--bg)); }
.recipe-category-name {
  font-weight: 700;
  font-size: 1rem;
  flex: 1;
}
.recipe-category-count {
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 0.1rem 0.5rem;
}
.recipe-category-chevron::before { content: '▼'; font-size: 0.7rem; color: var(--text-muted); }
.recipe-category-group.collapsed .recipe-category-chevron::before { content: '▶'; }
.recipe-category-group.collapsed .recipe-category-body { display: none; }

/* Prompt history */
.prompt-history-entry {
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 0.5rem;
  overflow: hidden;
}
.prompt-history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  background: var(--surface);
}
.prompt-history-date { font-size: 0.85rem; color: var(--text-muted); }
.prompt-history-preview {
  margin: 0;
  padding: 0.75rem;
  font-size: 0.75rem;
  font-family: monospace;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--bg);
  border-top: 1px solid var(--border);
  max-height: 300px;
  overflow-y: auto;
}

/* ===== Cooking View ===== */
.cooking-view {
  max-width: 680px;
  margin: 0 auto;
  padding: 1rem 1.5rem 4rem;
}
.cooking-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--border);
}
.cooking-header-actions {
  display: flex;
  gap: 0.75rem;
}
.cooking-title {
  font-size: 1.6rem;
  font-weight: 700;
  text-align: center;
  line-height: 1.2;
}
.cooking-meta {
  font-size: 1.2rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  text-align: center;
}
.cooking-image {
  margin-bottom: 2rem;
  border-radius: var(--radius);
  overflow: hidden;
}
.cooking-image img {
  width: 100%;
  max-height: 320px;
  object-fit: cover;
  display: block;
}
.cooking-section {
  margin-bottom: 2.5rem;
}
.cooking-section-title {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 1rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
  color: var(--accent-dark);
}
.cooking-ingredients {
  list-style: none;
  padding: 0;
  margin: 0;
}
.cooking-ingredients li {
  font-size: 1.25rem;
  line-height: 1.6;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}
.cooking-ingredients li:last-child {
  border-bottom: none;
}
.cooking-instructions {
  font-size: 1.2rem;
  line-height: 1.8;
}
.cooking-instructions ol,
.cooking-instructions ul {
  padding-left: 1.5rem;
}
.cooking-instructions li {
  margin-bottom: 1.2rem;
  padding-left: 0.25rem;
}
.cooking-instructions p {
  margin-bottom: 1.2rem;
}
.cooking-instructions h3 {
  font-size: 1.2rem;
  font-weight: 700;
  margin: 1.5rem 0 0.75rem;
}
.cooking-notes {
  font-size: 1.1rem;
  line-height: 1.7;
  color: var(--text-muted);
  white-space: pre-wrap;
}
@media (max-width: 500px) {
  .cooking-view { padding: 0.75rem 1rem 4rem; }
  .cooking-title { font-size: 1.35rem; }
  .cooking-ingredients li { font-size: 1.15rem; }
  .cooking-instructions { font-size: 1.1rem; }
}

/* ===== Records ===== */
.record-row { flex-direction: column; align-items: flex-start; gap: 0.25rem; }
.record-list-item { display: flex; justify-content: space-between; align-items: baseline; width: 100%; gap: 1rem; }
.record-title { font-weight: 500; }
.record-date { font-size: 0.8rem; color: var(--muted); white-space: nowrap; }
.record-tags-row { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.record-tag { font-size: 0.75rem; background: var(--surface-2, #f0f0f0); color: var(--text-muted, #666); padding: 0.15rem 0.5rem; border-radius: 99px; }
.record-detail { max-width: 720px; padding: 0.5rem 0 3rem; }
.record-detail-title { font-size: 1.6rem; font-weight: 700; margin: 0 0 0.5rem; }
.record-detail-meta { display: flex; flex-wrap: wrap; gap: 1rem; align-items: baseline; margin-bottom: 0.75rem; font-size: 0.85rem; color: var(--muted); }
.record-detail-url { color: var(--accent); word-break: break-all; }
.record-detail-section { margin-top: 1.5rem; }
.record-detail-section h3 { font-size: 1rem; font-weight: 600; margin: 0 0 0.5rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.record-detail-section p { margin: 0; line-height: 1.6; }
.record-full-text { white-space: pre-wrap; line-height: 1.7; font-size: 0.95rem; }
.record-full-text-md { white-space: normal; }
.record-full-text-md h1,.record-full-text-md h2,.record-full-text-md h3 { margin: 1.25rem 0 0.5rem; font-weight: 600; }
.record-full-text-md h1 { font-size: 1.3rem; }
.record-full-text-md h2 { font-size: 1.15rem; }
.record-full-text-md h3 { font-size: 1rem; }
.record-full-text-md p { margin: 0 0 0.85rem; }
.record-full-text-md ul,.record-full-text-md ol { margin: 0 0 0.85rem 1.5rem; }
.record-full-text-md li { margin-bottom: 0.25rem; }
.record-full-text-md strong { font-weight: 600; }
.record-full-text-md em { font-style: italic; }
.record-inline-img { max-width: 100%; height: auto; border-radius: 4px; margin: 0.75rem 0; display: block; }

.record-video-badge { font-size: 0.7rem; color: var(--accent); margin-right: 0.3rem; vertical-align: middle; }
.record-video-embed { position: relative; width: 100%; padding-top: 56.25%; margin: 1.25rem 0; border-radius: 6px; overflow: hidden; }
.record-video-embed iframe { position: absolute; inset: 0; width: 100%; height: 100%; }
.record-video-link { display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.5rem 1rem; background: var(--accent); color: #fff; border-radius: 6px; font-weight: 500; text-decoration: none; }
.record-video-link:hover { opacity: 0.85; }
.changelog-entry { padding: 0.75rem 0; border-bottom: 1px solid var(--border, #e5e5e5); }
.changelog-entry:last-child { border-bottom: none; }
.changelog-version { display: flex; align-items: baseline; gap: 0.75rem; margin-bottom: 0.4rem; }
.changelog-version-num { font-weight: 600; font-size: 0.95rem; }
.changelog-version-date { font-size: 0.8rem; color: var(--muted); }
.changelog-version-count { font-size: 0.75rem; color: var(--muted); margin-left: auto; }
.changelog-changes { margin: 0 0 0 1.25rem; padding: 0; font-size: 0.875rem; line-height: 1.6; color: var(--text-secondary, #444); }
.changelog-changes li { margin-bottom: 0.15rem; }
.record-url-bar { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.record-url-bar input { flex: 1; min-width: 200px; }
.record-url-status { font-size: 0.8rem; color: var(--muted); }
.record-url-status.error { color: var(--danger, #c0392b); }

.search-bar { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.75rem; }
.search-bar input { flex: 1; min-width: 200px; }
.search-clear-btn { white-space: nowrap; }
.ask-bar { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.ask-bar input { flex: 1; min-width: 200px; }
.ask-status { font-size: 0.8rem; color: var(--muted); }
.ask-status.error { color: var(--danger, #c0392b); }
.record-ask-reason { font-size: 0.8rem; color: var(--muted); font-style: italic; padding-top: 0.1rem; }

/* ===== Favourites ===== */
.record-list-trailing { display: flex; align-items: center; gap: 0.5rem; white-space: nowrap; flex-shrink: 0; }
.fav-btn { background: none; border: none; padding: 0 0.1rem; font-size: 1rem; color: var(--text-muted, #9ca3af); line-height: 1; cursor: pointer; transition: color 0.15s, transform 0.1s; }
.fav-btn:hover { color: #e05c5c; transform: scale(1.2); }
.fav-btn--on { color: #e05c5c; }
.fav-btn--lg { font-size: 1.4rem; margin-left: 0.5rem; align-self: flex-start; padding-top: 0.2rem; }
.record-detail-title-row { display: flex; align-items: flex-start; gap: 0.25rem; margin: 0 0 0.5rem; }
.record-detail-title-row .record-detail-title { margin: 0; flex: 1; }
