/*
================================================================================
FILE: frontend/css/style.css
ROLE: All visual styles for the STL Rides map application.
================================================================================

WHAT THIS FILE DOES
───────────────────
Provides all CSS for the single-page map application. Intentionally kept in
one file — the app is simple enough that splitting into multiple CSS files
would add complexity without benefit.

LAYOUT STRUCTURE
────────────────
  body
  └── #app  (full-height flex column)
      ├── #toolbar  (fixed-height top bar, flex row, wraps on small screens)
      │   ├── #title
      │   ├── .mode-btns  (Day/Week/Month/Custom toggle)
      │   ├── #nav        (Prev/Label/Next)
      │   ├── #custom-range  (date pickers, hidden unless Custom mode)
      │   └── #stats      (Trips/Routes/Avg mi/Avg min)
      └── #map  (fills remaining viewport height, Leaflet renders here)

  Fixed-position overlays:
  ├── #legend     (bottom-left)
  └── #no-data    (centered, shown when period has no trips)

COLOR TOKENS
────────────
  Background dark  #0f0f1a
  Panel            #1a1a2e  → #16213e  (gradient)
  Accent indigo    #4f46e5  (active buttons)
  Text primary     #e0e0ff
  Text muted       #64748b
  Text accent      #a5b4fc

DESIGN DECISIONS
────────────────
- Dark toolbar + light CARTO basemap: dark UI reduces eye strain, light map
  makes colored route lines readable against the background.
- Min-width on #period-label prevents toolbar reflowing when label changes.
- pointer-events: none on #legend so it doesn't block map clicks underneath.

TO CHANGE THE COLOR SCHEME
───────────────────────────
Update the accent color (#4f46e5) in:
  .mode-btn.active { background: #4f46e5 }
  .stat-val        { color: #a5b4fc }   ← lighten/darken relative to accent

TO ADD RESPONSIVE BREAKPOINTS
──────────────────────────────
Add @media queries at the bottom of this file. The toolbar already uses
flex-wrap: wrap, so it degrades gracefully on small screens.

FUTURE WORK
───────────
- Add CSS custom properties (--accent, --bg-panel) for easier theming.
- Add a light mode toggle (prefers-color-scheme media query).
- Add mobile-specific layout: move toolbar to bottom, collapse stats.
================================================================================
*/

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #0f0f1a;
}

/* ── Layout ──────────────────────────────────────────────────────────────── */

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

#map { flex: 1; }

/* ── Toolbar ─────────────────────────────────────────────────────────────── */

#toolbar {
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  color: #e0e0ff;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
  z-index: 500;
}

#title {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: #a5b4fc;
  white-space: nowrap;
}

#title span { color: #e0e0ff; }

/* ── Mode buttons ────────────────────────────────────────────────────────── */

.mode-btns {
  display: flex;
  gap: 3px;
  background: rgba(255, 255, 255, 0.07);
  border-radius: 24px;
  padding: 3px;
}

.mode-btn {
  padding: 5px 16px;
  border: none;
  border-radius: 20px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  background: transparent;
  color: #94a3b8;
  transition: all 0.2s;
  letter-spacing: 0.3px;
}

.mode-btn.active {
  background: #4f46e5;
  color: #fff;
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.5);
}

.mode-btn:hover:not(.active) { color: #e0e0ff; }

/* ── Period navigation ───────────────────────────────────────────────────── */

#nav { display: flex; align-items: center; gap: 8px; }

.nav-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #e0e0ff;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.nav-btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.2); }
.nav-btn:disabled { opacity: 0.25; cursor: default; }

#period-label {
  font-size: 14px;
  font-weight: 700;
  min-width: 200px;
  text-align: center;
  color: #e0e0ff;
}

/* ── Custom date pickers ─────────────────────────────────────────────────── */

#custom-range {
  display: none;
  align-items: center;
  gap: 8px;
}

#custom-range input[type="date"] {
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
  color: #e0e0ff;
  font-size: 12px;
  cursor: pointer;
}

#custom-range .separator { color: #64748b; font-size: 12px; }

/* ── Toolbar sub-groups ──────────────────────────────────────────────────── */
/*
  On desktop both groups sit inside the single #toolbar flex row.
  On mobile #toolbar becomes display:contents so the groups become
  direct children of #app and can be ordered independently.
*/

#toolbar-primary,
#toolbar-secondary {
  display: flex;
  align-items: center;
  gap: 18px;
}

/* Push the secondary group (nav + stats) to the right on desktop */
#toolbar-secondary { margin-left: auto; }

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

#stats {
  display: flex;
  gap: 24px;
  align-items: center;
  /* margin-left: auto handled by #toolbar-secondary on desktop */
}

.stat { display: flex; flex-direction: column; align-items: center; }

.stat-val {
  font-size: 18px;
  font-weight: 800;
  color: #a5b4fc;
  line-height: 1;
}

.stat-lbl {
  font-size: 10px;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 2px;
}

/* ── Legend (fixed, bottom-left) ─────────────────────────────────────────── */

#legend {
  position: fixed;
  bottom: 36px;
  left: 16px;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(4px);
  padding: 12px 16px;
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
  font-size: 12px;
  z-index: 1000;
  line-height: 1.8;
  pointer-events: none;   /* don't block map clicks underneath */
}

#legend b { font-size: 12px; display: block; margin-bottom: 2px; color: #1e293b; }

.dot {
  display: inline-block;
  width: 28px;
  height: 4px;
  border-radius: 2px;
  vertical-align: middle;
  margin-right: 4px;
}

.legend-note { margin-top: 6px; color: #64748b; font-size: 11px; }

/* ── No-data overlay (centered, shown when period is empty) ──────────────── */

#no-data {
  display: none;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(255, 255, 255, 0.92);
  padding: 20px 32px;
  border-radius: 12px;
  font-size: 15px;
  color: #475569;
  z-index: 800;
  text-align: center;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
}

/* ── Welcome Modal ───────────────────────────────────────────────────────── */

.welcome-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(5px);
  z-index: 9000;
}

.welcome-modal {
  display: none;
  flex-direction: column;
  align-items: center;
  text-align: center;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: linear-gradient(145deg, #1a1a2e 0%, #16213e 100%);
  border: 1px solid rgba(165, 180, 252, 0.22);
  border-radius: 22px;
  padding: 40px 48px 36px;
  max-width: 480px;
  width: calc(100vw - 32px);
  z-index: 9001;
  box-shadow: 0 32px 80px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(79, 70, 229, 0.18);
  animation: welcome-in 0.38s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes welcome-in {
  from { opacity: 0; transform: translate(-50%, -54%) scale(0.93); }
  to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

.welcome-icon {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  margin-bottom: 18px;
  box-shadow: 0 8px 24px rgba(79, 70, 229, 0.45);
}

.welcome-title {
  font-size: 26px;
  font-weight: 800;
  color: #a5b4fc;
  letter-spacing: 0.4px;
  margin-bottom: 4px;
  line-height: 1.2;
}

.welcome-title span { color: #e0e0ff; }

.welcome-byline {
  font-size: 11px;
  color: #6366f1;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  margin-bottom: 16px;
}

.welcome-bio {
  font-size: 14px;
  color: #94a3b8;
  line-height: 1.65;
  font-style: italic;
  margin-bottom: 14px;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 10px;
  border-left: 3px solid rgba(79, 70, 229, 0.5);
}

.welcome-desc {
  font-size: 13.5px;
  color: #cbd5e1;
  line-height: 1.7;
  margin-bottom: 28px;
}

.welcome-actions {
  display: flex;
  gap: 10px;
  width: 100%;
}

.welcome-btn-primary {
  flex: 1;
  padding: 12px 18px;
  background: #4f46e5;
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
  box-shadow: 0 4px 16px rgba(79, 70, 229, 0.42);
  letter-spacing: 0.2px;
}

.welcome-btn-primary:hover { background: #6366f1; transform: translateY(-1px); }

.welcome-btn-secondary {
  padding: 12px 18px;
  background: transparent;
  color: #64748b;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.welcome-btn-secondary:hover { color: #94a3b8; border-color: rgba(255, 255, 255, 0.22); }

/* × close button — top-right corner of the welcome modal */
.welcome-close {
  position: absolute;
  top: 14px;
  right: 16px;
  background: none;
  border: none;
  color: #475569;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}

.welcome-close:hover {
  color: #94a3b8;
  background: rgba(255, 255, 255, 0.07);
}

/* ── Interactive Tour ─────────────────────────────────────────────────────── */

.tour-highlight {
  display: none;
  position: fixed;
  border-radius: 10px;
  /* outer ring + full-screen overlay via giant spread */
  box-shadow: 0 0 0 5px rgba(99, 102, 241, 0.9),
              0 0 0 9999px rgba(10, 10, 26, 0.74);
  z-index: 9001;
  pointer-events: none;
  transition: top 0.28s cubic-bezier(0.4, 0, 0.2, 1),
              left 0.28s cubic-bezier(0.4, 0, 0.2, 1),
              width 0.28s cubic-bezier(0.4, 0, 0.2, 1),
              height 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  animation: tour-pulse 2.2s ease-in-out infinite;
}

@keyframes tour-pulse {
  0%, 100% { box-shadow: 0 0 0 5px rgba(99, 102, 241, 0.9),  0 0 0 9999px rgba(10, 10, 26, 0.74); }
  50%       { box-shadow: 0 0 0 8px rgba(129, 140, 248, 0.55), 0 0 0 9999px rgba(10, 10, 26, 0.74); }
}

.tour-popover {
  display: none;
  flex-direction: column;
  position: fixed;
  background: linear-gradient(145deg, #1e1e35 0%, #1a2744 100%);
  border: 1px solid rgba(165, 180, 252, 0.22);
  border-radius: 16px;
  padding: 20px 22px 16px;
  width: 300px;
  max-width: calc(100vw - 32px);
  z-index: 9002;
  box-shadow: 0 20px 56px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(79, 70, 229, 0.1);
  animation: popover-in 0.22s ease-out both;
}

@keyframes popover-in {
  from { opacity: 0; transform: scale(0.95) translateY(6px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.tour-step-badge {
  font-size: 10px;
  font-weight: 700;
  color: #6366f1;
  text-transform: uppercase;
  letter-spacing: 1.1px;
  margin-bottom: 7px;
}

.tour-step-dots {
  display: flex;
  gap: 5px;
  margin-bottom: 12px;
}

.tour-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  transition: background 0.2s;
}

.tour-dot.active { background: #4f46e5; }
.tour-dot.done   { background: #6366f1; opacity: 0.6; }

.tour-title {
  font-size: 15px;
  font-weight: 800;
  color: #e0e0ff;
  margin-bottom: 9px;
  line-height: 1.3;
}

.tour-body {
  font-size: 13px;
  color: #94a3b8;
  line-height: 1.7;
  margin-bottom: 18px;
}

.tour-body strong { color: #c7d2fe; font-weight: 600; }

.tour-body kbd {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 11px;
  font-family: 'SF Mono', Consolas, monospace;
  color: #e0e0ff;
}

.tour-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.tour-btn-exit {
  background: none;
  border: none;
  color: #475569;
  font-size: 12px;
  cursor: pointer;
  padding: 4px 0;
  transition: color 0.15s;
}

.tour-btn-exit:hover { color: #64748b; }

.tour-nav { display: flex; gap: 6px; }

.tour-btn-prev,
.tour-btn-next {
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 0.2px;
}

.tour-btn-prev {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #94a3b8;
}

.tour-btn-prev:hover:not(:disabled) { background: rgba(255, 255, 255, 0.13); color: #e0e0ff; }
.tour-btn-prev:disabled { opacity: 0.25; cursor: default; }

.tour-btn-next {
  background: #4f46e5;
  border: 1px solid transparent;
  color: #fff;
  box-shadow: 0 2px 10px rgba(79, 70, 229, 0.42);
}

.tour-btn-next:hover { background: #6366f1; }

/* ── Guide help button (bottom-right) ────────────────────────────────────── */

#guide-btn {
  position: fixed;
  bottom: 16px;
  right: 16px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  border: 1px solid rgba(165, 180, 252, 0.28);
  color: #a5b4fc;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
  transition: all 0.2s;
  line-height: 1;
}

#guide-btn:hover {
  background: #4f46e5;
  border-color: #4f46e5;
  color: #fff;
  transform: scale(1.1);
  box-shadow: 0 6px 22px rgba(79, 70, 229, 0.45);
}

/* ══════════════════════════════════════════════════════════════════════════
   RESPONSIVE — MOBILE  (≤ 640 px)
   Layout: title + mode-buttons strip at the TOP, map in the middle,
   nav + stats strip at the BOTTOM — the standard pattern for map apps.

   Technique: #toolbar becomes display:contents (vanishes from layout),
   so #toolbar-primary and #toolbar-secondary become direct children of
   #app's flex column and can be ordered independently around #map.
   ══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 640px) {

  /* Use dynamic viewport height so the bars don't hide behind browser chrome */
  #app {
    height: 100dvh;
    height: 100vh; /* fallback for browsers without dvh */
  }

  /* Make #toolbar a transparent wrapper — its children slot into #app directly */
  #toolbar { display: contents; }

  /* ── TOP BAR: title + mode toggle ── */

  #toolbar-primary {
    order: 1;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    padding: 10px 14px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
    z-index: 500;
    gap: 10px;
    flex-wrap: nowrap;
    /* reset desktop margin */
    margin-left: 0;
  }

  #title { font-size: 14px; flex-shrink: 0; }

  /* push mode buttons to the right */
  #toolbar-primary .mode-btns { margin-left: auto; }
  .mode-btn { padding: 5px 11px; font-size: 11px; }

  /* ── MAP: fills all remaining space between the two bars ── */

  #map { order: 2; }

  /* ── BOTTOM BAR: nav + stats ── */

  #toolbar-secondary {
    order: 3;
    flex-direction: column;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    padding: 10px 14px;
    padding-bottom: max(12px, env(safe-area-inset-bottom, 12px));
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.4);
    z-index: 500;
    gap: 8px;
    /* reset desktop margin */
    margin-left: 0;
  }

  /* Nav row: centered */
  #nav {
    width: 100%;
    justify-content: center;
  }

  #period-label {
    flex: 1;
    min-width: 0;
    max-width: 200px;
    font-size: 13px;
    text-align: center;
  }

  /* Custom date range: centered in its own row */
  #custom-range {
    width: 100%;
    justify-content: center;
  }

  /* Stats row: evenly spaced across full width */
  #stats {
    width: 100%;
    justify-content: space-around;
    gap: 0;
    padding-top: 6px;
    border-top: 1px solid rgba(255, 255, 255, 0.07);
  }

  .stat-val { font-size: 16px; }
  .stat-lbl { font-size: 9px; }

  /* ── Legend: move to bottom-left, sits above the bottom bar ──
     JS sets guide-btn just above the bottom bar dynamically.       */

  #legend {
    bottom: auto;
    top: 58px; /* just below the top bar */
    left: 10px;
    right: auto;
    font-size: 11px;
    padding: 8px 10px;
    line-height: 1.55;
  }

  #legend b    { font-size: 11px; }
  .dot         { width: 20px; }
  .legend-note { font-size: 10px; margin-top: 4px; }

  /* Leaflet attribution overlaps the bottom bar — hide it on mobile */
  .leaflet-control-attribution { display: none; }

  /* No-data banner */
  #no-data {
    font-size: 13px;
    padding: 14px 20px;
    width: calc(100% - 32px);
  }

  /* Tour popover: stretch to use the available width */
  .tour-popover {
    width: calc(100vw - 24px);
  }

  /* Welcome modal: tighter padding on small screens */
  .welcome-modal {
    padding: 28px 20px 22px;
    border-radius: 18px;
  }

  .welcome-icon  { width: 52px; height: 52px; font-size: 24px; margin-bottom: 12px; }
  .welcome-title { font-size: 21px; }
  .welcome-bio   { font-size: 13px; padding: 10px 12px; }
  .welcome-desc  { font-size: 13px; margin-bottom: 22px; }

  /* Stack buttons vertically — CTA on top */
  .welcome-actions       { flex-direction: column-reverse; gap: 8px; }
  .welcome-btn-primary   { padding: 13px 18px; font-size: 14px; }
  .welcome-btn-secondary { padding: 10px 18px; font-size: 13px; text-align: center; }
}

/* ══════════════════════════════════════════════════════════════════════════
   RESPONSIVE — SMALL PHONES  (≤ 380 px)
   ══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 380px) {
  .mode-btn     { padding: 5px 8px; font-size: 10px; }
  #title        { font-size: 13px; }
  #period-label { font-size: 12px; }
  .stat-val     { font-size: 15px; }
  .stat-lbl     { font-size: 8px; letter-spacing: 0; }

  #legend { padding: 6px 8px; font-size: 10px; }
  .dot    { width: 16px; }
}
