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

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: #f5f5f5;
  color: #222;
}

/* ── Index page ───────────────────────────────────── */

.page {
  max-width: 720px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

h1 { font-size: 1.6rem; margin-bottom: 1.5rem; }

.run-list { list-style: none; }

.run-item {
  background: #fff;
  border-radius: 8px;
  padding: 1rem 1.25rem;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
  text-decoration: none;
  color: inherit;
  transition: box-shadow .15s;
}
.run-item:hover { box-shadow: 0 3px 8px rgba(0,0,0,.15); }

.run-name { font-weight: 600; font-size: 1rem; }
.run-meta { font-size: .8rem; color: #666; margin-top: .2rem; }

.badge {
  font-size: .7rem;
  font-weight: 700;
  padding: .2rem .5rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.badge-active  { background: #dcfce7; color: #166534; }
.badge-finished { background: #e5e7eb; color: #374151; }

.empty { text-align: center; color: #999; margin-top: 3rem; }

/* ── Run map page ─────────────────────────────────── */

html, body { height: 100%; }

#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

#sidebar {
  width: 260px;
  flex-shrink: 0;
  background: #fff;
  border-right: 1px solid #e5e7eb;
  padding: 1.25rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

#run-name {
  font-size: 1.1rem;
  font-weight: 700;
  word-break: break-word;
}

.donate-card {
  background: rgba(34,197,94,.08);
  border: 1px solid rgba(34,197,94,.35);
  border-radius: 8px;
  padding: .7rem .75rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

.donate-text {
  font-size: .8rem;
  line-height: 1.3;
  margin: 0;
}

.donate-btn {
  display: block;
  background: linear-gradient(135deg, #22c55e, #10b981);
  border: 1px solid rgba(34,197,94,.65);
  color: #fff;
  text-align: center;
  text-decoration: none;
  font-size: .85rem;
  font-weight: 800;
  padding: .55rem .75rem;
  border-radius: 10px;
  transition: opacity .15s;
}
.donate-btn:hover { opacity: .88; }

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .5rem;
}

.stat {
  background: #f9fafb;
  border-radius: 6px;
  padding: .6rem .75rem;
}
.stat-label { font-size: .7rem; color: #6b7280; text-transform: uppercase; letter-spacing: .05em; }
.stat-value { font-size: 1.1rem; font-weight: 600; margin-top: .1rem; }

/* Featured distance stat */
.stat-feature { text-align: center; }
.stat-feature .stat-value { font-size: 1.5rem; }

/* Avg pace + moving time row */
.stat-pace-row {
  display: flex;
  justify-content: space-around;
  text-align: center;
}
.stat-pace-row .stat-value { font-size: 1.1rem; }

/* Secondary (small) stats — start, last update, elapsed, finished */
.stat-sm { padding: .35rem .5rem; }
.stat-sm .stat-label { font-size: .6rem; }
.stat-sm .stat-value { font-size: .75rem; }

#status-badge { align-self: flex-start; }

#gpx-link {
  display: inline-block;
  font-size: .8rem;
  color: #2563eb;
  text-decoration: none;
  margin-top: auto;
}
#gpx-link:hover { text-decoration: underline; }

#map { flex: 1; }

#loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,.8);
  font-size: 1.1rem;
  color: #555;
  z-index: 9999;
}

/* Tab bar — hidden on desktop, visible on mobile */
#tab-bar { display: none; }

@media (max-width: 640px) {
  #app { flex-direction: column; }

  #tab-bar {
    display: flex;
    flex-shrink: 0;
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
    z-index: 1000;
  }

  .tab-btn {
    flex: 1;
    padding: .65rem .5rem;
    border: none;
    border-bottom: 3px solid transparent;
    background: none;
    font-size: .9rem;
    font-weight: 600;
    color: #6b7280;
    cursor: pointer;
    transition: color .15s, border-color .15s;
  }

  .tab-btn.tab-active {
    color: #2563eb;
    border-bottom-color: #2563eb;
  }

  /* Map tab: full-screen map, sidebar hidden */
  #app.tab-map #sidebar { display: none; }
  #app.tab-map #map    { flex: 1; min-height: 0; }

  /* Stats tab: scrollable sidebar fills screen, map hidden */
  #app.tab-stats #sidebar {
    display: flex;
    width: 100%;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    border-right: none;
  }
  #app.tab-stats #map { display: none; }
}

/* ── Analytics sections ──────────────────────────── */

.analytics-section {
  border-top: 1px solid #e5e7eb;
  padding-top: .75rem;
}

.analytics-section h2 {
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: #6b7280;
  margin-bottom: .4rem;
}

.analytics-summary {
  font-size: .75rem;
  color: #555;
  margin-bottom: .4rem;
  line-height: 1.4;
}

.analytics-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .73rem;
}

.analytics-table th {
  text-align: left;
  font-weight: 600;
  color: #6b7280;
  padding: .2rem .3rem;
  border-bottom: 1px solid #e5e7eb;
}

.analytics-table td {
  padding: .25rem .3rem;
  border-bottom: 1px solid #f3f4f6;
}

.analytics-table tr:last-child td { border-bottom: none; }

.chart-wrap {
  position: relative;
  height: 130px;
}
