/* ==========================================================================
   Design tokens. Modeled on claude.ai's own look: a tight, neutral,
   icon-first sidebar that follows the light/dark theme like everything
   else (no bold brand-color panel). Theme is applied as
   data-theme="light|dark" on <html> by an inline script in base.html's
   <head> (runs before paint, no flash) plus js/theme_toggle.js for the
   toggle button itself.
   ========================================================================== */

:root, [data-theme="light"] {
  --bg: #f5f7f6;
  --surface: #ffffff;
  --surface-2: #eef2f0;
  --border: #e1e7e3;
  --text: #171a18;
  --text-muted: #666f6a;
  --primary: #0b8f5f;
  --primary-hover: #077249;
  --primary-contrast: #ffffff;
  --accent-soft: #e6f6ee;
  --danger: #c8382c;
  --danger-soft: #fbe9e7;
  --warning: #96650a;
  --warning-soft: #fdf1dc;
  --info: #1f5fa8;
  --info-soft: #e7f0fc;
  --success: #187a3d;
  --success-soft: #e5f6ea;
  --shadow-sm: 0 1px 2px rgba(20, 25, 22, 0.06), 0 1px 1px rgba(20, 25, 22, 0.04);
  --shadow-md: 0 8px 24px rgba(20, 25, 22, 0.10);
  --focus-ring: 0 0 0 3px rgba(11, 143, 95, 0.25);

  --sidebar-bg: #faf9f6;
  --sidebar-border: #e6e4dc;
  --sidebar-text: #3d3d3a;
  --sidebar-text-muted: #8a887f;
  --sidebar-hover: rgba(0, 0, 0, 0.055);
  --sidebar-active: rgba(0, 0, 0, 0.09);
}

[data-theme="dark"] {
  --bg: #14181a;
  --surface: #1b2023;
  --surface-2: #21272a;
  --border: #2c3336;
  --text: #eaeeec;
  --text-muted: #98a29c;
  --primary: #29c98a;
  --primary-hover: #3fdb9b;
  --primary-contrast: #06140e;
  --accent-soft: rgba(41, 201, 138, 0.14);
  --danger: #f0776d;
  --danger-soft: rgba(240, 119, 109, 0.14);
  --warning: #e3ac4c;
  --warning-soft: rgba(227, 172, 76, 0.14);
  --info: #7cabe6;
  --info-soft: rgba(124, 171, 230, 0.14);
  --success: #57cf85;
  --success-soft: rgba(87, 207, 133, 0.14);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.4);
  --focus-ring: 0 0 0 3px rgba(41, 201, 138, 0.3);

  --sidebar-bg: #1f1e1c;
  --sidebar-border: rgba(255, 255, 255, 0.08);
  --sidebar-text: #e8e6e0;
  --sidebar-text-muted: #96948b;
  --sidebar-hover: rgba(255, 255, 255, 0.06);
  --sidebar-active: rgba(255, 255, 255, 0.1);
}

* { box-sizing: border-box; }

html { color-scheme: light dark; }

body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  transition: background-color 0.15s ease, color 0.15s ease;
}

/* ==========================================================================
   App shell: a wide, always-expanded, grouped nav rail modeled on
   platform.claude.com's console sidebar -- icon+label rows, muted
   uppercase group labels, a soft rounded pill for the active link,
   instead of the old icon-only hover-flyout rail.
   ========================================================================== */

.app-shell {
  display: flex;
  min-height: 100vh;
  align-items: stretch;
}

.sidebar {
  width: 248px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 0;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1rem 0.75rem;
  flex-shrink: 0;
}

.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--text);
  text-decoration: none;
}
.sidebar .brand svg { color: var(--primary); flex-shrink: 0; }
.brand-name { font-size: 0.95rem; font-weight: 650; letter-spacing: -0.01em; }

.sidebar-close, .sidebar-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: none;
  background: none;
  color: var(--sidebar-text-muted);
  cursor: pointer;
  padding: 0;
}
.sidebar-close:hover, .sidebar-toggle:hover { background: var(--sidebar-hover); color: var(--sidebar-text); }

.sidebar-scrim { display: none; }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 0.25rem 0.75rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.nav-group { display: flex; flex-direction: column; }

.nav-group summary {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--sidebar-text);
  font-weight: 650;
  padding: 0.4rem 0.6rem;
  border-radius: 8px;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.nav-group summary::-webkit-details-marker,
.nav-group summary::marker { display: none; content: ""; }
.nav-group summary:hover { background: var(--sidebar-hover); }
.nav-group summary svg:first-child { flex-shrink: 0; opacity: 0.85; color: var(--sidebar-text-muted); }
.nav-group summary svg:last-child {
  margin-left: auto;
  flex-shrink: 0;
  color: var(--sidebar-text-muted);
  transition: transform 0.15s ease;
}
.nav-group[open] summary svg:last-child { transform: rotate(90deg); }

.nav-group-links {
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
  padding: 0.15rem 0 0.4rem 0.9rem;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.87rem;
  font-weight: 480;
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  white-space: nowrap;
}
.nav-link svg { flex-shrink: 0; opacity: 0.75; color: var(--sidebar-text-muted); }
.nav-link:hover { background: var(--sidebar-hover); }
.nav-link.active {
  background: var(--sidebar-active);
  color: var(--text);
  font-weight: 620;
}
.nav-link.active svg { opacity: 1; color: var(--primary); }

.sidebar-footer {
  flex-shrink: 0;
  margin-top: auto;
  padding: 0.6rem 0.75rem;
  border-top: 1px solid var(--sidebar-border);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.sidebar-account {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex: 1;
  min-width: 0;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 550;
  padding: 0.4rem 0.55rem;
  border-radius: 8px;
}
.sidebar-account span { overflow: hidden; text-overflow: ellipsis; }
.sidebar-account svg { flex-shrink: 0; color: var(--sidebar-text-muted); }
.sidebar-account:hover, .sidebar-account.active { background: var(--sidebar-hover); }

.sidebar-footer .link-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  color: var(--sidebar-text-muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}
.sidebar-footer .link-button:hover { color: var(--sidebar-text); background: var(--sidebar-hover); }

.content-area {
  flex: 1;
  min-width: 0;
}

main {
  padding: 2rem 2.5rem;
  max-width: 960px;
  margin: 0 auto;
}

main.wide { max-width: 1220px; }

/* ==========================================================================
   Typography / layout basics
   ========================================================================== */

.flashes { list-style: none; padding: 0; margin: 0 0 1.5rem; }

.flash {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 1rem;
  border-radius: 8px;
  margin-bottom: 0.5rem;
  font-size: 0.92rem;
  border: 1px solid transparent;
}
.flash-success { background: var(--success-soft); color: var(--success); }
.flash-error { background: var(--danger-soft); color: var(--danger); }
.flash-warning { background: var(--warning-soft); color: var(--warning); }
.flash-info { background: var(--info-soft); color: var(--info); }

.flash-dismiss {
  background: none;
  border: none;
  color: inherit;
  font-size: 1.2rem;
  line-height: 1;
  padding: 0 0.15rem;
  cursor: pointer;
  opacity: 0.6;
}
.flash-dismiss:hover { opacity: 1; }

h1 {
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0 0 1.25rem;
}
h2 {
  font-size: 1.15rem;
  font-weight: 700;
  margin-top: 2.25rem;
  margin-bottom: 0.85rem;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.section-heading h1, .section-heading h2 { margin: 0; }

a { color: var(--primary); }

/* ==========================================================================
   Tables — real borders, a proper header treatment, sortable affordance.
   ========================================================================== */

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow-x: auto;
  overflow-y: hidden;
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.75rem;
}

table { width: 100%; border-collapse: collapse; }

th, td {
  text-align: left;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface-2); }

/* Pins the "got it" checkbox + delete-button columns to the right edge of
   a horizontally-scrolling table (Cooking/Costco shopping lists) so they
   stay fully visible and tappable no matter how wide the row's other
   content gets (long item names, several sale-price tags, etc) instead of
   being scrolled/truncated off the visible edge -- the whole point of
   this checkbox is checking things off while walking around a store. */
.col-pin-check, .col-pin-delete {
  position: sticky;
  background: var(--surface);
  z-index: 1;
}
.col-pin-check { right: 2.5rem; }
.col-pin-delete { right: 0; }
th.col-pin-check, th.col-pin-delete { background: var(--surface-2); }
tbody tr:hover td.col-pin-check, tbody tr:hover td.col-pin-delete { background: var(--surface-2); }

th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--surface-2);
}

table.sortable th { cursor: pointer; user-select: none; white-space: nowrap; }
table.sortable th:hover { color: var(--primary); }
.th-tip { border-bottom: 1px dotted var(--text-muted); cursor: help; }
table.sortable th .sort-arrow { font-size: 0.7em; color: var(--text-muted); margin-left: 0.35em; }
table.sortable th.sorted-asc .sort-arrow::after { content: "\25B2"; color: var(--primary); }
table.sortable th.sorted-desc .sort-arrow::after { content: "\25BC"; color: var(--primary); }
table.sortable th:not(.sorted-asc):not(.sorted-desc) .sort-arrow::after { content: "\25B4\25BE"; }

/* Filter box shown above a table (data-filter-for="<table-id>") */
.table-filter {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px 10px 0 0;
  border-bottom: none;
  padding: 0.6rem 0.85rem;
  color: var(--text-muted);
}
.table-filter input {
  border: none;
  background: none;
  padding: 0.2rem 0;
  font-size: 0.92rem;
  color: var(--text);
}
.table-filter input:focus { outline: none; box-shadow: none; }
.table-filter + .table-wrap { border-top-left-radius: 0; border-top-right-radius: 0; margin-top: -1px; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Bulk-action bar (e.g. inventory's "N selected · Move to...") -- hidden
   via the `hidden` attribute until at least one row checkbox is checked. */
.bulk-move-bar {
  position: sticky;
  top: 0.75rem;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--primary);
  border-radius: 10px;
  padding: 0.6rem 0.85rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-md);
}
.bulk-move-bar select { width: auto; flex: 1; max-width: 220px; }
.bulk-move-bar .btn { margin: 0; }

/* ==========================================================================
   Cards
   ========================================================================== */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow-sm);
}

.card-title { font-weight: 700; margin-bottom: 0.35rem; }
.card-meta { color: var(--text-muted); font-size: 0.85rem; }

/* ==========================================================================
   Forms
   ========================================================================== */

form.inline { display: inline; }

label { display: block; margin: 1rem 0 0.3rem; font-size: 0.88rem; font-weight: 600; color: var(--text); }

input[type=text], input[type=number], input[type=date], input[type=email],
input[type=password], select, textarea {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  transition: box-shadow 0.12s ease, border-color 0.12s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
}
textarea { min-height: 6rem; }

/* Password fields with a press-and-hold "show password" icon button
   (see js/password_reveal.js) -- the icon overlaps the input's right
   padding rather than sitting beside it, so the field keeps the same
   width as every other input on the form. */
.password-field { position: relative; }
.password-field input { padding-right: 2.5rem; }
.password-field .password-toggle {
  position: absolute;
  right: 0.35rem;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.35rem;
  border: none;
  border-radius: 6px;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
}
.password-field .password-toggle:hover { color: var(--text); background: var(--surface-2); }

/* No spinner arrows on number inputs -- this app has no fields where
   incrementing by one via a tiny click target is actually useful. */
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; appearance: textfield; }

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1.05rem;
  border-radius: 8px;
  border: 1px solid var(--primary);
  background: var(--primary);
  color: var(--primary-contrast);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  margin: 0.2rem 0.4rem 0.2rem 0;
  transition: background-color 0.12s ease, transform 0.05s ease;
}
.btn:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn:active { transform: translateY(1px); }
.btn.secondary { background: var(--surface); color: var(--primary); border-color: var(--border); }
.btn.secondary:hover { background: var(--surface-2); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }

/* Round icon-only buttons (edit/delete/add/etc.) */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  text-decoration: none;
  padding: 0;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }
.icon-btn.primary { background: var(--primary); color: var(--primary-contrast); }
.icon-btn.primary:hover { background: var(--primary-hover); }

.icon-btn-add {
  width: 1.9rem;
  height: 1.9rem;
  border-radius: 999px;
  background: var(--primary);
  color: var(--primary-contrast);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  flex-shrink: 0;
}
.icon-btn-add:hover { background: var(--primary-hover); }

.row-actions { display: flex; gap: 0.3rem; align-items: center; }

.link-button {
  background: none;
  border: none;
  cursor: pointer;
  font: inherit;
  color: inherit;
  padding: 0;
}

/* ==========================================================================
   Misc small components
   ========================================================================== */

.ingredient-row, .dynamic-row {
  display: grid;
  grid-template-columns: 2fr 1fr 2fr auto;
  gap: 0.6rem;
  align-items: center;
  margin-bottom: 0.6rem;
}

.tag {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--primary);
  border-radius: 999px;
  padding: 0.18rem 0.6rem;
  font-size: 0.78rem;
  margin: 0 0.3rem 0.3rem 0;
  font-weight: 600;
  white-space: nowrap;
}
.tag.danger { background: var(--danger-soft); color: var(--danger); }
.tag.warning { background: var(--warning-soft); color: var(--warning); }
.tag.success { background: var(--success-soft); color: var(--success); }

/* Small lettered badges linking to a store's current flyer (home page,
   next to "Shopping List") -- one per tracked store, each store gets its
   own color purely so the three read as distinct at a glance. */
.store-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  border-radius: 50%;
  font-size: 0.7rem;
  font-weight: 700;
  color: #ffffff;
  text-decoration: none;
}
.store-badge:hover { opacity: 0.85; }
.store-badge-freshco { background: #16a34a; }
.store-badge-metro { background: #dc2626; }
.store-badge-loblaws { background: #f59e0b; }

.audible { color: var(--danger); font-weight: 600; }

/* Read-only 1-5 star display (recipes, eat-out places) */
.star-display { letter-spacing: 1px; }
.star-filled { color: var(--warning); }
.star-empty { color: var(--border); }

/* Clickable 1-5 star form input -- radios rendered 5..1 in DOM order,
   displayed 1..5 via row-reverse, so the ~ sibling selector can light up
   "this star and everything before it" with pure CSS. */
.star-rating-input {
  display: inline-flex;
  flex-direction: row-reverse;
  gap: 0.1rem;
}
.star-rating-input input { position: absolute; opacity: 0; width: 0; height: 0; }
.star-rating-input label {
  font-size: 1.6rem;
  line-height: 1;
  color: var(--border);
  cursor: pointer;
  margin: 0;
  padding: 0 0.05rem;
}
.star-rating-input input:checked ~ label,
.star-rating-input label:hover,
.star-rating-input label:hover ~ label {
  color: var(--warning);
}

/* Breadcrumb trail at the top of every page */
.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.breadcrumbs a { color: var(--text-muted); text-decoration: none; }
.breadcrumbs a:hover { color: var(--primary); text-decoration: underline; }
.breadcrumbs .crumb-current { color: var(--text); font-weight: 600; }

/* A row of cards/entries grouped under a sub-heading (recipe protein
   sections, honey-do lists, etc) */
.list-section { margin-top: 1.75rem; }
.list-section h2 { margin-top: 0; }

.day-card { display: flex; justify-content: space-between; align-items: center; gap: 1.25rem; }

.grocery-item.checked { text-decoration: line-through; opacity: 0.6; }

/* --------------------------------------------------------------------- */
/* Weekly meal table + lightbox dialogs (meal add/edit, inventory add/edit) */

.meal-table tr[data-day-offset] td:first-child { white-space: nowrap; }
.meal-table .meal-empty { color: var(--text-muted); font-style: italic; }

dialog {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.5rem;
  width: min(420px, 92vw);
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow-md);
}
dialog::backdrop { background: rgba(15, 18, 16, 0.45); }
dialog h2 { margin: 0 0 1rem; font-size: 1.05rem; }

.info-icon {
  display: inline-flex;
  vertical-align: middle;
  color: var(--text-muted);
  cursor: help;
  margin-left: 0.3rem;
}

.meal-mode-toggle {
  display: flex;
  gap: 1.25rem;
  margin-bottom: 0.75rem;
  font-size: 0.88rem;
}
.meal-mode-toggle label { display: flex; align-items: center; gap: 0.4rem; font-weight: 500; margin: 0; }
.meal-mode-toggle input { width: auto; }

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1.25rem;
}

/* --------------------------------------------------------------------- */
/* Drag-and-drop (menus: dragging a day's meal onto another day) */

.drop-target { transition: background-color 0.15s, border-color 0.15s; border-radius: 10px; }
.drop-target.drag-over { background-color: var(--accent-soft) !important; }
.drop-target.drag-source-active { opacity: 0.4; }

th.drag-over { background: var(--accent-soft); }
th.drag-source-active { opacity: 0.4; }

[draggable="true"] { cursor: grab; }

.drag-handle {
  display: inline-flex;
  color: var(--text-muted);
  margin-right: 0.35rem;
  cursor: grab;
  font-weight: 700;
}
.drag-handle:active { cursor: grabbing; }

/* ==========================================================================
   Tabs + compact field grid (Retirement: Assumptions)
   ========================================================================== */

.tabs {
  display: flex;
  gap: 0.15rem;
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
}
.tab-btn {
  padding: 0.6rem 0.8rem;
  border: none;
  background: none;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  flex-shrink: 0;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  text-decoration: none;
  display: inline-block;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }
.tab-panel-title { font-size: 1.15rem; margin: 0 0 0.3rem; }

.field-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.9rem 1rem;
}
.field-group {
  display: flex;
  flex-direction: column;
  flex: 0 1 90px;
}
.field-group label { margin: 0 0 0.3rem; white-space: nowrap; font-size: 0.82rem; }
.field-group input { width: 100%; padding: 0.45rem 0.5rem; }

/* Flex items default to min-width:auto, which means a long label with
   white-space:nowrap (e.g. "Contribution while working, per year") was
   overriding the 90px flex-basis and forcing the whole box wide, no
   matter how short the value inside actually is. flex-basis:auto lets
   each box size to its own label's natural width (so most labels show
   in full, no ellipsis) up to max-width, beyond which it truncates with
   an ellipsis instead of wrapping or overflowing into the next field
   (hover/focus for the full text via its title attribute) -- only the
   genuinely long labels hit that cap, instead of every label being cut
   by 1-2 characters against a fixed 90px box. min-width still lets it
   shrink below either when space is tight. Scoped to .field-grid
   (Assumptions/Expenses/Quick adjust) so Net Worth History's grid-based
   layout -- which doesn't have this problem -- is untouched. */
.field-grid .field-group { flex: 0 1 auto; min-width: 70px; max-width: 170px; }
.field-grid .field-group label { overflow: hidden; text-overflow: ellipsis; }
.field-grid .field-group input { text-align: center; }

/* A tighter grid variant for short "$xxx,xxx"-sized fields (Net Worth
   History's weekly entry form) -- a fixed 9-column grid instead of
   flex-wrap, so column N always lines up under column N on every row.
   Date spans columns 1-2; Business Corp/RESP/Notes are pinned to columns
   3/4/5 (under TFSA-Tim/TFSA-Amanda/onward) so they wrap onto row 2
   directly beneath the right fields instead of beneath Date. */
.field-grid-tight {
  display: grid;
  grid-template-columns: repeat(9, minmax(90px, 1fr));
  gap: 0.9rem 1rem;
}
.field-grid-tight .field-group.wide { grid-column: span 2; }
.field-grid-tight .field-group.gc-3 { grid-column: 3; }
.field-grid-tight .field-group.gc-4 { grid-column: 4; }
.field-grid-tight .field-group.gc-notes { grid-column: 5 / -1; }

@media (max-width: 900px) {
  .field-grid-tight { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
  .field-grid-tight .field-group.gc-3,
  .field-grid-tight .field-group.gc-4,
  .field-grid-tight .field-group.gc-notes { grid-column: auto; }
}

.currency-input { text-align: right; font-variant-numeric: tabular-nums; }

.text-good { color: var(--success); }
.text-bad { color: var(--danger); }
.nowrap { white-space: nowrap; }

/* ==========================================================================
   Stat tiles + Retirement chart
   ========================================================================== */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.15rem;
}
.stat-label { color: var(--text-muted); font-size: 0.82rem; font-weight: 600; }
.stat-value { font-size: 1.6rem; font-weight: 700; margin-top: 0.2rem; }
.stat-sub { color: var(--text-muted); font-size: 0.8rem; margin-top: 0.15rem; }
.stat-tile.status-good .stat-value { color: var(--success); }
.stat-tile.status-bad .stat-value { color: var(--danger); }

/* Home page tiles -- indented sub-item links, same treatment as the
   sidebar's nav-group-links, single line each (no wrap onto a second
   line for longer labels like "Shopping List History"). */
.home-tile-links {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.75rem;
  padding-left: 0.9rem;
}
.home-tile-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
}
.home-tile-link svg { flex-shrink: 0; opacity: 0.75; color: var(--text-muted); }

/* Wider minimum than the default .stat-grid (200px) -- at 200px, longer
   single-line labels like "Shopping List History" don't fit and spill
   past the card's edge. */
.home-tile-grid { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }

.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 1.25rem; margin-bottom: 1.5rem; }
.chart-card svg { width: 100%; height: auto; display: block; }
.chart-gridline { stroke: var(--border); stroke-width: 1; }
.chart-zeroline { stroke: var(--text-muted); stroke-width: 1; }
.chart-line { fill: none; stroke: var(--primary); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chart-area { fill: var(--primary); opacity: 0.1; }
.chart-marker { stroke: var(--text-muted); stroke-width: 1; stroke-dasharray: 4 3; }
.chart-tick { fill: var(--text-muted); font-size: 10px; }
.chart-endlabel { fill: var(--text); font-size: 11px; font-weight: 600; }
.chart-marker-label { fill: var(--text-muted); font-size: 10px; }
.chart-hover-dot { fill: transparent; }
.chart-hover-dot:hover { fill: var(--primary); fill-opacity: 0.25; }

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 900px) {
  .app-shell { position: relative; }

  .sidebar-toggle {
    display: flex;
    position: fixed;
    top: 0.6rem;
    left: 0.6rem;
    z-index: 50;
    background: var(--sidebar-bg);
    border: 1px solid var(--sidebar-border);
  }
  .sidebar-close { display: flex; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 70;
    width: 260px;
    max-width: 82vw;
    transform: translateX(-100%);
    transition: transform 0.18s ease;
    box-shadow: var(--shadow-md);
  }
  .sidebar.open { transform: translateX(0); }

  .sidebar-scrim {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 65;
  }
  .sidebar.open ~ .sidebar-scrim,
  .sidebar-toggle[aria-expanded="true"] ~ .sidebar-scrim {
    display: block;
  }

  main { padding: 1.25rem 1.25rem 1.25rem 1.25rem; padding-top: 3.5rem; }
}

@media (max-width: 640px) {
  .ingredient-row, .dynamic-row { grid-template-columns: 1fr 1fr; }
  th, td { font-size: 0.85rem; padding: 0.6rem 0.5rem; }

  /* Cooking Shopping List: Store/Used in/Substitute are nice-to-have but
     push the table wider than a phone screen, shoving the "got it"
     checkbox and delete button off the visible edge -- drop them on
     narrow screens so the checkbox stays reachable without scrolling. */
  .hide-narrow { display: none; }

  .grocery-check { width: 1.6rem !important; height: 1.6rem; flex-shrink: 0; }
  .grocery-item { padding: 0.85rem 1rem; }
  .day-card { flex-direction: column; align-items: flex-start; }
  .btn { padding: 0.65rem 1.1rem; }
}
