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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2d3155;
  --text: #e2e8f0;
  --muted: #8892a4;
  --accent: #6366f1;        /* indigo */
  --accent-light: #818cf8;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --blue: #3b82f6;
  --sidebar-width: 220px;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
}

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

/* ── Sidebar ───────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 0;
  flex-shrink: 0;
  height: 100vh;
  overflow-y: auto;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px 20px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}
.logo-icon { font-size: 22px; color: var(--accent); }

.nav-links {
  list-style: none;
  padding: 0 8px;
}
.nav-links li a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.nav-links li a svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
  flex-shrink: 0;
}
.nav-links li a:hover { background: var(--surface2); color: var(--text); }
.nav-links li a.active { background: var(--surface2); color: var(--accent-light); }

/* ── Content area ──────────────────────────────────────────── */
.content {
  flex: 1;
  overflow-y: auto;
  height: 100vh;
  padding: 28px 32px;
}

/* ── Page header ───────────────────────────────────────────── */
.page-header {
  margin-bottom: 24px;
}
.page-header h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.page-header p {
  color: var(--muted);
  margin-top: 4px;
}

/* ── Stat cards ────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 16px;
}
.stat-card .label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.stat-card .value {
  font-size: 28px;
  font-weight: 700;
  margin-top: 6px;
  letter-spacing: -0.02em;
}
.stat-card .unit {
  font-size: 13px;
  color: var(--muted);
  font-weight: 400;
  margin-left: 3px;
}
.stat-card .sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

/* ── Section card ──────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
}
.card h2 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
}

/* ── Tables ────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
thead th {
  text-align: left;
  padding: 10px 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
thead th:hover { color: var(--text); }
tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface2); }
tbody td {
  padding: 10px 12px;
  white-space: nowrap;
}
tbody td a { color: var(--accent-light); text-decoration: none; }
tbody td a:hover { text-decoration: underline; }

/* ── Badge ─────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 600;
}
.badge-green { background: #14532d; color: #4ade80; }
.badge-amber { background: #451a03; color: #fcd34d; }
.badge-red   { background: #450a0a; color: #fca5a5; }
.badge-blue  { background: #172554; color: #93c5fd; }

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: opacity 0.15s;
  text-decoration: none;
}
.btn:hover { opacity: 0.85; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-ghost { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }

/* ── Map container ─────────────────────────────────────────── */
.map-wrap {
  height: 420px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  position: relative;
}
.map-full {
  height: calc(100vh - 100px);
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.map-wrap .maplibregl-map,
.map-full .maplibregl-map { width: 100%; height: 100%; }

/* ── Chart ─────────────────────────────────────────────────── */
.chart-wrap { height: 220px; position: relative; }
.chart-wrap canvas { width: 100% !important; }

/* ── Elevation + HR chart ──────────────────────────────────── */
.elevation-wrap { height: 180px; position: relative; }

/* ── Splits table ──────────────────────────────────────────── */
.pace-bar {
  display: inline-block;
  height: 6px;
  border-radius: 3px;
  background: var(--accent);
  vertical-align: middle;
  min-width: 4px;
}

/* ── Activity detail layout ────────────────────────────────── */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
@media (max-width: 900px) { .detail-grid { grid-template-columns: 1fr; } }

/* ── PB cards ──────────────────────────────────────────────── */
.pb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}
.pb-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}
.pb-card .distance {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent-light);
}
.pb-card .time {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin: 8px 0 4px;
}
.pb-card .meta { font-size: 12px; color: var(--muted); }

/* ── Hex score display ─────────────────────────────────────── */
.hex-score {
  font-size: 64px;
  font-weight: 800;
  text-align: center;
  color: var(--accent-light);
  letter-spacing: -0.04em;
  padding: 20px 0;
}
.hex-score .label { font-size: 14px; color: var(--muted); font-weight: 400; }

/* ── Filter bar ────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.filter-bar input,
.filter-bar select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 7px 12px;
  font-size: 13px;
  outline: none;
}
.filter-bar input:focus,
.filter-bar select:focus { border-color: var(--accent); }

/* ── Loading ───────────────────────────────────────────────── */
.loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 60vh;
  gap: 16px;
  color: var(--muted);
}
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Pagination ────────────────────────────────────────────── */
.pagination {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 16px;
}
.pagination button {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
.pagination button:disabled { opacity: 0.4; cursor: default; }
.pagination button.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ── Toast ─────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 20px;
  font-size: 13px;
  z-index: 9999;
  transform: translateY(80px);
  opacity: 0;
  transition: transform 0.3s, opacity 0.3s;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { border-color: var(--green); color: var(--green); }
.toast.error { border-color: var(--red); color: var(--red); }

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

/* ── Mobile menu button ────────────────────────────────────── */
.mobile-menu-btn {
  display: none;
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 200;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  cursor: pointer;
  flex-direction: column;
  gap: 4px;
  width: 38px;
  height: 38px;
  align-items: center;
  justify-content: center;
}
.mobile-menu-btn span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: transform 0.2s, opacity 0.2s;
}
.mobile-menu-btn.active span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.mobile-menu-btn.active span:nth-child(2) { opacity: 0; }
.mobile-menu-btn.active span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 768px) {
  body { overflow: auto; }

  .mobile-menu-btn { display: flex; }

  .sidebar {
    position: fixed;
    left: -100%;
    top: 0;
    height: 100vh;
    z-index: 100;
    transition: left 0.25s ease;
    box-shadow: 4px 0 24px rgba(0,0,0,0.4);
  }
  .sidebar.open { left: 0; }

  .content {
    padding: 56px 16px 24px;
    height: auto;
    min-height: 100vh;
    overflow-y: auto;
  }

  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .stat-card .value { font-size: 22px; }

  .detail-grid { grid-template-columns: 1fr; }

  .pb-grid { grid-template-columns: repeat(2, 1fr); }

  .map-wrap { height: 280px; }
  .map-full { height: calc(100vh - 80px); }
  .elevation-wrap { height: 150px; }
  .chart-wrap { height: 180px; }

  .filter-bar { gap: 6px; }
  .filter-bar input,
  .filter-bar select { font-size: 12px; padding: 6px 8px; }

  /* Tables: allow horizontal scroll, freeze first col */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 500px; }

  /* Journal two-col grids become single col */
  .card + .card { margin-top: 12px; }
  [style*="grid-template-columns: 1fr 1fr"] {
    display: block !important;
  }

  .page-header h1 { font-size: 20px; }

  .hex-score { font-size: 48px; }

  .btn { padding: 7px 12px; font-size: 12px; }

  /* Pagination: smaller buttons */
  .pagination button { padding: 5px 10px; font-size: 12px; }
}
