/* ============================================================
   Dawn — Derbyshire drug & alcohol support
   Design system: Limitra. Obsidian neutrals, silver accent, Manrope,
   hairline borders, sharp radii. No gradients, glow, glass, or decorative motion.
   ============================================================ */

:root {
  --bg: #060606;
  --surface: #111113;
  --surface-2: #1c1c1f;
  --hover: #27272b;
  --nav: #0a0a0b;
  --fg: #ededee;
  --muted: #9a9a9e;
  --faint: #6b6b70;

  --accent: #d4d4d8;
  --accent-soft: #26262a;
  --border: #242427;
  --border-strong: #3a3a3f;
  --danger: #f87171;
  --success: #4ade80;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;

  --side: 264px;
  --chatw: 720px;

  --font: "Manrope", ui-sans-serif, system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", monospace;
  --ease: cubic-bezier(.4, 0, .2, 1);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
html { background: var(--bg); color-scheme: dark; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font-family: var(--font); font-size: 15.5px; line-height: 1.6;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  overflow: hidden;
}
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 1.5px solid var(--border-strong); outline-offset: 2px; }
::selection { background: var(--accent-soft); color: var(--fg); }

.scrollbar-thin { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
.scrollbar-thin::-webkit-scrollbar { width: 8px; height: 8px; }
.scrollbar-thin::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; }
.scrollbar-thin::-webkit-scrollbar-track { background: transparent; }

/* wordmark */
.mark { display: inline-flex; align-items: center; gap: 9px; color: var(--fg); }
.mark__icon { width: 20px; height: 20px; color: var(--accent); flex: none; }
.mark__word { font-weight: 600; font-size: 18px; letter-spacing: -.01em; }
.mark--sm .mark__icon { width: 17px; height: 17px; }
.mark--sm .mark__word { font-size: 16px; }

/* icon buttons */
.iconbtn {
  flex: none; display: grid; place-items: center; width: 34px; height: 34px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--border); color: var(--muted); cursor: pointer;
  transition: background .14s var(--ease), color .14s var(--ease);
}
.iconbtn:hover { background: var(--surface-2); color: var(--fg); }

/* screen orchestration */
.gate  { display: none; min-height: 100dvh; min-height: 100vh; place-items: center; padding: 24px; }
.shell { display: none; height: 100dvh; height: 100vh; }
body[data-screen="gate"] .gate  { display: grid; }
body[data-screen="app"]  .shell { display: flex; }

/* ───────────── login gate ───────────── */
.gate__card {
  width: 100%; max-width: 380px; padding: 32px 30px 26px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: 0 12px 40px -20px rgba(0, 0, 0, .8); text-align: center;
  animation: fadeUp .35s var(--ease) both;
}
.gate__card .mark { justify-content: center; margin-bottom: 16px; }
.gate__card .mark__icon { width: 26px; height: 26px; }
.gate__card .mark__word { font-size: 23px; }
.gate__tag { margin: 0; font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.gate__sub { margin: 9px 0 26px; color: var(--muted); font-size: 14px; }
.field { display: block; text-align: left; margin-bottom: 12px; }
.field__label { display: block; font-size: 11px; letter-spacing: .05em; color: var(--faint); margin: 0 0 7px 1px; text-transform: uppercase; font-weight: 600; }
.field__input { width: 100%; padding: 12px 14px; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border); color: var(--fg); transition: border-color .14s var(--ease); }
.field__input::placeholder { color: var(--faint); }
.field__input:focus { outline: none; border-color: var(--border-strong); }
.btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 18px; border: 1px solid transparent; border-radius: var(--radius); cursor: pointer;
  font-weight: 600; letter-spacing: -.005em; color: var(--bg); background: var(--accent);
  transition: background .14s var(--ease);
}
.btn--full { width: 100%; margin-top: 4px; }
.btn:hover { background: #e6e6e9; }
.btn:active { background: #c4c4c9; }
.btn[disabled] { cursor: progress; opacity: .9; }
.btn__spinner { display: none; width: 15px; height: 15px; border-radius: 50%; border: 2px solid rgba(6,6,6,.3); border-top-color: var(--bg); animation: spin .65s linear infinite; }
.btn.is-busy .btn__label { opacity: .45; }
.btn.is-busy .btn__spinner { display: inline-block; }
.gate__error { min-height: 17px; margin: 13px 1px 0; font-size: 13px; color: var(--danger); opacity: 0; transition: opacity .15s; }
.gate__error.show { opacity: 1; }
.gate__legal { margin: 20px 0 0; font-size: 12px; color: var(--faint); }
.gate__legal strong { color: var(--muted); font-weight: 600; }
.shake { animation: shake .4s var(--ease); }

/* ───────────── sidebar ───────────── */
.sidebar { width: var(--side); flex: none; display: flex; flex-direction: column; background: var(--nav); border-right: 1px solid var(--border); min-height: 0; }
.sidebar__head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 12px; }
.convos { flex: 1; min-height: 0; overflow-y: auto; padding: 6px 8px; display: flex; flex-direction: column; gap: 2px; }
.convos__empty { color: var(--faint); font-size: 12.5px; padding: 16px 10px; text-align: center; line-height: 1.5; }
.convo { display: flex; align-items: center; gap: 8px; padding: 9px 9px 9px 11px; border-radius: var(--radius); cursor: pointer; color: var(--muted); transition: background .14s var(--ease), color .14s var(--ease); }
.convo:hover { background: var(--surface); color: var(--fg); }
.convo.active { background: var(--surface-2); color: var(--fg); }
.convo__title { flex: 1; min-width: 0; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.convo__del { flex: none; display: grid; place-items: center; width: 24px; height: 24px; border-radius: 6px; border: none; background: none; color: var(--faint); cursor: pointer; opacity: 0; transition: opacity .14s, color .14s, background .14s; }
.convo:hover .convo__del, .convo.active .convo__del { opacity: 1; }
.convo__del:hover { color: var(--danger); background: var(--hover); }
.sidebar__foot { padding: 8px; border-top: 1px solid var(--border); }
.navbtn { width: 100%; display: flex; align-items: center; gap: 9px; padding: 9px 11px; border-radius: var(--radius); border: none; background: none; color: var(--muted); cursor: pointer; font-size: 13.5px; transition: background .14s var(--ease), color .14s var(--ease); }
.navbtn:hover { background: var(--surface); color: var(--fg); }

/* ───────────── app column ───────────── */
.app { flex: 1; min-width: 0; display: flex; flex-direction: column; height: 100%; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 11px 16px; flex: none; background: var(--nav); border-bottom: 1px solid var(--border); }
.topbar__menu { display: none; }
.topbar__note { margin: 0 0 0 auto; font-size: 12px; color: var(--faint); display: inline-flex; align-items: center; gap: 7px; text-align: right; }
.topbar__note strong { color: var(--muted); font-weight: 600; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--success); flex: none; }

/* stream */
.stream { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 4px 18px; }
.thread { max-width: var(--chatw); width: 100%; margin: 0 auto; display: flex; flex-direction: column; gap: 20px; padding: 22px 0 28px; min-height: 100%; }

.welcome { margin: auto 0; text-align: center; padding: 4vh 6px; animation: fadeUp .35s var(--ease) both; }
.welcome__title { font-weight: 600; font-size: clamp(22px, 4.5vw, 27px); margin: 0 0 9px; letter-spacing: -.02em; }
.welcome__text { max-width: 30rem; margin: 0 auto 24px; color: var(--muted); font-size: 15px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip { padding: 8px 13px; border-radius: var(--radius); cursor: pointer; font-size: 13.5px; color: var(--muted); background: var(--surface); border: 1px solid var(--border); transition: background .14s var(--ease), color .14s var(--ease), border-color .14s var(--ease); }
.chip:hover { background: var(--surface-2); color: var(--fg); border-color: var(--border-strong); }

/* messages */
.msg { display: flex; gap: 11px; animation: fadeUp .2s var(--ease) both; max-width: 100%; }
.msg--user { justify-content: flex-end; }
.msg__avatar { flex: none; width: 26px; height: 26px; border-radius: var(--radius-sm); margin-top: 2px; background: var(--surface-2); border: 1px solid var(--border); position: relative; }
.msg__avatar::before { content: ""; position: absolute; inset: 0; margin: auto; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.msg__body { min-width: 0; }
.msg--user .msg__body { max-width: min(84%, 38rem); padding: 11px 15px; border-radius: var(--radius-lg); background: var(--surface-2); border: 1px solid var(--border); color: var(--fg); }
.msg--assistant .msg__body { max-width: 100%; padding-top: 2px; }

/* markdown */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 .78em; }
.md strong { color: var(--fg); font-weight: 600; }
.md em { color: var(--fg); }
.md ul, .md ol { margin: .35em 0 .85em; padding-left: 1.3em; }
.md li { margin: .28em 0; }
.md li::marker { color: var(--muted); }
.md a { color: var(--fg); text-decoration: underline; text-decoration-color: var(--border-strong); text-underline-offset: 3px; }
.md a:hover { text-decoration-color: var(--accent); }
.md code { font-family: var(--mono); font-size: .9em; background: var(--surface-2); padding: .1em .4em; border-radius: var(--radius-sm); }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { margin: 1.05em 0 .45em; font-weight: 600; line-height: 1.3; letter-spacing: -.01em; color: var(--fg); }
.md h1 { font-size: 1.28em; } .md h2 { font-size: 1.16em; } .md h3 { font-size: 1.05em; } .md h4, .md h5, .md h6 { font-size: 1em; color: var(--muted); }
.md hr { border: none; border-top: 1px solid var(--border); margin: 1.05em 0; }
.md del { color: var(--muted); }
.md blockquote { margin: .7em 0; padding: .35em 0 .35em 14px; border-left: 2px solid var(--border-strong); color: var(--muted); }
.md blockquote > :last-child { margin-bottom: 0; }
.md pre { margin: .7em 0; padding: 12px 14px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; }
.md pre code { background: none; padding: 0; font-size: .88em; line-height: 1.5; }
.md table { border-collapse: collapse; margin: .8em 0; font-size: .92em; font-variant-numeric: tabular-nums; display: block; max-width: 100%; overflow-x: auto; }
.md thead th { text-align: left; font-weight: 600; color: var(--fg); background: var(--surface-2); white-space: nowrap; }
.md th, .md td { border: 1px solid var(--border); padding: 7px 11px; }
.md tbody tr:nth-child(even) { background: rgba(255, 255, 255, .018); }
.md input[type="checkbox"] { margin-right: 6px; accent-color: var(--accent); }
.md img { max-width: 100%; border-radius: var(--radius); }
.caret { display: inline-block; width: 2px; height: 1.05em; margin-left: 1.5px; vertical-align: text-bottom; border-radius: 2px; background: var(--accent); animation: caret 1.1s var(--ease) infinite; }

/* typing indicator (3 dots) */
.typing { display: inline-flex; align-items: center; gap: 5px; padding: 7px 2px 11px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: bounce 1.25s var(--ease) infinite; }
.typing i:nth-child(2) { animation-delay: .16s; }
.typing i:nth-child(3) { animation-delay: .32s; }

/* thinking panel */
.think { margin-bottom: 9px; }
.think__live { display: inline-flex; align-items: center; gap: 9px; padding: 7px 13px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); color: var(--muted); font-size: 13px; }
.think__live .tl { color: var(--fg); font-weight: 600; }
.dots { display: inline-flex; align-items: center; gap: 4px; }
.dots i { width: 4px; height: 4px; border-radius: 50%; background: currentColor; opacity: .4; animation: bounce 1.25s var(--ease) infinite; }
.dots i:nth-child(2) { animation-delay: .16s; }
.dots i:nth-child(3) { animation-delay: .32s; }
.think__chip { display: none; align-items: center; gap: 7px; padding: 5px 11px; border-radius: var(--radius); cursor: pointer; background: var(--surface); border: 1px solid var(--border); color: var(--faint); font-size: 12px; transition: background .14s var(--ease), color .14s var(--ease); }
.think__chip:hover { background: var(--surface-2); color: var(--muted); }
.think__chip .spark { width: 5px; height: 5px; flex: none; border-radius: 50%; background: var(--accent); }
.think__chip .chev { transition: transform .18s var(--ease); }
.think.collapsed .think__live { display: none; }
.think.collapsed .think__chip { display: inline-flex; }
.think__steps { display: none; margin: 9px 0 2px; padding-left: 11px; font-size: 12.5px; color: var(--faint); border-left: 1px solid var(--border); }
.think.open .think__steps { display: block; }
.think.open .think__chip .chev { transform: rotate(180deg); }
.think__steps p { margin: 5px 0; }
.think__steps .reason { color: var(--muted); white-space: pre-wrap; }

.msg__error { padding: 10px 14px; border-radius: var(--radius); background: rgba(248,113,113,.08); border: 1px solid rgba(248,113,113,.28); color: var(--danger); font-size: 14px; }

/* composer */
.composer { flex: none; padding: 6px 18px 14px; background: var(--bg); }
.composer__inner { max-width: var(--chatw); margin: 0 auto; }
.composer__box { display: flex; align-items: flex-end; gap: 9px; padding: 8px 8px 8px 15px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); transition: border-color .14s var(--ease); }
.composer__box:focus-within { border-color: var(--border-strong); }
.composer__input { flex: 1; resize: none; border: none; background: none; outline: none; padding: 8px 0; max-height: 176px; line-height: 1.5; font-size: 15.5px; }
.composer__input::placeholder { color: var(--faint); }
.sendbtn { flex: none; display: grid; place-items: center; width: 38px; height: 38px; border-radius: var(--radius); border: none; cursor: pointer; color: var(--bg); background: var(--accent); transition: background .14s var(--ease); }
.sendbtn:hover:not(:disabled) { background: #e6e6e9; }
.sendbtn:active:not(:disabled) { background: #c4c4c9; }
.sendbtn:disabled { background: var(--surface-2); color: var(--faint); cursor: default; border: 1px solid var(--border); }
.sendbtn.stop { background: var(--surface-2); color: var(--fg); border: 1px solid var(--border-strong); }
.composer__hint { margin: 9px 4px 0; text-align: center; font-size: 11px; color: var(--faint); }

/* scrim (mobile drawer) */
.scrim { display: none; }

/* ───────────── responsive ───────────── */
@media (max-width: 820px) {
  .sidebar { position: fixed; top: 0; left: 0; bottom: 0; z-index: 40; width: min(82vw, 300px); transform: translateX(-100%); transition: transform .22s var(--ease); }
  .shell.open .sidebar { transform: none; box-shadow: 0 0 60px rgba(0,0,0,.6); }
  .shell.open .scrim { display: block; position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.5); }
  .topbar__menu { display: grid; }
}
@media (max-width: 640px) {
  body { font-size: 15px; }
  .stream { padding: 2px 13px; }
  .composer { padding: 4px 13px 12px; }
  .topbar { padding: 10px 13px; }
  .topbar__note .t { display: none; }
}

/* ───────────── motion preferences ───────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
  .caret { animation: none; opacity: 1; }
  .typing i, .dots i { animation: none; opacity: .7; }
}

/* keyframes — functional only */
@keyframes fadeUp { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: none; } }
@keyframes caret { 0%, 100% { opacity: .2; } 50% { opacity: .9; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes bounce { 0%, 70%, 100% { transform: translateY(0); opacity: .35; } 35% { transform: translateY(-5px); opacity: 1; } }
@keyframes shake { 10%, 90% { transform: translateX(-1px); } 20%, 80% { transform: translateX(2px); } 30%, 50%, 70% { transform: translateX(-4px); } 40%, 60% { transform: translateX(4px); } }
