/* AstraReach design tokens */
:root {
  --bg-0: #07090F;
  --bg-1: #0B0F1A;
  --bg-2: #111827;
  --bg-3: #1A2030;
  --bg-4: #242B3D;
  --border: #232A3B;
  --border-strong: #2E3649;
  --text-1: #F4F6FB;
  --text-2: #A8B0C2;
  --text-3: #6B7489;
  --text-4: #4A5268;

  --accent: #8B5CF6;
  --accent-dim: #6D44D4;
  --accent-glow: rgba(139, 92, 246, 0.35);
  --cyan: #22D3EE;
  --emerald: #10B981;
  --amber: #F59E0B;
  --rose: #F43F5E;

  --radius-sm: 4px;
  --radius: 8px;
  --radius-lg: 12px;

  --mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;
  --sans: 'Inter', -apple-system, system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--sans);
  background: var(--bg-1);
  color: var(--text-1);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea, select { font-family: inherit; }

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

/* SIDEBAR */
.sidebar {
  background: var(--bg-0);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 14px 10px;
  gap: 2px;
  overflow-x: hidden;
  overflow-y: auto;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}
.brand-mark {
  width: 26px; height: 26px;
  border-radius: 7px;
  background: radial-gradient(circle at 30% 30%, var(--accent), #3b1f7a 60%, #0f0820);
  position: relative;
  box-shadow: 0 0 0 1px rgba(139,92,246,0.35), 0 0 14px rgba(139,92,246,0.25);
}
.brand-mark::before, .brand-mark::after {
  content: ''; position: absolute; inset: 2px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.08);
  transform: rotate(25deg);
}
.brand-mark::after { transform: rotate(-15deg); border-color: rgba(34,211,238,0.3); }
.brand-name { font-weight: 600; letter-spacing: -0.01em; font-size: 14px; }
.brand-version { font-family: var(--mono); font-size: 10px; color: var(--text-3); }

.nav-section-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-4);
  padding: 10px 10px 6px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: var(--radius);
  color: var(--text-2);
  cursor: pointer;
  font-size: 13px;
  position: relative;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--bg-2); color: var(--text-1); }
.nav-item.active {
  background: var(--bg-2);
  color: var(--text-1);
}
.nav-item.active::before {
  content: ''; position: absolute; left: -10px; top: 8px; bottom: 8px;
  width: 2px; border-radius: 2px; background: var(--accent);
}
.nav-item .icon { width: 16px; height: 16px; flex-shrink: 0; opacity: 0.85; }
.nav-badge {
  margin-left: auto;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 10px;
  background: var(--bg-3);
  color: var(--text-2);
  font-family: var(--mono);
}
.nav-badge.alert { background: rgba(244, 63, 94, 0.15); color: var(--rose); }

.sidebar-footer {
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.sys-health {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  font-size: 12px;
  color: var(--text-2);
}
.org-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px;
  border-radius: var(--radius);
  background: var(--bg-2);
  border: 1px solid var(--border);
  margin-top: 8px;
}
.org-avatar {
  width: 28px; height: 28px; border-radius: 6px;
  background: linear-gradient(135deg, #4c1d95, #065f46);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600;
}
.org-name { font-size: 12px; font-weight: 500; }
.org-plan { font-size: 10px; color: var(--text-3); }

/* DOTS + ANIMS */
.dot {
  display: inline-block;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--emerald);
  position: relative;
}
.dot.pulse::after {
  content: ''; position: absolute; inset: 0; border-radius: 50%;
  background: inherit;
  animation: ping 2s ease-out infinite;
}
@keyframes ping {
  0% { transform: scale(1); opacity: .6; }
  80%, 100% { transform: scale(2.4); opacity: 0; }
}
.dot.violet { background: var(--accent); }
.dot.amber { background: var(--amber); }
.dot.rose { background: var(--rose); }

/* MAIN */
.main {
  display: flex; flex-direction: column;
  overflow: hidden;
  background: var(--bg-1);
}
.topbar {
  height: 52px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 14px;
  flex-shrink: 0;
  background: var(--bg-1);
}
.breadcrumb {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--text-2);
}
.breadcrumb .sep { color: var(--text-4); }
.breadcrumb .current { color: var(--text-1); font-weight: 500; }
.topbar-spacer { flex: 1; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 500;
  background: var(--bg-3);
  border: 1px solid var(--border-strong);
  color: var(--text-1);
  transition: all .12s;
}
.btn:hover { background: var(--bg-4); border-color: #3a4360; }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  box-shadow: 0 0 0 1px var(--accent-dim), 0 4px 14px -4px var(--accent-glow);
}
.btn.primary:hover { background: #9B6EFF; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--bg-2); color: var(--text-1); }
.btn .kbd { font-family: var(--mono); font-size: 10px; padding: 1px 5px; border-radius: 3px; background: rgba(255,255,255,0.08); margin-left: 4px; }

.content {
  flex: 1;
  overflow: auto;
  padding: 24px;
  scrollbar-color: #2a3244 transparent;
}
.content::-webkit-scrollbar { width: 10px; height: 10px; }
.content::-webkit-scrollbar-thumb { background: #2a3244; border-radius: 10px; }

/* CARD */
.card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.card-title { font-size: 13px; font-weight: 600; letter-spacing: -0.01em; color: var(--text-1); }
.card-sub { font-size: 11px; color: var(--text-3); }

/* BADGES */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-family: var(--mono);
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--bg-3);
  color: var(--text-2);
  border: 1px solid var(--border);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.badge.violet { background: rgba(139, 92, 246, 0.1); color: #c4b5fd; border-color: rgba(139,92,246,0.25); }
.badge.cyan   { background: rgba(34, 211, 238, 0.1); color: #67e8f9; border-color: rgba(34,211,238,0.25); }
.badge.green  { background: rgba(16, 185, 129, 0.1); color: #6ee7b7; border-color: rgba(16,185,129,0.25); }
.badge.amber  { background: rgba(245, 158, 11, 0.1); color: #fbbf24; border-color: rgba(245,158,11,0.3); }
.badge.rose   { background: rgba(244, 63, 94, 0.12); color: #fda4af; border-color: rgba(244,63,94,0.3); }
.badge.plain  { background: transparent; }

/* METRIC */
.metric-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.metric {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px 10px;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.metric-label {
  font-size: 11px; color: var(--text-3);
  display: flex; align-items: center; gap: 6px;
  letter-spacing: 0.02em;
}
.metric-value {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-top: 8px;
  font-variant-numeric: tabular-nums;
}
.metric-delta {
  font-size: 11px;
  margin-top: 4px;
  display: flex; align-items: center; gap: 4px;
  font-variant-numeric: tabular-nums;
}
.metric-delta.up { color: var(--emerald); }
.metric-delta.down { color: var(--rose); }
.spark { display: block; margin-top: 10px; opacity: 0.9; align-self: flex-end; }

/* Mono */
.mono { font-family: var(--mono); }

/* Table */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.data-table th {
  text-align: left;
  font-weight: 500;
  color: var(--text-3);
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  position: sticky; top: 0;
  background: var(--bg-2);
}
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-2);
}
.data-table tr:hover td { background: rgba(255,255,255,0.02); color: var(--text-1); }
.data-table tr.selected td { background: rgba(139, 92, 246, 0.06); }
.data-table tr.flash td { animation: rowFlash 1.2s ease; }
@keyframes rowFlash {
  0% { background: rgba(139, 92, 246, 0.2); }
  100% { background: transparent; }
}

/* Tweaks */
.tweaks {
  position: fixed;
  bottom: 16px;
  right: 16px;
  width: 280px;
  background: var(--bg-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 40px rgba(0,0,0,0.5);
  z-index: 100;
  padding: 14px;
  font-size: 12px;
}
.tweaks-title { font-size: 11px; font-weight: 600; color: var(--text-1); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.tweaks-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.tweaks-row label { color: var(--text-2); }
.swatch-group { display: flex; gap: 6px; }
.swatch { width: 18px; height: 18px; border-radius: 4px; cursor: pointer; border: 2px solid transparent; }
.swatch.active { border-color: white; }
.toggle {
  width: 30px; height: 17px; background: var(--bg-4); border-radius: 20px; position: relative; cursor: pointer; transition: background .15s;
}
.toggle::after { content: ''; position: absolute; top: 2px; left: 2px; width: 13px; height: 13px; background: white; border-radius: 50%; transition: left .15s; }
.toggle.on { background: var(--accent); }
.toggle.on::after { left: 15px; }

/* Scroll helpers */
.scroll-y { overflow-y: auto; }

/* Chat */
.chat-wrap {
  max-width: 820px; margin: 0 auto; display: flex; flex-direction: column; gap: 20px;
  padding-bottom: 40px;
}
.bubble-user {
  align-self: flex-end;
  background: var(--accent);
  color: white;
  padding: 10px 14px;
  border-radius: 14px 14px 4px 14px;
  max-width: 70%;
  font-size: 13px;
}
.bubble-ai {
  background: var(--bg-2);
  border: 1px solid var(--border);
  padding: 18px 20px;
  border-radius: 14px 14px 14px 4px;
  max-width: 90%;
}
.bubble-ai .ans { font-size: 14px; line-height: 1.65; color: var(--text-1); }
.bubble-ai .meta { font-size: 10px; font-family: var(--mono); color: var(--text-4); margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--border); }

.chat-input {
  position: sticky;
  bottom: 0;
  max-width: 820px;
  margin: 0 auto;
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 12px 14px;
  box-shadow: 0 -8px 24px rgba(11,15,26,0.8);
}
.chat-input textarea {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text-1);
  resize: none;
  outline: none;
  font-size: 13px;
  min-height: 22px;
  max-height: 100px;
}
.chip-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.chip {
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text-2);
  cursor: pointer;
  transition: all .12s;
}
.chip:hover { background: var(--bg-4); color: var(--text-1); border-color: var(--border-strong); }

/* Empty */
.typing { display: inline-block; width: 7px; height: 14px; background: var(--accent); vertical-align: middle; animation: blink 1s step-end infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* Graph hover */
.node-circle { cursor: pointer; transition: filter .15s; }
.node-circle:hover { filter: brightness(1.3); }

/* AI insight callout */
.ai-callout {
  display: flex; gap: 10px;
  padding: 10px 12px;
  background: linear-gradient(90deg, rgba(139,92,246,0.1), rgba(139,92,246,0.02));
  border: 1px solid rgba(139,92,246,0.25);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--text-1);
  margin-bottom: 16px;
}
.ai-callout .ai-icon {
  width: 20px; height: 20px; border-radius: 6px;
  background: radial-gradient(circle, var(--accent), #3b1f7a);
  flex-shrink: 0;
  box-shadow: 0 0 12px var(--accent-glow);
}

/* Segmented */
.seg {
  display: inline-flex;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2px;
  gap: 2px;
}
.seg button {
  padding: 4px 10px;
  font-size: 11px;
  border-radius: 5px;
  color: var(--text-3);
}
.seg button.active { background: var(--bg-1); color: var(--text-1); }

/* Filter chip */
.filter-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  font-size: 11px;
  border-radius: 20px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text-2);
  cursor: pointer;
}
.filter-chip.active { background: rgba(139, 92, 246, 0.12); border-color: rgba(139,92,246,0.4); color: #c4b5fd; }

/* Json viewer */
.json-view {
  font-family: var(--mono);
  font-size: 11px;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  color: var(--text-2);
  line-height: 1.7;
  max-height: 240px;
  overflow: auto;
}
.json-view .k { color: #c4b5fd; }
.json-view .s { color: #86efac; }
.json-view .n { color: #fbbf24; }
.json-view .b { color: #67e8f9; }

/* Detail drawer */
.drawer {
  width: 360px;
  background: var(--bg-2);
  border-left: 1px solid var(--border);
  flex-shrink: 0;
  overflow-y: auto;
  padding: 18px;
}

/* Progress bar */
.progress { width: 100%; height: 4px; background: var(--bg-3); border-radius: 4px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); }

/* Event list */
.event-row {
  display: grid;
  grid-template-columns: 150px 100px 140px 1fr 110px 70px;
  gap: 10px;
  align-items: center;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  cursor: pointer;
  transition: background .1s;
}
.event-row:hover { background: rgba(255,255,255,0.03); }
.event-row.selected { background: rgba(139,92,246,0.08); }
.event-row.new { animation: rowFlash 1.4s ease; }

/* Funnel */
.funnel-step {
  display: flex; flex-direction: column; gap: 4px;
  padding: 10px 14px;
  margin: 0 auto;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.funnel-step-label { font-size: 11px; color: var(--text-3); }
.funnel-step-val { font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }
.drop-label { text-align: center; font-size: 11px; color: var(--rose); font-family: var(--mono); margin: 2px 0; }
