/* ========================================================================== */
/* MAPA UBICACIONES PAGE - Página de Mapa de Ubicaciones                    */
/* ========================================================================== */

/* Eliminar padding del main-content para esta página */
.main-content:has(.mapa-ubicaciones-page) {
    padding: 0 !important;
}

.mapa-ubicaciones-page {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 95px);
    width: 100%;
    padding: 0;
    overflow: hidden;
    background: var(--bg-primary);
}

.mapa-ubicaciones-page .camara-panel {
    margin: 0;
    padding: 0.75rem;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.mapa-ubicaciones-page .camara-header {
    margin: 0 0 0.5rem 0;
    padding: 0.25rem 0.5rem;
    flex-shrink: 0;
}

.mapa-ubicaciones-page .camara-body {
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 0.75rem;
    flex: 1;
    min-height: 0;
}

/* Grid de Conductores - 3 columnas */
.conductores-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    width: 100%;
    padding: 0.5rem;
}

/* Card de Conductor */
.conductor-card {
    background: var(--card-bg);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.3s ease;
    display: flex;
    flex-direction: column;
    height: 420px;
    min-height: 420px;
    max-height: 420px;
    isolation: isolate; /* Crear contexto de stacking aislado */
    position: relative;
}

.conductor-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Card Inactivo */
.conductor-card.conductor-inactivo {
    opacity: 0.6;
}

.conductor-card.conductor-inactivo:hover {
    transform: none;
    opacity: 0.7;
}

/* Card Header con gradiente */
.conductor-card-header {
    background: var(--primary-gradient);
    padding: 1rem 1rem 0.75rem 1rem; /* Más padding arriba */
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    font-weight: 600;
    color: white;
    flex: 0 0 80px; /* No crece, no se encoge, base de 80px */
    height: 80px;
    min-height: 80px;
    max-height: 80px;
    box-sizing: border-box;
    overflow: visible;
    position: relative;
    z-index: 10; /* Asegurar que esté encima del mapa */
}

.conductor-header-content {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.conductor-info {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    min-width: 0; /* Permite que los hijos se encojan si es necesario */
    flex-wrap: nowrap;
    overflow: hidden;
}

/* Badge de estado inline con el nombre */
.conductor-info .estado-badge {
    flex-shrink: 0;
    margin-left: auto;
}

.conductor-codigo {
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.conductor-separator {
    font-size: 0.9rem;
    opacity: 0.8;
}

.conductor-nombre {
    font-size: 0.9rem;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex-shrink: 1; /* Permite que se encoja si es necesario */
    min-width: 0;
}

/* conductor-estado removido - badge ahora está en conductor-info */

/* Badge de estado */
.estado-badge {
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}

.estado-badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    display: inline-block;
}

.estado-activo {
    background: rgba(76, 175, 80, 0.9);
    color: #ffffff;
    border: 1px solid rgba(76, 175, 80, 1);
    box-shadow: 0 2px 8px rgba(76, 175, 80, 0.3);
}

.estado-activo::before {
    background: #ffffff;
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.8);
    animation: pulse-dot 2s infinite;
}

.estado-inactivo {
    background: rgba(120, 120, 120, 0.9);
    color: #ffffff;
    border: 1px solid rgba(100, 100, 100, 1);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.estado-inactivo::before {
    background: #ffffff;
    opacity: 0.7;
}

@keyframes pulse-dot {
    0%, 100% {
        box-shadow: 0 0 8px rgba(76, 175, 80, 0.6);
    }
    50% {
        box-shadow: 0 0 16px rgba(76, 175, 80, 0.8);
    }
}

/* Estadísticas del Conductor */
.conductor-stats {
    display: flex;
    flex-wrap: nowrap;
    gap: 0.5rem;
    font-size: 0.7rem;
    font-weight: 700;
    color: #ffffff;
}

.stat-item {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    background: rgba(255, 255, 255, 0.1);
    padding: 0.2rem 0.4rem;
    border-radius: 5px;
    backdrop-filter: blur(5px);
    color: #ffffff;
    font-weight: 600;
    white-space: nowrap;
}

.mapa-stat-icon {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    padding: 3px;
    background: linear-gradient(135deg, #F07400, #00b4ff);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    fill: white;
}

.stat-last-update {
    font-style: italic;
}

/* Card Body - Contenedor del Mapa */
.conductor-card-body {
    flex: 1 1 auto;
    position: relative;
    overflow: hidden;
    min-height: 0;
    height: calc(420px - 80px); /* Altura del card menos header */
    touch-action: none; /* Dejar que Leaflet maneje todos los gestos táctiles */
    z-index: 1;
}

.mapa-container {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

/* Asegurar que los contenedores de Leaflet no afecten el layout del card */
.conductor-card .leaflet-container {
    position: absolute !important;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
}

/* Evitar que los grabbers de Leaflet se expandan fuera del área del mapa */
.conductor-card .leaflet-grab,
.conductor-card .leaflet-dragging {
    cursor: grab;
}

.conductor-card .leaflet-dragging .leaflet-grab {
    cursor: grabbing;
}

/* Overlay para conductores inactivos */
.mapa-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(30, 30, 30, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(8px);
}

.mapa-overlay span {
    color: rgba(255, 255, 255, 0.8);
    font-size: 1rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Filtros para mejorar legibilidad del texto en tiles del mapa */
.leaflet-tile-dark {
    filter: brightness(1.3) contrast(1.1);
}

.leaflet-tile-light {
    filter: none;
}

/* Modal para mapa expandido */
.mapa-modal-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

.mapa-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(5px);
}

.mapa-modal-content {
    position: relative;
    width: 80vw;
    height: 80vh;
    display: flex;
    flex-direction: column;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    animation: scaleIn 0.3s ease;
    z-index: 1;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes scaleIn {
    from {
        transform: scale(0.95);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.mapa-modal-header {
    background: var(--primary-gradient);
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: white;
    flex-shrink: 0;
}

.mapa-modal-title {
    font-size: 1.1rem;
    font-weight: 600;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.mapa-modal-subtitle {
    font-size: 0.85rem;
    opacity: 0.9;
    font-weight: 400;
}

.mapa-modal-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    padding: 0;
}

.mapa-modal-close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(90deg) scale(1.1);
}

.mapa-modal-body {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: var(--bg-primary);
}

.mapa-modal-body .mapa-container {
    width: 100%;
    height: 100%;
}

/* Cursor pointer en mapas para indicar que son clickeables */
.conductor-card-body {
    cursor: pointer;
}

.conductor-card-body:hover {
    opacity: 0.95;
}

/* Variables de tema para cards */
:root {
    --card-bg: #1a1a1a;
}

.light-mode {
    --card-bg: #ffffff;
}

/* ========================================================================== */
/* RESPONSIVE                                                                 */
/* ========================================================================== */

/* Tablet y pantallas medianas - 2 columnas */
@media (max-width: 1200px) {
    .conductores-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Tablet pequeña - 2 columnas */
@media (max-width: 768px) {
    .mapa-ubicaciones-page {
        height: calc(100vh - 95px);
        min-height: calc(100vh - 95px);
        max-height: calc(100vh - 95px);
        overflow: hidden;
    }

    .mapa-ubicaciones-page .camara-panel {
        display: flex;
        flex-direction: column;
        height: 100%;
        overflow: hidden;
        padding: 0.5rem;
    }

    .mapa-ubicaciones-page .camara-header {
        flex-shrink: 0;
    }

    .mapa-ubicaciones-page .camara-body {
        flex: 1;
        overflow-y: auto !important;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        min-height: 0;
        padding: 0.5rem;
    }

    .conductores-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
        padding: 0.25rem;
    }

    .conductor-card {
        height: 380px;
        min-height: 380px;
        max-height: 380px;
    }

    .conductor-card-header {
        padding: 0.85rem 0.8rem 0.6rem 0.8rem;
        flex: 0 0 75px;
        height: 75px;
        min-height: 75px;
        max-height: 75px;
    }

    .conductor-card-body {
        height: calc(380px - 75px);
    }

    .conductor-codigo {
        font-size: 0.85rem;
    }

    .conductor-nombre {
        font-size: 0.8rem;
    }

    .conductor-stats {
        font-size: 0.65rem;
        gap: 0.4rem;
    }

    .stat-item {
        padding: 0.15rem 0.35rem;
    }

    .mapa-stat-icon {
        width: 16px;
        height: 16px;
        padding: 2px;
        border-radius: 3px;
    }

    .estado-badge {
        font-size: 0.6rem;
        padding: 0.1rem 0.4rem;
    }
}

/* Móvil - 1 columna */
@media (max-width: 480px) {
    .mapa-ubicaciones-page {
        height: calc(100vh - 95px);
        min-height: calc(100vh - 95px);
        max-height: calc(100vh - 95px);
        overflow: hidden;
    }

    .mapa-ubicaciones-page .camara-panel {
        display: flex;
        flex-direction: column;
        height: 100%;
        overflow: hidden;
        padding: 0.5rem;
    }

    .mapa-ubicaciones-page .camara-header {
        flex-shrink: 0;
    }

    .mapa-ubicaciones-page .camara-body {
        flex: 1;
        overflow-y: auto !important;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        min-height: 0;
        padding: 0.5rem;
    }

    .conductores-grid {
        grid-template-columns: 1fr;
        gap: 0.75rem;
        padding: 0.25rem;
    }

    .conductor-card {
        height: 350px;
        min-height: 350px;
        max-height: 350px;
    }

    .conductor-card-header {
        padding: 0.75rem 0.75rem 0.5rem 0.75rem;
        flex: 0 0 70px;
        height: 70px;
        min-height: 70px;
        max-height: 70px;
    }

    .conductor-card-body {
        height: calc(350px - 70px);
    }

    .conductor-codigo {
        font-size: 0.8rem;
    }

    .conductor-nombre {
        font-size: 0.75rem;
    }

    .conductor-stats {
        font-size: 0.6rem;
        gap: 0.3rem;
        flex-wrap: wrap;
    }

    .stat-item {
        padding: 0.1rem 0.3rem;
    }

    .mapa-stat-icon {
        width: 14px;
        height: 14px;
        padding: 2px;
        border-radius: 3px;
    }

    .estado-badge {
        font-size: 0.55rem;
        padding: 0.1rem 0.35rem;
    }

    .estado-badge::before {
        width: 5px;
        height: 5px;
    }
}

/* ========================================================================== */
/* MENSAJE SIN CONDUCTORES                                                     */
/* ========================================================================== */

.no-conductores-message {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 300px;
    color: var(--text-secondary);
    font-size: 1.1rem;
    text-align: center;
    padding: 2rem;
}

.no-conductores-message p {
    background: var(--card-bg);
    padding: 2rem 3rem;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
