/* ── DESIGN TOKENS ─────────────────────────────── */
:root {
  --bg:         #0b0e14;
  --bg2:        #111520;
  --bg3:        #181d2a;
  --surface:    #1e2435;
  --surface2:   #252c40;
  --border:     #2a3250;
  --accent:     #4f8ef7;
  --accent2:    #7b5ea7;
  --accent3:    #36c5a0;
  --warn:       #f0a500;
  --danger:     #e05252;
  --text:       #e8ecf7;
  --text2:      #8e97b8;
  --text3:      #566080;
  --font-head:  'Syne', sans-serif;
  --font-body:  'Instrument Sans', sans-serif;
  --font-mono:  'DM Mono', monospace;
  --radius:     10px;
  --radius-lg:  16px;
  --sidebar-w:  240px;
  --topbar-h:   56px;
  --transition: 0.18s ease;
}

/* ── RESET ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
}

/* ── SCROLLBAR ──────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--bg2); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 9px; }

/* ── SIDEBAR ────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
  transition: transform var(--transition);
}
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
}
.logo-icon {
  width: 36px; height: 36px;
  background: var(--accent);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 700; color: #fff;
  font-family: var(--font-mono);
}
.logo-text {
  font-family: var(--font-head);
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.3px;
}
.logo-text em { color: var(--accent); font-style: normal; }

.sidebar-nav { padding: 12px 10px; flex: 1; }
.nav-divider {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text3);
  padding: 14px 10px 6px;
  font-family: var(--font-mono);
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius);
  color: var(--text2);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  transition: all var(--transition);
  cursor: pointer;
  margin-bottom: 2px;
}
.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-icon { font-style: normal; width: 18px; text-align: center; font-size: 14px; }

.sidebar-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text3);
  font-family: var(--font-mono);
}

/* ── TOPBAR ──────────────────────────────────────── */
.topbar {
  position: fixed;
  top: 0;
  left: var(--sidebar-w);
  right: 0;
  height: var(--topbar-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  z-index: 90;
}
.menu-toggle { display: none; background: none; border: none; color: var(--text); font-size: 20px; cursor: pointer; }
.topbar-title { font-family: var(--font-head); font-size: 15px; font-weight: 600; color: var(--text); flex: 1; }
.topbar-actions { display: flex; gap: 8px; }

/* ── MAIN ────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  margin-top: var(--topbar-h);
  flex: 1;
  padding: 32px 36px;
  min-height: calc(100vh - var(--topbar-h));
  overflow-x: hidden;
}

/* ── BUTTONS ─────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
}
.btn:hover { background: var(--surface2); border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #3a7ae0; border-color: #3a7ae0; }
.btn-success { background: var(--accent3); border-color: var(--accent3); color: #0b1a14; }
.btn-sm { padding: 6px 13px; font-size: 12.5px; }
.btn-icon { padding: 7px 10px; }

/* ── CARDS ───────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
}
.card-sm { padding: 16px 20px; }
.card-title {
  font-family: var(--font-head);
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-title .badge {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--accent);
  color: #fff;
  font-family: var(--font-mono);
  font-weight: 400;
}

/* ── GRID LAYOUTS ────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 20px; }

/* ── STAT PILLS ──────────────────────────────────── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-pill {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  text-align: center;
}
.stat-pill .stat-val {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 500;
  color: var(--accent);
  display: block;
}
.stat-pill .stat-lbl {
  font-size: 11px;
  color: var(--text3);
  letter-spacing: 0.5px;
  margin-top: 2px;
  display: block;
}

/* ── TABLES ──────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
thead tr { background: var(--bg3); }
thead th {
  padding: 10px 14px;
  text-align: left;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--text3);
  letter-spacing: 0.8px;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
}
tbody tr { border-bottom: 1px solid var(--border); transition: background var(--transition); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface2); }
tbody td { padding: 9px 14px; color: var(--text2); }
tbody td:first-child { color: var(--text); font-weight: 500; }

/* ── BADGES ──────────────────────────────────────── */
.badge-above { background: rgba(54,197,160,0.15); color: var(--accent3); padding: 2px 8px; border-radius: 20px; font-size: 11px; font-family: var(--font-mono); }
.badge-below { background: rgba(224,82,82,0.15); color: var(--danger); padding: 2px 8px; border-radius: 20px; font-size: 11px; font-family: var(--font-mono); }
.badge-avg   { background: rgba(79,142,247,0.15); color: var(--accent); padding: 2px 8px; border-radius: 20px; font-size: 11px; font-family: var(--font-mono); }

/* ── PAGE HEADER ─────────────────────────────────── */
.page-header { margin-bottom: 28px; }
.page-header h1 {
  font-family: var(--font-head);
  font-size: 28px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.5px;
  line-height: 1.2;
}
.page-header p { color: var(--text2); margin-top: 6px; font-size: 14px; }

/* ── UPLOAD ZONE ─────────────────────────────────── */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 48px 32px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--bg3);
}
.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--accent);
  background: rgba(79,142,247,0.05);
}
.upload-zone .upload-icon { font-size: 48px; margin-bottom: 12px; }
.upload-zone h3 { font-family: var(--font-head); font-size: 18px; margin-bottom: 6px; }
.upload-zone p { color: var(--text2); font-size: 13px; }

/* ── TABS ─────────────────────────────────────────── */
.tab-bar { display: flex; gap: 4px; background: var(--bg3); padding: 4px; border-radius: var(--radius); margin-bottom: 24px; width: fit-content; }
.tab-btn {
  padding: 7px 18px;
  border-radius: 7px;
  border: none;
  background: transparent;
  color: var(--text2);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}
.tab-btn.active { background: var(--surface2); color: var(--text); }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ── SELECT ──────────────────────────────────────── */
select, input[type="text"], input[type="number"] {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 8px 12px;
  font-family: var(--font-body);
  font-size: 13px;
  outline: none;
  transition: border-color var(--transition);
}
select:focus, input:focus { border-color: var(--accent); }
select option { background: var(--bg3); }

/* ── SECTION ─────────────────────────────────────── */
.section { margin-bottom: 32px; }
.section-title {
  font-family: var(--font-head);
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text3);
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

/* ── GUIDE STEPS ─────────────────────────────────── */
.guide-step {
  display: flex;
  gap: 16px;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--bg3);
  border: 1px solid var(--border);
  margin-bottom: 12px;
}
.step-num {
  width: 32px; height: 32px;
  background: var(--accent);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 13px;
  color: #fff;
  flex-shrink: 0;
}
.guide-step h4 { font-weight: 600; margin-bottom: 3px; font-size: 14px; }
.guide-step p { font-size: 13px; color: var(--text2); }

/* ── CHART CONTAINER ─────────────────────────────── */
.chart-box {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  position: relative;
}
.chart-box canvas { max-height: 320px; }

/* ── CHI TABLE ───────────────────────────────────── */
.chi-result {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-top: 12px;
}
.chi-stat {
  display: inline-flex;
  flex-direction: column;
  margin-right: 24px;
}
.chi-stat .val { font-family: var(--font-mono); font-size: 20px; color: var(--accent); }
.chi-stat .lbl { font-size: 11px; color: var(--text3); letter-spacing: 0.5px; }
.sig-yes { color: var(--accent3); font-weight: 600; }
.sig-no  { color: var(--danger); font-weight: 600; }

/* ── ALERT ───────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 16px;
}
.alert-info  { background: rgba(79,142,247,0.1); border: 1px solid rgba(79,142,247,0.25); color: var(--accent); }
.alert-warn  { background: rgba(240,165,0,0.1); border: 1px solid rgba(240,165,0,0.25); color: var(--warn); }
.alert-success{ background: rgba(54,197,160,0.1); border: 1px solid rgba(54,197,160,0.25); color: var(--accent3); }

/* ── EMPTY STATE ─────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text3);
}
.empty-state .empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state p { font-size: 13.5px; }

/* ── PROGRESS ────────────────────────────────────── */
.progress-bar-wrap { background: var(--bg3); border-radius: 9px; height: 6px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--accent); border-radius: 9px; transition: width 0.4s ease; }

/* ── RESPONSIVE ──────────────────────────────────── */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .topbar { left: 0; }
  .main-content { margin-left: 0; padding: 20px 16px; }
  .menu-toggle { display: flex; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .main-content { padding: 16px 12px; }
  .page-header h1 { font-size: 22px; }
}

/* ── SPINNER ─────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── TOOLTIP ─────────────────────────────────────── */
[data-tip] { position: relative; cursor: help; }
[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface2);
  color: var(--text);
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  white-space: nowrap;
  z-index: 200;
  pointer-events: none;
}

/* ── FADE IN ──────────────────────────────────────── */
.fade-in { animation: fadeIn 0.25s ease forwards; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* ── EDITABLE TABLE INPUTS ───────────────────────── */
.edit-label, .edit-val {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 5px 8px;
  font-family: var(--font-body);
  font-size: 12.5px;
}
.edit-label:focus, .edit-val:focus { border-color: var(--accent); outline: none; }

/* ── ALL-CHARTS TYPE SELECTOR ────────────────────── */
.all-chart-type {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text2);
  font-size: 11px;
  padding: 3px 8px;
  cursor: pointer;
  width: 100%;
}