:root {
  --bg: #f5f9ff;
  --surface: #ffffff;
  --surface-soft: #f0f6ff;
  --ink: #061442;
  --ink-2: #334155;
  --muted: #64748b;
  --border: #dce7f5;
  --brand: #0284c7;
  --brand-dark: #061442;
  --accent: #f59e0b;
  --emerald: #059669;
  --emerald-soft: #ecfdf5;
  --rose: #e11d48;
  --rose-soft: #fff1f2;
  --amber-soft: #fffbeb;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow: 0 8px 24px -10px rgba(6, 20, 66, 0.12);
  --header-h: 64px;
  --z-header: 40;
  --z-modal: 60;
  --z-toast: 80;
}

[data-theme="night"] {
  --bg: #070d1f;
  --surface: #101935;
  --surface-soft: #172347;
  --ink: #f1f5f9;
  --ink-2: #cbd5e1;
  --muted: #94a3b8;
  --border: #24335c;
  --brand: #38bdf8;
  --brand-dark: #1d4ed8;
  --emerald-soft: rgba(16, 185, 129, 0.14);
  --rose-soft: rgba(244, 63, 94, 0.15);
  --amber-soft: rgba(245, 158, 11, 0.15);
  --shadow: 0 10px 28px -10px rgba(0, 0, 0, 0.55);
}

*, *::before, *::after { box-sizing: border-box; }
html { font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif; font-size: 15px; scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--ink); line-height: 1.5; min-height: 100vh; padding-bottom: 84px; }
@media (min-width: 960px) { body { padding-bottom: 32px; } }
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); text-decoration: none; }

/* Top Header (Top-Only Navigation Architecture) */
.a-header {
  position: sticky; top: 0; z-index: var(--z-header);
  background: var(--surface); border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
}
.a-header-inner {
  max-width: 1220px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.a-brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex-shrink: 0; }
.a-brand a { display: inline-flex; align-items: center; flex-shrink: 0; }
.a-brand img { height: 34px; width: auto; object-fit: contain; background: #fff; border-radius: 10px; padding: 3px 7px; }
.a-brand-pill {
  font-size: 11px; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase;
  background: linear-gradient(135deg, #061442, #0284c7); color: #fff;
  padding: 4px 10px; border-radius: 999px; white-space: nowrap;
}
.a-top-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.a-icon-btn {
  height: 36px; padding: 0 11px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface-soft); color: var(--ink); font-size: 12px; font-weight: 700;
  display: inline-flex; align-items: center; gap: 5px; cursor: pointer; transition: 0.16s ease;
  white-space: nowrap;
}
.a-icon-btn:hover { border-color: var(--brand); }
.a-icon-btn.primary { background: #061442; color: #fff; border-color: #061442; }
[data-theme="night"] .a-icon-btn.primary { background: #0284c7; border-color: #0284c7; }
@media (max-width: 639px) {
  .a-header-inner { padding: 8px 12px; gap: 6px; }
  .a-brand img { height: 28px; padding: 2px 5px; }
  .a-brand-pill { display: none; }
  .a-top-actions { gap: 5px; }
  .a-icon-btn { height: 32px; padding: 0 8px; font-size: 11px; gap: 3px; border-radius: 10px; }
  .a-hide-xs { display: none; }
}

/* Desktop Top Tab Navigation */
.a-nav-bar {
  background: var(--surface); border-bottom: 1px solid var(--border);
  overflow-x: auto; scrollbar-width: none;
}
.a-nav-bar::-webkit-scrollbar { display: none; }
.a-nav-inner {
  max-width: 1220px; margin: 0 auto; padding: 8px 16px;
  display: flex; align-items: center; gap: 6px;
}
.a-nav-tab {
  padding: 8px 13px; border-radius: 12px; border: 1px solid transparent;
  background: transparent; color: var(--ink-2); font-size: 12.5px; font-weight: 700;
  cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px;
  transition: 0.16s ease;
}
.a-nav-tab:hover { background: var(--surface-soft); color: var(--ink); }
.a-nav-tab.is-active {
  background: linear-gradient(135deg, #061442, #0c2c72); color: #fff;
  box-shadow: 0 4px 12px -4px rgba(6, 20, 66, 0.35);
}
[data-theme="night"] .a-nav-tab.is-active { background: #0284c7; }

/* Mobile Bottom Tab Bar */
.a-bottom-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-header);
  background: var(--surface); border-top: 1px solid var(--border);
  display: grid; grid-template-columns: repeat(6, minmax(0, 1fr));
  padding: 6px 4px env(safe-area-inset-bottom, 6px);
  box-shadow: 0 -6px 20px -10px rgba(6, 20, 66, 0.18);
}
@media (min-width: 960px) { .a-bottom-bar { display: none; } }
.a-bnav-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: none; border: none; color: var(--muted); font-size: 10px; font-weight: 700;
  padding: 4px 2px; border-radius: 10px; cursor: pointer;
}
.a-bnav-btn span:first-child { font-size: 17px; line-height: 1.1; }
.a-bnav-btn.is-active { color: var(--brand); background: var(--surface-soft); font-weight: 800; }

/* Main Layout */
.a-main { max-width: 1220px; margin: 0 auto; padding: 18px 16px 28px; }
.a-view { display: none; }
.a-view.is-active { display: block; animation: fadeIn 0.18s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* Reusable Cards & Grids */
.a-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 18px; box-shadow: var(--shadow);
}
.a-card-dark {
  background: linear-gradient(135deg, #061442 0%, #0b2663 100%);
  color: #fff; border-radius: var(--radius-lg); padding: 20px; box-shadow: var(--shadow);
}
.a-grid-2 { display: grid; grid-template-columns: 1fr; gap: 16px; }
.a-grid-3 { display: grid; grid-template-columns: 1fr; gap: 14px; }
.a-grid-4 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (min-width: 720px) {
  .a-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .a-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 960px) {
  .a-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

/* Profile Hero Banner */
.a-profile-hero {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 14px;
  margin-bottom: 18px;
}
.a-avatar {
  width: 56px; height: 56px; border-radius: 18px;
  background: rgba(255, 255, 255, 0.16); border: 2px solid rgba(255, 255, 255, 0.35);
  display: flex; align-items: center; justify-content: center; font-size: 28px; flex-shrink: 0;
}
.a-kicker { font-size: 11px; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; opacity: 0.85; }
.a-h1 { margin: 2px 0 4px; font-size: 22px; font-weight: 900; line-height: 1.2; }
.a-h2 { margin: 0 0 8px; font-size: 17px; font-weight: 900; color: var(--ink); }
.a-h3 { margin: 0 0 6px; font-size: 14.5px; font-weight: 800; color: var(--ink); }
.a-muted { color: var(--muted); font-size: 12.5px; margin: 0; }
.a-stack { display: flex; flex-direction: column; gap: 14px; }
.a-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }

/* Pills, Badges, Buttons */
.a-badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px;
  border-radius: 999px; font-size: 11px; font-weight: 800;
  background: var(--surface-soft); color: var(--brand); border: 1px solid var(--border);
}
.a-badge.ok { background: var(--emerald-soft); color: var(--emerald); border-color: rgba(5, 150, 105, 0.25); }
.a-badge.warn { background: var(--amber-soft); color: #b45309; border-color: rgba(245, 158, 11, 0.35); }
.a-badge.danger { background: var(--rose-soft); color: var(--rose); border-color: rgba(225, 29, 72, 0.3); }

.a-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 15px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--ink); font-size: 12.5px; font-weight: 800;
  cursor: pointer; transition: 0.16s ease;
}
.a-btn:hover { border-color: var(--brand); }
.a-btn.brand { background: #0284c7; color: #fff; border-color: #0284c7; }
.a-btn.brand:hover { background: #0369a1; }
.a-btn.navy { background: #061442; color: #fff; border-color: #061442; }
.a-btn.amber { background: #f59e0b; color: #061442; border-color: #f59e0b; }
.a-btn.emerald { background: #059669; color: #fff; border-color: #059669; }
.a-btn.rose { background: #e11d48; color: #fff; border-color: #e11d48; }
.a-btn.sm { padding: 6px 11px; font-size: 11.5px; border-radius: 10px; }

.a-input, .a-select {
  width: 100%; padding: 9px 12px; border-radius: 11px; border: 1px solid var(--border);
  background: var(--surface-soft); color: var(--ink); font-size: 13px; font-weight: 600;
}
.a-label { display: block; font-size: 11.5px; font-weight: 800; color: var(--ink-2); margin-bottom: 5px; }

/* KPI Mini Card */
.a-kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 14px; display: flex; flex-direction: column; gap: 4px;
}
.a-kpi-val { font-size: 19px; font-weight: 900; color: var(--ink); line-height: 1.15; }
.a-kpi-lbl { font-size: 11px; font-weight: 700; color: var(--muted); }

/* Leap Timeline */
.a-leap-card {
  border: 1px solid var(--border); border-radius: 16px; padding: 14px; background: var(--surface);
  display: flex; flex-direction: column; gap: 6px;
}
.a-leap-card.is-current { border-color: #f59e0b; background: var(--amber-soft); box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.25); }
.a-leap-card.is-past { opacity: 0.72; }

/* Timer & Sound Mixer */
.a-timer-display { font-size: 32px; font-weight: 900; font-variant-numeric: tabular-nums; letter-spacing: 0.03em; color: var(--ink); }
.a-sound-card {
  border: 1px solid var(--border); border-radius: 16px; padding: 14px; background: var(--surface);
  display: flex; flex-direction: column; gap: 10px; transition: 0.16s ease;
}
.a-sound-card.is-playing { border-color: #0284c7; background: var(--surface-soft); box-shadow: 0 0 0 2px rgba(2, 132, 199, 0.18); }
.a-range { width: 100%; accent-color: #0284c7; cursor: pointer; }

/* Teeth Interactive Chart */
.a-teeth-row { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 5px; }
.a-tooth {
  aspect-ratio: 1 / 1.25; border-radius: 8px 8px 12px 12px; border: 1.5px solid var(--border);
  background: var(--surface-soft); color: var(--muted); font-size: 10px; font-weight: 800;
  display: flex; flex-direction: column; align-items: center; justify-content: center; cursor: pointer;
}
.a-tooth.is-out { background: #fef3c7; border-color: #f59e0b; color: #92400e; }

/* Food 3-Day Rule Cards */
.a-food-card {
  border: 1px solid var(--border); border-radius: 14px; padding: 12px; background: var(--surface);
  display: flex; flex-direction: column; gap: 8px;
}
.a-day-dots { display: flex; gap: 6px; }
.a-day-dot {
  flex: 1; padding: 5px 4px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-soft); font-size: 10.5px; font-weight: 800; cursor: pointer; text-align: center;
}
.a-day-dot.is-done { background: #059669; border-color: #059669; color: #fff; }

/* Guide & Product Cards */
.a-media-card {
  border: 1px solid var(--border); border-radius: 18px; overflow: hidden; background: var(--surface);
  display: flex; flex-direction: column; justify-content: space-between;
}
.a-media-thumb { aspect-ratio: 3 / 2; width: 100%; overflow: hidden; background: var(--surface-soft); }
.a-media-thumb img { width: 100%; height: 100%; object-fit: cover; }
.a-media-body { padding: 14px; display: flex; flex-direction: column; gap: 6px; }

/* Log List */
.a-log-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 12px; border-radius: 12px; background: var(--surface-soft); border: 1px solid var(--border);
  font-size: 12.5px;
}

/* Modal & Toast */
.a-modal {
  position: fixed; inset: 0; z-index: var(--z-modal);
  background: rgba(6, 20, 66, 0.72); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.a-modal.hidden { display: none; }
.a-modal-box {
  background: var(--surface); color: var(--ink); border: 1px solid var(--border);
  border-radius: 22px; max-width: 580px; width: 100%; max-height: 88vh; overflow-y: auto;
  padding: 22px; box-shadow: 0 24px 48px -12px rgba(0, 0, 0, 0.45);
}
.a-toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%); z-index: var(--z-toast);
  background: #061442; color: #fff; font-size: 12.5px; font-weight: 800;
  padding: 10px 18px; border-radius: 999px; box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
  transition: opacity 0.2s ease; pointer-events: none;
}
.a-toast.hidden { opacity: 0; }
.a-pwa-bar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 14px; border-radius: 14px; background: #eff6ff; border: 1px solid #bae6fd;
  color: #061442; font-size: 12px; font-weight: 700; margin-bottom: 14px;
}
.a-pwa-bar.hidden { display: none; }

/* Printable A4 Pediatrician Report */
#a4DoctorReport { display: none; }
@media print {
  body { background: #fff; color: #000; padding: 0; }
  body > *:not(#a4DoctorReport) { display: none; }
  #a4DoctorReport { display: block; padding: 18px; font-size: 12.5px; }
}
