:root {
  --ink: #1d1d2c; --muted: #5d5e78; --line: #e7e6f1; --bg: #f6f5fb; --surface: #ffffff;
  --indigo: #3737ac; --indigo-soft: #ecebfb; --magenta: #b51d68; --magenta-soft: #fbeaf2;
  --ok: #1f7a4d; --ok-soft: #e5f4ec; --warn: #8a5a00; --warn-soft: #fff3d6;
  --danger: #a3291c; --danger-soft: #fdece9; --radius: 20px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink); background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.icon { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* Top bar: brand and the always-available crisis help. */
.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: rgba(246, 245, 251, .94); backdrop-filter: blur(8px); }
.brand-logo { display: block; width: 78px; height: 40px; object-fit: contain; object-position: left center; }
.crisis { position: relative; }
.crisis summary { list-style: none; display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 8px 12px; border-radius: 999px; background: var(--danger-soft); color: var(--danger); font-size: 13px; font-weight: 700; cursor: pointer; }
.crisis summary::-webkit-details-marker { display: none; }
.crisis summary .icon { width: 18px; height: 18px; }
.crisis-sheet { position: absolute; right: 0; top: calc(100% + 8px); width: min(88vw, 340px); padding: 16px; border-radius: 18px; background: var(--surface); border: 1px solid #f3c9c2; box-shadow: 0 18px 40px rgba(29, 29, 44, .16); }
.crisis-sheet p { font-size: 13px; margin: 0 0 8px; }
.crisis-list { list-style: none; padding: 0; margin: 8px 0 10px; }
.crisis-list li { margin: 6px 0; }
.crisis-list a { display: flex; align-items: center; min-height: 46px; padding: 10px 14px; border-radius: 12px; background: var(--danger-soft); color: var(--danger); font-weight: 700; text-decoration: none; }
.crisis-note { font-size: 12px; color: var(--muted); }

.shell { width: min(100%, 560px); margin: 0 auto; padding: 4px 16px 32px; }
.notice { margin: 4px 0 8px; font-size: 12px; color: #7a3a58; text-align: center; }
.status { margin: 10px 0; font-size: 14px; line-height: 1.45; }
.status:not(:empty) { padding: 12px 14px; border-radius: 14px; background: var(--indigo-soft); }
.status.error:not(:empty) { background: var(--danger-soft); color: var(--danger); }

.card { margin-top: 14px; padding: 20px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 6px 22px rgba(29, 29, 44, .04); }
.card.highlight { border-color: #cfcdf3; box-shadow: 0 10px 30px rgba(55, 55, 172, .1); }
.hero-card { text-align: center; }
h1 { font-size: 30px; line-height: 1.1; letter-spacing: -.04em; margin: 6px 0 10px; }
h2 { font-size: 20px; letter-spacing: -.02em; margin: 2px 0 8px; }
h3 { font-size: 16px; margin: 0 0 4px; }
p { color: var(--muted); line-height: 1.5; font-size: 14px; margin: 0 0 14px; }
.muted { color: var(--muted); }
.eyebrow { font-size: 11px; font-weight: 750; text-transform: uppercase; letter-spacing: .12em; color: var(--indigo); }

label { display: block; font-size: 13px; font-weight: 650; margin: 14px 0 7px; }
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), select, textarea { display: block; width: 100%; min-height: 48px; padding: 11px 14px; border: 1px solid #c9c8de; border-radius: 12px; font: inherit; color: var(--ink); background: var(--surface); }
textarea { min-height: 96px; resize: vertical; }
input:focus-visible, button:focus-visible, a:focus-visible, summary:focus-visible, textarea:focus-visible { outline: 3px solid #8f8ff0; outline-offset: 2px; }

button { min-height: 48px; padding: 11px 16px; border: 1px solid var(--magenta); border-radius: 14px; background: var(--magenta); color: white; font: inherit; font-size: 15px; font-weight: 700; cursor: pointer; }
button:disabled { cursor: wait; opacity: .6; }
button.secondary { background: var(--surface); color: var(--magenta); }
button.quiet { background: transparent; color: var(--muted); border-color: #d3d2e3; }
button.wide { width: 100%; margin-top: 14px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.actions.stack { flex-direction: column; }
.actions.stack button { width: 100%; }
details { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 14px; }
details summary { cursor: pointer; font-size: 14px; font-weight: 700; min-height: 40px; }
details.crisis { margin: 0; border: 0; padding: 0; }

/* Page header with the refresh action. */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 6px; }
.page-title { margin: 4px 0; font-size: 30px; }
.icon-button { display: inline-grid; place-items: center; width: 46px; min-height: 46px; padding: 0; border-radius: 50%; background: var(--surface); color: var(--indigo); border: 1px solid var(--line); }
.page-intro { margin: 4px 0 6px; }
.section-title { font-size: 15px; letter-spacing: 0; margin: 22px 0 10px; color: var(--ink); }
.section-head { display: flex; align-items: baseline; justify-content: space-between; }
.see-all { color: var(--indigo); font-weight: 700; font-size: 14px; text-decoration: none; min-height: 44px; display: inline-flex; align-items: center; }

/* Home. */
.greeting { margin: 2px 0 4px; }
.greeting-title { margin: 0; font-size: 22px; font-weight: 750; color: var(--ink); letter-spacing: -.02em; }
.greeting-date { margin: 2px 0 0; }
.banner { display: flex; gap: 10px; align-items: flex-start; margin-top: 14px; padding: 12px 14px; border-radius: 16px; background: var(--warn-soft); color: var(--warn); }
.banner p { margin: 0; color: var(--warn); font-weight: 600; }
.next-card { display: flex; align-items: center; gap: 14px; padding: 18px; border-radius: 22px; color: white; text-decoration: none; background: var(--indigo); box-shadow: 0 16px 34px rgba(55, 55, 172, .28); }
.next-card .date-block { background: rgba(255, 255, 255, .16); color: white; }
.next-info { display: grid; gap: 4px; flex: 1; min-width: 0; }
.next-info strong { font-size: 18px; }
.next-info span { opacity: .9; font-size: 14px; }
.next-info .chip { justify-self: start; opacity: 1; }
.next-go { opacity: .8; }
.next-card.empty-next { display: grid; gap: 4px; background: var(--surface); color: var(--ink); border: 1px dashed #cfcdf3; box-shadow: none; }
.next-card.empty-next span { color: var(--muted); font-size: 14px; }
.overview { margin-top: 18px; font-size: 12px; text-align: center; }

/* Shared pieces. */
.chip { display: inline-flex; align-items: center; min-height: 26px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--indigo-soft); color: var(--indigo); line-height: 1.3; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.new { background: var(--magenta-soft); color: var(--magenta); }
.date-block { display: grid; place-content: center; justify-items: center; gap: 3px; width: 58px; height: 64px; flex: none; border-radius: 16px; background: var(--indigo-soft); color: var(--indigo); line-height: 1; }
.date-block span:first-child { font-size: 24px; font-weight: 800; }
.date-block span:last-child { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.card-list { display: grid; gap: 12px; margin-top: 12px; }
.card-list > .card { margin-top: 0; }
.empty { display: grid; justify-items: center; gap: 6px; padding: 26px 18px; border-radius: var(--radius); background: var(--surface); border: 1px dashed var(--line); text-align: center; }
.empty strong { font-size: 15px; }
.empty p { margin: 0; }
.empty-mark { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; background: var(--ok-soft); color: var(--ok); }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0; color: var(--muted); }
.note { margin: 12px 0 0; padding: 10px 12px; border-radius: 12px; background: var(--warn-soft); color: var(--warn); font-size: 13px; }

/* Appointments. */
.appointment-main { display: flex; gap: 14px; align-items: flex-start; }
.appointment-info { display: grid; gap: 6px; min-width: 0; }
.place { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 0; font-size: 13px; }
.place .icon { width: 18px; height: 18px; }
.text-actions { display: flex; gap: 6px; margin-top: 8px; }
.text-button { flex: 1; min-height: 44px; background: transparent; border: 0; color: var(--indigo); font-size: 14px; }
.text-button.danger { color: var(--danger); }
.appointment-panel { margin-top: 6px; }
.appointment-panel button { width: 100%; margin-top: 12px; }

/* Instruments list. */
.form-card { display: flex; align-items: center; gap: 14px; width: 100%; padding: 16px; text-align: left; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 6px 18px rgba(29, 29, 44, .04); font-weight: 400; }
.form-icon { display: grid; place-items: center; width: 48px; height: 48px; flex: none; border-radius: 14px; background: var(--indigo-soft); color: var(--indigo); }
.form-icon.self_monitoring { background: var(--magenta-soft); color: var(--magenta); }
.form-icon.intake { background: var(--ok-soft); color: var(--ok); }
.form-text { display: grid; gap: 3px; flex: 1; min-width: 0; }
.form-text strong { font-size: 15px; line-height: 1.3; }
.form-text span { font-size: 13px; color: var(--muted); }
.crisis-card { border-color: #f3c9c2; background: #fffaf9; }

/* Instrument page: one question at a time, actions always within reach. */
.back-link { display: inline-flex; align-items: center; gap: 4px; min-height: 44px; margin-top: 4px; color: var(--indigo); font-weight: 700; font-size: 14px; text-decoration: none; }
.form-panel { margin-top: 6px; }
.form-head h2 { font-size: 22px; }
.form-head .meta { margin-bottom: 8px; }
.form-notes { padding: 10px 12px; border-radius: 12px; background: var(--indigo-soft); color: var(--indigo); }
.progress { height: 8px; border-radius: 999px; background: #e3e2f2; overflow: hidden; margin: 14px 0 8px; }
.progress span { display: block; height: 100%; width: 0; background: var(--magenta); transition: width .25s; }
.step-count { font-size: 12px; font-weight: 700; color: var(--indigo); margin-bottom: 6px; }
fieldset { border: 0; padding: 0; margin: 0; }
fieldset legend { font-weight: 750; font-size: 20px; line-height: 1.3; letter-spacing: -.01em; color: var(--ink); margin-bottom: 14px; }
fieldset > label:has(input[type="radio"]) { display: flex; align-items: center; gap: 12px; margin: 10px 0; padding: 15px 16px; border-radius: 16px; border: 2px solid var(--line); background: var(--surface); font-size: 15px; font-weight: 600; cursor: pointer; }
fieldset > label:has(input[type="radio"]:checked) { border-color: var(--magenta); background: var(--magenta-soft); }
fieldset input[type="radio"] { width: 20px; height: 20px; accent-color: var(--magenta); flex: none; margin: 0; }
.scale { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin: 6px 0 12px; }
.scale-option { min-height: 52px; padding: 0; background: var(--surface); color: var(--ink); border: 2px solid var(--line); border-radius: 14px; font-size: 17px; }
.scale-option[aria-pressed="true"] { background: var(--magenta); color: white; border-color: var(--magenta); }
input[type="range"] { display: block; width: 100%; margin: 18px 0 8px; accent-color: var(--magenta); }
.slider-value { display: block; text-align: center; font-size: 30px; font-weight: 800; color: var(--magenta); }
#review-list { display: grid; gap: 8px; margin: 10px 0 6px; }
.review-item { display: block; width: 100%; text-align: left; font-weight: 500; font-size: 14px; background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
.form-footer { position: sticky; bottom: 0; z-index: 5; margin: 18px -16px 0; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--line); }
.form-footer .status:not(:empty) { margin-top: 0; }
#form-nav { margin-top: 0; flex-wrap: nowrap; }
#form-nav button { flex: 1; }
#submit-form { width: 100%; }
.draft-status { font-size: 12px; margin: 12px 0 0; min-height: 1em; text-align: center; }

/* Consent and account. */
.notice-text { max-height: 260px; overflow-y: auto; white-space: pre-wrap; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: #fafafd; font-size: 13px; line-height: 1.5; color: #3f405f; }
.purposes { padding-left: 18px; margin: 0 0 12px; font-size: 13px; color: var(--muted); line-height: 1.5; }
.consent { display: flex; gap: 10px; align-items: flex-start; font-weight: 500; line-height: 1.48; color: #3f405f; }
.consent.strong { padding: 12px; border-radius: 12px; background: var(--indigo-soft); }
.consent input { width: 20px; height: 20px; flex: none; margin: 2px 0 0; accent-color: var(--magenta); }
.link-list { display: grid; gap: 10px; margin-top: 8px; }
.link-row { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 16px; background: #fafafd; border: 1px solid var(--line); }
.link-row p { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0; color: var(--ink); font-weight: 650; }
.avatar { display: grid; place-items: center; width: 42px; height: 42px; flex: none; border-radius: 50%; background: var(--indigo); color: white; font-weight: 800; font-size: 14px; }
#use-invitation-link, #accept, #email-challenge button, #retry-session { width: 100%; margin-top: 14px; }
.logout { display: block; width: 100%; margin-top: 18px; }
.welcome-hero { padding: 26px 4px 6px; }
.welcome-hero h1 { font-size: 34px; }

/* Bottom navigation. */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: grid; grid-template-columns: repeat(4, 1fr); padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); background: rgba(255, 255, 255, .97); border-top: 1px solid var(--line); box-shadow: 0 -8px 24px rgba(29, 29, 44, .06); }
.tabbar a { position: relative; display: grid; justify-items: center; gap: 3px; padding: 6px 0; min-height: 56px; border-radius: 14px; color: #7a7b93; font-size: 11px; font-weight: 700; text-decoration: none; }
.tabbar a[aria-current="page"] { color: var(--magenta); background: var(--magenta-soft); }
.tabbar .badge { position: absolute; top: 4px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--magenta); color: white; font-size: 11px; line-height: 18px; text-align: center; }

/* Safety overlay. */
.safety { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; padding: 16px; background: rgba(29, 29, 44, .55); overflow-y: auto; }
.safety-box { width: min(100%, 480px); max-height: 100%; overflow-y: auto; background: var(--surface); border-radius: 24px; padding: 24px 20px; }
.safety-box button { width: 100%; margin-top: 14px; }

footer { text-align: center; font-size: 12px; color: #8b8ca3; margin-top: 26px; }
@media (min-width: 640px) { .safety { align-items: center; } }
.settings details { margin: 0; border: 0; padding: 0; }
.greeting-date { margin: -2px 0 6px; font-weight: 600; }
/* Install guide. */
.install-banner { display: flex; gap: 12px; align-items: flex-start; margin-top: 14px; padding: 14px; border-radius: 18px; background: var(--surface); border: 1px solid #cfcdf3; }
.install-banner strong { display: block; font-size: 15px; margin-bottom: 2px; }
.install-banner p { margin: 0 0 10px; font-size: 13px; }
.install-mark { display: grid; place-items: center; width: 44px; height: 44px; flex: none; border-radius: 14px; background: var(--indigo-soft); color: var(--indigo); }
.banner-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.banner-actions button { min-height: 40px; padding: 8px 14px; font-size: 14px; }
.install-steps { margin: 12px 0 0; padding-left: 22px; color: var(--ink); line-height: 1.55; font-size: 14px; }
.install-steps li { margin: 6px 0; }
/* Messages and personal data. */
.info-box { margin: 6px 0 14px; padding: 12px 14px; border-radius: 14px; background: var(--indigo-soft); color: var(--ink); font-size: 14px; }
.info-box ul { margin: 6px 0 0; padding-left: 18px; line-height: 1.5; }
.choice-list { display: grid; gap: 8px; margin-bottom: 8px; }
.choice { display: flex; gap: 12px; align-items: flex-start; margin: 0; padding: 12px 14px; border-radius: 14px; border: 2px solid var(--line); background: var(--surface); font-weight: 500; cursor: pointer; }
.choice:has(input:checked) { border-color: var(--magenta); background: var(--magenta-soft); }
.choice.disabled { opacity: .6; cursor: default; }
.choice input { width: 20px; height: 20px; margin: 2px 0 0; flex: none; accent-color: var(--magenta); }
.choice strong { display: block; font-size: 14px; color: var(--ink); }
.choice span span { display: block; font-size: 13px; color: var(--muted); line-height: 1.45; margin-top: 2px; }
.choice .hint { color: var(--warn); }
.preview { padding: 10px 0; border-bottom: 1px solid var(--line); }
.preview p { margin: 4px 0 0; font-size: 13px; }
.provisional { display: inline-block; padding: 4px 10px; border-radius: 999px; background: var(--warn-soft); color: var(--warn); font-size: 12px; font-weight: 700; }
.request { padding: 12px 14px; border-radius: 14px; border: 1px solid var(--line); background: #fafafd; }
.request p { margin: 4px 0 0; font-size: 13px; }
.link-row { flex-wrap: wrap; }
.link-actions { display: flex; gap: 6px; width: 100%; }
.link-actions .text-button { min-height: 40px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
button.danger { background: var(--danger); border-color: var(--danger); }
.danger-zone summary { color: var(--danger); }
.arco-option { margin-top: 10px; }
.arco-option[open] { padding-bottom: 6px; }
