:root {
  --sidebar-w:     220px;
  --sidebar-bg:    #080b0e;
  --sidebar-text:  #8d98a3;
  --sidebar-active-bg: rgba(255,90,31,0.15);
  --sidebar-active-border: #ff5a1f;
  --main-bg:       #0b0f12;
  --card-bg:       #13181d;
  --border:        #232b33;
  --text:          #f1f3f5;
  --text-muted:    #8d98a3;
  --accent:        #ff5a1f;
  --accent-hover:  #e64a12;
  --success:       #22c55e;
  --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 1rem; }

.nav-section-label {
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #2f597a;
  padding: 0.9rem 1rem 0.3rem;
}
.nav-section-label:first-child { padding-top: 0.4rem; }

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

.nav-item svg { flex-shrink: 0; opacity: 0.75; transition: opacity 0.12s; }

.nav-item:hover { background: rgba(255,255,255,0.04); color: #fff; }
.nav-item:hover svg { opacity: 1; }

.nav-item.active {
  background: rgba(255,90,31,0.07);
  border-left-color: var(--sidebar-active-border);
  color: #ffffff;
  font-weight: 500;
}
.nav-item.active svg { opacity: 1; color: var(--accent); }

.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: #1a2128; color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: #122d45; }

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

/* ── 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: #0b0f12;
  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(255,90,31,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: #1a2128; }\n.clickable-row { cursor: pointer; }\n.clickable-row:hover td { background: #1a2128; }

.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(255,90,31,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: #232b33;
  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: #1a2128;
  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: #1a2128;
}

.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;
}

/* ── Dashboard redesign (Phase 2) ─────────────────────── */
/* Reusable component classes, currently used by dashboard.html only. */

.page-greeting { margin-bottom: 1.25rem; }
.page-greeting h2 { font-size: 1.375rem; font-weight: 700; color: #fff; }
.page-greeting .sub { font-size: 0.8125rem; color: var(--text-muted); margin-top: 0.15rem; }

.metric-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.metric-tile {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.875rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.metric-tile .m-icon {
  width: 34px; height: 34px; border-radius: 0.5rem; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,90,31,0.1); color: var(--accent);
}
.metric-tile .m-value { font-size: 1.375rem; font-weight: 700; line-height: 1.15; color: #fff; }
.metric-tile .m-label { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.1rem; }

.metric-row-sub {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.625rem;
  margin-bottom: 1.5rem;
}
.metric-tile-sub {
  display: flex; align-items: baseline; gap: 0.4rem;
  padding: 0.5rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: transparent;
}
.metric-tile-sub .m-value { font-size: 0.9375rem; font-weight: 600; color: var(--text); }
.metric-tile-sub .m-label { font-size: 0.75rem; color: var(--text-muted); }

.chart-card { margin-bottom: 1.5rem; }
.chart-card-head {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 0.5rem;
  margin-bottom: 1rem;
}
.chart-card-head .card-title { margin-bottom: 0; }
.chart-card-head .sub { font-size: 0.75rem; color: var(--text-muted); }

.seg-tabs { display: flex; gap: 0.25rem; background: #0b0f12; border: 1px solid var(--border); border-radius: 0.375rem; padding: 0.2rem; }
.seg-btn {
  border: none; background: transparent; color: var(--text-muted);
  font-size: 0.8125rem; font-weight: 500; padding: 0.3rem 0.7rem;
  border-radius: 0.25rem; cursor: pointer; transition: background 0.12s, color 0.12s;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active { background: var(--accent); color: #fff; }

.dash-split {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1rem;
  align-items: start;
  margin-bottom: 1.5rem;
}

.table-compact th, .table-compact td { padding: 0.5rem 0.65rem; font-size: 0.8125rem; }
.table-compact tr.ride-row:hover td { background: #1a2128; }

.recovery-panel-head {
  display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 1rem;
}
.recovery-panel-head .card-title { margin-bottom: 0; }
.recovery-panel-head a { font-size: 0.75rem; color: var(--accent); text-decoration: none; }

.gauge-ring {
  --pct: 0;
  position: relative;
  width: 88px; height: 88px; border-radius: 50%;
  background: conic-gradient(var(--gauge-color, var(--accent)) calc(var(--pct) * 3.6deg), var(--border) 0);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 0.75rem;
}
.gauge-ring::before {
  content: '';
  width: 68px; height: 68px; border-radius: 50%;
  background: var(--card-bg);
  position: absolute;
}
.gauge-ring .gauge-value { position: relative; font-size: 1.25rem; font-weight: 700; color: #fff; }

.recovery-stats-row {
  display: flex; justify-content: space-around; text-align: center;
  padding-top: 0.875rem; margin-top: 0.875rem; border-top: 1px solid var(--border);
}
.recovery-stats-row .m-value { font-size: 0.9375rem; font-weight: 700; }
.recovery-stats-row .m-label { font-size: 0.6875rem; color: var(--text-muted); margin-top: 0.1rem; }

.toolbar {
  display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: flex-end;
  padding: 0.75rem 0; margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.toolbar .form-group-sm { display: flex; flex-direction: column; gap: 0.25rem; }
.toolbar label { font-size: 0.75rem; color: var(--text-muted); margin: 0; font-weight: 400; }
.toolbar input, .toolbar select {
  background: #1a2128; color: var(--text); border: 1px solid var(--border);
  border-radius: 5px; padding: 0.35rem 0.6rem; font-size: 0.875rem;
}

@media (max-width: 1100px) {
  .metric-row { grid-template-columns: repeat(2, 1fr); }
  .metric-row-sub { grid-template-columns: repeat(3, 1fr); }
  .dash-split { grid-template-columns: 1fr; }
}

@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)); }
  .metric-row, .metric-row-sub { grid-template-columns: 1fr; }
}

/* public demo banner */
.demo-banner { background: linear-gradient(90deg,#ff5a1f,#c13a00); color:#fff; font-size:.8rem; font-weight:600; letter-spacing:.02em; padding:.4rem 1rem; text-align:center; }
.demo-banner a { color:#fff; text-decoration:underline; }
