:root {
    /* Colores Institucionales Claros y Sin Blanco Puro */
    --bg-main: #f4f7f6;
    --bg-secondary: #e9ecef;
    --bg-card: #f8f9fa;
    --text-main: #2b3035;
    --text-muted: #6c757d;

    --primary: #0077b6;
    /* Azul institucional */
    --hover-primary: #005f92;
    --secondary: #00b4d8;

    /* Estados del Ticket */
    --state-0: #e63946;
    /* Reportado (🔴) */
    --state-1: #e9c46a;
    /* Validado (🟡) */
    --state-2: #457b9d;
    /* Enviado (🔵) */
    --state-3: #2a9d8f;
    /* Resuelto (✅) */

    --shadow-sm: 0 4px 6px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 8px 15px rgba(0, 0, 0, 0.08);
    --radius: 12px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    overflow: hidden;
}

#app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background-color: var(--bg-card);
    border-right: 1px solid var(--bg-secondary);
    display: flex;
    flex-direction: column;
    padding: 20px;
    z-index: 1000;
    box-shadow: var(--shadow-md);
}

.sidebar-header {
    text-align: center;
    margin-bottom: 30px;
}

.sidebar-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
}

.sidebar-header h2 span {
    font-weight: 300;
    color: var(--text-main);
}

.sidebar-header p {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex-grow: 1;
}

.nav-item {
    text-decoration: none;
    padding: 12px 15px;
    border-radius: var(--radius);
    color: var(--text-main);
    font-weight: 600;
    transition: all 0.3s ease;
}

.nav-item:hover {
    background-color: var(--bg-secondary);
}

.nav-item.active {
    background-color: var(--primary);
    color: #f8f9fa;
    box-shadow: var(--shadow-sm);
}

/* Botones de Autenticación */
.sidebar-auth {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.btn {
    padding: 12px;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-family: inherit;
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.3s ease;
    text-align: center;
}

.btn-primary {
    background-color: var(--primary);
    color: #f8f9fa;
    /* No blanco puro */
}

.btn-primary:hover {
    background-color: var(--hover-primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

.btn-secondary {
    background-color: var(--bg-secondary);
    color: var(--text-main);
}

.btn-secondary:hover {
    background-color: #dee2e6;
}

/* Main Content */
.main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Nuevo Reporte Botón Flotante Superior */
.topbar {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    align-items: center;
    pointer-events: none;
    /* Que solo los botones de adentro capturen click */
}

.topbar>* {
    pointer-events: auto;
    /* Reactivar clicks para los hijos */
}

.btn-report {
    background-color: var(--state-0);
    color: #f8f9fa;
    border: none;
    padding: 12px 24px;
    border-radius: 30px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-report:hover {
    background-color: #d90429;
    transform: scale(1.05);
}

/* Contenedor del Mapa */
#map-container {
    flex-grow: 1;
    position: relative;
}

#map {
    width: 100%;
    height: 100%;
}

/* Leyenda del Mapa */
.map-legend {
    position: absolute;
    bottom: 30px;
    left: 20px;
    background-color: var(--bg-card);
    padding: 15px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    z-index: 1000;
}

.map-legend h4 {
    margin-bottom: 10px;
    font-size: 0.9rem;
    color: var(--text-main);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 5px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
}

.state-0 {
    background-color: var(--state-0);
}

.state-1 {
    background-color: var(--state-1);
}

.state-2 {
    background-color: var(--state-2);
}

.state-3 {
    background-color: var(--state-3);
}

/* Custom Map Popup Styles */
.leaflet-popup-content-wrapper {
    background: var(--bg-card);
    color: var(--text-main);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 5px;
}

.leaflet-popup-tip {
    background: var(--bg-card);
}

.popup-title {
    font-weight: 700;
    margin-bottom: 5px;
}

.popup-desc {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 10px;
}

.btn-validate {
    background-color: var(--state-1);
    color: #fff;
    border: none;
    padding: 5px 10px;
    border-radius: 20px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.8rem;
    width: 100%;
}

.btn-validate:hover {
    background-color: #d4a742;
}

/* Modals y Forms */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    z-index: 2000;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    background: #fff;
    width: 90%;
    max-width: 400px;
    padding: 30px;
    border-radius: var(--radius);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
    z-index: 2001;
    display: none;
    opacity: 0;
    transition: all 0.3s ease;
}

.modal.active,
.modal-overlay.active {
    display: block;
    opacity: 1;
}

.modal.active {
    transform: translate(-50%, -50%) scale(1);
}

.modal h3 {
    color: var(--primary);
    margin-bottom: 5px;
    font-size: 1.4rem;
}

.modal p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 20px;
}

.modal-close {
    position: absolute;
    top: 15px;
    right: 20px;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-muted);
    cursor: pointer;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 5px;
    color: var(--text-main);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--bg-secondary);
    border-radius: 8px;
    background-color: var(--bg-card);
    font-family: inherit;
    transition: border 0.3s ease;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.form-msg {
    margin-top: 10px;
    font-size: 0.85rem;
    text-align: center;
}

.form-msg.error {
    color: var(--state-0);
}

.form-msg.success {
    color: var(--state-3);
}

/* Leaflet Popup y Z-Index Fixes */
.leaflet-popup-content-wrapper {
    background: #ffffff !important;
    color: #2b3035 !important;
    border-radius: 8px !important;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2) !important;
}

.leaflet-popup-tip {
    background: #ffffff !important;
}

.leaflet-popup-content {
    margin: 15px !important;
    line-height: 1.5 !important;
}

.popup-title {
    font-size: 1.1rem;
    font-weight: bold;
    color: var(--primary);
    margin-bottom: 5px;
}

/* =========================================
   MEDIA QUERIES - RESPONSIVIDAD PARA MÓVILES
   ========================================= */
@media (max-width: 768px) {
    #app-container {
        flex-direction: column-reverse;
        /* Sidebar va abajo, Mapa arriba en la pantalla del celular */
    }

    /* La barra lateral toma 40% del alto, mapa 60% inicial */
    .sidebar {
        width: 100% !important;
        height: 40% !important;
        max-height: 40% !important;
        border-right: none;
        border-top: 1px solid var(--bg-secondary);
        position: relative !important;
        padding: 15px;
        overflow-y: auto;
    }

    .main-content {
        width: 100% !important;
        height: 60% !important;
        margin-left: 0 !important;
    }

    #map-container {
        height: 100%;
    }

    .topbar {
        top: 10px;
        right: 10px;
    }

    .btn-report {
        padding: 8px 16px;
        font-size: 0.9rem;
    }

    /* Ajustar estilo y tamaño de la leyenda en móvil */
    .map-legend {
        bottom: 15px;
        left: 10px;
        padding: 8px 12px;
        background-color: rgba(255, 255, 255, 0.95);
        /* Forzar fondo blanco super opaco */
        border: 1px solid rgba(0, 0, 0, 0.1);
        border-radius: 8px;
        z-index: 1000;
        max-width: 90%;
    }

    .map-legend h4 {
        font-size: 0.8rem;
        margin-bottom: 4px;
        color: var(--primary);
    }

    .legend-item {
        font-size: 0.75rem;
        margin-bottom: 2px;
        color: #333;
    }

    /* Ajuste en el admin.php de responsividad */
    body {
        padding: 10px !important;
    }

    .admin-container {
        padding: 15px;
    }
}