/* ELAN Factory — Premium dashboard theme
   Inspired by Mercury Bank / Ramp / Attio / Linear
   Sophisticated dark mode with warm neutrals and sage accent */

:root {
  /* DEFAULT THEME: Porcelain (light) — warm white + Tiffany blue */
  --bg: #faf9f6;
  --surface: #ffffff;
  --surface-2: #f3f1eb;
  --surface-3: #ebe8df;
  --surface-hover: #f6f4ee;

  /* Borders */
  --border: rgba(26, 22, 18, 0.08);
  --border-strong: rgba(26, 22, 18, 0.14);
  --border-soft: rgba(26, 22, 18, 0.05);

  /* Text */
  --text: #1a1612;
  --text-muted: #4e4539;
  --text-dim: #857a6a;
  --text-subtle: #a89c88;

  /* Accent — Tiffany blue */
  --accent: #0abab5;
  --accent-hover: #087a75;
  --accent-soft: rgba(10, 186, 181, 0.10);
  --accent-border: rgba(10, 186, 181, 0.24);

  /* Semantic (warm, not neon) */
  --pos: #1a7a44;
  --pos-soft: rgba(26, 122, 68, 0.08);
  --neg: #b03232;
  --neg-soft: rgba(176, 50, 50, 0.08);
  --warn: #a66a0a;
  --warn-soft: rgba(166, 106, 10, 0.08);
  --info: #1a4a9a;
  --info-soft: rgba(26, 74, 154, 0.08);

  /* Chart palette — muted, editorial */
  --chart-1: #0abab5;
  --chart-2: #c8a35f;
  --chart-3: #b03232;
  --chart-4: #6a4d8a;
  --chart-5: #1a4a9a;
  --chart-6: #c76b3a;
  --chart-7: #9a4d7a;
  --chart-8: #7a7a7a;

  /* Typography */
  --font-serif: 'Instrument Serif', 'Fraunces', Georgia, serif;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', Menlo, Consolas, monospace;

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

  /* Radius */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.5);

  /* Legacy aliases for old markup compatibility */
  --bg-card: var(--surface);
  --text-dim: #71717a;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }

html { font-feature-settings: 'cv02','cv03','cv04','cv11'; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.55;
  min-height: 100vh;
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(10, 186, 181, 0.05), transparent),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(200, 163, 95, 0.04), transparent);
}

/* ============ Header ============ */

header {
  position: sticky; top: 0; z-index: 50;
  background: rgba(250, 249, 246, 0.85);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid var(--border);
  padding: 0 var(--space-8);
  height: 64px;
  display: flex; align-items: center; gap: var(--space-6);
}

html[data-theme="noir"] header {
  background: rgba(10, 10, 11, 0.85);
}

header .logo {
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 400;
  letter-spacing: -0.5px;
  color: var(--text);
  font-style: italic;
  text-decoration: none;
  line-height: 1;
  white-space: nowrap;
}

header .logo em {
  color: var(--accent);
  font-style: italic;
  margin-right: 2px;
  font-weight: 500;
}

header nav {
  display: flex; gap: 0;
  margin-left: var(--space-4);
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
header nav::-webkit-scrollbar { display: none; }

header nav a {
  position: relative;
  color: var(--text-muted);
  text-decoration: none;
  padding: 0 var(--space-3);
  height: 64px;
  display: flex; align-items: center;
  font-size: 13px;
  font-weight: 500;
  transition: color 0.2s ease;
  letter-spacing: -0.1px;
  white-space: nowrap;
}

header nav a:hover { color: var(--text); }
header nav a.active { color: var(--text); font-weight: 500; }
header nav a.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: var(--space-4);
  right: var(--space-4);
  height: 1px;
  background: var(--accent);
}

header .pill-date {
  margin-left: auto;
  padding: 5px 12px;
  font-size: 11px;
  color: var(--text-dim);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  letter-spacing: 0.3px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ============ Main ============ */

main {
  max-width: 1240px;
  margin: 0 auto;
  padding: var(--space-12) var(--space-10) var(--space-16);
}

/* DISPLAY h1 — only decorative serif in the whole system.
   Everything else is sans-serif Inter for readability. */
h1 {
  font-family: var(--font-serif);
  font-size: 52px;
  font-weight: 400;
  letter-spacing: -1.8px;
  color: var(--text);
  line-height: 1.02;
  margin-bottom: var(--space-4);
}

h1 em {
  font-style: italic;
  color: var(--accent);
  font-weight: 400;
}

h2 {
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1.6px;
  margin: var(--space-12) 0 var(--space-5);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--border);
}

h3 {
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: var(--space-4);
  letter-spacing: -0.1px;
}

.subtitle {
  font-family: var(--font-sans);
  color: var(--text-muted);
  font-size: 15px;
  line-height: 1.65;
  margin-bottom: var(--space-10);
  max-width: 68ch;
  font-weight: 400;
}

/* ============ Grid ============ */

.grid { display: grid; gap: var(--space-4); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 800px) {
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  h1 { font-size: 36px; }
  main { padding: var(--space-8) var(--space-5) var(--space-12); }
}
@media (max-width: 600px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  main { padding: var(--space-6) var(--space-4) var(--space-12); }
  h1 { font-size: 28px; letter-spacing: -1px; }
  .subtitle { font-size: 14px; margin-bottom: var(--space-6); }
  header { padding: 0 var(--space-4); height: 56px; }
  header nav { margin-left: 0; gap: 0; }
  header nav a { padding: 0 var(--space-3); font-size: 12px; height: 56px; }
  header .logo { font-size: 18px; }
  header .pill-date { display: none; }
  .card, .kpi { padding: var(--space-4) var(--space-5); }
  .kpi .value { font-size: 24px; }
  .kpi .label { font-size: 10px; }
  .chart-wrap { height: 240px; }
  .chart-wrap.tall { height: 280px; }
  .section { padding: var(--space-5) var(--space-5); }
  .section h2 { font-size: 16px; }
  /* Tables wrap for horizontal scroll on mobile */
  .card > table, .section > table, main > table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }
  th, td { padding: var(--space-2) var(--space-3); font-size: 12px; }
  th { font-size: 10px; }
}

/* Mobile: scrollbar aesthetics */
@media (max-width: 600px) {
  ::-webkit-scrollbar { height: 4px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 2px; }
}

/* ============ Cards ============ */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  transition: border-color 0.2s ease;
}

.card:hover { border-color: var(--border-strong); }

/* ============ KPI ============ */

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5) var(--space-6);
  transition: all 0.15s ease;
  position: relative;
  overflow: hidden;
}

.kpi::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.08), transparent);
}

.kpi:hover { border-color: var(--border-strong); background: var(--surface-2); }

.kpi .label {
  font-family: var(--font-sans);
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: var(--space-3);
}

/* KPI numbers: sans-serif tabular — finance data must be unambiguous */
.kpi .value {
  font-family: var(--font-sans);
  font-size: 30px;
  font-weight: 500;
  letter-spacing: -0.8px;
  color: var(--text);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum', 'cv11';
}

.kpi .sub {
  font-family: var(--font-sans);
  color: var(--text-dim);
  font-size: 12px;
  margin-top: var(--space-3);
  line-height: 1.5;
}

.pos { color: var(--pos); }
.neg { color: var(--neg); }
.warn { color: var(--warn); }
.dim { color: var(--text-dim); }
.muted { color: var(--text-muted); }

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

table { width: 100%; border-collapse: collapse; font-size: 13px; }

th {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  color: var(--text-dim);
  font-weight: 500;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 1px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-soft);
  color: var(--text);
}

th.num, td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum';
  font-size: 13px;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255, 255, 255, 0.02); }

/* ============ Pills ============ */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  font-size: 11px;
  font-weight: 500;
  border-radius: 20px;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  letter-spacing: 0.1px;
  white-space: nowrap;
}

.pill.green, .pill.pos { background: var(--pos-soft); color: var(--pos); border-color: transparent; }
.pill.red, .pill.neg { background: var(--neg-soft); color: var(--neg); border-color: transparent; }
.pill.amber, .pill.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.blue, .pill.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.pill.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

/* ============ Bar ============ */

.bar {
  height: 6px;
  background: var(--surface-3);
  border-radius: 3px;
  overflow: hidden;
  margin: var(--space-2) 0;
}

.bar > div {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-hover));
  border-radius: 3px;
  transition: width 0.8s cubic-bezier(0.22, 1, 0.36, 1);
}

/* ============ Callouts ============ */

.callout {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius);
  margin: var(--space-4) 0;
  font-size: 13.5px;
  color: var(--text-muted);
  line-height: 1.65;
}

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

.callout.green { border-left-color: var(--pos); background: linear-gradient(90deg, var(--pos-soft), var(--surface)); }
.callout.red { border-left-color: var(--neg); background: linear-gradient(90deg, var(--neg-soft), var(--surface)); }
.callout.amber { border-left-color: var(--warn); background: linear-gradient(90deg, var(--warn-soft), var(--surface)); }

/* ============ Charts ============ */

.chart-wrap { position: relative; height: 300px; margin: var(--space-2) 0; }
.chart-wrap.tall { height: 380px; }
.chart-wrap.short { height: 220px; }

/* ============ Footer ============ */

footer {
  max-width: 1280px;
  margin: var(--space-16) auto var(--space-8);
  padding: var(--space-6) var(--space-8);
  color: var(--text-subtle);
  font-size: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
}

footer a { color: var(--text-muted); text-decoration: none; }
footer a:hover { color: var(--accent); }

/* ============ Code ============ */

code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--accent);
  border: 1px solid var(--border);
}

pre {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: var(--space-4);
  border-radius: var(--radius);
  overflow-x: auto;
  color: var(--text-muted);
  line-height: 1.65;
}

/* ============ Intercos advice block ============ */

.intercos-advice {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6) var(--space-8);
  margin: var(--space-12) 0 var(--space-4);
  position: relative;
}

.intercos-advice::before {
  content: '';
  position: absolute;
  top: 0;
  left: var(--space-8);
  right: var(--space-8);
  height: 2px;
  background: linear-gradient(90deg, var(--accent), transparent);
}

.intercos-advice .header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: var(--space-6);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: var(--space-3);
}

.intercos-advice .title {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 22px;
  color: var(--text);
  letter-spacing: -0.4px;
  line-height: 1.1;
}

.intercos-advice .from {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1.8px;
  font-weight: 500;
}

.intercos-advice ul { list-style: none; padding: 0; margin: 0; }

.intercos-advice li {
  padding: var(--space-5) 0;
  border-bottom: 1px solid var(--border-soft);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-muted);
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: var(--space-5);
  align-items: start;
}

.intercos-advice li:last-child { border-bottom: 0; }

.intercos-advice li .num {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 36px;
  color: var(--accent);
  font-weight: 400;
  line-height: 0.9;
  padding-top: 2px;
  letter-spacing: -1px;
}

.intercos-advice li strong {
  color: var(--text);
  font-weight: 600;
  display: block;
  margin-bottom: 4px;
  font-size: 14.5px;
}

@media (max-width: 600px) {
  .intercos-advice { padding: var(--space-5); }
  .intercos-advice li { grid-template-columns: 40px 1fr; gap: var(--space-3); padding: var(--space-4) 0; }
  .intercos-advice li .num { font-size: 28px; }
}

/* ============ KPI tooltip (hover for plain-language explanation) ============ */

.has-tooltip {
  position: relative;
  cursor: help;
  border-bottom: 1px dashed var(--text-dim);
}

.has-tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 10px);
  left: 0;
  min-width: 280px;
  max-width: 400px;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  font-size: 12.5px;
  font-weight: 400;
  font-style: normal;
  font-family: var(--font-sans);
  color: var(--text);
  line-height: 1.55;
  letter-spacing: 0;
  text-transform: none;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity 0.15s ease, transform 0.15s ease;
  z-index: 100;
  white-space: normal;
}

.has-tooltip:hover::after {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 700px) {
  .has-tooltip::after { min-width: 220px; left: auto; right: 0; }
}

/* ============ Period switcher ============ */

.period-switcher {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  margin-bottom: var(--space-6);
}

.period-switcher button {
  padding: 6px 14px;
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s ease;
  letter-spacing: 0.2px;
}

.period-switcher button:hover { color: var(--text); }
.period-switcher button.active {
  background: var(--accent);
  color: var(--bg);
}

/* ============ Section (brain-style) ============ */

.section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6) var(--space-8);
  margin-bottom: var(--space-4);
}

.section h2 {
  font-size: 19px;
  font-weight: 400;
  color: var(--text);
  text-transform: none;
  letter-spacing: -0.3px;
  margin: 0 0 var(--space-4);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--border);
  font-family: var(--font-serif);
  font-style: italic;
}

.section h2 .num {
  color: var(--accent);
  font-family: var(--font-mono);
  font-style: normal;
  font-size: 13px;
  margin-right: var(--space-3);
  font-weight: 600;
}

.section h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin: var(--space-5) 0 var(--space-2);
  text-transform: none;
  letter-spacing: -0.2px;
}

.section p, .section li { color: var(--text-muted); line-height: 1.65; font-size: 14px; }
.section ul, .section ol { padding-left: var(--space-5); margin-bottom: var(--space-3); }
.section li { margin-bottom: var(--space-2); }

.rule {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--surface-2);
  border-radius: var(--radius);
  margin-bottom: var(--space-2);
  border: 1px solid var(--border);
}

.rule .num { font-family: var(--font-mono); font-size: 11px; font-weight: 600; color: var(--accent); min-width: 26px; padding-top: 2px; }
.rule .text { font-size: 13px; color: var(--text-muted); line-height: 1.6; }
.rule .text strong { color: var(--text); font-weight: 600; }

table.schema { font-size: 11.5px; margin: var(--space-3) 0; }
table.schema th { background: var(--surface-2); padding: var(--space-2) var(--space-3); font-size: 10px; letter-spacing: 1px; }
table.schema td { padding: var(--space-2) var(--space-3); font-family: var(--font-mono); font-size: 11px; color: var(--text-muted); }
