/* ============================================================================
   AiHub OS · Trader-style Dashboard
   Light theme, Bloomberg-inspired density, tabular-nums, LED indicators.
   ============================================================================ */

/* ─── Tokens ────────────────────────────────────────────────────────────── */
:root {
  /* Neutrals — subtle paper/grid feel */
  --bg:            #F7F8FA;
  --bg-card:       #FFFFFF;
  --bg-subtle:     #F1F3F6;
  --bg-emphasis:   #0B1220;

  --line:          #E5E7EB;
  --line-strong:   #CBD5E1;
  --line-subtle:   #EEF2F6;

  --ink:           #0B1220;
  --ink-2:         #334155;
  --ink-3:         #64748B;
  --ink-4:         #94A3B8;

  /* Semantic */
  --up:            #059669;
  --up-bg:         #ECFDF5;
  --up-soft:       #10B981;
  --down:          #DC2626;
  --down-bg:       #FEF2F2;
  --down-soft:     #EF4444;
  --warn:          #D97706;
  --warn-bg:       #FFFBEB;
  --warn-soft:     #F59E0B;
  --info:          #2563EB;
  --info-bg:       #EFF6FF;

  /* Brand accent — navy trading desk */
  --brand:         #0B1220;
  --brand-2:       #1E293B;
  --accent:        #1D4ED8;

  /* Typography */
  --font-ui:    ui-sans-serif, system-ui, -apple-system, 'Segoe UI', 'Inter', sans-serif;
  --font-mono:  ui-monospace, 'JetBrains Mono', 'SF Mono', 'IBM Plex Mono', 'Consolas', monospace;
  --font-serif: 'Cormorant Garamond', Georgia, serif;

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

  /* Shadows (very subtle for light theme) */
  --shadow-sm: 0 1px 2px rgba(15,23,42,0.04), 0 0 0 1px rgba(15,23,42,0.03);
  --shadow-md: 0 2px 8px rgba(15,23,42,0.06), 0 0 0 1px rgba(15,23,42,0.04);

  /* Sparkline stroke width */
  --spark-w: 1.5;
}

/* ─── Base ──────────────────────────────────────────────────────────────── */
* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color 120ms ease;
}
a:hover { color: var(--brand-2); }

/* Tabular numbers everywhere — critical for trader look */
.num, .kpi-value, .data-cell, td, .mono {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ─── Top bar (dense trading header) ────────────────────────────────────── */
.top {
  background: var(--bg-card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 100;
}
.top-row {
  display: flex;
  align-items: center;
  gap: 32px;
  height: 56px;
}
.brand {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}
.brand-title {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--brand);
}
.brand-sub {
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-4);
  margin-top: 2px;
}

.top-nav {
  display: flex;
  gap: 4px;
  margin-left: auto;
}
.top-nav a {
  padding: 6px 12px;
  border-radius: var(--r-sm);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--ink-2);
  position: relative;
}
.top-nav a:hover { background: var(--bg-subtle); color: var(--ink); }
.top-nav a.active {
  background: var(--bg-emphasis);
  color: #fff;
}

.meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-3);
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  letter-spacing: 0.02em;
}

/* Live pulse dot before timestamp */
.meta::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--up-soft);
  margin-right: 6px;
  vertical-align: middle;
  box-shadow: 0 0 0 0 rgba(16,185,129,0.7);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0   rgba(16,185,129,0.55); }
  70%  { box-shadow: 0 0 0 6px rgba(16,185,129,0);    }
  100% { box-shadow: 0 0 0 0   rgba(16,185,129,0);    }
}

/* ─── Hero / section headers ─────────────────────────────────────────────── */
main.container { padding-top: 24px; padding-bottom: 60px; }

.hero {
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}
.hero h1 {
  font-family: var(--font-serif);
  font-size: 30px;
  font-weight: 500;
  letter-spacing: -0.015em;
  margin: 0 0 6px 0;
  color: var(--ink);
}
.lede {
  font-size: 13px;
  color: var(--ink-3);
  margin: 0;
  font-family: var(--font-mono);
  letter-spacing: 0.01em;
}

/* ─── KPI Row — trading-card layout ─────────────────────────────────────── */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  overflow: hidden;
  margin-bottom: 24px;
}
.kpi {
  background: var(--bg-card);
  padding: 16px 18px;
  position: relative;
  transition: background 120ms ease;
}
.kpi:hover { background: #FBFCFD; }
.kpi-label {
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-3);
  font-weight: 600;
  margin-bottom: 10px;
}
.kpi-value {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--ink);
  line-height: 1;
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.kpi-sub {
  font-size: 14px;
  color: var(--ink-4);
  font-weight: 400;
}
.kpi-trend {
  margin-top: 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-3);
  letter-spacing: 0.02em;
}

/* Delta chip (e.g., "+12.4%") */
.delta {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.delta-up   { background: var(--up-bg);   color: var(--up); }
.delta-down { background: var(--down-bg); color: var(--down); }
.delta-flat { background: var(--bg-subtle); color: var(--ink-3); }
.delta::before {
  font-size: 9px;
  line-height: 1;
}
.delta-up::before   { content: '▲'; }
.delta-down::before { content: '▼'; }
.delta-flat::before { content: '▬'; }

/* ─── LED indicators ────────────────────────────────────────────────────── */
.led {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  vertical-align: middle;
  margin-right: 6px;
  position: relative;
}
.led-green  { background: var(--up-soft);   box-shadow: 0 0 0 2px rgba(16,185,129,0.18); }
.led-red    { background: var(--down-soft); box-shadow: 0 0 0 2px rgba(239,68,68,0.18);  }
.led-amber  { background: var(--warn-soft); box-shadow: 0 0 0 2px rgba(245,158,11,0.18); }
.led-grey   { background: var(--ink-4);     box-shadow: 0 0 0 2px rgba(148,163,184,0.18); }
.led-blink  { animation: ledPulse 1.8s ease-in-out infinite; }
@keyframes ledPulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.45; }
}

/* ─── Alerts strip ──────────────────────────────────────────────────────── */
.alerts-strip {
  background: var(--warn-bg);
  border: 1px solid #FDE68A;
  border-left: 3px solid var(--warn-soft);
  color: #78350F;
  padding: 10px 14px;
  border-radius: var(--r-sm);
  margin-bottom: 20px;
  font-size: 13px;
  font-family: var(--font-mono);
}
.alerts-strip strong {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 11px;
  color: var(--warn);
  margin-right: 8px;
}

/* ─── Sections ──────────────────────────────────────────────────────────── */
.section {
  margin-bottom: 32px;
}
.section h2 {
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 500;
  letter-spacing: -0.01em;
  margin: 0 0 4px 0;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 10px;
}
.section h2::before {
  content: '';
  width: 3px;
  height: 18px;
  background: var(--brand);
  border-radius: 1px;
}
.section-sub {
  font-size: 12px;
  color: var(--ink-3);
  margin: 0 0 16px 0;
  font-family: var(--font-mono);
}

/* ─── Hierarchy grid (agent cards) ──────────────────────────────────────── */
.hierarchy {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}
.h-node {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 14px 16px;
  cursor: pointer;
  transition: all 150ms ease;
  position: relative;
  overflow: hidden;
}
.h-node::before {
  content: '';
  position: absolute;
  left: 0; top: 0;
  width: 3px;
  height: 100%;
  background: var(--line-strong);
  transition: background 150ms ease;
}
.h-node:hover {
  border-color: var(--ink-4);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}
.h-node:hover::before { background: var(--accent); }

.h-status-online::before  { background: var(--up-soft); }
.h-status-standby::before { background: var(--warn-soft); }
.h-status-offline::before { background: var(--ink-4); }
.h-status-alert::before   { background: var(--down-soft); }

.h-node-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.h-chip {
  width: 32px;
  height: 32px;
  border-radius: var(--r-sm);
  background: var(--bg-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
}
.h-chip-human   { background: #EFF6FF; }
.h-chip-channel { background: #FEF3C7; }
.h-chip-agent   { background: #F0FDF4; }

.h-node-title { flex: 1; min-width: 0; }
.h-node-name {
  font-weight: 600;
  font-size: 13px;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.h-node-role {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-top: 2px;
}

.h-status-pill {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 3px 7px;
  border-radius: 3px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.h-pill-online  { background: var(--up-bg);   color: var(--up); }
.h-pill-standby { background: var(--warn-bg); color: var(--warn); }
.h-pill-offline { background: var(--bg-subtle); color: var(--ink-3); }
.h-pill-alert   { background: var(--down-bg); color: var(--down); }
.h-pill-online::before  { content:'●'; font-size:8px; color:var(--up-soft); }
.h-pill-standby::before { content:'●'; font-size:8px; color:var(--warn-soft); }
.h-pill-offline::before { content:'○'; font-size:8px; color:var(--ink-4); }
.h-pill-alert::before   { content:'◆'; font-size:8px; color:var(--down-soft); }

.h-node-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-3);
  line-height: 1.6;
  padding-top: 8px;
  border-top: 1px dashed var(--line);
}

/* ─── Sparkline ─────────────────────────────────────────────────────────── */
.spark {
  display: inline-block;
  width: 60px;
  height: 18px;
  vertical-align: middle;
  margin-left: 8px;
}
.spark path {
  fill: none;
  stroke: var(--up-soft);
  stroke-width: var(--spark-w);
  stroke-linecap: round;
  stroke-linejoin: round;
}
.spark-down path { stroke: var(--down-soft); }
.spark-flat path { stroke: var(--ink-4); }
.spark-fill {
  fill: var(--up-soft);
  opacity: 0.12;
}
.spark-down .spark-fill { fill: var(--down-soft); }

/* ─── Tables (trading-style zebra with monospace) ───────────────────────── */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  overflow: hidden;
}
th {
  background: var(--bg-subtle);
  text-align: left;
  padding: 8px 12px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--line-subtle);
  color: var(--ink);
}
tbody tr:nth-child(odd) td { background: #FAFBFC; }
tbody tr:hover td { background: var(--info-bg); }
td.num, th.num, td.data-cell {
  font-family: var(--font-mono);
  text-align: right;
}

/* ─── Data-grid two-col layout for dense sections ───────────────────────── */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}
.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 16px 18px;
}
.card h3 {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin: 0 0 12px 0;
}

/* ─── Modal (agent prompt) ──────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11,18,32,0.45);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 32px;
}
.modal {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  max-width: 900px;
  width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(11,18,32,0.2);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-subtle);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
}
.modal-head h3 {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--ink-2);
  text-transform: uppercase;
}
.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--ink-3);
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
}
.modal-close:hover { color: var(--ink); }

.modal-body {
  padding: 16px 20px;
  overflow-y: auto;
  flex: 1;
}
.fm-block {
  margin-bottom: 12px;
  background: var(--bg-subtle);
  border-radius: var(--r-sm);
  padding: 8px 12px;
}
.fm-block summary {
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.fm-table {
  border: none;
  margin-top: 8px;
}
.fm-table td {
  border-bottom: 1px dashed var(--line);
  padding: 4px 6px;
  font-family: var(--font-mono);
  font-size: 11px;
}
.fm-table td:first-child { color: var(--ink-3); width: 120px; }

.prompt-pre {
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
  background: #FAFBFC;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 12px 14px;
  color: var(--ink);
  white-space: pre-wrap;
  word-break: break-word;
  overflow-x: auto;
}

.muted { color: var(--ink-3); font-size: 13px; }

/* ─── Footer ────────────────────────────────────────────────────────────── */
footer {
  margin-top: 60px;
  padding: 20px 0;
  border-top: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-4);
  letter-spacing: 0.02em;
  background: var(--bg-card);
}
footer a { color: var(--ink-3); }
footer a:hover { color: var(--accent); }

/* ─── Tiny ticker (decorative micro-rail under top bar) ─────────────────── */
.ticker-rail {
  background: var(--bg-emphasis);
  color: #E2E8F0;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  padding: 5px 0;
  overflow: hidden;
  white-space: nowrap;
  position: sticky;
  top: 56px;
  z-index: 99;
  border-bottom: 1px solid var(--brand-2);
}
.ticker-track {
  display: inline-block;
  padding-left: 100%;
  animation: ticker 60s linear infinite;
}
.ticker-item {
  display: inline-block;
  padding: 0 24px;
  border-right: 1px solid rgba(226,232,240,0.15);
}
.ticker-item .t-label {
  color: var(--ink-4);
  margin-right: 6px;
}
.ticker-item .t-val { color: #fff; font-weight: 500; }
.ticker-item .t-delta { margin-left: 6px; }
@keyframes ticker {
  0%   { transform: translateX(0); }
  100% { transform: translateX(-100%); }
}

/* ─── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .container { padding: 0 14px; }
  .top-row   { height: 52px; gap: 16px; }
  .brand-title { font-size: 12px; }
  .top-nav   { gap: 2px; }
  .top-nav a { padding: 5px 8px; font-size: 11px; }
  .meta      { display: none; }
  .hero h1   { font-size: 24px; }
  .kpi       { padding: 12px 14px; }
  .kpi-value { font-size: 22px; }
  .section h2 { font-size: 18px; }
  .hierarchy { grid-template-columns: 1fr; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}
