/* ==========================================================================
   PIPASALPE ERP - HOJA DE ESTILOS CENTRAL Y MOTOR RESPONSIVO (styles.css)
   Fase 18.2 (Iconos SVG, Acordeones Desplegables, Menú Purga + Anti-zoom iPad)
   Architecture By AV Abraham Villagomez
   ========================================================================== */

body {
    font-family: 'Inter', sans-serif;
    -webkit-tap-highlight-color: transparent;
}

/* Corrige recorte de barra de direcciones en Android Chrome / iPadOS / iOS */
body.h-screen {
    height: 100vh;
    height: 100dvh;
}

/* Garantiza que el dashboard no rompa la altura del contenedor flex */
#dashboard-screen:not(.hidden) {
    min-height: 0;
}

/* Evita que el botón de Cerrar Sesión sea empujado fuera en pantallas horizontales cortas */
#main-sidebar > div:first-child {
    flex: 1 1 0%;
    min-height: 0;
}

/* ==========================================================================
   ICONOS VECTORIALES SVG MONOCROMÁTICOS (HEREDAN COLOR Y TAMAÑO DEL TEXTO)
   ========================================================================== */
.erp-icon {
    display: inline-block;
    width: 1.05em;
    height: 1.05em;
    vertical-align: -0.18em;
    flex-shrink: 0;
}

[data-icon] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* ==========================================================================
   ACORDEONES DESPLEGABLES EJECUTIVOS (<details class="erp-accordion">)
   ========================================================================== */
details.erp-accordion {
    background-color: #1e293b;
    border: 1px solid #334155;
    border-radius: 0.75rem;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.25);
    overflow: hidden;
}

details.erp-accordion > summary {
    list-style: none;
    cursor: pointer;
    padding: 1rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    user-select: none;
    background-color: rgba(15, 23, 42, 0.35);
    transition: background-color 0.15s ease;
}

details.erp-accordion > summary::-webkit-details-marker {
    display: none;
}

details.erp-accordion > summary:hover {
    background-color: rgba(15, 23, 42, 0.65);
}

details.erp-accordion[open] > summary {
    border-bottom: 1px solid #334155;
    background-color: rgba(15, 23, 42, 0.55);
}

details.erp-accordion > summary::after {
    content: "";
    width: 0.5rem;
    height: 0.5rem;
    border-right: 2px solid #94a3b8;
    border-bottom: 2px solid #94a3b8;
    transform: rotate(45deg);
    transition: transform 0.2s ease, border-color 0.2s ease;
    flex-shrink: 0;
    margin-right: 0.25rem;
}

details.erp-accordion[open] > summary::after {
    transform: rotate(-135deg);
    border-color: #e2e8f0;
}

.erp-accordion-body {
    padding: 1.25rem;
}

/* ==========================================================================
   MENÚ DESPLEGABLE DISCRETO DE MANTENIMIENTO / PURGA (ADMIN)
   ========================================================================== */
details.erp-danger-menu {
    position: relative;
}

details.erp-danger-menu > summary {
    list-style: none;
    cursor: pointer;
    user-select: none;
}

details.erp-danger-menu > summary::-webkit-details-marker {
    display: none;
}

.erp-danger-popover {
    position: absolute;
    right: 0;
    top: calc(100% + 0.5rem);
    width: 20rem;
    max-width: calc(100vw - 2rem);
    background-color: #0f172a;
    border: 1px solid rgba(225, 29, 72, 0.55);
    border-radius: 0.75rem;
    padding: 1rem;
    box-shadow: 0 20px 35px rgba(0, 0, 0, 0.75);
    z-index: 30;
}

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: #0f172a;
}

::-webkit-scrollbar-thumb {
    background: #334155;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #475569;
}

.view-section,
.rep-tab-panel {
    animation: fadeInView 0.16s ease-out;
}

@keyframes fadeInView {
    from {
        opacity: 0;
        transform: translateY(3px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.overflow-x-auto {
    -webkit-overflow-scrolling: touch;
}

.backdrop-blur-xs {
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}

/* ==========================================================================
   ANTI-ZOOM FORZADO EN IPAD / IPHONE (WebKit exige >= 16px en campos táctiles)
   ========================================================================== */
@media (pointer: coarse), (max-width: 1024px) {
    input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
    select,
    textarea {
        font-size: 16px !important;
    }
}

/* ==========================================================================
   PANTALLA DE CHOFER (?entrega=...) Y LOGIN: ENCUADRE + SCROLL TÁCTIL SEGURO
   ========================================================================== */
#driver-screen:not(.hidden),
#login-screen:not(.hidden) {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    flex: 1 1 0%;
    min-height: 0;
    width: 100%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    touch-action: pan-y;
}

#driver-screen:not(.hidden) {
    padding: 0.75rem 0.75rem calc(2.25rem + env(safe-area-inset-bottom, 0px));
}

#login-screen:not(.hidden) {
    padding: 1rem 1rem calc(1.75rem + env(safe-area-inset-bottom, 0px));
}

/* Centrado vertical seguro sin recortar inicio/fin cuando excede la pantalla */
#driver-screen:not(.hidden) > div,
#login-screen:not(.hidden) > div {
    margin-top: auto;
    margin-bottom: auto;
    flex-shrink: 0;
}

/* Compactación vertical de la Hoja de Ruta Digital para caber en 1 pantalla móvil */
#driver-screen:not(.hidden) > div {
    padding: 1rem;
}

#driver-screen .space-y-5 > :not([hidden]) ~ :not([hidden]) {
    margin-top: 0.75rem;
}

#driver-screen .space-y-4 > :not([hidden]) ~ :not([hidden]) {
    margin-top: 0.625rem;
}

#driver-screen .pb-4 {
    padding-bottom: 0.6rem;
}

#driver-screen .p-4 {
    padding: 0.75rem;
}

#driver-screen h1 {
    font-size: 1.35rem;
    line-height: 1.75rem;
    margin-top: 0.25rem;
}

#btn-drv-submit {
    padding-top: 0.85rem;
    padding-bottom: 0.85rem;
}

/* Aislamiento de z-index para contenedores de mapas Leaflet dentro de modales */
.mapa-erp-wrapper {
    position: relative;
    z-index: 10;
    isolation: isolate;
    background-color: #0f172a;
}

.leaflet-container {
    font-family: 'Inter', sans-serif !important;
    background: #0f172a;
}

.leaflet-control-attribution {
    font-size: 9px !important;
    background: rgba(15, 23, 42, 0.78) !important;
    color: #94a3b8 !important;
}

.leaflet-control-attribution a {
    color: #38bdf8 !important;
}

/* Sub-pestañas de Reportes y Utilidad */
.rep-tab-btn {
    color: #94a3b8;
    background-color: transparent;
    border: 1px solid transparent;
}

.rep-tab-btn:hover {
    color: #ffffff;
    background-color: #1e293b;
}

.rep-tab-btn.active-rep-tab {
    color: #ffffff;
    background-color: #2563eb;
    border-color: #3b82f6;
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
}

/* Inputs compactos dentro de la Matriz de Nómina y Costos */
.input-matriz {
    background-color: #0f172a;
    border: 1px solid #334155;
    border-radius: 0.375rem;
    padding: 0.35rem 0.5rem;
    color: #ffffff;
    font-weight: 600;
    width: 115px;
    transition: border-color 0.15s ease;
}

.input-matriz:focus {
    outline: none;
    border-color: #3b82f6;
}

/* ==========================================================================
   MODO MÓVIL EN TELÉFONOS (< 768px) — SIN COLISIÓN CON IPAD VERTICAL (768px)
   ========================================================================== */
@media (max-width: 767px) {
    body:not(.modo-escritorio-forzado) #main-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 50;
        height: 100vh;
        height: 100dvh;
        box-shadow: 10px 0 30px rgba(0, 0, 0, 0.75);
    }

    body:not(.modo-escritorio-forzado) #main-content-padding {
        padding: 1rem !important;
    }

    body:not(.modo-escritorio-forzado) header {
        padding: 0.75rem 1rem !important;
    }

    body:not(.modo-escritorio-forzado) input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
    body:not(.modo-escritorio-forzado) select,
    body:not(.modo-escritorio-forzado) button[type="submit"] {
        min-height: 44px;
    }
}

body.modo-movil-forzado #dashboard-screen {
    max-width: 480px;
    margin: 0 auto;
    border-left: 1px solid #1e293b;
    border-right: 1px solid #1e293b;
    position: relative;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.85);
}

body.modo-movil-forzado #main-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 50;
    height: 100vh;
    height: 100dvh;
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.85);
}

body.modo-movil-forzado #sidebar-backdrop:not(.hidden) {
    display: block !important;
}

body.modo-movil-forzado #main-content-padding {
    padding: 0.85rem !important;
}

body.modo-movil-forzado header {
    padding: 0.75rem 0.85rem !important;
}

body.modo-movil-forzado .grid {
    grid-template-columns: repeat(1, minmax(0, 1fr)) !important;
}

body.modo-movil-forzado .kpi-grid-movil {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
}

body.modo-movil-forzado input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
body.modo-movil-forzado select,
body.modo-movil-forzado button[type="submit"] {
    min-height: 44px;
    font-size: 16px !important;
}

/* ==========================================================================
   MODO ESCRITORIO FORZADO EN DISPOSITIVOS MÓVILES
   ========================================================================== */
body.modo-escritorio-forzado #dashboard-screen {
    min-width: 1180px;
    overflow-x: auto;
}