/**
 * app.css — hand-written "console" design system. No build step, no CDN,
 * no Tailwind (that pivot happened in W15 — see .claude/tasks/W15-design-console.md
 * for the full spec this file implements literally: dark-first, magenta accent,
 * 44x44 grid background, translucent blur panels, mono data typography, a
 * six-value status scale, sticky-shell layout, data-grid tables, one 820px
 * breakpoint).
 *
 * Rule for every component below: zero hardcoded colors. Everything reads a
 * `var(--...)` token from the "Tokens" section (dark values on `:root`,
 * light overrides under `[data-theme="light"]`). If a new component needs a
 * color that doesn't exist yet, add a token first, never inline a hex value
 * in a component rule.
 */

/* ==========================================================================
   1. Tokens
   ========================================================================== */
:root {
  color-scheme: dark;

  /* --- Layout constants -------------------------------------------------- */
  --sidebar-w: 232px;
  --topbar-h: 60px;
  --grid-cell: 44px;
  --breakpoint: 820px;
  --btn-h: 38px;
  --input-h: 40px;

  /* --- Radii / motion ------------------------------------------------------ */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 999px;
  --transition-fast: 120ms ease;
  --transition-base: 180ms ease;

  /* --- Typography ----------------------------------------------------------- */
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", "Roboto Mono", Menlo, Consolas, monospace;

  /* --- Base surface (dark, default) ---------------------------------------- */
  --bg: #0e1116;
  --grid-line: rgba(255, 255, 255, 0.05);
  --surface: rgba(22, 27, 34, 0.72);
  --surface-solid: #161b22;
  --surface-raised: #1c2229;
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #e6edf3;
  --text-muted: #8b949e;
  --text-dim: #6e7681;

  --shadow-panel: 0 8px 30px rgba(0, 0, 0, 0.45);
  --shadow-raised: 0 2px 10px rgba(0, 0, 0, 0.35);
  /* Fixed per spec: the brand mark's shadow must actually read as a shadow —
     a 14%-alpha version is nearly invisible against the dark panel behind it. */
  --shadow-mark: 0 6px 16px rgba(224, 57, 158, 0.45);

  /* --- Brand accent: magenta gradient 140deg --------------------------------- */
  --accent-start: #e0399e;
  --accent-end: #8f0177;
  --accent: #e0399e;
  --accent-gradient: linear-gradient(140deg, var(--accent-start), var(--accent-end));
  --accent-soft: rgba(224, 57, 158, 0.14);
  --accent-ring: rgba(224, 57, 158, 0.45);
  --accent-contrast: #ffffff;

  /* --- Status scale: color is never the only signal (always paired with
     text in .pill / cov-bar legend items) ------------------------------------- */
  --status-done: #2ea043;
  --status-done-soft: rgba(46, 160, 67, 0.16);
  --status-pending: #d29922;
  --status-pending-soft: rgba(210, 153, 34, 0.16);
  --status-failed: #f85149;
  --status-failed-soft: rgba(248, 81, 73, 0.16);
  --status-processing: #58a6ff;
  --status-processing-soft: rgba(88, 166, 255, 0.16);
  --status-requested: #a371f7;
  --status-requested-soft: rgba(163, 113, 247, 0.16);
  --status-empty: #6e7681;
  --status-empty-soft: rgba(110, 118, 129, 0.16);

  /* --- Scrollbars: thin, translucent, same token family ---------------------- */
  --scrollbar-thumb: rgba(255, 255, 255, 0.16);
  --scrollbar-thumb-hover: rgba(255, 255, 255, 0.28);
  --scrollbar-track: transparent;
}

/* Light theme: same variable set, darker accent for contrast on white
   (per spec, #B3147A rather than the dark-theme #E0399E). */
[data-theme="light"] {
  color-scheme: light;

  --bg: #f3f4f6;
  --grid-line: rgba(15, 23, 42, 0.05);
  --surface: rgba(255, 255, 255, 0.78);
  --surface-solid: #ffffff;
  --surface-raised: #ffffff;
  --border: rgba(15, 23, 42, 0.09);
  --border-strong: rgba(15, 23, 42, 0.16);
  --text: #1b1f24;
  --text-muted: #57606a;
  --text-dim: #6e7681;

  --shadow-panel: 0 8px 24px rgba(15, 23, 42, 0.1);
  --shadow-raised: 0 2px 8px rgba(15, 23, 42, 0.08);
  --shadow-mark: 0 6px 16px rgba(179, 20, 122, 0.35);

  --accent-start: #b3147a;
  --accent-end: #7a0f57;
  --accent: #b3147a;
  --accent-soft: rgba(179, 20, 122, 0.1);
  --accent-ring: rgba(179, 20, 122, 0.4);
  --accent-contrast: #ffffff;

  --scrollbar-thumb: rgba(15, 23, 42, 0.18);
  --scrollbar-thumb-hover: rgba(15, 23, 42, 0.3);
}

/* ==========================================================================
   2. Reset / base
   ========================================================================== */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background-color: var(--bg);
  /* Fixed 44x44 grid, two linear-gradients instead of an image asset. */
  background-image: linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: var(--grid-cell) var(--grid-cell);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

img,
svg {
  display: block;
  max-width: 100%;
}

a {
  color: inherit;
}

button {
  font: inherit;
  color: inherit;
}

h1,
h2,
h3,
p {
  margin: 0;
}

::selection {
  background: var(--accent-ring);
  color: var(--accent-contrast);
}

/* Visible, high-contrast focus ring everywhere — never `outline: none`
   without a replacement (docs/rules/41). */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Respect the OS-level "reduce motion" preference (docs/rules/08 §2). This
   is also what disables the .pulse ping, toast slide-in, and save-flash
   animation, per the design spec. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Thin, translucent scrollbars everywhere (WebKit + Firefox). */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

*::-webkit-scrollbar-thumb {
  background-color: var(--scrollbar-thumb);
  border-radius: var(--radius-full);
  border: 2px solid transparent;
  background-clip: content-box;
}

*::-webkit-scrollbar-thumb:hover {
  background-color: var(--scrollbar-thumb-hover);
}

/* ==========================================================================
   3. Typography helpers
   ========================================================================== */
.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.tabular-nums {
  font-variant-numeric: tabular-nums;
}

.section-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.stat-value {
  margin-top: 6px;
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -1px;
  color: var(--text);
}

.text-muted {
  color: var(--text-muted);
}

.text-dim {
  color: var(--text-dim);
}

.text-sm {
  font-size: 13px;
}

.text-xs {
  font-size: 12px;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

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

/* Skip link (WCAG 2.4.1 "Bypass Blocks"). */
.skip-link {
  position: absolute;
  left: 12px;
  top: -48px;
  z-index: 100;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  background: var(--accent-gradient);
  color: var(--accent-contrast);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  transition: top var(--transition-fast);
}

.skip-link:focus {
  top: 12px;
}

/* ==========================================================================
   4. Shell layout — sidebar 232px | 1fr, sticky topbar 60px
   ========================================================================== */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas:
    "sidebar topbar"
    "sidebar main";
  min-height: 100vh;
}

.sidebar {
  grid-area: sidebar;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  background: var(--surface);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-right: 1px solid var(--border);
  z-index: 30;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  flex-shrink: 0;
}

.brand .mark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  background: var(--accent-gradient);
  color: var(--accent-contrast);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  box-shadow: var(--shadow-mark);
}

.brand-name {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  overflow-y: auto;
}

.nav-group {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.nav-group-label {
  padding: 0 12px 6px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.nav-item:hover {
  background: var(--border);
  color: var(--text);
}

/* Active item: accent-soft fill + accent text, never a border alone. */
.nav-item.is-active {
  background: var(--accent-soft);
  color: var(--accent-start);
}

.nav-item .icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.sidebar-foot {
  flex-shrink: 0;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 11px;
}

.topbar {
  grid-area: topbar;
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 14px;
  height: var(--topbar-h);
  padding: 0 20px;
  background: var(--surface);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}

.topbar-title {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-left: 14px;
  border-left: 1px solid var(--border);
}

.user-name {
  font-size: 12px;
}

.main {
  grid-area: main;
  min-width: 0;
  overflow-y: auto;
  padding: 24px;
}

/* ==========================================================================
   5. Panels / cards
   ========================================================================== */
.card {
  background: var(--surface);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-panel);
  padding: 20px;
}

.card-title {
  margin-bottom: 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

/* ==========================================================================
   6. Grid / stack utilities — the small hand-written set templates use in
      place of Tailwind's utility classes (kept intentionally short)
   ========================================================================== */
.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

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

.stack-6 > * + * {
  margin-top: 24px;
}

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

.list-rows {
  list-style: none;
  margin: 0;
  padding: 0;
}

.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.list-row:last-child {
  border-bottom: none;
}

/* ==========================================================================
   7. Buttons
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: var(--btn-h);
  padding: 0 16px;
  border: none;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast),
    box-shadow var(--transition-fast);
}

.btn:disabled {
  pointer-events: none;
  opacity: 0.5;
}

.btn-primary {
  background: var(--accent-gradient);
  color: var(--accent-contrast);
  box-shadow: var(--shadow-raised);
}

.btn-primary:hover {
  filter: brightness(1.08);
}

.btn-secondary {
  background: var(--surface-raised);
  color: var(--text);
  border: 1px solid var(--border-strong);
}

.btn-secondary:hover {
  background: var(--border);
}

.btn-danger {
  background: var(--status-failed);
  color: var(--accent-contrast);
}

.btn-danger:hover {
  filter: brightness(1.1);
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--btn-h);
  height: var(--btn-h);
  padding: 0;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.btn-icon:hover {
  background: var(--border);
  color: var(--text);
}

.btn-icon svg {
  width: 20px;
  height: 20px;
}

.btn.w-full {
  width: 100%;
}

/* Theme toggle: swap the two icons by the current [data-theme]. */
.theme-toggle .icon-sun {
  display: none;
}

.theme-toggle .icon-moon {
  display: block;
}

[data-theme="light"] .theme-toggle .icon-sun {
  display: block;
}

[data-theme="light"] .theme-toggle .icon-moon {
  display: none;
}

/* ==========================================================================
   8. Forms
   ========================================================================== */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field + .field {
  margin-top: 16px;
}

.label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

/* NB: border-width and padding must be explicit and non-zero, or the field
   renders as an invisible sliver — a border *color* alone is not enough.
   Regression-guarded in tests/apps/test_auth_and_shell.py. */
.input {
  display: block;
  width: 100%;
  height: var(--input-h);
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
  color: var(--text);
  font-size: 13px;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.input::placeholder {
  color: var(--text-dim);
}

.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.input[aria-invalid="true"] {
  border-color: var(--status-failed);
}

.field-error {
  font-size: 12px;
  color: var(--status-failed);
}

.alert {
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--status-failed);
  background: var(--status-failed-soft);
  color: var(--status-failed);
  font-size: 13px;
}

/* --- Switch (toggle) — a native checkbox underneath carries keyboard and
   screen-reader semantics; track/thumb on top are purely visual. ------------ */
.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.switch input[type="checkbox"] {
  position: absolute;
  inset: 0;
  width: 38px;
  height: 22px;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.switch .track {
  position: relative;
  width: 38px;
  height: 22px;
  border-radius: var(--radius-full);
  background: var(--border-strong);
  transition: background var(--transition-fast), box-shadow var(--transition-base);
  flex-shrink: 0;
}

.switch .thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent-contrast);
  transition: transform var(--transition-fast);
}

.switch input:checked ~ .track {
  background: var(--accent-gradient);
}

.switch input:checked ~ .track .thumb {
  transform: translateX(16px);
}

.switch input:focus-visible ~ .track {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Save-flash: a green ring confirming a toggle's new state was persisted,
   applied briefly by app.js on `change` — never the only feedback (the
   toggle's own position is the primary signal, this is a bonus cue). */
.switch.is-saved .track {
  box-shadow: 0 0 0 4px var(--status-done-soft);
}

.switch-label {
  font-size: 13px;
  color: var(--text);
}

/* ==========================================================================
   9. Status pills + .cov-bar
   ========================================================================== */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px 3px 8px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
}

.pill-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.pill[data-status="done"] {
  background: var(--status-done-soft);
  color: var(--status-done);
}

.pill[data-status="pending"] {
  background: var(--status-pending-soft);
  color: var(--status-pending);
}

.pill[data-status="failed"] {
  background: var(--status-failed-soft);
  color: var(--status-failed);
}

.pill[data-status="processing"] {
  background: var(--status-processing-soft);
  color: var(--status-processing);
}

.pill[data-status="requested"] {
  background: var(--status-requested-soft);
  color: var(--status-requested);
}

.pill[data-status="empty"] {
  background: var(--status-empty-soft);
  color: var(--status-empty);
}

.cov-bar {
  display: flex;
  width: 100%;
  height: 8px;
  border-radius: var(--radius-full);
  overflow: hidden;
  background: var(--border);
}

.cov-bar-seg {
  height: 100%;
}

.cov-bar-seg[data-status="done"] {
  background: var(--status-done);
}

.cov-bar-seg[data-status="pending"] {
  background: var(--status-pending);
}

.cov-bar-seg[data-status="failed"] {
  background: var(--status-failed);
}

.cov-bar-seg[data-status="processing"] {
  background: var(--status-processing);
}

.cov-bar-seg[data-status="requested"] {
  background: var(--status-requested);
}

.cov-bar-seg[data-status="empty"] {
  background: var(--status-empty);
}

.cov-bar-legend {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  margin: 12px 0 0;
  padding: 0;
}

.cov-bar-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.cov-bar-legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.cov-bar-legend-dot[data-status="done"] {
  background: var(--status-done);
}

.cov-bar-legend-dot[data-status="pending"] {
  background: var(--status-pending);
}

.cov-bar-legend-dot[data-status="failed"] {
  background: var(--status-failed);
}

.cov-bar-legend-dot[data-status="processing"] {
  background: var(--status-processing);
}

.cov-bar-legend-dot[data-status="requested"] {
  background: var(--status-requested);
}

.cov-bar-legend-dot[data-status="empty"] {
  background: var(--status-empty);
}

/* ==========================================================================
   10. .pulse — coordinator/queue live indicator (topbar signature component)
   ========================================================================== */
.pulse {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 26px;
  padding: 0 12px;
  border-radius: var(--radius-full);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

.pulse-dot {
  position: relative;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--status-empty);
  flex-shrink: 0;
}

.pulse[data-state="idle"] .pulse-dot {
  background: var(--text-dim);
}

.pulse[data-state="run"] .pulse-dot {
  background: var(--status-done);
}

.pulse[data-state="error"] .pulse-dot {
  background: var(--status-failed);
}

/* The one decorative animation in the whole app, and it carries meaning: a
   pulsing ring only appears while the coordinator/queue is actually running.
   Disabled under prefers-reduced-motion (section 2, above). */
.pulse[data-state="run"] .pulse-dot::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--status-done);
  animation: pulse-ping 1.6s cubic-bezier(0, 0, 0.2, 1) infinite;
}

@keyframes pulse-ping {
  0% {
    transform: scale(1);
    opacity: 0.7;
  }
  100% {
    transform: scale(2.4);
    opacity: 0;
  }
}

/* ==========================================================================
   11. Data-grid tables
   ========================================================================== */
.table-wrap {
  position: relative;
  max-height: calc(100vh - var(--topbar-h) - 120px);
  overflow: auto;
  scrollbar-gutter: stable;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

table.data-grid {
  width: 100%;
  min-width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

table.data-grid thead {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface-solid);
}

table.data-grid thead th {
  position: relative;
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  /* border-collapse hides a plain bottom border on a sticky <thead>; an inset
     box-shadow survives sticky positioning where a border doesn't. */
  box-shadow: inset 0 -1px 0 var(--border-strong);
}

table.data-grid tbody td {
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

table.data-grid tbody tr:hover td {
  background: var(--accent-soft);
}

table.data-grid tbody tr:last-child td {
  border-bottom: none;
}

table.data-grid .cell-empty {
  padding: 48px 14px;
}

/* Column resize handle (JS-driven, static/js/app.js initColumnResize), width
   persisted to localStorage per table id. */
.col-resizer {
  position: absolute;
  top: 0;
  right: -4px;
  width: 8px;
  height: 100%;
  cursor: col-resize;
  z-index: 3;
  touch-action: none;
}

.col-resizer::after {
  content: "";
  position: absolute;
  top: 20%;
  bottom: 20%;
  left: 50%;
  width: 1px;
  background: var(--border-strong);
}

.col-resizer:hover::after,
.col-resizer.is-dragging::after {
  background: var(--accent);
  width: 2px;
}

/* Loading row: the first row of a data-grid while an async fetch is in
   flight (per spec, a "Loading…" row, not a full-table spinner overlay). */
.row-loading td {
  color: var(--text-muted);
  font-style: italic;
}

/* ==========================================================================
   12. Pagination
   ========================================================================== */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 4px 0;
  flex-wrap: wrap;
}

.pagination-count {
  font-size: 13px;
  color: var(--text-muted);
}

.pagination-actions {
  display: flex;
  gap: 8px;
}

/* ==========================================================================
   13. Empty state
   ========================================================================== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 56px 24px;
  text-align: center;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
}

.empty-state .icon {
  width: 36px;
  height: 36px;
  color: var(--text-dim);
}

.empty-state-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.empty-state-message {
  max-width: 32em;
  font-size: 13px;
  color: var(--text-muted);
}

/* ==========================================================================
   14. Modal / confirm dialog (native <dialog>)
   ========================================================================== */
dialog.modal {
  width: min(440px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface-solid);
  color: var(--text);
  box-shadow: var(--shadow-panel);
}

dialog.modal::backdrop {
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
}

.modal-panel {
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-size: 14px;
  font-weight: 600;
}

.modal-body {
  padding: 18px 20px;
  font-size: 13px;
  color: var(--text-muted);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}

.modal-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
}

.modal-close:hover {
  background: var(--border);
  color: var(--text);
}

/* ==========================================================================
   15. Toast — bottom-right stack, colored left border carries ok/err
       meaning, always paired with the message text (never color alone)
   ========================================================================== */
#toast-stack {
  position: fixed;
  right: 16px;
  bottom: 16px;
  left: 16px;
  z-index: 60;
  display: flex;
  flex-direction: column-reverse;
  align-items: flex-end;
  gap: 10px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  max-width: 360px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--status-empty);
  border-radius: var(--radius-md);
  background: var(--surface-solid);
  box-shadow: var(--shadow-panel);
  font-size: 13px;
  color: var(--text);
  animation: toast-in var(--transition-base);
}

.toast[data-variant="ok"] {
  border-left-color: var(--status-done);
}

.toast[data-variant="err"] {
  border-left-color: var(--status-failed);
}

.toast p {
  flex: 1;
}

.toast .js-toast-dismiss {
  flex-shrink: 0;
  display: inline-flex;
  width: 20px;
  height: 20px;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
}

.toast .js-toast-dismiss:hover {
  color: var(--text);
}

@keyframes toast-in {
  from {
    transform: translateY(8px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* ==========================================================================
   16. Login page
   ========================================================================== */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.auth-card {
  width: 100%;
  max-width: 360px;
}

.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  margin-bottom: 28px;
}

.auth-brand .mark {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-lg);
  background: var(--accent-gradient);
  color: var(--accent-contrast);
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 700;
  box-shadow: var(--shadow-mark);
}

.auth-brand h1 {
  font-size: 16px;
  font-weight: 600;
}

.auth-brand p {
  font-size: 13px;
  color: var(--text-muted);
}

/* ==========================================================================
   17. Single breakpoint: 820px
   ========================================================================== */
@media (max-width: 820px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: var(--topbar-h) auto 1fr;
    grid-template-areas:
      "topbar"
      "sidebar"
      "main";
  }

  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
  }

  .brand {
    flex-shrink: 0;
  }

  .nav {
    flex-direction: row;
    align-items: center;
    padding: 8px;
    overflow-x: auto;
    overflow-y: visible;
  }

  .nav-group {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
    padding-left: 10px;
    border-left: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 2px;
  }

  .nav-group-label {
    padding: 0 8px 0 0;
  }

  .nav-item .label {
    white-space: nowrap;
  }

  .sidebar-foot {
    display: none;
  }

  .main {
    padding: 16px;
  }

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

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

  #toast-stack {
    right: 12px;
    bottom: 12px;
    left: 12px;
  }

  .toast {
    max-width: none;
  }
}
