:root {
  color-scheme: light;
  --bg: #fafafa;
  --fg: #1a1a1a;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --muted: #666;
  --border: #e5e5e5;
  --danger: #b91c1c;
  --card: #fff;
  --shadow: 0 12px 40px rgb(0 0 0 / 18%);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  line-height: 1.45;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.top-nav {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { color: var(--fg); font-weight: 700; }
main { padding: 18px; max-width: 1280px; margin: 0 auto; }
.page-head { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.week-nav { display: flex; align-items: center; gap: 12px; }
.week-nav h1 { margin: 0; }
.week-nav-arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--accent);
  text-decoration: none;
  font-size: 0.9em;
  line-height: 1;
  flex-shrink: 0;
}
.week-nav-arrow:hover { background: var(--accent-soft); border-color: var(--accent); }
.week-nav-arrow.disabled { color: var(--muted); opacity: 0.4; pointer-events: none; }
.muted { color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
/* Stack the bridge pill above the action buttons, both right-aligned. */
.actions-col { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.actions-col .actions { justify-content: flex-end; }
/* Hide the pill slot entirely when empty (local mode / before first poll). */
#woolies-bridge-status:empty { display: none; }
.button, button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: 6px;
  padding: 8px 12px;
  cursor: pointer;
  font: inherit;
}
.button.secondary, button.secondary { background: #fff; color: var(--accent); }
button.danger { border-color: var(--danger); background: var(--danger); }
button.linklike { border: 0; background: transparent; color: var(--accent); padding: 0; text-decoration: underline; cursor: pointer; font: inherit; }
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  margin: 16px 0;
}
.grid-wrap { overflow-x: auto; border: 1px solid var(--border); background: var(--card); }
.grid { width: 100%; border-collapse: collapse; min-width: 920px; }
.grid th, .grid td { border: 1px solid var(--border); padding: 8px; vertical-align: top; }
.grid th { background: #f7f7f7; text-align: left; }
.meal-label { width: 130px; font-weight: 700; }

/* New week-grid layout.
 * Day-major DOM, CSS Grid lays it out: row 1 = day headers, col 1 = meal-type labels,
 * cells positioned via --day-col / --meal-row custom properties from the template.
 * Mobile (≤760px) re-flows into a horizontal scroll-snap carousel of day cards. */
.week-grid {
  display: grid;
  grid-template-columns: 130px repeat(var(--day-count, 7), minmax(0, 1fr));
  gap: 4px;
  background: var(--card);
  border: 1px solid var(--border);
  padding: 6px;
  border-radius: 8px;
}
.grid-corner { grid-row: 1; grid-column: 1; }
.grid-day-header {
  grid-row: 1;
  grid-column: calc(var(--day-col) + 1);
  background: #f7f7f7;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}
.grid-day-header .dh-date { font-weight: 400; font-size: 0.8em; }
.grid-meal-label {
  grid-column: 1;
  grid-row: calc(var(--meal-row) + 1);
  font-weight: 700;
  padding: 8px;
  background: #f7f7f7;
  border: 1px solid var(--border);
  border-radius: 6px;
  align-self: stretch;
}
.grid-day { display: contents; }
.grid-day-header-mobile, .grid-meal-label-mobile { /* hidden by default via .m-only */ }
.grid-meal {
  grid-column: calc(var(--day-col) + 1);
  grid-row: calc(var(--meal-row) + 1);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px;
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 72px;
}
.d-only { display: block; }
.m-only { display: none !important; }
/* Today highlight: applied to .grid-day and .grid-day-header[data-day=N] by JS. */
.week-grid .grid-day-header.is-today {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.cell {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 80px;
  margin-bottom: 6px;
  padding: 8px;
  border-radius: 8px;
  color: inherit;
  background: transparent;
  transition: background 0.1s;
}
.cell:hover { background: #f0f7ff; }
.cell.skipped { color: var(--muted); font-style: italic; }
.cell.empty { color: var(--muted); border: 1px dashed var(--border); }
.cell-title {
  display: block;
  width: 100%;
  text-align: left;
  font-weight: 600;
  background: transparent;
  border: none;
  color: inherit;
  padding: 0;
  font: inherit;
  cursor: pointer;
}
.cell-title:hover { color: var(--accent); text-decoration: underline; }
.cell-title.cell-edit-primary:hover { text-decoration: none; }
.cell-meta {
  margin-top: auto;
  padding-top: 6px;
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: space-between;
  min-height: 22px;
}
.servings-placeholder {
  flex: 1;
}
.cell-edit {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  font-size: 1em;
  padding: 0 6px;
  cursor: pointer;
  line-height: 1.4;
  margin-left: auto;
  border-radius: 4px;
  flex-shrink: 0;
}
.cell-edit:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: #fff;
}
.servings-badge {
  background: var(--accent);
  color: #fff;
  padding: 2px 6px;
  border-radius: 10px;
  font-size: 0.75em;
  font-style: normal;
  white-space: nowrap;
}
dialog.modal {
  padding: 24px;
  border: none;
  border-radius: 10px;
  max-width: 560px;
  width: min(94vw, 560px);
  max-height: 86vh;
  overflow: auto;
  box-shadow: var(--shadow);
}
dialog.modal.modal-wide {
  max-width: 1080px;
  width: min(96vw, 1080px);
}
dialog::backdrop { background: rgb(0 0 0 / 50%); backdrop-filter: blur(3px); }
.form-grid { display: grid; gap: 12px; }
.apply-matching { display: flex; align-items: flex-start; gap: 8px; font-weight: 400; }
.apply-matching input { width: auto; flex-shrink: 0; margin-top: 2px; }
label { font-weight: 600; }
input, select, textarea {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
}
.recipe-results { display: grid; gap: 6px; max-height: 180px; overflow: auto; }
.result-button { width: 100%; text-align: left; background: #fff; color: var(--fg); border-color: var(--border); }
.result-button:hover { border-color: var(--accent); background: var(--accent-soft); }
.shopping-footer { margin-top: 14px; display: flex; justify-content: space-between; gap: 12px; }
.table { width: 100%; border-collapse: collapse; background: var(--card); }
.table th, .table td { border-bottom: 1px solid var(--border); padding: 10px; text-align: left; }
.table th { background: #f7f7f7; }
.unit-heading { background: var(--accent-soft); font-weight: 700; }
.shopping-line.in-stock td { color: var(--muted); text-decoration: line-through; }
.shopping-line.in-stock td.stock-toggle { text-decoration: none; }
.stock-toggle button { font-size: 1.1em; line-height: 1; }
.week-list { display: grid; gap: 10px; }
.week-item { display: flex; justify-content: space-between; gap: 12px; align-items: center; }

.recipe-detail { display: grid; gap: 16px; }
.recipe-detail-image { width: 100%; max-height: 280px; object-fit: cover; border-radius: 8px; }
.recipe-detail-body {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(280px, 1.4fr);
  gap: 24px;
}
.recipe-detail-body > * { min-width: 0; }
.recipe-image { max-width: 100%; border-radius: 8px; }
.macros { display: flex; gap: 8px; flex-wrap: wrap; }
.macros span { background: #f3f4f6; padding: 4px 8px; border-radius: 12px; font-size: 0.9em; }
.recipe-notes { margin-top: 8px; padding: 10px 12px; background: #fff8e1; border-left: 3px solid #f59e0b; border-radius: 4px; }

/* Recipe modal: servings rescale input */
.recipe-servings-form {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0 4px;
  padding: 8px 12px;
  background: #f1f6f1;
  border-left: 3px solid var(--accent, #2a7);
  border-radius: 4px;
}
.recipe-servings-form label { font-weight: 600; margin: 0; }
.recipe-servings-form input[type="number"] {
  width: 72px;
  padding: 4px 6px;
  font-size: 1em;
  border: 1px solid var(--border);
  border-radius: 4px;
  text-align: right;
}
.recipe-scaled-notice {
  margin: 6px 0 12px;
  padding: 6px 12px;
  background: #fff8e1;
  border-left: 3px solid #f59e0b;
  border-radius: 4px;
  font-size: 0.9em;
}

/* Edit-modal "Originally: ..." panel for swapped meals */
.original-panel {
  margin: 8px 0 12px;
  padding: 8px 12px;
  background: #f8f4ec;
  border-left: 3px solid #c9a86b;
  border-radius: 4px;
}
.original-panel p { margin: 2px 0; }
.original-label { font-size: 0.85em; }
.original-title { display: flex; flex-wrap: wrap; gap: 10px; align-items: baseline; }
.original-title .linklike { font-size: 0.9em; }

/* Two-pane browse modal */
.browse-layout {
  display: grid;
  grid-template-columns: minmax(220px, 320px) 1fr;
  gap: 16px;
  height: min(70vh, 600px);
  min-height: 320px;
}
.browse-list {
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: auto;
  display: flex;
  flex-direction: column;
}
.browse-search { padding: 8px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--card); }
.browse-search input { padding: 6px 8px; }
.browse-items { list-style: none; margin: 0; padding: 4px 0; }
.browse-items li button {
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--fg);
  padding: 8px 12px;
  cursor: pointer;
  font: inherit;
  border-left: 3px solid transparent;
}
.browse-items li button:hover { background: var(--accent-soft); border-left-color: var(--accent); }
.browse-items li button.active { background: var(--accent-soft); border-left-color: var(--accent); font-weight: 600; }
.browse-preview {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 16px;
  overflow: auto;
}
.browse-preview .empty-state { color: var(--muted); display: grid; place-items: center; height: 100%; }
.browse-preview img { max-height: 180px; border-radius: 6px; }

@media (max-width: 760px) {
  main { padding: 10px; }
  .top-nav { gap: 8px; padding: 10px 12px; font-size: 0.95em; }
  .page-head, .week-item, .shopping-footer { align-items: flex-start; flex-direction: column; }
  /* Mobile: re-flow the week grid into a horizontal scroll-snap carousel of day cards.
   * The d-only desktop header strip and side label column are hidden; each .grid-day
   * shows its own header + per-cell meal-type labels (.m-only). */
  .week-grid {
    display: flex;
    flex-direction: row;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    gap: 0;
    padding: 0;
    border: 0;
    background: transparent;
    border-radius: 0;
  }
  .grid-corner, .grid-day-header, .grid-meal-label { display: none !important; }
  .grid-day {
    display: flex !important;
    flex-direction: column;
    flex: 0 0 100%;
    scroll-snap-align: start;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px;
    gap: 8px;
  }
  .grid-day + .grid-day { margin-left: 8px; }
  .grid-day.is-today { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
  .grid-day-header-mobile, .grid-meal-label-mobile { display: block !important; }
  .grid-day-header-mobile {
    display: flex !important;
    align-items: baseline;
    gap: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
    font-weight: 700;
  }
  .grid-day-header-mobile .dh-date { font-weight: 400; font-size: 0.85em; }
  .grid-meal {
    display: flex;
    flex-direction: column;
    gap: 4px;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px;
    min-height: 0;
  }
  .grid-meal-label-mobile {
    font-weight: 600;
    font-size: 0.85em;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }
  .d-only { display: none !important; }
  .cell { min-height: 48px; padding: 6px; }
  .cell-title { font-size: 0.95em; }
  .servings-badge { padding: 1px 5px; font-size: 0.7em; }
  .cell-edit { font-size: 0.95em; padding: 0 4px; }
  /* On narrow screens, dialogs go nearly fullscreen for tap comfort */
  dialog.modal, dialog.modal.modal-wide {
    max-width: 100vw;
    width: 100vw;
    max-height: 100vh;
    height: 100vh;
    border-radius: 0;
    padding: 16px;
  }
  .recipe-detail-body { grid-template-columns: 1fr; gap: 16px; }
  .browse-layout {
    grid-template-columns: 1fr;
    height: auto;
  }
  .browse-list { max-height: 40vh; }
  .browse-preview { min-height: 200px; }
}

/* Woolies cell on the shopping table */
.woolies-cell { max-width: 320px; }
.woolies-mapped {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  color: var(--fg);
}
.woolies-mapped:hover { text-decoration: underline; color: var(--accent); }
.woolies-thumb { width: 28px; height: 28px; object-fit: cover; border-radius: 4px; border: 1px solid var(--border); }
.woolies-tick { color: var(--accent); font-weight: 700; }
.woolies-name { font-size: 0.9em; }
.woolies-conf { font-size: 0.75em; }
.woolies-cell .linklike { margin-left: 6px; font-size: 0.8em; }

/* Picker modal */
.woolies-results { margin-top: 14px; }
.woolies-result-grid {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.woolies-card {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  background: var(--card);
}
.woolies-card img {
  width: 100%;
  height: 120px;
  object-fit: contain;
  background: #f7f7f7;
  border-radius: 4px;
}
.woolies-card-body { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.woolies-card-title { font-size: 0.92em; font-weight: 600; }
.woolies-brand { display: inline-block; color: var(--accent); margin-right: 4px; }
.woolies-card-meta { font-size: 0.8em; color: var(--muted); }
.badge-special {
  display: inline-block;
  background: var(--danger);
  color: #fff;
  font-size: 0.7em;
  padding: 1px 6px;
  border-radius: 8px;
  margin-left: 4px;
}

/* --- Woolies push / sync UI --- */
.woolies-auth-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 6px;
  margin: 12px 0;
  font-size: 0.92em;
}
.woolies-auth-banner .banner-icon { font-size: 1.1em; font-weight: 700; }
.woolies-auth-banner.banner-valid { background: #ecfdf5; color: #065f46; border: 1px solid #6ee7b7; }
.woolies-auth-banner.banner-expired,
.woolies-auth-banner.banner-missing,
.woolies-auth-banner.banner-corrupt {
  background: #fffbeb; color: #92400e; border: 1px solid #fcd34d;
}
.bridge-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.85em;
  font-weight: 600;
  white-space: nowrap;
}
.bridge-status .bridge-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex: none;
}
.bridge-status.bridge-connected {
  background: #ecfdf5; color: #065f46; border: 1px solid #6ee7b7;
}
.bridge-status.bridge-connected .bridge-dot {
  background: #10b981; box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
}
.bridge-status.bridge-disconnected {
  background: #fef2f2; color: #991b1b; border: 1px solid #fca5a5;
}
.bridge-status.bridge-disconnected .bridge-dot {
  background: #ef4444; box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2);
}
.push-result {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  margin: 12px 0;
  background: var(--card);
}
.push-result.push-success { border-left: 3px solid #10b981; }
.push-result.push-error { border-left: 3px solid var(--danger); background: #fef2f2; }
.push-result h3 { margin: 0 0 6px; }
.push-counts {
  list-style: none;
  padding: 0;
  margin: 6px 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.push-counts li {
  background: #f3f4f6;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 0.9em;
}
.push-counts li.warn { background: #fef3c7; color: #92400e; }
.push-items { margin: 6px 0 0 1.4em; padding: 0; }
.htmx-indicator { display: none; }
.htmx-request.htmx-indicator,
.htmx-request .htmx-indicator { display: inline; }

/* Linked-list panel — top-of-shopping-page card showing the Woolies
   list currently tied to this week, with Open + Unlink actions. */
.woolies-linked-card {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  margin: 12px 0;
  background: var(--card);
}
.woolies-linked-card.woolies-linked-empty {
  border-left-color: var(--border);
  font-style: italic;
}
.woolies-linked-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline; }
.woolies-linked-name { font-weight: 600; }
.woolies-linked-meta code { font-size: 0.85em; padding: 1px 4px; background: #f3f4f6; border-radius: 3px; }
.woolies-linked-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* --- mobile-first shopping list (replaces the old `.table` layout) --- */
.shopping-list { display: flex; flex-direction: column; gap: 4px; margin: 12px 0; }
.shopping-category {
  margin: 18px 0 4px;
  padding: 6px 10px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 6px;
  font-size: 0.95em;
}
.shopping-row {
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  transition: background 0.1s;
}
.shopping-row.in-stock { background: #f7f7f7; opacity: 0.65; }
.shopping-row.in-stock .shopping-food-name { text-decoration: line-through; }

/* "N already in stock" collapsible per category */
.shopping-instock-group {
  margin: 6px 0 4px;
}
.shopping-instock-group > summary {
  cursor: pointer;
  padding: 6px 10px;
  background: #fafaf7;
  border: 1px dashed var(--border);
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.88em;
  user-select: none;
  list-style-position: inside;
}
.shopping-instock-group > summary:hover { background: #f1f1ec; }
.shopping-instock-group > summary::marker { color: var(--muted); }
.shopping-instock-group[open] > summary { margin-bottom: 6px; }
.shopping-instock-group .instock-count { font-weight: 600; color: var(--text, #222); }
.shopping-instock-group > .shopping-row + .shopping-row { margin-top: 4px; }
.shopping-row-main {
  display: grid;
  grid-template-columns: 38px 70px 56px 1fr;
  gap: 10px;
  align-items: center;
}
.shopping-stock { margin: 0; }
.stock-checkbox {
  font-size: 1.5em;
  line-height: 1;
  padding: 4px 6px;
  border: none;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
}
.stock-checkbox:hover { background: var(--accent-soft); border-radius: 4px; }
.shopping-qty {
  font-variant-numeric: tabular-nums;
  text-align: right;
  font-size: 1.05em;
}
.shopping-qty .qty-num { font-weight: 600; }
.shopping-qty .qty-unit { margin-left: 1px; color: var(--muted); font-size: 0.9em; }
.shopping-qty .qty-unit-spaced { margin-left: 4px; }
.shopping-qty .qty-was { font-size: 0.75em; }
.shopping-thumb {
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.shopping-thumb img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
  background: #f7f7f7;
  border: 1px solid var(--border);
}
.shopping-thumb-placeholder {
  width: 44px; height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  font-weight: 700;
  text-decoration: none;
}
.shopping-thumb-mapped {
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent);
}
.shopping-thumb-unmapped {
  background: #fef3c7;
  color: #92400e;
  border: 1px dashed #fcd34d;
  font-size: 1.2em;
}
.shopping-food { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.shopping-food-name { font-weight: 600; overflow-wrap: anywhere; }
.shopping-food-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85em;
  min-width: 0;
}
.shopping-food-meta .woolies-mapped-link {
  color: var(--accent);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.shopping-food-meta .woolies-mapped-link:hover { text-decoration: underline; }
.shopping-edit-icon {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  font-size: 1em;
  padding: 0 6px;
  cursor: pointer;
  line-height: 1.4;
  border-radius: 4px;
  flex-shrink: 0;
}
.shopping-edit-icon:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: #fff;
}
.shopping-sources {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
  font-size: 0.9em;
}
.shopping-sources summary {
  cursor: pointer;
  color: var(--muted);
  list-style: none;
  padding: 2px 0;
}
.shopping-sources summary::before { content: "▶ "; font-size: 0.75em; transition: transform 0.1s; display: inline-block; }
.shopping-sources[open] summary::before { content: "▼ "; }
.shopping-sources ul { list-style: none; padding: 4px 0 0 18px; margin: 0; }
.shopping-sources li { padding: 1px 0; }
.shopping-sources .src-title {
  border: none;
  background: none;
  padding: 0;
  font: inherit;
  cursor: pointer;
  text-align: left;
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: rgba(0, 0, 0, 0.15);
  text-underline-offset: 2px;
}
.shopping-sources .src-title:hover {
  text-decoration-color: currentColor;
}

/* On narrow screens — slightly tighter grid; the layout naturally works
 * because the food column flexes to fill remaining width. */
@media (max-width: 760px) {
  .shopping-row-main { grid-template-columns: 34px 60px 48px 1fr; gap: 8px; }
  .shopping-thumb { width: 48px; height: 48px; }
  .shopping-thumb-placeholder { width: 38px; height: 38px; }
  .shopping-food-meta { font-size: 0.8em; }
  .stock-checkbox { font-size: 1.4em; padding: 2px 4px; }
}

/* ============================================================
   Dark mode — auto-detected from the browser/OS preference.
   Flips the core variables + the hardcoded light surfaces and
   the semantic (green/amber/red) badges to dark-friendly values.
   ============================================================ */
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0f1115;
    --fg: #e6e7ea;
    --accent: #60a5fa;
    --accent-soft: #1e293b;
    --muted: #9aa0aa;
    --border: #2a2e37;
    --danger: #f87171;
    --card: #181b21;
    --shadow: 0 12px 40px rgb(0 0 0 / 55%);
  }

  /* White/near-white surfaces -> card. */
  .week-nav-arrow,
  .button.secondary, button.secondary,
  .grid-meal,
  .result-button {
    background: var(--card);
  }

  /* Subtle grey surfaces (#f7f7f7 / #f3f4f6) -> a touch above card. */
  .grid th,
  .grid-day-header,
  .grid-meal-label,
  .table th,
  .woolies-card img,
  .shopping-row.in-stock,
  .shopping-thumb img,
  .macros span,
  .push-counts li,
  .woolies-linked-meta code {
    background: #20242c;
  }

  .cell:hover { background: #1c2330; }
  .cell-edit:hover,
  .shopping-edit-icon:hover { background: #20242c; }

  /* Filled accent/danger controls need readable text on the lighter dark accent. */
  .button, button { color: #0b1220; }
  .button.secondary, button.secondary { color: var(--accent); }
  .servings-badge { color: #0b1220; }
  button.danger,
  .badge-special { background: #dc2626; color: #fff; border-color: #dc2626; }

  /* Native form controls + scrollbars follow the dark scheme. */
  input, select, textarea { background: var(--card); color: var(--fg); }

  /* Amber "notes" panels. */
  .recipe-notes,
  .recipe-scaled-notice {
    background: #2a2410; border-left-color: #d39b1a; color: #f0d9a0;
  }
  .recipe-servings-form { background: #14241a; }
  .original-panel { background: #241f15; border-left-color: #8a7a4a; }

  /* In-stock collapsible. */
  .shopping-instock-group > summary { background: #16191e; }
  .shopping-instock-group > summary:hover { background: #1c2027; }
  .shopping-instock-group .instock-count { color: var(--fg); }

  /* Semantic badges: green / amber / red. */
  .woolies-auth-banner.banner-valid,
  .bridge-status.bridge-connected {
    background: #0f2a1e; color: #6ee7b7; border-color: #14532d;
  }
  .woolies-auth-banner.banner-expired,
  .woolies-auth-banner.banner-missing,
  .woolies-auth-banner.banner-corrupt,
  .push-counts li.warn,
  .shopping-thumb-unmapped {
    background: #2a230f; color: #fcd34d; border-color: #5a4a14;
  }
  .bridge-status.bridge-disconnected {
    background: #2a1416; color: #fca5a5; border-color: #5a1d1d;
  }
  .push-result.push-error { background: #2a1416; }

  /* Source-link underline visible on dark. */
  .shopping-sources .src-title { text-decoration-color: rgba(255, 255, 255, 0.25); }
}

/* --- Sign-in page --- */
.auth-card {
  max-width: 420px;
  margin: 64px auto;
  text-align: center;
}
.auth-card h1 { margin-top: 0; }
.auth-error {
  background: #fef2f2; color: #991b1b; border: 1px solid #fca5a5;
  border-radius: 6px; padding: 8px 12px; font-size: 0.9em;
}
.auth-gh {
  display: inline-flex; align-items: center; gap: 8px;
  margin-top: 8px; text-decoration: none;
}
.auth-gh:hover { text-decoration: none; }
@media (prefers-color-scheme: dark) {
  .auth-error { background: #2a1416; color: #fca5a5; border-color: #5a1d1d; }
}

.nav-signout { margin-left: auto; color: var(--muted); }
