/* ── Variables ───────────────────────────────────────────────── */
:root {
  --bg:          #0d1117;
  --bg2:         #161b22;
  --bg3:         #21262d;
  --border:      #30363d;
  --text:        #e6edf3;
  --muted:       #8b949e;
  --teal:        #00d4aa;
  --teal-dim:    rgba(0, 212, 170, 0.12);
  --blue:        #58a6ff;
  --blue-dim:    rgba(88, 166, 255, 0.12);
  --purple:      #bc8cff;
  --purple-dim:  rgba(188, 140, 255, 0.12);
  --green:       #3fb950;
  --green-dim:   rgba(63, 185, 80, 0.12);
  --orange:      #f0883e;
  --orange-dim:  rgba(240, 136, 62, 0.12);
  --red:         #f85149;
  --red-dim:     rgba(248, 81, 73, 0.12);
  --radius:      10px;
  --shadow:      0 4px 24px rgba(0,0,0,0.4);
  --font-mono:   'JetBrains Mono', monospace;
}

/* ── Reset ────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-size: 14px;
  line-height: 1.5;
}

/* ── Header ──────────────────────────────────────────────────── */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: rgba(13, 17, 23, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.header-brand { display: flex; align-items: center; gap: 12px; }
.brand-icon {
  width: 32px; height: 32px;
  color: var(--teal);
  flex-shrink: 0;
}
.brand-text h1 { font-size: 18px; font-weight: 700; color: var(--text); }
#headerSub     { font-size: 12px; color: var(--muted); }

.header-controls { display: flex; align-items: center; gap: 12px; }

.status-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 20px;
  background: var(--bg3);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--muted);
  transition: background 0.3s;
}
.status-dot.ok     { background: var(--green);  box-shadow: 0 0 6px var(--green);  }
.status-dot.warn   { background: var(--orange); box-shadow: 0 0 6px var(--orange); }
.status-dot.error  { background: var(--red);    box-shadow: 0 0 6px var(--red);    }

.btn-refresh, .btn-map {
  padding: 6px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s, border-color 0.15s;
}
.btn-refresh:hover, .btn-map:hover { background: var(--bg2); border-color: var(--teal); color: var(--teal); }
.btn-refresh:disabled { opacity: 0.5; cursor: not-allowed; }
#refreshIcon { display: inline-block; transition: transform 0.6s; }
#refreshIcon.spinning { animation: spin 0.8s linear infinite; }

/* ── Main layout ─────────────────────────────────────────────── */
.main {
  flex: 1;
  padding: 24px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}
.dashboard { display: flex; flex-direction: column; gap: 20px; }

/* ── Loading ──────────────────────────────────────────────────── */
.loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  min-height: 60vh;
  color: var(--muted);
}
.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--bg3);
  border-top-color: var(--teal);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ── Cards ────────────────────────────────────────────────────── */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.card:hover { border-color: rgba(255,255,255,0.12); }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.card-title  { font-size: 14px; font-weight: 600; color: var(--text); }
.card-label  { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px; }

/* ── Stat cards grid ──────────────────────────────────────────── */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}
.stat-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
  transition: transform 0.15s, border-color 0.2s, box-shadow 0.2s;
}
.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--card-accent, var(--teal));
}
.stat-card .label    { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.stat-card .value    { font-size: 28px; font-weight: 700; color: var(--text); margin: 6px 0 4px; font-family: var(--font-mono); line-height: 1; }
.stat-card .sublabel { font-size: 11px; color: var(--muted); }
.stat-card .delta    { font-size: 12px; margin-top: 8px; font-weight: 500; }
.delta.up   { color: var(--green); }
.delta.down { color: var(--red);   }
.delta.same { color: var(--muted); }

/* ── Two-col layout ───────────────────────────────────────────── */
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

/* ── Group card ───────────────────────────────────────────────── */
.group-stat-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 6px 0;
  border-bottom: 1px solid var(--bg3);
  font-size: 13px;
}
.group-stat-row:last-child { border-bottom: none; }
.group-stat-row .key   { color: var(--muted); }
.group-stat-row .val   { font-family: var(--font-mono); font-weight: 600; }

.progress-section { margin-top: 16px; }
.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}
.progress-label .pct { color: var(--teal); font-weight: 600; }
.progress-bar-bg {
  height: 8px;
  background: var(--bg3);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 12px;
}
.progress-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.8s ease;
  background: linear-gradient(90deg, var(--bar-color, var(--teal)), color-mix(in srgb, var(--bar-color, var(--teal)) 60%, white));
}
.you-vs-avg-row {
  margin-top: 14px;
  padding: 12px;
  background: var(--bg3);
  border-radius: 8px;
  font-size: 13px;
}
.you-vs-avg-row .highlight { color: var(--teal); font-weight: 700; }
.you-vs-avg-row .need      { color: var(--orange); }

/* ── Activity card ────────────────────────────────────────────── */
.activity-list { display: flex; flex-direction: column; gap: 0; }
.activity-item {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 12px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--bg3);
  font-size: 13px;
}
.activity-item:last-child { border-bottom: none; }
.activity-file { color: var(--muted); font-family: var(--font-mono); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.activity-date { color: var(--muted); font-size: 11px; }
.num-green { color: var(--green);  font-family: var(--font-mono); font-weight: 600; }
.num-blue  { color: var(--blue);   font-family: var(--font-mono); font-weight: 600; }
.activity-header {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 12px;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

/* ── Badges ───────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.badge-teal   { background: var(--teal-dim);   color: var(--teal);   }
.badge-blue   { background: var(--blue-dim);   color: var(--blue);   }
.badge-purple { background: var(--purple-dim); color: var(--purple); }
.badge-green  { background: var(--green-dim);  color: var(--green);  }
.badge-orange { background: var(--orange-dim); color: var(--orange); }
.badge-red    { background: var(--red-dim);    color: var(--red);    }

/* ── Charts ───────────────────────────────────────────────────── */
.chart-card { display: flex; flex-direction: column; }
.chart-wrap { position: relative; flex: 1; min-height: 220px; }
.chart-wrap canvas { width: 100% !important; height: 220px !important; }
.chart-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 13px;
  background: var(--bg2);
  border-radius: 6px;
  display: none;
}
.chart-empty.visible { display: flex; }

/* ── Uploads table ───────────────────────────────────────────── */
.uploads-card { padding-bottom: 4px; }
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  text-align: left;
  padding: 8px 12px;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 500;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--bg3);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg3); }
.data-table .mono { font-family: var(--font-mono); }
.data-table .file-cell {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
}
.status-done   { color: var(--green);  }
.status-error  { color: var(--red);    }
.status-pending{ color: var(--orange); }

/* ── Footer ───────────────────────────────────────────────────── */
.footer {
  display: flex;
  justify-content: center;
  gap: 32px;
  padding: 12px 24px;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  background: var(--bg);
}
.mono { font-family: var(--font-mono); }

/* ── Animations ───────────────────────────────────────────────── */
@keyframes spin    { to { transform: rotate(360deg); } }
@keyframes fadeIn  { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.dashboard { animation: fadeIn 0.4s ease; }

/* ── Responsive ───────────────────────────────────────────────── */
@media (max-width: 900px) {
  .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .main           { padding: 16px; }
  .cards-grid     { grid-template-columns: repeat(2, 1fr); }
  .header         { padding: 12px 16px; }
  .brand-text h1  { font-size: 15px; }
  .footer         { flex-direction: column; align-items: center; gap: 6px; }
}
