/* ── Emmett Glass Design System ──────────────────────────────
   Dawn is the default theme. Graphite overrides via
   [data-theme="graphite"]. All surfaces consume CSS variables.
   ──────────────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { min-height: 100vh; }

:root {
  /* Dawn tokens (default) */
  --bg-base: linear-gradient(135deg, #e6ecff 0%, #f5e9f2 45%, #fff0e3 100%);
  --bg-glow-a: radial-gradient(circle at 80% 20%, rgba(139, 92, 246, 0.25), transparent 55%);
  --bg-glow-b: radial-gradient(circle at 10% 90%, rgba(59, 130, 246, 0.20), transparent 50%);
  --surface: rgba(255, 255, 255, 0.55);
  --surface-elevated: rgba(255, 255, 255, 0.75);
  --surface-border: rgba(255, 255, 255, 0.60);
  --surface-border-strong: rgba(15, 23, 42, 0.08);
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --accent-gradient: linear-gradient(135deg, #6366f1, #ec4899);
  --accent-solid: #6366f1;
  --accent-solid-rgb: 99, 102, 241;
  --success: #16a34a;
  --success-rgb: 22, 163, 74;
  --warning: #ca8a04;
  --warning-rgb: 202, 138, 4;
  --error: #dc2626;
  --error-rgb: 220, 38, 38;
  --text-muted-rgb: 148, 163, 184;
  --highlight-inner: rgba(255, 255, 255, 0.80);
  --shadow-outer: rgba(15, 23, 42, 0.15);

  /* Scale */
  --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: 8px; --radius-md: 12px; --radius-lg: 16px;
  --font-primary: -apple-system, "SF Pro Display", system-ui, "Inter", sans-serif;
  --font-mono: "SF Mono", ui-monospace, Menlo, monospace;
}

[data-theme="graphite"] {
  --bg-base: radial-gradient(ellipse at 30% 10%, #1e293b, #030712 70%);
  --bg-glow-a: radial-gradient(circle at 75% 85%, rgba(56, 189, 248, 0.18), transparent 50%);
  --bg-glow-b: radial-gradient(circle at 15% 25%, rgba(168, 85, 247, 0.12), transparent 45%);
  --surface: rgba(255, 255, 255, 0.06);
  --surface-elevated: rgba(255, 255, 255, 0.10);
  --surface-border: rgba(255, 255, 255, 0.08);
  --surface-border-strong: rgba(255, 255, 255, 0.12);
  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --accent-gradient: linear-gradient(135deg, #38bdf8, #a855f7);
  --accent-solid: #38bdf8;
  --accent-solid-rgb: 56, 189, 248;
  --success: #4ade80;
  --success-rgb: 74, 222, 128;
  --warning: #facc15;
  --warning-rgb: 250, 204, 21;
  --error: #f87171;
  --error-rgb: 248, 113, 113;
  --text-muted-rgb: 148, 163, 184;
  --highlight-inner: rgba(255, 255, 255, 0.10);
  --shadow-outer: rgba(0, 0, 0, 0.50);
}

body {
  font-family: var(--font-primary);
  color: var(--text-primary);
  background: var(--bg-base);
  background-attachment: fixed;
  transition: color 200ms ease, background 200ms ease;
  font-size: 14px;
  line-height: 1.5;
}

body::before, body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
  transition: background 200ms ease;
}
body::before { background: var(--bg-glow-a); }
body::after  { background: var(--bg-glow-b); }

/* ── Glass primitive ─── */
.glass {
  background: var(--surface);
  backdrop-filter: blur(20px) saturate(170%);
  -webkit-backdrop-filter: blur(20px) saturate(170%);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  box-shadow:
    0 1px 0 var(--highlight-inner) inset,
    0 8px 24px -12px var(--shadow-outer);
  transition: background 200ms ease, border-color 200ms ease, box-shadow 200ms ease;
}
.glass-elevated {
  background: var(--surface-elevated);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  box-shadow:
    0 1px 0 var(--highlight-inner) inset,
    0 12px 32px -12px var(--shadow-outer);
}

/* Apply glass automatically to common container classes */
.card, .section, .venture-card, .decision-card, .mockup,
.venture-detail-grid > * {
  background: var(--surface);
  backdrop-filter: blur(20px) saturate(170%);
  -webkit-backdrop-filter: blur(20px) saturate(170%);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  box-shadow:
    0 1px 0 var(--highlight-inner) inset,
    0 8px 24px -12px var(--shadow-outer);
  transition: background 200ms ease, border-color 200ms ease, box-shadow 200ms ease;
}

/* Default padding for bare .card usage (overrideable inline). Growth-tool
   cards, status cards, and other compact tiles were rendering flush to the
   card edge with no inner gutter. */
.card { padding: var(--space-4); }

/* ── Typography ─── */
h1, .page-title {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  margin: 0 0 4px 0;
}
h2, .section-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  margin: 0 0 12px 0;
}
.mono, code {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}
.text-muted { color: var(--text-muted); }
.card-label {
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* ── Nav (top bar) ─── */
.nav {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  margin: var(--space-4) var(--space-5) var(--space-5);
  padding: var(--space-3) var(--space-5);
  background: var(--surface);
  backdrop-filter: blur(20px) saturate(170%);
  -webkit-backdrop-filter: blur(20px) saturate(170%);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-lg);
  box-shadow:
    0 1px 0 var(--highlight-inner) inset,
    0 8px 24px -12px var(--shadow-outer);
}
.nav-brand { display: flex; align-items: baseline; gap: 6px; }
.nav-logo { font-size: 14px; }
.nav-name {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}
.nav-sub {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
  font-family: var(--font-mono);
}
.nav-links {
  display: flex;
  flex: 1;
  gap: 2px;
  margin-left: var(--space-5);
  flex-wrap: wrap;
}
.nav-link {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  transition: color 150ms ease, background 150ms ease;
}
.nav-link:hover { color: var(--text-primary); background: var(--surface-elevated); }
.nav-link.active { color: var(--text-primary); background: var(--surface-elevated); }

/* Theme toggle */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-secondary);
  background: var(--surface-elevated);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color 150ms ease, background 150ms ease;
  letter-spacing: 0.06em;
}
.theme-toggle:hover { color: var(--text-primary); background: var(--surface); }

/* ── Main ─── */
.main {
  margin: 0 var(--space-5) var(--space-5);
  padding: 0 var(--space-5) var(--space-5);
  min-height: calc(100vh - 140px);
}

/* ── Page header ─── */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: var(--space-5);
  gap: var(--space-4);
  flex-wrap: wrap;
}
.health-line {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 6px;
  font-family: var(--font-mono);
}
.header-meta { display: flex; gap: var(--space-4); align-items: center; }
.meta-item { color: var(--text-secondary); font-size: 12.5px; }

/* ── KPI + venture cards ─── */
.venture-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}
.venture-detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-6);
}
.venture-card {
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-decoration: none;
  color: inherit;
  transition: transform 150ms ease, box-shadow 150ms ease, border-color 150ms ease;
}
.venture-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent-solid);
  box-shadow:
    0 1px 0 var(--highlight-inner) inset,
    0 16px 40px -16px var(--shadow-outer);
}
.venture-card-header { display: flex; justify-content: space-between; align-items: flex-start; }
.venture-name { font-size: 15px; font-weight: 600; color: var(--text-primary); }
.venture-domain { font-size: 11px; color: var(--text-muted); margin-top: 2px; font-family: var(--font-mono); }
.venture-mrr {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  margin-top: 8px;
}
.venture-mrr-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.10em;
  font-family: var(--font-mono);
  margin-top: 2px;
}
.venture-delta { font-size: 11.5px; margin-top: 4px; font-weight: 500; }
.venture-delta.positive { color: var(--success); }
.venture-delta.negative { color: var(--error); }
.venture-stats { display: flex; gap: 14px; font-size: 11.5px; color: var(--text-secondary); margin-top: 6px; }

/* Reusable KPI card */
.kpi-card { padding: var(--space-5); }
.kpi-label {
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-family: var(--font-mono);
}
.kpi-number {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.03em;
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
}
.kpi-number.accent {
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.kpi-delta { font-size: 11px; font-weight: 500; margin-top: 4px; color: var(--success); }
.kpi-delta.negative { color: var(--error); }
.kpi-delta.neutral { color: var(--text-muted); }

/* ── Section ─── */
.section {
  padding: var(--space-5) var(--space-6);
  margin-bottom: var(--space-5);
}

/* ── Table ─── */
.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  backdrop-filter: blur(20px) saturate(170%);
  -webkit-backdrop-filter: blur(20px) saturate(170%);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow:
    0 1px 0 var(--highlight-inner) inset,
    0 8px 24px -12px var(--shadow-outer);
}
.table th {
  background: var(--surface-elevated);
  padding: 10px 14px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  text-align: left;
  border-bottom: 1px solid var(--surface-border);
  font-family: var(--font-mono);
}
.table td {
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-primary);
  border-bottom: 1px solid var(--surface-border);
}
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--surface-elevated); }

/* ── Status ─── */
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  vertical-align: middle;
}
.status-dot.status-active   { background: var(--success); box-shadow: 0 0 8px var(--success); }
.status-dot.status-building { background: var(--warning); }
.status-dot.status-parked   { background: var(--text-muted); }
.status-dot.status-killed   { background: var(--error); }

.status-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-family: var(--font-mono);
}
.status-badge.status-active   { background: rgba(var(--success-rgb), 0.15); color: var(--success); }
.status-badge.status-building { background: rgba(var(--warning-rgb), 0.15); color: var(--warning); }
.status-badge.status-parked   { background: rgba(var(--text-muted-rgb), 0.15); color: var(--text-muted); }
.status-badge.status-killed   { background: rgba(var(--error-rgb), 0.15); color: var(--error); }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
}
.badge-alert {
  background: rgba(var(--error-rgb), 0.15);
  color: var(--error);
  text-decoration: none;
}

/* ── Buttons + forms ─── */
.btn-primary, button[type="submit"]:not(.btn-ghost):not([style*="background"]) {
  background: var(--accent-solid);
  color: white;
  border: none;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: opacity 150ms ease, transform 150ms ease;
}
.btn-primary:hover, button[type="submit"]:hover:not(.btn-ghost) { opacity: 0.9; }
.btn-ghost {
  background: var(--surface-elevated);
  color: var(--text-secondary);
  border: 1px solid var(--surface-border);
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  font-family: inherit;
  transition: color 150ms ease, background 150ms ease;
}
.btn-ghost:hover { color: var(--text-primary); background: var(--surface); }

input[type="text"], input[type="email"], input[type="date"],
input[type="number"], input[type="password"], input[type="url"],
textarea, select {
  background: var(--surface-elevated);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 14px;
  color: var(--text-primary);
  font-family: inherit;
  width: 100%;
  box-sizing: border-box;
  transition: border-color 150ms ease, background 150ms ease, box-shadow 150ms ease;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent-solid);
  box-shadow: 0 0 0 3px rgba(var(--accent-solid-rgb), 0.15);
}

/* ── Decision card ─── */
.decision-card {
  padding: var(--space-4);
  margin-bottom: var(--space-3);
}
.decision-type {
  font-size: 10.5px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-family: var(--font-mono);
}
.decision-title { font-size: 14px; font-weight: 500; margin: 4px 0; color: var(--text-primary); }
.cfo-line { font-size: 12px; color: var(--text-muted); margin: 4px 0; }
.link-accent { color: var(--accent-solid); font-weight: 500; font-size: 13px; text-decoration: none; }
.link-accent:hover { text-decoration: underline; }

/* ── Empty state + misc ─── */
.empty-state {
  color: var(--text-muted);
  text-align: center;
  padding: var(--space-7) var(--space-4);
  font-style: italic;
  font-size: 13.5px;
}
.sparkline { font-family: var(--font-mono); font-size: 16px; color: var(--accent-solid); }
.result-success { color: var(--success); }
.result-failed  { color: var(--error); }
.result-pending { color: var(--warning); }

/* ── Links ─── */
a { color: var(--accent-solid); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Accessibility ─── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
  }
}

/* ── Table scroll wrapper (used across all table-rendering routes) ─── */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

/* ── Hamburger toggle (desktop: hidden) ─── */
.nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  font-size: 18px;
  line-height: 1;
  background: var(--surface-elevated);
  color: var(--text-secondary);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: inherit;
}
.nav-toggle:hover { color: var(--text-primary); background: var(--surface); }

/* ── Sticky venture sub-nav scroll hint (visible on mobile only) ─── */
.venture-subnav { position: relative; }
.venture-subnav::after {
  content: '';
  position: absolute;
  right: 0; top: 0; bottom: 0;
  width: 24px;
  background: linear-gradient(to right, transparent, var(--surface));
  pointer-events: none;
  opacity: 0;
  transition: opacity 150ms ease;
  border-top-right-radius: var(--radius-md);
  border-bottom-right-radius: var(--radius-md);
}

/* ── Mobile breakpoints ─────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Nav collapses to hamburger + drawer */
  .nav {
    flex-wrap: wrap;
    padding: var(--space-2) var(--space-3);
    gap: var(--space-2);
    margin: var(--space-2);
  }
  .nav-brand { flex: 1; min-width: 0; }
  .nav-links {
    display: none;
    order: 99;
    flex-basis: 100%;
    margin-left: 0;
  }
  .nav-links.open {
    display: flex;
    flex-direction: column;
    gap: 0;
    margin-top: var(--space-3);
    padding-top: var(--space-3);
    border-top: 1px solid var(--surface-border);
  }
  .nav-links.open .nav-link {
    padding: 10px 12px;
    font-size: 14px;
  }
  .nav-toggle { display: inline-flex; }
  .theme-toggle { padding: 6px 8px; }
  .theme-toggle .label-text { display: none; }

  /* Main + page header */
  .main {
    margin: 0 var(--space-2) var(--space-3);
    padding: 0 var(--space-3) var(--space-3);
  }
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-2);
  }
  .header-meta { flex-wrap: wrap; gap: var(--space-2); }

  /* Sections + cards tighten padding */
  .section { padding: var(--space-4); }
  .venture-card { padding: var(--space-4); }
  .kpi-card { padding: var(--space-4); }
  .kpi-number { font-size: 22px; }
  .venture-mrr { font-size: 22px; }

  /* Grids collapse to single column */
  .venture-detail-grid { grid-template-columns: 1fr; }
  .venture-grid { grid-template-columns: 1fr; }

  /* Sticky venture sub-nav scroll hint reveals */
  .venture-subnav::after { opacity: 1; }

  /* Any direct form button rows wrap to avoid overflow */
  form > div[style*="display:flex"][style*="gap:"]:not([style*="flex-wrap"]) { flex-wrap: wrap; }

  /* Collapse inline 2-col / 3-col grids (e.g. "1fr 1fr", "2fr 1fr 1fr",
     "1fr 1fr 1fr") to a single column on narrow screens. Does not touch
     auto-fit minmax() grids — those already self-stack. Substring match
     on "1fr 1fr" also covers "1fr 1fr 1fr". */
  div[style*="grid-template-columns:1fr 1fr"],
  div[style*="grid-template-columns: 1fr 1fr"],
  div[style*="grid-template-columns:2fr 1fr"],
  div[style*="grid-template-columns: 2fr 1fr"] {
    grid-template-columns: 1fr !important;
  }
}

@media (max-width: 480px) {
  .page-title { font-size: 22px; }
  h1, .page-title { font-size: 22px; }
  .section { padding: var(--space-3); }
  .nav { margin: var(--space-1); }
  .main { margin: 0 var(--space-1) var(--space-3); padding: 0 var(--space-2) var(--space-3); }
}
