/* Layout: one-screen app shell. Onboarding is a centered column; chat is sidebar + conversation + right-side drawers. Light-only by design. */
:root {
  /* Light, airy lavender-white; navy ink; lavender + peach accents. */
  --bg: #f7f5fc;
  --bg-2: #efebf9;
  --surface: #ffffff;
  --surface-2: #f1edfb;
  --panel: rgba(255, 255, 255, 0.78);
  --glass: rgba(247, 245, 252, 0.82);
  --tint: rgba(122, 92, 214, 0.08);
  --line: rgba(45, 38, 90, 0.10);
  --line-strong: rgba(45, 38, 90, 0.20);
  --fg: #1d1a3a;
  --fg-muted: #555273;
  --fg-faint: #7f7c9c;
  --accent: #7457d1;
  --accent-strong: #6142c2;
  --accent-ink: #ffffff;
  --accent-soft: #d9cdf8;
  --me-a: #ece5fd;
  --me-b: #ddd1fa;
  --me-ink: #231b4b;
  --glow: #c8603d;
  --warm-bg: rgba(229, 138, 104, 0.08);
  --warm-line: rgba(200, 96, 61, 0.35);
  --danger: #c2414a;
  --danger-bg: rgba(194, 65, 74, 0.07);
  --danger-line: rgba(194, 65, 74, 0.3);
  --ok: #23805f;
  --ok-bg: rgba(35, 128, 95, 0.07);
  --ok-line: rgba(35, 128, 95, 0.3);
  --shadow: 0 1px 2px rgba(45, 38, 90, 0.06), 0 8px 24px rgba(45, 38, 90, 0.06);
  --font-display: "Instrument Serif", "Iowan Old Style", Georgia, serif;
  --font-body: "Figtree", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --r-sm: 10px; --r-md: 16px; --r-lg: 22px;
  color-scheme: light;
}
html, body { height: 100%; margin: 0; }
html { padding: env(safe-area-inset-top, 0px) 0 env(safe-area-inset-bottom, 0px); box-sizing: border-box; }
body { background: var(--bg); color: var(--fg); font-family: var(--font-body); font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
#root { height: 100%; }
* { box-sizing: border-box; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; }
button:disabled { cursor: not-allowed; opacity: .5; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
h1, h2, h3 { text-wrap: balance; margin: 0; font-weight: 400; }
p { margin: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Atmosphere */
.sky { position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(60vmax 40vmax at 85% -10%, rgba(160,130,240,.22), transparent 60%),
    radial-gradient(50vmax 35vmax at -10% 110%, rgba(241,170,140,.18), transparent 60%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%); }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border-radius: 999px; padding: 11px 20px; font-weight: 600; transition: background .2s, transform .2s, border-color .2s; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { background: var(--accent-strong); }
.btn-ghost { border: 1px solid var(--line-strong); color: var(--fg); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 7px 14px; font-size: 13.5px; }
.icon-btn { width: 38px; height: 38px; border-radius: 12px; display: inline-grid; place-items: center; color: var(--fg-muted); transition: background .2s, color .2s; flex-shrink: 0; }
.icon-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--fg); }
.icon-btn[aria-pressed="true"] { background: var(--surface-2); color: var(--accent); }
.link-btn { color: var(--fg-muted); font-size: 12.5px; display: inline-flex; align-items: center; gap: 5px; padding: 2px 4px; border-radius: 6px; }
.link-btn:hover { color: var(--accent); }

/* Onboarding */
.onboard { position: relative; z-index: 1; height: 100%; overflow-y: auto; padding: 32px 16px 48px; }
.onboard-inner { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 28px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 30px; height: 30px; flex-shrink: 0; background: url("/shared/logo.svg") center / contain no-repeat; filter: drop-shadow(0 0 10px rgba(255, 120, 70, .45)); }
.brand-name { font-family: var(--font-body); font-weight: 800; font-size: 22px; letter-spacing: -.035em; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.step { font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--fg-faint); }
.lede { display: flex; flex-direction: column; gap: 14px; }
.display { font-family: var(--font-display); font-size: clamp(38px, 7vw, 60px); line-height: 1.02; letter-spacing: -.01em; }
.display em { color: var(--accent); }
.sub { color: var(--fg-muted); font-size: 16.5px; max-width: 58ch; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.fact { padding: 16px; border-radius: var(--r-md); background: var(--panel); border: 1px solid var(--line); display: flex; flex-direction: column; gap: 6px; }
.fact strong { font-weight: 600; font-size: 14px; }
.fact span { color: var(--fg-muted); font-size: 13.5px; }
.checks { display: flex; flex-direction: column; gap: 10px; }
.check { display: flex; align-items: flex-start; gap: 12px; padding: 14px 16px; border-radius: var(--r-md); border: 1px solid var(--line); background: var(--panel); cursor: pointer; }
.check input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--accent); flex-shrink: 0; }
.actions { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.fine { color: var(--fg-faint); font-size: 12.5px; max-width: 64ch; }
.choice-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.choice { text-align: left; padding: 18px; border-radius: var(--r-md); border: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; gap: 6px; transition: border-color .2s, background .2s, transform .2s; }
.choice:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.choice[aria-checked="true"] { border-color: var(--accent); background: var(--tint); }
.choice-title { font-family: var(--font-display); font-size: 24px; line-height: 1.1; }
.choice-desc { color: var(--fg-muted); font-size: 13.5px; }
.choice-eg { color: var(--fg-faint); font-size: 13px; font-style: italic; margin-top: 4px; }
.people { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.person { text-align: left; border-radius: var(--r-lg); border: 1px solid var(--line); background: var(--panel); padding: 20px; display: flex; flex-direction: column; gap: 12px; transition: border-color .2s, transform .25s; }
.person:hover { border-color: var(--accent); transform: translateY(-2px); }
.person-head { display: flex; align-items: center; gap: 14px; }
.person-name { font-family: var(--font-display); font-size: 28px; line-height: 1; }
.person-role { color: var(--fg-muted); font-size: 13px; }
.person-blurb { color: var(--fg); font-size: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 12px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); color: var(--fg-muted); }
.person-cta { margin-top: auto; color: var(--accent); font-weight: 600; font-size: 14px; display: inline-flex; align-items: center; gap: 6px; }

/* App shell */
.app { position: relative; z-index: 1; display: flex; height: 100%; overflow: hidden; }
.sidebar { width: 290px; flex-shrink: 0; display: flex; flex-direction: column; border-right: 1px solid var(--line); background: var(--glass); backdrop-filter: blur(12px); transition: margin-left .3s ease; z-index: 30; }
.sidebar.collapsed { margin-left: -290px; }
.side-top { display: flex; align-items: center; justify-content: space-between; padding: 16px 14px 10px 18px; }
.side-scroll { flex: 1; overflow-y: auto; padding: 4px 12px 16px; display: flex; flex-direction: column; gap: 22px; }
.side-label { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--fg-faint); padding: 0 6px 8px; }
.side-list { display: flex; flex-direction: column; gap: 4px; }
.side-item { display: flex; align-items: center; gap: 12px; padding: 9px 8px; border-radius: 14px; text-align: left; width: 100%; transition: background .2s; }
.side-item:hover { background: var(--surface); }
.side-item[aria-current="true"] { background: var(--surface-2); }
.side-item-text { min-width: 0; display: flex; flex-direction: column; }
.side-item-name { font-weight: 600; font-size: 14px; }
.side-item-preview { color: var(--fg-faint); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-row { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border-radius: 12px; font-size: 13.5px; color: var(--fg-muted); text-align: left; }
.side-row:hover:not(:disabled) { background: var(--surface); color: var(--fg); }
.side-row.danger:hover:not(:disabled) { color: var(--danger); }
.switch-row { display: flex; gap: 12px; align-items: flex-start; padding: 10px; border-radius: 12px; background: var(--surface); }
.switch-row p { font-size: 12.5px; color: var(--fg-faint); }
.switch-row strong { font-size: 13.5px; font-weight: 600; display: block; }
.side-foot { padding: 14px 18px 18px; border-top: 1px solid var(--line); font-size: 12px; color: var(--fg-faint); display: flex; flex-direction: column; gap: 8px; }

.switch { position: relative; width: 40px; height: 24px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line-strong); flex-shrink: 0; transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: var(--fg-muted); transition: transform .2s, background .2s; }
.switch[aria-checked="true"] { background: var(--accent); border-color: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(16px); background: var(--accent-ink); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--glass); backdrop-filter: blur(10px); }
.chat-who { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1; text-align: left; padding: 4px; border-radius: 14px; }
.chat-who:hover { background: var(--surface); }
.chat-who-text { min-width: 0; display: flex; flex-direction: column; }
.chat-who-name { font-family: var(--font-display); font-size: 22px; line-height: 1.05; }
.chat-who-sub { font-size: 12px; color: var(--fg-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); color: var(--fg-muted); white-space: nowrap; }
.status .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--fg-faint); }
.status.live .dot { background: var(--ok); }
.status.demo { border-color: var(--warm-line); color: var(--glow); }
.status.demo .dot { background: var(--glow); }
.head-actions { display: flex; gap: 2px; }

.demo-note { margin: 12px auto 0; max-width: 720px; width: calc(100% - 32px); padding: 10px 14px; border-radius: 12px; border: 1px dashed var(--warm-line); color: var(--glow); font-size: 13px; background: var(--warm-bg); }

.messages { flex: 1; overflow-y: auto; padding: 24px 16px 12px; scroll-behavior: smooth; }
.thread { max-width: 720px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }
.msg { display: flex; gap: 10px; align-items: flex-end; animation: rise .35s ease both; }
.msg.user { justify-content: flex-end; }
.msg-col { display: flex; flex-direction: column; gap: 4px; max-width: min(78%, 560px); min-width: 0; }
.msg.user .msg-col { align-items: flex-end; }
.bubble { padding: 11px 15px; border-radius: 20px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; line-height: 1.55; }
.msg.assistant .bubble { background: var(--surface); border: 1px solid var(--line); box-shadow: 0 1px 2px rgba(45,38,90,.05); border-bottom-left-radius: 6px; }
.msg.user .bubble { background: linear-gradient(160deg, var(--me-a), var(--me-b)); color: var(--me-ink); border-bottom-right-radius: 6px; }
.meta { display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--fg-faint); padding: 0 6px; font-variant-numeric: tabular-nums; flex-wrap: wrap; }
.msg .meta .link-btn { opacity: 0; transition: opacity .2s; }
.msg:hover .meta .link-btn, .msg:focus-within .meta .link-btn, .meta .link-btn[aria-pressed="true"] { opacity: 1; }
@media (hover: none) { .msg .meta .link-btn { opacity: 1; } }
.tag { font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--glow); }
.typing { display: inline-flex; gap: 5px; padding: 15px 16px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--fg-muted); animation: blink 1.4s infinite both; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
.err { border: 1px solid var(--danger-line); background: var(--danger-bg); border-radius: 16px; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; font-size: 13.5px; color: var(--fg); }
.err-row { display: flex; gap: 8px; flex-wrap: wrap; }
.crisis { border: 1px solid var(--ok-line); background: var(--ok-bg); border-radius: 16px; padding: 14px 16px; font-size: 13.5px; display: flex; flex-direction: column; gap: 6px; }
.crisis strong { color: var(--ok); }

.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 14px; padding: 28px 0 8px; }
.empty h2 { font-family: var(--font-display); font-size: 34px; line-height: 1.05; }
.empty p { color: var(--fg-muted); max-width: 46ch; font-size: 14.5px; }
.starters { display: flex; flex-direction: column; gap: 8px; width: 100%; max-width: 480px; margin-top: 6px; }
.starter { text-align: left; padding: 12px 16px; border-radius: 14px; border: 1px solid var(--line); background: var(--panel); font-size: 14px; transition: border-color .2s, background .2s; }
.starter:hover { border-color: var(--accent); background: var(--surface); }

.composer-wrap { padding: 10px 16px 16px; }
.composer { box-shadow: var(--shadow); max-width: 720px; margin: 0 auto; display: flex; gap: 8px; align-items: flex-end; padding: 8px 8px 8px 16px; border-radius: 24px; background: var(--surface); border: 1px solid var(--line-strong); transition: border-color .2s; }
.composer:focus-within { border-color: var(--accent); }
.composer textarea { flex: 1; min-width: 0; resize: none; border: 0; background: transparent; outline: none; padding: 8px 0; max-height: 160px; line-height: 1.45; }
.composer textarea::placeholder { color: var(--fg-faint); }
.send { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); flex-shrink: 0; }
.send.stop { background: var(--surface-2); color: var(--fg); border: 1px solid var(--line-strong); }
.composer-hint { max-width: 720px; margin: 6px auto 0; font-size: 11.5px; color: var(--fg-faint); text-align: center; }

/* Drawers & dialogs */
.scrim { position: fixed; inset: 0; background: rgba(29, 26, 58, 0.28); z-index: 40; animation: fade .2s ease both; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(410px, 100%); background: var(--bg-2); border-left: 1px solid var(--line); z-index: 50; display: flex; flex-direction: column; animation: slide .28s ease both; padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 12px 22px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { font-family: var(--font-display); font-size: 26px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 20px 22px 28px; display: flex; flex-direction: column; gap: 24px; }
.section { display: flex; flex-direction: column; gap: 10px; }
.section-label { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--fg-faint); }
.muted { color: var(--fg-muted); font-size: 14px; }
.note { font-size: 12.5px; color: var(--fg-faint); padding: 12px 14px; border-radius: 12px; background: var(--surface); }
.profile-hero { display: flex; flex-direction: column; align-items: flex-start; gap: 12px; }
.profile-name { font-family: var(--font-display); font-size: 40px; line-height: 1; }
.opinions { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 6px; color: var(--fg-muted); font-size: 14px; }
.seg { display: flex; padding: 4px; gap: 4px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); }
.seg button { flex: 1; padding: 8px 6px; border-radius: 10px; font-size: 13.5px; color: var(--fg-muted); }
.seg button[aria-checked="true"] { background: var(--surface-2); color: var(--fg); box-shadow: inset 0 0 0 1px var(--line-strong); }
.tone-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tone-grid .choice { padding: 12px; }
.tone-grid .choice-title { font-size: 19px; }
.tone-grid .choice-desc { font-size: 12.5px; }
.pref-switch { display: flex; gap: 14px; justify-content: space-between; align-items: flex-start; }
.mem-list { display: flex; flex-direction: column; gap: 8px; }
.mem { padding: 12px 14px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.mem-text { font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.mem-actions { display: flex; gap: 6px; justify-content: flex-end; }
.field { width: 100%; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line-strong); background: var(--bg); resize: vertical; min-height: 70px; outline: none; }
.field:focus { border-color: var(--accent); }
.dialog { position: fixed; z-index: 60; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(420px, calc(100% - 32px)); background: var(--bg-2); border: 1px solid var(--line-strong); border-radius: var(--r-lg); padding: 22px; display: flex; flex-direction: column; gap: 14px; animation: pop .2s ease both; }
.dialog h2 { font-family: var(--font-display); font-size: 26px; }
.dialog .actions { justify-content: flex-end; }
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); z-index: 70; padding: 10px 16px; border-radius: 999px; background: var(--fg); color: var(--accent-ink); font-size: 13.5px; font-weight: 500; animation: pop .2s ease both; max-width: calc(100% - 32px); text-align: center; }
.connecting { display: flex; align-items: center; gap: 10px; color: var(--fg-muted); font-size: 13px; }
.spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line-strong); border-top-color: var(--accent); animation: spin .8s linear infinite; }

.mobile-only { display: none; }
@media (max-width: 860px) {
  .sidebar { position: fixed; top: 0; bottom: 0; left: 0; margin-left: 0 !important; transform: translateX(-100%); transition: transform .3s ease; padding-top: env(safe-area-inset-top, 0px); }
  .sidebar.mobile-open { transform: none; box-shadow: 20px 0 60px rgba(45,38,90,.18); }
  .desktop-only { display: none !important; }
  .mobile-only { display: inline-grid; }
  .chat-head { padding: 10px 10px; gap: 6px; }
  .chat-who-name { font-size: 20px; }
  .msg-col { max-width: 86%; }
  .status-text { display: none; }
}
@media (max-width: 420px) { .head-actions .icon-btn { width: 34px; } .messages { padding-top: 16px; } }

@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { transform: translateX(24px); opacity: 0; } }
@keyframes pop { from { opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }
