/* Aubade Patient App — CSS
   Brand restyle (2026-08-03 audit remediation, item 10): dawn palette per
   BRANDBOOK.md (Pre-dawn Indigo / Deep Night / First Light / Horizon Rose /
   Slate Mist / Bone / Ink / Ember / Meadow), Fraunces for display type,
   Inter for body — both self-hosted (see fonts.css), no external CDN.
   Dark circadian theme retained (ADHD-accessible: high contrast, no
   clutter) — the dawn gradient runs dark-to-light, so a dark app shell with
   warm gold/rose highlights is the on-brand execution, not a departure
   from it. */

@import url('./fonts.css');

:root {
  /* ── Brand tokens (BRANDBOOK.md) ──────────────────────────────────────── */
  --bg: #141634;           /* Deep Night */
  --surface: #2A2E5C;      /* Pre-dawn Indigo */
  --surface2: #363b78;     /* lighter indigo tint — nested elements/inputs */
  --border: #454b8a;       /* muted indigo-slate */
  --primary: #F2C572;      /* First Light — CTAs, highlights, active states */
  --primary-dark: #d9ab52; /* First Light, darkened — hover state */
  --primary-ink: #141634;  /* text color placed ON a --primary background (10.9:1) */
  --accent: #E88C7D;       /* Horizon Rose — warm accent, empathy states */
  --accent-green: #6FA07A; /* Meadow — signal-safe / confirmations */
  --accent-red: #EA9186;   /* Ember, lightened for text on dark surfaces (WCAG AA — see below) */
  --accent-red-strong: #C24B3E; /* Ember, true brand value — borders/backgrounds only, not small text on dark */
  --text: #F6F1E7;         /* Bone — body text on dark surfaces */
  /* --text-muted / --text-dim are lightened Slate Mist tints, not the raw
     #7B8AA8 swatch — raw Slate Mist is only 3.68:1 against --surface,
     below WCAG AA's 4.5:1 for normal text (2026-08-03 audit item 11).
     Verified via relative-luminance contrast calc against both --bg and
     --surface: text-muted 8.46:1 / 6.15:1, text-dim 6.81:1 / 4.95:1. */
  --text-muted: #A9B4CE;
  --text-dim: #93A1C4;
  --radius: 12px;
  --radius-sm: 8px;
  --font-display: 'Fraunces', Georgia, 'Times New Roman', serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.6;
  min-height: 100vh;
}

h1, h2, h3, .logo-text, .topbar-title, .metric-value {
  font-family: var(--font-display);
  letter-spacing: -0.01em;
}

/* Restore visible keyboard focus everywhere (2026-08-03 audit item 11) — a
   blanket `outline: none` on inputs previously removed it with no
   replacement, which is a WCAG 2.4.7 failure for keyboard/switch users.
   :focus-visible keeps mouse-click focus rings suppressed while keeping
   keyboard focus fully visible. */
a:focus-visible, button:focus-visible, input:focus-visible, textarea:focus-visible,
select:focus-visible, [tabindex]:focus-visible, .step-item:focus-visible,
.thread-item:focus-visible, .isi-scale-option:focus-within {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.screen { width: 100%; min-height: 100vh; }
.screen.hidden { display: none; }
.screen.active { display: block; }

/* ── Auth ──────────────────────────────────────────────────────────────────── */
#screen-auth {
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 60% 20%, #1c2050 0%, #141634 70%);
  padding: 1.5rem;
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  width: 100%; max-width: 400px;
  text-align: center;
}
.logo { display: flex; align-items: center; justify-content: center; gap: 0.5rem; margin-bottom: 0.5rem; }
.logo-icon { width: 2rem; height: 2rem; display: inline-block; vertical-align: middle; flex-shrink: 0; }
.topbar-left .logo-icon, .sidebar-logo .logo-icon { width: 1.5rem; height: 1.5rem; }
.logo-text { font-family: var(--font-display); font-size: 1.75rem; font-weight: 600; color: var(--primary); }
.tagline { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 2rem; }
.field { text-align: left; margin-bottom: 1rem; }
.field label { display: block; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 0.35rem; }
.field input, .field textarea {
  width: 100%; background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 0.65rem 0.9rem;
  color: var(--text); font-size: 1rem; transition: border-color 0.2s;
}
.field input:focus, .field textarea:focus { border-color: var(--primary); }
.auth-error { color: var(--accent-red); font-size: 0.85rem; min-height: 1.2rem; margin-top: 0.5rem; }
.disclaimer { font-size: 0.75rem; color: var(--text-dim); margin-top: 1.5rem; }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn-primary {
  width: 100%; background: var(--primary); color: var(--primary-ink); border: none;
  border-radius: var(--radius-sm); padding: 0.75rem 1.25rem;
  font-size: 1rem; font-weight: 600; cursor: pointer; transition: background 0.2s;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-secondary {
  background: transparent; border: 1px solid var(--primary); color: var(--primary);
  border-radius: var(--radius-sm); padding: 0.5rem 1rem; font-size: 0.9rem;
  cursor: pointer; transition: background 0.2s;
}
.btn-secondary:hover { background: var(--primary); color: var(--primary-ink); }
.btn-ghost {
  background: none; border: none; color: var(--text-muted); font-size: 0.9rem;
  cursor: pointer; padding: 0.25rem 0.5rem;
}
.btn-ghost:hover { color: var(--text); }
.btn-retry {
  background: var(--surface2); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius-sm); padding: 0.5rem 1rem; font-size: 0.85rem;
  cursor: pointer; margin-top: 0.75rem;
}
.btn-retry:hover { border-color: var(--primary); }

/* ── Main Layout ────────────────────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.25rem; position: sticky; top: 0; z-index: 10;
}
.topbar-left { display: flex; align-items: center; gap: 0.5rem; }
.topbar-title { font-weight: 600; font-size: 1.1rem; color: var(--primary); }
.topbar-right { display: flex; align-items: center; gap: 1rem; }
.greeting { font-size: 0.85rem; color: var(--text-muted); }

.bottom-nav {
  display: flex; background: var(--surface); border-top: 1px solid var(--border);
  position: fixed; bottom: 0; width: 100%; z-index: 10;
}
.nav-tab {
  flex: 1; background: none; border: none; color: var(--text-muted);
  padding: 0.9rem 0.5rem; font-size: 0.8rem; cursor: pointer; transition: color 0.2s;
  border-top: 2px solid transparent;
}
.nav-tab.active { color: var(--primary); border-top-color: var(--primary); font-weight: 600; }

.tab-content {
  padding: 1.25rem 1rem 5rem;
  max-width: 600px; margin: 0 auto;
}
.tab-content.hidden { display: none; }

/* ── Page elements ──────────────────────────────────────────────────────────── */
.page-header { margin-bottom: 1.25rem; }
.page-header h1 { font-size: 1.4rem; font-weight: 600; }
.subhead { font-size: 0.85rem; color: var(--text-muted); margin-top: 0.35rem; }
.loading-state { color: var(--text-muted); font-size: 0.9rem; padding: 2rem 0; text-align: center; }
.empty-state { text-align: center; padding: 2rem 1rem; color: var(--text-muted); }
.empty-state .btn-primary { max-width: 260px; margin: 1rem auto 0; }
.empty-state .btn-secondary { margin-top: 10px; }
.error-state { text-align: center; padding: 1.5rem 1rem; color: var(--accent-red); font-size: 0.9rem; }

/* ── Schedule items ─────────────────────────────────────────────────────────── */
.schedule-list { display: flex; flex-direction: column; gap: 0.75rem; margin-bottom: 1.5rem; }
.schedule-item {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem 1.1rem;
  display: flex; align-items: flex-start; gap: 0.9rem;
}
.schedule-item.morning_light { border-left: 3px solid var(--primary); }
.schedule-item.evening_dim { border-left: 3px solid #7b8ad0; }
.schedule-item.melatonin_reminder { border-left: 3px solid var(--accent-green); }
.schedule-item.blue_light_cutoff { border-left: 3px solid var(--accent); }
.schedule-item.target_wake { border-left: 3px solid #60b8f0; }
.sched-icon { font-size: 1.4rem; margin-top: 0.1rem; }
.sched-body { flex: 1; }
.sched-time { font-weight: 700; font-size: 1rem; color: var(--text); }
.sched-label { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.sched-instruction { font-size: 0.9rem; color: var(--text-muted); margin-top: 0.25rem; }

/* ── Protocol steps ─────────────────────────────────────────────────────────── */
.protocol-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem;
}
.protocol-card h2 { font-size: 1rem; font-weight: 600; margin-bottom: 1rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.steps-list { display: flex; flex-direction: column; gap: 0.6rem; }
.step-item {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.6rem 0.75rem; border-radius: var(--radius-sm);
  background: var(--surface2); cursor: pointer; transition: background 0.15s;
}
.step-item:hover { background: var(--border); }
.step-check {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--border); display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; flex-shrink: 0; transition: all 0.2s;
}
.step-item.done .step-check { background: var(--accent-green); border-color: var(--accent-green); color: var(--primary-ink); }
.step-title { font-size: 0.9rem; }
.step-item.done .step-title { color: var(--text-muted); text-decoration: line-through; }
.streak-badge {
  margin-top: 1rem; text-align: center; background: var(--surface2);
  border-radius: var(--radius-sm); padding: 0.6rem;
  font-size: 0.85rem; color: var(--primary);
}

/* ── Plan card ──────────────────────────────────────────────────────────────── */
.plan-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.5rem; display: flex; flex-direction: column; gap: 1rem;
}
.plan-metric {}
.metric-label { display: block; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); }
.metric-value { display: block; font-size: 1.5rem; font-weight: 600; color: var(--primary); }
.metric-note { font-size: 0.8rem; color: var(--text-dim); }
.disclaimer-text { color: var(--accent-red); }
.disclaimer-box {
  margin-top: 1rem; background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 0.75rem 1rem;
  font-size: 0.8rem; color: var(--text-muted);
}

/* ── Progress charts (simple bars) ─────────────────────────────────────────── */
.progress-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1rem;
}
.progress-card h2 { font-size: 0.9rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 1rem; }
.adherence-chart, .sleep-chart { display: flex; align-items: flex-end; gap: 6px; height: 80px; }
.chart-bar-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.chart-bar {
  width: 100%; background: var(--primary); border-radius: 4px 4px 0 0;
  min-height: 4px; transition: height 0.3s;
}
.chart-bar.incomplete { background: var(--border); }
.chart-label { font-size: 0.65rem; color: var(--text-dim); }

/* ── Coach threads ──────────────────────────────────────────────────────────── */
.threads-list { display: flex; flex-direction: column; gap: 0.6rem; }
.thread-item {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem;
  cursor: pointer; transition: border-color 0.2s;
}
.thread-item:hover { border-color: var(--primary); }
.thread-subject { font-weight: 600; font-size: 0.95rem; }
.thread-meta { font-size: 0.78rem; color: var(--text-muted); margin-top: 0.2rem; }
.thread-view { display: flex; flex-direction: column; gap: 0.75rem; }
.messages-list { display: flex; flex-direction: column; gap: 0.75rem; min-height: 300px; }
.message-bubble {
  max-width: 80%; padding: 0.75rem 1rem; border-radius: var(--radius);
  font-size: 0.9rem;
}
.message-bubble.from-patient { background: var(--primary); color: var(--primary-ink); align-self: flex-end; border-radius: var(--radius) var(--radius) 4px var(--radius); }
.message-bubble.from-coach { background: var(--surface2); align-self: flex-start; border-radius: var(--radius) var(--radius) var(--radius) 4px; }
.reply-form { display: flex; gap: 0.5rem; align-items: flex-end; margin-top: 0.5rem; }
.reply-form textarea {
  flex: 1; background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text); padding: 0.65rem;
  font-size: 0.9rem; resize: none;
}
.reply-form textarea:focus { border-color: var(--primary); }
.reply-form .btn-primary { width: auto; white-space: nowrap; }
.new-thread-form { display: flex; flex-direction: column; gap: 1rem; }
.back-btn { margin-bottom: 0.5rem; }

/* ── ISI Check-in (item 9) ──────────────────────────────────────────────────
   7-item Insomnia Severity Index (Bastien 2001), styled consistently with
   the onboarding questionnaire's fieldset/legend structure but themed for
   the dark in-app shell. */
.isi-intro { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 1rem; }
.isi-question {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem 1.1rem; margin-bottom: 1rem;
}
.isi-question legend {
  font-weight: 600; font-size: 0.92rem; padding: 0 0 0.7rem 0; color: var(--text);
  float: left; width: 100%;
}
.isi-scale { display: flex; flex-wrap: wrap; gap: 0.5rem; clear: both; }
.isi-scale-option {
  flex: 1 1 18%; min-width: 88px; display: flex; flex-direction: column;
  align-items: center; gap: 0.35rem; background: var(--surface2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 0.5rem 0.4rem; cursor: pointer; font-size: 0.72rem; text-align: center;
  color: var(--text-muted); transition: border-color .15s, color .15s;
}
.isi-scale-option.selected { border-color: var(--primary); color: var(--text); }
.isi-scale-option input { margin: 0; }
.isi-band { font-family: var(--font-display); font-size: 1.4rem; font-weight: 600; }
.isi-band-noClinical { color: var(--accent-green); }
.isi-band-subthreshold { color: var(--primary); }
.isi-band-moderate { color: var(--accent); }
.isi-band-severe { color: var(--accent-red); }
.isi-history-item { display: flex; justify-content: space-between; padding: 0.5rem 0; border-bottom: 1px solid var(--border); font-size: 0.85rem; }
.isi-history-item:last-child { border-bottom: none; }

/* ── Venture banner (index.html top strip) ─────────────────────────────────── */
.venture-banner {
  background: #F6F1E7; border-bottom: 1px solid #e3dcc8;
  padding: 14px 24px; display: flex; align-items: center; gap: 14px;
  font-family: var(--font-body);
}
.venture-banner-text { flex: 1; }
.venture-banner-title { font-family: var(--font-display); font-weight: 600; font-size: 16px; color: #2A2E5C; }
.venture-banner-sub { font-size: 12px; color: #556080; margin-top: 2px; }
.venture-banner-link { color: #A83A2D; text-decoration: none; }
.venture-banner-link:hover { text-decoration: underline; }

/* ── Inline-style migration utilities (CSP: no style="" attributes) ───────────── */
.muted-text { color: var(--text-muted); }
.muted-text-sm { color: var(--text-muted); font-size: 0.85rem; }
.muted-text-md { color: var(--text-muted); font-size: 0.9rem; }

/* Bucketed chart-bar heights (nearest 5%, scale: n * 0.75px, min 4px) — replaces
   dynamic style="height:...px" on adherence/sleep chart bars. See heightBucket()
   in app.js. */
.bar-h-0 { height: 4px; }
.bar-h-5 { height: 4px; }
.bar-h-10 { height: 8px; }
.bar-h-15 { height: 11px; }
.bar-h-20 { height: 15px; }
.bar-h-25 { height: 19px; }
.bar-h-30 { height: 23px; }
.bar-h-35 { height: 26px; }
.bar-h-40 { height: 30px; }
.bar-h-45 { height: 34px; }
.bar-h-50 { height: 38px; }
.bar-h-55 { height: 41px; }
.bar-h-60 { height: 45px; }
.bar-h-65 { height: 49px; }
.bar-h-70 { height: 53px; }
.bar-h-75 { height: 56px; }
.bar-h-80 { height: 60px; }
.bar-h-85 { height: 64px; }
.bar-h-90 { height: 68px; }
.bar-h-95 { height: 71px; }
.bar-h-100 { height: 75px; }

/* ── Onboarding page (onboarding.html) ─────────────────────────────────────────
   Moved out of a page-local <style> block for CSP hardening (styleSrc no
   longer allows 'unsafe-inline', which covers <style> elements too).
   Light card on a light page background (BRANDBOOK.md Bone/Ink), distinct
   from the dark in-app shell — onboarding is a one-time, form-heavy flow
   better read at high contrast on a plain light page. */
body.onboarding-page { background: #F6F1E7; }
.onboarding-card {
  max-width: 640px; margin: 40px auto; padding: 24px;
  background: #FFFFFF; color: #101018; border: 1px solid #e3dcc8;
}
.onboarding-card h1 { font-family: var(--font-display); color: #2A2E5C; font-size: 1.6rem; margin-bottom: 0.5rem; }
.step-help-text { font-size: 0.9em; color: #556080; }
.step { display: none; }
.step.active { display: block; }
.nav-buttons { margin-top: 20px; display: flex; justify-content: space-between; gap: 10px; }
.nav-buttons button {
  background: var(--surface, #2A2E5C); color: #F6F1E7; border: none;
  border-radius: 8px; padding: 0.6rem 1.1rem; font-size: 0.9rem; cursor: pointer;
}
.nav-buttons button:hover { background: #363b78; }
.nav-buttons button:disabled { opacity: 0.5; cursor: not-allowed; }
fieldset.step-fieldset { border: 1px solid #e3dcc8; padding: 16px; border-radius: 8px; margin-bottom: 12px; }
legend { font-weight: 600; font-family: var(--font-display); padding: 0 6px; color: #2A2E5C; }
.field-row { margin: 8px 0; display: block; }
.field-row label { display: block; margin-bottom: 4px; color: #101018; }
.field-row input {
  width: 100%; max-width: 320px; border: 1px solid #cfc7ae; border-radius: 6px;
  padding: 0.45rem 0.6rem; font-size: 0.95rem; color: #101018; background: #fff;
}
.checkbox-row { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.checkbox-row input[type=checkbox] { margin: 0; }
.checkbox-row label { color: #101018; }
.error-message { color: #A83A2D; font-size: 0.9em; margin-top: 4px; min-height: 1.2em; }
.error-message.status-ok { color: #3F7048; }
.progress-indicator { font-size: 0.9em; color: #556080; margin-bottom: 12px; }
.honest-gate { background: #F6F1E7; border-left: 4px solid #A83A2D; padding: 14px; margin-bottom: 18px; }
.honest-gate h3 { font-family: var(--font-display); margin: 0 0 6px 0; color: #2A2E5C; }
.honest-gate p { margin: 6px 0; font-size: 0.95em; color: #101018; }

/* ── Responsive (item 11) ─────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .auth-card { padding: 2rem 1.25rem; max-width: 100%; }
  .isi-scale-option { flex-basis: 30%; }
}
