/* ==========================================================================
   Testbed: the shared stylesheet of the sign-in page, the viewer portal, the admin dashboard
   and the server-rendered pages (lib/pages.js inlines this file, comments stripped, into every
   page it renders, including those on project subdomains). Tokens, primitives and shared
   pieces only: the dashboard's own styles are in dashboard.css, which the server pages don't
   need.

   Design system: proposal A, approved 2026-09-28 (design-planning/design-system/).
   Near-monochrome; colour only carries meaning. Blue: focus, selection, drop targets,
   progress, links. Green: live. Amber: in progress. Red: destructive or failed. The owner's
   logo keeps its own reds. Dark mode follows prefers-color-scheme, unless the theme button
   chose one (data-theme on <html>, public/theme.js).

   CSP: the dashboard allows no inline style attributes, so every state is a class and
   dynamic values (progress widths) go through the CSSOM.

    1 Tokens (light, dark)          9 Tooltip                 17 Top bar and account menu
    2 Base                         10 Dialog                  18 Centred pages
    3 Type                         11 Toast                   19 Google sign-in button
    4 Icons and the logo           12 Status, badge, progress 20 Reading pages
    5 Buttons                      13 Banner, empty, skeleton 21 Viewer portal
    6 Fields and the switch        14 Lists and tables        22 Touch, no hover, motion
    7 Drop zone                    15 Panels
    8 Menus                        16 Layout primitives
   ========================================================================== */


/* ==========================================================================
   1 Tokens
   ========================================================================== */

:root {
  /* neutral surfaces */
  --bg: #F6F6F6;              /* canvas behind centred pages and the portal */
  --surface-1: #FFFFFF;       /* main panes, top bar, dialogs, menus */
  --surface-2: #FAFAFA;       /* secondary pane (inspector), table header */
  --surface-3: #F0F0F0;       /* tracks, chips, pressed neutral, kbd */
  --overlay: #FFFFFF;         /* menus, popovers */
  --overlay-raised: #FFFFFF;  /* dialogs (one step above menus in dark) */
  --overlay-top: #FFFFFF;     /* a menu inside a dialog (one step above the dialog in dark) */

  --border-subtle: #EBEBEB;   /* dividers, pane edges, row lines */
  --border-strong: #CACACA;   /* inputs, secondary buttons, drop zone */
  --border-hover: #ADADAD;    /* input and secondary button hover */
  --field-bg: #FFFFFF;
  --switch-knob: #FFFFFF;     /* a switch's knob while it is off */
  --segment-on: #FFFFFF;      /* the pressed segment of a segmented control */

  --text-primary: #171717;
  --text-secondary: #525252;
  --text-muted: #696969;
  --text-disabled: #A3A3A3;

  /* interaction overlays: translucent, so they work on any surface */
  --hover: rgba(23, 23, 23, 0.045);
  --pressed: rgba(23, 23, 23, 0.08);
  --selected: rgba(37, 99, 235, 0.08);
  --media-edge: rgba(23, 23, 23, 0.12); /* the line drawn over a picture's edge (avatar, thumbnail) */

  /* accent: focus, selection, drop target, progress, links. Nothing else. */
  --accent: #2563EB;
  --accent-hover: #1D4ED8;
  --accent-text: #1D4ED8;
  --accent-subtle: rgba(37, 99, 235, 0.07);
  --accent-border: rgba(37, 99, 235, 0.55);
  --on-accent: #FFFFFF;
  --focus: #2563EB;
  --focus-ring: rgba(37, 99, 235, 0.22);

  /* meaning */
  --success: #16A34A;         /* live */
  --success-text: #11783A;
  --success-subtle: rgba(22, 163, 74, 0.10);
  --warning: #D97706;         /* in progress: setting up HTTPS */
  --warning-text: #A04B06;
  --warning-subtle: rgba(217, 119, 6, 0.12);
  --danger: #DC2626;          /* destructive, errors */
  --danger-hover: #B91C1C;
  --danger-text: #C11F1F;
  --danger-subtle: rgba(220, 38, 38, 0.07);

  /* solid actions: primary buttons are text-coloured */
  --primary: #171717;
  --primary-hover: #2E2E2E;
  --primary-pressed: #404040;
  --on-primary: #FFFFFF;
  --on-danger: #FFFFFF;
  --inverse: #171717;         /* toasts, tooltips */
  --on-inverse: #F5F5F5;
  --inverse-border: transparent;
  --on-inverse-ok: #4ADE80;
  --on-inverse-error: #F87171;

  /* the owner's logo: its charcoal (the wordmark's #1B2228 is a step off), where the server
     pages inline it */
  --logo-ink: #1C2228;

  /* elevation: flat panes; shadows only on things that float */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 1px 3px rgba(0, 0, 0, 0.06), 0 6px 18px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 2px 6px rgba(0, 0, 0, 0.06), 0 24px 64px rgba(0, 0, 0, 0.16);
  --backdrop: rgba(10, 10, 10, 0.32);

  /* type: system fonts only (project rule) */
  --font-ui: "Segoe UI Variable Text", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: "Segoe UI Variable Display", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  --text-2xs: 11px;  --lh-2xs: 14px;   /* tiny structural label */
  --text-xs: 12px;   --lh-xs: 16px;    /* secondary, meta, mono data */
  --text-sm: 13px;   --lh-sm: 18px;    /* standard UI text, controls */
  --text-md: 14px;   --lh-md: 20px;    /* lead text on centred pages */
  --text-lg: 15px;   --lh-lg: 20px;    /* section and pane titles */
  --text-xl: 20px;   --lh-xl: 26px;    /* page title (centred pages, portal) */
  --text-read: 15px; --lh-read: 24px;  /* long-form (privacy, terms) */

  --weight-regular: 400;
  --weight-medium: 500;
  --weight-semibold: 600;

  /* space: 4 px grid */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  /* geometry. Nested items are concentric: inner radius = outer radius - inset
     (menu 8 - 4 = item 4; chip 4 - 2 = remove button 2). */
  --radius-sm: 4px;   /* badges, chips, kbd, tooltips, xs buttons */
  --radius-md: 6px;   /* buttons, inputs, menu items */
  --radius-lg: 8px;   /* menus, drop zones, panels, toasts */
  --radius-xl: 10px;  /* dialogs */
  --control-xs: 24px;
  --control-sm: 28px;
  --control-md: 32px;
  --control-lg: 40px;
  --icon-xs: 12px;    /* inside chips and badges */
  --icon-sm: 14px;    /* dense rows */
  --icon-md: 16px;    /* controls */
  --icon-lg: 20px;    /* empty states */
  --topbar-h: 48px;
  --inspector-w: 392px;

  /* motion: short, only in response to the user */
  --dur-fast: 100ms;
  --dur: 150ms;
  --ease: cubic-bezier(0.2, 0, 0, 1);

  color-scheme: light;
}

/* Designed, not inverted: panes get lighter as they rise; blue splits into a deeper fill
   (white on it passes 4.5:1) and a lighter ring and link colour. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0A0A0A;
    --surface-1: #111111;
    --surface-2: #161616;
    --surface-3: #1E1E1E;
    --overlay: #1A1A1A;
    --overlay-raised: #222222;
    --overlay-top: #2A2A2A;

    --border-subtle: #232323;
    --border-strong: #3F3F3F;
    --border-hover: #525252;
    --field-bg: #151515;
    --switch-knob: #8A8A8A;
    --segment-on: #333333;

    --text-primary: #EDEDED;
    --text-secondary: #A3A3A3;
    --text-muted: #8A8A8A;
    --text-disabled: #5C5C5C;

    --hover: rgba(255, 255, 255, 0.05);
    --pressed: rgba(255, 255, 255, 0.085);
    --selected: rgba(91, 147, 255, 0.13);
    --media-edge: rgba(255, 255, 255, 0.16);

    --accent: #2F6FED;
    --accent-hover: #3F7CF0;
    --accent-text: #7EA8FF;
    --accent-subtle: rgba(91, 147, 255, 0.09);
    --accent-border: rgba(91, 147, 255, 0.6);
    --focus: #5B93FF;
    --focus-ring: rgba(91, 147, 255, 0.32);

    --success: #22C55E;
    --success-text: #4ADE80;
    --success-subtle: rgba(34, 197, 94, 0.12);
    --warning: #F59E0B;
    --warning-text: #FBBF24;
    --warning-subtle: rgba(245, 158, 11, 0.13);
    --danger: #DC2626;
    --danger-hover: #B91C1C;    /* darker, not lighter: white on it stays above 4.5:1 */
    --danger-text: #F87171;
    --danger-subtle: rgba(248, 113, 113, 0.10);

    --primary: #EDEDED;
    --primary-hover: #FFFFFF;
    --primary-pressed: #D4D4D4;
    --on-primary: #111111;
    --on-danger: #FFFFFF;
    --inverse: #383838;
    --on-inverse: #EDEDED;
    --inverse-border: transparent;

    --logo-ink: #EDEDED;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 0 0 1px rgba(255, 255, 255, 0.03), 0 8px 24px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 0 0 1px rgba(255, 255, 255, 0.04), 0 24px 64px rgba(0, 0, 0, 0.65);
    --backdrop: rgba(0, 0, 0, 0.6);

    color-scheme: dark;
  }
}

/* The same dark theme chosen by hand with the theme button (data-theme on <html>, set by
   public/theme.js). Keep this block identical to the one above: test/theme.test.js checks it. */
:root[data-theme="dark"] {
  --bg: #0A0A0A;
  --surface-1: #111111;
  --surface-2: #161616;
  --surface-3: #1E1E1E;
  --overlay: #1A1A1A;
  --overlay-raised: #222222;
  --overlay-top: #2A2A2A;

  --border-subtle: #232323;
  --border-strong: #3F3F3F;
  --border-hover: #525252;
  --field-bg: #151515;
  --switch-knob: #8A8A8A;
  --segment-on: #333333;

  --text-primary: #EDEDED;
  --text-secondary: #A3A3A3;
  --text-muted: #8A8A8A;
  --text-disabled: #5C5C5C;

  --hover: rgba(255, 255, 255, 0.05);
  --pressed: rgba(255, 255, 255, 0.085);
  --selected: rgba(91, 147, 255, 0.13);
  --media-edge: rgba(255, 255, 255, 0.16);

  --accent: #2F6FED;
  --accent-hover: #3F7CF0;
  --accent-text: #7EA8FF;
  --accent-subtle: rgba(91, 147, 255, 0.09);
  --accent-border: rgba(91, 147, 255, 0.6);
  --focus: #5B93FF;
  --focus-ring: rgba(91, 147, 255, 0.32);

  --success: #22C55E;
  --success-text: #4ADE80;
  --success-subtle: rgba(34, 197, 94, 0.12);
  --warning: #F59E0B;
  --warning-text: #FBBF24;
  --warning-subtle: rgba(245, 158, 11, 0.13);
  --danger: #DC2626;
  --danger-hover: #B91C1C;    /* darker, not lighter: white on it stays above 4.5:1 */
  --danger-text: #F87171;
  --danger-subtle: rgba(248, 113, 113, 0.10);

  --primary: #EDEDED;
  --primary-hover: #FFFFFF;
  --primary-pressed: #D4D4D4;
  --on-primary: #111111;
  --on-danger: #FFFFFF;
  --inverse: #383838;
  --on-inverse: #EDEDED;
  --inverse-border: transparent;

  --logo-ink: #EDEDED;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 0 0 1px rgba(255, 255, 255, 0.03), 0 8px 24px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 0 0 1px rgba(255, 255, 255, 0.04), 0 24px 64px rgba(0, 0, 0, 0.65);
  --backdrop: rgba(0, 0, 0, 0.6);

  color-scheme: dark;
}


/* ==========================================================================
   2 Base
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }
/* No flash on taps: rows and buttons show their own pressed state. */
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text-primary);
  font: var(--weight-regular) var(--text-sm)/var(--lh-sm) var(--font-ui);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4, p, ul, ol, dl, dd, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
img { display: block; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
::selection { background: var(--accent-subtle); }

.sr-only, .visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}


/* ==========================================================================
   3 Type
   ========================================================================== */

.t-title   { font: var(--weight-semibold) var(--text-xl)/var(--lh-xl) var(--font-display); letter-spacing: -0.015em; text-wrap: balance; }
.t-section { font-size: var(--text-lg); line-height: var(--lh-lg); font-weight: var(--weight-semibold); letter-spacing: -0.01em; }
.t-panel   { font-size: var(--text-sm); line-height: var(--lh-sm); font-weight: var(--weight-semibold); }
.t-body    { font-size: var(--text-sm); line-height: var(--lh-sm); }
.t-lead    { font-size: var(--text-md); line-height: var(--lh-md); color: var(--text-secondary); }
.t-control { font-size: var(--text-sm); line-height: var(--lh-sm); font-weight: var(--weight-medium); }
.t-meta    { font-size: var(--text-xs); line-height: var(--lh-xs); color: var(--text-muted); }
.t-label   { font-size: var(--text-2xs); line-height: var(--lh-2xs); font-weight: var(--weight-medium); color: var(--text-muted); letter-spacing: 0.04em; text-transform: uppercase; }
.t-mono    { font-family: var(--font-mono); font-size: var(--text-xs); line-height: var(--lh-xs); }
.t-read    { font-size: var(--text-read); line-height: var(--lh-read); }
.t-lead, .banner, .help, .dialog-text, .empty-text { text-wrap: pretty; }
.tnum      { font-variant-numeric: tabular-nums; }
.nowrap    { white-space: nowrap; }
.truncate  { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.c-primary   { color: var(--text-primary); }
.c-secondary { color: var(--text-secondary); }
.c-muted     { color: var(--text-muted); }

/* Links: .link is inline and underlined, .link-quiet underlines on hover. */
.link {
  color: var(--accent-text); text-decoration: underline; text-decoration-thickness: 1px;
  text-underline-offset: 2px; text-decoration-color: color-mix(in srgb, currentColor 40%, transparent);
  border-radius: 2px;
}
.link:hover { text-decoration-color: currentColor; }
/* A button that reads as a link in a sentence (it opens a dialog rather than a page). */
button.link { padding: 0; border: 0; background: none; font: inherit; text-align: inherit; cursor: pointer; }
.link-quiet { color: inherit; text-decoration: none; border-radius: 2px; }
.link-quiet:hover { color: var(--text-primary); text-decoration: underline; text-underline-offset: 2px; }

.kbd {
  display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 4px;
  border: 1px solid var(--border-subtle); border-radius: var(--radius-sm);
  background: var(--surface-2); box-shadow: inset 0 -1px 0 var(--border-subtle);
  font: 500 11px/1 var(--font-ui); color: var(--text-muted);
}
.code {
  padding: 1px 5px; border-radius: var(--radius-sm); background: var(--surface-3);
  font-family: var(--font-mono); font-size: 0.92em;
  line-height: 1; /* the mono face must not make its line taller than the text around it */
}
.mono { font-family: var(--font-mono); }


/* ==========================================================================
   4 Icons and the logo
   ========================================================================== */

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.i { width: var(--icon-md); height: var(--icon-md); flex: none; }
.i-xs { width: var(--icon-xs); height: var(--icon-xs); }
.i-sm { width: var(--icon-sm); height: var(--icon-sm); }
.i-lg { width: var(--icon-lg); height: var(--icon-lg); }
.spin { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* The logo in a top bar (the dashboard's, the reading pages'): side by side, 32 px tall. */
.brand { display: inline-flex; align-items: center; gap: 8px; border-radius: var(--radius-sm); color: var(--text-primary); text-decoration: none; }
.brand img { width: auto; height: 32px; } /* 77 px wide */
/* Server pages inline the logo as one SVG (lib/pages.js) whose charcoal parts are
   currentColor, so the token gives them each theme's ink. Both sides are set: an inline
   <svg> doesn't take its width from its height in every browser. */
.logo-svg { display: block; flex: none; color: var(--logo-ink); }
.brand .logo-svg { width: calc(32px * 622 / 260); height: 32px; }

/* Avatar: Google photo over the initial (the initial shows if the photo fails). */
.avatar {
  position: relative; display: inline-grid; place-items: center; width: 24px; height: 24px; flex: none;
  border-radius: 50%; background: var(--surface-3); color: var(--text-secondary);
  font-size: 11px; font-weight: var(--weight-semibold); line-height: 1; overflow: hidden;
  box-shadow: inset 0 0 0 1px var(--media-edge);
}
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.avatar::after { content: ""; position: absolute; inset: 0; border-radius: 50%; box-shadow: inset 0 0 0 1px var(--media-edge); pointer-events: none; }


/* ==========================================================================
   5 Buttons
   Variants: primary (one per view), secondary, subtle, ghost, danger, danger-ghost.
   Sizes: xs 24, sm 28, md 32 (default), lg 40; btn-icon is square.
   States: hover, pressed (:active or .is-pressed), focus, disabled (:disabled or
   aria-disabled), loading (.is-loading).
   ========================================================================== */

.btn {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: var(--control-md); padding: 0 12px;
  border: 1px solid transparent; border-radius: var(--radius-md);
  background-color: transparent; color: var(--text-primary);
  font-size: var(--text-sm); font-weight: var(--weight-medium); line-height: 1;
  white-space: nowrap; text-decoration: none; user-select: none;
  transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.btn .i { margin: 0 -1px; }
.btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.btn-primary { background-color: var(--primary); color: var(--on-primary); }
.btn-secondary { background-color: var(--field-bg); border-color: var(--border-strong); }
.btn-subtle { background-color: var(--surface-3); }
.btn-ghost { color: var(--text-secondary); }
.btn-danger { background-color: var(--danger); color: var(--on-danger); }
.btn-danger-ghost { color: var(--danger-text); }

/* Hover only where there is a pointer to hover with: after a tap on a touch screen it would
   stay lit. (Before the pressed states, which win over it.) The secondary hover fill is
   surface-3, which shows on the canvas of the centred pages too: the translucent hover tone
   turned the white button into #F5F5F5 on #F6F6F6 there. */
@media (hover: hover) {
  .btn-primary:hover { background-color: var(--primary-hover); }
  .btn-secondary:hover { border-color: var(--border-hover); background-color: var(--surface-3); }
  .btn-subtle:hover { background-image: linear-gradient(var(--hover), var(--hover)); }
  .btn-ghost:hover { background-color: var(--hover); color: var(--text-primary); }
  .btn-danger:hover { background-color: var(--danger-hover); }
  .btn-danger-ghost:hover { background-color: var(--danger-subtle); }
}

.btn-primary:active, .btn-primary.is-pressed { background-color: var(--primary-pressed); }
.btn-secondary:active, .btn-secondary.is-pressed { background-image: linear-gradient(var(--pressed), var(--pressed)); }
.btn-subtle:active, .btn-subtle.is-pressed { background-image: linear-gradient(var(--pressed), var(--pressed)); }
.btn-ghost:active, .btn-ghost.is-pressed, .btn-ghost[aria-expanded="true"] { background-color: var(--pressed); color: var(--text-primary); }
.btn-danger:active, .btn-danger.is-pressed { background-color: var(--danger-hover); background-image: linear-gradient(rgba(0, 0, 0, 0.12), rgba(0, 0, 0, 0.12)); }
.btn-danger-ghost:active, .btn-danger-ghost.is-pressed { background-color: var(--danger-subtle); background-image: linear-gradient(var(--pressed), var(--pressed)); }

.btn-sm { height: var(--control-sm); padding: 0 10px; }
.btn-xs { height: var(--control-xs); padding: 0 8px; font-size: var(--text-xs); border-radius: var(--radius-sm); }
.btn-lg { height: var(--control-lg); padding: 0 16px; font-size: var(--text-md); }
.btn-block { width: 100%; }
.btn-icon { width: var(--control-md); padding: 0; }
.btn-icon.btn-sm { width: var(--control-sm); }
.btn-icon.btn-xs { width: var(--control-xs); }
.btn-icon.btn-lg { width: var(--control-lg); }

.btn:disabled, .btn[aria-disabled="true"] {
  cursor: not-allowed; box-shadow: none; background-image: none;
  color: var(--text-disabled); border-color: var(--border-subtle);
}
.btn-primary:is(:disabled, [aria-disabled="true"]),
.btn-danger:is(:disabled, [aria-disabled="true"]) { background-color: var(--surface-3); }
.btn-secondary:is(:disabled, [aria-disabled="true"]) { background-color: var(--field-bg); }
.btn-ghost:is(:disabled, [aria-disabled="true"]),
.btn-danger-ghost:is(:disabled, [aria-disabled="true"]) { border-color: transparent; background-color: transparent; }

.btn.is-loading { color: transparent; pointer-events: none; }
.btn.is-loading::after {
  content: ""; position: absolute; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--on-primary); border-right-color: transparent; animation: spin 0.8s linear infinite;
}
.btn-secondary.is-loading::after, .btn-ghost.is-loading::after, .btn-subtle.is-loading::after { border-color: var(--text-secondary); border-right-color: transparent; }
.btn-danger.is-loading::after { border-color: var(--on-danger); border-right-color: transparent; }


/* ==========================================================================
   6 Fields and the switch
   .field wraps a borderless input, so it can carry an attached addon (the domain suffix),
   a leading icon or trailing controls. Label above (.label), help below (.help); errors
   turn both the field and the help red.
   ========================================================================== */

.label { display: block; margin-bottom: 6px; font-size: var(--text-xs); line-height: var(--lh-xs); font-weight: var(--weight-medium); color: var(--text-secondary); }
.label-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.help { display: flex; align-items: flex-start; gap: 6px; margin-top: 6px; font-size: var(--text-xs); line-height: var(--lh-xs); color: var(--text-muted); overflow-wrap: anywhere; }
.help .i { width: var(--icon-sm); height: var(--icon-sm); margin-top: 1px; }
.help .t-mono { line-height: 1; } /* an address in a help line keeps the line's height */
.help.is-error { color: var(--danger-text); }
.help.is-ok { color: var(--success-text); }
/* Two texts in one place, a note and the error that takes its place (.is-off hides one), so
   nothing around the field moves when an error comes or goes. */
.help-stack { display: grid; }
.help-stack > * { grid-area: 1 / 1; display: flex; align-items: flex-start; gap: 6px; min-width: 0; }
.help-stack > .is-block { display: block; }
.help-stack > .is-off { visibility: hidden; }

.field {
  display: flex; align-items: center; height: var(--control-md); min-width: 0;
  border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  background: var(--field-bg); color: var(--text-primary);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.field:hover { border-color: var(--border-hover); }
/* Focus is the ring blue (in dark, lighter than the fill blue), like every other focus ring. */
.field:focus-within, .field.is-focus { border-color: var(--focus); box-shadow: 0 0 0 3px var(--focus-ring); }
.field.is-invalid { border-color: var(--danger); }
/* Focused while invalid: the red border doubles to 2 px (3:1 or more against every surface, in
   both themes) inside a faint halo, so focus shows and the error colour stays. */
.field.is-invalid:focus-within, .field.is-invalid.is-focus { box-shadow: 0 0 0 1px var(--danger), 0 0 0 4px var(--danger-subtle); }
.field.is-disabled { background: var(--surface-3); border-color: var(--border-subtle); color: var(--text-disabled); }
.field input, .field .value {
  flex: 1 1 auto; min-width: 0; height: 100%; padding: 0 10px;
  border: 0; border-radius: inherit; background: transparent; outline: none;
  font-size: var(--text-sm); color: inherit;
}
.field .value { display: flex; align-items: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.field input::placeholder, .field .placeholder { color: var(--text-muted); opacity: 1; }
.field input:disabled { cursor: not-allowed; }
/* A secret typed into a text field, masked as a password's, so that no password manager takes
   it for one (the API key; app.js says where it can't be masked). */
.field input.is-masked { -webkit-text-security: disc; }
.field input:-webkit-autofill {
  -webkit-box-shadow: 0 0 0 40px var(--field-bg) inset; -webkit-text-fill-color: var(--text-primary);
  caret-color: var(--text-primary);
}
.field-mono input, .field-mono .value { font-family: var(--font-mono); font-size: var(--text-xs); }
.field-addon {
  flex: none; align-self: stretch; display: flex; align-items: center; padding: 0 10px;
  border-left: 1px solid var(--border-subtle); border-radius: 0 calc(var(--radius-md) - 1px) calc(var(--radius-md) - 1px) 0;
  background: var(--surface-2); color: var(--text-muted); font-family: var(--font-mono); font-size: var(--text-xs); white-space: nowrap;
}
.field-lead { flex: none; margin-left: 10px; margin-right: -4px; color: var(--text-muted); }
.field-end { flex: none; display: inline-flex; align-items: center; gap: 2px; margin-right: 4px; }
.field-end .kbd { margin-right: 4px; }
.field-sm { height: var(--control-sm); }
.field-lg { height: var(--control-lg); }
.field-lg input { font-size: var(--text-md); padding: 0 12px; }
/* A button at the field's end (Show / Hide) fits inside its border, on touch too. */
.field-end .btn { height: 24px; }

/* Switch: a <button role="switch"> with aria-checked; its text is the label, the track comes
   first. States: hover, pressed (:active: the knob stretches toward the other side),
   focus-visible (the ring on the track), disabled (:disabled or aria-disabled), checked. */
.switch {
  display: inline-flex; align-items: center; gap: 10px; min-height: var(--control-xs); padding: 0;
  border: 0; border-radius: var(--radius-sm); background: none; color: var(--text-primary);
  font-size: var(--text-sm); line-height: var(--lh-sm); text-align: left; cursor: pointer;
}
.switch-track {
  position: relative; width: 28px; height: 16px; flex: none; border-radius: 8px;
  background: var(--border-strong); transition: background-color var(--dur) var(--ease);
}
.switch-track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; border-radius: 6px;
  background: var(--switch-knob); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  transition: transform var(--dur) var(--ease), width var(--dur-fast) var(--ease);
}
.switch[aria-checked="true"] .switch-track { background: var(--accent); }
.switch[aria-checked="true"] .switch-track::after { transform: translateX(12px); background: var(--on-accent); }
@media (hover: hover) {
  .switch:not(:disabled):not([aria-disabled="true"]):hover .switch-track { background: var(--border-hover); }
  .switch[aria-checked="true"]:not(:disabled):not([aria-disabled="true"]):hover .switch-track { background: var(--accent-hover); }
}
.switch:not(:disabled):not([aria-disabled="true"]):active .switch-track::after { width: 16px; }
.switch[aria-checked="true"]:not(:disabled):not([aria-disabled="true"]):active .switch-track::after { transform: translateX(8px); }
.switch:focus-visible { outline: none; }
.switch:focus-visible .switch-track { outline: 2px solid var(--focus); outline-offset: 2px; }
.switch:is(:disabled, [aria-disabled="true"]) { color: var(--text-disabled); cursor: not-allowed; }
.switch:is(:disabled, [aria-disabled="true"]) .switch-track { opacity: 0.5; }
.switch[aria-busy="true"] { cursor: progress; }


/* ==========================================================================
   7 Drop zone: the product's core interaction. Never changes size under the pointer.
   States: idle (dashed), .is-over (the target under the pointer), .is-dragging on an
   ancestor (every target says so), .is-busy, .is-error.
   ========================================================================== */

.dropzone {
  display: grid; justify-items: center; align-content: center; gap: 10px;
  padding: 24px 16px; min-height: 148px;
  border: 1px dashed var(--border-strong); border-radius: var(--radius-lg);
  background: var(--surface-1); text-align: center;
  transition: border-color var(--dur) var(--ease), background-color var(--dur) var(--ease);
}
.dropzone-icon { display: grid; place-items: center; width: 24px; height: 24px; color: var(--text-muted); }
.dropzone-title { font-weight: var(--weight-medium); }
.dropzone-sub { font-size: var(--text-xs); line-height: var(--lh-xs); color: var(--text-muted); }
.dropzone .row-actions { justify-content: center; }
.dropzone.is-over { border-style: solid; border-color: var(--accent); background: var(--accent-subtle); box-shadow: inset 0 0 0 1px var(--accent); }
.dropzone.is-over .row-actions, .dropzone.is-busy .row-actions { visibility: hidden; }
.is-dragging .dropzone:not(.is-over):not(.is-busy) { border-color: var(--accent-border); }
.is-dragging .dropzone:not(.is-over):not(.is-busy) .dropzone-title,
.is-dragging .dropzone:not(.is-over):not(.is-busy) .dropzone-icon { color: var(--accent-text); }
.dropzone.is-over .dropzone-icon { color: var(--accent); }
.dropzone.is-busy { border-style: solid; border-color: var(--border-subtle); background: var(--surface-2); }
.dropzone.is-error { border-color: var(--danger); background: var(--danger-subtle); }
.dropzone.is-error .dropzone-icon { color: var(--danger-text); }
.dropzone-compact { min-height: 0; justify-items: start; align-content: start; text-align: left; padding: 12px; gap: 10px; }


/* ==========================================================================
   8 Menus
   A .menu-wrap holds the trigger (aria-haspopup, aria-expanded) and its .menu, which
   opens below the trigger, right-aligned, or above it (.is-up) when there is no room.
   Items are .menu-item (button or a) with role="menuitem"; the focused item is highlighted
   and keyboard focus adds an inset ring.
   ========================================================================== */

.menu {
  min-width: 200px; padding: 4px;
  border: 1px solid var(--border-subtle); border-radius: var(--radius-lg);
  background: var(--overlay); box-shadow: var(--shadow-md);
}
.menu-wrap { position: relative; }
.menu-wrap > .menu { position: absolute; top: calc(100% + 4px); right: 0; z-index: 30; animation: pop-in var(--dur-fast) var(--ease); }
.menu-wrap > .menu.is-up { top: auto; bottom: calc(100% + 4px); }
@keyframes pop-in { from { opacity: 0; transform: translateY(-2px); } }

.menu-item {
  display: flex; align-items: center; gap: 8px; width: 100%; height: var(--control-sm); padding: 0 8px;
  border: 0; border-radius: var(--radius-sm); background: none; color: var(--text-primary);
  font-size: var(--text-sm); text-align: left; text-decoration: none; white-space: nowrap; cursor: pointer;
}
.menu-item .i { color: var(--text-muted); }
.menu-item .kbd, .menu-item .end { margin-left: auto; }
/* One highlight: the focused item. The pointer moves focus to the item under it (app.js), so
   an item under a resting pointer isn't lit while the keys move focus elsewhere. */
.menu-item:focus, .menu-item.is-active { background: var(--pressed); outline: none; }
.menu-item:focus-visible, .menu-item.is-focus { outline: 2px solid var(--focus); outline-offset: -2px; background: var(--pressed); }
.menu .menu-item:disabled, .menu .menu-item[aria-disabled="true"] { color: var(--text-disabled); cursor: not-allowed; background: none; outline: none; }
.menu .menu-item:disabled .i, .menu .menu-item[aria-disabled="true"] .i { color: var(--text-disabled); }
.menu-item.is-danger, .menu-item.is-danger .i { color: var(--danger-text); }
.menu-item.is-danger:not(:disabled):not([aria-disabled="true"]):is(:focus, .is-active) { background: var(--danger-subtle); }
.menu-item .tick { margin-left: auto; color: var(--accent); }
.menu-sep { height: 1px; margin: 4px -4px; background: var(--border-subtle); }
.menu-label { padding: 6px 8px 4px; font-size: var(--text-xs); color: var(--text-muted); }
.menu-label.is-title { color: var(--text-secondary); font-weight: var(--weight-medium); }


/* ==========================================================================
   9 Tooltip: inverse surface, no border, so it never reads as a button.
   ========================================================================== */

.tooltip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px;
  border: 1px solid var(--inverse-border); border-radius: var(--radius-sm);
  background: var(--inverse); color: var(--on-inverse); box-shadow: var(--shadow-md);
  font-size: var(--text-xs); line-height: var(--lh-xs); white-space: nowrap;
}
.tooltip .kbd { height: 16px; min-width: 16px; background: transparent; border-color: rgba(255, 255, 255, 0.2); box-shadow: none; color: inherit; opacity: 0.8; }


/* ==========================================================================
   10 Dialog: a native modal <dialog> (top layer, inert page, Escape) styled as .dialog.
   ========================================================================== */

.dialog {
  width: min(440px, calc(100vw - 32px)); max-width: calc(100vw - 32px); max-height: calc(100dvh - 32px);
  padding: 0; border: 1px solid var(--border-subtle); border-radius: var(--radius-xl);
  background: var(--overlay-raised); color: var(--text-primary); box-shadow: var(--shadow-lg); overflow: hidden;
}
.dialog::backdrop { background: var(--backdrop); }
.dialog-body { display: grid; gap: 8px; padding: 20px 20px 16px; }
.dialog-title { font-size: var(--text-lg); line-height: var(--lh-lg); font-weight: var(--weight-semibold); letter-spacing: -0.01em; overflow-wrap: anywhere; }
.dialog-text { color: var(--text-secondary); }
.dialog-field { margin-top: 8px; }
.dialog-foot { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border-subtle); background: var(--surface-2); }
.dialog-foot .hint { margin-right: auto; font-size: var(--text-xs); color: var(--text-muted); }
/* Names and addresses in a dialog's text break rather than run past its edge. */
.dialog-text .t-mono, .dialog .label .t-mono { overflow-wrap: anywhere; }
/* A menu inside a dialog (a selector's list) stands one step above the dialog, as menus stand
   above the page. */
.dialog .menu { background: var(--overlay-top); border-color: var(--border-strong); }
/* Phones: at the top, where the on-screen keyboard doesn't reach (index.html's viewport has
   interactive-widget=resizes-content, so 100dvh ends above the keyboard), and scrolling when
   it doesn't fit. */
@media (max-width: 699px) {
  .dialog { margin: 16px auto auto; overflow: auto; }
}
.backdrop { position: fixed; inset: 0; display: grid; place-items: center; background: var(--backdrop); z-index: 40; }


/* ==========================================================================
   11 Toast: bottom centre. Success icon, error icon, optional action (Undo), close button.
   Each modal dialog holds its own .toasts, so a toast raised from a dialog shows above it.
   ========================================================================== */

.toasts {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 50;
  display: grid; justify-items: center; gap: 8px; width: max-content; max-width: calc(100vw - 32px);
  pointer-events: none;
}
.toast {
  display: inline-flex; align-items: center; gap: 10px; min-height: 36px; max-width: 100%; padding: 6px 12px;
  border: 1px solid var(--inverse-border); border-radius: var(--radius-lg);
  background: var(--inverse); color: var(--on-inverse); box-shadow: var(--shadow-md);
  font-size: var(--text-sm); pointer-events: auto; user-select: text; overflow-wrap: anywhere;
  animation: toast-in var(--dur) var(--ease);
}
.toast-text { min-width: 0; }
.toast .i-ok { color: var(--on-inverse-ok); }
.toast .i-err { color: var(--on-inverse-error); }
.toast .btn { flex: none; height: 24px; padding: 0 8px; color: inherit; opacity: 0.85; }
.toast .btn-icon { width: 24px; padding: 0; }
.toast .btn:last-child { margin-right: -6px; }
@media (hover: hover) {
  .toast .btn:hover { background: rgba(255, 255, 255, 0.1); opacity: 1; }
}
.toast .btn:active { background: rgba(255, 255, 255, 0.16); }
.toast .btn:focus-visible { outline-color: var(--on-inverse); opacity: 1; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }


/* ==========================================================================
   12 Status, badge, progress
   ========================================================================== */

.status { display: inline-flex; align-items: center; gap: 7px; font-size: var(--text-sm); color: var(--text-secondary); white-space: nowrap; }
.dot { width: 7px; height: 7px; flex: none; border-radius: 50%; background: var(--text-disabled); }
.dot.is-live { background: var(--success); box-shadow: 0 0 0 3px var(--success-subtle); }
.dot.is-pending { background: var(--warning); box-shadow: 0 0 0 3px var(--warning-subtle); animation: pulse 1.6s var(--ease) infinite; }
.dot.is-stalled { background: var(--warning); box-shadow: 0 0 0 3px var(--warning-subtle); }
.dot.is-busy { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-subtle); }
.dot.is-error { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-subtle); }
@keyframes pulse { 50% { opacity: 0.45; } }
.status-live { color: var(--success-text); }
.status-pending { color: var(--warning-text); }
.status-error { color: var(--danger-text); }

.badge {
  display: inline-flex; align-items: center; gap: 5px; height: 20px; padding: 0 6px;
  border-radius: var(--radius-sm); background: var(--surface-3); color: var(--text-secondary);
  font-size: var(--text-xs); font-weight: var(--weight-medium); line-height: 1; white-space: nowrap;
}
.badge .i { width: var(--icon-xs); height: var(--icon-xs); }
.badge-sm { height: 18px; padding: 0 6px; }
.badge-success { background: var(--success-subtle); color: var(--success-text); }
.badge-warning { background: var(--warning-subtle); color: var(--warning-text); }
.badge-danger  { background: var(--danger-subtle); color: var(--danger-text); }
.badge-accent  { background: var(--accent-subtle); color: var(--accent-text); }
.badge-outline { background: transparent; box-shadow: inset 0 0 0 1px var(--border-strong); }

.progress { display: grid; gap: 6px; width: 100%; }
.progress-track { height: 3px; border-radius: 2px; background: var(--surface-3); overflow: hidden; }
.progress-bar { width: 0; height: 100%; border-radius: 2px; background: var(--accent); transition: width var(--dur) linear; }
.progress-label { display: flex; justify-content: space-between; gap: 8px; font-size: var(--text-xs); line-height: var(--lh-xs); color: var(--text-muted); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }


/* ==========================================================================
   13 Banner, empty state, skeleton
   ========================================================================== */

.banner { display: flex; align-items: flex-start; gap: 8px; padding: 8px 10px; border-radius: var(--radius-md); font-size: var(--text-sm); overflow-wrap: anywhere; }
.banner .i { margin-top: 1px; }
.banner-error { background: var(--danger-subtle); color: var(--danger-text); }
.banner-info { background: var(--surface-1); color: var(--text-secondary); box-shadow: inset 0 0 0 1px var(--border-subtle); }
.banner-warning { background: var(--warning-subtle); color: var(--warning-text); }

.empty { display: grid; justify-items: center; gap: 6px; padding: 40px 24px; text-align: center; }
.empty-icon { display: grid; place-items: center; width: 24px; height: 24px; margin-bottom: 4px; color: var(--text-muted); }
.empty-title { font-weight: var(--weight-semibold); }
.empty-text { max-width: 320px; color: var(--text-secondary); overflow-wrap: anywhere; }
.empty-text b { color: var(--text-primary); font-weight: var(--weight-medium); }
.empty .row-actions { margin-top: 10px; justify-content: center; }

.skeleton { display: block; border-radius: var(--radius-sm); background: linear-gradient(90deg, var(--surface-3), var(--hover), var(--surface-3)); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }


/* ==========================================================================
   14 Lists and tables
   ========================================================================== */

.list { border-top: 1px solid var(--border-subtle); }
.list-item { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 8px 12px; border-bottom: 1px solid var(--border-subtle); }
.list-item:hover { background: var(--hover); }
.list-item .text { display: grid; min-width: 0; flex: 1; }
.list-item .title { font-weight: var(--weight-medium); overflow-wrap: anywhere; }
.list-dense .list-item { min-height: 36px; padding: 4px 8px; gap: 8px; }

/* Table: set --cols on .table for the grid columns. */
.table { width: 100%; }
.thead, .tr { display: grid; grid-template-columns: var(--cols); align-items: center; column-gap: 16px; padding: 0 12px 0 16px; }
.thead { height: 32px; border-bottom: 1px solid var(--border-subtle); background: var(--surface-2); color: var(--text-muted); font-size: var(--text-xs); font-weight: var(--weight-medium); }
.thead .sortable { display: inline-flex; align-items: center; gap: 4px; }
.tr { position: relative; min-height: 52px; border-bottom: 1px solid var(--border-subtle); cursor: default; outline: none; }
/* Hover only where there is a pointer to hover with (on touch it would stick after a tap). */
@media (hover: hover) {
  .tr:hover { background: var(--hover); }
}
.tr:focus-visible { box-shadow: inset 0 0 0 2px var(--focus); }
.tr[aria-selected="true"] { background: var(--selected); }
.tr[aria-selected="true"]::before { content: ""; position: absolute; left: 0; top: 0; bottom: -1px; width: 2px; background: var(--accent); }
.tr .actions { display: flex; align-items: center; justify-content: flex-end; gap: 2px; }
.tr .quiet { opacity: 0; transition: opacity var(--dur-fast) var(--ease); }
.tr:hover .quiet, .tr[aria-selected="true"] .quiet, .tr:focus-within .quiet { opacity: 1; }
.cell-name { display: flex; align-items: center; gap: 10px; min-width: 0; }
.cell-name .name { font-weight: var(--weight-medium); }
.cell-name .sub { display: flex; align-items: center; gap: 6px; min-width: 0; color: var(--text-muted); }
.cell-name .text { display: grid; min-width: 0; }
/* A row as a drop target: its instruction (data-drop) replaces the cells. */
.tr.is-over { background: color-mix(in srgb, var(--accent) 14%, transparent); box-shadow: inset 0 0 0 2px var(--accent); }
.is-dragging .tr[aria-selected="true"]:not(.is-over) { background: none; }
.is-dragging .tr[aria-selected="true"]:not(.is-over)::before { background: var(--border-strong); }
.tr.is-over::after {
  content: attr(data-drop); position: absolute; inset: 0 12px 0 auto; display: flex; align-items: center;
  color: var(--accent-text); font-weight: var(--weight-medium);
}


/* ==========================================================================
   15 Panels: only where content needs a container (one level at most).
   ========================================================================== */

.panel { border: 1px solid var(--border-subtle); border-radius: var(--radius-lg); background: var(--surface-1); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 40px; padding: 0 8px 0 12px; border-bottom: 1px solid var(--border-subtle); }
.panel-body { padding: 12px; }


/* ==========================================================================
   16 Layout primitives
   ========================================================================== */

.row-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.stack-1 { display: grid; gap: 4px; }
.stack-2 { display: grid; gap: 8px; }
.stack-3 { display: grid; gap: 12px; }
.stack-4 { display: grid; gap: 16px; }
.hstack { display: flex; align-items: center; gap: 8px; min-width: 0; }
.grow { flex: 1 1 auto; min-width: 0; }
.spacer { flex: 1 1 auto; }

/* Tool shell: top bar + workspace of panes (the dashboard). */
.app { display: grid; grid-template-rows: var(--topbar-h) minmax(0, 1fr); height: 100vh; height: 100dvh; background: var(--surface-1); }
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) var(--inspector-w); min-height: 0; }
.pane { min-height: 0; overflow: auto; scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
.pane-main { background: var(--surface-1); }
.pane-side { overflow: hidden; background: var(--surface-2); border-left: 1px solid var(--border-subtle); }
.pane-head { display: flex; align-items: center; gap: 8px; height: 48px; padding: 0 12px 0 16px; border-bottom: 1px solid var(--border-subtle); }
.pane-foot { display: flex; align-items: center; gap: 8px; padding: 12px 16px; color: var(--text-muted); font-size: var(--text-xs); }

.section { padding: 16px; border-bottom: 1px solid var(--border-subtle); }
.section:last-child { border-bottom: 0; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 24px; margin-bottom: 8px; }
.section-head .t-panel { display: inline-flex; align-items: center; gap: 6px; }
.section-head .count { font-weight: var(--weight-regular); color: var(--text-muted); font-variant-numeric: tabular-nums; }


/* ==========================================================================
   17 Top bar and account menu (portal and dashboard)
   headerHtml() in app.js renders: brand · spacer · account trigger with its menu.
   ========================================================================== */

.topbar {
  display: flex; align-items: center; gap: 12px; height: var(--topbar-h); padding: 0 12px 0 16px;
  border-bottom: 1px solid var(--border-subtle); background: var(--surface-1);
}
.topbar-sep { width: 1px; height: 16px; background: var(--border-subtle); }
.topbar-plain { background: transparent; border-bottom-color: transparent; }

.account {
  display: inline-flex; align-items: center; gap: 8px; height: var(--control-md); max-width: 100%; padding: 0 6px 0 4px;
  border: 0; border-radius: var(--radius-md); background: transparent; color: var(--text-secondary); font-size: var(--text-sm);
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
@media (hover: hover) {
  .account:hover { background: var(--hover); color: var(--text-primary); }
}
/* Open is pressed, as an open ⋯ trigger; the avatar keeps an edge on the pressed fill. */
.account:active, .account[aria-expanded="true"] { background: var(--pressed); color: var(--text-primary); }
.account[aria-expanded="true"] .avatar { background: var(--surface-1); }
.account[aria-expanded="true"] .avatar, .account[aria-expanded="true"] .avatar::after { box-shadow: inset 0 0 0 1px var(--border-strong); }
.account .i { width: 14px; height: 14px; color: var(--text-muted); }
.account-email { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.menu-account { width: 248px; }
.menu-account-who { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; color: var(--text-primary); font-weight: var(--weight-medium); overflow-wrap: anywhere; }
.menu-account-who > span:first-child { min-width: 0; }

@media (max-width: 559px) {
  .account-email { display: none; }
}


/* ==========================================================================
   18 Centred pages: sign-in and every server page (access denied, link expired, errors,
   404). The owner's logo first, its top at the same height on every page, then title, one
   line, actions (a single action is primary), Privacy · Terms at the foot. Pure HTML and
   CSS: server pages run no script.
   ========================================================================== */

.centered { position: relative; min-height: 100vh; min-height: 100dvh; display: grid; grid-template-rows: 1fr auto; background: var(--bg); }
/* The theme button on centred pages, where a top bar would hold it. */
.centered-top { position: absolute; top: 8px; right: 8px; }
.centered-main { display: grid; place-items: start center; padding: 22vh 16px 32px; }
.centered-foot { display: flex; justify-content: center; gap: 12px; padding: 16px; font-size: var(--text-xs); color: var(--text-muted); }
/* Privacy and Terms: 24 px tall to tap (WCAG 2.5.8) inside the same 18 px line. */
.centered-foot a, .read-foot a { display: inline-block; padding: 3px 0; margin: -3px 0; }

.cpage { width: min(320px, 100%); display: grid; justify-items: center; text-align: center; }
/* The owner's logo (flask over the wordmark): over the title, 88 px as over the portal's list;
   on sign-in it stands in for the title, 112 px. */
.cpage .page-logo { margin-bottom: 24px; line-height: 0; }
.page-logo .logo-svg { width: calc(88px * 888 / 960); height: 88px; }
.cpage .t-title { margin-bottom: 8px; max-width: 100%; overflow-wrap: anywhere; }
.cpage .signin-logo { margin: 0 0 16px; line-height: 0; }
.signin-logo img, .portal-logo img, .page-logo img { width: auto; }
.signin-logo img { height: 112px; }
.page-logo img { height: 88px; }
.cpage .t-lead { width: 100%; margin-bottom: 24px; text-wrap: balance; overflow-wrap: anywhere; }
.cpage .t-lead b { color: var(--text-primary); font-weight: var(--weight-medium); }
.cpage .t-lead .code { overflow-wrap: anywhere; }
/* Names stay on one line when they fit, and break only when a line can't hold them. */
.cpage .nowrap { display: inline-block; max-width: 100%; white-space: normal; }
.cpage .actions { display: grid; gap: 8px; width: 100%; }
.cpage .actions .btn { height: auto; min-height: var(--control-lg); padding-block: 9px; line-height: 20px; white-space: normal; overflow-wrap: anywhere; }
.cpage .banner { width: 100%; margin-bottom: 16px; text-align: left; }
/* The development sign-in and a shared link's password (lib/pages.js): a field, then actions. */
.cpage .dev, .cpage .pw-form { display: grid; gap: 16px; width: 100%; text-align: left; }
.cpage .dev .help, .cpage .pw-form .help { margin-top: 4px; } /* the help belongs to the field above it */
.cpage .fine { margin-top: 20px; font-size: var(--text-xs); line-height: var(--lh-xs); color: var(--text-muted); }


/* ==========================================================================
   19 Google sign-in button: Google's branding (rectangular shape), not the system's.
   ========================================================================== */

.gsi {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px; width: 100%;
  height: 40px; padding: 0 12px; border: 1px solid #747775; border-radius: 4px;
  background-color: #FFFFFF; color: #1F1F1F; font: 500 14px/20px Roboto, var(--font-ui); letter-spacing: 0.25px;
  text-decoration: none; cursor: pointer; transition: background-color var(--dur-fast) var(--ease);
}
.gsi:hover { background-image: linear-gradient(rgba(48, 48, 48, 0.08), rgba(48, 48, 48, 0.08)); }
.gsi:active { background-image: linear-gradient(rgba(48, 48, 48, 0.12), rgba(48, 48, 48, 0.12)); }
.gsi .g { width: 18px; height: 18px; flex: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .gsi { background-color: #131314; border-color: #8E918F; color: #E3E3E3; }
  :root:not([data-theme="light"]) .gsi:hover { background-image: linear-gradient(rgba(227, 227, 227, 0.08), rgba(227, 227, 227, 0.08)); }
  :root:not([data-theme="light"]) .gsi:active { background-image: linear-gradient(rgba(227, 227, 227, 0.12), rgba(227, 227, 227, 0.12)); }
}
:root[data-theme="dark"] .gsi { background-color: #131314; border-color: #8E918F; color: #E3E3E3; }
:root[data-theme="dark"] .gsi:hover { background-image: linear-gradient(rgba(227, 227, 227, 0.08), rgba(227, 227, 227, 0.08)); }
:root[data-theme="dark"] .gsi:active { background-image: linear-gradient(rgba(227, 227, 227, 0.12), rgba(227, 227, 227, 0.12)); }


/* ==========================================================================
   20 Reading pages: privacy policy and terms (640 px measure, 15/24 text).
   ========================================================================== */

.reading { min-height: 100vh; min-height: 100dvh; background: var(--bg); }
.read { width: min(640px, 100%); margin: 0 auto; padding: var(--space-7) 16px 80px; } /* the portal's top too */
.read h1 { margin-bottom: 4px; }
.read h2 { margin: 32px 0 8px; font-size: var(--text-lg); line-height: var(--lh-lg); font-weight: var(--weight-semibold); letter-spacing: -0.01em; }
.read p, .read li { font-size: var(--text-read); line-height: var(--lh-read); color: var(--text-secondary); }
.read p + p { margin-top: 12px; }
.read ul { display: grid; gap: 6px; margin-top: 8px; padding-left: 20px; list-style: disc; }
.read p.t-meta { margin: 4px 0 24px; font-size: var(--text-xs); line-height: var(--lh-xs); color: var(--text-muted); }
.read-foot { display: flex; gap: 12px; margin-top: 40px; padding-top: 16px; border-top: 1px solid var(--border-subtle); font-size: var(--text-xs); color: var(--text-muted); }


/* ==========================================================================
   21 Viewer portal: one centred list, every app one link (one tab stop).
   ========================================================================== */

.portal { min-height: 100vh; min-height: 100dvh; background: var(--bg); }
.portal .topbar { background: transparent; border-bottom-color: transparent; }
.portal-main { width: min(640px, 100%); margin: 0 auto; padding: var(--space-7) 16px 64px; } /* as the reading pages */
.portal-head { display: grid; gap: 4px; margin-bottom: 20px; }
.portal-logo { display: flex; justify-content: center; margin-bottom: 32px; line-height: 0; }
.portal-logo-link { display: block; border-radius: var(--radius-sm); }
.portal-logo img { height: 88px; }
/* Each logo comes as two images and the theme shows one (the dark copy is light grey where
   the artwork is charcoal). */
img.logo-light { display: block; }
img.logo-dark { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) img.logo-light { display: none; }
  :root:not([data-theme="light"]) img.logo-dark { display: block; }
}
:root[data-theme="dark"] img.logo-light { display: none; }
:root[data-theme="dark"] img.logo-dark { display: block; }
.apps { overflow: hidden; }
.apps .list-item { min-height: 60px; padding: 10px 12px 10px 14px; border-bottom: 0; color: inherit; text-decoration: none; }
.apps li:first-child .list-item { border-radius: calc(var(--radius-lg) - 1px) calc(var(--radius-lg) - 1px) 0 0; }
.apps li:last-child .list-item { border-bottom-left-radius: calc(var(--radius-lg) - 1px); border-bottom-right-radius: calc(var(--radius-lg) - 1px); }
.apps .list-item:active { background: var(--pressed); }
.apps .list-item:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--focus); }
.apps .list-item .go { flex: none; color: var(--text-muted); transition: color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease); }
.apps .list-item:hover .go, .apps .list-item:focus-visible .go { color: var(--text-primary); transform: translate(1px, -1px); }


/* ==========================================================================
   22 Touch, no hover, reduced motion
   Touch: controls grow to 40 px and inputs to 16 px text (no iOS zoom on focus).
   ========================================================================== */

@media (pointer: coarse) {
  :root { --topbar-h: 56px; }
  .btn, .btn-sm, .btn-xs, .field, .field-sm, .account { height: var(--control-lg); }
  .field-end .btn { height: 32px; } /* inside a 40 px field */
  .switch { min-height: var(--control-lg); }
  .btn-icon, .btn-icon.btn-sm, .btn-icon.btn-xs { width: var(--control-lg); }
  .btn-xs { padding: 0 12px; font-size: var(--text-sm); }
  .field input { font-size: 16px; }
  .menu-item { height: 40px; }
  .account { min-width: var(--control-lg); justify-content: center; }
  .topbar, .pane-head { height: 56px; padding: 0 16px; }
  .toast .btn { height: var(--control-lg); } /* as every other touch control */
  .toast .btn-icon { width: var(--control-lg); }
}
@media (hover: none) {
  .tr .quiet { opacity: 1; }
  .tr:not(.is-skeleton):active { background: var(--pressed); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
