/* ── Reset & Base ─────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #07070d;
  --bg-raised: #0e0e18;
  --bg-card:   #131320;
  --border:    #1c1c30;
  --border-lt: #26263e;
  --text:      #e4e4ec;
  --text-dim:  #8080a0;
  --accent:    #6366f1;
  --accent-lt: #818cf8;
  --green:     #22c55e;
  --red:       #ef4444;
  --amber:     #f59e0b;
  --cyan:      #06b6d4;
  --radius:    10px;
  --radius-sm: 6px;
}

html { font-size: 14px; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
}

/* ── Top Bar ─────────────────────────────────────────── */

.topbar {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; gap: 1.5rem;
  padding: 0 1.5rem;
  height: 56px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

.topbar-left {
  display: flex; align-items: center; gap: .6rem;
  flex-shrink: 0;
}

.topbar-left .logo {
  font-size: 1.25rem;
  color: var(--accent);
}

.topbar-left h1 {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -.02em;
}

.badge {
  font-size: .7rem; font-weight: 600;
  padding: 2px 8px; border-radius: 999px;
  background: var(--accent);
  color: #fff;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.topbar-nav {
  display: flex; gap: 2px;
  margin-left: 2rem;
}

.tab {
  background: none; border: none; color: var(--text-dim);
  font: inherit; font-size: .85rem; font-weight: 500;
  padding: .45rem .9rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all .15s;
}

.tab:hover { color: var(--text); background: var(--bg-card); }
.tab.active { color: #fff; background: var(--accent); }

.topbar-right {
  margin-left: auto;
  flex-shrink: 0;
}

.data-range {
  font-size: .78rem;
  color: var(--text-dim);
}

/* ── Layout ──────────────────────────────────────────── */

main {
  max-width: 1320px;
  margin: 0 auto;
  padding: 1.5rem;
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Cards ───────────────────────────────────────────── */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem;
  display: flex; flex-direction: column; gap: .3rem;
}

.card-sm { padding: .85rem 1rem; }

.card-label {
  font-size: .72rem; font-weight: 500;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .06em;
}

.card-value {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -.02em;
  line-height: 1.2;
}

.card-sm .card-value { font-size: 1.15rem; }

/* ── Panels ──────────────────────────────────────────── */

.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.panel h2 {
  font-size: .95rem; font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  margin-bottom: 1.25rem;
}

@media (max-width: 768px) {
  .grid-2 { grid-template-columns: 1fr; }
}

/* ── Charts ──────────────────────────────────────────── */

.chart-wrap { position: relative; width: 100%; max-height: 320px; }
.chart-short { max-height: 240px; }

/* ── Controls ────────────────────────────────────────── */

.controls {
  display: flex; align-items: center; gap: 1rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.controls label {
  font-size: .8rem; font-weight: 500;
  color: var(--text-dim);
  display: flex; align-items: center; gap: .4rem;
}

.controls select {
  font: inherit; font-size: .82rem;
  padding: .35rem .6rem;
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.controls select:focus { outline: none; border-color: var(--accent); }

.search-box {
  margin-left: auto;
}

.search-box input {
  font: inherit; font-size: .82rem;
  padding: .4rem .75rem;
  width: 220px;
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.search-box input::placeholder { color: var(--text-dim); }
.search-box input:focus { outline: none; border-color: var(--accent); }

/* ── Tables ──────────────────────────────────────────── */

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .82rem;
}

thead th {
  text-align: left;
  padding: .6rem .75rem;
  font-weight: 600;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: color .15s;
}

thead th:hover { color: var(--accent-lt); }
thead th.sorted-asc::after  { content: " ▲"; font-size: .65rem; }
thead th.sorted-desc::after { content: " ▼"; font-size: .65rem; }

tbody td {
  padding: .55rem .75rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr { transition: background .1s; }
tbody tr:hover { background: rgba(99, 102, 241, .06); }
tbody tr.clickable { cursor: pointer; }

.num { text-align: right; font-variant-numeric: tabular-nums; }

.positive { color: var(--green); }
.negative { color: var(--red); }
.muted    { color: var(--text-dim); }

.cell-bar {
  display: inline-block;
  height: 6px;
  border-radius: 3px;
  background: var(--accent);
  margin-right: .5rem;
  vertical-align: middle;
  min-width: 2px;
}

/* ── Modal ───────────────────────────────────────────── */

.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, .65);
  backdrop-filter: blur(4px);
  justify-content: center;
  align-items: flex-start;
  padding: 3rem 1rem;
  overflow-y: auto;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 100%;
  max-width: 820px;
  padding: 2rem;
  position: relative;
  animation: slideUp .25s ease;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: translateY(0); }
}

.modal-close {
  position: absolute; top: 1rem; right: 1.25rem;
  background: none; border: none;
  color: var(--text-dim); font-size: 1.5rem;
  cursor: pointer;
  transition: color .15s;
}

.modal-close:hover { color: var(--text); }

.modal-header { margin-bottom: 1.25rem; }
.modal-header h2 { font-size: 1.25rem; margin-bottom: .35rem; }

.modal-meta {
  display: flex; align-items: center; gap: .6rem;
  flex-wrap: wrap;
}

.modal-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: .75rem;
  margin-bottom: 1.5rem;
}

.modal-charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

@media (max-width: 640px) {
  .modal-charts { grid-template-columns: 1fr; }
}

.modal-chart-wrap h3 {
  font-size: .82rem; font-weight: 600;
  color: var(--text-dim);
  margin-bottom: .6rem;
}

/* ── Utilities ───────────────────────────────────────── */

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-dim);
}

.empty-state p { font-size: .9rem; margin-bottom: .3rem; }

.loading-spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid var(--border-lt);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  vertical-align: middle;
  margin-right: .4rem;
}

@keyframes spin { to { transform: rotate(360deg); } }
