/* ═══════════════════════════════════════════════════════
   Race Tracker — Estilos globales (mobile-first)
   Paleta: #1a2332 (dark blue) · #ff6b35 (orange) · #f0f2f5 (bg)
   ═══════════════════════════════════════════════════════ */

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

:root {
  --primary:   #1a2332;
  --accent:    #ff6b35;
  --accent-dk: #e05525;
  --bg:        #f0f2f5;
  --card:      #ffffff;
  --text:      #1a2332;
  --muted:     #6b7280;
  --border:    #e5e7eb;
  --success:   #22c55e;
  --danger:    #ef4444;
  --warning:   #f59e0b;
  --radius:    12px;
  --shadow:    0 2px 10px rgba(0,0,0,.08);
  --font:      system-ui, -apple-system, 'Segoe UI', sans-serif;
}

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.5;
}

/* ── Tipografía ── */
h1 { font-size: 1.5rem;  font-weight: 700; }
h2 { font-size: 1.2rem;  font-weight: 700; }
h3 { font-size: 1rem;    font-weight: 600; }
p  { font-size: .9rem; }

/* ── Header ── */
.header {
  background: var(--primary);
  color: white;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}
.header__logo { font-size: 1.1rem; font-weight: 700; display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.header__logo span { color: var(--accent); }
.header__nav  { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }
.header__nav a { color: rgba(255,255,255,.75); font-size: .85rem; text-decoration: none; white-space: nowrap; }
.header__nav a:hover { color: white; }

/* ── Layout ── */
.container    { max-width: 900px; margin: 0 auto; padding: 20px 16px; }
.container-sm { max-width: 480px; margin: 0 auto; padding: 20px 16px; }

/* ── Cards ── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
.card__title  { font-size: 1rem; font-weight: 700; margin-bottom: 14px; }

/* ── Botones ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 20px;
  border-radius: 10px;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  border: none;
  transition: filter .15s, transform .1s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary   { background: var(--accent);  color: white; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-dark      { background: var(--primary); color: white; }
.btn-dark:hover { filter: brightness(1.2); }
.btn-outline   { background: transparent; color: var(--primary); border: 2px solid var(--border); }
.btn-danger    { background: var(--danger);  color: white; }
.btn-success   { background: var(--success); color: white; }
.btn-full      { width: 100%; }
.btn-lg        { padding: 14px 24px; font-size: 1rem; }

/* ── Formularios ── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 6px; color: var(--muted); }
.form-control {
  width: 100%;
  padding: 11px 14px;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-size: .95rem;
  font-family: var(--font);
  color: var(--text);
  background: white;
  transition: border-color .15s;
  outline: none;
}
.form-control:focus { border-color: var(--accent); }
.form-error { font-size: .8rem; color: var(--danger); margin-top: 5px; }

/* ── Badges ── */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.badge-vivo      { background: #fee2e2; color: var(--danger); }
.badge-vivo::before { content: '●'; margin-right: 4px; animation: pulso 1s infinite; }
.badge-proximo   { background: #e0e7ff; color: #3730a3; }
.badge-finalizado { background: #dcfce7; color: #15803d; }
.badge-corriendo { background: #fef3c7; color: #b45309; }
.badge-abandono  { background: #f3f4f6; color: var(--muted); }

@keyframes pulso { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

/* ── Lista de eventos ── */
.evento-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.evento-item:last-child { border-bottom: none; }
.evento-info h3 { font-size: .95rem; }
.evento-info p  { font-size: .8rem; color: var(--muted); margin-top: 3px; }
.evento-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ── Alertas ── */
.alert {
  padding: 12px 16px;
  border-radius: 10px;
  font-size: .875rem;
  margin-bottom: 16px;
  border-left: 4px solid transparent;
}
.alert-error   { background: #fef2f2; border-color: var(--danger);  color: #991b1b; }
.alert-success { background: #f0fdf4; border-color: var(--success); color: #15803d; }
.alert-info    { background: #eff6ff; border-color: #3b82f6; color: #1d4ed8; }

/* ── Login ── */
.login-wrap {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px 16px;
  background: var(--primary);
}
.login-card {
  background: white;
  border-radius: 20px;
  padding: 32px 28px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.login-logo {
  text-align: center;
  margin-bottom: 28px;
}
.login-logo h1 { font-size: 1.6rem; }
.login-logo h1 span { color: var(--accent); }
.login-logo p  { font-size: .85rem; color: var(--muted); margin-top: 4px; }

/* ── Tracking Screen ── */
.tracking-screen {
  min-height: 100dvh;
  background: #0d1117;
  color: white;
  display: flex;
  flex-direction: column;
}

.tracking-header {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255,255,255,.05);
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.tracking-header h2 { font-size: .95rem; font-weight: 600; }

.tracking-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .8rem;
  padding: 4px 12px;
  border-radius: 20px;
  background: rgba(255,255,255,.08);
}
.tracking-status.activo   { background: rgba(34,197,94,.15);  color: #4ade80; }
.tracking-status.enviando { background: rgba(255,107,53,.15); color: #ff6b35; }
.tracking-status.sin-senal { background: rgba(239,68,68,.15); color: #f87171; }
.tracking-status.offline   { background: rgba(107,114,128,.2); color: #9ca3af; }

.tracking-stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 1px;
  background: rgba(255,255,255,.08);
  margin: 0;
}
.stat-box {
  background: #0d1117;
  padding: 20px 8px;
  text-align: center;
}
.stat-box__value {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
  color: white;
  font-variant-numeric: tabular-nums;
}
.stat-box__label {
  font-size: .7rem;
  color: rgba(255,255,255,.45);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-top: 4px;
}
.stat-box.highlight .stat-box__value { color: var(--accent); }

#tracking-map {
  flex: 1;
  min-height: 200px;
}

.tracking-controls {
  padding: 20px 16px;
  background: #0d1117;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.btn-tracking-start {
  background: var(--accent);
  color: white;
  padding: 20px;
  border-radius: 16px;
  font-size: 1.2rem;
  font-weight: 700;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: filter .15s, transform .1s;
}
.btn-tracking-start:active { transform: scale(.98); }
.btn-tracking-start.corriendo {
  background: rgba(239,68,68,.15);
  color: #f87171;
  border: 2px solid rgba(239,68,68,.3);
}

.tracking-info-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: .78rem;
  color: rgba(255,255,255,.4);
}

.gps-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  display: inline-block;
  background: var(--muted);
}
.gps-dot.ok  { background: var(--success); box-shadow: 0 0 6px var(--success); }
.gps-dot.err { background: var(--danger); }

/* ── Cola offline ── */
.offline-badge {
  background: rgba(245,158,11,.15);
  color: #fbbf24;
  padding: 6px 14px;
  border-radius: 8px;
  font-size: .8rem;
  display: none;
  text-align: center;
}
.offline-badge.visible { display: block; }

/* ── Mapa público ── */
#mapa-vivo {
  height: calc(100dvh - 56px);
  width: 100%;
}

/* ── Bottom sheet (lista de corredores) ── */
.bottom-sheet {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: white;
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -4px 20px rgba(0,0,0,.15);
  z-index: 500;
  transform: translateY(calc(100% - 72px));
  transition: transform .3s ease;
  max-height: 75dvh;
  display: flex;
  flex-direction: column;
}
.bottom-sheet.abierto { transform: translateY(0); }

.bottom-sheet__handle {
  padding: 14px 16px 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.bottom-sheet__pip {
  width: 36px; height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 8px;
}
.bottom-sheet__title { font-weight: 700; font-size: .95rem; }
.bottom-sheet__count { font-size: .8rem; color: var(--muted); background: var(--bg); padding: 3px 10px; border-radius: 20px; }

.bottom-sheet__search {
  padding: 0 16px 12px;
  flex-shrink: 0;
}
.bottom-sheet__search input {
  width: 100%;
  padding: 9px 14px;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-size: .9rem;
  outline: none;
}
.bottom-sheet__search input:focus { border-color: var(--accent); }

.corredor-list { overflow-y: auto; padding: 0 16px 20px; }

.corredor-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.corredor-item:last-child { border-bottom: none; }
.corredor-item:hover { background: var(--bg); margin: 0 -16px; padding-left: 16px; padding-right: 16px; }

.corredor-dorsal {
  width: 40px; height: 40px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .9rem;
  flex-shrink: 0;
}
.corredor-nombre { font-size: .9rem; font-weight: 600; }
.corredor-meta   { font-size: .78rem; color: var(--muted); }

/* ── Colores por categoría ── */
.cat-General   { background: #dbeafe; color: #1d4ed8; }
.cat-Femenino  { background: #fce7f3; color: #be185d; }
.cat-Veteranos { background: #fef3c7; color: #b45309; }
.cat-Junior    { background: #d1fae5; color: #065f46; }

/* ── Marcadores del mapa ── */
.marker-corredor {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 3px solid white;
  box-shadow: 0 2px 10px rgba(0,0,0,.35);
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700;
  font-family: system-ui, sans-serif;
  cursor: pointer;
  transition: transform .5s cubic-bezier(.25,.46,.45,.94);
  will-change: transform;
}
.marker-corredor.stale { opacity: .5; }
.marker-corredor.finalizado { opacity: .75; font-size: 16px; }

.marker-control {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: #1a2332;
  color: white;
  border: 3px solid white;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800;
  font-family: system-ui, sans-serif;
  box-shadow: 0 2px 8px rgba(0,0,0,.45);
}

.marker-meta {
  width: 36px; height: 36px;
  background: #ff6b35;
  border-radius: 50%;
  border: 3px solid white;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  box-shadow: 0 2px 10px rgba(255,107,53,.55);
}

.marker-largada {
  width: 36px; height: 36px;
  background: #16a34a;
  border-radius: 50%;
  border: 3px solid white;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  box-shadow: 0 2px 10px rgba(22,163,74,.55);
  font-family: system-ui, sans-serif;
}

/* ── Popup del marcador ── */
.popup-corredor { min-width: 160px; }
.popup-corredor h4 { font-size: .9rem; margin-bottom: 6px; }
.popup-corredor p  { font-size: .8rem; color: var(--muted); margin: 2px 0; }
.popup-corredor .speed { color: var(--accent); font-weight: 700; }

/* ── Responsivo ── */
@media (min-width: 640px) {
  .tracking-stats { grid-template-columns: repeat(3, 1fr); }
  .stat-box__value { font-size: 2.5rem; }
}

@media (min-width: 900px) {
  /* En desktop el bottom sheet se convierte en sidebar */
  .bottom-sheet {
    position: fixed;
    top: 56px; bottom: 0; right: 0; left: auto;
    width: 320px;
    border-radius: 0;
    transform: translateX(100%);
    max-height: none;
    box-shadow: -4px 0 20px rgba(0,0,0,.1);
  }
  .bottom-sheet.abierto { transform: translateX(0); }
  #mapa-vivo { height: calc(100dvh - 56px); }
}
