:root {
  --navy: #1F3A5F;
  --navy-dark: #16293F;
  --teal: #0E7C7B;
  --teal-tint: #E6F3F2;
  --coral: #E76F51;
  --coral-tint: #FDEEE7;
  --green: #2A9D6F;
  --green-tint: #EAF6EF;
  --amber: #C98A1E;
  --amber-tint: #FDF3E3;
  --red: #B23A2C;
  --red-tint: #FCE4E1;
  --text: #1A2E2C;
  --muted: #5C6470;
  --bg: #F6F8F9;
  --white: #FFFFFF;
  --border: #E7ECEE;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.muted { color: var(--muted); }
.small { font-size: 0.85em; }
.icon { width: 20px; height: 20px; display: inline-block; vertical-align: -5px; }
.icon-lg { width: 26px; height: 26px; }

/* ---------- Auth screen ---------- */
.auth-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--navy); padding: 24px; }
.auth-card { background: var(--white); border-radius: 16px; padding: 32px; max-width: 380px; width: 100%; }
.brand { display: flex; align-items: center; justify-content: center; margin-bottom: 8px; }
.logo-mark { height: 64px; }
.logo-mini { height: 28px; }
.auth-card form { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.auth-card input, .auth-card select, .auth-card textarea {
  padding: 10px 12px; border: 1px solid #DDE3E8; border-radius: 8px; font-size: 14px;
}
.auth-divider { text-align: center; margin: 18px 0 8px; color: var(--muted); font-size: 13px; }
.error-msg { background: var(--coral-tint); color: var(--coral); padding: 10px; border-radius: 8px; font-size: 13px; margin-bottom: 10px; }

/* ---------- Buttons ---------- */
.btn-primary, .btn-secondary, .btn-ghost {
  border: none; border-radius: 10px; padding: 11px 16px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.btn-primary { background: var(--teal); color: white; }
.btn-secondary { background: var(--teal-tint); color: var(--teal); }
.btn-ghost { background: transparent; color: var(--muted); text-decoration: underline; }

/* ---------- Topbar ---------- */
.topbar {
  background: var(--navy); color: white; padding: 12px 20px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; z-index: 10;
}
.topbar-right { display: flex; align-items: center; gap: 14px; }
.topbar .btn-ghost { color: #BFD3E8; }

.view { max-width: 720px; margin: 0 auto; padding: 20px; }

/* ---------- Welcome banner ---------- */
.welcome-banner { margin-bottom: 16px; }
.welcome-banner h2 { margin: 0 0 2px; font-size: 20px; color: var(--navy); }
.welcome-banner p { margin: 0; color: var(--muted); font-size: 13.5px; }

/* ---------- Generic card ---------- */
.card { background: var(--white); border-radius: 14px; padding: 18px; margin-bottom: 14px; border: 1px solid var(--border); }
.card h3 { margin-top: 0; margin-bottom: 10px; color: var(--navy); font-size: 15px; display: flex; align-items: center; gap: 8px; }

/* ---------- Band header card ---------- */
.band-header { border-radius: 16px; padding: 18px 20px; margin-bottom: 14px; background: var(--navy); transition: background 0.2s; }
.band-header.low { background: linear-gradient(135deg, #14332A, #1B4A3A); }
.band-header.borderline { background: linear-gradient(135deg, #3D2E12, #5C4319); }
.band-header.intermediate { background: linear-gradient(135deg, #4A2416, #6B331F); }
.band-header.high { background: linear-gradient(135deg, #4A1712, #6E1F16); }
.band-header-top { display: flex; justify-content: space-between; align-items: center; }
.band-header-label { color: #9FD8D2; font-size: 12px; }
.band-pill { font-size: 11px; font-weight: 600; padding: 4px 12px; border-radius: 20px; }
.band-pill.low { background: var(--green-tint); color: #1B5E42; }
.band-pill.borderline { background: var(--amber-tint); color: #7A4E0F; }
.band-pill.intermediate { background: var(--coral-tint); color: #7A3419; }
.band-pill.high { background: var(--red-tint); color: #6E1F16; }
.band-number { color: white; font-size: 26px; font-weight: 600; margin: 6px 0 2px; }
.band-number span { font-size: 12px; font-weight: 400; color: #9FD8D2; }
.band-detail-btn { background: transparent; border: 1px solid #3A6E68; color: #C8E8E4; font-size: 12px; padding: 7px 10px; border-radius: 8px; width: 100%; margin-top: 10px; cursor: pointer; }
.band-explain { background: #16342F; border-radius: 10px; padding: 12px; margin-top: 10px; font-size: 12.5px; color: #C8E8E4; }

/* ---------- Metric tiles ---------- */
.metric-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.metric-tile { border-radius: 12px; padding: 14px; cursor: pointer; border: none; text-align: left; width: 100%; }
.metric-tile.sleep { background: var(--teal-tint); }
.metric-tile.activity { background: var(--green-tint); }
.metric-tile-val { font-size: 19px; font-weight: 600; margin: 6px 0 0; }
.metric-tile.sleep .metric-tile-val { color: #08423F; }
.metric-tile.activity .metric-tile-val { color: #1B5E42; }
.metric-tile-label { font-size: 11px; margin: 0; }
.metric-tile.sleep .metric-tile-label { color: var(--teal); }
.metric-tile.activity .metric-tile-label { color: var(--green); }
.trend-tag.up { color: var(--green); }
.trend-tag.down { color: var(--coral); }

/* ---------- Tip callout ---------- */
.tip-callout { border-left: 3px solid var(--coral); background: var(--coral-tint); border-radius: 0 10px 10px 0; padding: 10px 14px; margin-bottom: 14px; font-size: 12.5px; color: #7A3419; }
.tip-callout.teal { border-left-color: var(--teal); background: var(--teal-tint); color: #08423F; }
.tip-callout.green { border-left-color: var(--green); background: var(--green-tint); color: #1B5E42; }

/* ---------- Referral buttons ---------- */
.referral-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.referral-btn { background: var(--white); border: 1px solid var(--border); border-radius: 10px; padding: 12px; text-align: left; cursor: pointer; }
.referral-btn p { margin: 6px 0 0; font-size: 12.5px; font-weight: 600; color: var(--text); }
.referral-btn span.d { display: block; font-size: 11px; color: var(--muted); font-weight: 400; margin-top: 2px; }

/* ---------- Badges / pills ---------- */
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 3px 10px; border-radius: 20px; }
.badge.open { background: var(--amber-tint); color: #7A4E0F; }
.badge.answered { background: var(--green-tint); color: #1B5E42; }

/* ---------- Forms ---------- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.checkbox { display: flex; align-items: center; gap: 6px; font-size: 14px; grid-column: span 2; }
input[type="range"] { width: 100%; margin: 6px 0 14px; accent-color: var(--teal); }
input[type="time"], input[type="number"], input[type="text"], input[type="email"], input[type="password"], select, textarea {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; width: 100%; font-family: inherit;
}
textarea { min-height: 70px; margin-bottom: 10px; }
input[type="file"] { margin: 8px 0; font-size: 13px; }
.unit-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin-left: 6px; }
.unit-toggle button { border: none; background: var(--white); padding: 4px 8px; font-size: 11px; cursor: pointer; color: var(--muted); }
.unit-toggle button.active { background: var(--teal); color: white; }

/* ---------- Stat cards (corporate/founder) ---------- */
.stat-card { background: var(--teal-tint); border-radius: 12px; padding: 16px; text-align: center; }
.stat-num { font-size: 24px; font-weight: 600; color: var(--teal); }
.stat-label { font-size: 11.5px; color: var(--muted); margin-top: 4px; }

/* ---------- Lists ---------- */
.list-item { padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.list-item:last-child { border-bottom: none; }
.clickable { cursor: pointer; }
.clickable:hover { color: var(--teal); }

/* ---------- Chart bars ---------- */
.chart-wrap { display: flex; align-items: flex-end; gap: 6px; height: 90px; margin: 10px 0; }
.chart-bar { flex: 1; background: var(--teal); border-radius: 4px 4px 0 0; min-height: 3px; position: relative; }
.chart-bar .v { position: absolute; top: -16px; left: 0; right: 0; text-align: center; font-size: 9px; color: var(--muted); }
.chart-labels { display: flex; gap: 6px; }
.chart-labels span { flex: 1; text-align: center; font-size: 9px; color: var(--muted); }

/* ---------- Progress bar (goals) ---------- */
.progress-track { background: var(--border); border-radius: 20px; height: 8px; overflow: hidden; margin: 8px 0; }
.progress-fill { background: var(--teal); height: 100%; border-radius: 20px; }

/* ---------- Upload dropzone ---------- */
.dropzone { border: 1.5px dashed var(--border); border-radius: 12px; padding: 18px; text-align: center; background: var(--teal-tint); margin-bottom: 10px; }
.dropzone .icon { margin-bottom: 4px; }
.doc-item { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.doc-item:last-child { border-bottom: none; }

/* ---------- Toggle switch (checklist) ---------- */
.toggle-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; }
.toggle-row span { font-size: 13.5px; }
.toggle { position: relative; width: 42px; height: 24px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle .slider { position: absolute; inset: 0; background: var(--border); border-radius: 20px; cursor: pointer; transition: 0.15s; }
.toggle .slider:before { content: ""; position: absolute; height: 18px; width: 18px; left: 3px; top: 3px; background: white; border-radius: 50%; transition: 0.15s; }
.toggle input:checked + .slider { background: var(--teal); }
.toggle input:checked + .slider:before { transform: translateX(18px); }

/* ---------- Profile edit ---------- */
.profile-summary { background: var(--teal-tint); border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; font-size: 13px; }
.profile-summary .row { display: flex; justify-content: space-between; padding: 3px 0; }
.edit-toggle-btn { background: var(--white); border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px; font-size: 12.5px; color: var(--teal); cursor: pointer; }

/* ---------- Segment picker (founder broadcast) ---------- */
.segment-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.segment-chip { border: 1px solid var(--border); background: var(--white); border-radius: 20px; padding: 6px 14px; font-size: 12.5px; cursor: pointer; }
.segment-chip.active { background: var(--teal); color: white; border-color: var(--teal); }

/* ---------- Nudge template chips ---------- */
.template-chip { display: inline-block; border: 1px solid var(--border); background: var(--teal-tint); color: #08423F; border-radius: 8px; padding: 8px 10px; font-size: 12px; margin: 0 6px 6px 0; cursor: pointer; text-align: left; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #10231F; --white: #16302B; --text: #E6F2EF; --muted: #9FB4B0; --border: #24443D;
    --teal-tint: #17332F; --green-tint: #17332F; --coral-tint: #2E211A; --amber-tint: #2E2A1A; --red-tint: #2E1D19;
  }
  body { background: var(--bg); }
  .auth-card input, .auth-card select { background: #1B3B35; color: var(--text); border-color: #2E534C; }
}

/* ---------- v5 additions ---------- */
body { font-size: 17px; }
.overlay { position: fixed; inset: 0; background: rgba(11,28,52,.82); z-index: 1000; display: flex; align-items: flex-start; justify-content: center; overflow-y: auto; padding: 20px 14px; }
.overlay-card { background: #fff; border-radius: 16px; max-width: 520px; width: 100%; padding: 22px; margin: auto; }
.big-text { font-size: 19px; line-height: 1.45; }
.sos-btn { width: 100%; margin-bottom: 14px; padding: 14px; border-radius: 12px; border: 2px solid #B3261E; background: #FDECEA; color: #B3261E; font-weight: 700; font-size: 16px; cursor: pointer; }
.sos-call { display: block; text-align: center; text-decoration: none; background: #B3261E !important; font-size: 22px; padding: 16px; border-radius: 12px; color: #fff; }
.emergency-banner { background: #B3261E; color: #fff; border-radius: 12px; padding: 16px; margin-bottom: 14px; font-size: 18px; line-height: 1.45; }
.emergency-banner a { color: #fff; font-weight: 800; }
.consent-item { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid #E6ECEF; font-size: 15px; line-height: 1.45; }
.consent-item input { margin-top: 4px; width: 20px; height: 20px; flex: none; }
.g-section { margin-bottom: 16px; }
.g-section h4 { margin: 0 0 4px; font-size: 18px; }
.g-section p { margin: 0; font-size: 17px; line-height: 1.55; }
.plan-choice { display: block; width: 100%; text-align: left; border: 2px solid #D5E3E1; background: #fff; border-radius: 12px; padding: 14px; margin-bottom: 10px; cursor: pointer; font-size: 16px; }
.plan-choice.selected { border-color: #1F8A82; background: #EAF4F3; }
.plan-choice strong { font-size: 19px; display: block; }
.bar-row { margin: 10px 0; }
.bar-label { display: flex; justify-content: space-between; font-size: 15px; margin-bottom: 4px; }
.bar-track { background: #E6ECEF; border-radius: 8px; height: 14px; position: relative; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 8px; background: #1F8A82; }
.bar-fill.prev { background: #9DB4B1; }
.week-note { background: #EAF4F3; border-radius: 12px; padding: 14px; font-size: 17px; line-height: 1.5; margin-top: 12px; }
.alert-card { border: 2px solid #B3261E; }
.alert-item { border-left: 5px solid #B3261E; background: #FDECEA; padding: 10px 12px; margin-bottom: 8px; border-radius: 8px; }
.alert-item.normal { border-color: #E0A100; background: #FFF6DD; }
.badge.pending_review { background: #FFF1C2; color: #7A5B00; }
.faq-q { font-size: 18px; }
