/* ════════════════════════════════════════════════════════════════════
   MotoRide Web — Sistema de diseño
   Paleta heredada de la app Android (mismo morado de marca y de ruta).
   Tipografía de sistema — sin Google Fonts, cero dependencias externas.
   ════════════════════════════════════════════════════════════════════ */

:root {
  /* Marca — idéntica a Android (mr_purple) */
  --mr-purple:        #6C4BD9;
  --mr-purple-dark:   #5333C2;
  --mr-purple-light:  #EDE7FB;

  /* Ruta — morado vivo usado en el mapa (igual a #7B2CFF de Android) */
  --mr-route:         #7B2CFF;

  /* Estado */
  --mr-success:       #16A34A;
  --mr-success-bg:    #E8F5E9;
  --mr-warning:       #E65100;
  --mr-warning-bg:    #FFF3E0;
  --mr-danger:        #DC2626;
  --mr-danger-bg:     #FEF2F2;

  /* Texto / superficie */
  --mr-text:          #212121;
  --mr-text-secondary:#757575;
  --mr-text-muted:    #9E9E9E;
  --mr-surface:       #FFFFFF;
  --mr-bg:            #F5F5F5;
  --mr-border:        #E8E8E8;

  /* Layout */
  --mr-radius:        14px;
  --mr-radius-sm:     10px;
  --mr-shadow:        0 2px 10px rgba(0,0,0,0.07);
  --mr-shadow-lg:     0 8px 28px rgba(0,0,0,0.14);

  /* Safe areas iOS (PWA standalone en iPhone con notch) */
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left, 0px);
  --safe-right:  env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  /* Pila de fuentes de sistema — nada de Google Fonts */
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               Helvetica, Arial, sans-serif;
  color: var(--mr-text);
  background: var(--mr-bg);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

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

button, input, select, textarea { font-family: inherit; }

a { color: var(--mr-purple); text-decoration: none; }

/* ── Botones ─────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 52px;
  padding: 0 20px;
  border: none;
  border-radius: var(--mr-radius-sm);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .08s ease, opacity .15s ease;
  -webkit-appearance: none;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary { background: var(--mr-purple); color: #fff; }
.btn-primary:active { background: var(--mr-purple-dark); }

.btn-secondary { background: var(--mr-purple-light); color: var(--mr-purple-dark); }

.btn-ghost { background: transparent; color: var(--mr-text-secondary); }

.btn-danger { background: var(--mr-danger-bg); color: var(--mr-danger); }

.btn-block { width: 100%; }

/* ── Inputs ──────────────────────────────────────────────────────── */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}
.field label {
  font-size: 13px;
  font-weight: 600;
  color: var(--mr-text-secondary);
}
.field input, .field select {
  height: 48px;
  padding: 0 14px;
  border: 1.5px solid var(--mr-border);
  border-radius: var(--mr-radius-sm);
  font-size: 16px; /* 16px previene zoom automático en iOS Safari */
  background: var(--mr-surface);
  color: var(--mr-text);
}
.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--mr-purple);
}

/* ── Tarjetas ────────────────────────────────────────────────────── */
.card {
  background: var(--mr-surface);
  border-radius: var(--mr-radius);
  box-shadow: var(--mr-shadow);
  padding: 16px;
}

/* ── Topbar ──────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(var(--safe-top) + 14px) 16px 14px;
  background: var(--mr-surface);
  border-bottom: 1px solid var(--mr-border);
  flex-shrink: 0;
}
.topbar h1 {
  font-size: 17px;
  font-weight: 700;
  margin: 0;
  flex: 1;
}
.topbar .icon-btn {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 20px;
}
.topbar .icon-btn:active { background: var(--mr-bg); }

/* ── Bottom nav ──────────────────────────────────────────────────── */
.bottom-nav {
  display: flex;
  background: var(--mr-surface);
  border-top: 1px solid var(--mr-border);
  padding: 6px var(--safe-right) calc(var(--safe-bottom) + 6px) var(--safe-left);
  flex-shrink: 0;
}
.bottom-nav .nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 0;
  font-size: 11px;
  color: var(--mr-text-muted);
  background: none;
  border: none;
  cursor: pointer;
}
.bottom-nav .nav-item .nav-icon { font-size: 21px; }
.bottom-nav .nav-item.active { color: var(--mr-purple); font-weight: 700; }

/* ── Contenido scrolleable ───────────────────────────────────────── */
.view {
  flex: 1;
  overflow-y: auto;
  display: none;
  -webkit-overflow-scrolling: touch;
}
.view.active { display: flex; flex-direction: column; }
.view-content { padding: 16px; padding-bottom: 24px; }

/* ── Estado vacío ────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 48px 24px;
  color: var(--mr-text-muted);
}
.empty-state .emoji { font-size: 40px; margin-bottom: 10px; }
.empty-state p { margin: 4px 0; font-size: 14px; }

/* ── Toast ───────────────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 90px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--mr-text);
  color: #fff;
  padding: 12px 20px;
  border-radius: 30px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--mr-shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 9999;
  max-width: 85%;
  text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Spinner ─────────────────────────────────────────────────────── */
.spinner {
  width: 22px; height: 22px;
  border: 3px solid rgba(255,255,255,.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: mr-spin .7s linear infinite;
}
.spinner.dark { border-color: rgba(108,75,217,.2); border-top-color: var(--mr-purple); }
@keyframes mr-spin { to { transform: rotate(360deg); } }

/* ── Mapa ────────────────────────────────────────────────────────── */
.map-box {
  width: 100%;
  border-radius: var(--mr-radius);
  overflow: hidden;
  background: #E8E8E8;
}
.leaflet-container { background: #E8E8E8 !important; }

/* Badge de estado del viaje */
.trip-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 700;
}
.trip-badge.searching { background: var(--mr-purple-light); color: var(--mr-purple-dark); }
.trip-badge.assigned  { background: #FFF3E0; color: #E65100; }
.trip-badge.ongoing   { background: var(--mr-success-bg); color: var(--mr-success); }

/* ── Búsqueda de lugares (home) ──────────────────────────────────── */
.search-results {
  margin-top: 4px;
  border-radius: var(--mr-radius-sm);
  overflow: hidden;
}
.search-result-item {
  padding: 10px 12px;
  font-size: 14px;
  background: var(--mr-surface);
  border-bottom: 1px solid var(--mr-border);
  cursor: pointer;
}
.search-result-item:active { background: var(--mr-purple-light); }
.search-result-item:last-child { border-bottom: none; }

.fav-chip {
  flex-shrink: 0;
  white-space: nowrap;
  height: 34px;
  padding: 0 14px;
  border-radius: 18px;
  background: var(--mr-purple-light);
  color: var(--mr-purple-dark);
  border: none;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.field .field-error {
  font-size: 12px;
  color: var(--mr-danger);
  min-height: 14px;
  display: block;
}

.error-box {
  background: var(--mr-danger-bg);
  color: var(--mr-danger);
  border-radius: var(--mr-radius-sm);
  padding: 12px 14px;
  font-size: 13px;
  margin-bottom: 14px;
  line-height: 1.4;
}
.error-box a { color: var(--mr-danger); font-weight: 700; text-decoration: underline; }

/* Accesibilidad: foco visible siempre */
:focus-visible {
  outline: 2.5px solid var(--mr-purple);
  outline-offset: 2px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
