/* ==========================================================================
   Website Agent — design tokens (dark-first, light via data-theme)
   ========================================================================== */

:root {
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
    Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

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

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-pill: 999px;

  --topbar-height: 60px;
  --container-max: 1140px;

  --transition: 0.15s ease;
}

/* Dark (default / dark-first) */
:root,
[data-theme='dark'] {
  color-scheme: dark;

  --bg: #080a10;
  --bg-subtle: #0c0f16;
  --bg-elevated: #10141c;
  --surface: #141a24;
  --surface-raised: #1a2230;
  --surface-hover: #222c3d;
  --border: #252f42;
  --border-subtle: #1c2433;
  --border-strong: #354155;

  --text: #f4f6fb;
  --text-secondary: #b8c2d4;
  --muted: #7b8aa3;

  --accent: #7c8cff;
  --accent-hover: #9aa8ff;
  --accent-muted: rgba(124, 140, 255, 0.12);
  --accent-glow: rgba(124, 140, 255, 0.25);
  --accent-text: #0a0c12;

  --danger: #f87171;
  --danger-bg: rgba(248, 113, 113, 0.1);
  --danger-border: rgba(248, 113, 113, 0.35);

  --success: #4ade80;
  --success-bg: rgba(74, 222, 128, 0.1);
  --warning: #fbbf24;
  --warning-bg: rgba(251, 191, 36, 0.1);
  --info-bg: rgba(59, 130, 246, 0.1);
  --info-border: rgba(96, 165, 250, 0.3);
  --info-text: #93c5fd;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.55);
  --shadow-inset: inset 0 1px 0 rgba(255, 255, 255, 0.04);

  --status-pending-bg: rgba(251, 191, 36, 0.15);
  --status-pending-text: #fcd34d;
  --status-pending-dot: #fbbf24;
  --status-running-bg: rgba(96, 165, 250, 0.15);
  --status-running-text: #93c5fd;
  --status-running-dot: #60a5fa;
  --status-done-bg: rgba(74, 222, 128, 0.12);
  --status-done-text: #86efac;
  --status-done-dot: #4ade80;
  --status-failed-bg: rgba(248, 113, 113, 0.12);
  --status-failed-text: #fca5a5;
  --status-failed-dot: #f87171;
  --status-needs-bg: rgba(250, 204, 21, 0.12);
  --status-needs-text: #fde047;
  --status-needs-dot: #facc15;
  --status-cancelled-bg: rgba(148, 163, 184, 0.1);
  --status-cancelled-text: #94a3b8;
  --status-cancelled-dot: #64748b;

  --code-bg: #060810;
  --code-text: #c8d2e4;
  --table-head-bg: #121820;
  --table-row-hover: rgba(255, 255, 255, 0.02);

  --topbar-bg: rgba(12, 15, 22, 0.85);
  --login-glow: radial-gradient(ellipse 80% 50% at 50% -20%, rgba(124, 140, 255, 0.18), transparent 70%);
}

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

  --bg: #eef1f6;
  --bg-subtle: #e8ecf2;
  --bg-elevated: #ffffff;
  --surface: #ffffff;
  --surface-raised: #f8fafc;
  --surface-hover: #f1f5f9;
  --border: #e2e8f0;
  --border-subtle: #eef2f7;
  --border-strong: #cbd5e1;

  --text: #0f172a;
  --text-secondary: #334155;
  --muted: #64748b;

  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-muted: #eef2ff;
  --accent-glow: rgba(79, 70, 229, 0.2);
  --accent-text: #ffffff;

  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --danger-border: #fecaca;

  --success: #16a34a;
  --success-bg: #f0fdf4;
  --warning: #d97706;
  --warning-bg: #fffbeb;
  --info-bg: #eff6ff;
  --info-border: #bfdbfe;
  --info-text: #1e40af;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 40px rgba(15, 23, 42, 0.12);
  --shadow-inset: inset 0 1px 0 rgba(255, 255, 255, 0.8);

  --status-pending-bg: #fef3c7;
  --status-pending-text: #92400e;
  --status-pending-dot: #f59e0b;
  --status-running-bg: #dbeafe;
  --status-running-text: #1d4ed8;
  --status-running-dot: #3b82f6;
  --status-done-bg: #dcfce7;
  --status-done-text: #15803d;
  --status-done-dot: #22c55e;
  --status-failed-bg: #fee2e2;
  --status-failed-text: #b91c1c;
  --status-failed-dot: #ef4444;
  --status-needs-bg: #fef9c3;
  --status-needs-text: #a16207;
  --status-needs-dot: #eab308;
  --status-cancelled-bg: #f1f5f9;
  --status-cancelled-text: #475569;
  --status-cancelled-dot: #94a3b8;

  --code-bg: #0f172a;
  --code-text: #e2e8f0;
  --table-head-bg: #f8fafc;
  --table-row-hover: rgba(15, 23, 42, 0.03);

  --topbar-bg: rgba(255, 255, 255, 0.9);
  --login-glow: radial-gradient(ellipse 80% 50% at 50% -20%, rgba(79, 70, 229, 0.12), transparent 70%);
}

/* ==========================================================================
   Base
   ========================================================================== */

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

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

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}

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

table a {
  font-weight: 600;
}

table a:hover {
  text-decoration: underline;
}

code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  background: var(--accent-muted);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}

h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  margin: 0;
  line-height: 1.25;
}

h2 {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  margin: 0;
}

h3.section-title {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
}

/* ==========================================================================
   Top bar
   ========================================================================== */

.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: var(--space-4) var(--space-5);
  min-height: var(--topbar-height);
  padding: 0 var(--space-5);
  background: var(--topbar-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-sm);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  min-width: 0;
}

.brand:hover {
  color: var(--text);
  text-decoration: none;
}

.brand-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border-radius: var(--radius);
  background: linear-gradient(145deg, var(--accent) 0%, #8b5cf6 100%);
  color: var(--accent-text);
  box-shadow: 0 2px 12px var(--accent-glow);
}

.brand-mark svg {
  display: block;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  line-height: 1.15;
  min-width: 0;
}

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

.brand-tag {
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  min-width: 0;
}

.nav-link {
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  border: 1px solid transparent;
  transition: color var(--transition), background var(--transition), border-color var(--transition);
}

.nav-link:hover {
  color: var(--text);
  background: var(--surface-hover);
  text-decoration: none;
}

.nav-link.active {
  color: var(--text);
  background: var(--surface);
  border-color: var(--border);
  box-shadow: var(--shadow-inset);
}

.topbar-end {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 4px 10px 4px 4px;
  border-radius: var(--radius-pill);
  background: var(--surface);
  border: 1px solid var(--border-subtle);
}

.user-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-pill);
  background: var(--accent-muted);
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
}

.user-name {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.logout-form {
  margin: 0;
}

/* Theme toggle */
.theme-toggle {
  display: inline-flex;
  padding: 3px;
  border-radius: var(--radius-pill);
  background: var(--surface);
  border: 1px solid var(--border);
  gap: 2px;
  box-shadow: var(--shadow-inset);
}

.theme-toggle button {
  padding: 5px 9px;
  font-size: 0.72rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  line-height: 1.2;
  transition: color var(--transition), background var(--transition);
}

.theme-toggle button:hover {
  color: var(--text);
}

.theme-toggle button.active {
  background: var(--surface-raised);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

[data-theme='dark'] .theme-toggle button.active {
  background: var(--border-strong);
}

/* ==========================================================================
   Layout
   ========================================================================== */

.container {
  flex: 1;
  width: 100%;
  max-width: var(--container-max);
  margin: 0 auto;
  padding: var(--space-6) var(--space-5) var(--space-8);
}

.footer {
  text-align: center;
  color: var(--muted);
  padding: var(--space-5) var(--space-4);
  font-size: 0.8rem;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-subtle);
}

/* ==========================================================================
   Buttons
   ========================================================================== */

button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  background: var(--accent);
  color: var(--accent-text);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 8px 15px;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  line-height: 1.25;
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--transition), border-color var(--transition), box-shadow var(--transition);
}

button:hover:not(:disabled),
.btn:hover {
  background: var(--accent-hover);
  text-decoration: none;
  color: var(--accent-text);
}

button:disabled,
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-light {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
  box-shadow: var(--shadow-inset);
}

.btn-light:hover:not(:disabled) {
  background: var(--surface-hover);
  border-color: var(--border-strong);
  color: var(--text);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-hover);
  color: var(--text);
  border-color: var(--border-strong);
}

.btn-small {
  padding: 5px 11px;
  font-size: 0.8rem;
}

.btn-danger {
  background: var(--danger);
  border-color: transparent;
  color: #fff;
}

.btn-danger:hover:not(:disabled) {
  filter: brightness(1.1);
  color: #fff;
}

/* ==========================================================================
   Forms
   ========================================================================== */

label {
  display: block;
  margin-bottom: var(--space-4);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.01em;
}

input,
select,
textarea {
  display: block;
  width: 100%;
  margin-top: var(--space-2);
  padding: 9px 12px;
  font-size: 0.94rem;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-muted);
  background: var(--surface);
}

textarea {
  resize: vertical;
  min-height: 88px;
}

label.checkbox {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  color: var(--text);
  cursor: pointer;
  font-weight: 500;
}

label.checkbox input {
  width: auto;
  margin-top: 3px;
}

.field-error {
  display: block;
  color: var(--danger);
  font-size: 0.8rem;
  margin-top: var(--space-2);
  font-weight: 500;
}

.form {
  max-width: 640px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-sm);
}

.form .form-row {
  display: flex;
  gap: var(--space-4);
}

.form .form-row label {
  flex: 1;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-2);
  padding-top: var(--space-2);
}

/* ==========================================================================
   Page structure
   ========================================================================== */

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3) var(--space-4);
  margin-bottom: var(--space-5);
}

.page-head-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.page-toolbar,
.head-actions,
.action-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.page-toolbar form,
.head-actions form,
.action-toolbar form {
  margin: 0;
  display: inline-flex;
}

.section-block {
  margin-top: var(--space-7);
}

.section-block:first-child {
  margin-top: 0;
}

.section-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.panel {
  margin-top: var(--space-7);
}

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
}

.panel-body {
  margin: 0;
}

.panel-body .empty {
  padding: var(--space-6) var(--space-4);
}

/* Dashboard */
.dashboard-intro {
  margin-bottom: var(--space-5);
}

.dashboard-intro .page-head {
  margin-bottom: var(--space-3);
}

.dashboard-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}

/* ==========================================================================
   Alerts & notices
   ========================================================================== */

.alert {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid var(--danger-border);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  font-size: 0.9rem;
  margin: 0 0 var(--space-4);
  line-height: 1.45;
}

.alert-danger {
  border-left: 3px solid var(--danger);
}

.notice {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  background: var(--info-bg);
  border: 1px solid var(--info-border);
  border-left: 3px solid var(--accent);
  color: var(--info-text);
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius);
  font-size: 0.88rem;
  line-height: 1.55;
  margin: 0 0 var(--space-5);
}

[data-theme='dark'] .notice {
  color: var(--text-secondary);
}

.notice-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
}

.notice strong {
  font-weight: 600;
  color: var(--text);
}

.auto-refresh {
  font-size: 0.8rem;
  margin: 0;
}

.note {
  margin-top: var(--space-3);
  font-size: 0.84rem;
}

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

.empty {
  color: var(--muted);
  padding: var(--space-6) var(--space-4);
  text-align: center;
  font-size: 0.9rem;
}

/* ==========================================================================
   Dashboard cards
   ========================================================================== */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: var(--space-3);
}

.card {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-5);
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  color: var(--text);
  box-shadow: var(--shadow-sm), var(--shadow-inset);
  transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
}

.card:hover {
  text-decoration: none;
  border-color: var(--accent);
  box-shadow: var(--shadow-md), 0 0 0 1px var(--accent-muted);
  transform: translateY(-1px);
  color: var(--text);
}

.card-count {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.card-label {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 500;
  line-height: 1.3;
}

/* ==========================================================================
   Filters
   ========================================================================== */

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-5);
}

.filter-link {
  display: inline-block;
  padding: 6px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 500;
  text-transform: capitalize;
}

.filter-link:hover {
  text-decoration: none;
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-muted);
}

.filter-link.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

/* ==========================================================================
   Tables
   ========================================================================== */

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 480px;
}

th,
td {
  text-align: left;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.875rem;
  vertical-align: middle;
}

th {
  background: var(--table-head-bg);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
  padding-top: 10px;
  padding-bottom: 10px;
}

tr:last-child td {
  border-bottom: none;
}

tbody tr {
  transition: background var(--transition);
}

tbody tr:hover td {
  background: var(--table-row-hover);
}

.actions-col {
  width: 1%;
  white-space: nowrap;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
  justify-content: flex-end;
}

.actions form {
  margin: 0;
  display: inline-flex;
}

.pre {
  white-space: pre-wrap;
  word-break: break-word;
  max-width: 420px;
}

/* Mobile stacked tables */
@media (max-width: 720px) {
  .table-wrap.table-stack table {
    min-width: 0;
  }

  .table-wrap.table-stack thead {
    display: none;
  }

  .table-wrap.table-stack tbody tr {
    display: block;
    padding: var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
  }

  .table-wrap.table-stack tbody tr:last-child {
    border-bottom: none;
  }

  .table-wrap.table-stack td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: var(--space-3);
    padding: 5px 0;
    border: none;
    text-align: right;
  }

  .table-wrap.table-stack td::before {
    content: attr(data-label);
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    text-align: left;
    flex-shrink: 0;
  }

  .table-wrap.table-stack td.actions-cell {
    justify-content: flex-end;
    padding-top: var(--space-3);
    border-top: 1px solid var(--border-subtle);
    margin-top: var(--space-2);
  }

  .table-wrap.table-stack td.actions-cell::before {
    display: none;
  }

  .table-wrap.table-stack .actions {
    justify-content: flex-end;
    width: 100%;
  }
}

/* ==========================================================================
   Status badges
   ========================================================================== */

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 8px;
  border-radius: var(--radius-pill);
  font-size: 0.76rem;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  letter-spacing: 0.01em;
  border: 1px solid transparent;
}

.status::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-pending {
  background: var(--status-pending-bg);
  color: var(--status-pending-text);
  border-color: rgba(251, 191, 36, 0.2);
}

.status-pending::before {
  background: var(--status-pending-dot);
}

.status-running {
  background: var(--status-running-bg);
  color: var(--status-running-text);
  border-color: rgba(96, 165, 250, 0.2);
}

.status-running::before {
  background: var(--status-running-dot);
  animation: pulse-dot 1.5s ease infinite;
}

@keyframes pulse-dot {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.45;
  }
}

.status-done {
  background: var(--status-done-bg);
  color: var(--status-done-text);
  border-color: rgba(74, 222, 128, 0.2);
}

.status-done::before {
  background: var(--status-done-dot);
}

.status-failed {
  background: var(--status-failed-bg);
  color: var(--status-failed-text);
  border-color: rgba(248, 113, 113, 0.2);
}

.status-failed::before {
  background: var(--status-failed-dot);
}

.status-needs_approval {
  background: var(--status-needs-bg);
  color: var(--status-needs-text);
  border-color: rgba(250, 204, 21, 0.2);
}

.status-needs_approval::before {
  background: var(--status-needs-dot);
}

.status-cancelled {
  background: var(--status-cancelled-bg);
  color: var(--status-cancelled-text);
}

.status-cancelled::before {
  background: var(--status-cancelled-dot);
}

/* Plain status without modifier (e.g. inactive) */
.status:not(.status-pending):not(.status-running):not(.status-done):not(.status-failed):not(.status-needs_approval):not(.status-cancelled)::before {
  display: none;
}

/* Environment badges */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.35;
  white-space: nowrap;
  vertical-align: middle;
  margin-left: var(--space-2);
  text-transform: capitalize;
  letter-spacing: 0.02em;
}

.badge-env-dev {
  background: var(--status-running-bg);
  color: var(--status-running-text);
}

.badge-env-staging {
  background: var(--status-pending-bg);
  color: var(--status-pending-text);
}

.badge-env-production {
  background: var(--status-failed-bg);
  color: var(--status-failed-text);
}

.badge-production {
  background: var(--danger);
  color: #fff;
  border: none;
}

/* ==========================================================================
   Detail panels
   ========================================================================== */

.detail {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-5) var(--space-6);
  margin-bottom: var(--space-5);
  box-shadow: var(--shadow-sm);
}

.detail-grid dl {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--space-4) var(--space-6);
  margin: 0;
}

.detail-grid dl > div {
  min-width: 0;
}

.detail dl {
  margin: 0;
}

.detail dt {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 var(--space-1);
  font-weight: 600;
}

.detail dd {
  margin: 0;
  color: var(--text);
  font-size: 0.92rem;
  line-height: 1.5;
}

.detail dd pre {
  margin: var(--space-2) 0 0;
  padding: var(--space-3);
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.85rem;
}

.mono {
  font-family: var(--font-mono);
  font-size: 0.88rem;
}

.fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4) var(--space-5) var(--space-3);
  margin: 0 0 var(--space-4);
  background: var(--bg-subtle);
}

.fieldset legend {
  padding: 0 var(--space-2);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Status bar & action panels */
.status-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
  padding: var(--space-4) var(--space-5);
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.status-bar .status {
  font-size: 0.85rem;
  padding: 6px 12px 6px 10px;
}

.status-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
}

.status-actions form {
  margin: 0;
  display: inline-flex;
}

.action-panel {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-5);
  margin-bottom: var(--space-5);
  box-shadow: var(--shadow-sm);
}

.action-panel-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 var(--space-3);
}

.danger-zone {
  margin-top: var(--space-6);
  padding: var(--space-5);
  border: 1px solid var(--danger-border);
  border-radius: var(--radius-lg);
  background: var(--danger-bg);
}

.danger-zone-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--danger);
  margin: 0 0 var(--space-3);
}

.raw-json {
  margin-top: var(--space-5);
}

.raw-json summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.88rem;
  padding: var(--space-2) 0;
}

.raw-json summary:hover {
  color: var(--text);
}

.raw-json pre {
  background: var(--code-bg);
  color: var(--code-text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
  overflow-x: auto;
  margin-top: var(--space-2);
}

/* Code blocks */
.scan-output,
.scan-error,
#final-prompt,
#cursor-output,
#cursor-edit-output,
#cursor-changed-files {
  width: 100%;
  border-radius: var(--radius);
  padding: var(--space-4);
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--font-mono);
  font-size: 0.84rem;
  line-height: 1.5;
  border: 1px solid var(--border);
  margin: 0 0 var(--space-4);
}

.scan-output,
#final-prompt,
#cursor-output,
#cursor-edit-output,
#cursor-changed-files {
  background: var(--code-bg);
  color: var(--code-text);
}

.scan-error {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: var(--danger-border);
}

/* ==========================================================================
   Login
   ========================================================================== */

.page-login {
  background: var(--bg);
  background-image: var(--login-glow);
}

.page-login .container {
  max-width: none;
  padding: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.page-login .footer {
  background: transparent;
  border-top: none;
  padding-top: var(--space-4);
}

.page-error .container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 50vh;
}

.page-error .login-card {
  margin: 0;
  text-align: center;
}

.login-shell {
  width: 100%;
  max-width: 400px;
  padding: var(--space-6) var(--space-5) var(--space-5);
}

.login-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

.login-brand-mini {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  font-size: 0.92rem;
}

.login-brand-mini:hover {
  text-decoration: none;
  color: var(--text);
}

.login-brand-mini .brand-mark {
  width: 34px;
  height: 34px;
}

.login-brand-mini .brand-mark svg {
  width: 16px;
  height: 16px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-6) var(--space-6) var(--space-5);
}

.login-card h1 {
  font-size: 1.25rem;
  margin-bottom: var(--space-2);
}

.login-card .login-sub {
  color: var(--muted);
  font-size: 0.88rem;
  margin: 0 0 var(--space-5);
  line-height: 1.45;
}

.login-card label:last-of-type {
  margin-bottom: var(--space-3);
}

.login-card button[type='submit'] {
  width: 100%;
  margin-top: var(--space-2);
  padding: 11px;
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 960px) {
  .topbar {
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    padding: var(--space-3) var(--space-4);
    gap: var(--space-3);
  }

  .brand {
    grid-column: 1;
  }

  .topbar-end {
    grid-column: 2;
    grid-row: 1;
  }

  .nav {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-content: flex-start;
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 2px;
    -webkit-overflow-scrolling: touch;
    mask-image: linear-gradient(90deg, transparent, #000 8px, #000 calc(100% - 8px), transparent);
  }
}

@media (max-width: 600px) {
  .container {
    padding: var(--space-4) var(--space-4) var(--space-7);
  }

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

  .card {
    padding: var(--space-4);
  }

  .card-count {
    font-size: 1.5rem;
  }

  .user-name {
    display: none;
  }

  .user-chip {
    padding: 4px;
    border: none;
    background: transparent;
  }

  .page-head {
    flex-direction: column;
    align-items: stretch;
  }

  .page-head-actions,
  .head-actions,
  .action-toolbar,
  .page-toolbar {
    width: 100%;
  }

  .head-actions .btn,
  .head-actions button,
  .action-toolbar .btn,
  .action-toolbar button {
    flex: 1 1 auto;
    min-width: 0;
  }

  .status-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .status-actions {
    width: 100%;
  }

  .status-actions .btn,
  .status-actions button {
    flex: 1 1 auto;
  }

  .form .form-row {
    flex-direction: column;
    gap: 0;
  }

  .detail-grid dl {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 380px) {
  .cards {
    grid-template-columns: 1fr 1fr;
  }

  .theme-toggle button {
    padding: 5px 7px;
    font-size: 0.68rem;
  }

  .topbar-end .logout-form .btn {
    padding: 5px 8px;
    font-size: 0.75rem;
  }
}
