/* The shared components for every AIGate browser surface.
 *
 * tokens.css (beside this file) names the values; this file builds the
 * components all three surfaces have each been writing for themselves:
 * the body font, buttons and form controls, a focus ring, card, pill,
 * banner, table, the app header with its Portal | Chat | Admin switcher, and
 * the sign-in card. portal/index.html, admin-ui/index.html and
 * chat-ui/index.html link it straight after tokens.css, and
 * ci/test_checks.py::TestSharedShell holds them to that.
 *
 * LOAD ORDER IS THE CONTRACT. This sheet is linked BEFORE each surface's own
 * CSS (the portal's inline <style>, the apps' bundled ui.css), so anything a
 * surface still says for itself wins over what is said here. The three
 * near-copies this replaced were deleted from the surfaces on 2026-10-14;
 * what each surface's own CSS still says about these components is a
 * deliberate addition or override, not a copy. When a surface needs to
 * differ, it overrides; it never edits this file for one surface's sake.
 *
 * Colours come from tokens.css only: ci/test_checks.py::TestNoHardcodedColours
 * scans this file like the other three.
 */

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font: var(--fs-md)/var(--lh) var(--font);
  background: var(--bg);
  color: var(--ink);
}

/* ---- Controls --------------------------------------------------------- */

/* --control-line, never --line: a white button on a white card has no edge
   but its border, and --line is 1.24:1 there (WCAG 1.4.11 wants 3:1). */
button {
  font: inherit;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--control-line);
  border-radius: var(--radius-md);
  padding: 7px 14px;
  cursor: pointer;
}
button.primary { background: var(--acc); border-color: var(--acc); color: var(--acc-ink); }
button.danger { color: var(--bad); }
button.small { padding: 3px 10px; font-size: var(--fs-sm); }
button:disabled { opacity: .5; cursor: default; }

input, select, textarea {
  font: inherit;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--control-line);
  border-radius: var(--radius-md);
  padding: 7px 10px;
}
/* A field the server refused (the admin UI's ErrorBanner sets this from a
   422). The banner beside it says why; the border says which. */
[aria-invalid="true"] { border-color: var(--bad); }

/* :focus-visible, not :focus -- a mouse click on a button does not draw the
   ring, a Tab onto it always does. Neither the portal nor the admin UI had
   any designed ring before this; they showed whatever the browser drew. */
:focus-visible { outline: var(--focus-ring); outline-offset: var(--focus-offset); }

/* ---- Text utilities --------------------------------------------------- */

.mut { color: var(--mut); font-size: var(--fs-sm); }
.mono { font-family: var(--font-mono); }
/* Read by a screen reader, not drawn. */
.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;
}

/* ---- Card ------------------------------------------------------------- */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
  margin-bottom: var(--sp-4);
}
.card h2 { font-size: var(--fs-md); margin: 0 0 var(--sp-3); font-weight: 600; }
/* Phone width: 24px a side is too much of 343px. The portal and admin UI
   each said this for themselves, at 16px and 14px. */
@media (max-width: 600px) { .card { padding: var(--sp-4); } }

/* ---- Pill ------------------------------------------------------------- *
 * One meaning per variant, and only these four. A pill that is coloured
 * for decoration teaches people to ignore the colour when it matters.
 *
 *   .pill (or .pill.neutral)  A label: a team, a model, a role. Says what
 *                             something IS, nothing about whether it works.
 *   .pill.ok                  Working now: an active key, a healthy check.
 *   .pill.warn                Still works, needs attention soon: expiring,
 *                             near a budget or quota.
 *   .pill.bad                 Not working now: revoked, blocked, exhausted,
 *                             suspended.
 *
 * Colour is never the only signal -- the pill's text says the state too. */
.pill {
  display: inline-block;
  padding: 1px 10px;
  border-radius: 999px;
  font-size: var(--fs-sm);
  line-height: 1.5;
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--line);
  margin: 0 var(--sp-1) var(--sp-1) 0;
}
.pill.ok { background: var(--ok-bg); color: var(--ok); border-color: var(--ok-line); }
.pill.warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-line); }
.pill.bad { background: var(--bad-bg); color: var(--bad); border-color: var(--bad-line); }

/* ---- Banner ----------------------------------------------------------- *
 * A message about the whole card or page, that stays until it is resolved
 * (a toast is for things that do not need to be read twice). Same three
 * states as the pill; the plain .banner is information. */
.banner {
  display: flex; gap: var(--sp-3); align-items: flex-start;
  padding: 10px var(--sp-3);
  margin: 0 0 var(--sp-3);
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--card);
}
.banner.ok { background: var(--ok-bg); border-color: var(--ok-line); color: var(--ok); }
.banner.warn { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn); }
.banner.bad { background: var(--bad-bg); border-color: var(--bad-line); color: var(--bad); }

/* ---- One-time secret ------------------------------------------------ *
 * A key shown once, in the portal (personal keys) and the admin UI (team
 * keys) alike, warn-tinted because losing it means making another one:
 *
 *   <div class="reveal" role="status" tabindex="-1">
 *     <h3>Copy your key now — it won't be shown again</h3>
 *     <code class="secret">…</code>
 *     <div class="note">…</div>
 *     <div class="reveal-actions">
 *       <button class="primary">Copy key</button> <button>I've stored it</button>
 *       <span class="copy-status" aria-live="polite"></span>
 *     </div>
 *   </div>
 *
 * The admin UI's team keys used to show theirs in a green success banner
 * with no Copy and no warning (2026-10-14 UX review). */
.reveal {
  background: var(--warn-bg); border: 1px solid var(--warn-line);
  border-radius: var(--radius-md); padding: 14px; margin: var(--sp-3) 0;
}
/* :focus, not just :focus-visible: the page moves focus here after a mouse
   click on Create or Rotate, and the ring is what draws the eye. */
.reveal:focus { outline: var(--focus-ring); outline-offset: var(--focus-offset); }
.reveal h3 { font-size: var(--fs-md); margin: 0 0 var(--sp-2); font-weight: 600; color: var(--ink); }
.reveal .secret {
  display: block; background: var(--card); border: 1px solid var(--warn-line);
  border-radius: var(--radius-sm); padding: var(--sp-2) 10px;
  font-family: var(--font-mono); font-size: var(--fs-sm); word-break: break-all; user-select: all;
}
.reveal .note { margin: var(--sp-2) 0 10px; font-size: var(--fs-sm); }
.reveal-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.reveal .copy-status { font-size: var(--fs-sm); }
.reveal .copy-status.bad { color: var(--bad); }

/* ---- Dialog ----------------------------------------------------------- *
 * A modal <dialog> (showModal), for a decision the page cannot go on
 * without: the admin UI's forms and confirmations, the portal's "Revoke
 * this key?". Never the browser's confirm()/prompt(), which cannot be
 * styled, cannot explain much and read as a different application. */
dialog {
  border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 20px;
  max-width: 560px; width: 92%; background: var(--card); color: var(--ink);
}
/* A scrim, not a palette colour: translucent black reads in both modes
   (ci/test_checks.py::TestNoHardcodedColours allows exactly this line). */
dialog::backdrop { background: rgba(15, 18, 22, .45); }
dialog h2, dialog h3 { font-size: var(--fs-md); font-weight: 600; margin: 0 0 var(--sp-3); }

/* ---- Table ------------------------------------------------------------ */

table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
th {
  text-align: left; color: var(--mut); font-weight: 500;
  padding: 6px var(--sp-2); border-bottom: 1px solid var(--line); white-space: nowrap;
}
td { padding: var(--sp-2); border-bottom: 1px solid var(--line); vertical-align: top; }
/* Wrap a wide table in this rather than letting it widen the page.
   Positioned so it is the containing block for the .sr-only spans inside
   (a header's hidden "Actions" label): they are absolute, and with no
   positioned ancestor they escaped the scroll box and made the admin's
   Dedicated keys page 655px wide at 375px (staging, 2026-10-14). */
.scroll-x { position: relative; overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---- App header ------------------------------------------------------- *
 * The same bar in all three apps:
 *
 *   <header class="app-header">
 *     [<button class="app-lead">…</button>]   optional, one app control
 *     <h1 class="app-brand">AIGate<span class="sr-only"> · Chat</span></h1>
 *     <nav class="app-switch" aria-label="AIGate apps">
 *       <a href="/portal/">Portal</a>
 *       <a href="/chat/" aria-current="page">Chat</a>
 *     </nav>
 *     <div class="app-who"><span class="app-id">…</span><button>Sign out</button></div>
 *   </header>
 *
 * Which links appear is decided once, in web-shared/shell.ts (and mirrored
 * by the portal's plain JS). The current app is marked by aria-current, and
 * shown by shape and weight as well as colour. */
.app-header {
  display: flex; align-items: center; flex-wrap: wrap;
  gap: var(--sp-2) var(--sp-4);
  padding: var(--sp-3) var(--sp-5);
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.app-brand { font-size: var(--fs-lg); line-height: 1.3; font-weight: 600; margin: 0; white-space: nowrap; }
.app-switch {
  display: flex; gap: 2px; padding: 2px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}
.app-switch a {
  padding: 3px var(--sp-3);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--mut);
  font-size: var(--fs-sm);
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
}
.app-switch a:hover { color: var(--ink); text-decoration: underline; }
.app-switch a[aria-current="page"] {
  background: var(--card);
  border-color: var(--control-line);
  color: var(--ink);
  font-weight: 600;
}
.app-switch a[aria-current="page"]:hover { text-decoration: none; }
/* The identity gives way first: a long address ellipsizes rather than
   pushing Sign out off the screen. */
.app-who { display: flex; align-items: center; gap: var(--sp-3); min-width: 0; margin-left: auto; }
.app-id { color: var(--mut); font-size: var(--fs-sm); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-who button, .app-lead { flex: none; white-space: nowrap; }
/* `display: flex` above outranks the UA's [hidden] rule; the portal hides
   these two with the attribute while signed out. */
.app-switch[hidden], .app-who[hidden] { display: none; }

/* Phone width: two rows. Brand and switcher on the first; the app's own
   control (chat's Conversations toggle) with the identity and Sign out on
   the second. Measured at 375px, the first row needs about 265 of 343px. */
@media (max-width: 600px) {
  .app-header {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: var(--sp-2) var(--sp-3);
    padding: var(--sp-2) var(--sp-4);
  }
  .app-brand { grid-row: 1; grid-column: 1; }
  .app-switch { grid-row: 1; grid-column: 2; justify-self: end; }
  .app-lead { grid-row: 2; grid-column: 1; }
  .app-who { grid-row: 2; grid-column: 1 / -1; margin-left: 0; justify-content: space-between; }
  .app-lead ~ .app-who { grid-column: 2; }
}

/* ---- Sign-in card ----------------------------------------------------- *
 * The one signed-out screen. The explanatory sentence is SIGN_IN_SENTENCE in
 * web-shared/shell.ts, verbatim in all three apps. */
.signin { display: flex; justify-content: center; padding: var(--sp-6) var(--sp-4); }
.signin-card { width: 100%; max-width: 440px; margin: 0; }
.signin-card h2 { font-size: var(--fs-lg); margin: 0 0 var(--sp-2); }
.signin-card p { margin: 0 0 var(--sp-4); }
.signin-card button { width: 100%; }
