/* The Cloud Console pages of this site, in the console's own look: its tokens, type, panels, buttons, chips, tables and
   messages, copied from cloud-console/web/console.css (CAP-159 to CAP-161), plus what a write-up needs: the screens
   drawn as the console draws them, and the numbered flow. Light by default; dark when chosen with the switch in the top
   bar (theme.js sets data-theme on <html>). */
:root {
  color-scheme: light;
  --canvas: #f4f5f8; --surface: #ffffff; --raised: #f7f8fa; --ink: #1c2230; --muted: #5a6272;
  --line: #e0e3e9; --line-strong: #c3c8d2;
  --accent: #3a4ed6; --accent-hover: #2f40b8; --accent-ink: #ffffff; --accent-soft: #eceffd;
  --ok: #17784a; --ok-soft: #e4f4ea; --bad: #c0262d; --bad-soft: #fcebea; --warn: #8d5a00; --warn-soft: #fcf1d9;
  --info: #0b67b0; --info-soft: #e5f0fa; --idle: #5a6272; --idle-soft: #eef0f3; --focus: #3a4ed6;
  --bar-bg: #1b2235; --bar-ink: #eef1f8; --bar-muted: #a9b1c6; --bar-line: rgb(255 255 255 / 16%);
  --bar-logo: #5b6cf0; --bar-logo-ink: #ffffff;
  --shadow-sm: 0 1px 2px rgb(20 26 40 / 8%);
  --shadow: 0 1px 2px rgb(20 26 40 / 8%), 0 8px 24px rgb(20 26 40 / 12%);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;
  --text-xs: 0.75rem; --text-sm: 0.8125rem; --text-md: 0.875rem; --text-lg: 1rem; --text-xl: 1.25rem; --text-2xl: 1.375rem;
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px; --space-5: 20px; --space-6: 24px; --space-8: 32px; --space-10: 40px;
  --radius-sm: 4px; --radius: 6px; --radius-lg: 10px;
  --bar-height: 56px; --control: 36px;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --canvas: #0f1218; --surface: #171b23; --raised: #1e232d; --ink: #e6e9ef; --muted: #9ba4b4;
  --line: #2a303c; --line-strong: #3c4452;
  --accent: #9aa7ff; --accent-hover: #b6bfff; --accent-ink: #121738; --accent-soft: #232a4d;
  --ok: #63d394; --ok-soft: #16301f; --bad: #ff8f88; --bad-soft: #3a1a1a; --warn: #f1be5e; --warn-soft: #33270f;
  --info: #72b7ff; --info-soft: #15283d; --idle: #a3acbb; --idle-soft: #252b35; --focus: #9aa7ff;
  --bar-bg: #151a26; --bar-line: rgb(255 255 255 / 12%);
  --shadow-sm: 0 1px 2px rgb(0 0 0 / 40%);
  --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 8px 24px rgb(0 0 0 / 45%);
}

/* Base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; overflow-x: clip; background: var(--canvas); color: var(--ink);
  font: var(--text-md)/1.5 var(--font); -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; text-underline-offset: 2px; }
a:hover { text-decoration: underline; }
h1 { font-size: var(--text-2xl); font-weight: 600; line-height: 1.25; letter-spacing: -0.01em; margin: 0; }
h2 { font-size: var(--text-lg); font-weight: 600; line-height: 1.35; margin: var(--space-8) 0 var(--space-3); }
h3 { font-size: var(--text-md); font-weight: 600; margin: 0 0 var(--space-2); }
p { margin: var(--space-2) 0; }
ul, ol { margin: var(--space-2) 0; padding-left: 1.4em; }
li + li { margin-top: var(--space-1); }
/* Code is a little smaller than the text around it, but never under 12px (inside a hint or a stop box too). */
code, .code-block { font-family: var(--mono); font-size: max(0.857em, 12px); }
code { background: var(--idle-soft); border-radius: var(--radius-sm); padding: 0.1em 0.4em; overflow-wrap: anywhere; }
.muted, .hint { color: var(--muted); }
.hint { font-size: var(--text-sm); margin: var(--space-1) 0 0; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--radius-sm); }
.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.measure { max-width: 72ch; }

/* The top bar: navy in both themes */
.topbar {
  display: flex; align-items: center; gap: var(--space-3); height: var(--bar-height); padding: 0 var(--space-4);
  background: var(--bar-bg); color: var(--bar-ink); border-bottom: 1px solid var(--bar-line);
}
.brand { display: inline-flex; align-items: center; gap: 10px; min-width: 0; font-weight: 600; font-size: var(--text-lg); color: inherit; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.logo { width: 28px; height: 28px; flex: none; }
.logo-tile { fill: var(--bar-logo); }
.logo-bar, .logo-dot { fill: var(--bar-logo-ink); }
.logo-dot { opacity: 0.75; }
.topbar-gap { flex: 1; }
/* The way back to the site: a full-height tap target, as the theme switch beside it. */
.topbar a.back { display: inline-flex; align-items: center; min-height: 36px; padding: 0 var(--space-2); color: var(--bar-muted); font-size: var(--text-sm); white-space: nowrap; }
.topbar a.back:hover { color: var(--bar-ink); }
.topbar :focus-visible { outline-color: var(--bar-ink); }
/* The theme switch: an icon and the theme it switches to. Without JavaScript it could do nothing, so it is hidden. */
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; flex: none; min-height: 32px; padding: 0 10px;
  border: 1px solid var(--bar-line); border-radius: var(--radius); background: transparent; color: var(--bar-muted);
  font: inherit; font-size: var(--text-sm); font-weight: 500; line-height: 1; white-space: nowrap; cursor: pointer;
}
.theme-toggle:hover { color: var(--bar-ink); background: rgb(255 255 255 / 10%); }
.theme-toggle:focus-visible { outline: 2px solid var(--bar-ink); outline-offset: 2px; border-radius: var(--radius); }
.theme-toggle .icon { width: 16px; height: 16px; }
:root:not([data-theme]) .theme-toggle { display: none; }
@media (pointer: coarse) { .theme-toggle, .topbar a.back { min-height: 44px; } }

.main { padding: var(--space-5) var(--space-8) var(--space-10); }

/* Breadcrumbs and the title row */
.crumbs { font-size: var(--text-sm); color: var(--muted); margin: 0 0 var(--space-2); }
.crumbs ol { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1) 0; list-style: none; margin: 0; padding: 0; }
.crumbs li { display: inline-flex; align-items: center; min-width: 0; overflow-wrap: anywhere; margin: 0; }
.crumbs li + li::before { content: "/"; margin: 0 var(--space-2); color: var(--line-strong); }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--accent); }
.crumbs [aria-current="page"] { color: var(--ink); }
.page-header {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3) var(--space-6);
  margin: 0 0 var(--space-5); padding-bottom: var(--space-4); border-bottom: 1px solid var(--line);
}
.page-header h1 { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); min-width: 0; overflow-wrap: anywhere; }

/* Buttons, as the console draws them (in a drawn screen they are pictures: spans, never focusable) */
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: var(--control); padding: 0 var(--space-4); border-radius: var(--radius); border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--accent); font: inherit; font-weight: 500; line-height: 1.2; white-space: nowrap;
}
.button .icon { margin-left: -2px; }
.button-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow-sm); }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin: var(--space-3) 0; }

/* Chips: a label, its tone by colour and by shape */
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 22px; padding: 0 10px 0 8px; border-radius: 999px;
  font-size: var(--text-xs); font-weight: 600; line-height: 1.2; white-space: nowrap; vertical-align: middle;
}
.chip::before { content: ""; width: 8px; height: 8px; flex: none; }
.chip-ok { background: var(--ok-soft); color: var(--ok); }
.chip-ok::before { background: currentColor; border-radius: 50%; }
.chip-bad { background: var(--bad-soft); color: var(--bad); }
.chip-bad::before { background: currentColor; transform: rotate(45deg); width: 7px; height: 7px; }
.chip-warn { background: var(--warn-soft); color: var(--warn); }
.chip-warn::before { background: currentColor; clip-path: polygon(50% 0, 100% 100%, 0 100%); }
.chip-info { background: var(--info-soft); color: var(--info); }
.chip-info::before { border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; }
.chip-idle { background: var(--idle-soft); color: var(--idle); }
.chip-idle::before { border: 2px solid currentColor; border-radius: 50%; }

/* Summary cards */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: var(--space-3); margin: var(--space-4) 0 var(--space-5); }
.stat { min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: var(--space-3) var(--space-4); }
.stat-label { color: var(--muted); font-size: var(--text-sm); margin: 0 0 var(--space-1); }
.stat-value { margin: 0; font-size: var(--text-xl); font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }

/* Panels */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: var(--space-5) var(--space-6); margin: 0 0 var(--space-4); }
.panel > h2:first-child { margin-top: 0; }
.code-block {
  display: block; margin: var(--space-3) 0; padding: 10px var(--space-3); background: var(--raised); border: 1px solid var(--line);
  border-radius: var(--radius); white-space: pre; overflow: auto; line-height: 1.5;
}

/* Tables: a card per row on a phone (each cell labelled by its column) */
.table-frame { overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); margin: var(--space-3) 0; }
table { width: 100%; border-collapse: separate; border-spacing: 0; }
th, td { text-align: left; padding: 10px var(--space-4); border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 600; font-size: var(--text-sm); color: var(--muted); background: var(--raised); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
.nowrap { white-space: nowrap; }
.truncate { display: inline-block; max-width: 30ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }

/* Forms and messages */
.label { display: block; font-weight: 600; font-size: var(--text-sm); margin: var(--space-3) 0 6px; }
.lead { font-weight: 600; }
.form-message {
  border: 1px solid var(--bad); border-left-width: 4px; background: var(--bad-soft); color: var(--bad);
  padding: 10px var(--space-4); border-radius: var(--radius); margin: var(--space-3) 0; overflow-wrap: anywhere;
}
.form-message p { margin: 0; font-weight: 500; }
.form-message ul { margin: var(--space-1) 0 0; padding-left: 1.2em; }
.notice {
  display: flex; align-items: center; gap: var(--space-3); padding: 8px var(--space-4); margin: var(--space-3) 0;
  border-radius: var(--radius); border: 1px solid; border-left-width: 4px; font-weight: 500;
}
.notice-ok { background: var(--ok-soft); color: var(--ok); border-color: var(--ok); }
/* The file chooser as the console now draws it: the text box's frame, its button the console's own. */
.file-input {
  display: flex; align-items: center; gap: var(--space-3); min-height: var(--control); padding: 3px; width: 100%;
  border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); color: var(--ink);
}
.file-input .pick {
  display: inline-flex; align-items: center; min-height: calc(var(--control) - 8px); padding: 0 var(--space-3);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--raised); color: var(--accent); font-weight: 500;
}
.file-input .name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* A screen as the console draws it: a window with its top bar, then the page */
.screen { margin: var(--space-4) 0 var(--space-6); }
.screen > figcaption { color: var(--muted); font-size: var(--text-sm); margin: 0 0 var(--space-2); }
.window { border: 1px solid var(--line-strong); border-radius: var(--radius-lg); overflow: hidden; background: var(--canvas); box-shadow: var(--shadow); }
.window .topbar { height: 44px; font-size: var(--text-sm); }
.window .topbar .brand { font-size: var(--text-md); }
.window .topbar .logo { width: 22px; height: 22px; }
.window .where { color: var(--bar-muted); font-size: var(--text-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.window-page { padding: var(--space-5) var(--space-6); }
.window-page .page-header { margin-bottom: var(--space-4); }
/* The form above the panel, drawn as quiet bars: it is there, the panel is the subject. */
.ghost { display: grid; gap: var(--space-2); max-width: 760px; margin: 0 0 var(--space-6); }
.ghost span { display: block; height: 14px; border-radius: var(--radius-sm); background: var(--idle-soft); }
.ghost span:nth-child(2) { width: 70%; }
.ghost span:nth-child(3) { width: 85%; }
.ghost em { font-style: normal; color: var(--muted); font-size: var(--text-sm); }
.window .panel { max-width: 760px; }
.states { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: var(--space-3); margin: var(--space-3) 0 var(--space-5); }
.state { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: var(--space-4); min-width: 0; }
.state h3 { margin-bottom: var(--space-1); }
.state > p:first-of-type { color: var(--muted); font-size: var(--text-sm); margin-top: 0; }

/* The flow: numbered steps top to bottom, each beside where it stops, joined by a line */
.flow { list-style: none; padding: 0; margin: var(--space-3) 0 var(--space-5); counter-reset: step; }
.flow > li { counter-increment: step; position: relative; display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: var(--space-3); margin: 0; padding: 0 0 22px; }
.flow > li::after { content: ""; position: absolute; left: 27px; bottom: 0; height: 22px; border-left: 2px solid var(--line-strong); }
.flow > li:last-child { padding-bottom: 0; }
.flow > li:last-child::after { content: none; }
.flow .step { display: flex; gap: var(--space-3); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: var(--space-3) var(--space-4); min-width: 0; }
.flow .step::before {
  content: counter(step); flex: none; display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: var(--text-sm);
}
.flow .step b { display: block; }
.flow .step span { display: block; color: var(--muted); font-size: var(--text-sm); }
.flow .stop {
  align-self: start; border: 1px dashed var(--bad); background: var(--bad-soft); color: var(--bad);
  border-radius: var(--radius); padding: var(--space-2) var(--space-3); font-size: var(--text-sm);
}
.flow .stop.part { border-color: var(--warn); background: var(--warn-soft); color: var(--warn); }
.flow .stop.good { border-style: solid; border-color: var(--ok); background: var(--ok-soft); color: var(--ok); }

.foot { color: var(--muted); font-size: var(--text-sm); border-top: 1px solid var(--line); margin-top: var(--space-10); padding-top: var(--space-4); }

/* Tablets */
@media (max-width: 960px) {
  .main { padding: var(--space-5) var(--space-5) var(--space-10); }
}
/* Phones: one column, rows as cards, controls of 44px */
@media (max-width: 640px) {
  :root { --control: 44px; }
  .topbar { gap: var(--space-2); padding: 0 var(--space-3); }
  .theme-toggle, .topbar a.back { min-height: 44px; }
  .main { padding: var(--space-4) var(--space-4) var(--space-10); }
  h1 { font-size: var(--text-xl); }
  .page-header { flex-flow: column nowrap; align-items: flex-start; gap: var(--space-2); }
  .panel { padding: var(--space-4); }
  .window-page { padding: var(--space-4); }
  .window .where { display: none; }
  .flow > li { grid-template-columns: minmax(0, 1fr); gap: 6px; }
  .table-frame { overflow: visible; background: transparent; border: 0; border-radius: 0; }
  .table-frame thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .table-frame table, .table-frame tbody, .table-frame tr { display: block; width: 100%; }
  .table-frame tbody tr {
    margin: 0 0 var(--space-3); padding: var(--space-1) var(--space-4);
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
  }
  .panel .table-frame tbody tr { background: var(--raised); box-shadow: none; }
  /* Each cell a block, its column's name on a line above its value, so text, code and chips in one cell stay together. */
  .table-frame td { display: block; padding: 8px 0; border-bottom: 0; border-top: 1px solid var(--line); white-space: normal; overflow-wrap: anywhere; }
  .table-frame td:first-child { border-top: 0; }
  .table-frame td::before { content: attr(data-label); display: block; margin-bottom: 2px; color: var(--muted); font-size: var(--text-sm); font-weight: 500; }
  .table-frame .truncate { max-width: 100%; }
}
/* Narrow phones: the switch as its icon alone (its aria-label still names it), so the bar keeps brand and back link. */
@media (max-width: 399px) {
  .theme-toggle { min-width: 44px; padding: 0; }
  .theme-toggle-text { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* The write-up's own navigation, under the top bar: one link per page, the current one marked. Scrolls sideways on a
   phone rather than wrapping. */
.subnav {
  display: flex; gap: var(--space-1); overflow-x: auto; padding: 0 var(--space-4);
  background: var(--surface); border-bottom: 1px solid var(--line); scrollbar-width: thin;
}
.subnav a {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 var(--space-3); white-space: nowrap;
  color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.subnav a:hover { color: var(--ink); text-decoration: none; }
.subnav a[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); }
/* Link cards (the overview): a title, a line on what is there */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--space-3); margin: var(--space-4) 0 var(--space-6); }
.card { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: var(--space-4); color: var(--ink); }
.card:hover { border-color: var(--accent); text-decoration: none; box-shadow: var(--shadow-sm); }
.card b { display: block; color: var(--accent); margin-bottom: var(--space-1); }
.card span { color: var(--muted); font-size: var(--text-sm); }
/* A real screenshot: framed as a window, sized by its own width; theme.js shows its light or dark file. */
.shot { margin: var(--space-4) 0 var(--space-6); }
.shot img { display: block; width: 100%; height: auto; border: 1px solid var(--line-strong); border-radius: var(--radius-lg); box-shadow: var(--shadow); background: var(--surface); }
.shot figcaption { color: var(--muted); font-size: var(--text-sm); margin-top: var(--space-2); }
.shot-pair { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 1fr); gap: var(--space-4); align-items: start; }
@media (max-width: 640px) { .shot-pair { grid-template-columns: minmax(0, 1fr); } }
