/* =========================================================================
   Vista4Ventures · Board Analytics — v2 "Quiet Authority"
   ========================================================================= */

:root {
  /* INK */
  --ink-950:#0a0e1a; --ink-900:#11172a; --ink-800:#1e2536; --ink-700:#2d3548;
  --ink-600:#475569; --ink-500:#64748b; --ink-400:#94a3b8; --ink-300:#cbd5e1;
  --ink-200:#e2e8f0; --ink-100:#eef1f6; --ink-50:#f6f7fa;

  /* PAPER */
  --paper:#fbfaf6; --paper-2:#ffffff; --paper-3:#f6f4ee;

  /* ACCENT */
  --accent-500:#5b5fc7; --accent-600:#4a4eb5;
  --accent-100:#e8e9f9; --accent-50:#f4f4fd;

  /* SEMANTIC */
  --pos:#047857; --pos-tint:#ecfdf5;
  --neg:#e11d48; --neg-tint:#fff1f2;
  --warn:#d97706; --warn-tint:#fffbeb;

  /* SHADOWS */
  --shadow-hairline: 0 0 0 1px rgba(15,23,42,0.06);
  --shadow-xs: 0 1px 0 rgba(15,23,42,0.04);
  --shadow-sm: 0 1px 2px rgba(15,23,42,0.05), 0 1px 1px rgba(15,23,42,0.03);
  --shadow-md: 0 4px 12px -2px rgba(15,23,42,0.08), 0 2px 4px -2px rgba(15,23,42,0.04);
  --shadow-lg: 0 10px 25px -5px rgba(15,23,42,0.10), 0 4px 6px -4px rgba(15,23,42,0.04);
  --ring-focus: 0 0 0 3px rgba(91,95,199,0.18);

  /* RADIUS */
  --r-sm:4px; --r-md:8px; --r-lg:12px; --r-xl:16px; --r-full:9999px;

  /* MOTION */
  --motion-fast:120ms; --motion:180ms;
  --ease:cubic-bezier(0.2, 0, 0, 1);

  /* FONTS */
  --font-display:'DM Serif Display', Georgia, 'Times New Roman', serif;
  --font-sans:'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --font-mono:'JetBrains Mono', 'SF Mono', Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink-800);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'tnum','cv11','ss01';
}
a { color: var(--accent-600); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ──────────────────────────────────────────────────────────────────────────
   LOGIN
   ────────────────────────────────────────────────────────────────────────── */
.login-bg {
  min-height: 100vh;
  display: grid; place-items: center;
  background:
    radial-gradient(900px 500px at 50% -10%, rgba(91,95,199,0.08), transparent 60%),
    var(--paper);
  padding: 24px;
}
.login-card {
  width: 100%; max-width: 380px;
  background: var(--paper-2);
  border-radius: var(--r-lg);
  padding: 40px 36px 28px;
  box-shadow: var(--shadow-md), var(--shadow-hairline);
}
.login-header { text-align: center; margin-bottom: 28px; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px;
  background: var(--ink-950);
  color: var(--paper);
  font-family: var(--font-display);
  font-size: 18px;
  letter-spacing: 0.02em;
  border-radius: var(--r-sm);
  margin-bottom: 14px;
}
.brand-title {
  font-family: var(--font-display);
  font-size: 22px; font-weight: 400;
  color: var(--ink-950);
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}
.brand-subtitle {
  font-size: 11px; color: var(--ink-500);
  margin: 0;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

/* ──────────────────────────────────────────────────────────────────────────
   PRIMITIVES
   ────────────────────────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 5px; }
.field-label {
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--ink-500);
}
.field input, .field select {
  font-family: inherit; font-size: 13px;
  height: 36px; padding: 0 12px;
  border: 1px solid var(--ink-200);
  border-radius: var(--r-sm);
  background: var(--paper-2);
  color: var(--ink-900);
  transition: border-color var(--motion-fast) var(--ease), box-shadow var(--motion-fast) var(--ease);
}
.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--accent-500);
  box-shadow: var(--ring-focus);
}

.btn {
  font-family: inherit; font-size: 13px; font-weight: 500;
  height: 36px; padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background var(--motion-fast) var(--ease), color var(--motion-fast) var(--ease), border-color var(--motion-fast) var(--ease);
}
.btn-primary { background: var(--ink-950); color: var(--paper); }
.btn-primary:hover { background: var(--ink-900); }
.btn-accent  { background: var(--accent-500); color: var(--paper); box-shadow: 0 1px 2px rgba(91,95,199,0.25); }
.btn-accent:hover { background: var(--accent-600); }
.btn-secondary { background: var(--paper-2); color: var(--ink-700); border-color: var(--ink-200); }
.btn-secondary:hover { background: var(--paper-3); }
.btn-ghost { background: transparent; color: var(--ink-600); }
.btn-ghost:hover { color: var(--ink-900); background: var(--paper-3); }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.55; cursor: default; box-shadow: none; }
.btn:disabled:hover { background: var(--paper-2); color: var(--ink-500); }
.dirty-dot {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--paper);
  margin-right: 2px;
  animation: pulse 1.2s ease-in-out infinite;
}

.alert {
  padding: 12px 14px;
  border-radius: var(--r-md);
  font-size: 13px;
  display: flex; align-items: center; gap: 10px;
}
.alert-error { background: var(--neg-tint); color: var(--neg); }
.alert-error strong { font-weight: 600; }

/* ──────────────────────────────────────────────────────────────────────────
   APP SHELL
   ────────────────────────────────────────────────────────────────────────── */
.app-shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--ink-950);
  color: var(--ink-200);
  padding: 22px 16px 18px;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  border-right: 1px solid rgba(255,255,255,0.04);
}
.sidebar-brand {
  display: flex; align-items: center; gap: 12px;
  padding: 0 6px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  margin-bottom: 18px;
}
.sidebar-brand .brand-mark {
  width: 36px; height: 36px; font-size: 15px;
  background: var(--paper); color: var(--ink-950);
  margin-bottom: 0;
}
.sidebar-brand-text { display: flex; flex-direction: column; line-height: 1.1; gap: 2px; }
.sidebar-brand-name {
  font-size: 13px; font-weight: 600; color: var(--paper);
}
.sidebar-brand-sub {
  font-size: 10px; color: var(--ink-500);
  letter-spacing: 0.12em; text-transform: uppercase;
}
.nav { display: flex; flex-direction: column; gap: 1px; flex: 1; overflow-y: auto; }
.nav-section {
  font-size: 10px; font-weight: 600;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--ink-500);
  margin: 16px 10px 4px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px 8px 12px;
  font-size: 13px; color: var(--ink-300);
  border-radius: var(--r-sm);
  cursor: pointer; user-select: none;
  position: relative;
  transition: background var(--motion-fast) var(--ease), color var(--motion-fast) var(--ease);
}
.nav-item:hover { background: rgba(255,255,255,0.04); color: var(--paper); text-decoration: none; }
.nav-item.active {
  background: rgba(91,95,199,0.15);
  color: var(--paper); font-weight: 500;
}
.nav-item.active::before {
  content: ''; position: absolute; left: 0; top: 6px; bottom: 6px; width: 2px;
  background: var(--accent-500); border-radius: 2px;
}
.nav-icon { width: 16px; height: 16px; flex-shrink: 0; opacity: 0.85; }
.nav-item.active .nav-icon { opacity: 1; color: var(--accent-500); }
.nav-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 6px;
  border-radius: var(--r-full);
  font-size: 10px; font-weight: 700;
  font-feature-settings: 'tnum';
}
.nav-badge.critical { background: var(--neg);  color: var(--paper); }
.nav-badge.warning  { background: var(--warn); color: var(--paper); }

.sidebar-footer {
  border-top: 1px solid rgba(255,255,255,0.06);
  padding-top: 14px; margin-top: 14px;
  font-size: 11px; color: var(--ink-500);
}
.sidebar-footer-email { color: var(--ink-300); word-break: break-all; margin-bottom: 4px; }
.sidebar-footer a { color: var(--ink-400); font-size: 11px; }
.sidebar-footer a:hover { color: var(--paper); }

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

.topbar {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 22px 32px 18px;
  background: var(--paper);
  position: sticky; top: 0; z-index: 10;
  border-bottom: 1px solid var(--ink-100);
}
.topbar-title {
  font-family: var(--font-display);
  font-size: 32px; font-weight: 400;
  color: var(--ink-950); margin: 0;
  letter-spacing: -0.015em;
}
.topbar-meta {
  display: flex; align-items: center; gap: 14px;
  font-size: 12px; color: var(--ink-500);
}
.topbar-period {
  font-family: var(--font-mono); font-size: 12px;
  color: var(--ink-700);
  padding: 4px 10px;
  background: var(--paper-3); border-radius: var(--r-sm);
}

.content { padding: 24px 32px 64px; max-width: 1640px; }

/* ──────────────────────────────────────────────────────────────────────────
   FILTER BAR
   ────────────────────────────────────────────────────────────────────────── */
.filter-card {
  background: var(--paper-2);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-xs), var(--shadow-hairline);
  margin-bottom: 24px;
  overflow: hidden;
}
.filter-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(340px, 1.6fr) minmax(340px, 1.6fr) auto;
  align-items: end;
}
.filter-section {
  padding: 16px 20px;
  border-right: 1px solid var(--ink-100);
}
.filter-section:last-child { border-right: none; }
.filter-section-title {
  font-size: 10px; font-weight: 600;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--ink-400);
  margin-bottom: 10px;
}
.filter-fields {
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}
.filter-actions {
  display: flex; align-items: center; gap: 8px;
  padding: 16px 20px;
}
.filter-pills {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 10px 20px 14px;
  border-top: 1px solid var(--ink-100);
  background: var(--paper-3);
}
.filter-pills:empty { display: none; }
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 4px 3px 10px;
  background: var(--paper-2);
  border: 1px solid var(--ink-200);
  border-radius: var(--r-full);
  font-size: 12px; color: var(--ink-700);
  transition: all var(--motion-fast) var(--ease);
}
.pill-x {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px;
  background: transparent;
  border: none;
  border-radius: var(--r-full);
  color: var(--ink-500);
  cursor: pointer;
  font-size: 14px; line-height: 1;
}
.pill-x:hover { background: var(--ink-100); color: var(--ink-900); }

/* ──────────────────────────────────────────────────────────────────────────
   KPI GRID
   ────────────────────────────────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 26px;
}
.kpi-grid.hero {
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 18px;
  margin-bottom: 18px;
}
.kpi {
  background: var(--paper-2);
  border-radius: var(--r-md);
  padding: 16px 18px 14px;
  box-shadow: var(--shadow-xs), var(--shadow-hairline);
  transition: box-shadow var(--motion) var(--ease), transform var(--motion) var(--ease);
  position: relative;
  overflow: hidden;
  min-height: 110px;
  display: flex; flex-direction: column; justify-content: space-between;
}
.kpi.hero { min-height: 138px; padding: 20px 22px 18px; }
.kpi:hover { box-shadow: var(--shadow-sm), var(--shadow-hairline); }

.kpi-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 8px;
}
.kpi-label {
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--ink-500);
}
.kpi-sparkline {
  width: 72px; height: 22px;
  flex-shrink: 0; margin-left: 8px;
}
.kpi.hero .kpi-sparkline { width: 96px; height: 28px; }

.kpi-value {
  font-family: var(--font-display);
  font-size: 28px; line-height: 1.1;
  color: var(--ink-950);
  font-feature-settings: 'tnum';
  margin: 0;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.kpi.hero .kpi-value { font-size: 38px; }

.kpi-footer {
  display: flex; align-items: center; gap: 8px;
  margin-top: 8px;
  font-size: 12px;
}
.delta-chip {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 2px 8px;
  border-radius: var(--r-full);
  font-size: 11px; font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.delta-chip.positive { background: var(--pos-tint); color: var(--pos); }
.delta-chip.negative { background: var(--neg-tint); color: var(--neg); }
.delta-chip.neutral  { background: var(--ink-100); color: var(--ink-600); }
.delta-meta { color: var(--ink-400); font-size: 11px; }

/* ──────────────────────────────────────────────────────────────────────────
   CARD
   ────────────────────────────────────────────────────────────────────────── */
.card {
  background: var(--paper-2);
  border-radius: var(--r-md);
  padding: 22px 24px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-xs), var(--shadow-hairline);
}
.card-flush { padding: 0; }
.card-header {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 16px;
  gap: 16px;
}
.card-flush .card-header { padding: 22px 24px 16px; margin-bottom: 0; }
.card-title {
  font-family: var(--font-display);
  font-size: 20px; font-weight: 400;
  color: var(--ink-950);
  margin: 0;
  letter-spacing: -0.01em;
}
.card-meta {
  font-size: 12px; color: var(--ink-500);
  display: flex; align-items: center; gap: 10px;
}
.card-meta .mono { font-family: var(--font-mono); font-size: 11px; }

/* ──────────────────────────────────────────────────────────────────────────
   TABLES — with sticky header row AND sticky first column
   ────────────────────────────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border-radius: 0 0 var(--r-md) var(--r-md);
}
table.data {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}
table.data thead th {
  position: sticky; top: 0;
  font-size: 10px; font-weight: 600;
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--ink-500);
  background: var(--paper-3);
  border-bottom: 1px solid var(--ink-200);
  padding: 11px 14px;
  text-align: left;
  cursor: pointer; user-select: none;
  white-space: nowrap;
  transition: color var(--motion-fast) var(--ease);
  z-index: 2;
}
/* sticky header + first column = highest priority */
table.data thead th:first-child {
  position: sticky; left: 0;
  z-index: 4;
  background: var(--paper-3);
  box-shadow: inset -1px 0 0 var(--ink-200);
}
table.data thead th:hover { color: var(--ink-800); }
table.data thead th.num { text-align: right; }
table.data thead th.sort-asc::after  { content: ' \2191'; color: var(--accent-500); }
table.data thead th.sort-desc::after { content: ' \2193'; color: var(--accent-500); }

table.data tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--ink-100);
  color: var(--ink-700);
  white-space: nowrap;
}
/* sticky body first column — gets opaque bg so other cells don't bleed through */
table.data tbody td:first-child {
  position: sticky; left: 0;
  z-index: 1;
  background: var(--paper-2);
  box-shadow: inset -1px 0 0 var(--ink-100);
}
table.data tbody td.num {
  text-align: right;
  font-family: var(--font-mono);
  font-feature-settings: 'tnum';
  font-variant-numeric: tabular-nums;
  color: var(--ink-800);
}
table.data tbody td.num.neg { color: var(--neg); }
table.data tbody tr {
  transition: background var(--motion-fast) var(--ease);
  position: relative;
}
table.data tbody tr:hover { background: var(--accent-50); }
/* row hover MUST also color the sticky first cell (otherwise it stays paper-2) */
table.data tbody tr:hover td:first-child {
  background: var(--accent-50);
  box-shadow: inset 2px 0 0 var(--accent-500), inset -1px 0 0 var(--ink-100);
}
.muted { color: var(--ink-400); }
.eur-prefix { color: var(--ink-400); font-weight: 400; margin-right: 2px; }

/* ──────────────────────────────────────────────────────────────────────────
   BADGES (color-hashed by content)
   ────────────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 10px;
  border-radius: var(--r-sm);
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
  font-family: var(--font-sans);
}
.badge-indigo  { background:#e8e9f9; color:#4338ca; }
.badge-emerald { background:#d1fae5; color:#047857; }
.badge-rose    { background:#ffe4e6; color:#be123c; }
.badge-amber   { background:#fef3c7; color:#b45309; }
.badge-sky     { background:#dbeafe; color:#1d4ed8; }
.badge-violet  { background:#ede9fe; color:#6d28d9; }
.badge-teal    { background:#ccfbf1; color:#0f766e; }
.badge-slate   { background:#e2e8f0; color:#334155; }
.badge-empty   { background: var(--ink-100); color: var(--ink-400); font-style: italic; }

/* ──────────────────────────────────────────────────────────────────────────
   CHART
   ────────────────────────────────────────────────────────────────────────── */
.chart-wrap { width: 100%; }
.apexcharts-tooltip {
  box-shadow: var(--shadow-lg) !important;
  border-radius: var(--r-md) !important;
  border: 1px solid var(--ink-200) !important;
  font-family: var(--font-sans) !important;
}
.apexcharts-tooltip-title {
  background: var(--paper-3) !important;
  border-bottom: 1px solid var(--ink-100) !important;
  font-weight: 600 !important;
  font-size: 12px !important;
}

/* ──────────────────────────────────────────────────────────────────────────
   SKELETON
   ────────────────────────────────────────────────────────────────────────── */
@keyframes shimmer {
  0%   { background-position: -400px 0; }
  100% { background-position: 400px 0; }
}
.skeleton {
  display: inline-block;
  background: linear-gradient(90deg, var(--ink-100) 0%, var(--ink-50) 50%, var(--ink-100) 100%);
  background-size: 800px 100%;
  animation: shimmer 1.4s linear infinite;
  border-radius: var(--r-sm);
  color: transparent;
  user-select: none;
}
.skel-line   { display: block; height: 12px; width: 100%; margin: 4px 0; }
.skel-value  { display: block; height: 28px; width: 60%; margin: 6px 0; }
.skel-spark  { display: block; height: 22px; width: 72px; }

/* ──────────────────────────────────────────────────────────────────────────
   EMPTY / LOADING DOT
   ────────────────────────────────────────────────────────────────────────── */
.empty {
  padding: 56px 0; text-align: center;
  color: var(--ink-400); font-size: 13px;
}
.loading-dot {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: var(--r-full);
  background: var(--accent-500);
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: 0.4; } 50% { opacity: 1; } }

/* ──────────────────────────────────────────────────────────────────────────
   TOM SELECT OVERRIDES (match design)
   ────────────────────────────────────────────────────────────────────────── */
.ts-wrapper { font-family: inherit; }
.ts-control {
  min-height: 36px !important;
  padding: 4px 8px !important;
  border: 1px solid var(--ink-200) !important;
  border-radius: var(--r-sm) !important;
  background: var(--paper-2) !important;
  font-size: 13px !important;
  box-shadow: none !important;
  transition: border-color var(--motion-fast) var(--ease), box-shadow var(--motion-fast) var(--ease) !important;
}
.ts-wrapper.focus .ts-control,
.ts-control:focus-within {
  border-color: var(--accent-500) !important;
  box-shadow: var(--ring-focus) !important;
}
.ts-control .item {
  background: var(--accent-100) !important;
  color: var(--accent-600) !important;
  border-radius: var(--r-sm) !important;
  padding: 2px 6px 2px 8px !important;
  font-size: 12px !important;
  font-weight: 500 !important;
  border: none !important;
  margin: 1px 2px !important;
}
.ts-control .item .remove {
  border-left: none !important;
  color: var(--accent-600) !important;
  padding-left: 4px !important;
}
.ts-dropdown {
  border-radius: var(--r-md) !important;
  border: 1px solid var(--ink-200) !important;
  box-shadow: var(--shadow-md) !important;
  margin-top: 4px !important;
  /* High z-index because dropdownParent='body' renders this above app shell */
  z-index: 10000 !important;
}
.ts-dropdown .active {
  background: var(--accent-50) !important;
  color: var(--ink-900) !important;
}

/* ──────────────────────────────────────────────────────────────────────────
   RESPONSIVE
   ────────────────────────────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .filter-row { grid-template-columns: 1fr; }
  .filter-section { border-right: none; border-bottom: 1px solid var(--ink-100); }
  .filter-section:last-of-type { border-bottom: none; }
}
@media (max-width: 920px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; flex-direction: row; padding: 12px; overflow-x: auto; }
  .sidebar-brand { padding: 0 16px 0 6px; border-bottom: none; border-right: 1px solid rgba(255,255,255,0.06); margin: 0 16px 0 0; }
  .nav { flex-direction: row; gap: 4px; overflow-x: auto; }
  .nav-section { display: none; }
  .sidebar-footer { display: none; }
  .topbar, .content { padding-left: 18px; padding-right: 18px; }
}
