:root {
  color-scheme: dark;

  /* Perceptual OKLCH Surface Hierarchy (Archetype 1 + 6: Precision Dark Cockpit) */
  --bg-canvas: oklch(0.115 0.012 252);
  --bg-rail: oklch(0.132 0.013 252);
  --bg-surface-1: oklch(0.155 0.014 252);
  --bg-surface-2: oklch(0.188 0.016 252);
  --bg-surface-hover: oklch(0.215 0.018 252);

  /* Text contrast: every foreground token passes WCAG AA (4.5:1) on every surface above */
  --fg-primary: oklch(0.965 0.006 240);
  --fg-secondary: oklch(0.76 0.012 250);
  --fg-muted: oklch(0.65 0.012 250);

  /* Brand Accents: Luminara Teal + Gourwest Warm Gold */
  --accent-teal: oklch(0.78 0.14 182);
  --accent-teal-soft: oklch(0.78 0.14 182 / 0.14);
  --accent-gold: oklch(0.81 0.15 78);
  --accent-gold-soft: oklch(0.81 0.15 78 / 0.15);
  --status-ok: oklch(0.76 0.16 155);
  --status-warn: oklch(0.80 0.16 75);
  --status-danger: oklch(0.68 0.19 25);

  --border-hairline: oklch(1 0 0 / 0.08);
  --border-strong: oklch(1 0 0 / 0.18);
  --shadow-elevated:
    inset 0 1px 0 0 oklch(1 0 0 / 0.09),
    0 0 0 1px oklch(1 0 0 / 0.07),
    0 14px 34px -10px oklch(0 0 0 / 0.62);

  --radius-inner: 8px;
  --card-pad: 14px;
  --radius-outer: calc(var(--radius-inner) + var(--card-pad));

  --titlebar-h: 48px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  --font-sans: 'Inter', 'Segoe UI Variable Display', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Cascadia Code', 'Consolas', ui-monospace, monospace;
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
}

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

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-canvas);
  color: var(--fg-primary);
  font-family: var(--font-sans);
  font-size: 13.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  text-size-adjust: 100%;
}

h1, h2, h3, h4 {
  margin: 0;
  text-wrap: balance;
  letter-spacing: -0.025em;
}

h1 {
  font-size: 18px;
}

p {
  margin: 0;
  text-wrap: pretty;
  max-width: 72ch;
}

a {
  color: var(--accent-teal);
}

code,
kbd {
  font-family: var(--font-mono);
  font-size: 0.92em;
}

kbd {
  opacity: 0.8;
}

.tabular,
td,
code,
.mono {
  font-variant-numeric: tabular-nums;
}

.mono { font-family: var(--font-mono); }
.strong { font-weight: 600; }
.small { font-size: 12px; }
.xsmall { font-size: 11px; }
.muted { color: var(--fg-muted); }
.muted-2 { color: var(--fg-secondary); }
.tone-ok { color: var(--status-ok); }
.tone-warn { color: var(--status-warn); }
.tone-gold { color: var(--accent-gold); }
.tone-teal { color: var(--accent-teal); }

.row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.kicker {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.11em;
  color: var(--fg-muted);
}

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

.skip-link {
  position: fixed;
  top: calc(var(--safe-top) + 8px);
  left: 8px;
  z-index: 100;
  padding: 8px 14px;
  border-radius: var(--radius-inner);
  background: var(--accent-teal);
  color: oklch(0.14 0.02 185);
  font-weight: 700;
  text-decoration: none;
  transform: translateY(-160%);
  transition: transform 160ms var(--ease-out-expo);
}

.skip-link:focus {
  transform: translateY(0);
}

/* ---------- Titlebar ---------- */

.titlebar {
  height: calc(var(--titlebar-h) + var(--safe-top));
  padding: var(--safe-top) 0 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--bg-rail);
  border-bottom: 1px solid var(--border-hairline);
  -webkit-app-region: drag;
  user-select: none;
}

[data-runtime='web'] .titlebar {
  padding-right: 12px;
  -webkit-app-region: no-drag;
}

.titlebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-name {
  font-weight: 700;
  letter-spacing: -0.02em;
  font-size: 13.5px;
  white-space: nowrap;
}

.titlebar-badge {
  padding: 2px 8px;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  white-space: nowrap;
  background: var(--accent-gold-soft);
  color: var(--accent-gold);
  border: 1px solid oklch(0.81 0.15 78 / 0.28);
}

.titlebar-telemetry {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  -webkit-app-region: no-drag;
}

.telemetry-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--bg-surface-1);
  border: 1px solid var(--border-hairline);
  font-size: 11.5px;
  color: var(--fg-secondary);
  white-space: nowrap;
}

#server-status-label {
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-dot {
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--status-ok);
  box-shadow: 0 0 8px var(--status-ok);
}

.status-dot.warn {
  background: var(--status-warn);
  box-shadow: 0 0 8px var(--status-warn);
}

.window-controls {
  display: flex;
  height: 100%;
  -webkit-app-region: no-drag;
}

.window-controls[hidden] {
  display: none;
}

.win-btn {
  width: 46px;
  height: 100%;
  border: 0;
  background: transparent;
  color: var(--fg-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}

.win-btn:hover {
  background: oklch(1 0 0 / 0.08);
  color: var(--fg-primary);
}

.win-btn.close:hover {
  background: oklch(0.58 0.21 25);
  color: white;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: none;
  border-radius: var(--radius-inner);
  border: 1px solid transparent;
  background: transparent;
  color: var(--fg-primary);
  cursor: pointer;
  -webkit-app-region: no-drag;
}

.icon-btn:hover {
  background: var(--bg-surface-1);
  border-color: var(--border-hairline);
}

.nav-toggle {
  display: none;
}

/* ---------- App shell ---------- */

.workspace-shell {
  position: relative;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  height: calc(100vh - var(--titlebar-h) - var(--safe-top));
  height: calc(100dvh - var(--titlebar-h) - var(--safe-top));
}

.nav-rail {
  background: var(--bg-rail);
  border-right: 1px solid var(--border-hairline);
  padding: 14px 12px calc(14px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.nav-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-group-label {
  padding: 6px 10px 4px;
}

.nav-group-gap {
  margin-top: 10px;
}

.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border-radius: var(--radius-inner);
  border: 1px solid transparent;
  background: transparent;
  color: var(--fg-secondary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition:
    background 160ms var(--ease-out-expo),
    color 160ms var(--ease-out-expo),
    border-color 160ms var(--ease-out-expo),
    transform 100ms ease;
}

.nav-item:hover {
  background: var(--bg-surface-1);
  color: var(--fg-primary);
}

.nav-item:active {
  transform: scale(0.985);
}

.nav-item.active {
  background: var(--accent-teal-soft);
  color: var(--fg-primary);
  border-color: oklch(0.78 0.14 182 / 0.32);
  box-shadow: inset 0 1px 0 0 oklch(1 0 0 / 0.08);
}

.nav-count {
  flex: none;
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 999px;
  background: oklch(1 0 0 / 0.07);
  color: var(--fg-secondary);
}

.rail-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.rail-note {
  font-size: 11.5px;
  color: var(--fg-secondary);
}

.synthetic-note {
  color: var(--accent-gold);
}

.nav-scrim {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: oklch(0.06 0.01 250 / 0.6);
  backdrop-filter: blur(2px);
}

.nav-scrim[hidden] {
  display: none;
}

/* ---------- Main stage ---------- */

.stage {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-width: 0;
  overflow: hidden;
}

.stage-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--border-hairline);
  background: oklch(0.125 0.012 252 / 0.85);
}

.stage-heading {
  min-width: 0;
}

#stage-title:focus {
  outline: none;
}

#stage-title:focus-visible {
  outline: 2px solid var(--accent-teal);
  outline-offset: 4px;
  border-radius: 4px;
}

.stage-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 20px 22px calc(28px + var(--safe-bottom));
  scroll-padding: 24px;
}

.tour-active .stage-body {
  padding-bottom: 300px;
}

.select {
  padding: 7px 10px;
  min-height: 34px;
  border-radius: var(--radius-inner);
  background: var(--bg-surface-1);
  color: var(--fg-primary);
  border: 1px solid var(--border-strong);
  font-family: inherit;
  font-size: 12.5px;
  max-width: 100%;
}

/* ---------- Bento grid & cards ---------- */

.bento-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 14px;
}

.col-12 { grid-column: span 12; }
.col-8 { grid-column: span 8; }
.col-7 { grid-column: span 7; }
.col-6 { grid-column: span 6; }
.col-5 { grid-column: span 5; }
.col-4 { grid-column: span 4; }
.col-3 { grid-column: span 3; }

@media (max-width: 1180px) {
  .col-8, .col-7, .col-6, .col-5, .col-4, .col-3 {
    grid-column: span 6;
  }
}

.card {
  min-width: 0;
  background: var(--bg-surface-1);
  border-radius: var(--radius-outer);
  padding: var(--card-pad);
  box-shadow: var(--shadow-elevated);
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: box-shadow 200ms var(--ease-out-expo);
}

/* Cards animate in only when a view opens, not on every in-place update. */
.stage-body[data-entering] .card {
  animation: panel-enter 260ms var(--ease-out-expo) both;
}

.stage-body[data-entering] .bento-grid > .card:nth-child(2) { animation-delay: 30ms; }
.stage-body[data-entering] .bento-grid > .card:nth-child(3) { animation-delay: 60ms; }
.stage-body[data-entering] .bento-grid > .card:nth-child(n + 4) { animation-delay: 90ms; }

@keyframes panel-enter {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.card-title {
  font-size: 15.5px;
}

.card-inner {
  margin: 0;
  background: var(--bg-canvas);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-inner);
  padding: 10px 12px;
}

.metric-value {
  font-size: clamp(1.35rem, 1.1rem + 0.9vw, 1.85rem);
  font-weight: 700;
  letter-spacing: -0.035em;
  font-variant-numeric: tabular-nums;
}

.metric-sub {
  font-size: 12px;
  color: var(--fg-secondary);
}

.audit-stream,
.gov-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.audit-item {
  padding: 8px 10px;
}

.gov-list dt {
  display: inline;
  font-weight: 700;
}

.gov-list dt::after {
  content: ': ';
}

.gov-list dd {
  display: inline;
  margin: 0;
}

.check-list {
  margin: 0;
  padding-left: 1.2em;
  color: var(--fg-secondary);
  display: grid;
  gap: 4px;
}

.check-list li::marker {
  content: '✓  ';
  color: var(--status-ok);
}

.output {
  margin: 0;
  white-space: pre-wrap;
  color: var(--fg-secondary);
}

/* ---------- Buttons ---------- */

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  padding: 7px 12px;
  border-radius: var(--radius-inner);
  border: 1px solid var(--border-strong);
  background: var(--bg-surface-2);
  color: var(--fg-primary);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition:
    transform 120ms var(--ease-out-expo),
    background 160ms var(--ease-out-expo),
    border-color 160ms var(--ease-out-expo);
}

.btn:hover {
  background: var(--bg-surface-hover);
  transform: translateY(-1px);
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled,
.btn[aria-disabled='true'] {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn-compact {
  min-height: 30px;
  padding: 4px 9px;
  font-size: 11.5px;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: var(--accent-teal);
  color: oklch(0.14 0.02 185);
  border-color: transparent;
}

.btn-primary:hover {
  background: oklch(0.83 0.14 182);
}

.btn-gold {
  background: var(--accent-gold-soft);
  color: var(--accent-gold);
  border-color: oklch(0.81 0.15 78 / 0.35);
}

.btn-gold:hover {
  background: oklch(0.81 0.15 78 / 0.24);
}

.btn[hidden] {
  display: none;
}

:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--accent-teal);
  outline-offset: 2px;
}

/* ---------- Tables ---------- */

.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-inner);
  border: 1px solid var(--border-hairline);
  -webkit-overflow-scrolling: touch;
}

.table-wrap:focus-visible {
  outline-offset: 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

thead th {
  text-align: left;
  padding: 9px 12px;
  background: oklch(0.13 0.012 252);
  color: var(--fg-muted);
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  border-bottom: 1px solid var(--border-hairline);
  white-space: nowrap;
}

tbody th {
  text-align: left;
  font-weight: 600;
}

tbody th,
td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border-hairline);
  color: var(--fg-primary);
  vertical-align: middle;
}

tr:last-child > * {
  border-bottom: 0;
}

tbody tr:hover > * {
  background: oklch(1 0 0 / 0.025);
}

.row-merged > * {
  color: var(--fg-secondary);
  background: oklch(1 0 0 / 0.015);
}

.row-merged strong {
  text-decoration: line-through;
  text-decoration-color: oklch(1 0 0 / 0.35);
}

.row-total > * {
  border-top: 1px solid var(--border-strong);
}

.empty-cell {
  padding: 22px 14px;
  text-align: center;
  color: var(--fg-secondary);
}

.sla-meter {
  margin-top: 5px;
  width: 92px;
  height: 4px;
  border-radius: 999px;
  background: oklch(1 0 0 / 0.08);
  overflow: hidden;
}

.sla-meter span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--status-ok);
}

.sla-meter.is-hot span {
  background: var(--status-warn);
}

/* ---------- Badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-ok {
  background: oklch(0.76 0.16 155 / 0.15);
  color: var(--status-ok);
  border: 1px solid oklch(0.76 0.16 155 / 0.32);
}

.badge-warn {
  background: oklch(0.80 0.16 75 / 0.15);
  color: var(--status-warn);
  border: 1px solid oklch(0.80 0.16 75 / 0.32);
}

.badge-danger {
  background: oklch(0.68 0.19 25 / 0.16);
  color: var(--status-danger);
  border: 1px solid oklch(0.68 0.19 25 / 0.34);
}

.badge-neutral {
  background: oklch(1 0 0 / 0.07);
  color: var(--fg-secondary);
  border: 1px solid var(--border-hairline);
}

/* ---------- Forms ---------- */

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

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.field label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--fg-secondary);
}

.field input,
.field select {
  min-height: 34px;
  padding: 7px 10px;
  border-radius: var(--radius-inner);
  border: 1px solid var(--border-strong);
  background: var(--bg-canvas);
  color: var(--fg-primary);
  font-family: inherit;
  font-size: 12.5px;
  min-width: 0;
}

.field-inline {
  display: flex;
  gap: 6px;
}

.field-inline input {
  flex: 1;
}

/* ---------- Command palette ---------- */

.palette-backdrop {
  position: fixed;
  inset: 0;
  background: oklch(0.06 0.01 250 / 0.72);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: calc(11vh + var(--safe-top)) 12px 12px;
  z-index: 60;
}

.palette-backdrop[hidden] {
  display: none;
}

.palette-box {
  width: min(580px, 100%);
  background: var(--bg-surface-1);
  border-radius: var(--radius-outer);
  box-shadow: var(--shadow-elevated);
  padding: 12px;
  animation: panel-enter 140ms var(--ease-out-expo) both;
}

.palette-input {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-inner);
  border: 1px solid var(--border-strong);
  background: var(--bg-canvas);
  color: var(--fg-primary);
  font-size: 14px;
  font-family: inherit;
  margin-bottom: 8px;
}

.palette-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-height: min(340px, 52vh);
  overflow-y: auto;
}

.palette-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-inner);
  border: 1px solid transparent;
  color: var(--fg-secondary);
  cursor: pointer;
}

.palette-option:hover {
  background: var(--bg-surface-2);
  color: var(--fg-primary);
}

.palette-option.active {
  background: var(--accent-teal-soft);
  border-color: oklch(0.78 0.14 182 / 0.32);
  color: var(--fg-primary);
}

.palette-empty {
  padding: 14px 10px;
  color: var(--fg-secondary);
}

.palette-hint {
  margin-top: 8px;
  font-size: 11px;
  color: var(--fg-muted);
}

/* ---------- Guided demo ---------- */

.tour-panel {
  position: fixed;
  right: 20px;
  bottom: calc(20px + var(--safe-bottom));
  z-index: 70;
  width: min(400px, calc(100vw - 24px));
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 16px 16px;
  border-radius: var(--radius-outer);
  background: var(--bg-surface-2);
  border: 1px solid oklch(0.78 0.14 182 / 0.4);
  box-shadow: var(--shadow-elevated), 0 24px 60px -20px oklch(0 0 0 / 0.8);
  animation: panel-enter 200ms var(--ease-out-expo) both;
}

.tour-panel[hidden] {
  display: none;
}

.tour-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.tour-head .icon-btn {
  width: 32px;
  height: 32px;
  margin: -6px -8px -6px 0;
}

.tour-progress {
  height: 4px;
  border-radius: 999px;
  background: oklch(1 0 0 / 0.08);
  overflow: hidden;
}

.tour-progress span {
  display: block;
  height: 100%;
  background: var(--accent-teal);
  border-radius: inherit;
  transition: width 260ms var(--ease-out-expo);
}

.tour-title {
  font-size: 16px;
}

.tour-body {
  color: var(--fg-secondary);
  font-size: 13px;
}

.tour-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 2px;
}

.tour-actions [data-tour-nav='back'] {
  margin-right: auto;
}

.tour-spotlight {
  position: relative;
  outline: 2px solid var(--accent-gold);
  outline-offset: 3px;
  border-radius: var(--radius-inner);
  box-shadow: 0 0 0 8px oklch(0.81 0.15 78 / 0.14);
  transition: box-shadow 240ms var(--ease-out-expo), outline-color 240ms var(--ease-out-expo);
}

tr.tour-spotlight > * {
  background: oklch(0.81 0.15 78 / 0.1);
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  right: 20px;
  bottom: calc(20px + var(--safe-bottom));
  max-width: min(440px, calc(100vw - 24px));
  padding: 10px 14px;
  border-radius: var(--radius-inner);
  background: var(--bg-surface-2);
  border: 1px solid oklch(0.78 0.14 182 / 0.4);
  box-shadow: var(--shadow-elevated);
  color: var(--fg-primary);
  font-size: 12.5px;
  z-index: 80;
  animation: panel-enter 180ms var(--ease-out-expo) both;
}

.toast[hidden] {
  display: none;
}

.tour-active .toast {
  bottom: auto;
  top: calc(var(--titlebar-h) + var(--safe-top) + 12px);
}

.noscript {
  position: fixed;
  inset: auto 12px 12px;
  padding: 12px;
  background: var(--bg-surface-2);
  border-radius: var(--radius-inner);
}

/* ---------- Responsive ---------- */

@media (max-width: 1100px) {
  .titlebar-badge {
    display: none;
  }
}

@media (max-width: 900px) {
  .hide-sm {
    display: none !important;
  }

  .nav-toggle {
    display: inline-grid;
  }

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

  /* Off-canvas drawer. visibility keeps closed links out of the tab order. */
  .nav-rail {
    position: fixed;
    top: calc(var(--titlebar-h) + var(--safe-top));
    bottom: 0;
    left: 0;
    z-index: 50;
    width: min(300px, 86vw);
    border-right: 1px solid var(--border-strong);
    box-shadow: 0 20px 60px -10px oklch(0 0 0 / 0.8);
    transform: translateX(-102%);
    visibility: hidden;
    transition:
      transform 260ms var(--ease-out-expo),
      visibility 0s linear 260ms;
  }

  .nav-open .nav-rail {
    transform: translateX(0);
    visibility: visible;
    transition: transform 260ms var(--ease-out-expo);
  }

  .stage-toolbar {
    padding: 12px 16px;
  }

  .stage-body {
    padding: 16px 16px calc(24px + var(--safe-bottom));
  }

  .form-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  /* Sticky first column so wide tables keep their row labels while scrolling sideways. */
  .table-wrap tr > :first-child {
    position: sticky;
    left: 0;
    z-index: 1;
    background: var(--bg-surface-1);
  }

  .table-wrap thead tr > :first-child {
    background: oklch(0.13 0.012 252);
  }
}

@media (max-width: 700px) {
  .col-8, .col-7, .col-6, .col-5, .col-4, .col-3 {
    grid-column: span 12;
  }

  .form-row {
    grid-template-columns: minmax(0, 1fr);
  }

  .toolbar-actions {
    width: 100%;
  }

  .toolbar-actions .select {
    flex: 1 1 100%;
  }

  .toolbar-actions .btn {
    flex: 1 1 auto;
  }

  h1 {
    font-size: 16px;
  }

  .tour-panel {
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    border-radius: var(--radius-outer) var(--radius-outer) 0 0;
    padding-bottom: calc(16px + var(--safe-bottom));
  }

  .tour-active .stage-body {
    padding-bottom: 340px;
  }

  .toast {
    left: 12px;
    right: 12px;
    max-width: none;
  }
}

@media (max-width: 520px) {
  .brand-name {
    display: none;
  }

  .titlebar {
    padding-left: 6px;
  }

  [data-runtime='web'] .titlebar {
    padding-right: 8px;
  }

  .telemetry-pill {
    padding: 4px 8px;
    max-width: 46vw;
  }
}

@media (hover: none) {
  .btn:hover,
  .nav-item:hover {
    transform: none;
  }

  .btn,
  .nav-item {
    min-height: 44px;
  }

  .btn-compact {
    min-height: 40px;
  }
}

/* Windows High Contrast / forced colours: keep focus, state and borders visible. */
@media (forced-colors: active) {
  .card,
  .card-inner,
  .btn,
  .badge,
  .tour-panel,
  .palette-box {
    border: 1px solid CanvasText;
  }

  .nav-item.active,
  .palette-option.active {
    outline: 2px solid Highlight;
  }

  .status-dot {
    forced-color-adjust: none;
  }
}

@media (prefers-contrast: more) {
  :root {
    --fg-secondary: oklch(0.86 0.01 250);
    --fg-muted: oklch(0.78 0.01 250);
    --border-hairline: oklch(1 0 0 / 0.22);
    --border-strong: oklch(1 0 0 / 0.38);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-delay: 0ms !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
}
