/* BrowserBot admin — design system ("strict technical").
   One stylesheet for the whole panel: tokens, layout, components, utilities.
   Sharp corners, 1px rules instead of floating boxes, one accent colour,
   monospace for numbers/codes/timestamps/statuses. No external fonts or CDNs. */

/* ---------- Tokens ---------- */
:root {
  color-scheme: dark;

  --bg: #0e1013;
  --surface: #13161a;
  --surface-2: #181b20;
  --surface-3: #20242a;
  --border: #262a31;
  --border-strong: #363b44;
  --text: #d8dce2;
  --text-muted: #8c939d;
  --text-subtle: #656c76;

  --accent: #f08a24;
  --accent-hover: #ff9d3f;
  --accent-contrast: #14100b;
  --accent-soft: rgba(240, 138, 36, 0.12);

  --success: #5fb36b;
  --warning: #d7b43c;
  --danger: #e5584f;
  --danger-contrast: #ffffff;
  --info: var(--accent);

  --console-bg: #0a0b0d;
  --console-text: #cfd4db;
  --overlay: rgba(5, 6, 8, 0.7);

  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", "SF Mono", Menlo, Consolas, "Liberation Mono", "DejaVu Sans Mono", monospace;

  --fs-2xs: 0.6875rem;
  --fs-xs: 0.75rem;
  --fs-sm: 0.8125rem;
  --fs-base: 0.8125rem;
  --fs-md: 0.9375rem;
  --fs-lg: 1rem;
  --fs-xl: 1.125rem;
  --fs-2xl: 1.375rem;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 28px;
  --space-7: 40px;

  --radius-sm: 0;
  --radius-md: 2px;

  --control-height: 32px;
  --control-height-sm: 28px;
  --tap-target: 44px;
  --topbar-height: 48px;
  --card-pad: var(--space-4);
  --kv-label: 8.5rem;

  --sidebar-width: 224px;
  --content-max: none; /* the panel uses the whole width next to the sidebar */
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f3f4f6;
    --surface: #ffffff;
    --surface-2: #f7f8f9;
    --surface-3: #eceef1;
    --border: #dcdfe4;
    --border-strong: #c3c8cf;
    --text: #1a1d21;
    --text-muted: #59616c;
    --text-subtle: #808893;

    --accent: #b85500;
    --accent-hover: #9a4700;
    --accent-contrast: #ffffff;
    --accent-soft: rgba(184, 85, 0, 0.1);

    --success: #2c7a3a;
    --warning: #8a6a00;
    --danger: #c0352c;
    --danger-contrast: #ffffff;

    --console-bg: #121418;
    --console-text: #d6dae0;
    --overlay: rgba(20, 22, 26, 0.45);
  }
}

/* Touch devices and phones get 44px controls. */
@media (max-width: 760px), (pointer: coarse) {
  :root {
    --control-height: var(--tap-target);
    --control-height-sm: 40px;
  }
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 600; color: var(--text); }
h1 { font-size: var(--fs-xl); }
h2 { font-size: var(--fs-md); }
h3 { font-size: var(--fs-base); }
h4 { font-size: var(--fs-base); }
p { margin: 0; }

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

code, pre, kbd, .mono { font-family: var(--font-mono); }
code, kbd { font-size: 0.92em; }
code {
  padding: 0 4px;
  background: var(--surface-3);
  color: var(--text);
  overflow-wrap: anywhere;
}
pre {
  margin: 0;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: var(--fs-xs);
  overflow: auto;
  max-height: 420px;
  white-space: pre-wrap;
  word-break: break-word;
}

td, th, p, li, label, h1, h2, h3, h4, dd, dt, .mono { overflow-wrap: anywhere; }

button, input, select, textarea { font: inherit; color: inherit; }

:focus-visible { outline: 1px solid var(--accent); outline-offset: 1px; }

[hidden] { display: none !important; }

/* ---------- App shell ---------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  align-items: start;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  border-right: 1px solid var(--border);
  background: var(--surface);
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  color: var(--text);
}
.sidebar > .brand {
  min-height: var(--topbar-height);
  padding: 0 var(--space-4);
  border-bottom: 1px solid var(--border);
}
.brand:hover { color: var(--text); text-decoration: none; }
.brand-mark {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  border: 1px solid var(--accent);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: 700;
  line-height: 1;
}
.brand-text { display: grid; min-width: 0; line-height: 1.2; }
.brand-text strong { font-size: var(--fs-sm); font-weight: 600; }
.brand-text span { color: var(--text-subtle); font-size: var(--fs-2xs); }

.nav { display: grid; gap: var(--space-3); padding: var(--space-3) 0; }
.nav-section { display: grid; }
.nav-title {
  padding: 0 var(--space-4) var(--space-1);
  color: var(--text-subtle);
  font-size: var(--fs-2xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 32px;
  padding: 0 var(--space-4);
  border-left: 2px solid transparent;
  color: var(--text-muted);
}
.nav-link svg { flex: 0 0 auto; width: 16px; height: 16px; }
.nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-link.active,
.nav-link[aria-current="page"] {
  border-left-color: var(--accent);
  background: var(--surface-3);
  color: var(--text);
}
.nav-link.active svg,
.nav-link[aria-current="page"] svg { color: var(--accent); }
.nav-count {
  margin-left: auto;
  min-width: 20px;
  padding: 0 5px;
  border: 1px solid var(--warning);
  color: var(--warning);
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  font-weight: 700;
  line-height: 16px;
  text-align: center;
}

.sidebar-footer {
  display: grid;
  gap: var(--space-2);
  margin-top: auto;
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border);
}
.sidebar-user {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  overflow-wrap: anywhere;
}

/* Top bar: the one header for phones/tablets (hidden on desktop). */
.topbar { display: none; }
.nav-overlay { display: none; }

.main { min-width: 0; }
.content-shell {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--space-5) var(--space-6) var(--space-7);
}
.page-stack { display: grid; gap: var(--space-4); align-content: start; }
.page-stack > * { min-width: 0; }

/* ---------- Page header ---------- */
.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-3) var(--space-4);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--border);
}
.page-heading { display: grid; gap: 2px; min-width: 0; }
.page-heading p { color: var(--text-muted); font-size: var(--fs-sm); max-width: 80ch; }
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  width: fit-content;
  min-height: 24px;
  margin-left: -3px;
  color: var(--text-muted);
  font-size: var(--fs-xs);
}
.back-link svg { width: 14px; height: 14px; }
.back-link:hover { color: var(--text); text-decoration: none; }
.page-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }

/* Sub navigation (settings section, module tabs). */
.tabbar {
  display: flex;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabbar a {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 var(--space-3);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  color: var(--text-muted);
  font-size: var(--fs-sm);
}
.tabbar a:hover { color: var(--text); text-decoration: none; }
.tabbar a.active { border-bottom-color: var(--accent); color: var(--text); }

/* ---------- Cards: bordered panels with a title strip ---------- */
.card {
  min-width: 0;
  padding: var(--card-pad);
  border: 1px solid var(--border);
  background: var(--surface);
}
.card > * + * { margin-top: var(--space-3); }

.card-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2) var(--space-3);
}
.card > .card-header:first-child {
  margin: calc(-1 * var(--card-pad)) calc(-1 * var(--card-pad)) 0;
  padding: var(--space-2) var(--card-pad);
  border-bottom: 1px solid var(--border);
}
.card > .card-header:first-child + * { margin-top: var(--card-pad); }
.card-header > div:first-child { display: grid; gap: 1px; min-width: 0; flex: 1 1 220px; }
.card-header h2 {
  color: var(--text);
  font-size: var(--fs-2xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.card-header p { color: var(--text-subtle); font-size: var(--fs-xs); }

.card-flush { padding: 0; }
.card-flush > .card-header:first-child { margin: 0; }
.card-flush > .card-header:first-child + * { margin-top: 0; }
.card-flush > .table-wrap { margin-top: 0; }

.grid { display: grid; gap: var(--space-4); }
.two-col,
.split-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4);
  align-items: start;
}
.split-col { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }

.stack { display: grid; gap: var(--space-3); }
.stack-sm { display: grid; gap: var(--space-2); }

/* ---------- Stats: one ruled strip of cells ---------- */
.stat-grid,
.grid.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 1px;
  border: 1px solid var(--border);
  background: var(--border);
}
.stat,
.status-note {
  display: grid;
  gap: 2px;
  align-content: start;
  padding: var(--space-3) var(--space-4);
  background: var(--surface);
  color: var(--text);
}
a.stat:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.stat-label {
  color: var(--text-muted);
  font-size: var(--fs-2xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.stat-value,
.status-note strong {
  font-family: var(--font-mono);
  font-size: var(--fs-2xl);
  font-weight: 500;
  line-height: 1.15;
}
.stat-hint,
.status-note p { color: var(--text-subtle); font-size: var(--fs-xs); }
.stat-warning .stat-value { color: var(--warning); }
.stat-danger .stat-value { color: var(--danger); }
.stat-success .stat-value { color: var(--success); }

/* ---------- Buttons ---------- */
button,
.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--control-height);
  padding: 0 var(--space-3);
  border: 1px solid var(--accent);
  border-radius: var(--radius-md);
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: var(--fs-sm);
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  white-space: nowrap;
  cursor: pointer;
}
button:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-contrast); text-decoration: none; }

.button-link,
.button-secondary {
  border-color: var(--border-strong);
  background: transparent;
  color: var(--text);
  font-weight: 500;
}
.button-link:hover,
.button-secondary:hover {
  border-color: var(--text-subtle);
  background: var(--surface-3);
  color: var(--text);
  text-decoration: none;
}
.button-link.button-primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 600;
}
.button-link.button-primary:hover { background: var(--accent-hover); color: var(--accent-contrast); }

.button-danger {
  border-color: var(--border-strong);
  background: transparent;
  color: var(--danger);
  font-weight: 500;
}
.button-danger:hover { border-color: var(--danger); background: var(--danger); color: var(--danger-contrast); }

.button-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--text-muted);
  font-weight: 500;
}
.button-ghost:hover { background: var(--surface-3); border-color: transparent; color: var(--text); }

.button-sm { min-height: var(--control-height-sm); padding: 0 var(--space-2); font-size: var(--fs-xs); }
.full-width { width: 100%; }

button:disabled,
button[disabled] { opacity: 0.45; cursor: not-allowed; pointer-events: none; }

.icon-button { width: var(--control-height); padding: 0; }
.icon-button.button-sm { width: var(--control-height-sm); }
.icon-button svg { width: 16px; height: 16px; }

/* Toolbars: rows of buttons and inline forms. */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}
.toolbar > form,
.page-actions > form,
form.inline { display: inline-flex; margin: 0; }
.form-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); justify-content: flex-start; }

/* Overflow menu built on <details>. */
.menu { position: relative; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu[open] > summary { border-color: var(--accent); }
.menu-panel {
  position: absolute;
  right: 0;
  z-index: 30;
  display: grid;
  min-width: 232px;
  margin-top: var(--space-1);
  padding: var(--space-1) 0;
  border: 1px solid var(--border-strong);
  background: var(--surface);
}
.menu-panel form { display: block; margin: 0; }
.menu-panel button,
.menu-panel a {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  min-height: var(--control-height);
  padding: 0 var(--space-3);
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: 400;
}
.menu-panel button:hover,
.menu-panel a:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.menu-panel .menu-danger { color: var(--danger); }
.menu-panel .menu-danger:hover { background: var(--surface-3); color: var(--danger); }
.menu-panel .divider { margin: var(--space-1) 0; }

/* ---------- Status labels (badges) ---------- */
.badge,
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 100%;
  min-height: 18px;
  padding: 0 5px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  font-weight: 500;
  line-height: 16px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  white-space: nowrap;
  vertical-align: middle;
  overflow: hidden;
  text-overflow: ellipsis;
}
.badge::before,
.status-pill::before {
  content: "";
  width: 5px;
  height: 5px;
  background: currentColor;
  flex: 0 0 auto;
}
.badge-plain::before { display: none; }
.badge-plain { text-transform: none; }
.badge-success,
.status-pill-ok, .status-pill-succeeded, .status-pill-success, .status-pill-active,
.status-pill-authenticated, .status-pill-current, .status-pill-enabled, .status-pill-valid,
.status-pill-downloaded, .status-pill-up-to-date, .status-pill-ready {
  border-color: color-mix(in srgb, var(--success) 45%, transparent);
  color: var(--success);
}
.badge-warning,
.status-pill-warning, .status-pill-partial, .status-pill-pending, .status-pill-queued,
.status-pill-update-available, .status-pill-manual-required, .status-pill-busy, .status-pill-paused,
.status-pill-retrying, .status-pill-skipped, .status-pill-cloudflare-required, .status-pill-two-step-required,
.status-pill-manual-login-required, .status-pill-manual-locked {
  border-color: color-mix(in srgb, var(--warning) 45%, transparent);
  color: var(--warning);
}
.badge-danger,
.status-pill-error, .status-pill-failed, .status-pill-captcha_unsolved, .status-pill-problem, .status-pill-download-failed,
.status-pill-check-failed, .status-pill-login-rejected, .status-pill-invalid, .status-pill-version-unavailable,
.status-pill-addon-error {
  border-color: color-mix(in srgb, var(--danger) 45%, transparent);
  color: var(--danger);
}
.badge-info,
.status-pill-running, .status-pill-running-auto, .status-pill-in-progress {
  border-color: color-mix(in srgb, var(--info) 45%, transparent);
  color: var(--info);
}
.badge-neutral,
.status-pill-disabled, .status-pill-idle, .status-pill-unknown, .status-pill-ended {
  border-color: var(--border-strong);
  color: var(--text-muted);
}
.badge-list { display: flex; flex-wrap: wrap; gap: var(--space-1); }

/* ---------- Alerts / results ---------- */
.alert {
  display: grid;
  gap: 2px;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-left: 2px solid var(--danger);
  background: var(--surface);
  color: var(--text);
}
.alert h3 { font-size: var(--fs-sm); color: var(--danger); }
.alert p { color: var(--text); font-size: var(--fs-sm); }
.alert .toolbar { margin-top: var(--space-1); }
.alert-success { border-left-color: var(--success); }
.alert-success h3 { color: var(--success); }
.alert-warning { border-left-color: var(--warning); }
.alert-warning h3 { color: var(--warning); }
.alert-info { border-left-color: var(--info); }
.alert-info h3 { color: var(--info); }
.alert pre { background: var(--bg); }

/* ---------- Empty state ---------- */
.empty-state {
  display: grid;
  justify-items: start;
  gap: 2px;
  padding: var(--space-3) 0;
  color: var(--text-muted);
  font-size: var(--fs-sm);
}
.card-flush .empty-state { padding: var(--space-4) var(--card-pad); }
.empty-state strong { color: var(--text); font-weight: 500; }
.empty-state p { max-width: 64ch; }
.empty-state .toolbar { margin-top: var(--space-2); }

/* ---------- Tables ---------- */
.table-wrap { width: 100%; min-width: 0; overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
}
th, td {
  padding: 6px var(--space-3);
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}
thead th {
  padding-top: var(--space-2);
  padding-bottom: var(--space-2);
  color: var(--text-subtle);
  font-size: var(--fs-2xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  white-space: nowrap;
  background: var(--surface-2);
}
tbody tr:last-child > td,
tbody tr:last-child > th { border-bottom: 0; }
tbody tr:hover > td { background: var(--surface-2); }
th:first-child, td:first-child { padding-left: var(--card-pad); }
th:last-child, td:last-child { padding-right: var(--card-pad); }
.card:not(.card-flush) th:first-child,
.card:not(.card-flush) td:first-child { padding-left: 0; }
.card:not(.card-flush) th:last-child,
.card:not(.card-flush) td:last-child { padding-right: 0; }
.card:not(.card-flush) thead th { background: transparent; }
td.table-actions,
th.table-actions { text-align: right; width: 1%; white-space: nowrap; }
td.table-actions .toolbar { justify-content: flex-end; flex-wrap: nowrap; gap: var(--space-1); }
td > .muted, td .cell-sub { display: block; font-size: var(--fs-xs); }
td.cell-primary { font-weight: 500; }
td.cell-primary > .muted { font-weight: 400; }
td.nowrap { font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--text-muted); }
td.empty-cell { padding: 0; }
td.empty-cell:hover, tr:hover > td.empty-cell { background: transparent; }

.kv-table th,
.kv-table td { padding: 5px var(--space-2); }
.kv-table th,
table:not(:has(thead)) tbody th {
  width: 34%;
  color: var(--text-subtle);
  font-size: var(--fs-2xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: transparent;
}
.kv-table tbody tr:hover > td { background: transparent; }

.truncate-cell,
.text-clip { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.mono { font-size: 0.92em; }
.num { text-align: right; font-family: var(--font-mono); }

/* Config tables keep inputs aligned. */
.config-table td { vertical-align: top; }
.config-table input:not([type="checkbox"]),
.config-table select,
.config-table textarea { min-width: 140px; }

/* ---------- Forms ---------- */
.field { display: grid; gap: 4px; min-width: 0; }
.field > label,
.field-label {
  color: var(--text-muted);
  font-size: var(--fs-2xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.field-help { color: var(--text-subtle); font-size: var(--fs-xs); }
.field > label.checkbox-field { color: var(--text); font-size: var(--fs-sm); font-weight: 500; text-transform: none; letter-spacing: 0; }

input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
select,
textarea {
  width: 100%;
  min-width: 0;
  min-height: var(--control-height);
  padding: 0 var(--space-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--bg);
  color: var(--text);
  font-size: var(--fs-sm);
  text-overflow: ellipsis;
}
select {
  -webkit-appearance: none;
  appearance: none;
  padding-right: 28px;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  /* Chevron drawn with two hard-stop gradients (no images: CSP default-src 'self'). */
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) 50%, calc(100% - 10px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
select[multiple] { background-image: none; padding-right: var(--space-2); white-space: normal; }
textarea { padding: 6px var(--space-2); min-height: 88px; resize: vertical; line-height: 1.45; }
input::placeholder, textarea::placeholder { color: var(--text-subtle); }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; }
input:disabled, select:disabled, textarea:disabled { opacity: 0.6; }
input[type="checkbox"], input[type="radio"] { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); flex: 0 0 auto; }

.form-grid,
.config-grid,
.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--space-3) var(--space-4);
}
.profile-settings-grid { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }

.checkbox-field {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--control-height);
  cursor: pointer;
}

/* Toggle rows: one ruled list, not floating boxes. */
.setting-list,
.workspace-options-grid { display: grid; border: 1px solid var(--border); }
.setting-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.setting-toggle:last-child { border-bottom: 0; }
.setting-toggle:hover { background: var(--surface-2); }
.setting-toggle input:not(.switch) { margin-top: 2px; }
.setting-toggle > .switch { margin-left: auto; }
.setting-toggle-copy { display: grid; gap: 1px; }
.setting-toggle-copy strong { font-weight: 500; }
.setting-toggle-copy span { color: var(--text-muted); font-size: var(--fs-xs); }

.config-section {
  display: grid;
  gap: var(--space-3);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border);
}
.config-section:first-of-type { border-top: 0; padding-top: 0; }
.config-table-block { display: grid; gap: var(--space-2); }

/* Collapsible filters. */
.filter-panel > summary {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--control-height);
  cursor: pointer;
  font-size: var(--fs-2xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  list-style: none;
}
.filter-panel > summary::-webkit-details-marker { display: none; }
.filter-panel > summary::before {
  content: "+";
  width: 1ch;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
}
.filter-panel[open] > summary::before { content: "−"; }
.filter-panel > summary .badge { margin-left: var(--space-1); }
.filter-panel > form { margin-top: var(--space-3); }

.row-details > summary {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  cursor: pointer;
  color: var(--accent);
  font-size: var(--fs-xs);
}
.row-details[open] > summary { margin-bottom: var(--space-1); }
.context-preview { max-height: 260px; }

/* ---------- Lists (environments, modules) ---------- */
.item-list { display: grid; }
.item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border);
}
.item:last-child { border-bottom: 0; padding-bottom: 0; }
.item:first-child { padding-top: 0; }
.item-main { display: grid; gap: 3px; flex: 1 1 200px; min-width: 0; }
.item-title { font-weight: 500; color: var(--text); width: fit-content; }
a.item-title:hover,
td.cell-primary a:hover { color: var(--accent); }
td.cell-primary a { color: var(--text); }
.item-meta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1); color: var(--text-muted); font-size: var(--fs-xs); }
.item-actions { display: flex; flex-wrap: wrap; gap: var(--space-1); align-items: center; margin-left: auto; }
.item-actions > form { display: inline-flex; gap: var(--space-1); margin: 0; }
form.item-actions input:not([type="hidden"]) { flex: 1 1 180px; width: auto; }

.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1px;
  border: 1px solid var(--border);
  background: var(--border);
}
.tile {
  display: grid;
  gap: var(--space-2);
  align-content: start;
  padding: var(--space-3) var(--space-4);
  background: var(--surface);
}
.tile-head { display: flex; justify-content: space-between; gap: var(--space-2); align-items: flex-start; }
.tile p { color: var(--text-muted); font-size: var(--fs-xs); }
.tile .toolbar { margin-top: var(--space-1); }

/* ---------- Muted / misc ---------- */
.muted { color: var(--text-muted); }
.small { font-size: var(--fs-xs); }
.divider { height: 1px; background: var(--border); border: 0; margin: var(--space-2) 0; }

.live-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  background: var(--success);
}
.live-dot.idle { background: var(--text-subtle); }

/* ---------- Console ---------- */
.console-stream {
  height: 420px;
  margin: 0;
  padding: var(--space-2) var(--space-3);
  overflow: auto;
  border: 1px solid var(--border);
  background: var(--console-bg);
  color: var(--console-text);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.console-empty { color: #7d8590; }
.log-row { padding: 1px 0; }
.log-time { color: #6e7681; }
.log-scope { color: #9da7b3; }
.log-data { color: #6e7681; }
.log-level { font-weight: 700; }
.log-level-debug { color: #6e7681; }
.log-level-info { color: #8fb3d9; }
.log-level-notice { color: #7cc48a; }
.log-level-warning { color: #e3c25a; }
.log-level-error,
.log-level-critical { color: #f0766e; }
.log-message-error,
.log-message-critical { color: #f5b8b3; }
.log-message-warning { color: #ecd99a; }

/* ---------- Modals ---------- */
dialog.modal {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  padding: 0;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
}
dialog.modal::backdrop { background: var(--overlay); }
dialog.modal > form,
dialog.modal > .modal-content { display: grid; max-height: inherit; }
.modal-header {
  display: grid;
  gap: var(--space-1);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: var(--fs-md); }
.modal-header p { color: var(--text-muted); font-size: var(--fs-sm); }
.modal-body { padding: var(--space-3) var(--space-4); overflow: auto; }
.field-error { color: var(--danger); font-size: var(--fs-sm); }
.plain-list { display: grid; gap: var(--space-1); margin: 0; padding: 0; list-style: none; }
.modal-body > * + * { margin-top: var(--space-3); }
.modal-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border);
}

/* ---------- Auth ---------- */
.auth-shell {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: var(--space-5) var(--space-3);
}
.auth-card {
  display: grid;
  gap: var(--space-4);
  width: min(400px, 100%);
  padding: var(--space-5);
  border: 1px solid var(--border);
  background: var(--surface);
}
.auth-card h1 { font-size: var(--fs-xl); }
.auth-card .page-heading p { font-size: var(--fs-sm); }
.auth-card button[type="submit"] { width: 100%; }
.auth-note { color: var(--text-subtle); font-size: var(--fs-xs); }

/* ---------- Visual session (noVNC wrapper) ---------- */
.visual-session-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: var(--space-2);
  height: 100vh;
  height: 100dvh;
  padding: var(--space-2);
  overflow: hidden;
}
.visual-session-shell.has-session-tabs { grid-template-rows: auto auto minmax(0, 1fr); }
.visual-session-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-width: 0;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  background: var(--surface);
}
.visual-session-header h1 { font-size: var(--fs-md); }
.visual-session-header p { margin-top: 2px; font-size: var(--fs-xs); }
.visual-session-tabs { display: flex; gap: var(--space-1); overflow-x: auto; }
.visual-session-tab {
  flex: 0 0 auto;
  border-color: var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-weight: 500;
}
.visual-session-tab:hover,
.visual-session-tab.is-active { border-color: var(--accent); background: var(--surface-3); color: var(--text); }
.visual-session-stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #050608;
}
.visual-session-frame { display: block; width: 100%; height: 100%; border: 0; background: #050608; }
.visual-session-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: var(--space-1);
  padding: var(--space-5);
  color: #8c939d;
  text-align: center;
}
.visual-session-empty strong { color: #d8dce2; }

/* ---------- Alignment: everything placed next to a control is as tall as the control ---------- */
.page-actions > .badge,
.page-actions > .status-pill { min-height: var(--control-height); padding: 0 var(--space-2); }
.toolbar > .badge,
.toolbar > .status-pill,
.entity-actions > .badge,
.entity-actions > .status-pill { min-height: var(--control-height-sm); padding: 0 var(--space-2); }
.menu > summary { cursor: pointer; }

/* ---------- Switch: a checkbox drawn as a toggle ---------- */
input.switch {
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  flex: 0 0 auto;
  width: 36px;
  height: 20px;
  margin: 0;
  border: 1px solid var(--border-strong);
  border-radius: 0;
  background: var(--surface-3);
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}
input.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 12px;
  height: 12px;
  background: var(--text-muted);
  transition: transform 0.12s ease, background 0.12s ease;
}
input.switch:checked { border-color: var(--accent); background: var(--accent-soft); }
input.switch:checked::after { transform: translateX(16px); background: var(--accent); }
input.switch:focus-visible { outline: 1px solid var(--accent); outline-offset: 2px; }

/* ---------- Entity list: rows of modules / addons / runs with a switch, badges and actions ---------- */
.entity-list { display: grid; }
.entity-row {
  display: flex;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  min-height: calc(var(--control-height) + var(--space-4));
  padding: var(--space-2) var(--card-pad);
  border-bottom: 1px solid var(--border);
}
.entity-row:last-child { border-bottom: 0; }
.card:not(.card-flush) .entity-row { padding-left: 0; padding-right: 0; }
.entity-switch {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: stretch;
  min-width: var(--control-height);
  margin: calc(-1 * var(--space-2)) 0;
  cursor: pointer;
}
.entity-main { display: grid; gap: 2px; flex: 1 1 auto; min-width: 0; }
.entity-title { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1) var(--space-2); min-width: 0; }
.entity-title > a,
.entity-title > strong { color: var(--text); font-weight: 500; }
.entity-title > a:hover { color: var(--accent); }
.entity-main > p { color: var(--text-muted); font-size: var(--fs-xs); }
.entity-row.is-off .entity-title > a,
.entity-row.is-off .entity-title > strong { color: var(--text-muted); }
.entity-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: var(--space-1); flex: 0 1 auto; }
.entity-actions > form { display: inline-flex; margin: 0; }

/* ---------- Entry tiles: «Модулі» / «Аддони» of an environment ---------- */
.entry-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  border: 1px solid var(--border);
  background: var(--border);
}
.entry-tile {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 64px;
  padding: var(--space-3) var(--space-4);
  background: var(--surface);
  color: var(--text);
}
.entry-tile:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.entry-tile-copy { display: grid; gap: 2px; flex: 1 1 auto; min-width: 0; }
.entry-tile-title { font-size: var(--fs-md); font-weight: 600; }
.entry-tile-hint { color: var(--text-muted); font-size: var(--fs-xs); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-tile-value { font-family: var(--font-mono); font-size: var(--fs-xl); color: var(--accent); }
.entry-tile svg { flex: 0 0 auto; width: 16px; height: 16px; color: var(--text-subtle); }

/* ---------- Save bar: sticks to the bottom of long settings forms ---------- */
.save-bar {
  position: sticky;
  bottom: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2) var(--space-3);
  padding: var(--space-2) var(--card-pad);
  border: 1px solid var(--border-strong);
  background: var(--surface);
}

/* ---------- Environment groups ---------- */
.group + .group { border-top: 1px solid var(--border); }
.group-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding-right: var(--space-2);
  background: var(--surface-2);
}
.group-toggle-form { display: flex; flex: 1 1 auto; min-width: 0; margin: 0; }
button.group-toggle {
  flex: 1 1 auto;
  justify-content: flex-start;
  min-height: var(--control-height);
  padding: 0 var(--card-pad);
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font-size: var(--fs-2xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
button.group-toggle:hover { background: var(--surface-3); color: var(--text); }
.group-toggle svg { width: 14px; height: 14px; color: var(--text-muted); transform: rotate(90deg); transition: transform 0.12s ease; }
.group.is-collapsed .group-toggle svg { transform: rotate(0deg); }
.group-name { overflow: hidden; text-overflow: ellipsis; }
.group-count { color: var(--text-subtle); font-family: var(--font-mono); letter-spacing: 0; }
.group-header .menu > summary { min-height: var(--control-height-sm); width: var(--control-height-sm); }
.group-body { border-top: 1px solid var(--border); }
.group-empty { padding: var(--space-3) var(--card-pad); color: var(--text-muted); font-size: var(--fs-xs); }

.env-list { display: grid; }
.env-row {
  display: flex;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  padding: var(--space-2) var(--card-pad);
  border-bottom: 1px solid var(--border);
}
.env-row:last-child { border-bottom: 0; }
.env-row > form { display: inline-flex; margin: 0; }
.env-row > .status-pill { min-height: var(--control-height-sm); padding: 0 var(--space-2); }
.env-main { display: grid; gap: 1px; flex: 1 1 auto; min-width: 0; }
.env-name { color: var(--text); font-weight: 500; width: fit-content; }
.env-name:hover { color: var(--accent); }
.env-meta { color: var(--text-muted); font-size: var(--fs-xs); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Prompts on the dashboard ---------- */
.card-attention { border-left: 2px solid var(--warning); }
.prompt-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border);
}
.prompt-row:last-child { border-bottom: 0; padding-bottom: 0; }
.prompt-row:first-child { padding-top: 0; }
.prompt-row .entity-main { flex: 1 1 260px; }
.input-group { display: flex; flex: 1 1 280px; min-width: 0; }
.input-group > input { flex: 1 1 auto; border-right: 0; }
.input-group > button { flex: 0 0 auto; }

/* ---------- Console component ---------- */
.console { display: grid; gap: 0; border: 1px solid var(--border); background: var(--console-bg); }
.console > .console-stream { border: 0; border-top: 1px solid var(--border); }
.console-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: var(--space-2);
  padding: var(--space-2);
  background: var(--surface);
}
.console-toolbar > select { flex: 0 1 190px; width: auto; }
.console-toolbar > input[type="search"] { flex: 1 1 180px; width: auto; }
.console-buttons { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.console-buttons > form { display: inline-flex; margin: 0; }
.console-footer {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-1) var(--space-3);
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-subtle);
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
}
.console-footer .live-dot { margin-right: 4px; }
.console.is-paused .console-stream { box-shadow: inset 2px 0 0 var(--warning); }
.console-tall .console-stream { height: calc(100dvh - 260px); min-height: 320px; }
.card-console { padding: 0; border: 0; background: transparent; }
.log-scope-addon { color: #c9a0dc; }
.log-scope-core { color: #6e7681; }
.log-run { color: #8fb3d9; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .two-col,
  .split-col { grid-template-columns: minmax(0, 1fr); }
  .content-shell { padding: var(--space-4) var(--space-5) var(--space-7); }
}

@media (max-width: 960px) {
  /* Single column, normal block flow. The shell must NOT be a stretching grid
     here: a min-height grid hands spare height to the header row and pushes the
     brand/menu button down on short pages. */
  .app { display: block; min-height: 0; }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    height: var(--topbar-height);
    padding: 0 0 0 var(--space-3);
    border-bottom: 1px solid var(--border);
    background: var(--surface);
  }
  .topbar .brand { flex: 1 1 auto; align-self: stretch; }
  .topbar-title { font-weight: 600; font-size: var(--fs-md); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar-toggle {
    align-self: stretch;
    width: var(--topbar-height);
    min-height: 0;
    border: 0;
    border-left: 1px solid var(--border);
    border-radius: 0;
    background: transparent;
    color: var(--text);
  }
  .topbar-toggle:hover { background: var(--surface-3); color: var(--text); }
  .topbar-toggle[aria-expanded="true"] { background: var(--surface-3); color: var(--accent); }
  .topbar-toggle svg { width: 20px; height: 20px; }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 60;
    width: min(288px, 84vw);
    height: auto;
    transform: translateX(-101%);
    transition: transform 0.16s ease;
    border-right: 1px solid var(--border-strong);
  }
  .nav-link { min-height: var(--tap-target); }
  body.nav-open .sidebar { transform: translateX(0); }
  html:has(body.nav-open) { overflow: hidden; }
  .nav-overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: block;
    width: 100%;
    min-height: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: var(--overlay);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.16s ease;
  }
  .nav-overlay:hover { background: var(--overlay); }
  body.nav-open .nav-overlay { opacity: 1; pointer-events: auto; }
}

@media (max-width: 760px) {
  :root { --card-pad: var(--space-3); }
  body { font-size: 0.875rem; }
  input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
  select,
  textarea { font-size: 16px; }
  input[type="checkbox"], input[type="radio"] { width: 20px; height: 20px; }

  .content-shell { padding: var(--space-3) var(--space-3) var(--space-7); }
  .page-stack { gap: var(--space-3); }
  h1 { font-size: var(--fs-lg); }
  .page-header { align-items: stretch; flex-direction: column; gap: var(--space-2); }
  .back-link { min-height: 32px; font-size: var(--fs-sm); }
  .page-actions { width: 100%; }
  /* Each action as wide as its label (a long one wraps to the next row and fills it): equal 0-based shares
     squeezed «Google login» / «Старт» / «Перезавантажити код» into one row with the labels running over. */
  .page-actions > *,
  .page-actions > form > button { flex: 1 1 auto; min-width: 0; max-width: 100%; }
  .page-actions > form { display: flex; }
  .page-actions > .menu,
  .page-actions > .badge,
  .page-actions > .status-pill { flex: 0 0 auto; }
  .page-actions .button-link,
  .page-actions button { padding: 0 var(--space-2); }

  /* Cards bleed to the screen edge: rules top and bottom only. */
  .card,
  .stat-grid,
  .grid.cards,
  .tile-grid { margin-left: calc(-1 * var(--space-3)); margin-right: calc(-1 * var(--space-3)); border-left: 0; border-right: 0; }

  /* Tabs wrap into a ruled grid instead of scrolling off-screen. */
  .tabbar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
    border-width: 1px 0 0 1px;
    border-style: solid;
    border-color: var(--border);
    overflow: visible;
  }
  .tabbar a {
    min-height: 40px;
    margin: 0;
    padding: 4px var(--space-2);
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    text-align: center;
    white-space: normal;
    line-height: 1.2;
  }
  .tabbar a.active { border-bottom-color: var(--border); background: var(--surface); box-shadow: inset 0 -2px 0 var(--accent); }

  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat { padding: var(--space-2) var(--space-3); }
  .stat-value { font-size: var(--fs-xl); }

  .form-grid,
  .config-grid,
  .filter-grid,
  .profile-settings-grid { grid-template-columns: minmax(0, 1fr); }
  .form-actions > button,
  .form-actions > .button-link { flex: 1 1 auto; }

  .row-details > summary { min-height: 36px; font-size: var(--fs-sm); }
  td.cell-primary a,
  a.item-title { display: inline-flex; align-items: center; min-height: 36px; }
  td a:not(.button-link) { padding: 8px 0; }
  .tile-head h3 a { display: inline-flex; align-items: center; min-height: 32px; }

  /* Tables collapse into ruled records: label column + value column. */
  table.responsive-table,
  table.responsive-table tbody,
  table.responsive-table tr { display: block; width: 100%; }
  table.responsive-table thead { display: none; }
  table.responsive-table tr {
    padding: var(--space-2) var(--card-pad);
    border-bottom: 1px solid var(--border);
  }
  .card:not(.card-flush) table.responsive-table tr { padding-left: 0; padding-right: 0; }
  table.responsive-table tbody tr:last-child { border-bottom: 0; }
  table.responsive-table td {
    display: flow-root;
    width: 100%;
    min-height: 26px;
    padding: 3px 0 3px calc(var(--kv-label) + var(--space-2)) !important;
    border: 0;
    text-align: left;
  }
  table.responsive-table td::before {
    content: attr(data-label);
    float: left;
    width: var(--kv-label);
    margin-left: calc(-1 * (var(--kv-label) + var(--space-2)));
    padding-top: 2px;
    color: var(--text-subtle);
    font-family: var(--font-sans);
    font-size: var(--fs-2xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    line-height: 1.3;
    white-space: normal;
    -webkit-hyphens: auto;
    hyphens: auto;
    overflow-wrap: anywhere;
  }
  table.responsive-table td:not([data-label]),
  table.responsive-table td[data-label=""],
  table.responsive-table td.cell-primary,
  table.responsive-table td.table-actions,
  table.responsive-table td.empty-cell { padding-left: 0 !important; }
  table.responsive-table td:not([data-label])::before,
  table.responsive-table td[data-label=""]::before,
  table.responsive-table td.cell-primary::before,
  table.responsive-table td.table-actions::before,
  table.responsive-table td.empty-cell::before { display: none; }
  .config-table.responsive-table td::before { padding-top: 15px; }
  .config-table.responsive-table td:has(> input[type="checkbox"])::before { padding-top: 3px; }
  table.responsive-table td.cell-primary { font-size: var(--fs-md); padding-bottom: var(--space-1) !important; }
  table.responsive-table td.table-actions {
    width: 100%;
    padding-top: var(--space-2) !important;
    text-align: left;
    white-space: normal;
  }
  table.responsive-table td.table-actions .toolbar { justify-content: flex-start; flex-wrap: wrap; }
  table.responsive-table td.table-actions .toolbar > *,
  table.responsive-table td.table-actions .toolbar > form > button { flex: 1 1 auto; }
  table.responsive-table td.table-actions .toolbar > form { display: flex; }
  table.responsive-table td.table-actions .toolbar > .menu,
  table.responsive-table td.table-actions .toolbar > .icon-button { flex: 0 0 auto; }
  tbody tr:hover > td { background: transparent; }
  .truncate-cell,
  .text-clip { max-width: none; white-space: normal; overflow-wrap: anywhere; }
  .config-table input:not([type="checkbox"]),
  .config-table select,
  .config-table textarea { min-width: 0; }
  .table-wrap { overflow-x: visible; }

  .kv-table th,
  table:not(:has(thead)) tbody th { width: var(--kv-label); }

  dialog.modal {
    width: 100%;
    max-width: 100%;
    max-height: 92dvh;
    margin: auto 0 0;
    border-width: 1px 0 0;
  }
  .modal-footer > button { flex: 1 1 auto; }

  .menu-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 70;
    min-width: 0;
    margin: 0;
    padding: var(--space-2) 0 max(var(--space-2), env(safe-area-inset-bottom));
    border-width: 2px 0 0;
    border-top-color: var(--accent);
    background: var(--surface-3);
  }
  /* The bottom sheet sits on a dimmed page, so it never blends into the background; a tap on the dim closes it. */
  .menu[open]::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 69;
    background: rgba(0, 0, 0, 0.6);
  }
  .menu-panel button,
  .menu-panel a { padding: 0 var(--space-4); }

  .console-stream { height: 60vh; }
  .console-toolbar { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .console-toolbar > select,
  .console-toolbar > input[type="search"] { width: 100%; }
  .console-toolbar > input[type="search"],
  .console-buttons { grid-column: 1 / -1; }
  /* Two buttons per row: a single row cut «Відкрити окремо» / «Видалити логи» on a phone. */
  .console-buttons { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .console-buttons > *,
  .console-buttons > form > button { width: 100%; min-width: 0; }
  .console-buttons > form { display: flex; }
  .console-tall .console-stream { height: calc(100dvh - 300px); }

  input.switch { width: 44px; height: 26px; }
  input.switch::after { top: 4px; left: 4px; width: 16px; height: 16px; }
  input.switch:checked::after { transform: translateX(18px); }
  .entity-switch { min-width: var(--tap-target); }
  .entity-row { flex-wrap: wrap; }
  .entity-row .entity-main { flex: 1 1 calc(100% - var(--tap-target) - var(--space-3)); }
  .entity-actions { width: 100%; justify-content: flex-start; padding-left: calc(var(--tap-target) + var(--space-3)); }
  .entity-row:not(:has(.entity-switch)) .entity-actions { padding-left: 0; }
  .entity-actions > .button-link,
  .entity-actions > form,
  .entity-actions > form > button { flex: 1 1 auto; }
  .entry-grid { margin-left: calc(-1 * var(--space-3)); margin-right: calc(-1 * var(--space-3)); border-left: 0; border-right: 0; }
  .entry-tile { padding: var(--space-3); gap: var(--space-2); }
  .entry-tile-hint { white-space: normal; }
  .save-bar { margin-left: calc(-1 * var(--space-3)); margin-right: calc(-1 * var(--space-3)); border-left: 0; border-right: 0;
              padding-bottom: max(var(--space-2), env(safe-area-inset-bottom)); }
  .save-bar > button { flex: 1 1 auto; }
  .env-row { flex-wrap: wrap; }
  .env-row > form { margin-left: auto; }
  .env-meta { white-space: normal; }
  .group-header .menu > summary { min-height: var(--control-height); width: var(--control-height); }

  .item-actions > .button-link:not(.icon-button),
  .item-actions > form > button { flex: 1 1 auto; }

  .visual-session-header { flex-direction: column; align-items: stretch; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
