/* ── Reset & base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #222534;
  --border: #2e3249;
  --accent: #4f6ef7;
  --accent2: #7c3aed;
  --danger: #ef4444;
  --warning: #f59e0b;
  --success: #10b981;
  --info: #06b6d4;
  --text: #e2e8f0;
  --muted: #6b7280;
  --radius: 10px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

html { font-size: 14px; }
body { background: var(--bg); color: var(--text); font-family: var(--font); min-height: 100vh; }

/* ── Navbar ──────────────────────────────────────────────────────────────── */
.navbar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 0 1.5rem; height: 56px; position: sticky; top: 0; z-index: 100;
}
.navbar-brand { display: flex; align-items: center; gap: 0.5rem; font-size: 1.15rem; font-weight: 700; }
.logo { font-size: 1.4rem; }
.navbar-right { display: flex; align-items: center; gap: 0.75rem; }
.last-update { font-size: 0.78rem; color: var(--muted); }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  cursor: pointer; border: none; border-radius: 6px;
  padding: 0.4rem 0.85rem; font-size: 0.82rem; font-weight: 600;
  transition: opacity .15s;
}
.btn:hover { opacity: 0.85; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-outline { background: transparent; color: var(--text); border: 1px solid var(--border); }

/* ── Container ───────────────────────────────────────────────────────────── */
.container { max-width: 1400px; margin: 0 auto; padding: 1.25rem 1.5rem; }

/* ── Banner ──────────────────────────────────────────────────────────────── */
.banner {
  background: #1c2a3a; border: 1px solid #2a4060;
  color: #93c5fd; border-radius: var(--radius); padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
}
.banner code { background: rgba(255,255,255,.08); padding: .1em .35em; border-radius: 4px; }

/* ── KPI Cards ───────────────────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem; margin-bottom: 1.5rem;
}
.kpi-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.1rem 1.25rem;
  border-left: 4px solid transparent;
}
.kpi-card.kpi-danger  { border-left-color: var(--danger); }
.kpi-card.kpi-warning { border-left-color: var(--warning); }
.kpi-card.kpi-success { border-left-color: var(--success); }
.kpi-card.kpi-info    { border-left-color: var(--info); }
.kpi-value { font-size: 2rem; font-weight: 800; line-height: 1; margin-bottom: .3rem; }
.kpi-label { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* ── Tabs ────────────────────────────────────────────────────────────────── */
.tabs {
  display: flex; gap: 0.25rem; border-bottom: 1px solid var(--border);
  margin-bottom: 1.25rem; overflow-x: auto;
}
.tab {
  cursor: pointer; background: none; border: none; color: var(--muted);
  padding: 0.65rem 1rem; font-size: 0.88rem; font-weight: 600;
  border-bottom: 2px solid transparent; white-space: nowrap; transition: color .15s;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab:hover:not(.active) { color: var(--text); }

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

/* Sub-tabs */
.sub-tabs {
  display: flex; gap: 0.25rem; margin-bottom: 1rem;
}
.sub-tab {
  cursor: pointer; background: var(--surface2); border: 1px solid var(--border);
  color: var(--muted); padding: 0.4rem 0.85rem; border-radius: 6px;
  font-size: 0.8rem; font-weight: 600; transition: all .15s;
}
.sub-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.sub-tab:hover:not(.active) { color: var(--text); }

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

/* ── Section header ──────────────────────────────────────────────────────── */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 0.75rem; margin-bottom: 1rem;
}
.section-header h2 { font-size: 1rem; font-weight: 700; }

/* ── Form controls ───────────────────────────────────────────────────────── */
.search-input, .select-input {
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text); border-radius: 6px; padding: 0.4rem 0.75rem;
  font-size: 0.82rem; outline: none; min-width: 220px;
}
.search-input:focus, .select-input:focus { border-color: var(--accent); }
.filters { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ── Charts ──────────────────────────────────────────────────────────────── */
.chart-row {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem; margin-bottom: 1.25rem;
}
.chart-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem; overflow: hidden;
}
.chart-card.chart-wide { grid-column: 1 / -1; }
.chart-card h3 { font-size: 0.85rem; color: var(--muted); margin-bottom: 0.75rem; }
.chart-card canvas { max-height: 240px; }

/* ── Data Table ──────────────────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; }
.data-table {
  width: 100%; border-collapse: collapse; font-size: 0.8rem;
}
.data-table thead th {
  background: var(--surface2); color: var(--muted);
  text-align: left; padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: .04em;
  white-space: nowrap; position: sticky; top: 56px; z-index: 5;
}
.data-table tbody tr { border-bottom: 1px solid var(--border); }
.data-table tbody tr:hover { background: var(--surface2); }
.data-table tbody td { padding: 0.45rem 0.75rem; white-space: nowrap; }

/* Color-coded cells */
td.cell-danger  { color: var(--danger); font-weight: 700; }
td.cell-warning { color: var(--warning); font-weight: 700; }
td.cell-ok      { color: var(--success); }

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 2rem; color: var(--muted); font-size: 0.9rem;
}

/* ── Files Grid ──────────────────────────────────────────────────────────── */
.files-grid { display: flex; flex-wrap: wrap; gap: 0.75rem; }
.file-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 0.65rem 1rem; min-width: 220px;
}
.file-name { font-size: 0.82rem; font-weight: 600; word-break: break-all; }
.file-meta { font-size: 0.72rem; color: var(--muted); margin-top: 0.25rem; }

/* ── Upload Modal ─────────────────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.65);
  display: flex; align-items: center; justify-content: center; z-index: 200;
}
.modal.hidden { display: none; }
.modal-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.5rem; width: 100%; max-width: 500px;
}
.modal-box h3 { font-size: 1.05rem; margin-bottom: 0.4rem; }
.muted { color: var(--muted); font-size: 0.82rem; margin-bottom: 1rem; }
.drop-zone {
  border: 2px dashed var(--border); border-radius: 8px; padding: 2rem;
  text-align: center; cursor: pointer; color: var(--muted); font-size: 0.85rem;
  transition: border-color .2s;
}
.drop-zone.dragover { border-color: var(--accent); color: var(--text); }
.upload-list { list-style: none; margin: 0.75rem 0; max-height: 180px; overflow-y: auto; }
.upload-list li { font-size: 0.82rem; padding: 0.25rem 0; border-bottom: 1px solid var(--border); }
.upload-list li.done { color: var(--success); }
.upload-list li.err  { color: var(--danger); }
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1rem; }

/* ── Footer ──────────────────────────────────────────────────────────────── */
.footer {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.5rem 1.5rem; font-size: 0.75rem; color: var(--muted);
  border-top: 1px solid var(--border); margin-top: 2rem;
}
.conn-status { font-size: 0.75rem; }
.conn-ok   { color: var(--success); }
.conn-err  { color: var(--danger); }

/* ── Stats Row (in-tab mini summary cards) ───────────────────────────────── */
.stats-row {
  display: flex; flex-wrap: wrap; gap: 0.75rem; margin-bottom: 1.25rem;
}
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.75rem 1.1rem;
  min-width: 130px; flex: 1;
  border-left: 3px solid var(--accent);
}
.stat-value { font-size: 1.45rem; font-weight: 800; line-height: 1; }
.stat-label { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-top: 0.25rem; }

/* ── Utility ─────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 700px) {
  .navbar-right .last-update { display: none; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .tabs { gap: 0; }
  .tab { padding: 0.55rem 0.6rem; font-size: 0.78rem; }
}
