:root {
  --sidebar-w:     220px;
  --sidebar-bg:    #050d18;
  --sidebar-text:  #5d8fa8;
  --sidebar-active-bg: rgba(252,76,2,0.15);
  --sidebar-active-border: #fc4c02;
  --main-bg:       #071525;
  --card-bg:       #0b1e30;
  --border:        #163352;
  --text:          #c8e0ed;
  --text-muted:    #4d7d95;
  --accent:        #fc4c02;
  --accent-hover:  #e04400;
  --success:       #10b981;
  --warning:       #f59e0b;
  --danger:        #ef4444;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

body {
  font-family: var(--font);
  font-size: 0.9375rem;
  color: var(--text);
  background: var(--main-bg);
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────── */

.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-header {
  padding: 1.25rem 1rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-header .app-name {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #ffffff;
}

.sidebar-header .person-name {
  margin-top: 0.25rem;
  font-size: 0.8125rem;
  color: var(--sidebar-text);
}

.sidebar-nav { padding: 0.5rem 0; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.625rem 1rem;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.875rem;
  border-left: 3px solid transparent;
  transition: background 0.12s, color 0.12s;
}

.nav-item:hover { background: rgba(255,255,255,0.05); color: #fff; }

.nav-item.active {
  background: var(--sidebar-active-bg);
  border-left-color: var(--sidebar-active-border);
  color: #ffffff;
}

.nav-divider {
  height: 1px;
  background: rgba(255,255,255,0.07);
  margin: 0.375rem 0;
}

/* ── Main area ───────────────────────────────────────── */

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.topbar {
  height: 52px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.topbar h1 { font-size: 1.0625rem; font-weight: 600; }

.topbar-actions { display: flex; gap: 0.5rem; }

.content {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
}

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

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

.card-title {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

/* ── Map + chart standard layout ────────────────────── */
/* Usage: wrap map card + charts-col in .map-charts-grid  */

.map-charts-grid {
  display: grid;
  gap: 1rem;
  margin-bottom: 1.5rem;
  align-items: start;
}
.map-charts-grid.has-both { grid-template-columns: 3fr 2fr; }
@media (max-width: 900px) {
  .map-charts-grid.has-both { grid-template-columns: 1fr; }
}
.map-card { padding: 0; overflow: hidden; }
.map-card .leaflet-container { height: 520px; }
.charts-col {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.map-charts-grid.has-both .charts-col { height: 520px; }
.map-charts-grid.has-both .charts-col .card {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding-bottom: 0.5rem;
}
.map-charts-grid.has-both .charts-col .card canvas { flex: 1; min-height: 0; }

/* ── Stats ───────────────────────────────────────────── */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.625rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.75rem 0.875rem;
}

.stat-value {
  font-size: 1.125rem;
  font-weight: 700;
  line-height: 1.1;
  word-break: break-word;
  overflow-wrap: break-word;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

.stat-sub {
  font-size: 0.6875rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
  opacity: 0.75;
}

/* ── Buttons ─────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  transition: background 0.12s, border-color 0.12s;
  line-height: 1.4;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary { background: #0e2437; color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: #122d45; }

.btn-strava { background: #fc4c02; color: #fff; font-weight: 600; }
.btn-strava:hover { background: #e04400; }

/* ── Forms ───────────────────────────────────────────── */

.form-group { margin-bottom: 1rem; }

label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.375rem;
}

input[type="text"],
input[type="url"],
input[type="password"],
select,
textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  font-size: 0.875rem;
  font-family: var(--font);
  color: var(--text);
  background: #071525;
  transition: border-color 0.12s, box-shadow 0.12s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(252,76,2,0.2);
}

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

table { width: 100%; border-collapse: collapse; }

th {
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 0.6875rem 0.75rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
}

tr:last-child td { border-bottom: none; }
.ride-row { cursor: pointer; }
\.ride-row:hover td { background: #0e2437; }\n.clickable-row { cursor: pointer; }\n.clickable-row:hover td { background: #0e2437; }

.text-muted { color: var(--text-muted); font-size: 0.8125rem; }

/* ── Flash messages ──────────────────────────────────── */

.flash {
  padding: 0.75rem 1rem;
  border-radius: 0.375rem;
  margin-bottom: 1rem;
  font-size: 0.875rem;
  border: 1px solid;
}

.flash-success { background: #053321; color: #4ade80;  border-color: #059669; }
.flash-error   { background: #2d0a0a; color: #f87171; border-color: #dc2626; }
.flash-warning { background: #2d1600; color: #fcd34d; border-color: #d97706; }

/* ── Empty states ────────────────────────────────────── */

.empty-state {
  padding: 2.5rem 1.5rem;
  text-align: center;
  color: var(--text-muted);
}

.empty-icon { font-size: 2rem; margin-bottom: 0.75rem; opacity: 0.4; }

/* ── Mobile hamburger ────────────────────────────────── */

.menu-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  background: var(--accent);
  border: none;
  border-radius: 0.375rem;
  cursor: pointer;
  padding: 0;
}

.menu-toggle:hover { background: var(--accent-hover); }

.hamburger-line {
  display: block;
  width: 20px;
  height: 2px;
  background: #fff;
  border-radius: 2px;
  flex-shrink: 0;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 199;
}

/* ── Ride tree (year / month / day) ──────────────────── */

.tree-year { border-bottom: 1px solid var(--border); }
.tree-year:last-child { border-bottom: none; }

.tree-year-summary,
.tree-month-summary {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0.5rem;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.tree-year-summary::-webkit-details-marker,
.tree-month-summary::-webkit-details-marker { display: none; }

.tree-year-summary::before  { content: '▶'; font-size: 0.625rem; color: var(--text-muted); transition: transform 0.15s; }
.tree-month-summary::before { content: '▶'; font-size: 0.5rem;   color: var(--text-muted); transition: transform 0.15s; }
details[open] > .tree-year-summary::before,
details[open] > .tree-month-summary::before { transform: rotate(90deg); }

.tree-year-summary:hover,
.tree-month-summary:hover { background: rgba(255,255,255,0.03); border-radius: 0.25rem; }

.tree-year-label  { font-size: 1rem; font-weight: 700; color: var(--text); }
.tree-month-label { font-size: 0.875rem; font-weight: 600; color: var(--text); padding-left: 1rem; }
.tree-meta        { font-size: 0.8125rem; color: var(--text-muted); margin-left: auto; }

.tree-month { padding-left: 0.5rem; }

.tree-day { padding-left: 1rem; margin-bottom: 0.25rem; }

.tree-day-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}
.tree-day-header .tree-meta { font-weight: 400; }

/* ── Import drop zone ────────────────────────────────── */

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: 0.5rem;
  padding: 2.5rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.drop-zone:hover,
.drop-zone.drag-over { border-color: var(--accent); background: rgba(252,76,2,0.05); }

.drop-icon  { font-size: 2rem; margin-bottom: 0.5rem; }
.drop-label { font-size: 0.9375rem; color: var(--text); margin-bottom: 0.25rem; }
.drop-browse { color: var(--accent); cursor: pointer; text-decoration: underline; }
.drop-hint  { font-size: 0.8125rem; color: var(--text-muted); }

.progress-bar-wrap {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 0.5rem;
}
.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.3s ease;
}

/* ── Rider avatars ───────────────────────────────────────── */

.rider-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.rider-initial {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #163352;
  border: 1px solid var(--border);
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text);
  flex-shrink: 0;
}

.rider-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.65rem 0.3rem 0.3rem;
  background: #0e2437;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text);
  text-decoration: none;
}

.rider-badge img,
.rider-badge .rider-initial {
  width: 22px;
  height: 22px;
  font-size: 0.6875rem;
}

.rider-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  text-align: center;
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.15s, background 0.15s;
}

.rider-card:hover {
  border-color: var(--accent);
  background: #0e2437;
}

.rider-card .rider-avatar,
.rider-card .rider-initial {
  width: 128px;
  height: 128px;
  font-size: 3rem;
}

.riders-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
}

@media (max-width: 768px) {
  body { overflow: auto; height: auto; }

  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    height: 100%;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
  }

  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }
  .menu-toggle { display: flex; }
  .main { width: 100%; min-height: 100vh; overflow: visible; }
  .topbar { padding: 0 1rem; gap: 0.75rem; }
  .content { padding: 1rem; }
  .stats-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
}
