/*
 * The web client's design foundation (VAI-031, ADR-021).
 *
 * Material Design 3's structure — tonal surface roles, a shape scale, state
 * layers, a type scale — expressed in the palette and density of the
 * VNCdirectory org-console prototype, so the two products look like one suite.
 * Not the material-web component library: a custom-element bundle would fight
 * Turbo's morphing and the platform's CSP, and M3 is a system before it is a
 * package.
 *
 * Tokens are named for their role, never their colour, which is what lets the
 * dark scheme be a token swap rather than a second stylesheet.
 */

:root {
  /* Surfaces, from furthest back to nearest front. */
  --ground: #f5f6f9;
  --surface: #ffffff;
  --surface-2: #fbfbfd;
  --sunken: #eef0f4;

  /* Ink, by prominence rather than by darkness. */
  --ink: #161a22;
  --ink-2: #4a5160;
  --ink-3: #7b8290;

  --line: #e2e6ec;
  --line-2: #d3d8e0;

  /* Structure is blue. The org console reserves brass for billing, which this
     surface has none of — carried anyway so the palettes stay one palette. */
  --accent: #2b5fdf;
  --accent-soft: #eaf0ff;
  --accent-ink: #1c47b0;
  --on-accent: #ffffff;
  --brass: #a9781f;
  --brass-soft: #f6efdf;

  --crit: #c4483b;
  --crit-soft: #fae9e6;

  /* M3 shape scale, trimmed to what this surface uses. */
  --radius-sm: 7px;
  --radius: 10px;
  --radius-lg: 18px;
  --radius-full: 999px;

  --shadow-sm: 0 1px 2px rgba(20, 26, 34, .06);
  --shadow: 0 1px 2px rgba(20, 26, 34, .05), 0 8px 24px -12px rgba(20, 26, 34, .18);

  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;

  /* M3 state layers: one opacity per interaction, applied over any role. */
  --state-hover: .08;
  --state-press: .12;
}

/* The default is the viewer's, not ours. An explicit choice wins in both
   directions, which is why the toggle sets data-theme rather than a class. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground: #0e1015; --surface: #171a21; --surface-2: #14171d; --sunken: #1e222b;
    --ink: #eef1f6; --ink-2: #b3bac8; --ink-3: #79808f;
    --line: #262b34; --line-2: #333944;
    --accent: #6f92ff; --accent-soft: #1a2540; --accent-ink: #a9c0ff; --on-accent: #0e1015;
    --brass: #d7ab5c; --brass-soft: #302713;
    --crit: #ec7264; --crit-soft: #351814;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px -14px rgba(0, 0, 0, .7);
  }
}

:root[data-theme="dark"] {
  --ground: #0e1015; --surface: #171a21; --surface-2: #14171d; --sunken: #1e222b;
  --ink: #eef1f6; --ink-2: #b3bac8; --ink-3: #79808f;
  --line: #262b34; --line-2: #333944;
  --accent: #6f92ff; --accent-soft: #1a2540; --accent-ink: #a9c0ff; --on-accent: #0e1015;
  --brass: #d7ab5c; --brass-soft: #302713;
  --crit: #ec7264; --crit-soft: #351814;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px -14px rgba(0, 0, 0, .7);
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* --- the centred surface the sign-in page sits on ----------------------- */

.auth {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 32px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.brand .glyph {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.brand h1 { font-size: 16px; font-weight: 600; margin: 0; letter-spacing: -.01em; }
.brand .sub { font-size: 12px; color: var(--ink-3); }

.auth-card h2 { font-size: 22px; font-weight: 600; margin: 0 0 8px; letter-spacing: -.02em; }
.auth-card p { color: var(--ink-2); margin: 0 0 24px; }

/* --- buttons: M3 state layers over role colours ------------------------- */

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px 20px;
  border: 0;
  border-radius: var(--radius-full);
  background: var(--accent);
  color: var(--on-accent);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  overflow: hidden;
}

/* The state layer is a pseudo-element rather than a colour change, so one rule
   covers every role and nothing has to know the button's own colour. */
.btn::after {
  content: "";
  position: absolute;
  inset: 0;
  background: currentColor;
  opacity: 0;
  transition: opacity 120ms ease;
}

.btn:hover::after { opacity: var(--state-hover); }
.btn:active::after { opacity: var(--state-press); }
.btn:focus-visible { outline: 2px solid var(--accent-ink); outline-offset: 2px; }

/* Deleting is destructive and says so in its colour as well as its label — the
   dialog is the guard, this is the warning inside it. */
.btn--danger { background: var(--crit-soft); color: var(--crit); }

/* The way out of a dialog, which must not compete with the way through it. */
.btn--quiet { background: transparent; color: var(--ink-2); border: 1px solid var(--line); }

.btn-text {
  width: auto;
  background: transparent;
  color: var(--ink-2);
  font-weight: 500;
  padding: 8px 12px;
}

/* --- refusal ------------------------------------------------------------ */

.notice-crit {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  margin-bottom: 20px;
  border-radius: var(--radius);
  background: var(--crit-soft);
  color: var(--crit);
  border: 1px solid color-mix(in srgb, var(--crit) 25%, transparent);
}

.auth-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--ink-3);
  font-size: 12px;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--ink-2);
  cursor: pointer;
}

.icon-btn:hover { background: var(--sunken); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* === the conversation surface =========================================== */

/* An app shell rather than a document: the composer stays reachable and the
   transcript scrolls under it, which is what makes a long conversation usable
   on a laptop. */
.app {
  height: 100%;
  display: grid;
  grid-template-columns: 280px 1fr;
  grid-template-rows: 56px 1fr;
  grid-template-areas: "rail head" "rail main";
}

/* A shell with no conversation rail. Without this the grid still reserved the
   rail's 280px, so the header on every railless page began a third of the way
   across the window with nothing to its left. */
.app--plain {
  grid-template-columns: 1fr;
  grid-template-areas: "head" "main";
}

.app__head {
  grid-area: head;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.app__rail {
  grid-area: rail;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: var(--surface-2);
}

.app__main {
  grid-area: main;
  display: grid;
  grid-template-rows: 1fr auto;
  min-height: 0;
  background: var(--ground);
}

/* Below this the rail is more in the way than it is useful. */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; grid-template-areas: "head" "main"; }
  .app__rail { display: none; }
}

.head__brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; }
.head__name { font-weight: 600; letter-spacing: -.01em; }
.head__sub { font-size: 12px; color: var(--ink-3); }
.head__actions { display: flex; align-items: center; gap: 8px; }

/* --- the rail ----------------------------------------------------------- */

.rail__top { padding: 12px; border-bottom: 1px solid var(--line); }
.rail__list { flex: 1; min-height: 0; overflow-y: auto; padding: 8px; margin: 0; list-style: none; }

.rail__item a {
  display: block;
  padding: 9px 12px;
  border-radius: var(--radius);
  color: var(--ink-2);
  text-decoration: none;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rail__item a:hover { background: var(--sunken); color: var(--ink); }
.rail__item--current a { background: var(--accent-soft); color: var(--accent-ink); font-weight: 500; }
.rail__empty { padding: 12px; color: var(--ink-3); font-size: 13px; }

/* Rename and delete (VAI-044).

   Two icon buttons per row, revealed on hover. Hover alone would hide them
   from anyone not using a mouse, so `:focus-within` brings them back for the
   keyboard and the current conversation keeps them because it is the one most
   likely to be acted on. Opacity rather than `display: none`, because a button
   removed from the box is also removed from the tab order. */
.rail__item { display: flex; align-items: center; gap: 2px; }
.rail__link { flex: 1 1 auto; min-width: 0; }

.rail__actions { flex: 0 0 auto; display: flex; gap: 2px; padding-right: 6px; opacity: 0; transition: opacity 120ms ease; }
.rail__item:hover .rail__actions,
.rail__item:focus-within .rail__actions,
.rail__item--current .rail__actions { opacity: 1; }

/* A pointer-less device has no hover to reveal with, so nothing is hidden. */
@media (hover: none) { .rail__actions { opacity: 1; } }

.rail__action {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-3);
  cursor: pointer;
}
.rail__action:hover { background: var(--surface-2); color: var(--ink); }
.rail__action--danger:hover { background: var(--crit-soft); color: var(--crit); }
.rail__action:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* --- the dialogs --------------------------------------------------------

   A native `<dialog>`, so the focus trap, the Escape key, the inert background
   and the backdrop are the browser's rather than ours — every one of them is a
   thing an app-authored modal gets wrong. */
.modal {
  width: min(420px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
}
.modal::backdrop { background: rgb(0 0 0 / .5); }

.modal__body { display: flex; flex-direction: column; gap: 10px; padding: 20px; }
.modal__title { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: -.01em; }
.modal__label { color: var(--ink-3); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.modal__hint { margin: 0; color: var(--ink-3); font-size: 12px; line-height: 1.5; }

/* The conversation being deleted, quoted back so the dialog is about one thing
   rather than about conversations in general. */
.modal__name {
  margin: 0;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--sunken);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modal__field {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--sunken);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
}
.modal__field:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.modal__actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.modal__actions .btn { width: auto; padding: 9px 18px; font-size: 13px; }

/* --- the transcript ----------------------------------------------------- */

.thread { overflow-y: auto; padding: 28px 20px; }
.thread__inner { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 24px; }

/* Centred, because an empty conversation is a starting point rather than a
   list with nothing in it. */
.thread__empty {
  height: 100%;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 8px;
  text-align: center;
  color: var(--ink-3);
}

.thread__empty h2 { margin: 0; font-size: 18px; font-weight: 600; color: var(--ink); letter-spacing: -.01em; }

.msg { display: flex; gap: 12px; }
.msg__avatar {
  flex: none;
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border-radius: var(--radius-full);
  background: var(--sunken);
  color: var(--ink-2);
  font-size: 11px; font-weight: 600;
}
.msg--assistant .msg__avatar { background: var(--accent-soft); color: var(--accent-ink); }
.msg__body { min-width: 0; flex: 1; }
.msg__who { font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
.msg__when { font-weight: 400; color: var(--ink-3); margin-left: 8px; }
/* An assistant turn is marked up (AnswerMarkup), so the blocks below own the
   spacing. `pre-wrap` is kept for the user's own turn, which is plain text and
   whose line breaks are the only structure it has — and harmless for the
   marked-up branch, where there is no stray whitespace left between tags. */
.msg__text { white-space: pre-wrap; overflow-wrap: anywhere; }

.msg__text > :first-child { margin-top: 0; }
.msg__text > :last-child { margin-bottom: 0; }
.msg__text p { margin: 0 0 10px; }
.msg__text h2, .msg__text h3, .msg__text h4, .msg__text h5, .msg__text h6 {
  margin: 16px 0 8px;
  font-size: 14px; font-weight: 650;
  color: var(--text);
}

/* `white-space: pre-wrap` on the container would otherwise render the newline
   between `<li>` elements as a blank line inside the list. */
.msg__text ul { margin: 0 0 10px; padding-left: 20px; white-space: normal; }
.msg__text li { margin: 3px 0; }

.msg__text code {
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}

.msg__text strong { font-weight: 650; color: var(--text); }

/* --- what ran ----------------------------------------------------------- */

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 9px;
  border-radius: var(--radius-full);
  font-size: 11px; font-weight: 600;
  background: var(--sunken); color: var(--ink-2);
}
.pill--ok { background: var(--accent-soft); color: var(--accent-ink); }
.pill--warn { background: var(--brass-soft); color: var(--brass); }
.pill--bad { background: var(--crit-soft); color: var(--crit); }

.ran { margin-top: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.ran > summary {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 12px;
  color: var(--ink-2);
  list-style: none;
}
.ran > summary::-webkit-details-marker { display: none; }
.ran > summary::before { content: "▸ "; color: var(--ink-3); }
.ran[open] > summary::before { content: "▾ "; }
.ran > summary:hover { color: var(--ink); }

.ran__steps { margin: 0; padding: 4px 12px 12px; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.ran__step { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 12px; }
.ran__name { font-family: var(--mono, ui-monospace, SFMono-Regular, Menlo, monospace); color: var(--ink-2); }
.ran__ms { color: var(--ink-3); font-variant-numeric: tabular-nums; }

.gate {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--brass-soft);
  color: var(--brass);
  border: 1px solid color-mix(in srgb, var(--brass) 25%, transparent);
  font-size: 13px;
}

/* A question, not a warning: the same shape as the gate so it reads as the
   platform speaking, in the accent rather than the brass that means "decide
   something". */
.asked {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  font-size: 13px;
}

.asked__label { color: var(--ink-2); margin-bottom: 6px; }

.asked__list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.asked__list li {
  padding: 2px 10px;
  border-radius: var(--radius-full);
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  color: var(--ink-1);
}

.gate__expiry { margin-top: 4px; color: color-mix(in srgb, var(--brass) 80%, transparent); }

/* `button_to` wraps each button in its own form, and a form is a block: left
   alone the two stack and stretch, because `.btn` is full-width for the
   composer's send. `display: contents` lets the buttons themselves be the flex
   items, so the wrapper markup stops affecting the layout. */
.gate__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 12px;
}

.gate__actions form { display: contents; }

.gate__actions .btn,
.gate__actions .btn-text { width: auto; }

/* Declining is the quieter of the two and should not compete with approving,
   but it still has to read as a control on a brass panel rather than as text. */
.gate__actions .btn-text {
  color: var(--brass);
  border: 1px solid color-mix(in srgb, var(--brass) 35%, transparent);
  border-radius: var(--radius-full);
  padding: 12px 20px;
  font-weight: 600;
}

/* What a turn spent at the models (VAI-031). Sits between the timeline and
   the sources: it is a property of the answer above it, not a footnote about
   where the answer came from.

   The bar is proportional to the turn's own totals rather than to any fixed
   ceiling — there is no budget line to draw it against, and inventing one
   would put a scale on the page that means nothing. */
.spend { margin-top: 10px; font-size: 12px; }

.spend > summary {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  color: var(--ink-3);
  list-style: none;
  padding: 2px 0;
}

.spend > summary::-webkit-details-marker { display: none; }
.spend > summary:hover { color: var(--ink-2); }
.spend > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: var(--radius-sm); }

.spend__total { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.spend__calls { color: var(--ink-3); }

/* Takes the leftover width so the bar ends where the message does, which is
   what makes two turns comparable at a glance. */
.spend__bar {
  flex: 1;
  min-width: 60px;
  display: flex;
  height: 4px;
  border-radius: var(--radius-full);
  overflow: hidden;
  background: var(--sunken);
}

.spend__seg { display: block; min-width: 1px; }

/* Sent is the quiet half — it is mostly the same catalog on every turn. What
   the model actually generated is the part that varies, so it carries the
   accent. */
.spend__seg--sent { background: var(--line-2); position: relative; }
.spend__seg--made { background: var(--accent); }

/* Inside the sent segment, because cached input was sent: it is a share of
   that bar, never a fourth thing beside it. */
.spend__cached {
  position: absolute;
  inset: 0 auto 0 0;
  display: block;
  background: color-mix(in srgb, var(--accent) 22%, var(--line-2));
}

.spend__detail {
  margin: 8px 0 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px 16px;
}

.spend__detail > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.spend__detail dt { color: var(--ink-3); font-size: 11px; letter-spacing: .02em; }
.spend__detail dd { margin: 0; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.spend__share { color: var(--ink-3); }

/* The model list is the one field that can be long, so it is allowed to run
   the width rather than squeezing into a column with a number in it. */
.spend__models { grid-column: 1 / -1; }
.spend__models dd { font-family: var(--mono, ui-monospace, SFMono-Regular, Menlo, monospace); font-size: 11px; overflow-wrap: anywhere; }

.sources { margin-top: 12px; font-size: 12px; color: var(--ink-3); }
.sources ul { margin: 4px 0 0; padding-left: 18px; }

/* A pending turn: the answer is on its way and the transcript should look
   like it is waiting, not like it is finished. */
.msg--pending .msg__avatar { opacity: .6; }

.msg__pending { color: var(--ink-3); }
.msg__pending::after {
  content: "";
  display: inline-block;
  width: 1ch;
  animation: dots 1.2s steps(4, end) infinite;
}

@keyframes dots {
  0%   { content: ""; }
  25%  { content: "."; }
  50%  { content: ".."; }
  75%  { content: "..."; }
}

/* --- the composer ------------------------------------------------------- */

.composer { border-top: 1px solid var(--line); background: var(--surface); padding: 16px 20px 20px; }
.composer__inner { max-width: 760px; margin: 0 auto; }

.composer__box {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 8px 8px 14px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius-lg);
  background: var(--surface-2);
}
.composer__box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.composer__input {
  flex: 1;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: var(--ink);
  font: inherit;
  max-height: 200px;
  padding: 6px 0;
}
.composer__input::placeholder { color: var(--ink-3); }

.composer__send { width: auto; padding: 10px 18px; }
.composer__send[disabled] { opacity: .5; cursor: default; }
.composer__hint { margin: 8px 2px 0; font-size: 11px; color: var(--ink-3); }

/* Visible to a screen reader, not to the eye — the composer's label is the
   placeholder visually, which is not a label. */
.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;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* --- live progress ------------------------------------------------------- */

/* Steps stream in here while a request runs (VAI-008 §Streaming Coordinator).
   The block lives inside the pending marker, so it disappears with it when the
   answer arrives and the settled timeline takes over. */
.ran--live { margin-top: 10px; }
.ran__row--live { animation: fade-in 160ms ease-out; }

@keyframes fade-in {
  from { opacity: 0; transform: translateY(2px); }
  to   { opacity: 1; transform: none; }
}

/* --- pages that are not the conversation -------------------------------- */

/* The chat surface fills the viewport and scrolls inside itself. A settings
   page is a document: it wants a column, a maximum measure, and the page to
   be the thing that scrolls. */

.app__main--page {
  overflow-y: auto;
  padding: 32px 24px 64px;
}

/* The usage view (VAI-031 §The usage view). Reporting only — nothing here is
   a control, so nothing here looks like one. */
.windows { display: flex; gap: 6px; flex-wrap: wrap; }

.windows__pick {
  padding: 5px 11px;
  border-radius: var(--radius-full);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 13px;
  text-decoration: none;
}

.windows__pick:hover { border-color: var(--line-2); color: var(--ink); }
.windows__pick--on { background: var(--accent-soft); border-color: transparent; color: var(--accent-ink); }

/* The four headline figures. `auto-fit` rather than a fixed four, so a narrow
   window wraps them instead of shrinking the digits. */
.figures {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}

.figures__one {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.figures__one dt { color: var(--ink-3); font-size: 12px; }
.figures__one dd { margin: 0; color: var(--ink); font-size: 1.35rem; font-weight: 600; font-variant-numeric: tabular-nums; }

/* "Not reported" is not a number and must not be set like one — a cache figure
   nobody supplied is a silence, not a zero. */
.figures__none { color: var(--ink-3); font-size: .85rem; font-weight: 400; }

.panel {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel__head { margin: 0; font-size: 13px; font-weight: 600; color: var(--ink-2); letter-spacing: .02em; }

/* Bars grow from the baseline, scaled to the window's own busiest bucket.
   There is no budget line in the platform to scale against, so an absolute
   ceiling would be invented. */
.series {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 132px;
  overflow-x: auto;
}

.series__bar { flex: 1 1 8px; min-width: 6px; height: 100%; display: flex; align-items: flex-end; }

.series__fill {
  width: 100%;
  min-height: 2px;
  border-radius: 3px 3px 0 0;
  background: var(--accent);
  display: block;
}

.series__span { margin: 0; color: var(--ink-3); font-size: 12px; font-variant-numeric: tabular-nums; }

/* A table that reads as a chart without becoming one: the share bar sits under
   the row's own name, so the eye gets the proportion and the columns keep the
   exact figures. */
.split { width: 100%; border-collapse: collapse; font-size: 13px; }
.split thead th { text-align: left; color: var(--ink-3); font-weight: 500; font-size: 11px; padding: 0 8px 6px 0; }
.split tbody th { text-align: left; font-weight: 500; padding: 8px 8px 8px 0; min-width: 140px; }
.split tbody tr + tr th, .split tbody tr + tr td { border-top: 1px solid var(--line); }
.split td { padding: 8px 0 8px 8px; color: var(--ink-2); }
.split__n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.split__name { display: block; color: var(--ink); font-family: var(--mono, ui-monospace, SFMono-Regular, Menlo, monospace); font-size: 12px; overflow-wrap: anywhere; }

.split__bar { display: block; margin-top: 5px; height: 3px; border-radius: var(--radius-full); background: var(--sunken); }
.split__fill { display: block; height: 100%; border-radius: var(--radius-full); background: var(--accent); min-width: 2px; }

/* The settings overlay (VAI-031 §Visual Design — product-owner mock).

   A sheet over the app rather than a page beside it: everything in it is about
   the person rather than about the conversation, and sending them away from
   their work to read a token count was the wrong trade. */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 24px;
}

/* A link, not a div, so dismissing works before any script runs and means the
   same thing as Escape. Covers the viewport beneath the panel. */
.sheet__scrim {
  position: absolute;
  inset: 0;
  display: block;
  background: rgba(9, 12, 18, .55);
  cursor: default;
}

.sheet__panel {
  position: relative;
  display: grid;
  grid-template-columns: 232px 1fr;
  width: min(1040px, 100%);
  height: min(720px, 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.sheet__menu {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 16px 12px;
  border-right: 1px solid var(--line);
  background: var(--surface-2);
  overflow-y: auto;
}

.sheet__title {
  margin: 0 0 10px;
  padding: 0 10px;
  color: var(--ink-3);
  font-size: 12px;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.sheet__item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--ink-2);
  font-size: 14px;
  text-decoration: none;
}

.sheet__item:hover { background: var(--sunken); color: var(--ink); }

/* The open section, which is also what the address bar says. */
.sheet__item--on { background: var(--accent-soft); color: var(--accent-ink); font-weight: 500; }

.sheet__body { position: relative; overflow-y: auto; }

.sheet__close {
  position: absolute;
  top: 14px;
  right: 16px;
  z-index: 1;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  color: var(--ink-3);
  font-size: 22px;
  line-height: 1;
  text-decoration: none;
}

.sheet__close::before { content: "\00d7"; }
.sheet__close:hover { background: var(--sunken); color: var(--ink); }

.sheet__content {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 28px 32px 36px;
  max-width: 680px;
}

.panel__intro { display: flex; flex-direction: column; gap: 6px; }
.panel__title { margin: 0; font-size: 1.35rem; font-weight: 620; letter-spacing: -.01em; }
.panel__blurb { margin: 0; color: var(--ink-2); max-width: 60ch; font-size: 14px; }
.panel__head { margin: 4px 0 0; font-size: 13px; font-weight: 600; color: var(--ink-2); letter-spacing: .02em; }
.panel__note { margin: 0; color: var(--ink-3); font-size: 12px; max-width: 60ch; }

/* Label-and-value rows, the shape the mock uses for a profile. Ruled rather
   than boxed: these are facts about one thing, not four separate cards. */
.facts { margin: 0; display: flex; flex-direction: column; }

.facts__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 24px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.facts__row:first-child { border-top: 1px solid var(--line); }
.facts dt { color: var(--ink-2); font-size: 14px; }
.facts dd { margin: 0; color: var(--ink); font-size: 14px; text-align: right; overflow-wrap: anywhere; }

/* Identifiers are read character by character when someone is comparing one
   against a directory, so they get the monospaced face. */
.facts__id { font-family: var(--mono, ui-monospace, SFMono-Regular, Menlo, monospace); font-size: 13px; }

/* Narrow: the menu becomes a strip above the panel rather than a column
   beside it, so the content keeps the width it needs. */
@media (max-width: 720px) {
  .sheet { padding: 0; }

  .sheet__panel {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    width: 100%;
    height: 100%;
    border: 0;
    border-radius: 0;
  }

  .sheet__menu {
    flex-direction: row;
    gap: 4px;
    padding: 10px 12px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    overflow-x: auto;
  }

  .sheet__title { display: none; }
  .sheet__item { white-space: nowrap; }
  .sheet__content { padding: 20px 18px 32px; }
}

.page {
  max-width: 780px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.page__head { display: flex; flex-direction: column; gap: 8px; }
.page__title { margin: 0; font-size: 1.5rem; font-weight: 650; letter-spacing: -.01em; }
.page__blurb { margin: 0; color: var(--ink-2); max-width: 60ch; }
.page__empty { margin: 0; color: var(--ink-3); }

.page__error {
  margin: 0;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--crit-soft);
  color: var(--crit);
}

/* --- the key, the one time it is shown ---------------------------------- */

/* Deliberately the loudest thing on the page. It is the only element here
   whose information is gone the moment the page is left. */

.keycard {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px;
  border: 1px solid var(--accent);
  border-radius: var(--radius-lg);
  background: var(--accent-soft);
}

.keycard__title { margin: 0; font-size: 1rem; font-weight: 650; }
.keycard__warning { margin: 0; color: var(--accent-ink); max-width: 60ch; }

.keycard__row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* Breaks anywhere, because a secret has no word boundaries and an overflowing
   one is a secret that gets copied short. */
.keycard__secret {
  flex: 1 1 320px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .85rem;
  overflow-wrap: anywhere;
}

/* --- issuing and listing ------------------------------------------------ */

.keyform {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: end;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.keyform__label { grid-column: 1 / -1; font-weight: 500; color: var(--ink-2); }

.keyform__input {
  padding: 12px 14px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--ink);
  font: inherit;
}

.keyform__input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* `.btn` is full-width by default, which is right in the composer and wrong
   in a row beside a field. */
.btn-inline { width: auto; }
.keyform form, .keys__actions form { display: contents; }

.keys { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }

.keys__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  flex-wrap: wrap;
}

.keys__detail { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.keys__name { font-weight: 600; }

.keys__id {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .8rem;
  color: var(--ink-3);
  overflow-wrap: anywhere;
}

.keys__used, .keys__rotated { font-size: .85rem; color: var(--ink-3); }

.keys__status {
  align-self: flex-start;
  padding: 2px 10px;
  border-radius: var(--radius-full);
  font-size: .78rem;
  font-weight: 600;
}

.keys__status--active  { background: var(--accent-soft); color: var(--accent-ink); }
.keys__status--grace   { background: var(--brass-soft);  color: var(--brass); }
.keys__status--expired { background: var(--sunken);      color: var(--ink-3); }
.keys__status--revoked { background: var(--crit-soft);   color: var(--crit); }

.keys__actions { display: flex; gap: 4px; }
.btn-danger { color: var(--crit); }

/* --- provider connections ----------------------------------------------- */

.conns { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }

.conns__item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px 16px;
  padding: 16px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.conns__detail { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.conns__name { font-weight: 600; }
.conns__meta { font-size: .85rem; color: var(--ink-3); }
.conns__actions { display: flex; gap: 4px; align-items: start; }

.conns__status {
  align-self: flex-start;
  padding: 2px 10px;
  border-radius: var(--radius-full);
  font-size: .78rem;
  font-weight: 600;
}

.conns__status--active         { background: var(--accent-soft); color: var(--accent-ink); }
.conns__status--disconnected   { background: var(--sunken);      color: var(--ink-3); }
.conns__status--expired,
.conns__status--refresh_failed { background: var(--brass-soft);  color: var(--brass); }
.conns__status--revoked        { background: var(--crit-soft);   color: var(--crit); }

/* The token field spans the row: it is the whole reason the row is taller
   than the others, and squeezing it beside the status reads as an afterthought
   rather than as the thing being asked for. */
.conns__form {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  align-items: end;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.conns__hint { grid-column: 1 / -1; margin: 0; font-size: .85rem; color: var(--ink-3); max-width: 62ch; }

/* Why a request did not work, when the platform can say so plainly. Beside the
   answer rather than inside it: the sentence above is the platform's, and this
   is the provider's account of what was wrong with the request. */
.msg__reason {
  margin: 8px 0 0;
  padding: 10px 14px;
  border-left: 3px solid var(--brass);
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--brass-soft);
  color: var(--ink-2);
  font-size: .92rem;
}

/* --- The embedded panel (VAI-058) -------------------------------------- */

/* A frame is not a viewport. A panel is sized by its content: the layout is
   intrinsic (the body's `height` is not forced), the host learns the height
   over `postMessage`, and the *thread* is the one capped, scrolling part. A
   panel with nothing to show is then short, and one with a thread grows to the
   cap instead of always reserving the host's full frame. */
.embed {
  height: auto;
  margin: 0;
  background: var(--ground);
}

.embed__app {
  height: auto;
  display: grid;
  grid-template-rows: auto;
  min-height: 0;
}

/* The same two-row shape `.app__main` has — thread above, composer below —
   without the grid area that only exists inside the full client's shell. */
.embed__main {
  display: grid;
  grid-template-rows: auto auto;
  min-height: 0;
  background: var(--ground);
}

/* Narrower than the full client's, because a panel is usually a third of a
   page rather than a whole one, and the composer's hint wraps badly below
   this. The cap is what keeps a long thread from pushing the frame past the
   host's limit; within it the thread scrolls as it always did. */
.embed .thread { padding: 16px 14px; max-height: 360px; }
.embed .thread__empty { padding: 24px 14px; }

/* The panel's sign-in prompt: centred in whatever height the host gave us. */
.embed__gate {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px 18px;
  text-align: center;
}

.embed__gate-lead { margin: 0; color: var(--ink); }
.embed__gate-hint { margin: 0; font-size: 12px; color: var(--ink-muted); }

/* The record's history, set apart above the thread: a title row and a rule, so
   the messages below read as this record's, not a general chat. The row is the
   grid's third track only when it is present. */
.embed__main--head { grid-template-rows: auto auto auto; }

.embed__history {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--ground);
}

.embed__history-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.embed__history-about { font-size: 12px; color: var(--ink-3); }
