/* =========================================
   1. VARIABLES Y RESET GLOBAL
========================================= */
:root {
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --color-bg: #f8f9fa;
    --color-text: #212529;
    --color-muted: #868e96;
    --color-brand-dark: #264653; 
    --color-brand-teal: #2a9d8f; 
    
    --color-bad: #e03131;
    --color-neutral: #f59f00;
    --color-good: #37b24d;

    --shadow-ui: 0 4px 12px rgba(0,0,0,0.1);
    --shadow-popup: 0 10px 25px rgba(0,0,0,0.15);
    --radius-ui: 12px;
    --radius-popup: 16px;
}

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

body { 
    height: 100vh; width: 100vw; 
    font-family: var(--font-family); 
    overflow: hidden; 
    background-color: #eee;
}

/* =========================================
   2. INTERFAZ FLOTANTE (HEADER)
========================================= */
.floating-ui {
    position: absolute;
    top: 20px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(5px);
    padding: 8px 15px;
    border-radius: 30px; 
    box-shadow: var(--shadow-ui);
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Caja Izquierda: Logo + Selector + Buscador */
.brand-box {
    left: 20px;
    padding: 6px 15px;
    max-width: 600px; 
}

.logo-text {
    font-size: 1.1rem;
    font-weight: 800;
    margin-right: 5px;
    white-space: nowrap;
}
.text-brand-dark { color: var(--color-brand-dark); }
.text-brand-teal { color: var(--color-brand-teal); }

/* Selector de Ciudad */
#city-selector {
    background-color: #f1f3f5;
    border: none;
    border-radius: 20px;
    padding: 6px 12px;
    font-family: var(--font-family);
    font-weight: 600;
    font-size: 0.85rem;
    color: #495057;
    cursor: pointer;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23495057' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 8px center;
    background-size: 12px;
    padding-right: 25px;
    transition: background 0.2s;
    max-width: 130px;
}
#city-selector:hover { background-color: #e9ecef; color: #000; }

/* --- BUSCADOR INTEGRADO --- */
.search-container {
    position: relative;
    display: flex;
    align-items: center;
}

#custom-search-input {
    border: 1px solid #dee2e6;
    background: #fff;
    padding: 6px 12px;
    padding-left: 30px;
    border-radius: 20px;
    font-family: var(--font-family);
    font-size: 0.85rem;
    outline: none;
    width: 180px;
    transition: all 0.3s;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%23999' viewBox='0 0 16 16'%3e%3cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001c.03.04.062.078.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1.007 1.007 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0z'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: 8px center;
}
#custom-search-input:focus {
    width: 220px;
    border-color: var(--color-brand-teal);
    box-shadow: 0 0 0 3px rgba(42, 157, 143, 0.1);
}

/* Lista de Resultados */
.search-results-list {
    position: absolute;
    top: 40px;
    left: 0;
    width: 100%;
    min-width: 250px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.15);
    padding: 0;
    margin: 0;
    list-style: none;
    z-index: 2000;
    overflow: hidden;
}
.search-results-list.hidden { display: none; }

.search-result-item {
    padding: 10px 15px;
    border-bottom: 1px solid #f1f3f5;
    font-size: 0.85rem;
    color: var(--color-text);
    cursor: pointer;
    transition: background 0.2s;
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background-color: #f8f9fa; color: var(--color-brand-teal); }


/* Caja Derecha: Idiomas */
.lang-box { right: 20px; padding: 8px 15px; }
.lang-btn { background: transparent; border: none; font-size: 1.2rem; cursor: pointer; transition: transform 0.2s; padding: 0 5px; }
.lang-btn:hover { transform: scale(1.2); }

/* =========================================
   3. TUTORIAL / AYUDA (?)
========================================= */
.help-box {
    top: 80px; 
    right: 20px;
    width: 40px; height: 40px;
    padding: 0;
    justify-content: center;
    border-radius: 50%;
    cursor: pointer;
    background: white;
}
.help-btn {
    background: none; border: none; font-weight: 800; font-size: 1.2rem; color: var(--color-text); cursor: pointer; width: 100%; height: 100%;
}

.tutorial-card {
    position: absolute;
    top: 80px; right: 70px;
    width: 280px;
    background: white;
    padding: 20px;
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    z-index: 2000;
    font-family: var(--font-family);
    transition: all 0.3s ease;
    opacity: 1; transform: scale(1);
}
.tutorial-card.hidden { opacity: 0; pointer-events: none; transform: scale(0.9); }
.tutorial-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; }
.tutorial-header h4 { font-weight: 800; color: var(--color-brand-dark); font-size: 1rem; margin: 0; }
.close-btn { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: #999; line-height: 1; }
.tutorial-steps { padding-left: 20px; font-size: 0.85rem; color: #555; line-height: 1.6; }
.tutorial-steps li { margin-bottom: 8px; }
.tutorial-steps b { color: var(--color-brand-teal); }

/* =========================================
   4. NOTIFICACIONES (TOAST)
========================================= */
#notification {
    visibility: hidden;
    min-width: 250px;
    max-width: 90%;
    background-color: #333;
    color: #fff;
    text-align: center;
    border-radius: 50px;
    padding: 12px 24px;
    position: fixed;
    z-index: 2000;
    left: 50%;
    top: 90px;
    transform: translateX(-50%);
    font-size: 0.9rem;
    font-weight: 600;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    opacity: 0;
    transition: opacity 0.3s, top 0.3s;
}
#notification.show { visibility: visible; opacity: 1; top: 100px; }
#notification.success { background-color: rgba(55, 178, 77, 0.95); }
#notification.error { background-color: rgba(224, 49, 49, 0.95); }

/* =========================================
   5. MAPA
========================================= */
main { height: 100%; width: 100%; }
#map-container { width: 100%; height: 100%; border: none; }
footer { display: none; }

.leaflet-top.leaflet-left { top: 80px; } 

/* =========================================
   6. POPUP MODERNO
========================================= */
.leaflet-popup-content-wrapper { border-radius: var(--radius-popup); box-shadow: var(--shadow-popup); padding: 0; overflow: visible; }

/* --- CORRECCIÓN DE TEXTO CORTADO --- */
.leaflet-popup-content { 
    margin: 0 !important; 
    width: 290px !important; 
    font-family: var(--font-family); 
    
    /* Estas 3 líneas permiten que las direcciones largas bajen de línea */
    white-space: normal !important;
    word-wrap: break-word !important;
    line-height: 1.4;
}

.leaflet-popup-tip { background: #fff; box-shadow: var(--shadow-popup); }
.leaflet-container a.leaflet-popup-close-button { color: #999; font-size: 24px; top: 10px; right: 10px; }

.modern-popup { padding: 24px; text-align: center; }
.popup-header h3 { font-size: 1.2rem; font-weight: 700; color: var(--color-text); margin-bottom: 5px; text-align: left; }

.popup-score-section { display: flex; justify-content: center; align-items: center; margin: 20px 0; }
.score-big { font-size: 3.5rem; font-weight: 800; line-height: 1; }
.trend-big { font-size: 2rem; }
.popup-trend-label { display: block; font-size: 0.6rem; text-transform: uppercase; color: var(--color-muted); margin-top: 2px; font-weight: 700; letter-spacing: 0.5px; }

.color-bad { color: var(--color-bad); }
.color-neutral { color: var(--color-neutral); }
.color-good { color: var(--color-good); }
.popup-divider { height: 1px; background: #eee; margin: 0 -24px 20px; }

.popup-voting p { font-size: 0.9rem; color: var(--color-muted); margin-bottom: 10px; font-weight: 600; }
.vote-buttons-container { display: flex; justify-content: center; gap: 10px; }
.vote-circle-btn { width: 45px; height: 45px; border-radius: 50%; border: none; color: white; font-weight: 700; font-size: 1.1rem; cursor: pointer; transition: 0.2s; display: flex; align-items: center; justify-content: center; box-shadow: 0 3px 6px rgba(0,0,0,0.15); }
.vote-circle-btn:hover { transform: scale(1.1); box-shadow: 0 5px 10px rgba(0,0,0,0.2); }

.btn-1 { background: var(--color-bad); }
.btn-2 { background: var(--color-neutral); }
.btn-3 { background: #84cc16; }
.btn-4 { background: var(--color-good); }

/* =========================================
   7. LEYENDA
========================================= */
.info.legend {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(5px);
    padding: 15px;
    border-radius: var(--radius-ui);
    box-shadow: var(--shadow-ui);
    font-family: var(--font-family);
    min-width: 230px;
}
.info.legend h4 { margin: 0 0 10px; font-weight: 700; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.5px; color: #555; }
.legend-labels { display: flex; justify-content: space-between; font-size: 0.75rem; color: #666; margin-top: 5px; }

/* =========================================
   8. RESPONSIVE (MÓVIL)
========================================= */
@media (max-width: 768px) {
    /* Header mucho más compacto */
    .floating-ui { top: 10px; padding: 6px 10px; gap: 5px; }
    .brand-box { left: 10px; padding: 4px 10px; }
    .logo-text { display: none; } /* Ocultar Logo */
    
    #city-selector { max-width: 100px; padding-right: 20px; font-size: 0.8rem; }
    #custom-search-input { width: 120px; font-size: 0.8rem; padding: 5px 10px 5px 28px; }
    #custom-search-input:focus { width: 140px; }

    .lang-box { right: 10px; padding: 4px 8px; }
    .lang-btn { font-size: 1rem; }
    
    .help-box { top: 60px; right: 10px; }
    .tutorial-card { width: 90%; top: 50%; left: 50%; transform: translate(-50%, -50%); }

    .leaflet-top.leaflet-left { top: 70px; left: 10px; }
    .leaflet-popup-content { width: 280px !important; margin: 0 !important; }

    .info.legend { position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%); width: 90%; z-index: 1000; }
    .leaflet-control-attribution { font-size: 8px; margin-bottom: 5px; background: rgba(255,255,255,0.7) !important; }
}

@media (max-height: 500px) and (orientation: landscape) {
    .floating-ui { top: 5px; }
    .popup-header { display: none; }
    .info.legend { width: auto; position: absolute; left: auto; right: 10px; transform: none; bottom: 10px; }
}
/* =========================================
   11. POPUP DE BÚSQUEDA (Dirección)
========================================= */
.search-popup {
    padding: 24px 20px; /* Relleno generoso */
    text-align: center;
}

.search-popup h4 {
    margin: 0 0 8px 0;
    color: var(--color-brand-dark);
    font-size: 1rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.search-popup p {
    margin: 0;
    color: #555;
    font-size: 0.95rem;
    line-height: 1.5;
    font-weight: 500;
}

/* ====================================================
   CORRECCIÓN FINAL: ESTILOS PARA FLASH CARDS (3D)
   ==================================================== */

/* Contenedor principal de la escena 3D */
.scene {
    perspective: 1000px; /* Perspectiva más profunda */
    width: 100%;
    min-height: 280px; /* Un poco más alto para que quepa todo */
    margin-bottom: 5px;
    position: relative;
}

/* La tarjeta en sí */
.card {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    transition: transform 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    transform-style: preserve-3d;
}

/* Clase que activa el giro */
.card.is-flipped {
    transform: rotateY(180deg);
}

/* ESTILO COMÚN PARA AMBAS CARAS */
.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden; /* Safari */
    backface-visibility: hidden; /* Esencial para que no se vea el revés */
    background: white;
    border-radius: 12px; /* Bordes redondeados */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 15px 10px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1); /* Sombra suave */
    overflow: hidden; /* Evita que el contenido se salga */
}

/* CARA DELANTERA (Votación) */
.card-face-front {
    z-index: 2; /* Por defecto, está delante */
    transform: rotateY(0deg); /* Asegura la posición inicial */
}

/* CARA TRASERA (Razones) */
.card-face-back {
    transform: rotateY(180deg); /* Ya está girada de inicio */
    z-index: 1; /* Está detrás */
    background: linear-gradient(to bottom right, #f8f9fa, #ffffff); /* Fondo sutil */
    padding-top: 20px;
}

/* Cuando la tarjeta gira, la cara trasera pasa al frente */
.card.is-flipped .card-face-back {
    z-index: 3;
}

/* ---- Resto de estilos (Chips y Botones) ---- */
.reasons-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin: 15px 0;
    width: 100%;
    max-width: 240px; /* Limita el ancho para que no se desmadre */
}

.reason-chip {
    background: #fff;
    border: 1px solid #dce4ec;
    border-radius: 20px;
    padding: 8px 14px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
    color: #555;
    user-select: none;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    font-weight: 500;
}

.reason-chip:hover {
    background: #f0f4f8;
    transform: translateY(-2px);
    border-color: #cbd6e2;
}

.reason-chip.selected {
    background: #3498db;
    color: white;
    border-color: #3498db;
    box-shadow: 0 4px 8px rgba(52, 152, 219, 0.3);
    font-weight: 600;
    transform: scale(1.05);
}

.btn-confirm {
    background: linear-gradient(135deg, #2ecc71, #27ae60);
    color: white;
    border: none;
    padding: 12px 30px;
    border-radius: 30px;
    font-weight: bold;
    font-size: 1rem;
    cursor: pointer;
    margin-top: 15px;
    width: auto;
    min-width: 180px;
    box-shadow: 0 4px 10px rgba(46, 204, 113, 0.3);
    transition: all 0.2s;
}

.btn-confirm:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(46, 204, 113, 0.4);
}

.btn-confirm:active {
    transform: scale(0.98);
}

.btn-back {
    margin-top: 15px;
    background: none;
    border: none;
    color: #95a5a6;
    cursor: pointer;
    text-decoration: none;
    font-size: 0.85rem;
    border-bottom: 1px dotted #95a5a6;
    transition: color 0.2s;
}
.btn-back:hover { color: #7f8c8d; border-bottom-style: solid; }

/* Ajuste para el mensaje final de éxito */
.success-message-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 20px;
}
/* --- ESTILOS PARA LA LEYENDA DEL MAPA --- */
/* Esto da estilo al bloque único de la leyenda */
.info.legend {
    background: white;
    padding: 12px;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.15);
    font-family: 'Inter', sans-serif;
    min-width: 150px;
}

/* Título de la leyenda */
.info.legend h4 {
    margin: 0 0 8px;
    font-size: 13px;
    text-align: center;
    color: #666;
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.5px;
}

/* Barra de colores */
.legend-gradient {
    background: linear-gradient(to right, #e74c3c, #e67e22, #f1c40f, #2ecc71);
    height: 10px;
    border-radius: 5px;
    margin-bottom: 6px;
}

/* Etiquetas de números (1.0 - 4.0) */
.legend-labels {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: #888;
    font-weight: 500;
}