/* Advisers Research: the app's own layout, on top of house-style.css.
 * Every colour here is a house token (the dimming behind a drawer is the house dialog's).
 * Reading text (questions, answers, the text box) is 15px, or 17px with Large type,
 * as brief section 9 asks; the chrome keeps the house scale. */

:root {
  --read: 15px;
  --col: 720px;
  --gutter: 16px;
  --tap: 30px;            /* least height of a control; 44px on touch screens */
  --field-size: 13px;     /* 16px on touch screens, or iOS zooms the page on focus */
}
:root[data-large] { --read: 17px; }
@media (pointer: coarse) {
  :root { --tap: 44px; --field-size: 16px; }
}

html { height: 100%; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { height: 100%; overflow: hidden; overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
button, a, summary, label { touch-action: manipulation; }
input[type=text], input[type=search], input[type=email], textarea { font-size: var(--field-size); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.noscript { padding: 24px; color: var(--dim); }

/* ------------------------------------------------------------ the frame */
/* --vvh and --vvt follow the visible part of the screen (see fitViewport in app.ts),
   so the input bar rides above the iPhone keyboard. */
.app { position: fixed; top: 0; left: 0; right: 0; height: var(--vvh, 100dvh);
  transform: translateY(var(--vvt, 0px)); }

.topbar { height: calc(var(--hdr) + env(safe-area-inset-top)); flex-basis: calc(var(--hdr) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(8px, env(safe-area-inset-right)) 0 max(8px, env(safe-area-inset-left)); gap: 4px; }
.topbar button { min-height: var(--tap); }
.topbar a.brand { color: var(--text); text-decoration: none; padding: 6px 4px; border-radius: var(--r-sm); gap: 3px; }
.signin .brand { gap: 3px; }
.topbar .brand span, .signin .brand span { margin-left: 0; }
.topbar .brand span, .signin .brand span { display: inline; }   /* the second word is part of the name here */

.ask { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.scroller { position: relative; flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; outline: none; }
.thread { max-width: var(--col); margin: 0 auto;
  padding: 16px max(var(--gutter), env(safe-area-inset-right)) 24px max(var(--gutter), env(safe-area-inset-left)); }

/* --------------------------------------------------------- conversation */
.turn + .turn { margin-top: 28px; }
.turn:last-child { min-height: calc(var(--scroller-h, 0px) - 40px); }   /* so the newest question can sit at the top */

.question { display: flex; justify-content: flex-end; margin: 0 0 14px; }
.question > div { max-width: 88%; background: var(--raised); border: 1px solid var(--line); border-radius: var(--r);
  padding: 8px 12px; font-size: var(--read); line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }

.md { font-size: var(--read); line-height: 1.6; overflow-wrap: break-word; }
.md:empty { display: none; }
.md p { margin: 0 0 12px; }
.md ul, .md ol { margin: 0 0 12px; padding-left: 22px; }
.md li { margin: 0 0 6px; }
.md li > p { margin-bottom: 6px; }
.md li > ul, .md li > ol { margin: 6px 0 0; }
.md blockquote { margin: 0 0 12px; padding: 1px 0 1px 12px; border-left: 2px solid var(--line-hover); color: var(--dim); }
.md .section-label { margin: 20px 0 8px; }
/* A table in an answer (contract 1.6). It sits in its own box, which scrolls sideways when the table
 * is wider than the answer, so the page and the answer column never widen. Cells wrap. The table is
 * as wide as its words need, but never narrower than the box, and never wider than the box or 660px,
 * whichever is more: on a computer it always fits the column, and on a phone it gets room to be read
 * and scrolls. Type sizes follow --read, so Large type enlarges it too. */
.md .table-block { margin: 0 0 12px; }
.md .table-wrap { max-width: 100%; overflow-x: auto; overscroll-behavior-x: contain;
  border: 1px solid var(--line); border-radius: var(--r); }
.md .table-hint { margin: 5px 0 0; font-size: 12px; line-height: 1.45; color: var(--dim); }   /* only while the table overflows */
.md .table-wrap:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.md table { border-collapse: collapse; width: max-content; min-width: 100%; max-width: max(100%, 660px);
  font-size: calc(var(--read) - 1px); line-height: 1.45; }
.md th, .md td { padding: 7px 10px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line-soft);
  overflow-wrap: break-word; }
.md th { font-size: calc(var(--read) - 4px); font-weight: bold; letter-spacing: .08em; text-transform: uppercase;
  color: var(--dim); background: var(--panel); white-space: nowrap; vertical-align: bottom; }
.md tbody tr:last-child td { border-bottom: 0; }
.md :is(th, td)[align="right"] { text-align: right; font-variant-numeric: tabular-nums; }
.md :is(th, td)[align="center"] { text-align: center; }
.md > :first-child { margin-top: 0; }
.md > :last-child, .md blockquote > :last-child, .md li > :last-child { margin-bottom: 0; }
.md a, .checked-list a { color: var(--text); text-decoration: underline; text-decoration-thickness: 1px;
  text-decoration-color: var(--dimmer); text-underline-offset: 2px; border-radius: 2px; }
.md a:hover, .checked-list a:hover { text-decoration-color: var(--text); }

/* the "Opening…" line while a chat loads */
.quiet-line { display: flex; align-items: center; gap: 9px; min-height: 28px; margin: 0;
  color: var(--dim); font-size: calc(var(--read) - 1px); }

/* how an answer ended, when it did not simply finish */
.status-note { margin: 10px 0 0; color: var(--dim); font-size: 12px; }
.status-box { margin-top: 12px; align-items: center; font-size: calc(var(--read) - 2px); line-height: 1.5; }
.status-box > span { flex: 1; min-width: 0; }
.status-box button { flex: 0 0 auto; min-height: var(--tap); }
.callout { display: flex; gap: 8px; padding: 9px 10px; color: var(--dim); background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--r); }
.callout b { color: var(--text); }

/* The too-long note and its way on: the button sits beside the note where there is room and
 * under it on a phone; a failure adds one line beneath. */
.continue-box { flex-wrap: wrap; row-gap: 10px; }
.continue-box > span:first-child { flex: 1 1 16em; }
.continue-box .preparing { flex: 0 0 auto; display: flex; align-items: center; gap: 9px; min-height: var(--tap); color: var(--text); }
.continue-box .continue-problem { flex: 1 0 100%; margin: 0; color: var(--text); }

/* A chat that carries on from an earlier one opens with what was carried over, folded shut. */
.carried { margin: 0 0 18px; border-bottom: 1px solid var(--line-soft); }
.carried > details { border-top: 0; margin-top: 0; padding-top: 0; }
.carried > details > summary, .carried-head { display: block; min-height: var(--tap); padding: 9px 0; margin: 0; line-height: 1.6;
  font-size: 11px; font-weight: bold; letter-spacing: .12em; text-transform: uppercase; color: var(--dim); }
.carried > details > summary::before { display: inline-block; margin-right: 8px; vertical-align: 1px; }
.carried .cap { margin-right: 8px; }
.carried .from { font-size: 12px; font-weight: normal; letter-spacing: 0; text-transform: none; color: var(--text); overflow-wrap: anywhere; }
.carried details > .md { margin: 4px 0 12px; }
.carried-link { margin: 0; padding: 2px 0 12px; font-size: calc(var(--read) - 2px); }   /* outside the fold: always in view */
.carried-link a { color: var(--text); text-decoration: underline; text-decoration-thickness: 1px;
  text-decoration-color: var(--dimmer); text-underline-offset: 2px; border-radius: 2px; }
.carried-link a:hover { text-decoration-color: var(--text); }
.carried ~ .welcome { min-height: 180px; }
@media (pointer: coarse) {
  .carried > details > summary, .carried-head { padding-block: 12px; }
  .carried-link { padding: 0 0 4px; }
  .carried-link a { display: inline-block; padding-block: 10px; }
}

/* "Checked:" is one quiet caption that opens into a list */
details.checked { margin-top: 14px; padding-top: 4px; }
details.checked > summary { display: block; min-height: var(--tap); padding: 9px 0; margin: 0; line-height: 1.6; }
details.checked > summary::before { display: inline-block; margin-right: 8px; vertical-align: 1px; }
details.checked .cap { margin-right: 8px; }
details.checked .labels { font-size: 12px; font-weight: normal; letter-spacing: 0; text-transform: none; }
details.checked[open] .labels { display: none; }
@media (pointer: coarse) { details.checked > summary { padding-block: 12px; } }
.checked-list { list-style: none; margin: 0; padding: 0; font-size: calc(var(--read) - 2px); line-height: 1.45; color: var(--dim); }
.checked-list li { border-bottom: 1px solid var(--line-soft); }
.checked-list li:last-child { border-bottom: 0; }
.checked-list li > * { display: block; padding: 8px 0 8px 14px; }
@media (pointer: coarse) { .checked-list li > * { padding-block: 12px; } }

.actions { display: flex; gap: 6px; margin: 6px 0 0 -10px; }
.actions button { min-height: var(--tap); }

.welcome { min-height: calc(var(--scroller-h, 320px) - 40px); display: grid; place-content: center; justify-items: center;
  gap: 14px; text-align: center; color: var(--dim); font-size: var(--read); line-height: 1.5; }
.welcome p { margin: 0; max-width: 34ch; }
.welcome button { min-height: var(--tap); }

/* ------------------------------------------------------------ input bar */
.composer { flex: 0 0 auto; margin: 0; background: var(--panel); border-top: 1px solid var(--line);
  padding: 10px max(var(--gutter), env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom))
    max(var(--gutter), env(safe-area-inset-left)); }
:root[data-keyboard] .composer { padding-bottom: 10px; }   /* the keyboard already covers the home bar */
.composer-in { max-width: var(--col); margin: 0 auto; display: flex; flex-direction: column; gap: 8px; }
.composer textarea { display: block; width: 100%; min-height: 44px; max-height: 168px; resize: none;
  padding: 10px 11px; border-radius: var(--r); line-height: 1.45; font-size: max(var(--read), var(--field-size)); }
.composer textarea:disabled { opacity: .45; }   /* while the chat that carries this one on is being prepared */
/* The row is as tall as the switch with its border or two lines of the progress text, whichever is
 * more, so the bar keeps one height whether he is idle, waiting on a short line or on a long one. */
.composer-row { display: flex; align-items: center; gap: 8px;
  min-height: max(calc(var(--tap) + 2px), calc((var(--read) - 1px) * 2.6)); }
/* the one progress line: in the speed switch's place while an answer is on its way. A long line
 * (the model's own notes run to about 130 characters) wraps to two lines and then ends in "…". */
.composer .progress { flex: 1; min-width: 0; display: flex; align-items: center; gap: 9px; padding-left: 2px;
  color: var(--dim); font-size: calc(var(--read) - 1px); line-height: 1.3; }
.composer .progress span { min-width: 0; overflow: hidden; overflow-wrap: anywhere; display: -webkit-box; -webkit-box-orient: vertical;
  -webkit-line-clamp: 2; line-clamp: 2; }
.composer .progress + .grow { display: none; }
.composer .progress[hidden] + .grow { display: block; }
.composer .seg button, .drawer-body .seg button { min-height: var(--tap); padding: 4px 13px; }
.composer .send, .composer .stop { min-height: var(--tap); min-width: 78px; }
.composer-problem { font-size: 13px; line-height: 1.45; }

/* -------------------------------------------------------------- sign-in */
.signin { position: fixed; top: var(--vvt, 0px); left: 0; right: 0; height: var(--vvh, 100dvh); overflow: auto;
  display: grid; place-content: center; justify-items: center; gap: 24px;
  padding: calc(24px + env(safe-area-inset-top)) 24px calc(24px + env(safe-area-inset-bottom)); }
.signin-box { width: min(320px, calc(100vw - 48px)); }
.signin form { display: flex; flex-direction: column; gap: 10px; margin: 0; }
.signin label { font-size: 15px; }
.signin input { width: 100%; min-height: 46px; padding: 10px 12px; font-size: 16px; }
.signin input.code { font-family: var(--narrow); font-size: 20px; font-weight: bold; letter-spacing: .32em; text-align: center; }
.signin button { min-height: 44px; }
.signin .sent { margin: 0 0 8px; color: var(--dim); font-size: 13px; line-height: 1.5; overflow-wrap: anywhere; }
.signin .sent b { color: var(--text); font-weight: normal; }
.problem { margin: 0; color: var(--gold); font-size: 13px; line-height: 1.45; }
.signin-box > .problem { margin-bottom: 14px; text-align: center; }
.signin-more { display: flex; justify-content: space-between; gap: 6px; margin: 4px -10px 0; }

/* -------------------------------------------------------------- drawers */
.scrim { position: fixed; inset: 0; z-index: 10; background: rgba(0, 0, 0, .55); animation: fade-in .14s ease; }
.drawer { position: fixed; z-index: 11; top: var(--vvt, 0px); height: var(--vvh, 100dvh); width: min(380px, 100%);
  display: flex; flex-direction: column; background: var(--panel); box-shadow: var(--shadow-dialog);
  padding-top: env(safe-area-inset-top); }
.drawer.left { left: 0; border-right: 1px solid var(--line); padding-left: env(safe-area-inset-left); animation: drawer-left .16s ease; }
.drawer.right { right: 0; border-left: 1px solid var(--line); padding-right: env(safe-area-inset-right); animation: drawer-right .16s ease; }
@media (max-width: 600px) { .drawer { width: 100%; border: 0; } }
@keyframes drawer-left { from { opacity: 0; transform: translateX(-10px); } to { opacity: 1; transform: none; } }
@keyframes drawer-right { from { opacity: 0; transform: translateX(10px); } to { opacity: 1; transform: none; } }

.drawer .phead { height: var(--hdr); flex-basis: var(--hdr); padding: 0 8px 0 16px; gap: 4px; }
.drawer .phead button { min-height: var(--tap); }
.drawer-search { flex: 0 0 auto; padding: 10px 16px; border-bottom: 1px solid var(--line-soft); }
.drawer-search input { width: 100%; min-height: max(34px, var(--tap)); padding: 4px 10px; }

.history-list { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
.history-list .section-label, .history-list .section-label:first-child { margin: 18px 16px 4px; }
.history-list .empty { padding: 18px 16px; font-size: 13px; color: var(--dim); margin: 0; }
.history-list .retry, .history-list .more-chats { margin: 10px 16px 0; min-height: var(--tap); }
.chat-rows { list-style: none; margin: 0; padding: 0; }
.chat-rows li { display: flex; align-items: center; gap: 4px; padding: 0 8px 0 16px;
  border-bottom: 1px solid var(--line-soft); transition: background var(--ease); }
.chat-rows li:hover { background: var(--raised); }
.chat-rows li.here { background: var(--accent-wash); box-shadow: inset 2px 0 0 var(--accent); }
.chat-link { flex: 1; min-width: 0; min-height: var(--tap); display: flex; flex-direction: column; justify-content: center;
  gap: 2px; padding: 9px 0; color: var(--text); text-decoration: none; border-radius: var(--r-sm); }
.chat-link .title { font-size: calc(var(--read) - 1px); line-height: 1.35; overflow: hidden; display: -webkit-box;
  -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; }
.chat-link .meta { display: flex; gap: 10px; color: var(--dim); font-size: 12px; }
button.icon.more { flex: 0 0 auto; width: max(32px, var(--tap)); height: max(32px, var(--tap)); font-size: 17px; line-height: 1; }

.drawer-body { flex: 1; min-height: 0; overflow-y: auto; padding: 6px 16px calc(24px + env(safe-area-inset-bottom)); }
.drawer-body .section-label, .drawer-body .section-label:first-child { margin: 20px 0 8px; }
.drawer-body .hint { margin: 6px 0 0; line-height: 1.45; }
.drawer-body .value { margin: 0; font-size: 14px; overflow-wrap: anywhere; }
.drawer-body .about { margin: 0; color: var(--dim); font-size: 13px; line-height: 1.55; }
.toggle { display: flex; align-items: center; gap: 10px; min-height: var(--tap); font-size: 14px; cursor: pointer; }
@media (pointer: coarse) { .toggle input[type=checkbox] { width: 20px; height: 20px; } }
.signout { margin-top: 28px; padding-top: 16px; border-top: 1px solid var(--line-soft); }
.signout button { min-height: var(--tap); }

/* ----------------------------------------------------- dialogs and menu */
dialog.sheet { width: min(420px, calc(100vw - 32px)); overflow: auto;
  max-height: calc(var(--vvh, 100vh) - env(safe-area-inset-top) - 24px);
  padding: 16px; color: var(--text); background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--shadow-dialog); animation: rise-in .18s ease; }
dialog.sheet::backdrop { background: rgba(0, 0, 0, .55); }
/* With the on-screen keyboard up, a dialog centres in what is left of the screen
   rather than on the whole screen, where its buttons would sit behind the keyboard. */
:root[data-keyboard] dialog.sheet { top: calc(var(--vvt, 0px) + env(safe-area-inset-top) / 2 + var(--vvh, 100vh) / 2);
  bottom: auto; margin-block: 0; transform: translateY(-50%); animation: none; }
dialog.sheet h3 { margin: 0 0 4px; font-size: 15px; }
dialog.sheet .sub { margin: 0 0 12px; color: var(--dim); font-size: 13px; line-height: 1.45; overflow-wrap: anywhere; }
dialog.sheet .foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
dialog.sheet .foot:empty { display: none; }
dialog.sheet button { min-height: var(--tap); }
dialog.sheet .foot button { min-width: 76px; }
dialog.sheet form { margin: 10px 0 0; }
dialog.sheet input[type=text] { width: 100%; min-height: max(34px, var(--tap)); }
.matter-options { list-style: none; margin: 10px 0 14px; padding: 0; max-height: 38vh; overflow: auto;
  border-top: 1px solid var(--line-soft); }
button.matter { width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 10px; text-align: left;
  padding: 8px 10px; background: none; border: 0; border-bottom: 1px solid var(--line-soft); border-radius: 0; }
button.matter:hover { background: var(--raised); }
button.matter.selected { background: var(--raised); box-shadow: inset 3px 0 0 var(--accent); }
button.matter .num { color: var(--dim); }
.new-matter .ctl { display: flex; gap: 6px; flex-wrap: nowrap; }
.new-matter .ctl input { flex: 1; min-width: 0; }

.popover.menu { position: fixed; z-index: 30; width: 196px; padding: 5px; display: flex; flex-direction: column; gap: 1px; }
.popover.menu button { min-height: var(--tap); padding: 6px 10px; text-align: left; color: var(--text); }

.toast { position: fixed; bottom: calc(112px + env(safe-area-inset-bottom)); z-index: 40; }
