/* styles.css — GPX Viewer. Light/dark via [data-theme]; chart.js reads the
   --muted / --grid / --tooltip-bg / --accent custom properties at draw time. */

:root {
  --accent: #2563eb;
  --accent-ink: #fff;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --border: #e2e8f0;
  --grid: rgba(15, 23, 42, 0.07);
  --tooltip-bg: rgba(15, 23, 42, 0.92);
  --shadow: 0 1px 2px rgba(15,23,42,.06), 0 8px 24px rgba(15,23,42,.08);
  --radius: 12px;
  --topbar-h: 56px;
  --sidebar-w: 340px;
  --chart-h: 184px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

:root[data-theme="dark"] {
  --accent: #3b82f6;
  --bg: #0b1220;
  --surface: #111827;
  --surface-2: #0f172a;
  --ink: #f1f5f9;
  --ink-2: #cbd5e1;
  --muted: #94a3b8;
  --border: #1f2937;
  --grid: rgba(148, 163, 184, 0.14);
  --tooltip-bg: rgba(2, 6, 23, 0.94);
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.45);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Topbar ─────────────────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 1000;
}
.brand {
  display: flex; align-items: center; gap: 9px;
  font-weight: 700; font-size: 17px; letter-spacing: -0.01em;
}
.brand-mark { color: var(--accent); }
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.btn {
  font: inherit; font-size: 13px; font-weight: 600;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--ink-2); padding: 7px 12px; border-radius: 9px;
  cursor: pointer; transition: background .15s, border-color .15s, color .15s, transform .05s;
}
.btn:hover { border-color: var(--muted); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.icon { width: 34px; padding: 7px 0; text-align: center; }
.btn.lg { padding: 11px 20px; font-size: 15px; }

.select {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--muted); font-weight: 600;
}
.select select {
  font: inherit; font-size: 13px; font-weight: 600; color: var(--ink-2);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 9px; padding: 6px 8px; cursor: pointer;
}

/* ── Layout ─────────────────────────────────────────────────────────────── */
.layout { flex: 1 1 auto; display: flex; min-height: 0; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--bg);
  border-right: 1px solid var(--border);
  padding: 14px;
  display: flex; flex-direction: column; gap: 14px;
  overflow-y: auto;
}
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; }
.panel-head h2 {
  margin: 0; font-size: 14px; font-weight: 700; letter-spacing: -0.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pill {
  display: inline-block; min-width: 20px; text-align: center;
  font-size: 12px; font-weight: 700; color: var(--muted);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 20px; padding: 1px 7px; margin-left: 4px;
}

/* Track list */
.track-list { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.track {
  display: grid; grid-template-columns: 28px 1fr 24px; align-items: center;
  gap: 6px; padding: 6px; border-radius: 9px; border: 1px solid transparent;
}
.track:hover { background: var(--surface-2); }
.track.active { background: var(--surface-2); border-color: var(--border); }
.track.hidden-track { opacity: .45; }
.track button { all: unset; cursor: pointer; }
.track-vis { display: flex; justify-content: center; }
.swatch { width: 14px; height: 14px; border-radius: 4px; box-shadow: 0 0 0 1px rgba(0,0,0,.15) inset; }
.track-name { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.t-title { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.t-sub { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track-del { text-align: center; color: var(--muted); font-size: 13px; }
.track-del:hover { color: #dc2626; }

/* Stat grid */
.summary .panel-head h2 { color: var(--ink); }
.stat-grid {
  margin-top: 12px;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
}
.stat {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 9px 8px; text-align: center;
}
.stat-v { font-size: 15px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.stat-k { font-size: 10.5px; color: var(--muted); margin-top: 3px; text-transform: uppercase; letter-spacing: .03em; }
.start-time { margin-top: 10px; font-size: 11.5px; color: var(--muted); text-align: center; }

.segment {
  margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--border);
}
.seg-head { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--accent); margin-bottom: 8px; }
.seg-body { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px 6px; }
.seg-body span { display: flex; flex-direction: column; font-size: 10.5px; color: var(--muted); }
.seg-body b { font-size: 14px; font-weight: 700; color: var(--ink); }

.privacy { margin: auto 2px 0; font-size: 11px; color: var(--muted); text-align: center; }

/* ── Stage (map + chart) ────────────────────────────────────────────────── */
.stage { position: relative; flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
#map { flex: 1 1 auto; min-height: 0; background: var(--surface-2); }
.chart-dock {
  flex: 0 0 var(--chart-h); height: var(--chart-h);
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 6px 10px 4px;
}
.chart-dock { position: relative; }
#chart { width: 100%; height: 100%; display: block; cursor: crosshair; touch-action: none; }
.chart-series {
  position: absolute; top: 8px; right: 14px; z-index: 5;
}
.chart-series select {
  font: inherit; font-size: 12px; font-weight: 600; color: var(--ink-2);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 4px 8px; cursor: pointer; box-shadow: var(--shadow);
}

/* Splits table */
.splits-panel .panel-head { margin-bottom: 8px; }
.splits-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.splits-table tr { cursor: pointer; }
.splits-table td { padding: 4px 4px; border-top: 1px solid var(--border); vertical-align: middle; }
.splits-table tr:first-child td { border-top: none; }
.splits-table tr:hover { background: var(--surface-2); }
.splits-table tr.sel { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.sp-n { width: 26px; font-weight: 700; color: var(--ink); text-align: center; }
.sp-part { color: var(--muted); font-weight: 600; }
.sp-pace { width: 78px; font-variant-numeric: tabular-nums; }
.sp-gain { width: 56px; color: var(--muted); font-variant-numeric: tabular-nums; }
.sp-bar { padding-left: 6px !important; }
.sp-bar span { display: block; height: 7px; border-radius: 4px; min-width: 2px; }

.legend {
  position: absolute; top: 12px; left: 12px; z-index: 500;
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 9px; box-shadow: var(--shadow); padding: 6px 10px;
  font-size: 11px; color: var(--muted); font-weight: 600;
}
.legend-bar { width: 110px; height: 9px; border-radius: 5px; }

/* Leaflet tweaks so controls match the theme */
.leaflet-bar a, .leaflet-control-layers {
  background: var(--surface) !important; color: var(--ink) !important;
  border-color: var(--border) !important;
}
.leaflet-bar a { border-bottom-color: var(--border) !important; }
:root[data-theme="dark"] .leaflet-tile { filter: brightness(.92) contrast(1.02); }

/* ── Empty state ────────────────────────────────────────────────────────── */
.empty {
  position: absolute; inset: 0; z-index: 600;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
body.has-tracks .empty { display: none; }
.empty-card { text-align: center; max-width: 440px; padding: 24px; color: var(--ink-2); }
.empty-card svg { color: var(--accent); opacity: .9; }
.empty-card h1 { margin: 14px 0 6px; font-size: 24px; letter-spacing: -0.02em; color: var(--ink); }
.empty-card p { margin: 0 0 18px; font-size: 14px; line-height: 1.5; color: var(--muted); }
.empty-card .hint { margin-top: 14px; font-size: 12.5px; }

/* ── Drop veil ──────────────────────────────────────────────────────────── */
.drop-veil {
  position: fixed; inset: 0; z-index: 5000; display: none;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  align-items: center; justify-content: center; padding: 24px;
}
.drop-veil.show { display: flex; }
.drop-inner {
  border: 3px dashed var(--accent); border-radius: 18px;
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 700; color: var(--accent);
  background: color-mix(in srgb, var(--surface) 70%, transparent);
}

/* ── Toast ──────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: var(--tooltip-bg); color: #fff; font-size: 13px; font-weight: 600;
  padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 6000;
  max-width: 80vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Share modal ────────────────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; z-index: 7000; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(2, 6, 23, .45); backdrop-filter: blur(2px); }
.modal-card {
  position: relative; width: min(520px, 100%);
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow); padding: 18px 18px 16px;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h3 { margin: 0; font-size: 17px; letter-spacing: -0.01em; }
.modal-x { all: unset; cursor: pointer; color: var(--muted); font-size: 16px; padding: 4px 8px; border-radius: 8px; }
.modal-x:hover { background: var(--surface-2); color: var(--ink); }

.seg-toggle { display: flex; gap: 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; margin-bottom: 14px; }
.seg-btn {
  all: unset; cursor: pointer; flex: 1; text-align: center;
  font-size: 13px; font-weight: 600; color: var(--muted);
  padding: 7px 10px; border-radius: 8px; transition: background .15s, color .15s;
}
.seg-btn:hover { color: var(--ink); }
.seg-btn.sel { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(15,23,42,.08); }
.seg-btn:disabled { opacity: .4; cursor: not-allowed; }

.link-row { display: flex; gap: 8px; }
.link-row input {
  flex: 1; min-width: 0; font: inherit; font-size: 13px; color: var(--ink-2);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 9px; padding: 9px 11px;
}
.modal-note { margin: 10px 2px 0; font-size: 12px; color: var(--muted); line-height: 1.45; min-height: 16px; }
.modal-foot { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.foot-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-right: 2px; }
.modal-foot .btn { font-size: 12px; padding: 6px 10px; }

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 820px) {
  :root { --chart-h: 150px; }
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%; flex: 0 0 auto; max-height: 42%;
    border-right: none; border-bottom: 1px solid var(--border);
    flex-direction: row; overflow-x: auto; overflow-y: hidden;
  }
  .sidebar .panel { min-width: 260px; }
  .privacy { display: none; }
  .brand span { display: none; }
}
