/*
  Cortex console: instrument panel.
  Tokens first, then base, then components, then the responsive structure at the bottom.
  No external resources: system fonts only.
*/

:root {
  color-scheme: light;

  /* Field and panels: warm gray, a second neutral layer for the faceplate. */
  --bg: #e3e5e8;
  --panel: #f2f3f5;
  --faceplate: #eaecee;
  --inset: #dcdfe3;
  --field: #fbfbfc;
  --line: #cbcfd4;
  --line-strong: #aeb4bb;

  --ink: #1c1f23;
  --ink-2: #4f555c;
  --ink-3: #646a72;

  /* One signal accent: the active client and the primary action. */
  --accent: #1d4ed8;
  --accent-ink: #ffffff;
  --on-fault: #ffffff;
  --accent-soft: #dbe5fb;

  --ok: #1a6e3e;
  --warn: #8f5200;
  --bad: #b3261e;
  --ok-soft: #dcefe3;
  --warn-soft: #f7e8cc;
  --bad-soft: #f6dcd8;

  /* The display window stays dark in both themes, like instrument glass. */
  --screen: #15171a;
  --screen-bar: #1d2024;
  --screen-ink: #e4e6e9;
  --screen-dim: #979ba2;
  --screen-line: #2c3035;
  --screen-cmd: #9cc2ff;
  --screen-err: #ff9d92;
  --screen-ok: #86d6a8;
  --screen-bad: #ff9d92;

  --shadow-key: 0 1px 0 rgb(255 255 255 / 0.7) inset, 0 1px 2px rgb(28 31 35 / 0.18);
  --shadow-pop: 0 10px 28px rgb(28 31 35 / 0.18), 0 2px 6px rgb(28 31 35 / 0.12);

  --font-ui: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Roboto, "Noto Sans", Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, "Liberation Mono", Menlo, monospace;

  /* Type scale, fixed rem, ratio about 1.15. */
  --fs-xs: 0.75rem;
  --fs-sm: 0.8125rem;
  --fs-md: 0.9375rem;
  --fs-lg: 1.0625rem;
  --fs-xl: 1.375rem;

  --radius: 6px;
  --radius-sm: 4px;
  --gutter: 16px;
  --control: 36px;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}

/* Dark theme = the same instrument at night. Two blocks carry the same values: one for the system setting, one for the manual override. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121315;
    --panel: #1a1b1d;
    --faceplate: #212326;
    --inset: #0e0f10;
    --field: #0e0f10;
    --line: #2f3236;
    --line-strong: #464a50;
    --ink: #e8eaed;
    --ink-2: #b0b5bc;
    --ink-3: #8a9098;
    --accent: #6ea0ff;
    --accent-ink: #04122e;
    --on-fault: #04122e;
    --accent-soft: #16264a;
    --ok: #6fd09a;
    --warn: #f0b84a;
    --bad: #ff8d83;
    --ok-soft: #17301f;
    --warn-soft: #382b10;
    --bad-soft: #3b1b18;
    --screen: #0c0d0e;
    --screen-bar: #15171a;
    --screen-line: #24272b;
    --shadow-key: 0 1px 0 rgb(255 255 255 / 0.06) inset, 0 1px 2px rgb(0 0 0 / 0.5);
    --shadow-pop: 0 12px 30px rgb(0 0 0 / 0.55), 0 2px 6px rgb(0 0 0 / 0.4);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121315;
  --panel: #1a1b1d;
  --faceplate: #212326;
  --inset: #0e0f10;
  --field: #0e0f10;
  --line: #2f3236;
  --line-strong: #464a50;
  --ink: #e8eaed;
  --ink-2: #b0b5bc;
  --ink-3: #8a9098;
  --accent: #6ea0ff;
  --accent-ink: #04122e;
  --on-fault: #04122e;
  --accent-soft: #16264a;
  --ok: #6fd09a;
  --warn: #f0b84a;
  --bad: #ff8d83;
  --ok-soft: #17301f;
  --warn-soft: #382b10;
  --bad-soft: #3b1b18;
  --screen: #0c0d0e;
  --screen-bar: #15171a;
  --screen-line: #24272b;
  --shadow-key: 0 1px 0 rgb(255 255 255 / 0.06) inset, 0 1px 2px rgb(0 0 0 / 0.5);
  --shadow-pop: 0 12px 30px rgb(0 0 0 / 0.55), 0 2px 6px rgb(0 0 0 / 0.4);
}

@media (pointer: coarse) {
  :root { --control: 44px; }
}

/* ---------- Base ---------- */

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  background: var(--bg);
  color: var(--ink);
  font: 400 var(--fs-md) / 1.45 var(--font-ui);
  -webkit-text-size-adjust: 100%;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
}

@supports (height: 100dvh) {
  html, body { height: 100dvh; }
}

h1, h2, p, dl, dd, ul { margin: 0; padding: 0; }
ul { list-style: none; }
h1 { font-size: var(--fs-xl); line-height: 1.2; font-weight: 600; letter-spacing: -0.01em; }
a { color: inherit; text-decoration: none; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.icon-sm { width: 15px; height: 15px; }
.marker { width: 12px; height: 12px; flex: none; }
.muted { color: var(--ink-2); font-size: var(--fs-sm); }
.noscript { padding: var(--gutter); }

::selection { background: var(--accent); color: var(--accent-ink); }
input { caret-color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--radius-sm); }

* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
.screen { scrollbar-color: #4a4f56 transparent; }

kbd {
  font: 500 var(--fs-xs) / 1 var(--font-mono);
  padding: 2px 5px;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--panel);
}

/* ---------- Faceplate (top bar) ---------- */

.bar {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 8px var(--gutter);
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--faceplate);
  border-bottom: 1px solid var(--line-strong);
  box-shadow: 0 1px 0 rgb(255 255 255 / 0.35) inset;
  position: relative;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: -0.005em; }
.brand-mark {
  display: grid; place-items: center;
  width: 30px; height: 30px;
  background: var(--accent); color: var(--accent-ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow-key);
}
.brand-name { font-size: var(--fs-lg); }

.bar-nav { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1 1 0; margin-left: 4px; }
.bar-end { display: flex; align-items: center; gap: 8px; margin-left: auto; flex: none; }

.tool, .iconbtn {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: var(--control);
  padding: 0 12px;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-key);
  font-size: var(--fs-md);
  line-height: 1;
  transition: background-color 120ms var(--ease), border-color 120ms var(--ease), transform 120ms var(--ease);
}
.iconbtn { justify-content: center; width: var(--control); padding: 0; }
.tool:hover, .iconbtn:hover { border-color: var(--ink-3); }
.tool:active, .iconbtn:active { transform: translateY(1px); box-shadow: 0 1px 2px rgb(0 0 0 / 0.2) inset; }
.tool[aria-current="page"] { border-color: var(--accent); }

.count {
  min-width: 22px; padding: 2px 6px;
  border-radius: 999px;
  background: var(--inset);
  color: var(--ink-2);
  font: 600 var(--fs-xs) / 1.2 var(--font-ui);
  text-align: center;
}

.switcher { position: relative; min-width: 0; flex: 0 1 auto; }
.switcher-btn { max-width: min(46vw, 340px); min-width: 0; }
.switcher-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.switcher-btn[aria-expanded="true"] { border-color: var(--accent); }

.link { display: inline-flex; align-items: center; gap: 8px; font-size: var(--fs-sm); color: var(--ink-2); white-space: nowrap; }

/* State markers: shape and color together. */
.state-online { color: var(--ok); }
.state-attention { color: var(--warn); }
.state-offline { color: var(--ink-3); }
.state-bad { color: var(--bad); }
.is-busy .marker { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }

/* ---------- Popover (client switcher) ---------- */

.popover {
  position: absolute; top: calc(100% + 8px); left: 0;
  width: min(420px, 92vw);
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-pop);
  padding: 8px;
}

.search {
  display: flex; align-items: center; gap: 8px;
  min-height: var(--control);
  padding: 0 10px;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink-2);
}
.search:focus-within { border-color: var(--accent); }
.search input { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; color: var(--ink); }
.search input::placeholder { color: var(--ink-3); opacity: 1; }
.search-wide { flex: 1; min-width: 200px; }

.options { max-height: min(52vh, 360px); overflow: auto; margin-top: 6px; }
.option {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm); cursor: pointer; min-height: var(--control);
}
.option[aria-selected="true"], .option:hover { background: var(--accent-soft); }
.option-main { min-width: 0; }
.option-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.option-sub { color: var(--ink-2); font-size: var(--fs-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.option-note { color: var(--ink-2); font-size: var(--fs-xs); }
.options-empty { padding: 14px 10px; color: var(--ink-2); font-size: var(--fs-sm); }
.popover-foot { margin-top: 8px; padding: 6px 4px 0; border-top: 1px solid var(--line); color: var(--ink-3); font-size: var(--fs-xs); }

/* ---------- Layout shell ---------- */

.main { min-height: 0; position: relative; }
.view { height: 100%; min-height: 0; overflow: auto; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }

/* ---------- Connecting ---------- */

.view-boot { display: grid; place-items: center; padding: var(--gutter); }

/* ---------- Login ---------- */

.view-login { display: grid; place-items: center; padding: var(--gutter); }
.warn-btn { color: var(--warn); }
.warn-btn .marker { width: 16px; height: 16px; }
.modal { width: min(520px, calc(100vw - 32px)); padding: 24px; color: var(--ink); box-shadow: var(--shadow-pop); }
.modal::backdrop { background: rgb(0 0 0 / 0.5); }
.modal h2 { margin: 0 0 14px; font-size: var(--fs-lg); }
.modal form { margin-top: 16px; display: flex; justify-content: flex-end; }
.warn-list { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 12px; }
.warn-list li { padding: 12px 14px; background: var(--warn-soft); border-left: 3px solid var(--warn); border-radius: var(--radius); }
.warn-list p { margin: 4px 0 0; color: var(--ink-2); }
.login { width: min(440px, 100%); display: grid; gap: 14px; padding: 24px; box-shadow: var(--shadow-pop); }
.field { display: grid; gap: 6px; font-size: var(--fs-sm); color: var(--ink-2); font-weight: 600; }
.field input {
  min-height: var(--control); padding: 0 12px;
  background: var(--field); border: 1px solid var(--line-strong); border-radius: var(--radius);
  color: var(--ink); font: 500 var(--fs-md) var(--font-mono); letter-spacing: 0.02em;
}
.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-error { min-height: 1.3em; color: var(--bad); font-size: var(--fs-sm); }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--control); padding: 0 16px;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--panel); box-shadow: var(--shadow-key);
  font-weight: 600; line-height: 1;
  transition: background-color 120ms var(--ease), border-color 120ms var(--ease), color 120ms var(--ease), transform 120ms var(--ease);
}
.btn:active:not(:disabled) { transform: translateY(1px); box-shadow: 0 1px 2px rgb(0 0 0 / 0.25) inset; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.06); }
.btn.outline { background: transparent; box-shadow: none; }

/* Recovery controls stay quiet until deliberately hovered or focused. */
.danger-on-focus:hover:not(:disabled),
.danger-on-focus:focus-visible { border-color: var(--bad); color: var(--bad); background: var(--bad-soft); }
.danger-on-focus.armed { border-color: var(--bad); background: var(--bad); color: var(--on-fault); }

/* ---------- Segmented controls ---------- */

.segmented { display: inline-flex; padding: 3px; gap: 2px; background: var(--inset); border: 1px solid var(--line); border-radius: var(--radius); }
.segmented button, .segmented label {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: calc(var(--control) - 8px); padding: 0 12px;
  border: 0; border-radius: var(--radius-sm); background: transparent;
  color: var(--ink-2); font-size: var(--fs-sm); font-weight: 600; white-space: nowrap; cursor: pointer;
}
.segmented button[aria-pressed="true"], .segmented label:has(input:checked) {
  background: var(--panel); color: var(--ink); box-shadow: var(--shadow-key);
}
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- Clients overview ---------- */

.page { width: min(1280px, 100%); margin: 0 auto; padding: 20px var(--gutter) 32px; display: grid; gap: 16px; align-content: start; }
.page-head { display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; }
.toolbar { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }

.table-wrap { container-type: inline-size; overflow: hidden; }
table.clients { width: 100%; border-collapse: collapse; }
.clients th { text-align: left; font-size: var(--fs-xs); font-weight: 600; color: var(--ink-2); padding: 0; background: var(--faceplate); border-bottom: 1px solid var(--line-strong); }
.clients th > button, .clients th:not([data-sort]) { padding: 10px 14px; }
.clients th > button { width: 100%; text-align: left; background: none; border: 0; font-weight: 600; color: inherit; }
.clients th[aria-sort] > button::after { content: ""; display: inline-block; margin-left: 6px; border: 4px solid transparent; vertical-align: middle; }
.clients th[aria-sort="ascending"] > button::after { border-bottom-color: currentColor; border-top-width: 0; }
.clients th[aria-sort="descending"] > button::after { border-top-color: currentColor; border-bottom-width: 0; }
.clients td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.clients tbody tr:last-child td { border-bottom: 0; }
.clients tbody tr { cursor: pointer; transition: background-color 100ms var(--ease); }
.clients tbody tr:hover, .clients tbody tr:focus-visible { background: var(--accent-soft); }
.clients tbody tr:focus-visible { outline-offset: -2px; }
.clients tr.is-selected { background: var(--accent-soft); }
.cell-state { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; white-space: nowrap; }
.cell-name { font-weight: 650; }
.cell-sub, .cell-mono { color: var(--ink-2); font-size: var(--fs-sm); }
.cell-mono { font-family: var(--font-mono); font-size: var(--fs-xs); overflow-wrap: anywhere; }
.chip { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: var(--fs-xs); font-weight: 600; background: var(--inset); color: var(--ink-2); }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.clients td .chip { margin-left: 8px; }

.empty { padding: 40px 20px; text-align: center; color: var(--ink-2); display: grid; gap: 10px; justify-items: center; }
.empty strong { color: var(--ink); font-size: var(--fs-lg); }
.empty code { font: 500 var(--fs-sm) var(--font-mono); background: var(--inset); padding: 8px 10px; border-radius: var(--radius-sm); overflow-wrap: anywhere; max-width: 100%; }

/* ---------- Console ---------- */

.view-console { overflow: hidden; }
.console {
  height: 100%;
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
  padding: 14px var(--gutter);
  padding-bottom: max(14px, env(safe-area-inset-bottom));
  width: min(1680px, 100%); margin: 0 auto;
}

.console-head { display: flex; align-items: center; gap: 12px 16px; flex-wrap: wrap; justify-content: space-between; }
.identity { display: flex; align-items: center; gap: 4px 12px; flex-wrap: wrap; min-width: 0; }
.identity h1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.state-pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; background: var(--inset); font-size: var(--fs-sm); font-weight: 600; }
.state-pill.state-online { background: var(--ok-soft); }
.state-pill.state-attention { background: var(--warn-soft); }
.recovery { display: flex; gap: 8px; padding-left: 16px; border-left: 1px solid var(--line-strong); }

.console-body { display: grid; gap: 12px; min-height: 0; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }

.readout { padding: 4px 14px; align-self: start; }
.readout-toggle { display: none; }
.readout-body { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0 20px; }
.readout-body > div { padding: 8px 0; min-width: 0; border-bottom: 1px solid var(--line); }
.readout-body dt { color: var(--ink-2); font-size: var(--fs-xs); font-weight: 600; }
.readout-body dd { font: 500 var(--fs-sm) / 1.35 var(--font-mono); overflow-wrap: anywhere; display: flex; align-items: center; gap: 6px; }
.readout-body dd.proportional { font-family: var(--font-ui); font-size: var(--fs-md); }

.screen-wrap {
  position: relative; min-height: 0;
  display: grid; grid-template-rows: auto minmax(0, 1fr);
  background: var(--screen);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: 0 2px 6px rgb(0 0 0 / 0.25) inset;
  overflow: hidden;
}
.screen-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 6px 4px 14px; background: var(--screen-bar); border-bottom: 1px solid var(--screen-line); color: var(--screen-dim); font-size: var(--fs-xs); }
.screen-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--font-mono); }
.screen-actions { display: flex; gap: 2px; }
.screen-btn { background: transparent; border-color: transparent; box-shadow: none; color: var(--screen-dim); min-height: 32px; width: 32px; }
.screen-btn:hover { color: var(--screen-ink); border-color: var(--screen-line); }
.screen-btn[aria-pressed="true"] { color: var(--screen-cmd); }

.screen {
  min-height: 0; overflow: auto; overscroll-behavior: contain;
  padding: 12px 16px 16px;
  color: var(--screen-ink);
  font: 400 0.84375rem / 1.5 var(--font-mono);
  white-space: pre; tab-size: 4;
}
.screen.wrap { white-space: pre-wrap; overflow-wrap: anywhere; }
.screen:focus-visible { outline-offset: -3px; }
.screen ::selection { background: var(--screen-cmd); color: #15171a; }

.line { min-height: 1.5em; }
.line.cmd { margin-top: 10px; color: var(--screen-cmd); font-weight: 600; }
.line.cmd:first-child { margin-top: 0; }
.line.cmd .prompt { color: var(--screen-dim); margin-right: 8px; user-select: none; }
.line.err { color: var(--screen-err); }
.line.note { color: var(--screen-dim); font-style: italic; }
.line.exit { color: var(--screen-dim); }
.line.exit .code { display: inline-block; padding: 0 8px; border-radius: 999px; font-weight: 600; background: rgb(134 214 168 / 0.14); color: var(--screen-ok); }
.line.exit.fail .code { background: rgb(255 157 146 / 0.16); color: var(--screen-bad); }
.screen-empty { color: var(--screen-dim); font-style: italic; }

.jump {
  position: absolute; right: 16px; bottom: 14px;
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 34px; padding: 0 12px;
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 999px;
  font-size: var(--fs-sm); font-weight: 600; box-shadow: var(--shadow-pop);
}

/* ---------- Composer ---------- */

.composer {
  display: grid; align-items: center; gap: 8px 10px;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  grid-template-areas: "mode field clear send" "note note note note";
}
.composer .mode { grid-area: mode; }
.command-field {
  grid-area: field;
  display: flex; align-items: center; gap: 10px;
  min-height: var(--control); padding: 0 12px;
  background: var(--field); border: 1px solid var(--line-strong); border-radius: var(--radius);
}
.command-field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.command-field .prompt { color: var(--accent); font: 700 var(--fs-md) var(--font-mono); user-select: none; }
.command-field input { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; font: 500 var(--fs-md) var(--font-mono); color: var(--ink); }
.command-field input::placeholder { color: var(--ink-3); opacity: 1; font-family: var(--font-ui); }
.composer .clear { grid-area: clear; }
.composer .send { grid-area: send; }
.composer-note { grid-area: note; min-height: 1.2em; font-size: var(--fs-sm); color: var(--ink-2); }
.composer-note.error { color: var(--bad); }

/* ---------- Responsive structure ---------- */

/* Wide: the health readout becomes a fixed column beside the display window. */
@media (min-width: 1200px) {
  .console-body { grid-template-columns: minmax(0, 1fr) 300px; grid-template-rows: minmax(0, 1fr); }
  .readout { order: 2; align-self: stretch; padding: 8px 16px; overflow: auto; }
  .readout-body { grid-template-columns: 1fr; }
  .readout-body > div:last-child { border-bottom: 0; }
}

/* Medium and below: the clients table drops to stacked rows, the faceplate tightens. */
@media (max-width: 900px) {
  .brand-name { display: none; }
  .recovery { padding-left: 0; border-left: 0; }
}

/* Narrow: one column, readout collapsed behind a summary, controls sized for thumbs, composer docked. */
@media (max-width: 720px) {
  :root { --gutter: 12px; }
  .tool-text { display: none; }
  .link span { display: none; }
  .link[data-state="connected"] { display: none; }
  .bar { gap: 8px; }
  .switcher-btn { max-width: 100%; }
  .switcher { max-width: 100%; }
  .popover { position: fixed; top: 60px; left: 8px; right: 8px; width: auto; }

  .console { gap: 10px; padding-top: 10px; }
  .console-head { gap: 8px; }
  .recovery { width: 100%; }
  .recovery .btn { flex: 1; }

  .readout { padding: 0 12px; }
  .readout-toggle {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    width: 100%; min-height: var(--control); padding: 0;
    background: none; border: 0; font-size: var(--fs-sm); font-weight: 600; color: var(--ink);
  }
  .readout-toggle .icon { transition: transform 150ms var(--ease); }
  .readout-toggle[aria-expanded="true"] .icon { transform: rotate(180deg); }
  .readout-body { display: none; }
  .readout-toggle[aria-expanded="true"] + .readout-body { display: grid; }

  .composer { grid-template-columns: minmax(0, 1fr) auto auto; grid-template-areas: "field clear send" "mode mode mode" "note note note"; }
  .composer .mode { justify-self: start; }
  .composer-note:empty { display: none; }
}

/* Short windows (landscape phones): give the output the height. */
@media (max-height: 520px) {
  .console { gap: 8px; padding-block: 8px; }
  .console-head h1 { font-size: var(--fs-lg); }
  .readout { display: none; }
  .composer-note { display: none; }
}

/* Clients table as stacked rows when its own container is narrow. */
@container (max-width: 760px) {
  table.clients, .clients tbody, .clients tr, .clients td { display: block; }
  .clients thead { display: none; }
  .clients tbody tr { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
  .clients tbody tr:last-child { border-bottom: 0; }
  .clients td { padding: 0; border: 0; }
  .clients td[data-col="state"] { grid-column: 2; grid-row: 1; justify-self: end; }
  .clients td[data-col="name"] { grid-column: 1; grid-row: 1; }
  .clients td[data-col="os"], .clients td[data-col="user"] { grid-column: 1; color: var(--ink-2); font-size: var(--fs-sm); }
  .clients td[data-col="activity"] { grid-column: 1; font-size: var(--fs-sm); }
  .clients td[data-col="seen"] { grid-column: 2; grid-row: 2; justify-self: end; color: var(--ink-2); font-size: var(--fs-sm); }
  .clients td[data-col="id"] { grid-column: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
