/* TrendCut — hand-rolled CSS. Tokens come from design/DESIGN.md (source of truth);
   no CSS framework. The look: "Technical Instrument" — quiet, data-forward,
   Apple-Health-like. Cards use a hairline border + one very soft shadow. */

:root {
  /* Colours (design/DESIGN.md) */
  --background: #fafafa;
  --surface: #ffffff;
  --surface-container-low: #f3f3f3;
  --surface-container: #eeeeee;
  --surface-container-highest: #e2e2e2;
  --on-surface: #1a1c1c;
  --on-surface-variant: #424754;
  --outline: #727785;
  --border-hairline: #e5e5e5;
  --text-muted: #737373;
  --primary: #0058be;
  --on-primary: #ffffff;
  --trend-blue: #3b82f6; /* raw-point / signal blue (DESIGN.md prose) */
  --secondary: #006c49; /* on-track green */
  --secondary-container: #6cf8bb;
  --status-warning: #f59e0b;
  --status-error: #ef4444;
  --data-fill: rgba(59, 130, 246, 0.08);

  /* Type */
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", monospace;

  /* Spacing / shape */
  --container-padding: 24px;
  --stack-gap: 16px;
  --section-margin: 40px;
  --radius-card: 20px;
  --radius-lg: 8px;
  --radius-xl: 12px;
  --card-shadow: 0px 4px 20px rgba(0, 0, 0, 0.04);
}

* {
  box-sizing: border-box;
}

/* Elements with display rules of their own must still honour `hidden`. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--background);
  color: var(--on-surface);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 24px;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Top bar ---------- */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-hairline);
}

.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  height: 64px;
  padding: 0 var(--container-padding);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  font-size: 24px;
  line-height: 32px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

/* ---------- Page layout ---------- */
.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 96px var(--container-padding) 96px;
  display: flex;
  flex-direction: column;
  gap: var(--stack-gap);
}

.page-error {
  background: #fff5f5;
  border: 1px solid #f3c7c7;
  color: #93000a;
  border-radius: var(--radius-xl);
  padding: 12px 16px;
  font-size: 14px;
}

.hero-grid,
.metrics-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--stack-gap);
}

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-card);
  padding: var(--container-padding);
  box-shadow: var(--card-shadow);
}

.card-label {
  display: block;
  font-size: 12px;
  line-height: 16px;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.unit-mono {
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 14px;
  color: var(--text-muted);
}

/* ---------- Hero (TDEE) card ---------- */
.hero-number {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-top: 16px;
}

.hero-value {
  font-size: 28px;
  line-height: 34px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.hero-value.is-muted {
  color: var(--text-muted);
  font-weight: 600;
}

.hero-ci {
  margin: 4px 0 0;
  font-size: 12px;
  line-height: 16px;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.hero-ci.is-prominent {
  font-size: 14px;
  color: var(--on-surface-variant);
  font-weight: 500;
}

.hero-footer {
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid var(--border-hairline);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.status-line {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 9999px;
  background: var(--surface-container-highest);
  flex: none;
}

.status-dot.is-ontrack { background: var(--secondary); }
.status-dot.is-slowing { background: var(--status-warning); }
.status-dot.is-stalled { background: #b45252; }
.status-dot.is-undetermined { background: var(--outline); }

.status-text {
  font-weight: 500;
  color: var(--on-surface-variant);
}

.status-text.is-ontrack { color: var(--secondary); }
.status-text.is-slowing { color: #92600a; }
.status-text.is-stalled { color: #9b3535; }
.status-text.is-undetermined { color: var(--text-muted); }

.status-explain {
  margin: 0;
  font-size: 12px;
  line-height: 16px;
  color: var(--text-muted);
}

/* Chips */
.chip {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 9999px;
  font-size: 12px;
  line-height: 16px;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.chip-warning {
  background: rgba(245, 158, 11, 0.12);
  color: #92600a;
}

/* ---------- Pace card ---------- */
.pace-rows {
  display: flex;
  flex-direction: column;
  gap: 24px;
  margin-top: 24px;
}

.pace-deficit-line {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 6px;
}

.pace-row-label {
  color: var(--on-surface-variant);
  font-weight: 500;
  font-size: 15px;
}

.pace-deficit-value {
  font-family: var(--font-mono);
  font-size: 28px;
  line-height: 36px;
  font-weight: 500;
  color: var(--primary);
}

.pace-deficit-value .unit-mono {
  color: var(--text-muted);
}

.pace-bar {
  width: 100%;
  height: 4px;
  border-radius: 9999px;
  background: var(--surface-container);
  overflow: hidden;
}

.pace-bar-fill {
  height: 100%;
  width: 0;
  background: var(--primary);
  border-radius: 9999px;
  transition: width 0.4s ease;
}

.pace-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-hairline);
}

.pace-row-value {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
}

.pace-chip {
  padding: 12px;
  border-radius: var(--radius-xl);
  font-size: 12px;
  line-height: 16px;
  font-weight: 600;
  background: var(--surface-container-low);
  color: var(--on-surface-variant);
}

.pace-chip.is-ontrack {
  background: rgba(108, 248, 187, 0.2);
  color: var(--secondary);
}

.pace-chip.is-behind {
  background: rgba(245, 158, 11, 0.12);
  color: #92600a;
}

/* ---------- Chart card ---------- */
.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.chart-title {
  margin: 0;
  font-size: 24px;
  line-height: 32px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.chart-subtitle {
  margin: 2px 0 0;
  font-size: 12px;
  line-height: 16px;
  color: var(--text-muted);
}

.chart-controls {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

/* Goal-line switch — a quiet iOS-style toggle, matching the range pills' scale. */
.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  color: var(--on-surface);
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-track {
  position: relative;
  display: inline-block;
  width: 34px;
  height: 20px;
  border-radius: 999px;
  background: var(--surface-container-highest);
  transition: background 0.15s ease;
  flex: none;
}

.switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  transition: transform 0.15s ease;
}

.switch input:checked + .switch-track {
  background: var(--secondary);
}

.switch input:checked + .switch-track .switch-thumb {
  transform: translateX(14px);
}

.switch input:focus-visible + .switch-track {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Disabled: no target set yet — dim the control and swap the label to a hint. */
.switch.is-disabled {
  cursor: not-allowed;
  color: var(--text-muted);
}

.switch.is-disabled .switch-track {
  opacity: 0.5;
}

.range-group {
  display: flex;
  gap: 8px;
}

.range-btn {
  padding: 6px 12px;
  border: none;
  border-radius: var(--radius-lg);
  background: var(--surface-container-low);
  color: var(--on-surface);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease;
}

.range-btn:hover {
  background: var(--surface-container);
}

.range-btn.is-active {
  background: var(--primary);
  color: var(--on-primary);
}

.chart-wrap {
  position: relative;
}

.chart-area {
  position: relative;
  width: 100%;
  height: 300px;
}

/* Hover tooltip + cursor dot (overlays; siblings of #chart so the chart's
   innerHTML redraw never removes them). */
.chart-tooltip {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-lg);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
  padding: 8px 10px;
  min-width: 108px;
}

.chart-tooltip[hidden] {
  display: none;
}

.tt-date {
  font-size: 11px;
  font-weight: 600;
  color: var(--on-surface);
  margin-bottom: 4px;
}

.tt-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 16px;
}

.tt-k {
  color: var(--text-muted);
}

.tt-k.tt-k-trend {
  color: var(--primary);
}

.tt-v {
  color: var(--on-surface);
}

.chart-cursor {
  position: absolute;
  z-index: 4;
  width: 12px;
  height: 12px;
  margin: -6px 0 0 -6px;
  border-radius: 50%;
  border: 2px solid var(--trend-blue);
  background: var(--surface);
  pointer-events: none;
}

.chart-cursor[hidden] {
  display: none;
}

.chart-area svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.chart-empty {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
  padding: 0 24px;
}

.chart-axis-label {
  font-family: var(--font-mono);
  font-size: 11px;
  fill: var(--text-muted);
}

/* ---------- Metric cards ---------- */
.metric-value {
  margin: 12px 0 0;
  font-size: 24px;
  line-height: 32px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.metric-value.is-muted {
  font-size: 18px;
  color: var(--text-muted);
}

.metric-note {
  margin: 4px 0 0;
  font-size: 12px;
  line-height: 16px;
  color: var(--text-muted);
}

/* ---------- Buttons ---------- */
.btn {
  font-family: var(--font-sans);
  font-size: 12px;
  line-height: 16px;
  font-weight: 600;
  letter-spacing: 0.02em;
  border-radius: 9999px;
  border: none;
  cursor: pointer;
  padding: 10px 24px;
  transition: transform 0.1s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.btn:active {
  transform: scale(0.96);
}

.btn-primary {
  background: var(--primary);
  color: var(--on-primary);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.btn-primary:hover {
  background: #004395;
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: default;
  transform: none;
}

.btn-ghost {
  background: var(--surface);
  color: var(--on-surface-variant);
  border: 1px solid var(--border-hairline);
}

.btn-ghost:hover {
  background: var(--surface-container-low);
}

.btn-wide {
  height: 48px;
  padding: 0 32px;
}

/* ---------- Floating log button (mobile) ---------- */
.fab {
  position: fixed;
  right: 20px;
  bottom: 24px;
  z-index: 60;
  width: 56px;
  height: 56px;
  border-radius: 9999px;
  border: none;
  background: var(--primary);
  color: var(--on-primary);
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(0, 88, 190, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(26, 28, 28, 0.1);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: var(--container-padding);
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-card);
  box-shadow: 0px 4px 40px rgba(0, 0, 0, 0.06);
  overflow: hidden;
  animation: modal-in 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-header {
  padding: var(--container-padding) var(--container-padding) 16px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.modal-title {
  margin: 0;
  font-size: 24px;
  line-height: 32px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.modal-subtitle {
  margin: 4px 0 0;
  font-size: 12px;
  line-height: 16px;
  color: var(--text-muted);
}

.modal-close {
  border: none;
  background: none;
  color: var(--outline);
  font-size: 24px;
  line-height: 1;
  padding: 8px;
  margin: -8px -8px 0 0;
  border-radius: 9999px;
  cursor: pointer;
}

.modal-close:hover {
  background: var(--surface-container-low);
}

.modal-form {
  padding: 0 var(--container-padding) var(--container-padding);
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--stack-gap);
}

.field-label {
  display: block;
  font-size: 12px;
  line-height: 16px;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 8px;
}

/* Minimalist inputs: transparent, bottom hairline, blue on focus (DESIGN.md). */
.field-box {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  border-bottom: 1px solid var(--border-hairline);
  padding: 8px 0;
  transition: border-color 0.15s ease;
}

.field-box:focus-within {
  border-bottom-color: var(--trend-blue);
}

.field-input {
  width: 100%;
  border: none;
  background: transparent;
  padding: 0;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 24px;
  color: var(--on-surface);
}

.field-input:focus {
  outline: none;
}

.field-input-big {
  font-size: 28px;
  line-height: 34px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.field-input-big::placeholder {
  color: var(--surface-container-highest);
  font-weight: 700;
}

.field-box .unit-mono {
  padding-bottom: 6px;
}

/* Hide number spinners for the clean look */
.field-input::-webkit-outer-spin-button,
.field-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.field-input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

.form-warnings {
  background: rgba(245, 158, 11, 0.1);
  border-radius: var(--radius-xl);
  padding: 12px 16px;
  color: #92600a;
  font-size: 13px;
  line-height: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-error {
  background: #fff5f5;
  border-radius: var(--radius-xl);
  padding: 12px 16px;
  color: #93000a;
  font-size: 13px;
  line-height: 18px;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: var(--stack-gap);
  padding-top: 8px;
}

/* ---------- Desktop ---------- */
@media (min-width: 768px) {
  .hero-grid {
    grid-template-columns: 2fr 1fr;
  }

  .metrics-grid {
    grid-template-columns: 1fr 1fr;
  }

  .metrics-grid-3 {
    grid-template-columns: repeat(3, 1fr);
  }

  .hero-value {
    font-size: 32px;
    line-height: 40px;
  }

  .hero-footer {
    flex-direction: row;
    align-items: flex-end;
    justify-content: space-between;
  }

  .status-explain {
    text-align: right;
    max-width: 55%;
  }

  .modal-actions {
    flex-direction: row-reverse;
  }

  .fab {
    display: none;
  }

  .page {
    padding-bottom: var(--section-margin);
  }
}

@media (max-width: 767px) {
  #open-log-btn {
    display: none;
  }

  .chart-area {
    height: auto;
    aspect-ratio: 4 / 3;
  }
}

/* ============================================================= */
/* Navigation (added for Settings + TDEE screens)                */
/* ============================================================= */
.topnav {
  display: flex;
  gap: 24px;
  margin: 0 auto 0 32px;
}

.topnav-link {
  font-size: 14px;
  font-weight: 500;
  color: var(--on-surface-variant);
  text-decoration: none;
  padding: 20px 0;
  border-bottom: 2px solid transparent;
  transition: color 0.15s ease;
}

.topnav-link:hover {
  color: var(--on-surface);
}

.topnav-link.is-active {
  color: var(--primary);
  font-weight: 600;
  border-bottom-color: var(--primary);
}

@media (max-width: 767px) {
  .topnav {
    gap: 16px;
    margin-left: 16px;
  }

  .topnav-link {
    font-size: 13px;
    padding: 20px 0;
  }
}

/* ============================================================= */
/* Settings screen                                               */
/* ============================================================= */
.page-head {
  margin-bottom: 8px;
}

.page-title {
  margin: 0;
  font-size: 32px;
  line-height: 40px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.page-subtitle {
  margin: 4px 0 0;
  font-size: 16px;
  color: var(--text-muted);
}

.settings-group {
  margin-top: var(--section-margin);
}

.settings-group-label {
  margin: 0 0 12px 4px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* One card per group; rows divided by hairlines (iOS-settings style). */
.settings-card {
  background: var(--surface);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-card);
  box-shadow: var(--card-shadow);
  overflow: hidden;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px var(--container-padding);
  border-bottom: 1px solid var(--border-hairline);
}

.settings-row:last-child {
  border-bottom: none;
}

.settings-row-stack {
  flex-direction: column;
  align-items: stretch;
  gap: 16px;
}

.settings-row-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.settings-row-label {
  font-size: 16px;
  color: var(--on-surface);
  font-weight: 500;
}

.settings-readout {
  font-family: var(--font-mono);
  font-size: 18px;
  color: var(--secondary);
}

.settings-input-inline {
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.settings-number {
  width: 88px;
  border: none;
  border-bottom: 1px solid var(--border-hairline);
  background: transparent;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 20px;
  color: var(--on-surface);
  padding: 2px 0;
}

.settings-number:focus {
  outline: none;
  border-bottom-color: var(--trend-blue);
}

.settings-date {
  border: none;
  background: transparent;
  font-family: var(--font-sans);
  font-size: 16px;
  color: var(--primary);
  cursor: pointer;
}

.settings-date:focus {
  outline: none;
}

.settings-hint {
  margin: 0;
  font-size: 13px;
  line-height: 18px;
  color: var(--text-muted);
}

/* Number-spinner removal, matching the log modal inputs. */
.settings-number::-webkit-outer-spin-button,
.settings-number::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.settings-number[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

/* Segmented control (units, window) */
.segmented {
  display: inline-flex;
  gap: 4px;
  background: var(--surface-container-low);
  padding: 4px;
  border-radius: var(--radius-lg);
}

.segmented-wide {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: 100%;
}

.segment {
  border: none;
  background: transparent;
  border-radius: 6px;
  padding: 8px 16px;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.segment.is-active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
  font-weight: 600;
}

/* Slider (smoothing α) */
.slider {
  width: 100%;
  height: 4px;
  border-radius: 9999px;
  background: var(--surface-container-high);
  appearance: none;
  -webkit-appearance: none;
  accent-color: var(--secondary);
  cursor: pointer;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border-hairline);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12);
  cursor: pointer;
}

.slider::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border-hairline);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12);
  cursor: pointer;
}

.slider-ends {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}

.settings-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 16px;
  margin-top: var(--section-margin);
}

.settings-saved {
  font-size: 14px;
  font-weight: 600;
  color: var(--secondary);
}

/* ============================================================= */
/* TDEE-over-time screen                                         */
/* ============================================================= */
.tdee-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: var(--stack-gap);
}

.tdee-head .page-subtitle {
  max-width: 44rem;
}

.chip-drift {
  background: var(--surface-container-low);
  color: var(--on-surface-variant);
  font-family: var(--font-mono);
  white-space: nowrap;
}

.chip-drift.chip-drift-down {
  background: rgba(108, 248, 187, 0.2);
  color: var(--secondary);
}

.chart-area-tall {
  height: 340px;
}

.tdee-current {
  text-align: right;
}

.tdee-current-value {
  display: block;
  font-family: var(--font-mono);
  font-size: 28px;
  line-height: 36px;
  font-weight: 500;
  color: var(--primary);
  margin-top: 2px;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin: 16px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-swatch {
  display: inline-block;
  width: 14px;
  height: 10px;
  border-radius: 2px;
}

.legend-line {
  height: 3px;
  background: var(--primary);
}

.legend-band {
  background: rgba(59, 130, 246, 0.18);
}

.legend-lowconf {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--surface);
  border: 1.5px solid var(--status-warning);
}

.legend-gap {
  font-style: italic;
}

@media (max-width: 767px) {
  .chart-area-tall {
    height: auto;
    aspect-ratio: 4 / 3;
  }
}

/* ============================================================= */
/* History screen — entry list, weekly summary                   */
/* ============================================================= */
.entries-empty {
  padding: 32px var(--container-padding);
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

.entry-row {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 16px var(--container-padding);
  border-bottom: 1px solid var(--border-hairline);
}

.entry-row:last-child {
  border-bottom: none;
}

.entry-date {
  font-weight: 600;
  font-size: 15px;
  min-width: 116px;
}

.entry-vals {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--on-surface-variant);
}

.entry-dot {
  color: var(--text-muted);
  opacity: 0.5;
}

.entry-actions,
.entry-confirm {
  display: flex;
  align-items: center;
  gap: 8px;
}

.entry-confirm-text {
  font-size: 13px;
  color: var(--text-muted);
  margin-right: 4px;
}

.entry-btn {
  border: 1px solid var(--border-hairline);
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 6px 14px;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  color: var(--on-surface-variant);
  cursor: pointer;
  transition: background 0.15s ease;
}

.entry-btn:hover {
  background: var(--surface-container-low);
}

.entry-btn-danger {
  color: #9b3535;
}

.entry-btn-danger:hover {
  background: rgba(186, 26, 26, 0.06);
}

.weekly-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--stack-gap);
}

.weekly-card {
  padding: 20px var(--container-padding);
}

.weekly-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 16px;
}

.weekly-range {
  font-weight: 600;
  font-size: 15px;
}

.weekly-adherence {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

.weekly-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px 24px;
}

.weekly-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.weekly-k {
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.weekly-v {
  font-family: var(--font-mono);
  font-size: 15px;
  color: var(--on-surface);
}

.export-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

/* Fixed date in the edit modal (History) */
.field-input.is-readonly {
  color: var(--on-surface-variant);
  cursor: default;
}

@media (min-width: 768px) {
  .weekly-list {
    grid-template-columns: repeat(2, 1fr);
  }

  .weekly-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* ---------- Auth (login) ---------- */
.auth-page {
  min-height: 70vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: var(--stack-gap, 16px);
}

.auth-title {
  font-size: 20px;
  line-height: 26px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.auth-subtitle {
  font-size: 13px;
  line-height: 18px;
  color: var(--text-muted);
  margin-top: 4px;
}

.auth-card .btn-primary {
  width: 100%;
  padding: 12px 24px;
}

/* Reciprocal login/signup link under the form. */
.auth-alt {
  font-size: 13px;
  line-height: 18px;
  color: var(--text-muted);
  text-align: center;
}

.auth-alt a {
  color: var(--trend-blue);
  font-weight: 500;
  text-decoration: none;
}

.auth-alt a:hover {
  text-decoration: underline;
}

.auth-alt-sep {
  margin: 0 6px;
  color: var(--border-hairline, rgba(0, 0, 0, 0.2));
}

.auth-card .field-box.is-disabled {
  opacity: 0.5;
}

/* Logout control at the right of the top bar. The nav's auto right margin already
   pushes trailing items to the edge; this just spaces it from a sibling button. */
.topbar-logout {
  margin-left: 16px;
}

/* ---------- Onboarding (first-run empty / low-data state) ---------- */
.onboarding {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: var(--section-margin, 24px);
  border: 1px solid var(--trend-blue);
}

.onboarding-title {
  font-size: 20px;
  line-height: 26px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.onboarding-lead {
  font-size: 14px;
  line-height: 20px;
  color: var(--on-surface-variant);
  max-width: 60ch;
}

.onboarding-progress {
  font-size: 13px;
  line-height: 18px;
  font-weight: 500;
  color: var(--on-surface);
}

.onboarding-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.onboarding-hint {
  font-size: 12px;
  line-height: 16px;
  color: var(--text-muted);
}

.onboarding-hint a {
  color: var(--trend-blue);
  text-decoration: none;
}

.onboarding-hint a:hover {
  text-decoration: underline;
}

/* Provisional (day-1 formula) estimate — deliberately DISTINCT from the real hero
   TDEE: dashed amber "provisional" treatment, muted number, prominent caveat, so it
   can never be mistaken for a data-derived estimate. */
.provisional {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 16px;
  border: 1px dashed #b45309;
  border-radius: var(--radius-xl, 16px);
  background: rgba(245, 158, 11, 0.08);
}

.provisional-tag {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #92600a;
}

.provisional-value {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.provisional-value #provisional-tdee {
  font-size: 26px;
  line-height: 30px;
  font-weight: 700;
  color: var(--on-surface-variant);
}

.provisional-unit {
  font-family: var(--font-mono, monospace);
  font-size: 12px;
  color: var(--text-muted);
}

.provisional-band {
  font-size: 13px;
  line-height: 18px;
  color: #92600a;
}

.provisional-caveat {
  font-size: 12px;
  line-height: 16px;
  color: var(--text-muted);
}

.provisional-method {
  font-size: 12px;
  line-height: 16px;
  color: #92600a;
  margin-top: 2px;
}

/* ---------- "How we calculated this" transparency panel ---------- */
.derivation {
  margin: 8px 0 4px;
  border-top: 1px solid var(--border-hairline, rgba(0, 0, 0, 0.08));
  padding-top: 8px;
}

.derivation-summary {
  font-size: 13px;
  font-weight: 500;
  color: var(--trend-blue);
  cursor: pointer;
  list-style: none;
}

.derivation-summary::-webkit-details-marker {
  display: none;
}

.derivation-summary::before {
  content: "▸ ";
  font-size: 10px;
}

.derivation[open] .derivation-summary::before {
  content: "▾ ";
}

.derivation-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 8px;
}

.derivation-intro,
.derivation-ci {
  font-size: 13px;
  line-height: 18px;
  color: var(--on-surface-variant);
}

.derivation-chain {
  font-family: var(--font-mono, monospace);
  font-size: 14px;
  line-height: 20px;
  color: var(--on-surface);
  background: var(--surface-container, rgba(0, 0, 0, 0.03));
  border-radius: var(--radius-md, 10px);
  padding: 8px 12px;
  overflow-x: auto;
}

.derivation-caveats {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  padding: 0;
}

.derivation-caveats li {
  font-size: 12px;
  line-height: 17px;
  color: var(--text-muted);
  padding-left: 14px;
  position: relative;
}

.derivation-caveats li::before {
  content: "•";
  position: absolute;
  left: 2px;
}

/* The unflattering caveats (optimistic CI, low-confidence reason) get a slightly
   stronger amber so candour is visible, not buried. */
.derivation-caveats li.caveat-optimistic-ci,
.derivation-caveats li.caveat-why-low-confidence {
  color: #92600a;
}

/* ---------- Public validation page ---------- */
.validation-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: var(--section-margin, 24px);
}

.validation-h2 {
  font-size: 18px;
  line-height: 24px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.validation-how {
  margin: 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
  line-height: 20px;
  color: var(--on-surface-variant);
}

.validation-note {
  font-size: 13px;
  line-height: 19px;
  color: var(--text-muted);
}

.validation-headline {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.validation-headline-num {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.validation-headline-num > span:first-child {
  font-size: 40px;
  line-height: 44px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--trend-blue);
}

.validation-headline-label {
  font-size: 14px;
  color: var(--on-surface-variant);
}

.validation-headline-sub {
  font-size: 13px;
  color: var(--text-muted);
}

.validation-chart-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.validation-scatter {
  width: 100%;
  height: auto;
  background: var(--surface-container, rgba(0, 0, 0, 0.02));
  border-radius: var(--radius-md, 10px);
}

.scatter-diagonal {
  stroke: var(--text-muted);
  stroke-width: 1.5;
  stroke-dasharray: 5 4;
  opacity: 0.6;
}

.scatter-axis {
  fill: var(--text-muted);
  font-size: 12px;
  text-anchor: middle;
  font-family: var(--font-sans, sans-serif);
}

.scatter-dot.is-pass {
  fill: var(--trend-blue);
  opacity: 0.75;
}

.scatter-dot.is-fail {
  fill: #b45309;
  opacity: 0.9;
}

.validation-legend {
  font-size: 12px;
  color: var(--text-muted);
}

.legend-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin: 0 3px 0 8px;
  vertical-align: middle;
}

.legend-dot.legend-pass {
  background: var(--trend-blue);
}

.legend-dot.legend-fail {
  background: #b45309;
}

.validation-scenarios {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.validation-scenario {
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-md, 10px);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* The weak scenario is visually prominent, not buried: amber accent. */
.validation-scenario.is-weak {
  border-color: #b45309;
  background: rgba(245, 158, 11, 0.06);
}

.validation-scenario-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.validation-scenario-title {
  font-size: 15px;
  font-weight: 600;
}

.validation-scenario-rate {
  font-size: 18px;
  font-weight: 700;
  color: var(--trend-blue);
}

.validation-scenario-rate.is-weak {
  color: #b45309;
}

.validation-scenario-desc {
  font-size: 13px;
  line-height: 19px;
  color: var(--on-surface-variant);
}

.validation-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px 16px;
  margin: 0;
}

.validation-stats div {
  display: flex;
  flex-direction: column;
}

.validation-stats dt {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.validation-stats dd {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  font-family: var(--font-mono, monospace);
}

.validation-fail-count {
  color: #b45309;
  font-weight: 600;
}

.validation-table-wrap {
  overflow-x: auto;
}

.validation-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.validation-table th,
.validation-table td {
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-hairline);
  font-family: var(--font-mono, monospace);
}

.validation-table th {
  font-family: var(--font-sans, sans-serif);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.validation-limits {
  margin: 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
  line-height: 19px;
  color: var(--on-surface-variant);
}

@media (min-width: 768px) {
  .validation-stats {
    grid-template-columns: repeat(4, 1fr);
  }
}
