/* Design tokens — Nexus palette */
:root {
  --bg: #F7F6F2;
  --surface: #FBFBF9;
  --surface-alt: #F1EFEA;
  --border: #D4D1CA;
  --text: #28251D;
  --text-muted: #7A7974;
  --text-faint: #BAB9B4;
  --primary: #01696F;
  --primary-hover: #0C4E54;
  --primary-soft: #E4F0F1;
  --success: #437A22;
  --warning: #964219;
  --error: #A12C7B;
  --caution: #DA7101;
  --status-orange: #A64C0B;
  --status-red: #B42318;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(40, 37, 29, 0.05);
  --shadow: 0 4px 20px rgba(40, 37, 29, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  font-weight: 600;
  color: var(--text);
  margin: 0;
  letter-spacing: -0.01em;
}

.container {
  max-width: 880px;
  margin: 0 auto;
  padding: 0 24px;
}

/* Hero */
.hero {
  padding: 48px 0 32px;
  background: linear-gradient(180deg, var(--primary-soft) 0%, var(--bg) 100%);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--primary);
  font-family: 'DM Sans', sans-serif;
  font-weight: 600;
  font-size: 18px;
  margin-bottom: 24px;
}

.hero h1 {
  font-size: 34px;
  line-height: 1.15;
  margin-bottom: 12px;
  max-width: 640px;
}

.hero .lede {
  font-size: 16px;
  color: var(--text-muted);
  max-width: 620px;
  margin: 0;
}

.trust-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 20px;
}

.trust-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 30px;
  padding: 5px 10px;
  border: 1px solid color-mix(in srgb, var(--primary) 24%, var(--border));
  border-radius: 999px;
  background: color-mix(in srgb, var(--primary-soft) 62%, var(--surface));
  color: var(--primary-hover);
  font-family: 'DM Sans', sans-serif;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.2;
}

.trust-badge svg {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow-sm);
  margin-top: 32px;
}

.card h2 {
  font-size: 20px;
  margin-bottom: 4px;
}

.hint {
  color: var(--text-muted);
  font-size: 14px;
  margin: 0;
}

/* Form */
.form-intro {
  display: grid;
  gap: 7px;
  margin-bottom: 24px;
}

.privacy-note {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  color: var(--text-muted);
  font-size: 13px;
}

.privacy-note svg {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
  fill: none;
  stroke: var(--primary);
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.form-section-block {
  margin-top: 22px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.form-section-block:first-of-type {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

.form-section-title {
  margin-bottom: 13px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.standalone-fields {
  margin-top: 22px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px 20px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

.field input,
.field select {
  font-family: 'Inter', sans-serif;
  font-size: 15px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.field .micro {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.check-group {
  margin: 24px 0 0;
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.check-group legend {
  padding: 0 6px;
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.check-group > .micro {
  display: block;
  margin: 0 0 12px;
  color: var(--text-muted);
  font-size: 12px;
}

.check-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 18px;
}

.check-grid label {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  color: var(--text);
  font-size: 14px;
  line-height: 1.35;
  cursor: pointer;
}

.check-grid input {
  width: 17px;
  height: 17px;
  margin: 1px 0 0;
  accent-color: var(--primary);
  flex: 0 0 auto;
}

.actions {
  margin-top: 24px;
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  align-items: center;
}

button {
  font-family: 'DM Sans', sans-serif;
  font-size: 15px;
  font-weight: 500;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}

button[type="submit"],
.btn-primary {
  background: var(--primary);
  color: #fff;
}

button[type="submit"]:hover:not(:disabled),
.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

button:disabled {
  opacity: 0.6;
  cursor: wait;
}

.btn-secondary {
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border);
}

/* Error */
.error {
  margin-top: 16px;
  padding: 12px 16px;
  background: #FDE9F1;
  border: 1px solid var(--error);
  border-radius: var(--radius-sm);
  color: var(--error);
  font-size: 14px;
}

/* Results */
.results {
  margin-top: 32px;
}

.sanity-warnings {
  margin-bottom: 24px;
  padding: 20px 24px;
  border: 2px solid var(--error);
  border-radius: var(--radius);
  background: #FDE9F1;
  color: var(--text);
}

.sanity-warnings h2 {
  margin-bottom: 8px;
  color: var(--error);
  font-size: 18px;
}

.sanity-warnings p {
  margin: 8px 0 0;
  font-size: 14px;
}

.allergy-notice,
.clinical-gate {
  margin-bottom: 24px;
  padding: 18px 22px;
  border-radius: var(--radius);
}

.allergy-notice {
  border: 1px solid var(--primary);
  background: var(--primary-soft);
  color: var(--text);
}

.clinical-gate {
  border: 2px solid var(--warning);
  background: var(--surface);
  color: var(--text);
}

.clinical-gate h3 {
  margin-bottom: 8px;
  color: var(--warning);
  font-size: 19px;
}

.clinical-gate p {
  margin: 0;
}

/* Hero Results */
.result-hero {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  margin-bottom: 24px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 999px;
  font-family: 'DM Sans', sans-serif;
  font-weight: 600;
  font-size: clamp(24px, 5vw, 32px);
  margin-bottom: 16px;
}

.status-normal {
  background: color-mix(in srgb, var(--success) 15%, var(--surface));
  color: var(--success);
  border: 1px solid color-mix(in srgb, var(--success) 30%, transparent);
}

.status-warning {
  background: color-mix(in srgb, var(--status-orange) 10%, var(--surface));
  color: var(--status-orange);
  border: 1px solid color-mix(in srgb, var(--status-orange) 30%, transparent);
}

.status-severe {
  background: color-mix(in srgb, var(--status-red) 10%, var(--surface));
  color: var(--status-red);
  border: 1px solid color-mix(in srgb, var(--status-red) 30%, transparent);
}

.result-eyebrow {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.result-hero h2 {
  font-size: 18px;
  overflow-wrap: anywhere;
  margin-bottom: 8px;
}

.hero-summary {
  font-size: 16px;
  color: var(--text-muted);
  max-width: 600px;
  margin: 0 auto 24px;
}

.hero-metrics {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 24px;
  margin-bottom: 24px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.h-metric {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.hm-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-family: 'DM Sans', sans-serif;
}

.hm-value {
  font-family: 'DM Sans', sans-serif;
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.hero-note {
  font-size: 14px;
  color: var(--text-muted);
  background: var(--bg);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-top: 12px;
  text-align: left;
}

.warning-note {
  border-left: 3px solid var(--caution);
}

/* Growth Chart */
.growth-chart {
  margin: 0 0 24px 0;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.growth-chart-svg {
  width: 100%;
  height: auto;
  max-height: 400px;
}

.growth-chart.normal { color: var(--success); }
.growth-chart.underweight,
.growth-chart.overweight,
.growth-chart.risk_overweight { color: var(--status-orange); }
.growth-chart.severe_underweight { color: var(--status-red); }
.growth-chart h3 { font-size: 18px; margin-bottom: 16px; }

.growth-chart figcaption {
  margin-top: 16px;
  font-size: 14px;
  color: var(--text-muted);
  text-align: center;
}

/* Details / Summary */
.plan-details {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  overflow: hidden;
}

.plan-details summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  cursor: pointer;
  user-select: none;
  list-style: none;
}

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

.plan-details summary h3 {
  margin: 0;
  font-size: 18px;
  color: var(--primary);
  display: inline-block;
}

.plan-details summary .icon-chevron {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease;
}

.plan-details summary .icon-chevron::after {
  content: '';
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
  transform: rotate(45deg);
}

.plan-details[open] summary .icon-chevron {
  transform: rotate(180deg);
}

.plan-details[open] summary {
  border-bottom: 1px solid var(--border);
}

.details-content {
  padding: 20px 24px;
}

.details-content h4 {
  font-size: 16px;
  margin-bottom: 8px;
}

.details-content p {
  margin: 0 0 12px 0;
  color: var(--text);
}

/* Timeline */
.timeline {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 16px;
}

.timeline-item {
  display: flex;
  gap: 16px;
  position: relative;
}

.timeline-item:not(:last-child)::after {
  content: '';
  position: absolute;
  top: 24px;
  bottom: -16px;
  left: 65px;
}

.timeline-time {
  flex: 0 0 50px;
  font-weight: 600;
  font-family: 'DM Sans', sans-serif;
  color: var(--primary);
  text-align: right;
  padding-top: 2px;
  font-size: 14px;
}

.timeline-marker {
  flex: 0 0 20px;
  display: flex;
  justify-content: center;
  padding-top: 4px;
  position: relative;
  color: var(--border);
}

.timeline-marker svg {
  width: 20px;
  height: 20px;
  color: var(--primary);
  z-index: 2;
  background: var(--surface);
}

.timeline-item:not(:last-child) .timeline-marker::after {
  content: '';
  position: absolute;
  top: 16px;
  bottom: -16px;
  left: 50%;
  width: 2px;
  transform: translateX(-50%);
  background: var(--border);
  z-index: 1;
}

.timeline-content {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.tl-meal {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  margin-bottom: 4px;
}

.tl-desc {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.tl-amount {
  display: inline-block;
  font-size: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 999px;
  color: var(--text);
}

/* Foods Grid */
.foods-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.food-card {
  display: flex;
  gap: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  align-items: flex-start;
  min-width: 0;
}

.food-icon {
  flex: 0 0 32px;
  height: 32px;
  background: var(--primary-soft);
  color: var(--primary);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.food-info {
  flex: 1;
  min-width: 0;
}

.food-name {
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  margin-bottom: 2px;
  overflow-wrap: break-word;
}

.food-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
  overflow-wrap: break-word;
}

.food-tip {
  font-size: 13px;
  color: var(--text);
  line-height: 1.4;
  overflow-wrap: break-word;
}

/* Sections */
.section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 28px;
  margin-bottom: 20px;
}

.section h3 {
  font-size: 18px;
  color: var(--primary);
  margin-bottom: 12px;
}

.section p {
  margin: 0 0 12px 0;
  color: var(--text);
}

/* Tables */
.table-scroll {
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
}

.table {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
  margin-top: 12px;
  font-size: 14px;
}

.table th {
  background: var(--primary);
  color: #fff;
  text-align: left;
  padding: 10px 12px;
  font-family: 'DM Sans', sans-serif;
  font-weight: 500;
  font-size: 13px;
}

.table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.table tr:nth-child(even) td {
  background: var(--bg);
}

/* Bullets */
.section ul {
  margin: 8px 0;
  padding-left: 20px;
}

.section li {
  margin-bottom: 6px;
  color: var(--text);
}

.section.warning h3 { color: var(--error); }
.section.warning li { color: var(--text); }
.section.warning li::marker { color: var(--error); }

/* Objectives */
.objectives {
  display: grid;
  gap: 10px;
}

.objective {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 16px;
  padding: 12px 14px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  align-items: start;
}

.objective .obj-label {
  font-family: 'DM Sans', sans-serif;
  font-weight: 500;
  color: var(--text);
  font-size: 14px;
}

.objective .obj-value {
  font-size: 14px;
  color: var(--text);
}

/* Menu grid */
.menu {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 12px;
}

.day {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
}

.day h4 {
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  color: var(--primary);
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.day .meal {
  margin-bottom: 8px;
  font-size: 13px;
}

.day .meal-name {
  font-weight: 600;
  color: var(--text);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  display: block;
  margin-bottom: 2px;
}

/* Download bar updates */
.download-bar-floating {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  left: max(16px, env(safe-area-inset-left));
  z-index: 20;
  width: min(calc(100% - 32px), 920px);
  margin: 0 auto;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(16px);
  transition:
    opacity 180ms ease,
    transform 180ms ease,
    visibility 0s linear 180ms;
}

.download-bar-floating.is-scroll-active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0);
  transition-delay: 0s;
}

.download-bar-inner {
  background: var(--primary);
  color: #fff;
  padding: 14px 20px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  box-shadow: 0 8px 32px rgba(1, 105, 111, 0.25);
}

.download-bar-inner .info {
  font-size: 15px;
  display: flex;
  flex-direction: column;
}

.download-bar-inner .info-sub {
  color: rgba(255, 255, 255, 0.8);
  font-size: 13px;
}

.download-bar-inner button {
  background: #fff;
  color: var(--primary);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  padding: 12px 20px;
}

.download-bar-inner button:hover:not(:disabled) {
  background: var(--surface-alt);
}

/* Loading */
.loading {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 14px;
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Footer */
footer {
  margin-top: 64px;
  padding: 24px 0 32px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
}

footer a {
  color: var(--primary);
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}

/* Responsive */
@media (max-width: 640px) {
  .hero { padding: 32px 0 24px; }
  .hero h1 { font-size: 26px; }
  .hero .lede { font-size: 15px; }
  .trust-badges { gap: 7px; margin-top: 16px; }
  .trust-badge { font-size: 11px; }
  .card { padding: 20px; }
  .grid { grid-template-columns: 1fr; }
  .check-grid { grid-template-columns: 1fr; }
  .objective { grid-template-columns: 1fr; gap: 4px; }
  .menu { grid-template-columns: 1fr; }
  .hero-metrics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
  .result-hero { padding: 20px 16px; }
  .growth-chart { padding: 16px 10px; }
  .timeline-item { gap: 10px; }
  .schedule-timeline { padding: 20px 16px; }
  .download-bar-inner { flex-direction: column; align-items: stretch; text-align: center; }
  .download-bar-inner button { justify-content: center; }
  .table { font-size: 13px; }
  .table th, .table td { padding: 8px 8px; }

  .foods-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .food-card { flex-direction: column; gap: 8px; padding: 12px; }
  .food-icon { flex: 0 0 28px; height: 28px; }
  .plan-details summary { padding: 16px; }
  .details-content { padding: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .download-bar-floating {
    transition: none;
  }
}
