/* Run — jog tracker & local events. Dark theme, same family as FindIt /
 * EVENTULIST, with a fresh run-green accent. */

:root {
  --bg: #0b0f14;
  --card: #151b23;
  --card2: #1b2330;
  --line: #2a3342;
  --text: #e6edf3;
  --muted: #8b98a5;
  --accent: #4f9cf9;
  --accent2: #6ee7b7;
  --good: #3fb950;
  --warn: #d29922;
  --bad: #f85149;
  --radius: 14px;
  --run: #6ee7b7;          /* route + run stats */
  --trail: #f472b6;        /* jogging paths overlay */
  --park: #4ade80;         /* parks overlay */
  --ev: #a78bfa;           /* events dots */
  --pace-fast: #34d399;
  --pace-mid: #fbbf24;
  --pace-slow: #f87171;
  --header-h: 56px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.hidden { display: none !important; }

/* ---- header ---- */
header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 14px calc(8px + env(safe-area-inset-top, 0)) 14px;
  background: rgba(11, 15, 20, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.logo { font-size: 18px; letter-spacing: 0.3px; white-space: nowrap; }
.logo b { color: var(--run); }
.status { font-size: 12.5px; color: var(--muted); text-align: right; max-width: 55%; line-height: 1.35; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev-link { font-size: 12.5px; color: var(--accent); text-decoration: none; white-space: nowrap; padding: 6px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); }
@media (max-width: 420px) { .ev-link { font-size: 11px; padding: 5px 8px; } }

/* ---- app layout ---- */
.app {
  position: fixed; inset: 0;
  top: calc(var(--header-h) + env(safe-area-inset-top, 0));
  bottom: calc(34px + env(safe-area-inset-bottom, 0));
  display: flex;
}
.map-wrap { position: relative; flex: 1; min-width: 0; }
#map {
  position: absolute; inset: 0;
  z-index: 0; /* stacking context: keeps Leaflet's internal panes (z 200-1000) INSIDE the map so they never paint over the FABs / ctrl bar / panel */
  background: #0b0f14;
}

/* ---- panel (left column on desktop, bottom sheet on phone) ---- */
.panel {
  background: var(--bg);
  position: relative;
  display: flex; flex-direction: column;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.view { padding: 14px; }
.view:not(.hidden) + .view:not(.hidden) { border-top: 1px solid var(--line); }

/* ---- where box ---- */
.where {
  display: flex; align-items: center; gap: 8px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 12px; margin-bottom: 12px;
  font-size: 13.5px; color: var(--muted);
}
.where-dot {
  flex: 0 0 auto; width: 10px; height: 10px; border-radius: 50%;
  background: var(--warn); box-shadow: 0 0 0 4px rgba(210, 153, 34, 0.15);
}
.where.ok .where-dot { background: var(--good); box-shadow: 0 0 0 4px rgba(63, 185, 80, 0.15); }
.where .where-name { color: var(--text); font-weight: 600; }

/* ---- start card ---- */
.start-card { text-align: center; padding: 6px 0 14px; }
.run-btn {
  border: none; cursor: pointer; border-radius: 999px;
  font-size: 19px; font-weight: 700; letter-spacing: 0.4px;
  color: #04140d; padding: 17px 20px; width: 100%;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.12s ease, box-shadow 0.2s ease;
}
.run-btn:active { transform: scale(0.97); }
.run-btn.start {
  background: linear-gradient(135deg, #8ff0c8, #2fd38a 60%, #1fb874);
  box-shadow: 0 10px 32px rgba(47, 211, 138, 0.35);
}
.run-btn.stop {
  background: linear-gradient(135deg, #ff9d8a, #e5484d 60%, #c22525);
  box-shadow: 0 10px 32px rgba(229, 72, 77, 0.35);
  color: #fff;
}
.start-hint { font-size: 12.5px; color: var(--muted); margin-top: 10px; }

/* ---- layer chips + legend ---- */
.layer-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 10px; }
.chip {
  background: var(--card); color: var(--muted);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 9px 6px; font-size: 12.5px; cursor: pointer;
  text-align: center; white-space: nowrap; transition: all 0.15s ease;
}
.chip.on { color: var(--text); border-color: var(--accent2); background: rgba(110, 231, 183, 0.08); box-shadow: inset 0 0 0 1px rgba(110, 231, 183, 0.25); }
.chip:active { background: var(--card2); }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--muted); padding: 2px 2px 12px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.lg-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.lg-line { width: 16px; height: 3px; border-radius: 2px; display: inline-block; }

/* ---- section heads + lists ---- */
.sec-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin: 14px 0 8px; font-size: 13.5px; font-weight: 600; color: var(--text);
}
.sec-count { font-size: 12px; color: var(--muted); font-weight: 400; }
.ev-list { display: flex; flex-direction: column; gap: 8px; }
.ev-item {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; cursor: pointer; transition: border-color 0.15s ease, transform 0.1s ease;
}
.ev-item:active { transform: scale(0.99); border-color: var(--ev); }
.ev-item .ev-name { font-size: 14px; font-weight: 600; line-height: 1.3; }
.ev-item .ev-when { font-size: 12px; color: var(--accent2); margin-top: 2px; }
.ev-item .ev-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.ev-empty { font-size: 12.5px; color: var(--muted); padding: 8px 2px; }

.btn {
  background: var(--card); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 13px; font-size: 13.5px; cursor: pointer;
  text-decoration: none; display: inline-block; text-align: center;
}
.btn.small { padding: 7px 10px; font-size: 12.5px; }
.btn.ghost { background: transparent; }
.btn.full { width: 100%; margin-top: 12px; }
.btn.danger { color: var(--bad); border-color: rgba(248, 81, 73, 0.4); }
.btn.danger.armed { background: rgba(248, 81, 73, 0.14); color: #fda29b; border-color: var(--bad); }

/* ---- live view ---- */
.live-top { display: flex; gap: 10px; }
.live-mid { display: flex; gap: 10px; margin-top: 10px; }
.stat {
  flex: 1; background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px; text-align: center; min-width: 0;
}
.stat .val { display: block; font-size: 20px; font-weight: 700; color: var(--run); font-variant-numeric: tabular-nums; white-space: nowrap; }
.stat.big .val { font-size: 30px; }
.stat .lbl { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }
.split-strip { display: flex; gap: 6px; overflow-x: auto; padding: 10px 0 4px; }
.split-chip {
  flex: 0 0 auto; background: var(--card2); border: 1px solid var(--line);
  border-radius: 10px; padding: 6px 9px; text-align: center; font-size: 11.5px;
}
.split-chip .sc-mile { color: var(--muted); }
.split-chip .sc-pace { color: var(--text); font-weight: 700; font-variant-numeric: tabular-nums; }
.run-btns { display: flex; gap: 10px; margin-top: 12px; }
.run-btns .btn { flex: 0 0 auto; width: 30%; }
.run-btns .run-btn { flex: 1; font-size: 17px; padding: 14px 16px; }
.live-note { font-size: 12px; color: var(--muted); margin-top: 10px; text-align: center; }
.live-note.warn { color: var(--warn); font-weight: 600; }

/* ---- done view ---- */
.done-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.done-head h3 { margin: 0; font-size: 17px; }
.cal-row { display: flex; gap: 8px; margin-top: 12px; }
.cal-row .btn { flex: 1; }
.pick-note {
  position: absolute; left: 50%; bottom: 150px;
  transform: translateX(-50%); z-index: 30;
  display: flex; align-items: center; gap: 10px;
  background: rgba(21, 27, 35, 0.97); color: var(--text);
  border: 1px solid var(--accent); border-radius: 12px;
  padding: 8px 12px; font-size: 12.5px; white-space: nowrap;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
}
.pick-x { background: none; border: none; color: var(--muted); font-size: 14px; cursor: pointer; padding: 2px 4px; }
.splits-wrap { margin-top: 12px; }
.splits-title { font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.splits-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.splits-table th { text-align: left; color: var(--muted); font-weight: 500; font-size: 11px; padding: 4px 8px; border-bottom: 1px solid var(--line); }
.splits-table td { padding: 6px 8px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.splits-table tr:last-child td { border-bottom: none; }

/* ---- history ---- */
.hist-item {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 12px; margin-bottom: 8px; cursor: pointer;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.hist-item .hi-date { font-size: 13px; font-weight: 600; }
.hist-item .hi-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.hist-item .hi-right { text-align: right; font-size: 13px; font-weight: 700; color: var(--run); white-space: nowrap; }
.hist-item .hi-right small { display: block; font-size: 11px; color: var(--muted); font-weight: 400; }
.hist-del { color: var(--bad); border: 1px solid var(--line); background: transparent; border-radius: 8px; padding: 4px 8px; cursor: pointer; font-size: 12px; }
.export-row { display: flex; gap: 8px; margin-bottom: 12px; }
.export-row .btn { flex: 1; }

/* ---- detail sheet ---- */
.sheet {
  position: absolute; inset: 0; z-index: 30;
  background: var(--bg); border-top: 1px solid var(--line);
  display: flex; flex-direction: column; overflow-y: auto;
  border-radius: 18px 18px 0 0;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 14px 0; }
.grabber { width: 44px; height: 4px; border-radius: 2px; background: var(--line); }
.sheet-close {
  background: var(--card2); color: var(--text); border: 1px solid var(--line);
  border-radius: 999px; width: 30px; height: 30px; cursor: pointer; font-size: 13px;
}
.sheet-body-pad { padding: 10px 14px 16px; }
.sheet .ev-img { width: 100%; max-height: 180px; object-fit: cover; border-radius: 12px; border: 1px solid var(--line); margin-bottom: 10px; }
.sheet h2 { font-size: 17px; margin: 0 0 6px; line-height: 1.3; }
.sheet .cat-pill { display: inline-block; font-size: 11px; font-weight: 600; color: #0b0f14; background: var(--ev); border-radius: 999px; padding: 3px 9px; margin-bottom: 8px; }
.sheet .sh-row { font-size: 13px; color: var(--muted); margin: 4px 0; }
.sheet .sh-row b { color: var(--text); font-weight: 600; }
.sheet .sh-desc { font-size: 13.5px; color: var(--text); line-height: 1.5; margin: 10px 0; }
.sheet .sh-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.sheet .sh-actions .btn { flex: 1; min-width: 120px; }
.sheet .sh-extra { font-size: 12px; color: var(--muted); margin-top: 10px; }
.sheet .sh-subhead { font-size: 13px; font-weight: 700; margin: 14px 0 6px; color: var(--run); }
.sheet .park-meta { font-size: 12.5px; color: var(--muted); }

/* ---- you dot + run pins ---- */
.you-dot {
  width: 16px; height: 16px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #6ab0ff, #2563eb 70%);
  border: 2.5px solid #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.55);
}
.pin {
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; font-weight: 800; font-size: 11px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}
.pin-start {
  background: #6ee7b7; color: #04140d; border: 2px solid #fff;
}
.pin-end {
  background: #fff; font-size: 13px; border: 2px solid #2a3342;
}
.leaflet-tooltip.trail-tip { font-size: 11px; }
/* custom dot label (phones): a plain div we fully control — always tappable */
.dot-label {
  position: absolute; z-index: 35;
  transform: translate(-50%, calc(-100% - 10px));
  max-width: 240px;
  background: rgba(21, 27, 35, 0.97); color: #e6edf3;
  border: 1px solid #2a3342; border-radius: 10px;
  padding: 6px 11px; font-size: 12.5px; line-height: 1.35;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
  cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dot-label-hint { color: #4f9cf9; font-weight: 700; }

/* ---- phone bottom control bar (hidden on desktop; shown in the phone media query) ---- */
.ctrl-bar { display: none; }

/* ---- layer notice (why nothing is drawn) ---- */
.layer-note {
  position: absolute; left: 50%; bottom: 96px;
  transform: translateX(-50%); z-index: 30;
  max-width: 86%;
  background: rgba(21, 27, 35, 0.95); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px;
  padding: 8px 14px; font-size: 12.5px; line-height: 1.4;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
  text-align: center;
}

/* ---- floating Start/Stop bar (always visible on the map) ---- */
.run-fab-wrap {
  position: absolute; left: 50%; bottom: 12px;
  transform: translateX(-50%); z-index: 25;
  display: flex; align-items: center; gap: 8px;
  pointer-events: none; /* empty space lets map clicks through */
}
.run-fab {
  pointer-events: auto;
  border: none; cursor: pointer; border-radius: 999px;
  font-size: 15px; font-weight: 700; letter-spacing: 0.3px;
  color: #04140d; padding: 12px 24px; white-space: nowrap;
  background: linear-gradient(135deg, #8ff0c8, #2fd38a 60%, #1fb874);
  box-shadow: 0 8px 26px rgba(47, 211, 138, 0.4);
  transition: transform 0.12s ease, box-shadow 0.2s ease;
}
.run-fab:active { transform: scale(0.95); }
.run-fab.stop {
  background: linear-gradient(135deg, #ff9d8a, #e5484d 60%, #c22525);
  color: #fff; box-shadow: 0 8px 26px rgba(229, 72, 77, 0.4);
}
.fab-btn {
  pointer-events: auto;
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--card); color: var(--text); border: 1px solid var(--line);
  font-size: 16px; cursor: pointer; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
}

/* ---- map FABs ---- */
.map-fab {
  position: absolute; z-index: 20; right: 12px; bottom: 14px;
  width: 44px; height: 44px; border-radius: 50%;
  background: rgba(21, 27, 35, 0.9); color: var(--muted); border: 1px solid var(--line);
  font-size: 17px; cursor: pointer; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}
/* FOLLOW ON: solid blue + pulsing glow — impossible to miss. OFF: dim gray. */
.map-fab.on {
  background: var(--accent); color: #fff; border-color: var(--accent);
  animation: followPulse 2s ease-in-out infinite;
}
@keyframes followPulse {
  0%, 100% { box-shadow: 0 0 0 4px rgba(79, 156, 249, 0.45), 0 6px 18px rgba(0, 0, 0, 0.45); }
  50% { box-shadow: 0 0 0 9px rgba(79, 156, 249, 0.12), 0 6px 18px rgba(0, 0, 0, 0.45); }
}
.full-fab { right: 12px; top: 12px; bottom: auto; font-size: 19px; }

/* ---- fullscreen map (desktop: hides the side panel for a full-bleed map; phone: N/A — the map already fills the screen, so the button is hidden there) ---- */
.app.fullscreen .panel { display: none !important; }
.app.fullscreen ~ footer { display: none; }
.app.fullscreen { bottom: 0; }
.app.live #fullBtn { display: none; } /* keep run stats + Stop visible during a run */
@media (min-width: 900px) { .full-fab { right: 16px; top: 16px; } }

/* ---- blackout mode: pure-black run screen (OLED pixels off ≈ near-zero display power) ---- */
.blackout {
  position: fixed; inset: 0; z-index: 200;
  background: #000;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 14px 0;
}
.blk-btn {
  background: rgba(255, 255, 255, 0.07); color: #e6edf3;
  border: 1px solid rgba(255, 255, 255, 0.2); border-radius: 999px;
  padding: 8px 14px; font-size: 13px; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.blk-btn:active { background: rgba(255, 255, 255, 0.16); }
.blk-btn.stop { color: #ff8a80; border-color: rgba(255, 138, 128, 0.45); }
/* 🌙 re-enter blackout from the map (only while a run is live) */
#blackBtn { display: none; }
.app.live #blackBtn { display: flex; }
.black-fab { right: 12px; bottom: auto; top: 62px; }

/* ---- coverage note + footer ---- */
.coverage-note { font-size: 11.5px; color: var(--muted); margin-top: 14px; line-height: 1.45; }
footer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  height: 34px; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 0 14px calc(env(safe-area-inset-bottom, 0)) 14px;
  background: rgba(11, 15, 20, 0.92); border-top: 1px solid var(--line);
  font-size: 11px; color: var(--muted);
}
footer a { color: var(--muted); }
.foot-right { display: flex; gap: 10px; align-items: center; white-space: nowrap; }

/* ================= DESKTOP (≥900px) ================= */
@media (min-width: 900px) {
  .app { top: calc(var(--header-h) + 0px); }
  .panel {
    flex: 0 0 400px; max-width: 420px;
    border-right: 1px solid var(--line);
  }
  #map { border-radius: 0; }
  .map-fab { right: 16px; bottom: 16px; }
  .black-fab { top: 16px; bottom: auto; }
  .sheet { border-radius: 0; }
}

/* ================= PHONE (<900px): map fills; controls are a FIXED bottom bar,
 * panel is a slide-up overlay sheet (nothing can push the controls off-screen) ================= */
@media (max-width: 899px) {
  .ctrl-bar {
    position: fixed; left: 10px; right: 10px;
    bottom: calc(40px + env(safe-area-inset-bottom, 0px));
    z-index: 60;
    display: flex; align-items: flex-end; gap: 8px;
    /* distinct floating pill so the buttons stay visible on the map AND
     * in front of the dark menu panel */
    background: rgba(11, 15, 20, 0.92);
    border: 1px solid var(--line);
    border-radius: 20px;
    padding: 8px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
  }
  .ctrl-btn {
    flex: 0 0 52px; height: 52px; border-radius: 16px;
    background: var(--card); color: var(--text); border: 1px solid var(--line);
    font-size: 19px; cursor: pointer; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
    display: flex; align-items: center; justify-content: center;
  }
  .ctrl-main-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
  .ctrl-stats {
    display: none;
    justify-content: center; gap: 16px;
    background: rgba(21, 27, 35, 0.92); border: 1px solid var(--line);
    border-radius: 12px; padding: 5px 10px;
    font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums;
  }
  .app.live .ctrl-stats { display: flex; }
  .ctrl-stats b { color: var(--run); font-weight: 700; font-size: 13.5px; }
  /* wake-lock status line (visible during a run; hidden otherwise) */
  .ctrl-wake { display: none; }
  .app.live .ctrl-wake {
    display: block;
    text-align: center; font-size: 11px; line-height: 1.35;
    color: var(--good); padding: 1px 6px;
  }
  .ctrl-wake.warn { color: var(--warn); font-weight: 600; }
  .ctrl-main {
    width: 100%; border: none; cursor: pointer; border-radius: 999px;
    font-size: 17px; font-weight: 700; letter-spacing: 0.3px;
    color: #04140d; padding: 15px 18px; white-space: nowrap;
    background: linear-gradient(135deg, #8ff0c8, #2fd38a 60%, #1fb874);
    box-shadow: 0 8px 26px rgba(47, 211, 138, 0.4);
    transition: transform 0.12s ease;
  }
  .ctrl-main:active { transform: scale(0.97); }
  .ctrl-main.stop { background: linear-gradient(135deg, #ff9d8a, #e5484d 60%, #c22525); color: #fff; box-shadow: 0 8px 26px rgba(229, 72, 77, 0.4); }

  /* panel = overlay sheet ABOVE the control bar (the ☰ button stays
   * visible below it at all times), closed by default via .hidden */
  .panel {
    position: fixed; left: 0; right: 0;
    bottom: calc(118px + env(safe-area-inset-bottom, 0px));
    max-height: 62dvh;
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.55);
    z-index: 55;
  }
  /* grabber on the open sheet */
  .panel::before {
    content: ""; display: block; width: 44px; height: 4px;
    border-radius: 2px; background: var(--line);
    margin: 8px auto 2px;
  }
  /* detail sheet overlays the whole screen above the bar */
  #detailSheet {
    position: fixed; left: 0; right: 0; top: 0; bottom: calc(40px + env(safe-area-inset-bottom, 0px));
    z-index: 70; border-radius: 0; max-height: none;
  }
  /* keep the ✕ clear of the status bar / notch */
  #detailSheet .sheet-head { padding-top: calc(10px + env(safe-area-inset-top, 0px)); }
  #detailSheet .sheet-close { width: 40px; height: 40px; font-size: 16px; }
  /* the floating Start bar is desktop-only now; phone uses the ctrl bar */
  .run-fab-wrap { display: none; }
  .map-fab { right: 10px; }
  .black-fab { right: 10px; top: 62px; bottom: auto; }
  .full-fab { display: none; } /* no expand button on phones: the map already fills the screen */
  .follow-fab { top: 10px; bottom: auto; } /* move follow up where the expand button was */
  .where { margin-bottom: 10px; }
  .ev-item .ev-when { font-size: 11.5px; }
}
