/* ============================================================
   shared/base.css — Keywordit Design System
   Single source of truth for theme variables, reset, typography.
   Include BEFORE any page-specific <style> blocks.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;600;700&display=swap');

/* ── ROOT TOKENS ── */
:root {
  --font-sans: 'Space Grotesk', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', monospace;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 16px;
  --transition-fast: 0.15s ease;
  --transition-med: 0.25s ease;
}

/* ── DARK THEME (default) ── */
[data-theme="dark"] {
  --bg-base: #020203;
  --bg-surface: #080810;
  --bg-raised: #0e0e14;
  --bg-elevated: #14141c;
  --bg-hover: #1a1a24;
  --bg-input: #0e0e14;
  --text-primary: #e8e8f0;
  --text-secondary: #7a7a8c;
  --text-tertiary: #4a4a58;
  --text-muted: #2e2e3a;
  --border: #141418;
  --border-light: #1c1c24;
  --border-focus: #2dd4bf;

  --accent: #2dd4bf;
  --accent-dim: rgba(45,212,191,0.12);
  --accent-hover: rgba(45,212,191,0.18);
  --accent-text: #2dd4bf;

  --c-green: #22c55e;
  --c-green-dim: rgba(34,197,94,0.12);
  --c-amber: #f59e0b;
  --c-amber-dim: rgba(245,158,11,0.12);
  --c-red: #ef4444;
  --c-red-dim: rgba(239,68,68,0.10);
  --c-cyan: #06b6d4;
  --c-cyan-dim: rgba(6,182,212,0.10);
  --c-purple: #a78bfa;
  --c-purple-dim: rgba(167,139,250,0.10);
  --c-gray: #6b7280;
  --c-gray-dim: rgba(107,114,128,0.10);

  --status-ok: #22c55e;
  --status-warn: #f59e0b;
  --status-error: #ef4444;

  --shadow-dropdown: 0 12px 40px rgba(0,0,0,0.7);

  /* Legacy aliases for pages still using old names */
  --bg: var(--bg-base);
  --surface: var(--bg-surface);
  --teal: var(--accent);
  --teal-glow: var(--accent-dim);
  --text: var(--text-primary);
  --text-dim: var(--text-secondary);
  --red: var(--c-red);
  --green: var(--c-green);
  --amber: var(--c-amber);
}

/* ── LIGHT THEME ── */
[data-theme="light"] {
  --bg-base: #f5f5f7;
  --bg-surface: #ffffff;
  --bg-raised: #f0f0f3;
  --bg-elevated: #e8e8ec;
  --bg-hover: #e0e0e6;
  --bg-input: #ffffff;
  --text-primary: #1a1a2e;
  --text-secondary: #5a5a70;
  --text-tertiary: #8a8a9a;
  --text-muted: #b0b0c0;
  --border: #dcdce4;
  --border-light: #e8e8f0;
  --border-focus: #0d9488;

  --accent: #0d9488;
  --accent-dim: rgba(13,148,136,0.08);
  --accent-hover: rgba(13,148,136,0.14);
  --accent-text: #0d9488;

  --c-green: #16a34a;
  --c-green-dim: rgba(22,163,74,0.10);
  --c-amber: #d97706;
  --c-amber-dim: rgba(217,119,6,0.10);
  --c-red: #dc2626;
  --c-red-dim: rgba(220,38,38,0.08);
  --c-cyan: #0891b2;
  --c-cyan-dim: rgba(8,145,178,0.08);
  --c-purple: #7c3aed;
  --c-purple-dim: rgba(124,58,237,0.08);
  --c-gray: #6b7280;
  --c-gray-dim: rgba(107,114,128,0.08);

  --status-ok: #16a34a;
  --status-warn: #d97706;
  --status-error: #dc2626;

  --shadow-dropdown: 0 8px 32px rgba(0,0,0,0.12);

  /* Legacy aliases */
  --bg: var(--bg-base);
  --surface: var(--bg-surface);
  --teal: var(--accent);
  --teal-glow: var(--accent-dim);
  --text: var(--text-primary);
  --text-dim: var(--text-secondary);
  --red: var(--c-red);
  --green: var(--c-green);
  --amber: var(--c-amber);
}

/* ── RESET ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-sans);
  background: var(--bg-base);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

/* ── SHARED COMPONENTS ── */

/* Auth gate overlay */
.auth-gate {
  position: fixed; inset: 0; z-index: 9999;
  background: var(--bg-base);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-size: 13px;
  color: var(--text-secondary);
}
.auth-gate .msg { color: var(--text-tertiary); }

/* Theme toggle button */
.theme-toggle {
  width: 36px; height: 36px; border-radius: 50%;
  background: transparent; border: 1px solid var(--border);
  color: var(--text-secondary); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; transition: border-color var(--transition-fast);
}
.theme-toggle:hover { border-color: var(--accent); color: var(--text-primary); }

/* Badge / pill */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: 10px;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge-green { background: var(--c-green-dim); color: var(--c-green); }
.badge-amber { background: var(--c-amber-dim); color: var(--c-amber); }
.badge-red   { background: var(--c-red-dim);   color: var(--c-red); }
.badge-cyan  { background: var(--c-cyan-dim);  color: var(--c-cyan); }

/* Status dot */
.sys-dot {
  width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0;
}
.sys-dot.ok    { background: var(--status-ok);    box-shadow: 0 0 6px var(--status-ok); }
.sys-dot.warn  { background: var(--status-warn);  box-shadow: 0 0 6px var(--status-warn); }
.sys-dot.error { background: var(--status-error); box-shadow: 0 0 6px var(--status-error); }
.sys-dot.off   { background: var(--text-muted); }

/* Spinner */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ── COMMAND PALETTE ── */
.palette-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 10000;
  display: flex; align-items: flex-start; justify-content: center;
  padding-top: 20vh;
}
.palette-box {
  width: 560px; max-width: 90vw; max-height: 60vh;
  background: var(--bg-raised);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.palette-input {
  width: 100%; padding: 16px 20px;
  background: transparent; border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 16px; font-family: var(--font-sans);
  outline: none;
}
.palette-input::placeholder { color: var(--text-muted); }
.palette-results { overflow-y: auto; max-height: calc(60vh - 60px); }
.palette-category {
  padding: 8px 20px 4px;
  font-size: 10px; text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
  font-family: var(--font-mono);
}
.palette-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 20px; cursor: pointer;
  transition: background var(--transition-fast);
}
.palette-item:hover, .palette-item.active { background: var(--accent-dim); }
.palette-item-label { font-size: 14px; color: var(--text-primary); }
.palette-item-shortcut {
  font-size: 11px; color: var(--text-muted);
  font-family: var(--font-mono);
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

/* ── PIPELINE TAB ── */
#tab-pipeline { overflow-y: auto; flex: 1; min-height: 0; }
.pipeline-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; padding: 20px 24px; }
.pipeline-card { background: var(--bg-raised); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; }
.pipeline-card-title { font-family: var(--font-mono); font-size: 11px; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 12px; }
.pipeline-status-value { font-size: 24px; font-weight: 700; margin-bottom: 16px; }
.pipeline-status-value.ok { color: var(--status-ok); }
.pipeline-status-value.warn { color: var(--status-warn); }
.pipeline-status-value.error { color: var(--status-error); }
.pipeline-meta { font-size: 12px; color: var(--text-secondary); font-family: var(--font-mono); line-height: 1.8; margin-bottom: 16px; }
.pipeline-meta span { color: var(--text-primary); }
.stage-timeline { list-style: none; }
.stage-item { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 12px; }
.stage-icon { width: 20px; text-align: center; font-size: 14px; }
.stage-icon.done { color: var(--status-ok); }
.stage-icon.pending { color: var(--text-muted); }
.stage-icon.error { color: var(--status-error); }
.stage-icon.running { color: var(--c-amber); }
.stage-name { font-family: var(--font-mono); color: var(--text-secondary); flex: 1; }
.stage-duration { font-family: var(--font-mono); color: var(--text-tertiary); font-size: 11px; }
.run-history { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; }
.run-card { background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 12px; min-width: 100px; text-align: center; flex-shrink: 0; }
.run-card-date { font-family: var(--font-mono); font-size: 10px; color: var(--text-tertiary); margin-bottom: 4px; }
.run-card-golden { font-size: 20px; font-weight: 700; color: var(--c-green); }
.run-card-total { font-size: 10px; color: var(--text-muted); margin-top: 2px; }
.error-list { max-height: 300px; overflow-y: auto; }
.error-item { padding: 8px 0; border-bottom: 1px solid var(--border); }
.error-timestamp { font-family: var(--font-mono); font-size: 10px; color: var(--text-tertiary); }
.error-stage { font-family: var(--font-mono); font-size: 11px; color: var(--c-amber); margin-left: 8px; }
.error-msg { font-size: 12px; color: var(--c-red); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; cursor: pointer; }
.error-msg.expanded { white-space: normal; }
.error-explain { font-size: 11px; color: var(--text-secondary); margin-top: 4px; line-height: 1.5; }
.pipeline-status-explain { font-size: 12px; color: var(--text-secondary); line-height: 1.6; margin-bottom: 16px; padding: 10px 12px; background: var(--bg-surface); border-radius: var(--radius-md); border-left: 3px solid var(--status-warn); }
.btn-run-now { background: var(--accent); color: #000; border: none; padding: 10px 24px; border-radius: var(--radius-md); font-weight: 600; font-size: 13px; cursor: pointer; transition: all 0.2s; }
.btn-run-now:hover { box-shadow: 0 0 20px var(--accent-dim); transform: translateY(-1px); }
.btn-run-now:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }
@media (max-width: 768px) { .pipeline-grid { grid-template-columns: 1fr; } .pipeline-card[style*="span 2"] { grid-column: span 1; } }
