/* =========================================================
   Rutapeo — capa de tema de la app (se carga después de style.css)
   Navegación, autenticación, tipografía y ajustes de marca.
   ========================================================= */

body {
  background: var(--bg-main);
  font-family: var(--font-main);
  -webkit-font-smoothing: antialiased;
}
body#bg-image1 { background: var(--bg-main); }

h1, h2, .section-title, .pro-hero-card h1 {
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: -.005em;
  color: var(--oro-claro);
}
h3, h4, h5, h6 { font-family: var(--font-main); }

:focus-visible { outline: 3px solid var(--oro); outline-offset: 2px; }

a { color: var(--oro-claro); }

/* ---------- Pantalla de carga (hasta saber si hay sesión) ---------- */
.arranque {
  position: fixed; inset: 0; z-index: 5000;
  display: grid; place-content: center; justify-items: center; gap: 20px;
  background: var(--bg-main);
}
.arranque img { width: 72px; height: 72px; border-radius: 50%; border: 2px solid rgba(201, 162, 75, .5); }
.arranque-barra { width: 120px; height: 3px; border-radius: 3px; background: rgba(201, 162, 75, .18); overflow: hidden; }
.arranque-barra span { display: block; width: 40%; height: 100%; background: var(--oro); border-radius: 3px; animation: arranque 1s ease-in-out infinite; }
@keyframes arranque { from { transform: translateX(-100%); } to { transform: translateX(250%); } }

/* ---------- Pantalla de acceso (móvil primero) ---------- */
.contenidoPrincipalLogin {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex; align-items: flex-start; justify-content: center;
  padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  background:
    radial-gradient(600px 400px at 80% 0%, rgba(201, 162, 75, .12), transparent 60%),
    var(--bg-main);
}
/* Con sesión iniciada la app oculta #pantallaAuth: el contenedor también debe desaparecer */
.contenidoPrincipalLogin:has(> #pantallaAuth[style*="none"]) { display: none; }

/* En el teléfono no hay tarjeta: el formulario ocupa la pantalla */
.contenidoPrincipalLogin > #pantallaAuth {
  width: 100%; max-width: 420px; margin: 0;
  padding: 8px 0 0;
  background: none; border: 0; box-shadow: none; border-radius: 0;
  text-align: left;
}
.contenidoPrincipalLogin > #pantallaAuth .auth-logo { display: block; width: max-content; margin: 0 auto 12px; }
.contenidoPrincipalLogin > #pantallaAuth .app-logo {
  width: 72px; height: 72px; border-radius: 50%;
  display: block; object-fit: cover; margin: 0;
  border: 2px solid rgba(201, 162, 75, .5);
}
.contenidoPrincipalLogin > #pantallaAuth h2 {
  font-size: 1.85rem; line-height: 1.15; text-align: center;
  margin: 0 0 24px; color: var(--oro-claro);
}
.contenidoPrincipalLogin > #pantallaAuth h2 .app-name { color: inherit; font-weight: 400; }

.auth-tabs {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  padding: 4px; margin: 0 0 24px; list-style: none;
  background: rgba(0, 0, 0, .22); border-radius: var(--radius-full);
}
.auth-tabs li { margin: 0; }
.auth-tabs .nav-link {
  display: flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 8px;
  border-radius: var(--radius-full); color: var(--text-secondary);
  font-size: .98rem; font-weight: 600; text-decoration: none; text-align: center;
}
.auth-tabs .nav-link.active { background: var(--oro); color: var(--botella-hondo); }
.auth-tabs-reset { display: block; background: none; padding: 0; margin: 16px 0 0; }
.auth-tabs-reset .nav-link { display: inline-flex; min-height: 44px; padding: 0; color: var(--oro-claro); font-weight: 500; }
.auth-tabs-reset .nav-link.active { background: none; color: var(--oro-claro); }

.auth-form { display: grid; gap: 16px; }
.auth-form h3 { margin: 0; font-size: 1.2rem; color: var(--text-primary); }
.campo { display: grid; gap: 6px; }
.campo > span:first-child { font-size: .92rem; font-weight: 600; color: var(--text-secondary); }
.auth-form input, .auth-form select {
  width: 100%;
  min-height: 52px; padding: 0 16px;
  font-size: 16px; /* 16px evita el zoom automático de iOS al enfocar */
  background: var(--botella-hondo);
  border: 1px solid rgba(230, 207, 143, .22);
  color: var(--text-primary);
  border-radius: var(--radius-md);
}
.auth-form input:focus, .auth-form select:focus { border-color: var(--oro); outline: none; box-shadow: 0 0 0 3px rgba(201, 162, 75, .25); background: var(--botella-hondo); }
.campo-pass { position: relative; display: block; }
.campo-pass input { padding-right: 56px; }
.ver-pass {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 44px; height: 44px; border: 0; background: none; cursor: pointer;
  color: var(--text-muted); font-size: 1.2rem; border-radius: var(--radius-sm);
}
.ver-pass:hover, .ver-pass[aria-pressed="true"] { color: var(--oro-claro); }
.auth-form .btn-primary {
  width: 100%; min-height: 52px; margin: 4px 0 0;
  border: 0; border-radius: var(--radius-full);
  font-size: 1.05rem; font-weight: 700; cursor: pointer;
}
.auth-form .btn-primary:disabled { opacity: .75; cursor: progress; }
.auth-hint { font-size: .88rem; color: var(--text-muted); text-align: left; margin: -8px 0 0; }
.auth-msg {
  margin: 0; padding: 12px 14px; border-radius: var(--radius-md);
  font-size: .95rem; line-height: 1.4;
  background: rgba(210, 70, 90, .14); border: 1px solid rgba(210, 70, 90, .45); color: #FFD5DB;
}
.auth-msg[data-tipo="ok"] { background: rgba(63, 163, 107, .14); border-color: rgba(63, 163, 107, .45); color: #CFF2DD; }
.auth-enlace-local { color: var(--oro-claro); word-break: break-all; }
.auth-volver { display: inline-flex; align-items: center; min-height: 44px; margin-top: 8px; color: var(--text-muted); font-size: .95rem; text-decoration: none; }
.auth-volver:hover { color: var(--oro-claro); }

/* A partir de tablet sí hay tarjeta centrada */
@media (min-width: 600px) {
  .contenidoPrincipalLogin { align-items: center; padding: 48px 24px; }
  .contenidoPrincipalLogin > #pantallaAuth {
    padding: 40px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
  }
}

/* ---------- Botones ---------- */
.btn-primary, .btn.btn-primary {
  background: var(--oro);
  color: var(--botella-hondo);
  border-color: var(--oro);
  font-weight: 600;
}
.btn-primary:hover, .btn.btn-primary:hover { background: var(--oro-claro); border-color: var(--oro-claro); color: var(--botella-hondo); }

/* ---------- Barra superior ---------- */
.navbar {
  margin-top: 0;
  background: rgba(11, 38, 29, .94);
  backdrop-filter: saturate(140%) blur(10px);
  -webkit-backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--border-color);
  box-shadow: none;
  padding: 0 clamp(12px, 3vw, 24px);
}
.navbar-container { height: 64px; max-width: 1240px; gap: 16px; }
.navbar-brand { text-decoration: none; flex-shrink: 0; }
.navbar-brand img { width: 38px; height: 38px; border-radius: 50%; }
.navbar-brand .app-name {
  font-family: var(--font-display); font-weight: 400;
  font-size: 1.4rem; margin: 0; color: var(--oro-claro);
}
.navbar-menu { margin-left: auto; gap: 2px; flex-wrap: nowrap; }
.navbar-menu .nav-link {
  padding: .5rem .75rem;
  font-size: .95rem;
  color: var(--text-secondary);
  white-space: nowrap;
  text-decoration: none;
  border-radius: var(--radius-full);
  background: none;
  border: 0;
  font-family: inherit;
}
.navbar-menu .nav-link:hover { color: var(--oro-claro); background: rgba(201, 162, 75, .08); }
.navbar-menu .nav-link[aria-current="page"] { color: var(--oro-claro); background: rgba(201, 162, 75, .14); }
.navbar-menu .nav-crear {
  background: var(--oro); color: var(--botella-hondo); font-weight: 600; margin-left: 6px;
}
.navbar-menu .nav-crear:hover { background: var(--oro-claro); color: var(--botella-hondo); }

/* Menú "Más" con <details> (sin selects nativos) */
.nav-mas { position: relative; }
.nav-mas > summary { list-style: none; cursor: pointer; }
.nav-mas > summary::-webkit-details-marker { display: none; }
.nav-mas > summary i.bi-chevron-down { font-size: .75rem; transition: transform .2s; }
.nav-mas[open] > summary i.bi-chevron-down { transform: rotate(180deg); }
.nav-mas-panel {
  position: absolute; right: 0; top: calc(100% + 8px);
  min-width: 230px; padding: 6px;
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  display: grid; z-index: 1100;
}
.nav-mas-panel .nav-link { border-radius: var(--radius-md); justify-content: flex-start; }
.nav-mas-panel hr { border: 0; border-top: 1px solid var(--border-color); margin: 6px 4px; }

.navbar-toggle { color: var(--oro-claro); width: 44px; height: 44px; }

@media (max-width: 1100px) {
  .navbar-toggle { display: grid; place-items: center; margin-left: auto; }
  .navbar-menu {
    display: none;
    position: absolute; top: 64px; left: 0; right: 0;
    flex-direction: column; align-items: stretch; gap: 0;
    background: var(--bg-main);
    border-bottom: 1px solid var(--border-color);
    padding: 8px clamp(12px, 3vw, 24px) 16px;
    max-height: calc(100dvh - 64px); overflow-y: auto;
    margin-left: 0;
  }
  .navbar-menu.active { display: flex; }
  .navbar-menu .nav-link { padding: .85rem .5rem; border-radius: var(--radius-sm); }
  .navbar-menu .nav-crear { margin: 8px 0 4px; justify-content: center; border-radius: var(--radius-full); }
  .nav-mas-panel { position: static; box-shadow: none; border: 0; background: none; padding: 0 0 0 1rem; min-width: 0; }
}

/* ---------- Navegación inferior (móvil) ---------- */
.bottom-nav-pro { background: rgba(11, 38, 29, .97); border-top: 1px solid var(--border-color); }
.bottom-nav-pro button { color: var(--text-muted); min-height: 52px; font-family: inherit; cursor: pointer; }
.bottom-nav-pro button[aria-current="page"] { color: var(--oro-claro); }
.bottom-nav-pro button.bn-crear i {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--oro); color: var(--botella-hondo);
  margin-top: -14px; box-shadow: 0 6px 16px -6px rgba(0, 0, 0, .6);
}

/* ---------- Contenido ---------- */
#contenidoPrincipal { max-width: 1240px; margin: 0 auto; }
.card, .pro-card, .mapa-item, .empty-state {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
}
.pro-hero-card {
  background:
    radial-gradient(700px 300px at 100% 0%, rgba(201, 162, 75, .16), transparent 70%),
    var(--bg-card);
  border: 1px solid var(--border-color);
  box-shadow: none;
}
.pro-hero-card p { color: var(--text-secondary); }
.pro-badge { background: rgba(201, 162, 75, .14); color: var(--oro-claro); }
.pro-card { color: var(--text-primary); box-shadow: none; transition: border-color var(--transition); }
.pro-card:hover { border-color: rgba(201, 162, 75, .5); }
.pro-card i { color: var(--oro); }
.pro-card span { color: var(--text-muted); }
.chip { background: transparent; border-color: var(--border-color); color: var(--text-secondary); cursor: pointer; }
.chip.active { background: var(--oro); border-color: var(--oro); color: var(--botella-hondo); }

input, select, textarea { font-family: inherit; }
.form-control, .form-select, input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="search"], select, textarea {
  background-color: var(--bg-main);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}
.form-control:focus, .form-select:focus, input:focus, select:focus, textarea:focus {
  border-color: var(--oro);
  box-shadow: 0 0 0 3px rgba(201, 162, 75, .22);
  outline: none;
}

/* Toast */
.toast-rutapeo, .toast, #toast {
  font-family: var(--font-main);
}

/* Leaflet: popups con la marca */
.leaflet-popup-content-wrapper { border-radius: var(--radius-md); }
.leaflet-container a.leaflet-popup-close-button { color: var(--botella); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

/* ---------- Toast ---------- */
.toast-zona {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 3000;
  display: grid; gap: 8px; width: min(92vw, 420px); pointer-events: none;
}
@media (min-width: 761px) { .toast-zona { bottom: 24px; } }
.toast-rp {
  padding: 12px 16px; border-radius: var(--radius-md);
  background: var(--oro-claro); color: var(--botella-hondo);
  font-weight: 600; box-shadow: var(--shadow-lg);
  opacity: 0; transform: translateY(8px); transition: opacity .2s, transform .2s;
}
.toast-rp.visible { opacity: 1; transform: none; }
.toast-rp-error { background: var(--danger); color: #fff; }
.toast-rp-aviso { background: var(--warning); color: var(--botella-hondo); }

/* Subtítulos legibles (antes gris oscuro sobre fondo oscuro) */
.app-slogan { color: var(--text-secondary) !important; opacity: 1 !important; font-size: 1rem; }
.text-muted { color: var(--text-muted) !important; }
.pro-actions > * { width: 100%; justify-content: center; }

/* Sin sesión (barra superior oculta) no se muestra la navegación inferior */
body:has(#mainNavbar[style*="none"]) .bottom-nav-pro { display: none !important; }
.contenidoPrincipalLogin > #pantallaAuth .auth-volver { display: flex; justify-content: center; width: 100%; }
.contenidoPrincipalLogin > #pantallaAuth .auth-tabs-reset { text-align: center; }
.pro-actions > .btn { margin: 0; min-height: 52px; }

/* ---------- Alta: datos del bar, consentimientos, antirrobots y enlaces legales ---------- */
.campos-bar { display: grid; gap: 16px; padding: 14px; border-radius: 14px; border: 1px dashed rgba(230, 207, 143, .35); }
.campos-bar[hidden] { display: none; }
.trampa { position: absolute !important; left: -10000px !important; width: 1px; height: 1px; overflow: hidden; }
.consentimientos { display: grid; gap: 10px; }
.check { display: grid; grid-template-columns: 24px 1fr; gap: 10px; align-items: start; font-size: .92rem; color: var(--text-secondary); line-height: 1.4; cursor: pointer; }
.check input { width: 22px !important; height: 22px; min-height: 0 !important; margin: 0; padding: 0 !important; accent-color: var(--oro); }
.check a { color: var(--oro-claro); }
.auth-legal { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 16px; margin-top: 4px; }
.auth-legal a { display: inline-flex; align-items: center; min-height: 40px; color: var(--text-muted); font-size: .85rem; text-decoration: none; }
.auth-legal a:hover { color: var(--oro-claro); }
.auth-reenviar { margin-top: 8px; min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid currentColor; background: none; color: inherit; font: 600 .9rem var(--font-main); cursor: pointer; }
#formCodigo input[name="codigo"] { font-size: 1.6rem !important; letter-spacing: .4em; text-align: center; font-variant-numeric: tabular-nums; }
#cancelarCodigo { background: none; border: 0; cursor: pointer; justify-content: center; width: 100%; }

/* Aviso «la ruta se guarda sola» al venir de «Guárdala gratis» */
.auth-aviso-guardar { display: flex; align-items: center; gap: 8px; margin: -12px 0 18px; padding: 10px 12px; border-radius: 12px; background: rgba(201, 162, 75, .14); color: var(--oro-claro); font-size: .9rem; }
.auth-aviso-guardar .bi { color: var(--oro); }
