/* =========================================================
   PULSE — Design System
   ========================================================= */

:root {
  /* Type */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --font-serif: 'Source Serif 4', 'Charter', Georgia, serif;

  /* Scale */
  --t-xs: 11px;
  --t-sm: 12px;
  --t-base: 13px;
  --t-md: 14px;
  --t-lg: 16px;
  --t-xl: 20px;
  --t-2xl: 28px;
  --t-3xl: 40px;
  --t-4xl: 56px;

  /* Spacing (4pt base) */
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 20px;
  --s-6: 24px; --s-8: 32px; --s-10: 40px; --s-12: 48px; --s-16: 64px;

  /* Radii */
  --r-sm: 4px; --r-md: 6px; --r-lg: 10px; --r-xl: 14px;

  /* Light palette (cool neutrals) */
  --bg:        #fafafa;
  --surface:   #ffffff;
  --surface-2: #f4f4f5;
  --surface-3: #ececee;
  --border:    #e4e4e7;
  --border-2:  #d4d4d8;
  --text:      #09090b;
  --text-2:    #52525b;
  --text-3:    #a1a1aa;
  --overlay:   rgba(9, 9, 11, 0.5);

  /* Semantic (RAG) — saturated, used as accents */
  --red:    #dc2626;
  --red-bg: #fef2f2;
  --amber:  #d97706;
  --amber-bg: #fffbeb;
  --green:  #059669;
  --green-bg: #ecfdf5;
  --blue:   #2563eb;
  --blue-bg:#eff6ff;

  /* Brand accent — subtle */
  --accent: #18181b;
  --accent-fg: #ffffff;

  /* Shadow */
  --sh-sm: 0 1px 2px rgba(9, 9, 11, 0.04);
  --sh-md: 0 1px 3px rgba(9, 9, 11, 0.06), 0 4px 12px rgba(9, 9, 11, 0.04);
  --sh-lg: 0 4px 16px rgba(9, 9, 11, 0.08), 0 24px 48px rgba(9, 9, 11, 0.06);

  /* Layout */
  --nav-w: 240px;
  --topbar-h: 48px;
}

[data-theme="dark"] {
  --bg:        #09090b;
  --surface:   #111113;
  --surface-2: #18181b;
  --surface-3: #232327;
  --border:    #27272a;
  --border-2:  #3f3f46;
  --text:      #fafafa;
  --text-2:    #a1a1aa;
  --text-3:    #71717a;
  --overlay:   rgba(0, 0, 0, 0.7);

  --red-bg: rgba(220, 38, 38, 0.1);
  --amber-bg: rgba(217, 119, 6, 0.1);
  --green-bg: rgba(5, 150, 105, 0.1);
  --blue-bg: rgba(37, 99, 235, 0.1);

  --accent: #fafafa;
  --accent-fg: #09090b;

  --sh-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --sh-md: 0 1px 3px rgba(0, 0, 0, 0.4), 0 4px 12px rgba(0, 0, 0, 0.3);
  --sh-lg: 0 4px 16px rgba(0, 0, 0, 0.5), 0 24px 48px rgba(0, 0, 0, 0.4);
}

/* Reset */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  font-size: var(--t-base);
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "cv11", "ss01";
}
h1, h2, h3, h4, h5, p { margin: 0; }
button { font-family: inherit; cursor: pointer; }
a { color: inherit; text-decoration: none; }

/* =========================================================
   PRIMITIVES
   ========================================================= */

.mono { font-family: var(--font-mono); font-feature-settings: "ss01"; }
.serif { font-family: var(--font-serif); }

.label-xs {
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
}

.kbd {
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 1px 5px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-2);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: var(--t-base);
  font-weight: 500;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  transition: all 0.1s ease;
  white-space: nowrap;
  height: 30px;
}
.btn:hover { background: var(--surface-2); }
.btn-primary {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}
.btn-primary:hover { opacity: 0.9; background: var(--accent); }
.btn-secondary {
  background: var(--surface);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--surface-2); border-color: var(--border-2); }
.btn-ghost { color: var(--text-2); }
.btn-ghost:hover { color: var(--text); background: var(--surface-2); }
.btn-lg { height: 36px; padding: 8px 16px; font-size: var(--t-md); }
.btn-sm { height: 26px; padding: 4px 10px; font-size: var(--t-sm); }

/* Input */
.input {
  width: 100%;
  padding: 8px 12px;
  font-size: var(--t-md);
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  transition: border-color 0.1s, box-shadow 0.1s;
}
.input:focus {
  outline: none;
  border-color: var(--text);
  box-shadow: 0 0 0 3px var(--surface-3);
}
.input::placeholder { color: var(--text-3); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
  font-size: var(--t-sm);
  font-weight: 500;
  color: var(--text-2);
}

/* Card */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
}
.card-body { padding: var(--s-5); }
.card-head {
  padding: var(--s-4) var(--s-5);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-title { font-size: var(--t-md); font-weight: 600; }

/* Badges / Pills */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  font-size: var(--t-xs);
  font-weight: 500;
  border-radius: 100px;
  background: var(--surface-2);
  color: var(--text-2);
  border: 1px solid var(--border);
  line-height: 1.5;
}
.pill-red { background: var(--red-bg); color: var(--red); border-color: color-mix(in oklab, var(--red) 25%, transparent); }
.pill-amber { background: var(--amber-bg); color: var(--amber); border-color: color-mix(in oklab, var(--amber) 25%, transparent); }
.pill-green { background: var(--green-bg); color: var(--green); border-color: color-mix(in oklab, var(--green) 25%, transparent); }
.pill-blue { background: var(--blue-bg); color: var(--blue); border-color: color-mix(in oklab, var(--blue) 25%, transparent); }

/* RAG dot */
.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-3);
  flex-shrink: 0;
}
.dot-red { background: var(--red); box-shadow: 0 0 0 3px color-mix(in oklab, var(--red) 15%, transparent); }
.dot-amber { background: var(--amber); box-shadow: 0 0 0 3px color-mix(in oklab, var(--amber) 15%, transparent); }
.dot-green { background: var(--green); box-shadow: 0 0 0 3px color-mix(in oklab, var(--green) 15%, transparent); }

/* Table */
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--t-base);
}
table.data th {
  text-align: left;
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
table.data td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.data tr:last-child td { border-bottom: none; }
table.data tr:hover td { background: var(--surface-2); }

/* Focus ring */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--border-2); }

/* Progress bar */
.bar-track {
  width: 100%;
  height: 6px;
  background: var(--surface-2);
  border-radius: 100px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  background: var(--text);
  border-radius: 100px;
  transition: width 0.3s ease;
}
.bar-fill.red { background: var(--red); }
.bar-fill.amber { background: var(--amber); }
.bar-fill.green { background: var(--green); }

/* =========================================================
   APP SHELL
   ========================================================= */

.app {
  display: grid;
  grid-template-columns: var(--nav-w) 1fr;
  min-height: 100vh;
}

.nav {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.nav-logo {
  width: 22px; height: 22px;
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-fg);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.nav-logo::after {
  content: "";
  position: absolute; inset: 0;
  background: radial-gradient(circle at center, var(--accent-fg) 0%, var(--accent-fg) 22%, transparent 22%);
  mask: radial-gradient(circle at center, transparent 45%, black 45%, black 55%, transparent 55%), radial-gradient(circle at center, black 22%, transparent 22%);
  -webkit-mask-composite: source-over;
  mask-composite: add;
  border-radius: 6px;
}
.nav-title {
  font-weight: 600;
  font-size: var(--t-md);
  letter-spacing: -0.01em;
}
.nav-project {
  padding: 12px 18px;
  font-size: var(--t-sm);
  color: var(--text-2);
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.nav-project:hover { background: var(--surface-2); }
.nav-project .sq {
  width: 18px; height: 18px;
  border-radius: 4px;
  background: linear-gradient(135deg, #e879f9, #818cf8);
}
.nav-sections { padding: 10px 10px; flex: 1; }
.nav-section {
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
  padding: 10px 10px 6px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border-radius: var(--r-md);
  font-size: var(--t-base);
  color: var(--text-2);
  cursor: pointer;
  margin-bottom: 1px;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active {
  background: var(--surface-2);
  color: var(--text);
  font-weight: 500;
}
.nav-item svg { width: 15px; height: 15px; flex-shrink: 0; }
.nav-item .count {
  margin-left: auto;
  font-size: 10px;
  color: var(--text-3);
  font-family: var(--font-mono);
}
.nav-footer {
  padding: 10px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, #fde047, #ec4899);
  color: #18181b;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
}
.nav-footer .who { display: flex; flex-direction: column; font-size: var(--t-sm); line-height: 1.3; }
.nav-footer .who strong { font-weight: 500; color: var(--text); }
.nav-footer .who span { color: var(--text-3); font-size: 10px; }

.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: var(--topbar-h);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 var(--s-6);
  gap: var(--s-4);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar .crumbs {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--t-base);
  color: var(--text-2);
  flex: 1;
  min-width: 0;
}
.topbar .crumbs .sep { color: var(--text-3); }
.topbar .crumbs .current { color: var(--text); font-weight: 500; }

.page { padding: var(--s-8) var(--s-6); max-width: 1280px; width: 100%; margin: 0 auto; flex: 1; }
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--s-4);
  margin-bottom: var(--s-8);
}
.page-title {
  font-size: var(--t-2xl);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.page-sub {
  color: var(--text-2);
  font-size: var(--t-md);
  margin-top: 6px;
}

/* Icon glyph */
.ic { width: 16px; height: 16px; flex-shrink: 0; display: inline-block; vertical-align: middle; }

/* =========================================================
   DIRECTION OVERRIDES
   ========================================================= */

/* Direction: command (terminal-dense) */
[data-direction="command"] {
  --font-sans: 'JetBrains Mono', ui-monospace, monospace;
  --t-base: 12px;
  --t-md: 12px;
  --t-xl: 16px;
  --t-2xl: 22px;
  --nav-w: 220px;
  --r-sm: 2px; --r-md: 3px; --r-lg: 4px; --r-xl: 6px;
}
[data-direction="command"] body { font-family: var(--font-mono); }
[data-direction="command"] .nav-title { font-family: var(--font-mono); letter-spacing: 0; }
[data-direction="command"] .page-title { font-family: var(--font-mono); font-weight: 500; }
[data-direction="command"] .card { border-radius: 4px; }
[data-direction="command"] .pill { border-radius: 2px; font-family: var(--font-mono); }
[data-direction="command"] .btn { border-radius: 3px; font-family: var(--font-mono); }
[data-direction="command"] .nav-item { border-radius: 3px; font-family: var(--font-mono); }
[data-direction="command"] .serif { font-family: var(--font-mono); }

/* Direction: editorial (calm, wide, serif headlines) */
[data-direction="editorial"] {
  --nav-w: 260px;
}
[data-direction="editorial"] .page { max-width: 1100px; padding: 56px 48px; }
[data-direction="editorial"] .page-title { font-family: var(--font-serif); font-weight: 400; font-size: 42px; letter-spacing: -0.03em; }
[data-direction="editorial"] .page-sub { font-family: var(--font-serif); font-style: italic; color: var(--text-2); }
[data-direction="editorial"] .card-title { font-family: var(--font-serif); font-weight: 600; }
[data-direction="editorial"] .page-head { margin-bottom: 48px; border-bottom: 1px solid var(--border); padding-bottom: 32px; align-items: flex-start; flex-direction: column; }
[data-direction="editorial"] .card { border-radius: 2px; box-shadow: none; border-color: var(--border); }
[data-direction="editorial"] .btn { border-radius: 2px; }
[data-direction="editorial"] .pill { border-radius: 2px; }

/* =========================================================
   UTILITIES
   ========================================================= */
.row { display: flex; align-items: center; gap: var(--s-3); }
.col { display: flex; flex-direction: column; }
.grow { flex: 1; }
.spacer { flex: 1; }
.gap-1 { gap: var(--s-1); } .gap-2 { gap: var(--s-2); } .gap-3 { gap: var(--s-3); }
.gap-4 { gap: var(--s-4); } .gap-5 { gap: var(--s-5); } .gap-6 { gap: var(--s-6); } .gap-8 { gap: var(--s-8); }
.mb-2 { margin-bottom: var(--s-2); } .mb-3 { margin-bottom: var(--s-3); }
.mb-4 { margin-bottom: var(--s-4); } .mb-6 { margin-bottom: var(--s-6); } .mb-8 { margin-bottom: var(--s-8); }
.mt-2 { margin-top: var(--s-2); } .mt-4 { margin-top: var(--s-4); } .mt-6 { margin-top: var(--s-6); }
.text-2 { color: var(--text-2); }
.text-3 { color: var(--text-3); }
.text-red { color: var(--red); }
.text-amber { color: var(--amber); }
.text-green { color: var(--green); }
.fw-500 { font-weight: 500; }
.fw-600 { font-weight: 600; }
.text-xs { font-size: var(--t-xs); }
.text-sm { font-size: var(--t-sm); }
.text-lg { font-size: var(--t-lg); }
.text-xl { font-size: var(--t-xl); }
