/* =============================================================================
 * Linkr Bee · skin v2
 *
 * A presentation layer only: tokens, shell layout, chrome and the terminal
 * footer. No behavior lives here and none of the DOM hooks app.js binds to are
 * renamed. Loaded after style.css + window.css so it can retune the older
 * visual rules without touching them.
 *
 * Material rule: glass is for chrome (topbar, rail, drawer, key strip, chips).
 * The terminal canvas stays near-solid, because equal-width log text loses
 * contrast the moment it sits on a translucent surface.
 * ========================================================================== */

:root {
  color-scheme: dark;

  --bg: #05080d;
  --bg-glow-1: rgba(63, 200, 138, 0.16);
  --bg-glow-2: rgba(96, 128, 228, 0.16);
  --bg-glow-3: rgba(240, 168, 104, 0.07);

  --panel: rgba(17, 24, 34, 0.72);
  --panel-2: rgba(24, 33, 46, 0.62);
  /* Sticky drawer chrome must hide the content scrolling behind it, so it
   * cannot reuse the translucent glass token. */
  --sticky-surface: #18212e;
  --panel-3: rgba(255, 255, 255, 0.07);
  --glass: rgba(255, 255, 255, 0.045);
  --glass-2: rgba(255, 255, 255, 0.075);
  --glass-3: rgba(255, 255, 255, 0.12);
  --glass-line: rgba(255, 255, 255, 0.09);
  --glass-blur: blur(26px) saturate(150%);

  --text: #e8eef6;
  --muted: #9aa7b8;
  --line: rgba(255, 255, 255, 0.09);
  --line-soft: rgba(255, 255, 255, 0.055);
  --line-strong: rgba(255, 255, 255, 0.17);
  --placeholder: #7c8a9e;

  /* The accent in the form the tinted borders, glows and hover washes below
   * need: the same green, so `<token> / 0.12` follows the theme instead of
   * keeping the other theme's green the way a literal rgba() did. */
  --accent-rgb: 63 200 138;
  --accent: rgb(var(--accent-rgb));
  --accent-strong: #5fe0a6;
  --accent-ink: #04160e;
  --primary-grad: linear-gradient(180deg, #4fda9d, #33b87d);
  --focus: #6aa6f5;
  --danger: #ef6a68;

  --rx: #6aa6f5;
  --tx: #f0a868;
  --warn: #f0b45e;

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;

  --terminal: #05080d;
  --input-bg: rgba(0, 0, 0, 0.22);
  --btn-hover: rgba(255, 255, 255, 0.09);

  --shadow:
    0 40px 90px -46px rgba(0, 0, 0, 0.95),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  --shadow-flat:
    0 24px 50px -38px rgba(0, 0, 0, 0.9),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

[data-theme="light"] {
  color-scheme: light;

  --bg: #e2e9f4;
  --bg-glow-1: rgba(47, 158, 99, 0.13);
  --bg-glow-2: rgba(59, 130, 246, 0.09);
  --bg-glow-3: rgba(226, 148, 78, 0.06);

  --panel: rgba(255, 255, 255, 0.88);
  --panel-2: rgba(255, 255, 255, 0.72);
  --sticky-surface: #ffffff;
  --panel-3: rgba(15, 32, 56, 0.055);
  --glass: rgba(255, 255, 255, 0.55);
  --glass-2: rgba(15, 32, 56, 0.05);
  --glass-3: rgba(15, 32, 56, 0.08);
  --glass-line: rgba(15, 32, 56, 0.1);

  --text: #0f1c2e;
  --muted: #5c6a82;
  --line: rgba(15, 32, 56, 0.16);
  --line-soft: rgba(15, 32, 56, 0.1);
  --line-strong: rgba(15, 32, 56, 0.2);
  --placeholder: #5e6e84;

  --accent-rgb: 31 157 100;
  --accent: rgb(var(--accent-rgb));
  --accent-strong: #157a4c;
  --accent-ink: #ffffff;
  --primary-grad: linear-gradient(180deg, #2fb377, #1f9d64);
  --focus: #3b82f6;
  --danger: #d93a3a;
  --rx: #2f6fd0;
  --tx: #b8671f;

  --terminal: #f8fafd;
  --input-bg: rgba(15, 32, 56, 0.045);
  --btn-hover: rgba(15, 32, 56, 0.07);

  --shadow:
    0 30px 70px -44px rgba(15, 35, 70, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.7);
  --shadow-flat:
    0 20px 44px -36px rgba(15, 35, 70, 0.24),
    inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

body {
  background:
    radial-gradient(760px 420px at 8% -6%, var(--bg-glow-1), transparent 62%),
    radial-gradient(820px 520px at 102% 4%, var(--bg-glow-2), transparent 58%),
    radial-gradient(700px 460px at 46% 108%, var(--bg-glow-3), transparent 62%),
    var(--bg);
}

/* A single focus ring for every control. The UA default draws a square halo
 * around rounded buttons, which reads as a bug next to this much radius. */
:where(button, a, input, select, textarea):focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ---------- Shell: icon rail · drawer · workspace ---------- */

.app-shell {
  gap: 10px;
}

.rail {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-height: 0;
  padding: 10px 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--panel);
  box-shadow: var(--shadow-flat);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
}

.rail-btn {
  position: relative;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease,
    border-color 0.15s ease;
}

.rail-btn svg {
  width: 17px;
  height: 17px;
}

.rail-btn:hover {
  background: var(--glass);
  color: var(--text);
}

.rail-btn.active {
  border-color: rgb(var(--accent-rgb) / 0.22);
  background: rgb(var(--accent-rgb) / 0.12);
  color: var(--accent-strong);
}

.rail-btn.active::before {
  content: "";
  position: absolute;
  left: -6px;
  top: 13px;
  width: 2px;
  height: 14px;
  border-radius: 2px;
  background: var(--accent);
  box-shadow: 0 0 8px rgb(var(--accent-rgb) / 0.6);
}

.rail-btn:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.rail-spacer {
  flex: 1 1 auto;
}

/* The assistant entry only exists once the agent settings page is enabled.
 * rail_nav.js mirrors the real tab's [hidden] attribute onto .is-available,
 * so the rail never advertises a section the page does not have. */
.rail-btn[data-rail-target="ai"] {
  display: none;
}

.rail-btn[data-rail-target="ai"].is-available {
  display: grid;
}

/* The rail layout is for pointer devices. `settings-drawer-layout` is chosen by
 * the input device, not the window width — every coarse-pointer host (all
 * phones and tablets, and HarmonyOS) uses the overlay drawer at any width — so
 * gating on width alone put a flex rail into a one-column grid: it stretched to
 * the full width and covered the page, intercepting every tap. A 1194x834 iPad
 * in landscape is exactly that case. */
@media (min-width: 1101px) {
  html:not(.settings-drawer-layout) .app-shell {
    --sidebar-width: clamp(312px, 23vw, 400px);
    grid-template-columns: 56px minmax(0, var(--sidebar-width)) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
  }

  html:not(.settings-drawer-layout) .rail {
    display: flex;
    grid-column: 1;
    grid-row: 2;
  }

  html:not(.settings-drawer-layout) .controls {
    grid-column: 2;
    grid-row: 2;
    padding-right: 0;
  }

  html:not(.settings-drawer-layout) .workpanel {
    grid-column: 3;
    grid-row: 2;
  }

  html:not(.settings-drawer-layout) .app-shell.controls-hidden {
    grid-template-columns: 56px 0 minmax(0, 1fr);
  }
}

/* ---------- Topbar ---------- */

.topbar {
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--panel);
  box-shadow: var(--shadow-flat);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
}

.brand {
  gap: 10px;
}

/* The hexagon is the mark now, so the tinted tile behind it is gone: a box
 * around an outlined hexagon read as two nested frames. */
.logo {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 0;
  color: var(--accent);
  background: none;
  box-shadow: none;
}

.logo svg {
  width: 32px;
  height: 32px;
}

h1 {
  font-size: 14px;
  font-weight: 500;
  letter-spacing: -0.01em;
}

.support-text {
  margin-top: 2px;
  font-size: 11px;
  color: var(--placeholder);
}

/* Phone-only brand identity line; hidden until the <=600 rule re-enables it. */
.compact-device {
  display: none;
}

[data-theme="dark"] h1 {
  color: var(--text);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 30px;
  min-width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  transition: background 0.15s ease, color 0.15s ease,
    border-color 0.15s ease;
}

.icon-btn:hover:not(:disabled) {
  border-color: var(--line);
  background: var(--glass-2);
  color: var(--text);
}

#themeButton .btn-label {
  display: none;
}

#themeButton,
#langButton {
  width: 30px;
  padding: 0;
  justify-content: center;
}

#langButton .btn-label {
  font-size: 12px;
  color: var(--muted);
}

.status-pill {
  gap: 8px;
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--glass);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.status-pill:has(.status-dot.connected) {
  border-color: rgb(var(--accent-rgb) / 0.3);
  background: rgb(var(--accent-rgb) / 0.1);
  color: var(--text);
}

.status-dot {
  width: 6px;
  height: 6px;
  background: var(--danger);
}

.status-dot.connected {
  background: var(--accent);
  box-shadow: 0 0 0 3px rgb(var(--accent-rgb) / 0.14);
}

.status-dot.connected::after {
  inset: -2px;
  border-width: 1px;
  border-color: rgb(var(--accent-rgb) / 0.5);
  animation-duration: 2.4s;
}

.device-name {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
  padding-left: 8px;
  border-left: 1px solid var(--line);
}

.device-name:empty {
  display: none;
}

@media (min-width: 901px) {
  /* Keep the header one row on every engine. Once the actions wrap, the
   * topbar grows and pushes the whole terminal down; Segoe UI on Windows and
   * the Linux system font measure the same labels differently, so the old
   * wrapping rule made the two platforms open at different heights. */
  .topbar {
    flex-wrap: nowrap;
  }

  .top-right {
    display: contents;
  }

  .brand {
    flex: 0 1 auto;
    min-width: 0;
  }

  .brand h1,
  .brand .support-text {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .status-pill {
    order: 1;
    flex: 0 1 auto;
    min-width: 0;
    margin-left: 4px;
  }

  .status-pill #statusText,
  .status-pill .device-name {
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .top-actions {
    order: 2;
    flex: 0 0 auto;
    flex-wrap: nowrap;
    margin-left: auto;
    gap: 4px;
  }

  .top-actions .mobile-connect {
    margin-right: 4px;
  }
}

/* ---------- Drawer ---------- */

.controls.window-surface {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--panel);
  box-shadow: var(--shadow-flat);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  /* Reserve the lane whether or not this drawer scrolls right now, so the text
   * measure does not shift between pages. */
  scrollbar-gutter: stable;
}

/* Firefox before 103 and browsers that disable compositing render the glass
 * tokens as almost transparent panels. Keep the layout, make the chrome
 * readable instead of falling back to the page background. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .topbar,
  .rail,
  .controls.window-surface {
    background: var(--bg);
  }

  .status-pill {
    background: var(--panel-2);
  }
}

.controls .card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.032);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  /* The section header is a full-bleed band now; the card owns its corners. */
  overflow: hidden;
}

[data-theme="light"] .controls .card {
  border-color: rgba(15, 32, 56, 0.1);
  background: rgba(15, 32, 56, 0.032);
}

.controls .card:hover {
  border-color: var(--line);
}

/* A section title is the pane title's own type, not a caption: the terminal
 * header beside the drawer sets 13 px/600 with no tracking, and the drawer used
 * to set a 10.5 px letter-spaced label, so the two panes disagreed about what a
 * section heading is. */
.card-title {
  margin-bottom: 12px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0;
  color: var(--text);
}

/* Card headers take the shape .terminal-head already has — a chrome band with
 * the title on it — at card scale: full bleed inside the card, the accent dot,
 * and a hairline under it. The negative margins cancel .card's 16 px padding;
 * the card clips the band with its own radius. */
/* Follow the card's own padding: the phone layout uses 13 px, so the
 * hard-coded -16px band stuck 3 px out of the rounded card and clipped. */
.controls .card > .card-title {
  margin: calc(-1 * var(--card-pad, 16px)) calc(-1 * var(--card-pad, 16px)) 14px;
  padding: 11px var(--card-pad, 16px);
  min-height: 44px;
  align-items: center;
  border-bottom: 1px solid var(--line-soft);
  background: var(--panel-2);
}

/* The collapsible section is its header plus whatever it reveals, so its
 * summary is the band and the hairline only appears once there is something
 * under it. */
.controls .diagnostics-summary {
  /* Same horizontal edge as the body below it: the phone layout shrinks
   * --card-pad to 13px, and a hardcoded 16px here offset the title by 3px. */
  padding: 11px var(--card-pad, 16px);
  min-height: 44px;
  background: var(--panel-2);
}

.controls .diagnostics-summary .card-title {
  margin-bottom: 0;
}

/* The band is this card's full-bleed header and carries the card padding, so the
 * body lines up with it: same horizontal edge, plus the 14px rhythm under the
 * hairline. Without the top padding the first tile row sat flush against the
 * band while every other card shows 14px there, and the old 14px side padding
 * put the tiles 2px left of the title. */
.controls .diagnostics-content {
  padding: 14px var(--card-pad, 16px) var(--card-pad, 16px);
}

.controls .diagnostics-card[open] > .diagnostics-summary {
  border-bottom: 1px solid var(--line-soft);
}

/* Two action groups share this card. Without the gap the WebDAV heading sat
 * flush against the WiFi buttons above it (0px, where every other group starts
 * 14px down), so it read as a label for those buttons. */
#webdavBlock {
  margin-top: 14px;
}

/* Field labels are labels, not body copy: 12.5 px/400 read as prose next to
 * the 600-weight controls they describe. */
.controls .field-label {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--muted);
}

/* A segmented control is chrome, not a label: the 0.25 px tracking the old
 * sheet added is the only place the shell tracked a control label. */
.controls .ts-btn {
  letter-spacing: 0;
}

/* A diagnostic value is a value: the same mono face the device name and the
 * terminal counters use, so numbers line up and read as machine output. */
.controls .diagnostic-item > span:first-child {
  font-size: 11.5px;
  color: var(--muted);
}

.controls .diagnostic-item strong {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
}

.card-title .dot {
  width: 6px;
  height: 6px;
}

/* AI settings: board-stored configuration mirrors the target-binding section
 * next to it: a divider, a small heading, then a quiet action row. */
/* The AI page is a stack of cards, not one long card. Keep this on the class,
 * not the id: the rail's page filter hides [data-settings-page] with a
 * class-level selector, and an id rule would override it and spill every AI
 * card under every section. */
.agent-settings {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

/* The AI page owns its scroll: the footer stays put while the cards scroll, so
 * it can never cover the last field or drift below the drawer. */
.controls[data-settings-active="ai"] {
  overflow: hidden;
}

#agentSettingsForm {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

.agent-settings-scroll {
  display: grid;
  gap: 10px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior-y: auto;
  /* Cards size to their content; without this, a definite grid height makes
   * the overflowing cards shrink to their min-content and clip. */
  align-content: start;
  align-items: start;
  grid-auto-rows: max-content;
  padding-right: 2px;
  padding-bottom: 4px;
}

.agent-settings .field {
  margin-bottom: 12px;
}

.agent-settings .field-hint {
  margin-top: 4px;
  font-size: 12px;
  line-height: 1.45;
}

.agent-settings .field-label {
  font-size: 12px;
  color: var(--muted);
}

.agent-settings .key-note {
  margin: 0 0 12px;
}

/* Tertiary disclosures inside the model card keep verbose settings out of the
 * default view without spending a whole card on a toggle. */
.agent-inline-disclosure {
  margin-top: 4px;
  border-top: 1px solid var(--line);
}

.agent-inline-disclosure > summary {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 11px 2px;
  box-sizing: border-box;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  list-style: none;
  cursor: pointer;
}

.agent-inline-disclosure > summary::-webkit-details-marker {
  display: none;
}

.agent-inline-disclosure > summary::after {
  content: "";
  width: 6px;
  height: 6px;
  margin-left: auto;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.18s ease;
}

.agent-inline-disclosure[open] > summary {
  color: var(--text);
}

.agent-inline-disclosure[open] > summary::after {
  transform: rotate(-135deg);
}

.agent-inline-disclosure > summary:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.agent-inline-disclosure .agent-advanced-fields {
  padding-bottom: 4px;
}

.agent-model-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: -2px 0 12px;
}

.agent-model-actions .btn {
  flex: 0 0 auto;
}

.agent-model-actions .field-hint {
  flex: 1 1 auto;
  margin: 0;
}

@media (prefers-reduced-motion: reduce) {
  .agent-inline-disclosure > summary::after {
    transition: none;
  }
}

.agent-settings[hidden],
#agentSettings[hidden] {
  display: none !important;
}

#agentSettingsFields {
  display: grid;
  gap: 10px;
}

/* Auto-save makes the old save card redundant: a slim footer keeps the status
 * and a fallback action within thumb reach without covering the fields. */
.agent-config-footer {
  flex: 0 0 auto;
  display: grid;
  gap: 8px;
  padding: 10px 2px 2px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.agent-config-footer .field-hint {
  margin: 0;
  font-size: 11.5px;
}

.agent-config-footer-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.agent-config-footer-actions .btn {
  min-height: 36px;
  padding: 4px 12px;
  font-size: 12px;
}

/* The board configuration and binding blocks became cards, so their old
 * section dividers are gone. */
.agent-board-config {
  display: grid;
  gap: 10px;
}

.agent-board-config[hidden] {
  display: none !important;
}

#agentBindingCard .target-binding {
  margin: 0;
  padding: 0;
  border-top: 0;
}

/* A card that is itself a <details>: the summary is its header band and the
 * browser's disclosure triangle is replaced by a quiet chevron. */
details.card > summary.card-title {
  cursor: pointer;
  list-style: none;
}

details.card > summary.card-title::-webkit-details-marker {
  display: none;
}

details.card > summary.card-title::after {
  content: "";
  width: 7px;
  height: 7px;
  margin-left: auto;
  /* Match the section-card toggle: its 24px hit box is centred on the glyph,
   * so the glyph's right edge is 8.5px inside the summary's content edge. The
   * summary's own horizontal padding is outside this box. */
  margin-right: 8.5px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  /* Closed points right; open points down. The section-card toggle below
   * draws the same 7px chevron so every card header reads identically. */
  transform: rotate(-45deg);
  transition: transform 0.18s ease;
}

details.card[open] > summary.card-title::after {
  transform: rotate(45deg);
}

/* A closed card is just its header band, not a band plus empty padding. */
details.card:not([open]) {
  padding-bottom: 0;
}

details.card:not([open]) > summary.card-title {
  margin-bottom: 0;
}

@media (prefers-reduced-motion: reduce) {
  details.card > summary.card-title::after {
    transition: none;
  }
}

.agent-board-config h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.agent-board-config .field-hint {
  margin: 0;
}

.agent-board-config .field-hint.is-error {
  color: var(--danger);
}

.agent-board-config .check {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.agent-board-config .btn-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

@media (max-width: 600px) {
  .agent-board-config .btn-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .agent-board-config .btn {
    padding-inline: 6px;
    font-size: 12px;
  }
}

/* A phone held sideways with the keyboard open leaves very little height; the
 * footer drops its status line so the fields above keep a usable scroll area. */
@media (max-height: 520px) {
  .agent-config-footer .field-hint {
    display: none;
  }

  .agent-config-footer {
    padding-block: 4px;
  }
}

/* Collapsible cards: the header band keeps its shape and gains a quiet
 * chevron; the content disappears without re-flowing the pages above. */
.card-toggle {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  margin-left: auto;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.card-toggle:hover {
  background: var(--btn-hover);
  color: var(--text);
}

.card-toggle::before {
  content: "";
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  transition: transform 0.18s ease;
}

.card.is-collapsed {
  overflow: hidden;
  padding-bottom: 0;
}

.card.is-collapsed > .card-title {
  margin-bottom: 0;
}

.card.is-collapsed > :not(.card-title) {
  display: none !important;
}

.card.is-collapsible > .card-title {
  cursor: pointer;
}

.card.is-collapsed .card-toggle::before {
  transform: rotate(-45deg);
}

@media (prefers-reduced-motion: reduce) {
  .card-toggle::before {
    transition: none;
  }
}

.settings-tabs {
  /* One labelled row, never a wrapped stack. The drawer/tablet panel can be
   * narrower than six full labels, so the strip scrolls horizontally instead
   * of turning AI into a lonely second row; AI stays in the visible head of
   * the strip and About is one swipe further. */
  display: grid;
  grid-template-columns: none;
  grid-auto-flow: column;
  grid-auto-columns: minmax(56px, 1fr);
  gap: 4px;
  flex: 0 0 auto;
  padding: 3px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--line-soft) transparent;
  scroll-snap-type: x proximity;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  background: var(--input-bg);
}

@media (min-width: 1101px) {
  /* The rail and the tab row are the same menu. Once the rail is laid out,
   * the tab row would duplicate it and read as a second title bar, so hide it;
   * rail_nav.js still forwards rail clicks to the real tabs. Below 1101px the
   * rail is absent and the one-row tab strip is the section switcher. */
  html:not(.settings-drawer-layout) .settings-tabs {
    display: none !important;
  }

  /* One section at a time: the rail and the tabs drive the same page state. */
  .controls[data-settings-active="connection"] [data-settings-page]:not([data-settings-page="connection"]),
  .controls[data-settings-active="terminal"] [data-settings-page]:not([data-settings-page="terminal"]),
  .controls[data-settings-active="network"] [data-settings-page]:not([data-settings-page="network"]),
  .controls[data-settings-active="ai"] [data-settings-page]:not([data-settings-page="ai"]) {
    display: none;
  }
}

/* Hiding a section is a capability decision: the tab and its rail button must
 * disappear even though their layout rules set display. */
/* A [hidden] section must win over the layout rules that give cards and
 * subsections `display: grid`. */
.card[hidden],
.board-card[hidden],
.board-subsection[hidden],
.board-empty[hidden],
.settings-tab[hidden],
.rail-btn[hidden] {
  display: none !important;
}

.settings-tab {
  min-width: 0;
  min-height: 36px;
  padding: 5px 4px;
  border-radius: 7px;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
  scroll-snap-align: start;
}

/* Phone: one row so AI never drops into a second "stack"; all six fit at
 * 390px and the last one stays reachable by swiping on very narrow phones. */
html.settings-drawer-layout .settings-tabs,
.controls.has-agent-settings .settings-tabs {
  grid-template-columns: none;
  grid-auto-flow: column;
  grid-auto-columns: minmax(56px, 1fr);
  overflow-x: auto;
}

@media (max-width: 1100px) {
  .settings-tabs {
    grid-template-columns: none;
    grid-auto-columns: minmax(56px, 1fr);
    overflow-x: auto;
  }
}

/* Tablet / narrow desktop: the panel is wide enough for two tidy labelled
 * rows, so all six sections stay visible without a swipe. */
@media (min-width: 601px) and (max-width: 1100px) {
  html.settings-drawer-layout .settings-tabs,
  .controls.has-agent-settings .settings-tabs,
  .settings-tabs {
    grid-template-columns: repeat(auto-fit, minmax(84px, 1fr));
    grid-auto-flow: row;
    grid-auto-columns: auto;
    overflow: visible;
  }
}

/* Phone: six equal tracks, no horizontal clipping and no second row. At the
 * 360px device viewport the panel gives ~344px, which is enough for 6 x 53px;
 * the active AI tab can never scroll the first tab out of view. */
@media (max-width: 600px) {
  html.settings-drawer-layout .settings-tabs,
  .controls.has-agent-settings .settings-tabs,
  .settings-tabs {
    grid-auto-columns: minmax(0, 1fr);
    overflow-x: hidden;
  }

  .settings-tabs .settings-tab {
    padding-inline: 2px;
  }
}

@media (max-width: 340px) {
  .settings-tabs .settings-tab {
    padding-inline: 1px;
    font-size: 10.5px;
  }
}

@media (pointer: coarse), (max-width: 900px) {
  .settings-tabs .settings-tab {
    min-height: 44px;
  }
}

.settings-tab.active {
  border: 0;
  background: var(--glass-2);
  color: var(--text);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.07);
}

/* A two-column action grid at 300px leaves ~130px per button; labels with a
 * space ("Query UART") used to break onto a second line there. */
.controls .btn-grid .btn {
  white-space: nowrap;
}

.controls .btn-grid .btn svg {
  flex: 0 0 auto;
}

/* ---------- Terminal ---------- */

.terminal-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--terminal);
  box-shadow: var(--shadow);
}

.terminal-head {
  min-height: 40px;
  padding: 7px 10px 7px 14px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(255, 255, 255, 0.026);
}

[data-theme="light"] .terminal-head {
  background: rgba(15, 32, 56, 0.025);
}

.term-title {
  gap: 7px;
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  color: var(--muted);
}

.term-led {
  width: 6px;
  height: 6px;
}

.term-tools {
  min-width: 0;
  gap: 6px 8px;
  flex-wrap: wrap;
}

.serial-control-group,
.terminal-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}
.serial-control-group { margin-inline-end: auto; }
.terminal-actions { margin-inline-start: auto; gap: 3px; }
.terminal-head .term-tools .serial-control-button { flex: 0 0 auto; width: auto; min-width: max-content; padding-inline: 8px; }

.serial-control-status {
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.term-tools .serial-control-button {
  width: auto;
  font-family: var(--font-sans, system-ui, sans-serif);
  white-space: nowrap;
  color: var(--text);
  border-color: var(--line);
}

@media (max-width: 600px) {
  .terminal-head:has(#serialControlButton:not([hidden])) .term-title { display: none; }
  .terminal-head:has(#serialControlButton:not([hidden])) .term-tools { width: 100%; }
  .terminal-head:has(#serialControlButton:not([hidden])) :is(#zoomOutBtn, #zoomInBtn) { display: none; }
  .term-tools .serial-control-status { margin-inline-end: auto; }
  .term-tools .serial-control-status { font-size: 11px; }
  .term-tools .serial-control-button { padding-inline: 7px; }
}

.term-tool {
  min-width: 28px;
  height: 28px;
  padding: 0 7px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--placeholder);
  font-family: var(--font-mono);
  font-size: 11px;
}

.term-tool:hover:not(:disabled) {
  border-color: var(--line);
  background: var(--glass-2);
  color: var(--text);
}

.term-hint {
  padding-left: 6px;
  font-size: 10px;
  color: var(--placeholder);
  opacity: 0.7;
}

@media (min-width: 901px) {
  .terminal-output .xterm {
    padding: 12px;
  }
}

/* Single-row accessory strip. Everything scrolls except Ctrl-C, which stays
 * pinned at the thumb edge because it is the one key pressed blind. */
.terminal-card .terminal-input-bar {
  gap: 10px;
  padding: 8px 10px 9px;
  border-top: 1px solid var(--line-soft);
  background: rgba(255, 255, 255, 0.024);
}

[data-theme="light"] .terminal-card .terminal-input-bar {
  background: rgba(15, 32, 56, 0.022);
}

.terminal-input-hint {
  padding: 0 2px;
  font-size: 10.5px;
  line-height: 1.5;
  color: var(--placeholder);
}

.terminal-output.connected + .terminal-input-bar .terminal-input-hint {
  color: var(--muted);
}

.terminal-card .terminal-input-actions {
  gap: 7px;
  align-items: center;
}

/* Desktop holds 34 keys in one scrollable strip; touch uses the wrapped
 * favourite grid in mobile-ui.css. Reserve the track so nothing shifts. */
.terminal-key-scroll {
  flex: 1 1 auto;
  min-width: 0;
  align-items: center;
  gap: 6px;
  padding: 2px 8px 5px 0;
  overflow-x: auto;
  scrollbar-width: thin;
  /* Keep a hairline scrollbar visible; the thumb strengthens on pointer hover.
   * Touch no longer relies on a half-visible key as its scroll cue. */
  border-right: 1px solid var(--line-soft);
}

.terminal-key-scroll::-webkit-scrollbar {
  display: block;
  height: 4px;
}

.terminal-key-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.terminal-key-scroll::-webkit-scrollbar-thumb {
  border-radius: 4px;
  background: transparent;
}

@media (hover: hover) and (pointer: fine) {
  .terminal-key-scroll:hover,
  .terminal-key-scroll:focus-within {
    scrollbar-color: var(--line-strong) transparent;
  }

  .terminal-key-scroll:hover::-webkit-scrollbar-thumb,
  .terminal-key-scroll:focus-within::-webkit-scrollbar-thumb {
    background: var(--line-strong);
  }
}

@media (min-width: 901px) {
  /* Every key is already in the strip on desktop, so the mobile "more" and
   * favourite-editor affordances would be no-ops. */
  #terminalKeysToggle,
  #terminalKeysCustomize {
    display: none !important;
  }
}

/* One row, always. The old layout stacked each group into a 3x2 grid; here the
 * groups become clusters on a single scrollable track. */
.terminal-key-group {
  display: flex;
  grid-template-columns: none;
  grid-template-rows: none;
  gap: 6px;
  padding: 0;
}

.terminal-card .terminal-key,
.terminal-card .terminal-keyboard {
  width: auto;
  min-width: 34px;
  height: 30px;
  min-height: 30px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--glass-2);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.07);
  color: #c3cfdf;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 400;
}

[data-theme="light"] .terminal-card .terminal-key {
  border-color: rgba(15, 32, 56, 0.13);
  background: rgba(15, 32, 56, 0.045);
  color: #33445c;
}

.terminal-card .terminal-key:hover:not(:disabled) {
  border-color: var(--line-strong);
  background: var(--glass-3);
  color: var(--text);
}

.terminal-card .terminal-key[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}

.terminal-card .terminal-key:disabled {
  opacity: 0.42;
}

/* The one key pressed without looking: pinned outside the scroll track. */
#breakButton {
  flex: 0 0 auto;
  min-width: 62px;
  height: 30px;
  min-height: 30px;
  border-color: transparent;
  background: var(--tx);
  box-shadow:
    0 8px 18px -12px var(--tx),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
  color: #241505;
  font-weight: 500;
}

#breakButton:hover:not(:disabled) {
  border-color: transparent;
  filter: brightness(1.08);
  color: #241505;
}

#breakButton:disabled {
  border-color: var(--line);
  background: var(--glass-2);
  box-shadow: none;
  color: var(--muted);
}

/* ---------- Quick commands + status ---------- */

/* Quick commands belong to the terminal, not to the page background: they sit
 * between the canvas and the key strip and share its hairlines. */
.terminal-card .presets {
  flex: 0 1 auto;
  min-width: 0;
  flex-wrap: nowrap;
  gap: 6px;
  padding: 8px 10px 3px;
  overflow-x: auto;
  border-top: 1px solid var(--line-soft);
  scrollbar-width: none;
}

.terminal-card .presets::-webkit-scrollbar {
  display: none;
}

.terminal-card .presets + .terminal-input-bar {
  padding-top: 3px;
  border-top: 0;
}

.preset-chip {
  flex: 0 0 auto;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--glass);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 400;
}

.preset-chip:disabled {
  opacity: 0.55;
}

.preset-chip:hover:not(:disabled) {
  border-color: rgb(var(--accent-rgb) / 0.4);
  background: rgb(var(--accent-rgb) / 0.08);
  color: var(--text);
  transform: none;
}

.preset-chip[data-danger="true"]:not(:disabled) {
  color: rgba(239, 106, 104, 0.8);
}

.statusbar {
  gap: 14px;
  padding: 0 6px 2px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--muted);
}

.statusbar .sb-item b {
  font-weight: 500;
  color: var(--muted);
}

#rxCount {
  color: var(--rx);
}

#txCount {
  color: var(--tx);
}

.statusbar .sb-state {
  margin-left: auto;
  color: var(--muted);
}

/* ---------- Boot failure notice ---------- */

/* This strip only appears when a vendor script failed to load, which is exactly
 * when the page must not look decorative. Amber, compact, left aligned. */
.terminal-card .boot-notice {
  justify-content: flex-start;
  gap: 10px;
  padding: 8px 12px;
  border-top: 1px solid rgba(240, 180, 94, 0.26);
  border-bottom: 1px solid rgba(240, 180, 94, 0.16);
  background: rgba(240, 180, 94, 0.08);
  color: var(--warn);
  font-size: 11.5px;
  line-height: 1.5;
  text-align: left;
}

.terminal-card .boot-notice .btn {
  min-height: 26px;
  padding: 0 10px;
  border-color: rgba(240, 180, 94, 0.34);
  background: rgba(240, 180, 94, 0.13);
  color: var(--warn);
  font-size: 11px;
}

.terminal-card .boot-notice .btn:hover:not(:disabled) {
  border-color: rgba(240, 180, 94, 0.55);
  background: rgba(240, 180, 94, 0.2);
  color: var(--warn);
}

[data-theme="light"] .terminal-card .boot-notice {
  border-color: rgba(138, 90, 18, 0.22);
  background: rgba(240, 180, 94, 0.16);
  color: #7a5210;
}

[data-theme="light"] .terminal-card .boot-notice .btn {
  border-color: rgba(138, 90, 18, 0.3);
  background: rgba(255, 255, 255, 0.7);
  color: #7a5210;
}

/* 901–1100px: keep the panel on the left. v1 docked it on the right here, which
 * made the panel jump across the window at the 1101px breakpoint. */
@media (min-width: 901px) and (max-width: 1100px) {
  .app-shell {
    grid-template-columns: minmax(300px, 34vw) minmax(0, 1fr);
  }

  .app-shell.controls-hidden {
    grid-template-columns: 0 minmax(0, 1fr);
  }

  .controls {
    grid-column: 1;
    grid-row: 2;
  }

  .workpanel {
    grid-column: 2;
    grid-row: 2;
  }

  /* The panel already carries the primary action; don't duplicate it. */
  .app-shell:not(.controls-hidden) .top-actions .mobile-connect {
    display: none;
  }
}

/* ---------- Touch / narrow windows keep their existing drawer ---------- */

@media (max-width: 900px) {
  .topbar {
    gap: 8px;
    padding: 8px 10px;
  }

  .brand {
    flex: 0 1 auto;
    min-width: 0;
  }

  .brand > div {
    min-width: 0;
  }

  .brand h1 {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .top-right {
    display: flex;
    flex: 0 0 auto;
  }

  /* v1 drops the pill on touch layouts. A serial terminal is exactly where you
   * need the link state at a glance, so it stays — just tighter. */
  .status-pill {
    display: inline-flex;
    flex: 0 0 auto;
    order: -1;
    padding: 5px 9px;
    font-size: 11px;
  }

  @media (max-width: 600px) {
    .status-pill .device-name {
      display: none;
    }

    /* Keep the board identity visible on a phone: the support line is hidden
     * there, so the brand block gets a dedicated one-line device name. */
    .brand .compact-device:not([hidden]) {
      display: block;
      margin-top: 1px;
      overflow: hidden;
      font-size: 11px;
      color: var(--placeholder);
      white-space: nowrap;
      text-overflow: ellipsis;
    }
  }

  .terminal-card .terminal-key,
  .terminal-card .terminal-keyboard {
    min-width: 40px;
    height: 38px;
    min-height: 38px;
    padding: 0 10px;
    font-size: 12px;
  }

  #breakButton {
    height: 38px;
    min-height: 38px;
  }

  .terminal-key-group {
    gap: 7px;
  }

  .terminal-input-hint {
    font-size: 11.5px;
  }

  .statusbar {
    padding: 4px 6px 0;
  }
}

/* Phones: theme and language already live in the drawer header, so the topbar
 * keeps only the two controls that matter while a device is in hand. */
@media (max-width: 520px) {
  .top-actions #themeButton,
  .top-actions #langButton {
    display: none;
  }

  .top-actions .mobile-connect {
    min-width: 92px;
  }

  .brand h1 {
    font-size: 13px;
  }
}

@media (min-width: 901px) {
  /* The on-screen keyboard key is a touch affordance. */
  .terminal-card .terminal-keyboard {
    display: none;
  }
}

@media (min-width: 1101px) {
  /* The title row comes back now that the tab strip is gone (see above): without
   * it the drawer began with a card at the very top, while the terminal beside
   * it starts below a 59 px header band, so the two panes' content did not line
   * up. It carries the title only — its theme/language buttons are the topbar's
   * job from 901 px up, and showing both was the same duplication again. */
  .controls .drawer-head {
    display: flex;
  }
}

/* The topbar keeps theme and language from 901 px up (see the 900 px block
 * below, which is where it hands them to the drawer), so the drawer's own copy
 * of those two buttons is a duplicate control pair at every width above the
 * phone breakpoint — including the 901-1100 band, where the title row was
 * already visible. Only the title stays. */
@media (min-width: 901px) {
  /* The topbar carries these two from 901 px up, so the drawer's copies are a
   * second pair of the same controls. The close button is not a duplicate: it
   * is the in-panel way out, so it stays. */
  .controls .drawer-head-actions #drawerThemeButton,
  .controls .drawer-head-actions #drawerLangButton {
    display: none;
  }
}

/* Drawer mode floats over live content: glass there costs legibility on forms,
 * so the sheet goes nearly opaque. */
@media (max-width: 1100px) {
  html.settings-drawer-layout .controls.window-surface {
    background: rgba(11, 16, 24, 0.97);
  }

  html[data-theme="light"].settings-drawer-layout .controls.window-surface {
    background: rgba(255, 255, 255, 0.98);
  }
}

/* ---------- AI settings: stored-key disclosure ---------- */

/* The key is written to local storage in plaintext, so the card says where it
 * goes and what can read it, next to the field rather than in a footer. */
.agent-settings .key-note {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 6px 0 2px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.5;
}

.agent-settings .key-note-icon {
  flex: 0 0 auto;
  width: 14px;
  height: 14px;
  margin-top: 2px;
  color: var(--accent-strong);
}

/* The fetched model list is a suggestion under the key, not a replacement for
 * the field; a full-width action keeps it clearly separate from Save. */
.agent-settings .model-fetch {
  width: 100%;
  margin-top: 6px;
}

#agentModelStatus:empty {
  display: none;
}

/* ---------- Empty terminal ---------- */

/* Before the first connection the canvas is a black field with nothing on it,
 * which on a phone is most of the screen. This fills it and disappears the
 * instant .connected lands on the container (app.js already toggles it). */
.terminal-output {
  position: relative;
}

.terminal-empty {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 28px;
  text-align: center;
  pointer-events: none;
}

.terminal-output.connected .terminal-empty {
  display: none;
}

/* Once a session has existed the empty state is gone for good. It keys on the
 * current connection, so a disconnect used to bring it back on top of the
 * transcript that is still in the buffer — transparent, absolutely positioned
 * and centred, which reads as two texts printed over each other. */
.terminal-output[data-ever-connected] .terminal-empty {
  display: none;
}

.te-mark {
  width: 54px;
  height: 54px;
  color: var(--accent);
  opacity: 0.85;
}

.te-title {
  margin: 0;
  font-size: 14.5px;
  font-weight: 500;
  color: var(--text);
}

.te-hint {
  margin: 0;
  max-width: 260px;
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--placeholder);
}

/* ---------- Touch ---------- */

/* WebView defaults that make a native shell feel like a web page: the grey
 * flash on tap, the rubber-band bounce, double-tap zoom and, worst of all,
 * the long-press selection handles landing on a keyboard key. */
body {
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

button,
.rail-btn,
.preset-chip,
.terminal-key,
.settings-tab,
.btn {
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* Output stays selectable: copying a boot log is half the point. */
.terminal-output,
.terminal-output .xterm,
.xterm-viewport {
  user-select: text;
  -webkit-user-select: text;
}

/* The strip is a horizontal surface. Without this the browser claims the
 * swipe as a page pan and the keys never move under the finger. */
.terminal-key-scroll,
.terminal-card .presets {
  touch-action: pan-x;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
}

/* iOS zooms the page when a focused field is under 16px. xterm focuses a
 * hidden textarea on every keystroke, so the whole terminal would drift under
 * the user's thumb the moment they start typing. */
.xterm .xterm-helper-textarea {
  font-size: 16px;
}

@media (max-width: 900px) {
  .controls input,
  .controls textarea,
  .controls select {
    font-size: 16px;
  }
}

/* ---------- Phones ---------- */

/* At 390 px the desktop toolbar is what breaks first: five topbar controls
 * plus a six-button terminal header leave the title 60 px wide and the
 * terminal itself empty of context. */
@media (max-width: 520px) {
  /* The pill's word ("Disconnected") repeats what the Connect button already
   * says and costs the title half its width. Keep the dot; keep the device
   * name once one is chosen. */
  .status-pill {
    min-width: 26px;
    justify-content: center;
    padding: 5px 6px;
  }

  #statusText {
    display: none;
  }

  .top-actions .mobile-connect {
    min-width: 84px;
    padding: 0 12px;
  }

  .brand h1 {
    font-size: 13.5px;
  }

  /* Quick commands duplicate what typing does, and on a 375 px screen they
   * cost the key strip a full row. */
  .terminal-card .presets {
    display: none;
  }

  /* The empty state already explains the state; this sentence would be the
   * third one saying the same thing. */
  .terminal-input-hint {
    display: none;
  }

  /* Keep copy within thumb reach; auto-scroll and the xterm credit are not
   * useful enough to spend the narrow header on. */
  .term-tools #autoscrollBtn,
  .term-tools .term-hint {
    display: none;
  }

  .terminal-card .term-tool {
    min-width: 34px;
    height: 34px;
    padding: 0 8px;
  }

  /* 44 px is the smallest target that does not need aiming. */
  .terminal-card .terminal-key,
  .terminal-card .terminal-keyboard {
    min-width: 44px;
    height: 44px;
    min-height: 44px;
    padding: 0 12px;
    font-size: 12.5px;
  }

  /* Slightly narrower than desktop so the strip keeps one more key in view. */
  #breakButton {
    min-width: 56px;
    height: 44px;
    min-height: 44px;
  }

  /* Repeats the dot in the topbar on the same screen. */
  .statusbar .sb-state {
    display: none;
  }

  .terminal-empty {
    gap: 10px;
    padding: 20px;
  }

  .te-mark {
    width: 52px;
    height: 52px;
  }
}

/* ---------- Touch targets ---------- */

/* Fingers are not cursors, so target size has to follow the input device
 * rather than the window width. Measured at 390 px, fourteen controls came out
 * under 44 px tall: tabs at 30, mode switches at 30, panel buttons at 36 and
 * the topbar toggle at 40. A width-only query left every one of them at 30 px
 * on a phone held sideways — 844 px wide and still without a pointer — so the
 * device is asked directly. The width half is kept as a fallback for narrow
 * desktop windows, and it is the only half the offline audit can verify: its
 * WKWebView reports a fine pointer, so the coarse-pointer arm is exercised on
 * hardware, not there. The drawer already scrolls, so the extra height costs a
 * swipe, not content. */
@media (pointer: coarse), (max-width: 520px) {
  .settings-tab,
  .ts-btn {
    min-height: 38px;
  }

  .controls .btn {
    min-height: 44px;
  }

  .top-actions .icon-btn {
    min-width: 44px;
    min-height: 44px;
  }

  .term-tools .term-tool {
    min-width: 40px;
  }
}

/* ---------- Drawer geometry ---------- */

/* style.css carries two conflicting drawer rules: one anchors it left with
 * translateX(-100%), a later one anchors it right with translateX(100%). The
 * winner was "right-aligned, moved left by its own width", which leaves the
 * panel parked at the left edge whenever the viewport is wider than the panel —
 * 402 px of it on an 834 px tablet. Restate the geometry in one place: left
 * anchored, hidden by its own width. */
@media (max-width: 900px) {
  /* A later rule in style.css — html.settings-drawer-layout .controls, at
   * specificity 0,2,1 — anchors the panel to the right with translateX(+100%)
   * and visibility:visible. It was written for the agent sidebar but matches
   * every drawer layout, so the drawer never left the screen: on an 834 px
   * tablet it still covered 402 px. These selectors match its specificity so
   * the geometry is stated once, and clearly. */
  html.settings-drawer-layout .app-shell .controls {
    position: fixed;
    top: 0;
    left: 0;
    right: auto;
    bottom: 0;
    width: min(86vw, 340px);
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform 0.25s ease, visibility 0s 0.25s,
      background-color 0.25s ease, border-color 0.25s ease;
  }

  html.settings-drawer-layout .app-shell.sidebar-open .controls {
    transform: translateX(0);
    visibility: visible;
    transition-delay: 0s;
  }
}

/* Phones get the full-width sheet. At 86vw a strip of the dimmed app stayed
 * visible beside the drawer, so the page behind it (the agent toolbar, the
 * terminal keys) looked like it was spilling out past the sidebar. Tablets keep
 * the 86vw panel because they have room for a backdrop. */
@media (max-width: 600px) {
  html.settings-drawer-layout .app-shell .controls {
    width: 100vw;
    max-width: 100vw;
    right: auto;
    border-radius: 0;
    box-shadow: none;
  }
}

/* ---------- Landscape phones ---------- */

/* 844x390 is wider than the phone breakpoint but only 390 tall, so the width
 * queries treat it as a tablet while there is no vertical room at all. Reclaim
 * the chrome height instead of the width. */
@media (max-height: 500px) and (orientation: landscape) {
  .topbar {
    padding: 6px 12px;
  }

  .support-text {
    display: none;
  }

  .brand h1 {
    font-size: 13px;
  }

  .terminal-head {
    min-height: 34px;
    padding-block: 4px;
  }

  .terminal-card .terminal-key,
  .terminal-card .terminal-keyboard {
    height: 38px;
    min-height: 38px;
  }

  #breakButton {
    height: 38px;
    min-height: 38px;
  }

  .statusbar {
    padding: 2px 6px;
  }

  /* The empty state needs less air than it can afford in portrait. */
  .terminal-empty {
    gap: 8px;
  }

  .te-mark {
    width: 40px;
    height: 40px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .rail-btn,
  .status-dot.connected::after {
    transition: none;
    animation: none;
  }
}

/* ---------- About page ---------- */

/* One section at a time, including About. The legacy sheet lists the other
 * pages explicitly and this sheet only needed to add the new direction: when
 * About is active, everything else goes. */
.controls[data-settings-active="about"] [data-settings-page]:not([data-settings-page="about"]) {
  display: none;
}

/* ...and the reverse for the bands where the legacy sheet's list is the only
 * thing hiding pages. Both directions live here so the About page cannot show
 * up beside another section at any width. */
.controls[data-settings-active="connection"] [data-settings-page="about"],
.controls[data-settings-active="terminal"] [data-settings-page="about"],
.controls[data-settings-active="network"] [data-settings-page="about"],
.controls[data-settings-active="ai"] [data-settings-page="about"] {
  display: none;
}

.about-page .about-lead {
  margin: 0 0 6px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text);
}

.about-page .about-meta {
  margin: 0;
  font-size: 11.5px;
  color: var(--muted);
}

.about-page .about-heading {
  margin: 14px 0 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}

.about-page .about-group-title {
  margin: 10px 0 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}

.about-page .about-group {
  display: grid;
  gap: 2px;
}

.about-page .about-component {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}

.about-page .about-component:last-child {
  border-bottom: 0;
}

.about-page .about-name {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 12px;
  color: var(--text);
  text-decoration: none;
  overflow-wrap: anywhere;
}

.about-page .about-name:hover {
  color: var(--accent-strong);
}

.about-page .about-version {
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.about-page .about-license,
.about-page .about-license-link {
  flex: 0 0 auto;
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-2);
  font-size: 10.5px;
  color: var(--muted);
  text-decoration: none;
}

.about-page .about-license-link:hover {
  color: var(--accent-strong);
}

.about-page .about-extra {
  flex: 1 1 100%;
  font-size: 11px;
  line-height: 1.45;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.about-page .about-compliance {
  margin: 0;
  padding-left: 18px;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--muted);
}

.about-page .about-compliance li {
  margin: 4px 0;
}

.about-page .about-contributors {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.about-page .about-contributor {
  padding: 3px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-2);
  font-size: 11.5px;
  color: var(--text);
}

.about-page .about-links {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 14px;
}

.about-page .about-links a {
  font-size: 12px;
  color: var(--accent-strong);
  text-decoration: none;
}

.about-page .about-links a:hover {
  text-decoration: underline;
}

/* ---------- Board I/O (Linkr Bee X1.0) ---------- */

/* One section at a time, in every layout. The older sheets encode this rule
 * per layout (rail, drawer, agent mode) and every one of them predates the
 * Board section, so a board card would stay visible under every rail entry.
 * This list is layout-independent and later in the cascade. */
.controls[data-settings-active="connection"] [data-settings-page]:not([data-settings-page="connection"]),
.controls[data-settings-active="terminal"] [data-settings-page]:not([data-settings-page="terminal"]),
.controls[data-settings-active="network"] [data-settings-page]:not([data-settings-page="network"]),
.controls[data-settings-active="board"] [data-settings-page]:not([data-settings-page="board"]),
.controls[data-settings-active="ai"] [data-settings-page]:not([data-settings-page="ai"]),
.controls[data-settings-active="about"] [data-settings-page]:not([data-settings-page="about"]) {
  display: none;
}

/* Cards are tool trays, not marketing cards: tighter than the settings form,
 * same workbench grid, one quiet status line per action group. */
.board-card {
  display: grid;
  gap: 14px;
}

/* Paired devices live in the Connection section, not the Board hardware page. */
.bond-card {
  display: grid;
  gap: 14px;
}

/* Inside a grid card the gap is the only rhythm. Left alone, the header band's
 * own 14px bottom margin, the gap, and the next row's top margin (6-8px on a
 * hint or a button grid) all add up: 34px under the header against the 14px a
 * block card shows, and uneven steps between the rows below it. The band's
 * margin comes from `.controls .card > .card-title`, hence the prefix. */
.controls .card.board-card > .card-title,
.controls .card.bond-card > .card-title {
  margin-bottom: 0;
}

.board-card > :not(.card-title),
.bond-card > :not(.card-title) {
  margin-top: 0;
  margin-bottom: 0;
}

/* The global `.field` margin is for stacked forms; inside the board rows it
 * pushes a select above the button baseline and adds phantom gaps. */
.board-card .field {
  margin-bottom: 0;
}

.board-card input,
.board-card select,
.board-card textarea {
  min-width: 0;
}

.board-card textarea {
  min-height: 108px;
  resize: vertical;
}

.board-banner {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--warn) 45%, var(--line));
  border-radius: 10px;
  background: color-mix(in srgb, var(--warn) 12%, transparent);
  color: var(--text);
  font-size: 12px;
  line-height: 1.5;
}

/* One quiet status line with a semantic dot; numbers stay tabular. */
.board-status {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  min-height: 18px;
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.board-status::before {
  content: "";
  flex: 0 0 auto;
  width: 6px;
  height: 6px;
  margin-top: 6px;
  border-radius: 999px;
  background: var(--line-strong);
}

.board-status.is-ok::before {
  background: var(--accent);
}

.board-status.is-ok {
  color: var(--muted);
}

.board-status.is-error {
  color: var(--danger);
}

.board-status.is-error::before {
  background: var(--danger);
}

/* LED colour chips: a current-state ring instead of a heavier border. */
.board-swatches {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 8px;
  padding: 2px 0;
}

.board-swatch {
  width: 100%;
  min-width: 28px;
  aspect-ratio: 1;
  padding: 0;
  border-radius: 50%;
  border: 1px solid color-mix(in srgb, var(--line-strong) 80%, transparent);
  background: var(--board-swatch, #000);
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.18);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.board-swatch:hover:not(:disabled) {
  transform: translateY(-1px);
}

.board-swatch.is-current {
  border-color: var(--accent);
  box-shadow:
    0 0 0 2px var(--panel),
    0 0 0 3px var(--accent),
    inset 0 1px 1px rgba(255, 255, 255, 0.2);
}

.board-swatch[data-off="1"] {
  background:
    linear-gradient(135deg, transparent 45%, var(--danger) 46%, var(--danger) 54%, transparent 55%),
    var(--input-bg);
}

.board-swatch:disabled {
  opacity: 0.35;
  cursor: default;
}

.board-swatch:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.board-color-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

/* Pulse length and its button are a field row: the number field takes the space
 * and the button keeps its own width, so the row ends where the button row above
 * it ends. As a flex row the field shrank to its content width instead and left
 * the right half of the card empty. */
.board-pulse-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.board-color-row input[type="color"] {
  width: 40px;
  height: 36px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--input-bg);
  cursor: pointer;
}

.board-ir-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.board-learn-row {
  display: grid;
  gap: 8px;
}

.board-learn-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.board-subsection {
  display: grid;
  gap: 10px;
  padding-top: 14px;
  border-top: 1px solid var(--line-soft);
}

.board-subsection:first-of-type {
  padding-top: 0;
  border-top: 0;
}

.board-subtitle {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--text);
}

/* Board prompt: one field, one primary action, a quiet byte budget. */
.board-prompt-meta {
  display: flex;
  justify-content: flex-end;
  margin: -6px 0 -2px;
}

.board-count {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.board-count.is-over {
  color: var(--danger);
}

.board-prompt-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: center;
}

/* Saved signals: a quiet table of callable rows. Empty slots recede so the
 * learned keys are what the eye lands on. */
.board-empty[hidden] {
  display: none;
}

.board-empty {
  margin: 0;
  padding: 10px 12px;
  border: 1px dashed var(--line-strong);
  border-radius: 10px;
  background: color-mix(in srgb, var(--panel-2) 60%, transparent);
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.5;
}

.board-slots {
  display: grid;
  gap: 6px;
  min-height: 14px;
  font-size: 11px;
  line-height: 1.45;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.board-slot-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  background: var(--panel-2);
}

.board-slot-row.is-empty {
  opacity: 0.5;
}

/* Empty slots are placeholders, not controls: keep the name, drop the actions
 * so the learned keys stay the only clickable rows in the list. */
.board-slot-row.is-empty .board-slot-actions {
  display: none;
}

.board-slot-row.is-editing {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
}

.board-slot-row.is-editing .board-slot-copy {
  display: none;
}

.board-slot-copy {
  display: grid;
  gap: 2px;
  flex: 1 1 auto;
  min-width: 0;
}

.board-slot-name,
.board-slot-meta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.board-slot-name {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
}

.board-slot-meta {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.02em;
  color: var(--muted);
}

.board-slot-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 4px;
}

.board-slot-action {
  flex: 0 0 auto;
  min-height: 30px;
  padding: 4px 9px;
  border-radius: 8px;
  font-size: 11.5px;
  white-space: nowrap;
}

.board-slot-input {
  width: 100%;
  min-height: 32px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--text);
  font-size: 12px;
}

@media (max-width: 380px) {
  .board-prompt-actions {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  #boardPromptSave {
    grid-column: 1 / -1;
  }

  .board-slot-action {
    padding: 4px 7px;
    font-size: 11px;
  }

  .board-ir-form {
    gap: 8px;
  }
}

/* Paired-host identities wrap inside the existing board card. */
.bond-list { display: grid; gap: 10px; margin-bottom: 12px; }
.bond-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.bond-row > span { flex: 1 1 150px; min-width: 0; overflow-wrap: anywhere; font-family: var(--font-mono); font-size: 12px; }
.bond-row .btn { min-height: 44px; }

/* Match the divider and spacing used by other settings subsections. */
.shell-integration-field {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
