/* ==========================================================================
   App styles — chat, login and account. Direction: "warm with character".
   Loaded AFTER tokens.css and site.css, which supply every colour, radius,
   shadow and font family used here. Nothing below hard-codes a hex and nothing
   below fetches anything over the network.

   The chat is a viewport-locked column: header, then the shell (conversation
   margin + thread), then the composer. Only #chat-main scrolls, because
   scripts/chat.js pins the thread to the bottom by writing chat-main.scrollTop.

   Class contract with scripts/chat.js (it builds these nodes, so they are
   styled here by the exact names it uses):
     .msg .msg-user .msg-assistant .msg-pending .typing>i
     .chat-card .chat-card-crisis .chat-card-error .actions .fine
     .lines .who .num .hours (site.css) .plan-row .plan-btn .price .per
     .pill .pill-quiet  (chat.js REWRITES the pill's className — never rely on
                         another class surviving on #free-pill)
     .dialog-list li[aria-current] .open .meta  .icon-btn  .form-msg(-error)
   Reference markup that chat.js may grow into is styled alongside it:
     .msg-person .msg-companion .msg-bubble .msg-who .who-dot .msg-meta
     .day-divider (and the older .day-note).
   ========================================================================== */

/* The hidden attribute is how every script here shows and hides things; without
   this it loses to any display rule below. */
[hidden] { display: none !important; }

/* ---------- App shell ----------
   site.css puts `display:flex; flex-direction:column` on body. The chat keeps
   that column but locks it to the viewport so only the message list scrolls.
   `100dvh` keeps the composer above the mobile browser chrome; `100vh` is the
   fallback for browsers without dynamic viewport units. */
body.app {
  min-height: 100vh;
  min-height: 100dvh;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
}
body.app-scroll {           /* login and account: ordinary scrolling pages */
  height: auto;
  overflow: visible;
}

.app-shell {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.thread-col {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- App header ---------- */
.app-header {
  flex: none;
  z-index: 40;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.app-header .bar {
  width: 100%;
  max-width: 82rem;
  margin-inline: auto;
  padding-inline: 16px;
  display: flex;
  align-items: center;
  gap: .6rem;
  min-height: 60px;
}
.app-header .brand { font-size: 1.2rem; gap: .5rem; }
.app-header .brand svg,
.app-header .brand .logo { width: 30px; height: 30px; }
.app-logo-fill { fill: var(--accent); }
.app-logo-line { fill: none; stroke: var(--accent-ink); stroke-width: 2.2; stroke-linecap: round; }
.spacer { flex: 1 1 auto; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 2.5rem; min-width: 2.5rem; padding: .35rem .65rem;
  background: transparent; color: var(--ink-2);
  border: 1px solid transparent; border-radius: var(--radius-pill);
  font: 700 .9375rem/1.2 var(--font-body); text-decoration: none; cursor: pointer;
}
.icon-btn:hover { background: var(--ochre-soft); color: var(--terracotta); text-decoration: none; }
.icon-btn svg { width: 1.25rem; height: 1.25rem; flex: none; }
.menu-btn { margin-inline-start: -.35rem; }

/* "Get help now" — always visible, never shouty. Matches site.css .btn-help so
   the app pages and the marketing pages wear the same badge. */
.help-link {
  display: inline-flex; align-items: center; gap: .45rem;
  padding: .55rem 1rem; min-height: 2.5rem;
  border: 2px solid var(--terracotta); border-radius: var(--radius-pill);
  color: var(--terracotta); background: transparent;
  font: 700 .9375rem/1.2 var(--font-body); text-decoration: none; white-space: nowrap;
}
.help-link:hover,
.help-link:focus { background: var(--ochre-soft); color: var(--terracotta); text-decoration: none; }
.help-ico { width: 1rem; height: 1rem; flex: none; }

/* ---------- Conversations: a notebook margin ----------
   One element, two jobs. On a phone chat.js opens it as a modal drawer; from
   900px up it sits in the page as a rail. A <dialog> without [open] is
   display:none in the UA sheet, so the rail rule below only lives in the
   wide-screen block — and `.sheet[open]` is what makes the drawer visible. */
dialog::backdrop { background: rgba(35, 25, 15, .5); }
dialog {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  padding: 0;
  box-shadow: var(--shadow-lift);
}

.sheet {
  margin: 0; height: 100%; max-height: 100%;
  width: min(21rem, 88vw); max-width: 88vw;
  background: var(--surface-2);
  border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
  border-inline-start: none;
}
.sheet[open] { display: flex; flex-direction: column; }

.sheet .sheet-head {
  flex: none;
  display: flex; align-items: center; gap: .5rem;
  padding: .85rem 1rem; border-bottom: 1px solid var(--line);
}
.sheet .sheet-head h2 { margin: 0; font-size: 1.15rem; letter-spacing: -.01em; }
/* flex:0 1 auto, not 1 1 auto: the ruling is painted on this element, so a
   stretched body would fill the whole drawer with empty ruled lines. It still
   shrinks and scrolls when the list is longer than the drawer. */
.sheet .sheet-body { flex: 0 1 auto; padding: 1rem 1rem 1.5rem; overflow-y: auto; }

/* A ruled page with one ochre margin line, drawn in CSS: no image, no request. */
.rail-body {
  background-image:
    linear-gradient(to right, transparent 26px, var(--ochre-line) 26px, var(--ochre-line) 27.5px, transparent 27.5px),
    repeating-linear-gradient(to bottom, transparent 0 31px, var(--line) 31px 32px);
  background-position: 16px 0, 0 0;
  background-repeat: repeat-y, repeat;
}

.dialog-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .2rem; }
/* min-width:0 on both: a grid item's automatic minimum otherwise lets a long
   conversation name push the whole list wider than the margin it sits in. */
.dialog-list li { display: flex; align-items: center; gap: .15rem; min-width: 0; }
.dialog-list .open {
  flex: 1 1 auto; min-width: 0; text-align: left;
  background: transparent; border: 1px solid transparent;
  border-radius: var(--radius-sm); padding: .5rem .6rem .5rem 1.35rem; cursor: pointer;
  color: var(--ink-2); font: 600 .9375rem/1.35 var(--font-body);
  overflow: hidden;
}
/* chat.js writes the name into the first span and the date into .meta. */
.dialog-list .open > span:first-child {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; overflow-wrap: anywhere;
}
.dialog-list .open:hover { background: var(--surface); color: var(--ink); }
.dialog-list li[aria-current="true"] .open {
  background: var(--accent-soft);
  border-color: var(--accent-line);
  color: var(--ink);
  padding-left: 1.25rem;
}
.dialog-list .meta {
  display: block; font-family: var(--font-hand); font-weight: 500;
  font-size: 1.0625rem; line-height: 1.2; color: var(--muted); margin-top: .05rem;
}
.dialog-list .icon-btn { min-width: 2.25rem; min-height: 2.25rem; padding: .3rem; }

#dialog-note { padding-left: 1.35rem; margin: .85rem 0 0; }

.sheet-nav {
  margin-top: 1.4rem; padding-top: 1rem; padding-left: 1.35rem;
  border-top: 1px solid var(--line);
  display: flex; flex-wrap: wrap; gap: .4rem 1rem; font-size: .9rem;
}
.sheet-nav a { color: var(--ink-2); text-decoration: none; font-weight: 600; }
.sheet-nav a:hover { color: var(--accent); text-decoration: underline; }

/* ---------- Message list ---------- */
.chat-main {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 1rem 0 .5rem;
}
.chat-inner {
  width: 100%;
  max-width: 46rem;
  margin-inline: auto;
  padding-inline: 20px;
  display: flex; flex-direction: column; gap: 1.1rem;
  min-height: 100%;
}

/* The list and the card slot are themselves columns: without this the bubbles
   inside them are plain blocks and align-self never applies. */
.messages-slot, #cards { display: flex; flex-direction: column; gap: .75rem; }
/* An empty card slot would still take a gap of the thread column. The message
   list is left alone on purpose: it is the aria-live region, and a live region
   that is display:none when its first child arrives is not announced. */
#cards:empty { display: none; }

.msg { margin: 0; max-width: 88%; }
/* Single line breaks inside an answer (lists, short lines) are kept as written. */
.msg p, .msg-bubble p { margin: 0 0 .65rem; max-width: none; white-space: pre-wrap; }
.msg p:last-child, .msg-bubble p:last-child { margin-bottom: 0; }

/* The person: ochre paper, right-hand side. */
.msg-user,
.msg-person > .msg-bubble {
  background: var(--ochre-soft);
  border: 1px solid var(--ochre-line);
  border-radius: var(--radius-lg);
  border-bottom-right-radius: 8px;
  padding: .9rem 1.1rem;
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}
.msg-user { align-self: flex-end; }
.msg-person { align-self: flex-end; display: flex; flex-direction: column; align-items: flex-end; }
.msg-person > .msg-bubble { max-width: 100%; }

/* The companion: white paper with a green rule down the left edge. */
.msg-assistant,
.msg-companion > .msg-bubble {
  background: var(--surface);
  border: 1px solid var(--accent-line);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-lg);
  border-bottom-left-radius: 8px;
  padding: .9rem 1.1rem;
  color: var(--ink);
  box-shadow: var(--shadow);
  font-size: 1.0625rem;
  line-height: 1.55;
}
.msg-assistant { align-self: flex-start; max-width: 94%; position: relative; margin-top: 1.4rem; }
.msg-companion { align-self: flex-start; display: flex; flex-direction: column; align-items: flex-start; max-width: 94%; }
.msg-companion > .msg-bubble { max-width: 100%; }

/* The who-mark above a companion answer. chat.js does not build a who-line yet,
   so the plain bubble gets the dot on its own; when a .msg-who arrives (with the
   brand in a [data-brand] span, never a string in this file) the dot moves into
   it and the stand-alone one steps aside. */
.msg-assistant::before {
  content: "";
  position: absolute;
  top: -1rem; left: 2px;
  width: .55rem; height: .55rem;
  border-radius: 50%;
  background: var(--accent);
}
.msg-assistant:has(.msg-who)::before { content: none; }

.msg-who {
  display: flex; align-items: center; gap: .4rem;
  font-family: var(--font-display);
  font-size: .8125rem; font-weight: 600;
  letter-spacing: .08em; text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 .35rem .25rem;
  max-width: none;
}
.who-dot { width: .55rem; height: .55rem; border-radius: 50%; background: var(--accent); flex: none; }

.msg-meta {
  font-family: var(--font-hand); font-weight: 500;
  font-size: 1.0625rem; line-height: 1;
  color: var(--muted);
  margin: .35rem .35rem 0;
  max-width: none;
}

/* While the first token is on its way. */
.msg-pending { color: var(--ink-2); }
.typing { display: inline-flex; gap: .3rem; align-items: center; height: 1.2em; }
.typing i {
  width: .42rem; height: .42rem; border-radius: 50%; background: var(--accent);
  animation: blink 1.2s infinite ease-in-out;
}
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* A date, written in the margin hand. */
.day-divider, .day-note {
  display: flex; align-items: center; gap: .75rem;
  margin: .25rem 0 0; max-width: none;
  color: var(--muted);
  font-family: var(--font-hand); font-weight: 500; font-size: 1.125rem;
}
.day-divider::before, .day-divider::after,
.day-note::before, .day-note::after {
  content: ""; flex: 1 1 auto; height: 1px; background: var(--line);
}

/* ---------- Empty state ---------- */
.opener { text-align: center; max-width: none; }
.opener-art { width: 84px; height: 56px; display: block; margin: 0 auto .45rem; }
.sun-core { fill: var(--sun); opacity: .8; }
.sun-rays { fill: none; stroke: var(--ochre); stroke-width: 3.4; stroke-linecap: round; opacity: .85; }
.sun-hill { fill: none; stroke: var(--accent-line); stroke-width: 3.4; stroke-linecap: round; }
.opener h1 {
  font-size: clamp(1.55rem, 5.2vw, 1.95rem);
  line-height: 1.08;
  letter-spacing: -.02em;
  margin: 0 0 .4rem;
  color: var(--ink);
}
.opener p { color: var(--ink-2); font-size: 1rem; max-width: 44ch; margin: 0 auto; }

/* ---------- Inline cards (paywall, crisis, sign-in prompt, errors) ---------- */
.chat-card {
  align-self: stretch;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 1.15rem 1.3rem;
  box-shadow: var(--shadow-sm);
}
.chat-card h2 { font-size: 1.2rem; margin-bottom: .35rem; letter-spacing: -.01em; }
.chat-card p { color: var(--ink-2); max-width: none; }
.chat-card .actions { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1rem; }
.chat-card .actions .btn { flex: 1 1 12rem; }
.chat-card .fine { font-size: .85rem; margin: .75rem 0 0; color: var(--muted); max-width: none; }
.chat-card .lines { margin-top: .9rem; }
.chat-card-crisis { border-color: var(--ochre-line); border-left: 4px solid var(--terracotta); background: var(--ochre-soft); }
.chat-card-crisis h2 { color: var(--terracotta); }
.chat-card-crisis .lines li { background: var(--surface); }
.chat-card-error { border-color: var(--line-strong); border-left: 4px solid var(--danger); background: var(--danger-soft); }

.plan-row { display: grid; gap: .6rem; margin-top: 1rem; }
@media (min-width: 30em) { .plan-row { grid-template-columns: 1fr 1fr; } }
.plan-btn {
  display: flex; flex-direction: column; align-items: flex-start; gap: .1rem;
  padding: .85rem 1.1rem; text-align: left;
  border: 2px solid var(--accent-line); border-radius: var(--radius);
  background: var(--surface); color: var(--ink); cursor: pointer;
  font: 700 1rem/1.3 var(--font-body);
}
.plan-btn:hover { background: var(--accent-soft); border-color: var(--accent); }
.plan-btn .price { font-family: var(--font-display); font-size: 1.4rem; color: var(--accent); }
.plan-btn .per { color: var(--ink-2); font-weight: 400; font-size: .9rem; }

/* ---------- Composer ---------- */
.composer-bar {
  flex: none;
  border-top: 1px solid var(--line);
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: .6rem 0 .75rem;
  padding-bottom: calc(.75rem + env(safe-area-inset-bottom));
}
.composer-inner {
  width: 100%;
  max-width: 46rem;
  margin-inline: auto;
  padding-inline: 20px;
}

/* Topic chips. Each one is a link to the message box: it works with no script
   at all, and chat.js can take the click and drop [data-suggestion] in. */
.composer-top { display: flex; align-items: center; flex-wrap: wrap; gap: .5rem; margin-bottom: .6rem; }
.suggestions { list-style: none; margin: 0; padding: 0; display: flex; gap: .5rem; flex-wrap: wrap; flex: 1 1 auto; }
.chip-btn {
  display: inline-flex; align-items: center;
  font: 600 .875rem/1.2 var(--font-body);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-bottom-width: 3px;
  border-radius: var(--radius-pill);
  padding: .45rem .9rem;
  text-decoration: none;
  cursor: pointer;
}
.chip-btn:hover, .chip-btn:focus { background: var(--accent-soft); border-color: var(--accent-line); color: var(--ink); text-decoration: none; }

.composer {
  display: flex; align-items: flex-end; gap: .6rem;
  background: var(--surface);
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-lg);
  padding: .5rem .5rem .5rem 1rem;
  box-shadow: var(--shadow);
}
.composer:focus-within { border-color: var(--accent); box-shadow: var(--shadow), var(--ring); }
.composer textarea {
  flex: 1 1 auto;
  resize: none;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: 400 1.0625rem/1.5 var(--font-body);
  padding: .55rem 0;
  min-height: 2.6rem;
  max-height: 9rem;          /* chat.js caps the auto-grow at 144px */
}
.composer textarea::placeholder { color: var(--muted); }
.composer textarea:focus { outline: none; }

.send-btn {
  flex: none; width: 2.9rem; height: 2.9rem; padding: 0;
  border-radius: 50%; border: 0; cursor: pointer;
  background: var(--accent); color: var(--accent-ink);
  display: inline-grid; place-items: center;
}
.send-btn:hover { background: var(--accent-strong); }
.send-btn:disabled { opacity: .45; cursor: default; }
.send-btn svg { width: 1.3rem; height: 1.3rem; }

/* site.css styles .btn but not its disabled state, and the consent gate depends
   on "Continue" visibly not being ready yet. */
.btn:disabled, .btn[disabled] { opacity: .45; cursor: default; filter: none; }
.btn:disabled:hover, .btn[disabled]:hover { filter: none; }

.composer-foot {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap-reverse; gap: .45rem; margin-top: .55rem;
}
.composer-note {
  margin: 0; flex: 1 1 16rem; max-width: none;
  font-size: .8125rem; line-height: 1.5; color: var(--muted);
}

/* The allowance pill. chat.js rewrites className to "pill" or "pill pill-quiet",
   so everything this element needs has to hang off those two names. */
.pill {
  display: inline-block; margin: 0; flex: none; max-width: none;
  padding: .25rem .8rem;
  font-size: .8125rem; font-weight: 700; letter-spacing: .02em;
  color: var(--ink);
  background: var(--ochre-soft);
  border: 1px solid var(--ochre-line);
  border-radius: var(--radius-pill);
}
.pill-quiet { background: var(--surface-2); color: var(--ink-2); border-color: var(--line-strong); }

/* ---------- Modals (native <dialog>) ---------- */
.modal {
  margin: auto;
  width: min(32rem, calc(100vw - 2rem));
  border-radius: var(--radius-lg);
  background: var(--surface);
}
.modal .modal-body { padding: 1.5rem; }
.modal h2 { font-size: 1.35rem; letter-spacing: -.015em; }
.modal p { max-width: none; }
.modal .actions { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1.25rem; }
.modal .actions .btn { flex: 1 1 9rem; }
.modal .fine { font-size: .8125rem; color: var(--muted); margin: .75rem 0 0; max-width: none; }

/* Consent checkboxes — large hit area, visible focus. */
.consent-check {
  display: flex; gap: .75rem; align-items: flex-start;
  padding: .8rem; margin: .6rem 0;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface-2); cursor: pointer;
}
.consent-check:hover { border-color: var(--ochre-line); }
.consent-check input { flex: none; width: 1.25rem; height: 1.25rem; margin: .15rem 0 0; accent-color: var(--accent); }
.consent-check span { font-size: .95rem; }

/* ---------- Forms (login, account) ---------- */
.app-page-main { width: min(100% - 2rem, 27rem); margin: 2.5rem auto 3rem; }
/* site.css sizes h1 for a full-width page; a form column wants a quieter one. */
.app-page-main h1 { font-size: clamp(2rem, 5vw, 2.6rem); margin-bottom: .6rem; }
.app-wide { max-width: 44rem; width: min(100% - 2rem, 44rem); }
.field { display: block; margin-bottom: 1rem; }
.field > span { display: block; font-weight: 700; font-size: .9rem; margin-bottom: .35rem; }
.field input {
  width: 100%; padding: .75rem .95rem;
  border: 1.5px solid var(--line-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--ink);
  font: 400 1rem/1.4 var(--font-body);
}
.field input:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
.field input::placeholder { color: var(--muted); }
.field .hint { display: block; font-weight: 400; color: var(--ink-2); font-size: .85rem; margin-top: .35rem; }
.code-input { letter-spacing: .5em; font-size: 1.4rem !important; text-align: center; }

.or {
  display: flex; align-items: center; gap: .75rem;
  color: var(--muted); font-size: .9rem; margin: 1.25rem 0;
}
.or::before, .or::after { content: ""; flex: 1 1 auto; border-top: 1px solid var(--line); }

.google-btn { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.google-btn:hover { background: var(--surface-2); color: var(--ink); }
.google-btn svg { width: 1.15rem; height: 1.15rem; }

.form-msg { margin: .75rem 0 0; font-size: .9375rem; max-width: none; }
.form-msg-error { color: var(--danger); }
.form-msg-ok { color: var(--accent); }

.link-btn {
  background: none; border: none; padding: 0; cursor: pointer;
  color: var(--accent); font: 700 .9375rem var(--font-body); text-decoration: underline;
  text-underline-offset: .15em;
}
.link-btn:hover { color: var(--accent-strong); }
.link-btn:disabled { color: var(--muted); cursor: default; text-decoration: none; }

/* ---------- Account ---------- */
.account-section { margin-bottom: 1rem; }
.account-section h2 { font-size: 1.2rem; letter-spacing: -.01em; }
.kv { list-style: none; margin: 0; padding: 0; }
.kv li {
  display: flex; flex-wrap: wrap; gap: .25rem 1rem; justify-content: space-between;
  padding: .55rem 0; border-bottom: 1px solid var(--line);
}
.kv li:last-child { border-bottom: none; }
.kv .k { color: var(--ink-2); font-size: .9375rem; }
.kv .v { font-weight: 700; text-align: right; }
.status-tag {
  display: inline-block; border-radius: var(--radius-pill); padding: .1rem .65rem;
  font-size: .8125rem; font-weight: 700;
  background: var(--accent-soft); color: var(--accent); border: 1px solid var(--accent-line);
}
.status-tag-quiet { background: var(--surface-2); color: var(--ink-2); border-color: var(--line-strong); }
.status-tag-warn { background: var(--ochre-soft); color: var(--warn); border-color: var(--ochre-line); }
.danger-btn, button.danger-btn, a.danger-btn { color: var(--danger); border-color: var(--danger); background: transparent; }
.danger-btn:hover, button.danger-btn:hover { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.stack { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1rem; }
.stack .btn { flex: 1 1 12rem; }

.busy { opacity: .6; pointer-events: none; }

/* ---------- Very narrow phones (360px and under) ----------
   The header carries three things that must all stay: the conversations
   button, the brand and the crisis link. Below this width they need to be a
   little smaller rather than one of them falling off the edge. */
@media (max-width: 24em) {
  .app-header .bar { gap: .35rem; padding-inline: 12px; }
  .app-header .brand { font-size: 1.05rem; }
  .app-header .brand svg,
  .app-header .brand .logo { width: 26px; height: 26px; }
  .menu-btn { min-width: 2.25rem; padding-inline: .3rem; }
  .help-link { padding: .5rem .7rem; font-size: .875rem; gap: .35rem; }
  .chat-inner, .composer-inner { padding-inline: 14px; }
}

/* ---------- Wide screens: the margin becomes a rail ----------
   The same <dialog> is pulled into the flow. The UA sheet gives a dialog
   position:absolute and hides it without [open]; both are overridden here.
   chat.js can still open it modally (it is the only thing that loads the list),
   and :modal puts the drawer back for that moment. */
@media (min-width: 900px) {
  .app-shell {
    flex-direction: row;
    align-items: stretch;
    width: 100%;
    max-width: 82rem;
    margin-inline: auto;
    padding-inline: 16px;
  }

  .sheet {
    display: flex; flex-direction: column;
    position: static; inset: auto; margin: 0;
    flex: none;
    width: 20rem; max-width: none; height: auto; max-height: none;
    padding: 1.4rem 1.25rem 2rem 0;
    background: transparent;
    border: 0; border-right: 1px solid var(--line); border-radius: 0;
    box-shadow: none;
    overflow: visible;
  }
  .sheet .sheet-head { padding: 0 0 .4rem; border-bottom: 0; }
  .sheet .sheet-head h2 {
    font-family: var(--font-hand); font-weight: 500;
    font-size: 1.5rem; line-height: 1; color: var(--terracotta);
    padding-left: 1.6rem;
  }
  #sheet-close { display: none; }
  /* flex:none so the ruling stops where the list stops, instead of filling the
     whole column with empty lines. */
  .sheet .sheet-body { flex: 0 0 auto; padding: .6rem 0 .75rem .25rem; overflow: visible; }
  .sheet .rail-body {
    background-image:
      linear-gradient(to right, transparent 14px, var(--ochre-line) 14px, var(--ochre-line) 15.5px, transparent 15.5px),
      repeating-linear-gradient(to bottom, transparent 0 31px, var(--line) 31px 32px);
    background-position: 0 0, 0 0;
  }
  .sheet .btn-block { width: auto; margin-left: 1.6rem; display: flex; }
  .dialog-list .open, #dialog-note, .sheet-nav { padding-left: 1.6rem; }
  .dialog-list li[aria-current="true"] .open { padding-left: 1.5rem; }

  /* Opened from the header button: a drawer over the page again. */
  .sheet:modal {
    position: fixed; inset: 0 auto 0 0;
    width: min(22rem, 88vw); height: 100%; max-height: 100%;
    padding: 0;
    background: var(--surface-2);
    border: 1px solid var(--line); border-inline-start: 0;
    border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
    box-shadow: var(--shadow-lift);
    overflow: hidden;
  }
  .sheet:modal .sheet-head { padding: .85rem 1rem; border-bottom: 1px solid var(--line); }
  .sheet:modal .sheet-head h2 {
    font-family: var(--font-display); font-weight: 600;
    font-size: 1.15rem; color: var(--ink); padding-left: 0;
  }
  .sheet:modal #sheet-close { display: inline-flex; }
  .sheet:modal .sheet-body { padding: 1rem 1rem 1.5rem; overflow-y: auto; }
  .sheet:modal .btn-block { width: 100%; margin-left: 0; }

  .thread-col { padding-left: 1.75rem; }
  .chat-main { padding-top: 1.1rem; }
  .chat-inner, .composer-inner { padding-inline: 0; max-width: 44rem; }
  /* An unfinished thread sits on the composer, the way a page fills from the
     bottom; the opening note stays at the top. */
  .messages-slot { margin-top: auto; }
  .msg-user { max-width: 76%; }
  .msg-person { max-width: 76%; }
  .msg-assistant, .msg-companion { max-width: 86%; }
}

@media (prefers-reduced-motion: reduce) {
  .typing i { animation: none; opacity: .6; }
}

/* ---------- Feedback components ---------- */
.answer-rating {
  display: flex; gap: .5rem; align-items: center;
  margin-top: .75rem; padding-top: .75rem;
  border-top: 1px solid var(--line);
  font-size: .875rem;
}
.rating-btn {
  background: transparent; border: none; cursor: pointer;
  padding: .35rem .5rem; min-width: 2rem; min-height: 2rem;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--ink-2);
  font: 1rem/1 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.rating-btn:hover:not(:disabled) {
  background: var(--surface); color: var(--ink);
}
.rating-btn:disabled {
  cursor: not-allowed; opacity: .5;
}
.rating-thanks {
  margin-left: .75rem;
  color: var(--ink-2); font-size: .8125rem;
  font-weight: 500;
}

/* Pulse modal: keep it small on all sizes */
#pulse-modal .modal-body {
  max-width: 360px;
}
#pulse-modal h2 {
  font-size: 1.1rem; margin-bottom: .75rem;
}
#pulse-modal .actions {
  display: flex; gap: .5rem; flex-wrap: wrap;
}
#pulse-modal .btn {
  flex: 1 1 auto; min-width: auto;
}
.btn-close {
  background: transparent; border: none; color: var(--ink-2);
  font-size: 1.5rem; cursor: pointer; padding: .25rem;
  width: 2.5rem; height: 2.5rem; position: absolute;
  top: .5rem; right: .5rem;
}
.btn-close:hover { color: var(--ink); }
.btn-close-link {
  color: var(--ink-2); text-decoration: none; font-weight: 600;
  font-size: .875rem; display: inline-block; padding: .5rem;
  background: transparent; border: none; cursor: pointer;
}
.btn-close-link:hover { color: var(--accent); text-decoration: underline; }

/* Exit panel within cards */
.exit-panel {
  margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--line);
}
.exit-panel p { font-size: .95rem; margin: 0 0 .75rem; color: var(--ink-2); }
.exit-actions {
  display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .5rem;
}
.exit-actions .btn { flex: 1 1 auto; min-width: auto; font-size: .9rem; }
.exit-skip {
  color: var(--ink-2); text-decoration: none; font-weight: 600;
  font-size: .875rem; display: inline-block; padding: .5rem;
  background: transparent; border: none; cursor: pointer;
}
.exit-skip:hover { color: var(--accent); text-decoration: underline; }

/* Cancellation modal */
#cancellation-modal .modal-body {
  max-width: 380px;
}
#cancellation-modal h2 {
  font-size: 1.1rem; margin-bottom: 1rem;
}
#cancellation-modal .actions {
  display: flex; flex-direction: column; gap: .5rem;
  margin-bottom: 1rem;
}
#cancellation-modal .btn {
  width: 100%; text-align: left;
}
#cancellation-modal .form-msg {
  margin-top: .5rem;
}
