/* ============================================================
   Healthy Human — styles.css
   Premium pediatric health tracker
   ============================================================ */

/* ----- Design Tokens ----- */
:root {
  /* Colors */
  --bg: #FAFBF9;
  --ink: #1C2B33;
  --primary: #4E8B7C;
  --primary-light: #6BA396;
  --primary-dark: #3D7063;
  --secondary: #7FA98E;
  --secondary-light: #A3C5AE;
  --alert: #D9A441;
  --alert-light: #F0D08E;
  --alert-bg: #FFF8EB;
  --surface: #FFFFFF;
  --muted: #F3F2EF;
  --border: #DCD8D0;
  --border-light: #EAE7E2;
  --text-secondary: #5C6B73;
  --text-muted: #8A9199;

  /* Status */
  --status-good: #7FA98E;
  --status-good-bg: #F0F7F2;
  --status-due: #D9A441;
  --status-due-bg: #FFF8EB;
  --status-overdue: #C97B3A;
  --status-overdue-bg: #FFF3E8;
  --status-upcoming: #8A9199;
  --status-upcoming-bg: #F3F2EF;

  /* Spacing — 8px baseline */
  --space-1: 8px;
  --space-2: 16px;
  --space-3: 24px;
  --space-4: 32px;
  --space-5: 40px;
  --space-6: 48px;
  --space-7: 56px;
  --space-8: 64px;

  /* Typography */
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-data: 'IBM Plex Mono', 'Menlo', monospace;

  /* Radii */
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 16px;

  /* Shadows */
  --shadow-card: 0 1px 3px rgba(28, 43, 51, 0.06), 0 1px 2px rgba(28, 43, 51, 0.04);
  --shadow-card-hover: 0 4px 12px rgba(28, 43, 51, 0.08), 0 2px 4px rgba(28, 43, 51, 0.04);
  --shadow-modal: 0 8px 32px rgba(28, 43, 51, 0.12), 0 4px 8px rgba(28, 43, 51, 0.06);
}

/* ----- Global Reset & Base ----- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
}

#app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 var(--space-3);
}

/* ----- Header ----- */
#app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border-bottom: 1px solid var(--border-light);
  padding: 12px 24px;
  margin: 0 calc(-1 * var(--space-3));
  gap: 16px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 0 0 auto;
}

.header-right {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 14px;
  justify-content: flex-end;
  flex: 1 1 auto;
}

.app-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -0.01em;
  white-space: nowrap;
}

/* Child selector */
.child-selector select {
  font-family: var(--font-ui);
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--ink);
  background: var(--muted);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 6px 32px 6px 12px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%235C6B73' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  cursor: pointer;
}

.child-selector select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(78, 139, 124, 0.15);
}

/* Unit toggle */
.unit-toggle {
  display: flex;
  background: var(--muted);
  border-radius: 9999px;
  padding: 2px;
  border: 1px solid var(--border-light);
}

.unit-btn {
  font-family: var(--font-data);
  font-size: 0.75rem;
  font-weight: 500;
  padding: 4px 12px;
  border: none;
  border-radius: 9999px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.unit-btn.active {
  background: var(--primary);
  color: var(--surface);
}

.unit-btn:hover:not(.active) {
  color: var(--ink);
}

/* Icon buttons */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.btn-icon:hover {
  background: var(--muted);
  color: var(--ink);
}

/* ----- Tab Navigation ----- */
#tab-nav {
  display: flex;
  gap: var(--space-4);
  border-bottom: 1px solid var(--border-light);
  margin-top: var(--space-2);
  padding: 0;
}

.tab {
  font-family: var(--font-ui);
  font-size: 0.9375rem;
  font-weight: 400;
  color: var(--text-secondary);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: var(--space-1) 0 var(--space-2);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.tab:hover {
  color: var(--primary-light);
}

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

/* ----- Tab Panels ----- */
.tab-panel {
  display: none;
  padding-top: var(--space-4);
  padding-bottom: var(--space-6);
}

.tab-panel.active {
  display: block;
}

/* ----- Chart Controls ----- */
.chart-controls {
  display: flex;
  gap: var(--space-1);
  margin-bottom: var(--space-2);
}

.chart-metric-btn {
  font-family: var(--font-ui);
  font-size: 0.8125rem;
  font-weight: 500;
  padding: 6px 16px;
  border: 1px solid var(--border);
  border-radius: 9999px;
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.chart-metric-btn:hover {
  border-color: var(--primary-light);
  color: var(--primary);
}

.chart-metric-btn.active {
  background: var(--primary);
  color: var(--surface);
  border-color: var(--primary);
}

/* ----- Growth Chart Container ----- */
.chart-container {
  position: relative;
  width: 100%;
  max-height: 55vh;
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: var(--space-2);
  box-shadow: var(--shadow-card);
  margin-bottom: var(--space-4);
}

.chart-container canvas {
  width: 100% !important;
  height: 100% !important;
}

/* ----- Metric Cards ----- */
.metric-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.metric-card {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  box-shadow: var(--shadow-card);
  transition: box-shadow 0.2s;
  display: flex;
  flex-direction: column;
}

.metric-card:hover {
  box-shadow: var(--shadow-card-hover);
}

.metric-card.alert-flag {
  border-left: 4px solid var(--alert);
}

.metric-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-1);
  margin-bottom: var(--space-1);
}

.metric-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.metric-updated {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.metric-value-container {
  display: flex;
  align-items: baseline;
  gap: 4px;
  margin-bottom: var(--space-1);
}

.metric-value {
  font-family: var(--font-data);
  font-size: 1.75rem;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.2;
}

.metric-unit {
  font-family: var(--font-data);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.metric-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-1);
  margin-top: auto;
  padding-top: var(--space-1);
}

.metric-percentile {
  display: inline-flex;
  align-items: center;
  font-family: var(--font-data);
  font-size: 0.8125rem;
  font-weight: 500;
  background: var(--muted);
  color: var(--text-secondary);
  border-radius: 9999px;
  padding: 2px 10px;
}

.metric-trend {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8125rem;
  font-weight: 500;
}

.metric-trend.trend-up {
  color: var(--secondary);
}

.metric-trend.trend-sharp {
  color: var(--alert);
}

.metric-trend.trend-down {
  color: var(--status-overdue);
}

.metric-trend.trend-stable {
  color: var(--text-muted);
}

/* ----- Summary Box ----- */
.summary-box {
  background: var(--muted);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  margin-bottom: var(--space-4);
  font-size: 0.9375rem;
  line-height: 1.6;
  color: var(--ink);
}

.summary-box:empty {
  display: none;
}

.summary-advisory {
  border-left: 3px solid var(--alert);
  padding-left: var(--space-2);
  margin-top: var(--space-2);
  color: var(--text-secondary);
}

/* ----- Section Cards ----- */
.section-card {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  box-shadow: var(--shadow-card);
  margin-bottom: var(--space-3);
}

.section-card h2 {
  font-size: 1.0625rem;
  font-weight: 600;
  margin-bottom: var(--space-3);
  color: var(--ink);
}

/* ----- Forms ----- */
.form-row {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.form-group {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.form-group label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--ink);
  margin-bottom: 4px;
}

.form-group .optional {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.8125rem;
}

.form-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.form-group input,
.form-group select {
  font-family: var(--font-ui);
  font-size: 0.9375rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-group input::placeholder {
  color: var(--text-muted);
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(78, 139, 124, 0.15);
}

/* Input with unit label inside */
.input-with-unit {
  position: relative;
}

.input-with-unit input {
  width: 100%;
  padding-right: 40px;
}

.unit-label {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--font-data);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  pointer-events: none;
}

/* Buttons */
.btn-primary {
  font-family: var(--font-ui);
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--surface);
  background: var(--primary);
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 24px;
  cursor: pointer;
  transition: background 0.15s;
  margin-top: var(--space-1);
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-primary:active {
  transform: translateY(1px);
}

.btn-secondary {
  font-family: var(--font-ui);
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--primary);
  background: transparent;
  border: 1px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 10px 24px;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-secondary:hover {
  background: rgba(78, 139, 124, 0.06);
}

/* ----- Tables ----- */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

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

thead th {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-align: left;
  padding: var(--space-1) var(--space-2) var(--space-1) 0;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  font-size: 0.875rem;
  padding: var(--space-2) var(--space-2) var(--space-2) 0;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}

/* Mono for data cells */
tbody td:nth-child(n+2) {
  font-family: var(--font-data);
  font-size: 0.8125rem;
}

tbody tr:hover {
  background: var(--muted);
}

tbody tr:last-child td {
  border-bottom: none;
}

/* Delete / action buttons in table */
tbody td:last-child .btn-delete {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

tbody td:last-child .btn-delete:hover {
  background: var(--status-overdue-bg);
  color: var(--status-overdue);
}

/* Status pills */
.status-pill {
  display: inline-flex;
  align-items: center;
  font-family: var(--font-ui);
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 9999px;
  padding: 2px 12px;
  white-space: nowrap;
}

.status-pill.good {
  color: var(--status-good);
  background: var(--status-good-bg);
}

.status-pill.due {
  color: var(--status-due);
  background: var(--status-due-bg);
}

.status-pill.overdue {
  color: var(--status-overdue);
  background: var(--status-overdue-bg);
}

.status-pill.upcoming {
  color: var(--status-upcoming);
  background: var(--status-upcoming-bg);
}

/* Vaccine abbreviation badge */
.vax-abbrev {
  display: inline-block;
  font-family: var(--font-data);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--primary-dark);
  background: var(--status-good-bg);
  border: 1px solid var(--secondary-light);
  border-radius: var(--radius-sm);
  padding: 1px 6px;
  margin-left: 6px;
  vertical-align: middle;
  letter-spacing: 0.02em;
}

/* Empty state */
.empty-state {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9375rem;
  padding: var(--space-5) 0;
}

/* ----- Next Checkup Banner ----- */
.next-checkup {
  background: var(--alert-bg);
  border: 1px solid var(--alert-light);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  margin-bottom: var(--space-3);
  font-size: 0.9375rem;
  color: var(--ink);
}

.next-checkup:empty {
  display: none;
}

/* ----- Source Citation ----- */
.source-citation {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: var(--space-3) 0;
}

/* ----- Onboarding Overlay ----- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(28, 43, 51, 0.5);
}

.overlay[hidden] {
  display: none;
}

.onboarding-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-modal);
  max-width: 440px;
  width: 90%;
  padding: var(--space-6);
}

.onboarding-card h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: var(--space-1);
  color: var(--ink);
}

.onboarding-card > p {
  font-size: 0.9375rem;
  color: var(--text-secondary);
  margin-bottom: var(--space-4);
  line-height: 1.6;
}

.onboard-step {
  display: block;
}

.onboard-step[hidden] {
  display: none;
}

.onboard-step-indicator {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--primary);
  background: var(--primary-light-bg, rgba(78, 139, 124, 0.1));
  padding: 4px 10px;
  border-radius: 12px;
  margin-bottom: var(--space-3);
}

.onboard-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-2);
}

.btn-back {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-family: var(--font-ui);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s;
}

.btn-back:hover {
  background: var(--muted);
  color: var(--ink);
}

.onboard-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 4px;
}

.onboard-subtext {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: var(--space-3);
  line-height: 1.5;
}

.onboard-privacy-footer {
  margin-top: var(--space-4);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border-light);
  font-size: 0.78125rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
}

.onboard-privacy-footer svg {
  color: var(--primary);
  flex-shrink: 0;
}

.onboarding-card .form-group {
  margin-bottom: var(--space-2);
}

.onboarding-card .btn-primary {
  width: 100%;
  margin-top: var(--space-3);
  padding: 12px 24px;
}

/* ----- Modals ----- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal[hidden] {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(28, 43, 51, 0.5);
}

.modal-card {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-modal);
  max-width: 480px;
  width: 90%;
  padding: var(--space-4);
}

.modal-card h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: var(--space-2);
}

.modal-desc {
  font-size: 0.9375rem;
  color: var(--text-secondary);
  margin-bottom: var(--space-3);
}

.modal-card .form-group {
  margin-bottom: var(--space-2);
}

.modal-actions {
  display: flex;
  gap: var(--space-2);
  justify-content: flex-end;
  margin-top: var(--space-3);
}

/* ----- Export Options ----- */
.export-options {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.export-option {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
  transition: box-shadow 0.15s, border-color 0.15s;
  text-align: left;
  font-family: var(--font-ui);
}

.export-option:hover {
  box-shadow: var(--shadow-card-hover);
  border-color: var(--primary);
}

.export-option svg {
  flex-shrink: 0;
  color: var(--primary);
}

.export-option span {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--ink);
}

.export-option .export-desc {
  font-size: 0.8125rem;
  font-weight: 400;
  color: var(--text-muted);
  margin-left: auto;
}

/* Header Nav Action Buttons */
.btn-nav-action {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--surface);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-family: var(--font-ui);
  font-size: 0.84375rem;
  font-weight: 500;
  height: 38px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.1s;
  white-space: nowrap;
}

.btn-nav-action:hover {
  background: var(--muted);
  color: var(--ink);
  border-color: var(--primary);
}

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

.btn-nav-action svg {
  flex-shrink: 0;
}

.btn-nav-delete {
  color: var(--status-overdue, #d9534f);
  border-color: rgba(217, 83, 79, 0.3);
}

.btn-nav-delete:hover {
  background: rgba(217, 83, 79, 0.08);
  color: var(--status-overdue, #d9534f);
  border-color: var(--status-overdue, #d9534f);
}

.btn-nav-highlight {
  background: var(--primary-light-bg, rgba(78, 139, 124, 0.12));
  color: var(--primary-dark, #2b564c);
  border-color: rgba(78, 139, 124, 0.35);
  font-weight: 600;
}

.btn-nav-highlight:hover {
  background: rgba(78, 139, 124, 0.22);
  border-color: var(--primary);
}

/* Front Page Privacy Banner & Actions */
.privacy-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface-subtle, rgba(78, 139, 124, 0.07));
  border: 1px solid rgba(78, 139, 124, 0.2);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  margin: var(--space-3) 0 var(--space-2);
  font-size: 0.8125rem;
  color: var(--ink-light, #2c423d);
}

.privacy-banner-text {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 300px;
}

.privacy-banner .privacy-icon {
  color: var(--primary);
  flex-shrink: 0;
}

.privacy-banner-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-banner-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-ui);
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.btn-banner-primary {
  background: var(--primary);
  color: var(--surface);
  border: 1px solid var(--primary);
}

.btn-banner-primary:hover {
  background: var(--primary-dark);
}

.btn-banner-secondary {
  background: var(--surface);
  color: var(--primary-dark, #2b564c);
  border: 1px solid var(--border);
}

.btn-banner-secondary:hover {
  background: var(--muted);
  border-color: var(--primary);
}

/* Footer Privacy Note & Guide Link */
.footer-privacy {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--primary-dark, #366358);
  background: rgba(78, 139, 124, 0.08);
  padding: 8px 16px;
  border-radius: 9999px;
  margin-bottom: var(--space-3);
  text-align: center;
}

.btn-link-underline {
  background: none;
  border: none;
  color: var(--primary-dark, #2b564c);
  font-family: var(--font-ui);
  font-size: 0.8125rem;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
  padding: 0 4px;
}

.btn-link-underline:hover {
  color: var(--primary);
}
  margin-bottom: var(--space-3);
}

.footer-privacy svg {
  color: var(--primary);
  flex-shrink: 0;
}

#app-footer {
  text-align: center;
  padding: var(--space-5) 0 var(--space-4);
  border-top: 1px solid var(--border-light);
  margin-top: var(--space-4);
}

.disclaimer {
  font-size: 0.8125rem;
  color: var(--text-muted);
  line-height: 1.6;
  max-width: 640px;
  margin: 0 auto var(--space-1);
}

.source-footer {
  font-size: 0.78125rem;
  color: var(--text-muted);
  margin-top: var(--space-2);
}

.source-footer-title {
  display: block;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.source-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px 8px;
}

.source-links a {
  color: var(--primary);
  text-decoration: underline;
  text-decoration-color: rgba(37, 99, 235, 0.3);
  text-underline-offset: 3px;
  transition: color 0.15s ease, text-decoration-color 0.15s ease;
}

.source-links a:hover {
  color: var(--primary-hover);
  text-decoration-color: var(--primary-hover);
}

.source-sep {
  color: var(--border);
  user-select: none;
}

.active-source-badge {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 6px;
  font-style: italic;
}

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

/* Mobile (<768px) */
@media (max-width: 767px) {
  #app {
    padding: 0 var(--space-2);
  }

  #app-header {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px 14px;
    margin: 0 calc(-1 * var(--space-2));
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid var(--border-light);
  }

  .header-left {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 12px;
  }

  .app-title {
    font-size: 1.15rem;
  }

  .child-selector select {
    font-size: 15px; /* Stops iOS Safari auto-zoom */
    padding: 8px 32px 8px 12px;
    height: 40px;
    border-radius: var(--radius-sm);
    min-width: 130px;
  }

  .header-right {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 10px;
    width: 100%;
    justify-content: flex-start;
  }

  .btn-nav-action {
    padding: 7px 12px;
    font-size: 0.8125rem;
    height: 38px;
    flex: 0 1 auto;
  }

  .unit-toggle {
    height: 38px;
    padding: 3px;
    align-items: center;
  }

  .unit-btn {
    padding: 4px 10px;
    font-size: 0.78125rem;
    height: 32px;
    font-weight: 600;
  }

  #tab-nav {
    position: sticky;
    top: 106px;
    z-index: 99;
    display: flex;
    gap: 4px;
    background: rgba(243, 242, 239, 0.92);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 4px;
    border-radius: var(--radius-md);
    margin: 8px 0 16px;
    border: 1px solid var(--border-light);
  }

  .tab {
    flex: 1;
    text-align: center;
    padding: 10px 8px;
    border-bottom: none !important;
    border-radius: var(--radius-sm);
    font-size: 0.84rem;
    font-weight: 500;
    white-space: nowrap;
  }

  .tab.active {
    background: var(--surface);
    color: var(--primary);
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(28, 43, 51, 0.08);
  }

  .chart-controls {
    display: flex;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 6px;
    gap: 6px;
    scrollbar-width: none;
  }

  .chart-controls::-webkit-scrollbar {
    display: none;
  }

  .chart-metric-btn {
    padding: 8px 14px;
    font-size: 0.8125rem;
    white-space: nowrap;
    min-height: 36px;
    flex-shrink: 0;
  }

  .chart-container {
    height: clamp(260px, 42vh, 340px);
    max-height: none;
    padding: 10px 8px;
  }

  /* Metric cards: 1-column responsive deck on mobile */
  .metric-cards {
    grid-template-columns: 1fr;
    gap: 10px;
    margin-bottom: var(--space-3);
  }

  .metric-card {
    padding: 14px 16px;
    text-align: left;
    border-radius: var(--radius-md);
  }

  .metric-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
  }

  .metric-label {
    font-size: 0.75rem;
  }

  .metric-updated {
    font-size: 0.72rem;
  }

  .metric-value-container {
    margin-bottom: 6px;
  }

  .metric-value {
    font-size: 1.5rem;
  }

  .metric-unit {
    font-size: 0.8125rem;
  }

  .metric-meta-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }

  .metric-percentile {
    font-size: 0.75rem;
    padding: 2px 8px;
  }

  .metric-trend {
    font-size: 0.75rem;
  }

  .metric-trend .trend-text {
    display: inline;
  }

  .form-row {
    flex-direction: column;
    gap: 12px;
  }

  .form-row .form-group {
    width: 100%;
  }

  .form-group label {
    font-size: 0.84rem;
    margin-bottom: 4px;
  }

  .form-group input,
  .form-group select {
    font-size: 16px !important; /* Critical: prevents iOS auto-zoom */
    height: 44px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
  }

  .form-row button[type="submit"],
  .section-card .btn-primary {
    width: 100%;
    height: 44px;
    font-size: 0.9375rem;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 8px;
  }

  .section-card {
    padding: 14px 16px;
    margin-bottom: var(--space-3);
    border-radius: var(--radius-md);
  }

  .table-wrapper {
    margin: 0 -4px;
    padding: 0 4px;
  }

  table {
    font-size: 0.84rem;
  }

  thead th {
    padding: 8px 6px 8px 0;
    font-size: 0.7rem;
  }

  tbody td {
    padding: 10px 6px 10px 0;
    font-size: 0.8125rem;
  }

  .overlay,
  .modal {
    padding: 12px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
  }

  .modal-card,
  .onboarding-card {
    padding: 20px 16px;
    width: 100%;
    max-width: 440px;
    max-height: 90vh;
    overflow-y: auto;
    border-radius: var(--radius-lg);
  }

  .export-option .export-desc {
    display: none;
  }

  .custom-chart-tooltip {
    min-width: 145px;
    max-width: 185px;
    padding: 8px 10px;
  }

  .custom-chart-tooltip .tooltip-btn {
    min-height: 36px;
    font-size: 0.75rem;
    padding: 6px 8px;
  }
}

/* Extra small devices (<380px) */
@media (max-width: 380px) {
  .app-title {
    font-size: 0.98rem;
  }

  .btn-icon {
    width: 34px;
    height: 34px;
  }

  .unit-btn {
    padding: 3px 6px;
    font-size: 0.7rem;
  }

  .tab {
    font-size: 0.78rem;
    padding: 8px 6px;
  }

  .metric-value {
    font-size: 1.35rem;
  }
}

/* Tablet (768px–1023px) */
@media (min-width: 768px) and (max-width: 1023px) {
  .metric-cards {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Third card spans full width on 2-col */
  .metric-card:nth-child(3) {
    grid-column: 1 / -1;
  }
}

/* Desktop (≥1024px) */
@media (min-width: 1024px) {
  .metric-cards {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* Large (≥1440px) */
@media (min-width: 1440px) {
  #app {
    padding: 0 var(--space-5);
  }

  .section-card {
    padding: var(--space-5);
  }
}

/* ============================================================
   Animations (prefers-reduced-motion)
   ============================================================ */
@media (prefers-reduced-motion: no-preference) {
  /* Modal slide-up entry */
  .modal .modal-card {
    animation: modal-slide-up 0.25s ease-out;
  }

  @keyframes modal-slide-up {
    from {
      opacity: 0;
      transform: translateY(16px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  /* Onboarding card fade in */
  .overlay .onboarding-card {
    animation: fade-in 0.3s ease-out;
  }

  @keyframes fade-in {
    from {
      opacity: 0;
      transform: translateY(8px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  /* Metric card subtle entrance */
  .metric-card {
    animation: card-enter 0.2s ease-out;
  }

  @keyframes card-enter {
    from {
      opacity: 0;
      transform: translateY(4px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
}

/* ============================================================
   Print Styles
   ============================================================ */
@media print {
  /* Hide interactive elements */
  #app-header .header-right,
  #tab-nav,
  .btn-primary,
  .btn-secondary,
  .btn-icon,
  .chart-controls,
  .modal,
  .overlay,
  #measurement-section,
  #log-vaccine-section,
  #log-checkup-section,
  .unit-toggle {
    display: none !important;
  }

  body {
    background: white;
    color: black;
    font-size: 12pt;
  }

  #app {
    max-width: 100%;
    padding: 0;
  }

  #app-header {
    position: static;
    border-bottom: 2px solid #333;
    margin: 0;
    padding: 8pt 0;
  }

  .chart-container {
    max-height: none;
    box-shadow: none;
    border: 1px solid #ccc;
    page-break-inside: avoid;
  }

  .metric-cards {
    grid-template-columns: repeat(3, 1fr);
    gap: 8pt;
  }

  .metric-card {
    box-shadow: none;
    border: 1px solid #ccc;
    page-break-inside: avoid;
  }

  .section-card {
    box-shadow: none;
    border: 1px solid #ccc;
    page-break-inside: avoid;
  }

  table {
    font-size: 10pt;
  }

  /* Show source citations */
  #app-footer {
    border-top: 1px solid #ccc;
    padding-top: 8pt;
  }

  .source-footer,
  .disclaimer,
  .source-citation {
    display: block !important;
    color: #555;
  }
}

/* ===== Custom Chart Tooltip ===== */
.custom-chart-tooltip {
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  box-shadow: var(--shadow-sm);
  font-family: var(--font-ui);
  font-size: 0.75rem;
  color: var(--ink);
  min-width: 125px;
  max-width: 160px;
  z-index: 1000;
  pointer-events: none;
  transition: opacity 0.1s ease-out;
  opacity: 0;
}

.custom-chart-tooltip .tooltip-title {
  font-weight: 600;
  margin-bottom: 2px;
  color: var(--ink);
  font-size: 0.8rem;
}

.custom-chart-tooltip .tooltip-body {
  font-family: var(--font-data);
  line-height: 1.35;
  font-size: 0.72rem;
  margin-bottom: 4px;
}

.custom-chart-tooltip .tooltip-label {
  color: var(--text-secondary);
  font-family: var(--font-ui);
}

.custom-chart-tooltip .tooltip-actions {
  display: flex;
  gap: 4px;
  border-top: 1px solid var(--border-light);
  padding-top: 4px;
  margin-top: 4px;
}

.custom-chart-tooltip .tooltip-btn {
  flex: 1;
  padding: 3px 6px;
  font-size: 0.68rem;
  font-weight: 500;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--surface);
  transition: background 0.1s;
}

.custom-chart-tooltip .tooltip-btn--edit {
  background: var(--primary);
}

.custom-chart-tooltip .tooltip-btn--edit:hover {
  background: #3e7367;
}

.custom-chart-tooltip .tooltip-btn--delete {
  background: #c94e4e;
}

.custom-chart-tooltip .tooltip-btn--delete:hover {
  background: #b03e3e;
}
