/* StaticMaps v0.2 — mobile-first stylesheet */

:root {
  --bg: #0c0f14;
  --bg-elev: #141821;
  --bg-elev-2: #1c2230;
  --line: #2a3140;
  --text: #e8ecf2;
  --text-dim: #8b94a5;
  --accent: #ff6a3d;
  --accent-2: #ffd166;
  --good: #4ade80;
  --bad: #ef4444;
  --route-fast: #3b82f6;
  --route-safe: #ff6a3d;
  --route-best: #22c55e;
  --route-other: #6b7280;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
  --radius: 14px;
  --radius-sm: 10px;
  --tap: 44px; /* min tap target */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overscroll-behavior: none;
}
button { font-family: inherit; }

#app { position: fixed; inset: 0; }

/* --- Map ----------------------------------------------------------------- */

#map { position: absolute; inset: 0; background: #0a0c11; z-index: 0; }
.leaflet-container { background: #0a0c11; }
.leaflet-tile-pane { filter: brightness(0.85) contrast(1.05); }
.leaflet-control-attribution {
  background: rgba(12, 15, 20, 0.8) !important;
  color: var(--text-dim) !important;
  font-size: 10px !important;
}
.leaflet-control-attribution a { color: var(--text-dim) !important; }

/* Hazard markers */
.hz-marker {
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

/* Endpoint marker (from/to) */
.endpoint-marker {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 3px solid white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
}

/* User location marker */
.me-marker { position: relative; width: 22px; height: 22px; }
.me-dot {
  position: absolute; inset: 5px;
  background: var(--route-fast);
  border-radius: 50%;
  border: 2px solid white;
  box-shadow: 0 0 0 2px var(--route-fast), 0 2px 6px rgba(0,0,0,0.5);
}
.me-pulse {
  position: absolute; inset: -2px;
  background: rgba(59, 130, 246, 0.35);
  border-radius: 50%;
  animation: mePulse 1.6s ease-out infinite;
}
@keyframes mePulse {
  0% { transform: scale(0.6); opacity: 0.8; }
  100% { transform: scale(1.6); opacity: 0; }
}

/* Leaflet popups */
.leaflet-popup-content-wrapper {
  background: var(--bg-elev-2);
  color: var(--text);
  border-radius: 10px;
  box-shadow: var(--shadow);
}
.leaflet-popup-tip { background: var(--bg-elev-2); }
.leaflet-popup-content { margin: 12px 14px; font-size: 13px; line-height: 1.4; }
.hz-pop-title { font-size: 13px; font-weight: 700; }
.hz-pop-row { font-size: 12px; margin-top: 2px; }
.hz-pop-note { font-size: 12px; color: var(--text-dim); margin-top: 4px; }
.hz-pop-source { font-size: 10px; color: var(--text-dim); margin-top: 6px; }
.hz-pop-actions { margin-top: 8px; }
.hz-pop-actions button {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 11px;
  cursor: pointer;
}

/* --- Top bar (logo + locate) -------------------------------------------- */

#topbar {
  position: absolute;
  top: env(safe-area-inset-top, 0);
  left: 0; right: 0;
  z-index: 1000;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 12px 12px 0;
  pointer-events: none;
}
.brand {
  background: rgba(12, 15, 20, 0.85);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px 6px 6px;
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
  box-shadow: var(--shadow);
}
.brand-mark {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent) 0%, #ffb199 100%);
  display: grid; place-items: center;
  flex-shrink: 0;
}
.brand-mark svg { width: 18px; height: 18px; }
.brand-text { line-height: 1.05; }
.brand-text h1 {
  margin: 0; font-size: 15px; font-weight: 700; letter-spacing: -0.01em;
}
.brand-text small {
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.icon-btn {
  width: var(--tap); height: var(--tap);
  border-radius: 50%;
  background: rgba(12, 15, 20, 0.85);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: var(--text);
  border: 1px solid var(--line);
  display: grid; place-items: center;
  cursor: pointer;
  pointer-events: auto;
  box-shadow: var(--shadow);
  transition: transform 0.05s, color 0.15s, border-color 0.15s;
}
.icon-btn:active { transform: scale(0.96); }
.icon-btn.active {
  color: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(255, 106, 61, 0.25), var(--shadow);
}

/* --- Bottom sheet (mobile-first) ---------------------------------------- */

#sheet {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  background: var(--bg);
  border-top: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  z-index: 1100;
  box-shadow: 0 -12px 32px rgba(0, 0, 0, 0.45);
  display: flex; flex-direction: column;
  transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
  max-height: 85vh;
  /* Default collapsed: only the handle + first ~140px peek out */
  transform: translateY(calc(100% - 200px));
  padding-bottom: env(safe-area-inset-bottom, 0);
}
#sheet[data-state="expanded"] {
  transform: translateY(0);
}

.sheet-handle {
  appearance: none;
  background: transparent;
  border: 0;
  width: 100%;
  padding: 10px 0 4px;
  display: grid;
  place-items: center;
  cursor: pointer;
  touch-action: none;
}
.sheet-grip {
  width: 44px; height: 4px;
  border-radius: 999px;
  background: var(--line);
}

.sheet-content {
  overflow-y: auto;
  padding: 0 16px 12px;
}
.sheet-content::-webkit-scrollbar { width: 6px; }
.sheet-content::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }

/* --- Panel --------------------------------------------------------------- */

.panel {
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.panel:last-of-type { border-bottom: 0; }
.panel h2 {
  font-size: 11px; font-weight: 700; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--text-dim);
  margin: 0 0 10px;
}

.field {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 8px;
  min-height: var(--tap);
  transition: border-color 0.15s;
}
.field:focus-within { border-color: var(--accent); }
.field .dot {
  width: 10px; height: 10px; border-radius: 50%;
  flex-shrink: 0;
}
.dot-from { background: var(--good); }
.dot-to   { background: var(--accent); }
.field input {
  flex: 1; background: transparent; border: 0; outline: 0;
  color: var(--text); font-size: 16px; /* >=16px prevents iOS zoom on focus */
  min-width: 0;
}
.field input::placeholder { color: var(--text-dim); }

.inline-btn {
  background: transparent; border: 0; color: var(--text-dim);
  cursor: pointer; padding: 6px;
  display: grid; place-items: center;
  border-radius: 6px;
}
.inline-btn:hover { color: var(--accent); background: var(--bg-elev-2); }

.row { display: flex; gap: 8px; }
.btn {
  background: var(--accent); color: #1a0a04;
  border: 0; border-radius: var(--radius-sm);
  padding: 12px 14px; font-size: 14px; font-weight: 600;
  cursor: pointer;
  transition: filter 0.15s, transform 0.05s;
  flex: 1;
  min-height: var(--tap);
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn.secondary {
  background: var(--bg-elev-2); color: var(--text);
  border: 1px solid var(--line); flex: 0 0 auto; min-width: var(--tap);
}
.btn.ghost {
  background: transparent; color: var(--text-dim);
  border: 1px solid var(--line); flex: 0 0 auto; min-width: var(--tap);
}

.ride-height-wrap { margin-top: 12px; }
.ride-label { font-size: 11px; color: var(--text-dim); margin-bottom: 6px; }
.ride-height {
  display: flex; background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 3px; gap: 2px;
}
.ride-height button {
  flex: 1; background: transparent; border: 0; color: var(--text-dim);
  padding: 9px 8px; font-size: 12px; border-radius: 7px;
  cursor: pointer; font-weight: 500; min-height: 36px;
}
.ride-height button.active {
  background: var(--accent); color: #1a0a04; font-weight: 600;
}

/* Route cards */
.route-card {
  appearance: none;
  width: 100%; text-align: left;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 8px;
  cursor: pointer;
  color: var(--text);
  transition: border-color 0.15s, transform 0.05s;
}
.route-card:hover { border-color: var(--accent); }
.route-card:active { transform: translateY(1px); }
.route-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent) inset;
}
.route-card .label {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 14px; font-weight: 600; margin-bottom: 6px;
}
.route-card .badge {
  font-size: 10px; font-weight: 700; padding: 3px 7px; border-radius: 999px;
  letter-spacing: 0.05em;
}
.badge.safe { background: rgba(255, 106, 61, 0.15); color: var(--accent); }
.badge.fast { background: rgba(59, 130, 246, 0.15); color: var(--route-fast); }
.badge.alt  { background: rgba(107, 114, 128, 0.18); color: #b8bfcc; }
.route-card .meta {
  display: flex; gap: 14px; color: var(--text-dim); font-size: 12px;
}
.route-card .meta strong { color: var(--text); font-weight: 600; }
.route-card .hazards { margin-top: 6px; font-size: 11px; color: var(--text-dim); }

/* Hazard buttons */
.hazard-types {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
}
.hz-btn {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-elev); border: 1px solid var(--line);
  color: var(--text); padding: 10px;
  border-radius: var(--radius-sm); cursor: pointer;
  font-size: 12px; min-height: 40px;
  transition: border-color 0.15s;
}
.hz-btn:hover { border-color: var(--accent); }
.hz-btn.active { border-color: var(--accent); background: var(--bg-elev-2); }
.hz-btn .swatch {
  width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0;
}

.severity { display: flex; gap: 4px; margin-top: 4px; }
.severity button {
  flex: 1; background: var(--bg-elev); border: 1px solid var(--line);
  color: var(--text-dim); padding: 8px; font-size: 12px;
  cursor: pointer; border-radius: 6px; font-weight: 600;
  min-height: 36px;
}
.severity button.active {
  background: var(--accent); color: #1a0a04; border-color: var(--accent);
}

/* Layer toggles */
.toggle {
  display: flex; align-items: center; gap: 10px;
  font-size: 14px; cursor: pointer;
  padding: 8px 0;
  min-height: 36px;
}
.toggle input { accent-color: var(--accent); width: 18px; height: 18px; }

.dim { color: var(--text-dim); }
.small { font-size: 11px; margin-top: 4px; }
.link {
  background: none; border: 0; color: var(--accent);
  cursor: pointer; padding: 0; font-size: 11px;
}

.footer {
  display: flex; justify-content: space-between;
  color: var(--text-dim); font-size: 10px;
  padding: 12px 0 4px;
}

/* --- Banners ------------------------------------------------------------- */

#report-banner {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0) + 64px);
  left: 50%; transform: translateX(-50%);
  background: var(--accent); color: #1a0a04;
  font-weight: 600; font-size: 13px;
  padding: 10px 16px; border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 1200;
  display: none; align-items: center; gap: 10px;
}
#report-banner.show { display: flex; }
#report-banner button {
  background: rgba(0, 0, 0, 0.2); border: 0; color: #1a0a04;
  border-radius: 999px; padding: 4px 10px; font-size: 11px;
  cursor: pointer; font-weight: 700;
}

#offline-banner {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0) + 64px);
  left: 50%; transform: translateX(-50%);
  background: var(--bad); color: white;
  font-weight: 600; font-size: 12px;
  padding: 8px 14px; border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 1200;
  display: none;
}
#offline-banner.show { display: block; }

/* --- Toast --------------------------------------------------------------- */

#toast {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom, 0) + 220px);
  left: 50%; transform: translateX(-50%);
  background: var(--bg-elev-2); color: var(--text);
  border: 1px solid var(--line);
  padding: 10px 16px; border-radius: 999px; font-size: 13px;
  box-shadow: var(--shadow);
  z-index: 1300;
  opacity: 0; transition: opacity 0.25s;
  pointer-events: none;
  max-width: 90vw;
  text-align: center;
}
#toast.show { opacity: 1; }

/* --- Desktop layout ----------------------------------------------------- */

@media (min-width: 900px) {
  #sheet {
    top: 0; bottom: 0; left: 0; right: auto;
    width: 380px;
    max-height: none;
    border-radius: 0;
    border-top: 0;
    border-right: 1px solid var(--line);
    transform: none;
    box-shadow: 6px 0 24px rgba(0, 0, 0, 0.4);
  }
  .sheet-handle { display: none; }
  #sheet .sheet-content { padding: 16px 18px 24px; }
  #map { left: 380px; }
  #topbar {
    left: 380px;
    padding-left: 18px;
  }
  #topbar .brand { display: none; }
  #report-banner, #offline-banner {
    left: calc(50% + 190px);
  }
  #toast {
    bottom: 24px;
    left: calc(50% + 190px);
  }
}
