/* ===== Datavise Design Tokens ===== */
:root {
  /* Surfaces */
  --bg: #0A0D14;
  --bg-2: #0E1320;
  --surface: #131722;
  --surface-2: #181D2B;
  --surface-3: #1F2536;
  --surface-hover: #1c2334;

  /* Borders */
  --border: #232938;
  --border-strong: #2D3447;
  --border-subtle: #1A2030;

  /* Text */
  --text: #E6E9EF;
  --text-2: #A4ABBE;
  --text-3: #6B7385;
  --text-4: #4B5366;

  /* Brand */
  --accent: #4F8CFF;
  --accent-2: #2D6FF7;
  --accent-soft: rgba(79, 140, 255, 0.12);
  --accent-ring: rgba(79, 140, 255, 0.35);

  /* AI / Agent */
  --ai: #A78BFA;
  --ai-2: #8B5CF6;
  --ai-soft: rgba(167, 139, 250, 0.12);
  --ai-ring: rgba(167, 139, 250, 0.35);

  /* Signals */
  --success: #34D399;
  --success-soft: rgba(52, 211, 153, 0.12);
  --warn: #F59E0B;
  --warn-soft: rgba(245, 158, 11, 0.12);
  --danger: #F87171;
  --danger-soft: rgba(248, 113, 113, 0.12);
  --info: #38BDF8;
  --info-soft: rgba(56, 189, 248, 0.12);

  /* Radii */
  --r-xs: 4px;
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 12px;
  --r-xl: 16px;

  /* Shadow */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 16px 40px rgba(0,0,0,0.55);
  --shadow-glow: 0 0 0 1px var(--accent-ring), 0 8px 24px rgba(79,140,255,0.18);

  /* Type */
  --font-ui: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;

  /* Density */
  --row-h: 40px;
  --pad: 16px;
}

/* Light theme */
body[data-theme="light"] {
  --bg: #F5F6F8;
  --bg-2: #ECEEF2;
  --surface: #FFFFFF;
  --surface-2: #F7F8FA;
  --surface-3: #EEF0F4;
  --surface-hover: #F1F3F7;

  --border: #E2E5EB;
  --border-strong: #C9CED7;
  --border-subtle: #ECEEF2;

  --text: #0F1422;
  --text-2: #4B5366;
  --text-3: #6B7385;
  --text-4: #98A0B0;

  --accent-soft: rgba(79, 140, 255, 0.10);
  --ai-soft: rgba(139, 92, 246, 0.10);
  --success-soft: rgba(16, 161, 110, 0.10);
  --warn-soft: rgba(217, 119, 6, 0.10);
  --danger-soft: rgba(220, 38, 38, 0.10);
  --info-soft: rgba(2, 132, 199, 0.10);

  --success: #10A16E;
  --warn: #D97706;
  --danger: #DC2626;
  --info: #0284C7;
  --ai: #8B5CF6;

  --shadow-sm: 0 1px 2px rgba(15,20,34,0.06);
  --shadow-md: 0 4px 12px rgba(15,20,34,0.08);
  --shadow-lg: 0 16px 40px rgba(15,20,34,0.12);
}
body[data-theme="light"] .btn.primary { color: #FFFFFF; }
body[data-theme="light"] .avatar.agent { color: #6D28D9; }
body[data-theme="light"] .insight-strip {
  background: linear-gradient(180deg, rgba(139,92,246,0.06), rgba(139,92,246,0.02));
  border-color: rgba(139,92,246,0.2);
}
body[data-theme="light"] .ai-glyph { color: #FFFFFF; }
body[data-theme="light"] ::-webkit-scrollbar-thumb { background: #D5D9E1; border-color: var(--bg); }
body[data-theme="light"] .ai-surface {
  background:
    radial-gradient(1200px 200px at 100% -50%, rgba(139,92,246,0.06), transparent 60%),
    var(--surface);
}
body[data-theme="light"] .aurora {
  background:
    radial-gradient(600px 240px at 10% 0%, rgba(79,140,255,0.07), transparent 70%),
    radial-gradient(500px 200px at 90% 0%, rgba(139,92,246,0.06), transparent 70%);
}
body[data-theme="light"] .kbd { background: #FFFFFF; }
body[data-theme="light"] .nav-item.active { background: var(--accent-soft); }
body[data-theme="light"] .tbl thead th { background: var(--bg-2); }

/* Density modes via data attribute on body */
body[data-density="compact"] {
  --row-h: 32px;
  --pad: 12px;
}
body[data-density="cozy"] {
  --row-h: 48px;
  --pad: 20px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-size: 13.5px;
  line-height: 1.5;
  letter-spacing: -0.005em;
  overflow: hidden;
}

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; padding: 0; }
input, textarea, select { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }

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

/* ============== Reusable atoms ============== */
.mono { font-family: var(--font-mono); font-feature-settings: "tnum" 1, "ss01" 1; }
.muted { color: var(--text-2); }
.dim { color: var(--text-3); }

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

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-2);
  white-space: nowrap;
  line-height: 1.4;
}
.chip.success { color: var(--success); background: var(--success-soft); border-color: rgba(52,211,153,0.25); }
.chip.warn { color: var(--warn); background: var(--warn-soft); border-color: rgba(245,158,11,0.25); }
.chip.danger { color: var(--danger); background: var(--danger-soft); border-color: rgba(248,113,113,0.25); }
.chip.info { color: var(--info); background: var(--info-soft); border-color: rgba(56,189,248,0.25); }
.chip.ai { color: var(--ai); background: var(--ai-soft); border-color: rgba(167,139,250,0.3); }
.chip.brand { color: var(--accent); background: var(--accent-soft); border-color: rgba(79,140,255,0.3); }
.chip .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  transition: background .15s, border-color .15s, transform .1s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-3); border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #0a0d14; font-weight: 600; }
.btn.primary:hover { background: #6BA0FF; border-color: #6BA0FF; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.ai {
  background: linear-gradient(180deg, rgba(167,139,250,0.16), rgba(167,139,250,0.08));
  border-color: rgba(167,139,250,0.3);
  color: var(--ai);
}
.btn.ai:hover { background: rgba(167,139,250,0.18); }
.btn.sm { padding: 4px 8px; font-size: 11.5px; }
.btn.icon { padding: 6px; aspect-ratio: 1; justify-content: center; }

.divider { height: 1px; background: var(--border-subtle); width: 100%; }
.vdivider { width: 1px; background: var(--border-subtle); height: 100%; align-self: stretch; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-subtle);
}
.card-title {
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-2);
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-title .accent-bar {
  width: 3px;
  height: 14px;
  background: var(--accent);
  border-radius: 2px;
}
.card-title.ai .accent-bar { background: var(--ai); }
.card-body { padding: 16px; }

.section-label {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Avatar */
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--text);
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
  border: 1px solid var(--border);
  letter-spacing: -0.02em;
}
.avatar.lg { width: 40px; height: 40px; font-size: 14px; }
.avatar.xl { width: 56px; height: 56px; font-size: 18px; }
.avatar.sm { width: 22px; height: 22px; font-size: 10px; }
.avatar.agent {
  background: linear-gradient(135deg, rgba(167,139,250,0.3), rgba(79,140,255,0.3));
  border-color: rgba(167,139,250,0.4);
  color: var(--ai);
  position: relative;
}
.avatar.agent::after {
  content: "";
  position: absolute;
  bottom: -1px; right: -1px;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--ai);
  border: 2px solid var(--surface);
  box-shadow: 0 0 6px var(--ai);
}

/* Spark sizes */
.spark { display: block; }

/* Subtle scanline / grain on AI surfaces */
.ai-surface {
  background:
    radial-gradient(1200px 200px at 100% -50%, rgba(167,139,250,0.08), transparent 60%),
    var(--surface);
  border: 1px solid var(--border);
}

/* Skeleton pulse */
@keyframes pulse-soft {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}
.pulse-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--ai);
  box-shadow: 0 0 8px var(--ai);
  animation: pulse-soft 1.6s ease-in-out infinite;
}
.pulse-dot.live { background: var(--success); box-shadow: 0 0 8px var(--success); }

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

/* utility */
.row { display: flex; align-items: center; }
.col { display: flex; flex-direction: column; }
.gap-4 { gap: 4px; } .gap-6 { gap: 6px; } .gap-8 { gap: 8px; }
.gap-12 { gap: 12px; } .gap-16 { gap: 16px; } .gap-24 { gap: 24px; }
.grow { flex: 1; }
.center { display: flex; align-items: center; justify-content: center; }
.between { display: flex; align-items: center; justify-content: space-between; }
.right { margin-left: auto; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

h1,h2,h3,h4 { margin: 0; font-weight: 600; letter-spacing: -0.015em; }
p { margin: 0; }

/* Tables */
.tbl { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.tbl thead th {
  text-align: left;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
  position: sticky; top: 0; z-index: 1;
}
.tbl tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}
.tbl tbody tr:hover { background: var(--surface-hover); cursor: pointer; }
.tbl tbody tr.selected { background: var(--accent-soft); }

/* Progress / bar */
.bar {
  height: 6px;
  background: var(--surface-3);
  border-radius: 3px;
  overflow: hidden;
  position: relative;
}
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.bar.ai > span { background: var(--ai); }
.bar.success > span { background: var(--success); }
.bar.warn > span { background: var(--warn); }

/* Nav rail entries */
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px;
  border-radius: var(--r-sm);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  position: relative;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active {
  background: var(--surface-2);
  color: var(--text);
}
.nav-item.active::before {
  content: "";
  position: absolute; left: -10px; top: 8px; bottom: 8px;
  width: 2px; background: var(--accent); border-radius: 2px;
}
.nav-item .count {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-3);
  background: var(--bg-2);
  padding: 1px 6px;
  border-radius: 999px;
}
.nav-item.ai .count { color: var(--ai); background: var(--ai-soft); }

/* Glow background for hero sections */
.aurora {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(600px 240px at 10% 0%, rgba(79,140,255,0.10), transparent 70%),
    radial-gradient(500px 200px at 90% 0%, rgba(167,139,250,0.08), transparent 70%);
  z-index: 0;
}

/* Tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); }
.tab {
  padding: 10px 14px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-3);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  display: flex; align-items: center; gap: 6px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab .count { font-family: var(--font-mono); font-size: 10.5px; color: var(--text-3); }

/* Number deltas */
.delta {
  font-family: var(--font-mono);
  font-size: 11.5px;
  display: inline-flex;
  align-items: center;
  gap: 2px;
}
.delta.up { color: var(--success); }
.delta.down { color: var(--danger); }
.delta.flat { color: var(--text-3); }

/* AI suggestion/insight inline strip */
.insight-strip {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--r-md);
  background: linear-gradient(180deg, rgba(167,139,250,0.08), rgba(167,139,250,0.03));
  border: 1px solid rgba(167,139,250,0.22);
  font-size: 12.5px;
  color: var(--text);
}
.insight-strip .ai-glyph {
  width: 18px; height: 18px;
  border-radius: 5px;
  background: linear-gradient(135deg, var(--ai), var(--accent));
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono);
  font-weight: 700; font-size: 11px;
  color: #0a0d14;
}

/* Status dots */
.dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }
.dot.success { background: var(--success); }
.dot.warn { background: var(--warn); }
.dot.danger { background: var(--danger); }
.dot.info { background: var(--info); }
.dot.ai { background: var(--ai); }

/* App layout */
.app {
  display: grid;
  grid-template-columns: 232px 1fr auto;
  grid-template-rows: 100vh;
  height: 100vh;
  width: 100vw;
}

@media (max-width: 1280px) {
  .app { grid-template-columns: 64px 1fr auto; }
}
