/* ==========================================================================
   0. Self-Hosted Fonts (variable font — single file covers all weights)
   ========================================================================== */

@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('/fonts/jetbrains-mono-v24-latin-regular.woff2') format('woff2');
}

/* ==========================================================================
   1. Design Tokens
   ========================================================================== */

:root {
  /* Brand / Accent — DESIGN.md: restrained teal, no gradients */
  --accent-primary: #2EB88A;
  --accent-light: #5EDBB5;
  --accent-dark: #1E8A65;
  --accent-text: #1E8A65;  /* Use for small teal text on white — passes WCAG AA 4.5:1 */
  --accent-bg: rgba(46, 184, 138, 0.08);
  --accent-bg-hover: rgba(46, 184, 138, 0.14);

  /* Surfaces — DESIGN.md: warm whites, slightly warm-black */
  --surface-page: #F5F7F6;
  --surface-primary: #ffffff;
  --surface-secondary: #E5E7EB;
  --surface-dark: #131719;
  --surface-dark-hover: #1A1E21;

  /* Text — DESIGN.md: 3-tier hierarchy + on-dark */
  --text-primary: #1A1D1F;
  --text-secondary: #6B7280;
  --text-tertiary: #9CA3AF;
  --text-muted: #9CA3AF;
  --text-on-dark: #E5E7EB;
  --text-on-dark-muted: #6B7280;

  /* Status — DESIGN.md: standard semantic colors */
  --status-pass: #16A34A;
  --status-fail: #DC2626;
  --status-warn: #D97706;
  --status-running: #2EB88A;
  --status-queued: #6B7280;
  --status-danger: #DC2626;

  /* Signals */
  --signal-failing: #DC2626;
  --signal-flaky: #D97706;
  --signal-drift: #2563EB;
  --signal-regression: #7C3AED;

  /* Resource badges — DESIGN.md */
  --badge-http-bg: #DBEAFE;
  --badge-http-text: #1D4ED8;
  --badge-sql-bg: #FEF3C7;
  --badge-sql-text: #92400E;
  --badge-kafka-bg: #F3E8FF;
  --badge-kafka-text: #7C3AED;
  --badge-mongodb-bg: #D1FAE5;
  --badge-mongodb-text: #065F46;
  --badge-util-bg: #F3F4F6;
  --badge-util-text: #4B5563;

  /* Borders */
  --border-default: rgba(24,29,31,0.08);
  --border-strong: rgba(24,29,31,0.12);
  --border-on-dark: rgba(255,255,255,0.08);

  /* Border Radius — DESIGN.md */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-pill: 9999px;

  /* Typography */
  --font-mono: 'JetBrains Mono', monospace;
  --text-xs: 11px;
  --text-sm: 12px;
  --text-caption: 13px;
  --text-base: 14px;
  --text-lg: 16px;
  --text-xl: 18px;
  --text-2xl: 22px;
  --text-3xl: 28px;
  --text-4xl: 48px;
  --weight-normal: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;
  --tracking-wider: 0.05em;

  /* Spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;

  /* Shadows — DESIGN.md: minimal-functional */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
}

/* ==========================================================================
   2. Reset & Base
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body, h1, h2, h3, .btn, button, input, select, textarea, label, summary, th, td, code, pre {
  font-family: var(--font-mono);
}

body {
  font-family: var(--font-mono);
  margin: 0;
  padding: 0;
  background: var(--surface-page);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1 {
  margin-top: 0;
  color: var(--text-primary);
  font-weight: var(--weight-bold);
  font-size: var(--text-3xl);
  letter-spacing: -0.03em;
}

h2 {
  color: var(--text-primary);
  font-weight: var(--weight-semibold);
  font-size: var(--text-2xl);
  letter-spacing: -0.02em;
}

h3 {
  color: var(--text-primary);
  font-weight: var(--weight-semibold);
  font-size: var(--text-xl);
  letter-spacing: -0.01em;
}

main a { color: var(--status-pass); text-decoration: none; transition: color 0.2s; }
main a:hover { color: var(--accent-primary); }
main a:visited { color: var(--status-pass); }

pre {
  background: var(--surface-dark);
  color: var(--text-on-dark);
  padding: 18px;
  overflow-x: auto;
  border-radius: var(--radius-lg);
  font-size: var(--text-caption);
  box-shadow: rgba(255,255,255,0.04) 0px 2px 8px inset;
}

code {
  background: rgba(24,29,31,0.06);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-size: var(--text-caption);
}

label {
  display: block;
  margin: var(--space-2) 0 var(--space-1);
  font-weight: var(--weight-medium);
}

details { margin: var(--space-4) 0; }

summary {
  cursor: pointer;
  font-weight: var(--weight-semibold);
  padding: 10px 14px;
  background: var(--surface-secondary);
  border-radius: var(--radius-md);
  user-select: none;
  transition: background 0.2s;
  box-shadow: rgba(255,255,255,0.24) 0px 2px 8px inset;
}

summary:hover { background: #CED9D1; }
details[open] summary { border-radius: var(--radius-md) var(--radius-md) 0 0; margin-bottom: 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; }

/* ==========================================================================
   3. Layout
   ========================================================================== */

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 240px;
  background: var(--surface-dark);
  display: flex;
  flex-direction: column;
  z-index: 50;
  transition: width 200ms ease-out;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-header {
  padding: var(--space-4) 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-on-dark);
}

.sidebar-header .logo {
  color: var(--text-on-dark);
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
  text-decoration: none;
  letter-spacing: -0.03em;
}

.sidebar-nav {
  flex: 1;
  padding: var(--space-2) 0;
  display: flex;
  flex-direction: column;
}

.sidebar-section-label {
  padding: var(--space-4) 20px 6px;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  color: rgba(238,246,240,0.4);
  user-select: none;
}

.sidebar-item {
  display: flex;
  align-items: center;
  padding: var(--space-2) 20px;
  color: rgba(238,246,240,0.7);
  text-decoration: none;
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  transition: background 0.15s, color 0.15s;
  border-left: 3px solid transparent;
  margin: 1px 0;
}

.sidebar-item:hover {
  background: rgba(127,242,184,0.06);
  color: var(--text-on-dark);
}

.sidebar-item.active {
  border-left-color: var(--accent-primary);
  background: rgba(46,184,138,0.08);
  color: var(--accent-light);
}

.sidebar-item .item-badge {
  margin-left: auto;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  padding: 1px 6px;
  border-radius: var(--radius-pill);
  background: rgba(127,242,184,0.15);
  color: var(--accent-light);
}

.sidebar-divider {
  border-top: 1px solid var(--border-on-dark);
  margin: var(--space-2) 20px;
}

.sidebar-footer {
  padding: var(--space-3) 20px;
  border-top: 1px solid var(--border-on-dark);
}

.sidebar-footer .user-info {
  font-size: var(--text-caption);
  color: var(--text-on-dark-muted);
  margin-bottom: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-footer form { margin: 0; display: inline; }

.sidebar-footer button {
  background: none;
  border: none;
  color: var(--text-on-dark-muted);
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  padding: 0;
  transition: color 0.2s;
}

.sidebar-footer button:hover { color: var(--accent-light); }

.env-selector { margin: var(--space-3) var(--space-4); position: relative; }

.env-selector select {
  width: 100%;
  padding: 8px 12px;
  background: var(--surface-dark-hover);
  color: var(--text-on-dark);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-md);
  font-size: var(--text-caption);
  font-family: var(--font-mono);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 5l3 3 3-3' stroke='%23667085' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

.env-selector select:focus {
  border-color: var(--accent-primary);
  outline: none;
  box-shadow: 0 0 0 2px rgba(46,184,138,0.2);
}

main {
  max-width: 1200px;
  padding: var(--space-8) var(--space-10);
  margin: var(--space-6) auto var(--space-10);
  /* Center within viewport, offset to clear fixed sidebar */
  margin-left: max(264px, calc(50% - 600px + 132px));
  background: var(--surface-primary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.container { max-width: 1200px; margin: 0 auto; }
.container-narrow { max-width: 780px; margin: 0 auto; }

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-2);
}
.page-header h1 { margin: 0; }
.page-header .actions { margin: 0; }

.breadcrumbs {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-sm);
  color: var(--text-tertiary);
  margin-bottom: var(--space-3);
}
.breadcrumbs a { color: var(--text-tertiary); text-decoration: none; transition: color 0.2s; }
.breadcrumbs a:hover { color: var(--accent-primary); }
.breadcrumbs .sep { color: var(--text-tertiary); font-size: 10px; }
.breadcrumbs .current { color: var(--text-secondary); font-weight: var(--weight-medium); }

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  padding: var(--space-2) var(--space-4);
  background: var(--surface-dark);
  color: var(--text-on-dark);
  z-index: 100;
  border-radius: 0 0 var(--radius-md) 0;
  font-size: var(--text-caption);
  font-weight: var(--weight-medium);
  text-decoration: none;
}
.skip-link:focus { left: 0; }

.mobile-header {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  background: var(--surface-dark);
  padding: 0 var(--space-4);
  height: 48px;
  align-items: center;
  justify-content: space-between;
}
.mobile-header .logo {
  color: var(--text-on-dark);
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
  text-decoration: none;
}
.mobile-header .menu-btn {
  background: none;
  border: none;
  color: var(--text-on-dark);
  font-size: 20px;
  cursor: pointer;
  padding: var(--space-2);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 40;
}

/* ==========================================================================
   4. Components — Buttons
   ========================================================================== */

.btn {
  display: inline-block;
  padding: 10px 20px;
  margin: 2px;
  background: var(--accent-primary);
  color: #fff;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
  font-weight: var(--weight-medium);
  font-size: var(--text-caption);
  transition: all 150ms cubic-bezier(0.16, 1, 0.3, 1);
}

.btn:visited { color: #fff; }

.btn:hover {
  background: var(--accent-dark);
}

.btn:disabled, .btn.is-disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
  filter: grayscale(0.6);
}

.btn-sm { padding: 6px 12px; font-size: var(--text-sm); }
.btn-xs { padding: 2px 8px; font-size: var(--text-xs); }
.btn-lg { padding: 14px 32px; font-size: var(--text-lg); }

.btn-danger {
  background: var(--status-danger);
  color: #fff;
}
.btn-danger:hover { background: #B91C1C; }

.btn-secondary {
  background: var(--surface-dark);
  color: var(--text-on-dark);
}
.btn-secondary:hover { background: var(--surface-dark-hover); }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
}
.btn-ghost:hover { background: var(--accent-bg); border-color: var(--accent-primary); }

/* ==========================================================================
   5. Components — Badges & Signals
   ========================================================================== */

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.02em;
}

.badge-http { background: var(--badge-http-bg); color: var(--badge-http-text); }
.badge-sql { background: var(--badge-sql-bg); color: var(--badge-sql-text); }
.badge-kafka { background: var(--badge-kafka-bg); color: var(--badge-kafka-text); }
.badge-mongodb { background: var(--badge-mongodb-bg); color: var(--badge-mongodb-text); }
.badge-util { background: var(--badge-util-bg); color: var(--badge-util-text); }
.badge-tag {
  background: var(--surface-secondary);
  color: var(--text-secondary);
}

.signal-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  margin-left: 6px;
}
.signal-failing { background: rgba(239,68,68,0.12); color: var(--signal-failing); }
.signal-flaky { background: rgba(245,158,11,0.12); color: var(--signal-flaky); }
.signal-drift { background: rgba(59,130,246,0.12); color: var(--signal-drift); }
.signal-regression { background: rgba(168,85,247,0.12); color: var(--signal-regression); }

.signal-banner { margin-bottom: var(--space-4); }
.signal-banner-item {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  margin-bottom: 6px;
  font-size: var(--text-caption);
}
.signal-banner-item.signal-failing { background: rgba(239,68,68,0.08); border-left: 3px solid var(--signal-failing); color: #991B1B; }
.signal-banner-item.signal-flaky { background: rgba(245,158,11,0.08); border-left: 3px solid var(--signal-flaky); color: #92400E; }
.signal-banner-item.signal-drift { background: rgba(59,130,246,0.08); border-left: 3px solid var(--signal-drift); color: #1E40AF; }
.signal-banner-item.signal-regression { background: rgba(168,85,247,0.08); border-left: 3px solid var(--signal-regression); color: #5B21B6; }

/* ==========================================================================
   6. Components — Cards & Panels
   ========================================================================== */

.card {
  background: var(--surface-primary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-6);
}

.card-kpi {
  padding: 20px 24px;
  background: var(--surface-primary);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  /* border-top color set via inline style — dynamic per KPI */
}

.kpi-label {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  color: var(--text-tertiary);
  margin-bottom: 6px;
}
.kpi-value {
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  color: var(--text-primary);
  line-height: 1;
}
.kpi-subtitle {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: var(--space-1);
}

.card-setting {
  padding: var(--space-6);
  background: var(--surface-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  text-decoration: none;
  color: var(--text-primary);
  transition: box-shadow 0.2s;
  display: block;
}
.card-setting:hover { box-shadow: var(--shadow-lg); }
.card-setting.is-disabled { opacity: 0.5; cursor: default; position: relative; }

/* V2 Project Card */
.project-card {
  background: var(--surface-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  transition: border-color 150ms cubic-bezier(0.16, 1, 0.3, 1), box-shadow 150ms cubic-bezier(0.16, 1, 0.3, 1);
  text-decoration: none;
  color: var(--text-primary);
  display: block;
}
.project-card:hover { border-color: var(--accent-primary); box-shadow: var(--shadow-md); }
.project-card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-2); }
.project-card-name { font-size: var(--text-base); font-weight: var(--weight-semibold); }
.project-card-meta { font-size: var(--text-sm); color: var(--text-tertiary); display: flex; gap: var(--space-3); margin-bottom: var(--space-2); }
.project-card-signals { display: flex; gap: var(--space-1); flex-wrap: wrap; }
.project-card-path { font-size: var(--text-xs); color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Project Cards Grid */
.project-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-4); }
@media (max-width: 900px) { .project-grid { grid-template-columns: 1fr; } }

/* Health Summary Bar */
.health-bar { display: flex; gap: var(--space-4); padding: var(--space-3) var(--space-4); background: var(--surface-primary); border: 1px solid var(--border-default); border-radius: var(--radius-md); margin-bottom: var(--space-4); font-size: var(--text-sm); color: var(--text-secondary); }
.health-bar-item { display: flex; align-items: center; gap: var(--space-1); }
.health-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.health-dot.pass { background: var(--status-pass); }
.health-dot.warn { background: var(--status-warn); }
.health-dot.fail { background: var(--status-fail); }

/* V2 KPI Strip (compact row) */
.kpi-strip { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-3); margin-bottom: var(--space-6); }
.kpi-strip-item { background: var(--surface-primary); border: 1px solid var(--border-default); border-radius: var(--radius-md); padding: var(--space-3) var(--space-4); }
.kpi-strip-label { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: var(--tracking-wider); color: var(--text-muted); margin-bottom: 2px; }
.kpi-strip-value { font-size: var(--text-xl); font-weight: var(--weight-bold); font-variant-numeric: tabular-nums; }
@media (max-width: 768px) { .kpi-strip { grid-template-columns: 1fr; } }

/* First-Run Empty State */
.first-run { display: flex; align-items: center; justify-content: center; min-height: 400px; }
.first-run-card { text-align: center; max-width: 480px; padding: var(--space-12) var(--space-8); }
.first-run-title { font-size: var(--text-xl); font-weight: var(--weight-bold); margin-bottom: var(--space-2); }
.first-run-desc { font-size: var(--text-caption); color: var(--text-secondary); line-height: 1.65; margin-bottom: var(--space-6); }

/* V2 Pipeline List */
.pipeline-row { display: grid; grid-template-columns: 24px 1fr auto auto; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border-default); font-size: var(--text-caption); }
.pipeline-row:last-child { border-bottom: none; }
.pipeline-row:hover { background: var(--accent-bg); }
.pipeline-status-dot { width: 8px; height: 8px; border-radius: 50%; }
.pipeline-status-dot.pass { background: var(--status-pass); }
.pipeline-status-dot.fail { background: var(--status-fail); }
.pipeline-status-dot.warn { background: var(--status-warn); }
.pipeline-status-dot.unknown { background: var(--text-muted); }
.pipeline-name { font-weight: var(--weight-medium); }
.pipeline-meta { font-size: var(--text-sm); color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* V2 Section Header */
.v2-section { margin-bottom: var(--space-6); }
.v2-section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-3); }
.v2-section-title { font-size: var(--text-base); font-weight: var(--weight-semibold); }
.v2-section-count { font-size: var(--text-sm); color: var(--text-muted); }

/* V2 Compact Table (resources, environments) */
.compact-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
@media (max-width: 768px) { .compact-grid { grid-template-columns: 1fr; } }
.compact-item { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-3); background: var(--surface-primary); border: 1px solid var(--border-default); border-radius: var(--radius-sm); font-size: var(--text-caption); }
.compact-item-name { font-weight: var(--weight-medium); flex: 1; }
.compact-item-meta { font-size: var(--text-sm); color: var(--text-muted); }

/* V2 Project Path Display */
.project-path { font-size: var(--text-sm); color: var(--text-muted); margin-bottom: var(--space-1); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-sync-time { font-size: var(--text-xs); color: var(--text-muted); }
.project-file-counts { font-size: var(--text-xs); color: var(--text-muted); }

/* Confirm Modal */
.confirm-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 1000; align-items: center; justify-content: center; }
.confirm-overlay.is-open { display: flex; }
.confirm-dialog { background: var(--surface-primary); border-radius: var(--radius-md); padding: var(--space-6) var(--space-8); max-width: 400px; width: 90%; box-shadow: var(--shadow-lg); }
.confirm-dialog h3 { font-size: var(--text-lg); font-weight: var(--weight-semibold); margin-bottom: var(--space-2); }
.confirm-dialog p { font-size: var(--text-caption); color: var(--text-secondary); line-height: 1.6; margin-bottom: var(--space-6); }
.confirm-actions { display: flex; gap: var(--space-2); justify-content: flex-end; }

/* CSS-only tab switcher for Add Project page */
.tab-bar { display: flex; gap: var(--space-1); margin-bottom: var(--space-6); border-bottom: 1px solid var(--border-default); }
.tab-item { padding: var(--space-2) var(--space-4); font-size: var(--text-caption); font-weight: var(--weight-medium); color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; transition: color 150ms, border-color 150ms; }
.tab-item:hover { color: var(--text-primary); }
#tab-create:checked ~ .tab-bar label[for="tab-create"],
#tab-existing:checked ~ .tab-bar label[for="tab-existing"] { color: var(--accent-text); border-color: var(--accent-primary); }
.tab-panel { display: none; }
#tab-create:checked ~ .tab-create-panel { display: block; }
#tab-existing:checked ~ .tab-existing-panel { display: block; }

.card-setting h3 { margin: 0 0 var(--space-2); font-size: var(--text-lg); }
.card-setting p { color: var(--text-tertiary); font-size: var(--text-caption); margin: 0; }

.card-feature {
  background: var(--surface-primary);
  padding: 28px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-default);
  box-shadow: 0 1px 3px rgba(24,29,31,0.04);
  transition: box-shadow 0.2s;
}
.card-feature:hover { box-shadow: var(--shadow-lg); }

.panel {
  background: var(--surface-primary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-6);
  margin-bottom: var(--space-6);
}
.panel h2 {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  margin-bottom: var(--space-4);
}

/* ==========================================================================
   7. Components — Tables
   ========================================================================== */

table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  margin: 15px 0;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border-strong);
}

th {
  background: var(--surface-secondary);
  font-weight: var(--weight-semibold);
  font-size: var(--text-sm);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  color: var(--text-secondary);
  padding: var(--space-3) var(--space-4);
  text-align: left;
  border-bottom: 1px solid var(--border-strong);
}

td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-default);
  font-size: var(--text-base);
  text-align: left;
}

tr:last-child td { border-bottom: none; }
tr:hover { background: rgba(46,184,138,0.06); }

/* ==========================================================================
   8. Components — Forms
   ========================================================================== */

.form-group { margin-bottom: var(--space-4); }
.form-inline { display: flex; gap: var(--space-2); align-items: end; }
.form-filter { margin-bottom: var(--space-4); display: flex; gap: var(--space-2); align-items: center; }

input[type=text], input[type=email], input[type=password], input[type=time], input[type=number], select, textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-sizing: border-box;
  font-size: var(--text-base);
  background: var(--surface-primary);
  transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent-primary);
  outline: none;
  box-shadow: 0 0 0 3px rgba(46,184,138,0.15);
}

.actions {
  margin: var(--space-4) 0;
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex-wrap: wrap;
}
.actions form, .sidebar-footer form, td form { margin: 0; display: inline-flex; align-items: center; }

/* ==========================================================================
   9. Components — Alerts
   ========================================================================== */

.alert-error {
  color: var(--text-primary);
  background: rgba(249,112,102,0.08);
  border: 1px solid rgba(249,112,102,0.2);
  padding: 14px 18px;
  margin: 10px 0;
  border-radius: var(--radius-md);
}

.alert-success {
  color: var(--text-primary);
  background: rgba(46,184,138,0.1);
  border: 1px solid rgba(46,184,138,0.25);
  padding: 14px 18px;
  margin: 10px 0;
  border-radius: var(--radius-md);
}

.alert-warning {
  background: #FFFBEB;
  border: 1px solid var(--status-warn);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  margin-bottom: var(--space-4);
  color: #92400E;
}

/* ==========================================================================
   10. Components — Progress Bars
   ========================================================================== */

.progress-bar {
  width: 80px;
  height: 8px;
  background: var(--surface-secondary);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  border-radius: var(--radius-sm);
  min-width: 2px;
  /* width and background-color set via inline style — dynamic */
}

.progress-bar-label {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
}

/* ==========================================================================
   11. Components — Pill Selector
   ========================================================================== */

.pill-group { display: flex; gap: var(--space-1); }

.pill {
  padding: var(--space-1) 14px;
  border-radius: var(--radius-md);
  font-size: var(--text-caption);
  font-weight: var(--weight-medium);
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
.pill:not(.is-active) { background: var(--surface-secondary); color: var(--text-secondary); }
.pill.is-active { background: var(--surface-dark); color: var(--text-on-dark); }

/* ==========================================================================
   12. Components — Empty State
   ========================================================================== */

.empty-state {
  text-align: center;
  padding: var(--space-10) 0;
  color: var(--text-muted);
  font-size: var(--text-base);
}

/* ==========================================================================
   13. Components — Search Box
   ========================================================================== */

.search-box {
  width: 250px;
  padding: var(--space-2) 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  margin-bottom: var(--space-2);
}

/* ==========================================================================
   14. Components — Ref Panel
   ========================================================================== */

.ref-panel { margin: 15px 0; }
.ref-panel-body { padding: var(--space-3); background: var(--surface-page); border-radius: var(--radius-md); }
.ref-section { margin: 10px 0; }
.ref-table { font-size: var(--text-caption); width: 100%; }

/* ==========================================================================
   15. Components — Key Display
   ========================================================================== */

.key-display {
  background: rgba(245,226,126,0.15);
  border: 1px solid rgba(245,226,126,0.4);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  margin: 10px 0;
  word-break: break-all;
}

/* ==========================================================================
   16. Pages — Auth
   ========================================================================== */

.auth-page {
  max-width: 400px;
  margin: 60px auto;
  background: var(--surface-primary);
  padding: 30px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}
.auth-page h1 { text-align: center; margin-top: 0; }
.auth-page .btn[type="submit"] { width: 100%; display: flex; align-items: center; justify-content: center; gap: var(--space-2); }
.auth-page .btn .last-used { color: rgba(255,255,255,0.7); }

.auth-link { text-align: center; margin-top: 15px; font-size: var(--text-base); }
.auth-link a { color: var(--status-pass); transition: color 0.2s; }
.auth-link a:hover { color: var(--accent-primary); }

.hint { font-size: var(--text-sm); color: var(--text-tertiary); margin-top: var(--space-1); }

.oauth-divider {
  text-align: center;
  margin: 20px 0 16px;
  color: var(--text-tertiary);
  font-size: var(--text-caption);
  position: relative;
}
.oauth-divider::before, .oauth-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 40%;
  height: 1px;
  background: rgba(24,29,31,0.1);
}
.oauth-divider::before { left: 0; }
.oauth-divider::after { right: 0; }

.oauth-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text-primary);
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  transition: 0.2s;
  margin-bottom: 8px;
  background: var(--surface-primary);
}
.oauth-btn:hover { border-color: var(--accent-primary); background: var(--accent-bg); }
.oauth-btn svg { width: 18px; height: 18px; flex-shrink: 0; }

.last-used {
  font-size: var(--text-xs);
  color: var(--accent-text);
  margin-left: var(--space-2);
  font-weight: var(--weight-normal);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

/* ==========================================================================
   17. Pages — Error
   ========================================================================== */

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

.error-card {
  max-width: 500px;
  margin: 20px;
  background: var(--surface-primary);
  padding: 40px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  text-align: center;
}

.status-code {
  font-size: 72px;
  font-weight: var(--weight-bold);
  color: var(--status-danger);
  margin: 0 0 10px;
}

.error-card h1 { margin: 0 0 15px; font-size: 24px; font-weight: var(--weight-semibold); }
.message { color: var(--text-secondary); line-height: 1.6; margin: 0 0 20px; }
.detail {
  background: var(--surface-page);
  border-radius: var(--radius-md);
  padding: 12px;
  margin: 20px 0;
  text-align: left;
  font-size: var(--text-base);
  color: var(--text-secondary);
}
.error-id {
  background: var(--surface-secondary);
  padding: 4px 8px;
  border-radius: var(--radius-md);
  font-size: var(--text-caption);
  color: var(--text-secondary);
}
.help-text {
  font-size: var(--text-caption);
  color: var(--text-tertiary);
  margin: 20px 0 25px;
}

/* ==========================================================================
   18. Pages — Landing
   ========================================================================== */

.landing-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--surface-dark);
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.nav-inner {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 var(--space-10);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.landing-nav .logo {
  color: var(--text-on-dark);
  font-size: var(--text-xl);
  font-weight: var(--weight-bold);
  letter-spacing: -0.03em;
  text-decoration: none;
}
.landing-nav .nav-links { display: flex; align-items: center; gap: var(--space-6); }
.landing-nav .login-link {
  color: rgba(238,246,240,0.7);
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  text-decoration: none;
  transition: color 0.2s;
}
.landing-nav .login-link:hover { color: var(--accent-light); }

.landing-main {
  margin: 0 !important;
  padding: 0 !important;
  border-radius: 0 !important;
  max-width: none !important;
}

/* Nav link (e.g. GitHub) */
.landing-nav .nav-link {
  color: rgba(238,246,240,0.7);
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  text-decoration: none;
  transition: color 0.2s;
}
.landing-nav .nav-link:hover { color: var(--accent-light); }

/* ── Hero ── */
.landing-hero {
  background: var(--surface-dark);
  padding: 140px 0 100px;
}
.hero-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 var(--space-10);
}
.hero-split {
  display: flex;
  gap: 80px;
  align-items: center;
}
.hero-copy { flex: 1; min-width: 0; }
.hero-code { flex: 1; min-width: 0; }
.landing-hero h1 {
  font-size: 52px;
  font-weight: var(--weight-bold);
  letter-spacing: -0.04em;
  line-height: 1.1;
  color: var(--text-on-dark);
  margin-bottom: 24px;
}
.landing-hero h1 .accent { color: var(--accent-primary); }
.hero-sub {
  font-size: 16px;
  color: rgba(238,246,240,0.6);
  max-width: 440px;
  margin: 0 0 40px;
  line-height: 1.7;
}
.hero-actions { display: flex; gap: var(--space-3); flex-wrap: wrap; }
.hero-actions .btn { min-width: 200px; text-align: center; }
.hero-actions .btn-ghost {
  border-color: rgba(238,246,240,0.25);
  color: var(--text-on-dark);
}
.hero-actions .btn-ghost:hover {
  border-color: var(--accent-primary);
  background: rgba(46,184,138,0.1);
}
.hero-code .code-block.code-hero {
  font-size: 14px;
  line-height: 1.8;
  padding: var(--space-8);
  border: 1px solid rgba(46,184,138,0.15);
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}
.hero-code-caption {
  text-align: center;
  font-size: var(--text-sm);
  color: rgba(238,246,240,0.35);
  margin-top: var(--space-4);
  letter-spacing: 0.08em;
}

.code-block {
  background: var(--surface-dark);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  overflow-x: auto;
  font-size: var(--text-caption);
  line-height: 1.7;
}
.code-block pre { margin: 0; color: var(--text-on-dark); white-space: pre; }
.code-block .kw { color: #0296BA; }
.code-block .str { color: var(--status-danger); }
.code-block .num { color: var(--accent-primary); }
.code-block .comment { color: #8892A6; font-style: italic; }
.code-block .sym { color: var(--text-on-dark); }
.code-block .bracket { color: var(--text-on-dark-muted); }

/* ── Features ── */
.features-section {
  padding: 120px 0;
  background: var(--surface-primary);
}
.features-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 var(--space-10);
}
.features-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 64px;
}
.feature-col {
  display: flex;
  flex-direction: column;
}
.feature-col h3 {
  font-size: var(--text-xl);
  font-weight: var(--weight-bold);
  letter-spacing: -0.02em;
  margin-bottom: var(--space-4);
  color: var(--text-primary);
}
.feature-col p {
  font-size: var(--text-base);
  color: var(--text-secondary);
  line-height: 1.7;
  margin: 0 0 var(--space-6);
}
.feature-col h3::before {
  content: '';
  display: block;
  width: 24px;
  height: 2px;
  background: var(--accent-primary);
  margin-bottom: var(--space-4);
}
.feature-snippet {
  margin-top: auto;
  padding: var(--space-4);
  background: var(--surface-dark);
  border-radius: var(--radius-md);
  line-height: 1.8;
}
.feature-snippet code {
  color: var(--text-on-dark);
}
.feature-snippet code.muted {
  color: var(--accent-primary);
}

/* ── Close ── */
.close-section {
  padding-top: 0;
}

.stats-strip {
  padding: var(--space-10);
  background: var(--surface-dark);
  display: flex;
  justify-content: center;
  gap: var(--space-12);
  flex-wrap: wrap;
}
.stat { text-align: center; }
.stat-value { font-size: var(--text-3xl); font-weight: var(--weight-bold); color: var(--accent-light); }
.stat-label {
  font-size: var(--text-sm);
  color: var(--text-on-dark-muted);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  margin-top: var(--space-1);
}

.cta-footer { padding: 80px var(--space-10); text-align: center; max-width: 1120px; margin: 0 auto; }
.cta-footer h2 { font-size: var(--text-3xl); font-weight: var(--weight-bold); margin-bottom: var(--space-3); letter-spacing: -0.02em; }
.cta-sub { font-size: 15px; color: var(--text-tertiary); margin-bottom: var(--space-6); }
.cta-footer .auth-link { font-size: var(--text-base); color: var(--text-tertiary); margin-top: var(--space-4); }
.cta-footer .auth-link a { color: var(--status-pass); text-decoration: underline; text-underline-offset: 2px; transition: color 0.2s; }
.cta-footer .auth-link a:hover { color: #156B50; }

/* ==========================================================================
   19. Pages — Batch Bar
   ========================================================================== */

#batch-bar {
  display: none;
  position: sticky;
  bottom: 0;
  background: var(--surface-primary);
  border-top: 1px solid var(--surface-secondary);
  padding: var(--space-3) var(--space-4);
  align-items: center;
  gap: var(--space-3);
  z-index: 10;
}

/* ==========================================================================
   20. Status & Utility
   ========================================================================== */

.status-pass, .status-completed { color: var(--status-pass); }
.status-fail, .status-failed, .status-error { color: var(--status-fail); }
.status-running { color: var(--status-running); }
.status-queued { color: var(--status-queued); }

.badge-coming-soon {
  position: absolute;
  top: 8px;
  right: 12px;
  font-size: var(--text-xs);
  color: var(--text-muted);
  background: var(--surface-secondary);
  padding: 2px 8px;
  border-radius: var(--radius-md);
}

.detail-label {
  font-size: var(--text-sm);
  color: var(--text-tertiary);
  margin-bottom: var(--space-1);
}

.narrative {
  margin-top: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--surface-secondary);
  border-left: 3px solid var(--status-fail);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: var(--text-base);
  color: var(--text-secondary);
}

/* ==========================================================================
   20b. Failure-First Run Detail
   ========================================================================== */

.step-detail {
  border-left: 3px solid transparent;
  margin-bottom: 2px;
  border-radius: var(--radius-sm);
}
.step-detail.step-fail {
  border-left-color: var(--status-fail);
  background: rgba(220, 38, 38, 0.04);
}
.step-detail summary {
  cursor: pointer;
  padding: 8px 12px;
  font-size: var(--text-caption);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: none;
  box-shadow: none;
  border-radius: var(--radius-sm);
  font-weight: var(--weight-medium);
}
.step-detail summary:hover {
  background: rgba(46,184,138,0.06);
}
.step-detail summary::marker { content: ''; }
.step-detail summary::-webkit-details-marker { display: none; }
.step-detail .step-expanded {
  padding: 8px 12px 12px;
}

/* ==========================================================================
   21. Animations
   ========================================================================== */

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

/* ==========================================================================
   22. Responsive — Tablet (max-width: 1024px)
   ========================================================================== */

@media (max-width: 1024px) {
  .sidebar { width: 56px; }
  .sidebar-section-label { display: none; }
  .sidebar-item { padding: var(--space-2) var(--space-4); justify-content: center; }
  .sidebar-header .logo { display: none; }
  .sidebar-footer .user-info { display: none; }
  .env-selector { display: none; }
  main { margin-left: max(80px, calc(50% - 600px + 28px)); padding: var(--space-6); }

  /* Landing tablet */
  .hero-split { flex-direction: column; gap: var(--space-10); }
  .hero-copy { text-align: center; }
  .hero-sub { margin: 0 auto 40px; max-width: 480px; }
  .hero-actions { justify-content: center; }
  .features-grid { grid-template-columns: 1fr; gap: var(--space-10); max-width: 480px; margin: 0 auto; }
}

/* ==========================================================================
   23. Responsive — Mobile (max-width: 768px)
   ========================================================================== */

@media (max-width: 768px) {
  .sidebar { display: none; }
  .sidebar.drawer-open { display: flex; width: 280px; z-index: 60; }
  .sidebar-overlay.drawer-open { display: block; }
  .mobile-header { display: flex; }
  main { margin-left: 0; margin-top: 64px; padding: var(--space-4); border-radius: var(--radius-lg); }

  /* Landing responsive — mobile */
  .nav-inner { padding: 0 var(--space-4); }
  .landing-nav { height: 52px; }
  .landing-nav .logo { font-size: var(--text-lg); }
  .landing-nav .nav-links { gap: var(--space-3); }
  .landing-nav .login-link,
  .landing-nav .nav-link { font-size: var(--text-caption); }
  .landing-hero { padding: 100px 0 48px; }
  .hero-inner { padding: 0 var(--space-4); }
  .hero-split { flex-direction: column; gap: var(--space-8); }
  .hero-code { display: none; }
  .landing-hero h1 { font-size: 32px; text-align: center; }
  .hero-sub { font-size: var(--text-base); margin: 0 auto var(--space-8); text-align: center; }
  .hero-actions { justify-content: center; }
  .features-section { padding: 80px 0; }
  .features-inner { padding: 0 var(--space-4); }
  .features-grid { grid-template-columns: 1fr; gap: var(--space-10); }
  .feature-col h3 { font-size: var(--text-lg); }
  .code-block { padding: 20px; font-size: var(--text-sm); border-radius: var(--radius-lg); }
  .stats-strip { gap: var(--space-4); padding: var(--space-8) var(--space-4); }
  .stat { min-width: 90px; }
  .stat-value { font-size: var(--text-2xl); }
  .cta-footer { padding: var(--space-10) var(--space-4); }
  .cta-footer h2 { font-size: 24px; }
  .cta-footer .btn.btn-lg { width: 100%; text-align: center; display: block; }
}

/* ==========================================================================
   24. V2 Pipeline Step Viewer
   ========================================================================== */

.edn-step { padding: 8px 12px; border-bottom: 1px solid var(--border-default); font-size: var(--text-caption); display: flex; align-items: baseline; gap: var(--space-2); }
.edn-step:last-child { border-bottom: none; }
.edn-step-type { font-weight: var(--weight-semibold); min-width: 48px; }
.edn-step-type.type-call { color: var(--accent-text); }
.edn-step-type.type-assert { color: var(--status-warn); }
.edn-step-type.type-set, .edn-step-type.type-let { color: var(--text-muted); }
.edn-step-type.type-sleep, .edn-step-type.type-log { color: var(--text-muted); }
.edn-step-type.type-poll { color: var(--signal-drift); }
.edn-step-ref { color: var(--accent-text); text-decoration: none; }
.edn-step-ref:hover { text-decoration: underline; }
.edn-step-detail { color: var(--text-secondary); }

/* ==========================================================================
   25. Responsive — Small (max-width: 480px)
   ========================================================================== */

@media (max-width: 480px) {
  .landing-hero { padding: 72px 0 28px; }
  .hero-inner { padding: 0 var(--space-4); }
  .landing-hero h1 { font-size: 26px; line-height: 1.2; }
  .hero-sub { font-size: var(--text-base); line-height: 1.6; }
  .hero-actions { flex-direction: column; align-items: stretch; }
  .hero-actions .btn { width: 100%; text-align: center; padding: 14px 24px; min-width: 0; }
  .code-block { font-size: var(--text-xs); padding: var(--space-4); }
  .stats-strip { gap: var(--space-3); padding: 28px var(--space-4); }
  .stat { min-width: calc(50% - 8px); }
  .stat:last-child { min-width: 100%; }
  .cta-footer h2 { font-size: var(--text-2xl); }
  .cta-sub { font-size: var(--text-base); }
}
