:root {
  --bs-primary: #10b981;
  --bs-primary-rgb: 16, 185, 129;
  --bs-body-bg: #f8fafc;
  --bs-body-color: #1e293b;
  --bs-body-font-family: 'Inter', system-ui, -apple-system, sans-serif;
  --bs-secondary: #64748b;
  --bs-secondary-rgb: 100, 116, 139;
  --bs-success: #10b981;
  --bs-success-rgb: 16, 185, 129;
  --bs-info: #3b82f6;
  --bs-info-rgb: 59, 130, 246;
  --bs-warning: #f59e0b;
  --bs-warning-rgb: 245, 158, 11;
  --bs-danger: #ef4444;
  --bs-danger-rgb: 239, 68, 68;
  --bs-link-color: #10b981;
  --bs-link-hover-color: #059669;
  --bs-border-color: #e2e8f0;
  --bs-border-radius: 0.5rem;
  --bs-border-radius-sm: 0.375rem;
  --bs-border-radius-lg: 0.75rem;
  --bs-card-bg: #ffffff;
  --bs-card-border-color: #e2e8f0;
  --bs-card-border-radius: 0.75rem;
  --bs-card-cap-padding-y: 0.875rem;
  --bs-card-cap-padding-x: 1.25rem;
  --bs-box-shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.06);
  --bs-box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.08), 0 1px 2px -1px rgba(0, 0, 0, 0.06);
  --sidebar-bg: #f8fafc;
  --sidebar-color: #1e293b;
  --sidebar-border: #e2e8f0;
  --sidebar-link-active-bg: #10b981;
  --sidebar-link-active-color: #ffffff;
  --sidebar-link-hover-bg: #f1f5f9;
  --sidebar-width: 260px;
  --sidebar-collapsed-width: 0px;
  --bottom-nav-bg: #ffffff;
  --bottom-nav-border: #e2e8f0;
  --bottom-nav-active: #10b981;
  --bottom-nav-inactive: #94a3b8;
}

[data-bs-theme="dark"] {
  --bs-body-bg: #0f172a;
  --bs-body-color: #e2e8f0;
  --bs-primary: #10b981;
  --bs-primary-rgb: 16, 185, 129;
  --bs-secondary: #475569;
  --bs-secondary-rgb: 71, 85, 105;
  --bs-border-color: #1e293b;
  --bs-card-bg: #1e293b;
  --bs-card-border-color: #334155;
  --bs-link-color: #34d399;
  --bs-link-hover-color: #6ee7b7;
  --bs-tertiary-bg: #1e293b;
  --bs-box-shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.4);
  --bs-box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.5), 0 1px 2px -1px rgba(0, 0, 0, 0.4);
  --sidebar-bg: #0f172a;
  --sidebar-color: #e2e8f0;
  --sidebar-border: #1e293b;
  --sidebar-link-active-bg: #10b981;
  --sidebar-link-active-color: #ffffff;
  --sidebar-link-hover-bg: #1e293b;
  --bottom-nav-bg: #1e293b;
  --bottom-nav-border: #334155;
  --bottom-nav-active: #34d399;
  --bottom-nav-inactive: #64748b;
  --bs-light: #1e293b;
  --bs-light-rgb: 30, 41, 59;
  --bs-dark: #e2e8f0;
  --bs-dark-rgb: 226, 232, 240;
}

[data-bs-theme="dark"] .bg-light {
  background-color: #1e293b !important;
}
[data-bs-theme="dark"] .bg-dark {
  background-color: #0f172a !important;
}
[data-bs-theme="dark"] .text-muted {
  color: #94a3b8 !important;
}
[data-bs-theme="dark"] .table {
  --bs-table-bg: transparent;
  --bs-table-hover-bg: rgba(255, 255, 255, 0.04);
  color: #e2e8f0;
}
[data-bs-theme="dark"] .table thead.bg-light {
  background-color: #0f172a !important;
}
[data-bs-theme="dark"] .form-control,
[data-bs-theme="dark"] .form-select {
  background-color: #0f172a;
  border-color: #334155;
  color: #e2e8f0;
}
[data-bs-theme="dark"] .dropdown-menu {
  background-color: #1e293b;
  border-color: #334155;
}
[data-bs-theme="dark"] .dropdown-item {
  color: #e2e8f0;
}
[data-bs-theme="dark"] .dropdown-item:hover {
  background-color: #334155;
  color: #ffffff;
}
[data-bs-theme="dark"] .modal-content {
  background-color: #1e293b;
  border-color: #334155;
}
[data-bs-theme="dark"] .card-header {
  border-bottom-color: #334155;
}
[data-bs-theme="dark"] .alert {
  --bs-alert-bg: #1e293b;
}

html {
  overflow-x: hidden;
}

body {
  font-family: var(--bs-body-font-family);
  letter-spacing: -0.01em;
  overflow-x: hidden;
}

.min-w-0 {
  min-width: 0 !important;
}

[x-cloak] { display: none !important; }

.card {
  border: 1px solid var(--bs-card-border-color);
  border-radius: var(--bs-card-border-radius);
  box-shadow: var(--bs-box-shadow-sm);
  overflow: hidden;
}
.card-header {
  border-bottom: 1px solid var(--bs-card-border-color);
}

.bg-primary, .btn-primary {
  background-color: var(--bs-primary) !important;
  border-color: var(--bs-primary) !important;
}
.btn-primary:hover {
  background-color: #059669 !important;
  border-color: #059669 !important;
}
.btn-outline-primary {
  color: var(--bs-primary);
  border-color: var(--bs-primary);
}
.btn-outline-primary:hover,
.btn-outline-primary.active {
  background-color: var(--bs-primary);
  border-color: var(--bs-primary);
  color: #fff;
}
.text-primary {
  color: var(--bs-primary) !important;
}

.progress {
  border-radius: 9999px;
  background-color: var(--bs-border-color);
}
.progress-bar.bg-primary,
.progress-bar:not([class*="bg-"]) {
  background-color: var(--bs-primary) !important;
}

.btn {
  border-radius: var(--bs-border-radius);
  font-weight: 500;
  transition: all 0.15s ease-in-out;
}
.btn-sm {
  border-radius: var(--bs-border-radius-sm);
}

.form-control, .form-select {
  border-radius: var(--bs-border-radius);
  border-color: var(--bs-border-color);
}
.form-control:focus, .form-select:focus {
  border-color: var(--bs-primary);
  box-shadow: 0 0 0 0.2rem rgba(var(--bs-primary-rgb), 0.25);
}

.badge {
  border-radius: 9999px;
  font-weight: 500;
  letter-spacing: 0.01em;
}

.alert {
  border-radius: var(--bs-border-radius-lg);
}

.app-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  z-index: 1040;
  transition: transform 0.3s ease;
}
.app-sidebar .sidebar-brand {
  padding: 1.25rem 1.25rem 0.75rem;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--bs-primary);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.app-sidebar .sidebar-nav {
  flex: 1;
  padding: 0.5rem 0.75rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.app-sidebar .sidebar-nav .nav-item {
  margin-bottom: 2px;
}
.app-sidebar .sidebar-nav .nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 0.875rem;
  border-radius: var(--bs-border-radius);
  color: var(--sidebar-color);
  font-weight: 500;
  font-size: 0.9rem;
  text-decoration: none;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.app-sidebar .sidebar-nav .nav-link:hover {
  background-color: var(--sidebar-link-hover-bg);
}
.app-sidebar .sidebar-nav .nav-link.active {
  background-color: var(--sidebar-link-active-bg);
  color: var(--sidebar-link-active-color);
}
.app-sidebar .sidebar-nav .nav-link i {
  font-size: 1.1rem;
  width: 1.25rem;
  text-align: center;
}
.app-sidebar .sidebar-footer {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--sidebar-border);
}
.sidebar-footer-links {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  font-size: 0.7rem;
  margin-top: auto;
  padding: 0.75rem 0.875rem 0.25rem;
}
.sidebar-footer-links a {
  color: var(--bs-secondary-color);
  text-decoration: none;
}
.sidebar-footer-links a:hover {
  color: var(--bs-primary);
}
.sidebar-footer-links span {
  color: var(--bs-secondary-color);
}

.app-main {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  transition: margin-left 0.3s ease;
}
.app-content {
  max-width: 80rem;
  margin: 0 auto;
  padding: 1.5rem 1.5rem;
}
@media (max-width: 575.98px) {
  .app-content { padding: 1rem; }
}

.app-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: var(--bs-card-bg);
  border-bottom: 1px solid var(--bs-border-color);
  position: sticky;
  top: 0;
  z-index: 1030;
}

@media (max-width: 991.98px) {
  .app-sidebar {
    transform: translateX(-100%);
  }
  .app-sidebar.show {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
  }
  .app-main {
    margin-left: 0;
    padding-bottom: 5rem;
  }
  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 1039;
    display: none;
  }
  .sidebar-overlay.show {
    display: block;
  }
}

.app-bottom-nav {
  display: none;
}
@media (max-width: 991.98px) {
  .app-bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bottom-nav-bg);
    border-top: 1px solid var(--bottom-nav-border);
    z-index: 1050;
    padding: 0.375rem 0;
    justify-content: space-around;
    align-items: center;
  }
  .app-bottom-nav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.125rem;
    padding: 0.25rem 0.75rem;
    text-decoration: none;
    color: var(--bottom-nav-inactive);
    font-size: 0.65rem;
    font-weight: 500;
    transition: color 0.15s ease;
  }
  .app-bottom-nav a i {
    font-size: 1.25rem;
  }
  .app-bottom-nav a.active {
    color: var(--bottom-nav-active);
  }
  .app-bottom-nav a:hover {
    color: var(--bottom-nav-active);
  }
}

.topbar-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.25rem;
  color: var(--bs-body-color);
  padding: 0.25rem 0.5rem;
  cursor: pointer;
}
@media (max-width: 991.98px) {
  .topbar-toggle {
    display: inline-flex;
  }
}

.dark-mode-toggle {
  background: none;
  border: 1px solid var(--bs-border-color);
  border-radius: var(--bs-border-radius);
  padding: 0.375rem 0.625rem;
  color: var(--bs-body-color);
  cursor: pointer;
  font-size: 1rem;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
}
.dark-mode-toggle:hover {
  background-color: var(--sidebar-link-hover-bg);
}

.toast-container-custom {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 1090;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}
@media (max-width: 991.98px) {
  .toast-container-custom {
    bottom: 5.5rem;
    left: 1rem;
    right: 1rem;
  }
}
.toast-item {
  pointer-events: auto;
  padding: 0.75rem 1rem;
  border-radius: var(--bs-border-radius-lg);
  box-shadow: var(--bs-box-shadow);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  animation: toast-slide-in 0.3s ease-out;
}
.toast-item.toast-success {
  background-color: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}
.toast-item.toast-error {
  background-color: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}
.toast-item.toast-info {
  background-color: #eff6ff;
  color: #1e40af;
  border: 1px solid #bfdbfe;
}
[data-bs-theme="dark"] .toast-item.toast-success {
  background-color: #064e3b;
  color: #a7f3d0;
  border-color: #065f46;
}
[data-bs-theme="dark"] .toast-item.toast-error {
  background-color: #7f1d1d;
  color: #fecaca;
  border-color: #991b1b;
}
[data-bs-theme="dark"] .toast-item.toast-info {
  background-color: #1e3a5f;
  color: #bfdbfe;
  border-color: #1e40af;
}
.toast-item.toast-leaving {
  animation: toast-slide-out 0.2s ease-in forwards;
}
@keyframes toast-slide-in {
  from { opacity: 0; transform: translateY(1rem); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes toast-slide-out {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(1rem); }
}

.macro-ring-container {
  display: flex;
  align-items: center;
  justify-content: center;
}
.macro-ring-container svg {
  transform: rotate(-90deg);
}
.macro-ring-track {
  fill: none;
  stroke: var(--bs-border-color);
}
.macro-ring-fill {
  fill: none;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.6s ease;
}
.macro-ring-label {
  text-anchor: middle;
  dominant-baseline: central;
  font-weight: 600;
  fill: var(--bs-body-color);
}

.macro-arch-container {
  display: flex;
  align-items: center;
  justify-content: center;
}
.macro-arch-svg {
  width: 100%;
  height: auto;
}
.macro-arch-value {
  text-anchor: middle;
  font-weight: 700;
  font-size: 2rem;
  fill: var(--bs-body-color);
}
.macro-arch-unit {
  text-anchor: middle;
  font-size: 0.8rem;
  fill: var(--bs-secondary-color, #6c757d);
}

.beta-banner {
  background-color: var(--bs-warning);
  color: #000;
  text-align: center;
  font-weight: 600;
  padding: 0.375rem 0;
  font-size: 0.8rem;
}
[data-bs-theme="dark"] .beta-banner {
  background-color: #92400e;
  color: #fef3c7;
}

.app-footer {
  padding: 1rem 0;
  text-align: center;
  font-size: 0.75rem;
  color: var(--bs-secondary-color);
}

.app-footer a {
  margin-left: 0.75rem;
  color: var(--bs-secondary-color);
  text-decoration: none;
}

.app-footer a:hover {
  color: var(--bs-primary);
}


/* ---------------------------------------------------------------------------
   This Week (weekly allocator)

   A phone reads this page far more often than a desktop does, so the day list
   is cards first and a table only where there is room for eight columns. Tones
   come from the allocator's own `fuel_priority`, so the colour of a day never
   disagrees with the deficit it was given.
   --------------------------------------------------------------------------- */
.week-page {
  --tone-rest: #94a3b8;
  --tone-easy: #3b82f6;
  --tone-moderate: #f59e0b;
  --tone-key: #10b981;
  /* The fill colours are too light to read as text on a pale chip, so labels get
     their own darker pair, flipped for the dark theme. */
  --tone-rest-text: #475569;
  --tone-easy-text: #1d4ed8;
  --tone-moderate-text: #b45309;
  --tone-key-text: #047857;
  --macro-carb: #3b82f6;
  --macro-protein: #10b981;
  --macro-fat: #f59e0b;
}
[data-bs-theme="dark"] .week-page {
  --tone-rest-text: #cbd5e1;
  --tone-easy-text: #93c5fd;
  --tone-moderate-text: #fcd34d;
  --tone-key-text: #6ee7b7;
}
.tone-rest { --tone: var(--tone-rest); --tone-text: var(--tone-rest-text); }
.tone-easy { --tone: var(--tone-easy); --tone-text: var(--tone-easy-text); }
.tone-moderate { --tone: var(--tone-moderate); --tone-text: var(--tone-moderate-text); }
.tone-key { --tone: var(--tone-key); --tone-text: var(--tone-key-text); }

.week-num {
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

/* The week at a glance: seven bars, tappable straight to the day. */
.week-strip {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.25rem;
  align-items: end;
}
.week-strip-day {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 0.375rem 0.125rem;
  border-radius: var(--bs-border-radius);
  text-decoration: none;
  color: var(--bs-body-color);
  border: 1px solid transparent;
}
.week-strip-day:hover {
  background-color: var(--bs-tertiary-bg);
  color: var(--bs-body-color);
}
.week-strip-day.is-today {
  border-color: var(--bs-primary);
  background-color: rgba(var(--bs-primary-rgb), 0.08);
}
.week-strip-day.is-past { opacity: 0.6; }
@media (min-width: 992px) {
  /* The strip jumps to a day card, and the cards only exist below `lg`. Wide
     enough for the table, the whole week is on screen anyway, so the strip is
     a chart there and nothing to click. */
  .week-strip-day { pointer-events: none; }
}
.week-strip-label {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--bs-secondary-color);
}
.week-strip-kcal {
  font-size: 0.625rem;
  font-variant-numeric: tabular-nums;
  color: var(--bs-secondary-color);
}
.week-bar {
  width: 100%;
  /* Uncapped, a desktop column turns the bar into a slab and the week stops
     reading as a chart. */
  max-width: 3.5rem;
  margin-inline: auto;
  height: 3rem;
  display: flex;
  align-items: flex-end;
  background-color: var(--bs-tertiary-bg);
  border-radius: var(--bs-border-radius-sm);
  overflow: hidden;
}
.week-bar-fill {
  width: 100%;
  background-color: var(--tone, var(--bs-primary));
  border-radius: var(--bs-border-radius-sm);
  min-height: 0.25rem;
}

/* One day. The whole header is the disclosure control, so a thumb cannot miss it. */
.day-card {
  border: 1px solid var(--bs-card-border-color);
  border-left: 3px solid var(--tone, var(--bs-border-color));
  border-radius: var(--bs-card-border-radius);
  background-color: var(--bs-card-bg);
  margin-bottom: 0.625rem;
  scroll-margin-top: 5rem;
}
.day-card.is-today {
  border-color: var(--bs-primary);
  border-left-color: var(--bs-primary);
  box-shadow: 0 0 0 1px rgba(var(--bs-primary-rgb), 0.35);
}
.day-card.is-past .day-card-head { opacity: 0.65; }
.day-toggle {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  padding: 0.75rem 0.875rem;
  color: inherit;
  border-radius: var(--bs-card-border-radius);
}
.day-toggle:focus-visible {
  outline: 2px solid var(--bs-primary);
  outline-offset: -2px;
}
.day-toggle .day-chevron {
  transition: transform 0.15s ease;
  color: var(--bs-secondary-color);
}
.day-toggle[aria-expanded="true"] .day-chevron { transform: rotate(180deg); }
.day-name {
  font-weight: 600;
  font-size: 0.9375rem;
  white-space: nowrap;
}
.day-kcal {
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.day-why {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  color: var(--bs-secondary-color);
  font-size: 0.8125rem;
}
[aria-expanded="true"] .day-why {
  -webkit-line-clamp: unset;
  line-clamp: unset;
}
.day-detail {
  border-top: 1px solid var(--bs-border-color);
  padding: 0.875rem;
}

/* Macros: grams for the shopping, an energy-share bar for the shape. */
.macro-split {
  display: flex;
  height: 0.375rem;
  border-radius: 999px;
  overflow: hidden;
  background-color: var(--bs-tertiary-bg);
}
.macro-split span { display: block; }
.macro-c { background-color: var(--macro-carb); }
.macro-p { background-color: var(--macro-protein); }
.macro-f { background-color: var(--macro-fat); }
.macro-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
}
.macro-legend .dot {
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 999px;
  margin-right: 0.3125rem;
  vertical-align: 0.05rem;
}
.macro-legend .label {
  color: var(--bs-secondary-color);
  margin-right: 0.25rem;
}

.role-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3125rem;
  padding: 0.1875rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  color: var(--tone-text, var(--bs-secondary-color));
  background-color: var(--bs-tertiary-bg);
}
.role-badge .dot {
  width: 0.4375rem;
  height: 0.4375rem;
  border-radius: 999px;
  background-color: var(--tone, currentColor);
}

.week-stat {
  padding: 0.625rem 0.75rem;
  border-radius: var(--bs-border-radius);
  background-color: var(--bs-tertiary-bg);
}
.week-stat .week-stat-label {
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--bs-secondary-color);
}
.week-stat .week-stat-value {
  font-size: 1.0625rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.mode-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.625rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.mode-chip.is-live {
  color: #047857;
  background-color: rgba(16, 185, 129, 0.14);
}
[data-bs-theme="dark"] .mode-chip.is-live { color: #6ee7b7; }
