/* ─────────────────────────────────────────────────────────────────────────
   ZenFlow593 — styles.css  v2.0
   ─────────────────────────────────────────────────────────────────────────*/

/* ═══════════════════════════════════════════════════════════════════════════
   BARRA DE MÓDULOS
   ═══════════════════════════════════════════════════════════════════════════ */

.module-nav-bar {
    position: sticky;
    top: 0;
    z-index: 40;
}

.module-btn {
    color: #64748b;
    border-bottom-color: transparent;
    flex-shrink: 0;
    min-width: 72px;
}
.module-btn:hover {
    color: #1e3a8a;
    background-color: #eff6ff;
}
.module-btn.active-module {
    color: #1d4ed8;
    border-bottom-color: #1d4ed8;
    background-color: #eff6ff;
}

/* En mobile: barra fija en la parte inferior, como app nativa */
@media (max-width: 767px) {
    .module-nav-bar {
        position: fixed;
        bottom: 0;
        top: auto;
        left: 0;
        right: 0;
        z-index: 50;
        border-top: 1px solid #e2e8f0;
        border-bottom: none;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.08);
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }
    .module-nav-bar .max-w-7xl {
        max-width: 100%;
    }
    .module-nav-bar .flex {
        justify-content: space-around;
    }
    .module-btn {
        flex: 1;
        padding: 10px 4px;
        font-size: 10px;
        border-bottom: none;
        border-top: 2px solid transparent;
    }
    .module-btn.active-module {
        border-top-color: #1d4ed8;
        border-bottom: none;
    }
    .module-label {
        display: block;
    }
    /* Evitar que el contenido quede detrás de la barra inferior */
    main.flex-grow {
        padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px)) !important;
    }
}

@media (min-width: 768px) {
    .module-label { display: inline; }
}

.hide-scrollbar { scrollbar-width: none; -ms-overflow-style: none; }
.hide-scrollbar::-webkit-scrollbar { display: none; }

/* Sub-nav de Reportes (pills) */
.subnav-btn {
    background: white;
    color: #475569;
    border-color: #cbd5e1;
}
.subnav-btn:hover { background: #f8fafc; }
.subnav-btn.active-sub {
    background: #1d4ed8;
    color: white;
    border-color: #1d4ed8;
}

/* ═══════════════════════════════════════════════════════════════════════════
   MÓDULO DROPDOWN MENU
   ═══════════════════════════════════════════════════════════════════════════ */

.module-btn {
    color: #475569;
    border-bottom-color: transparent;
    background: transparent;
}
.module-btn:hover { color: #1e3a8a; background: #eff6ff; }
.module-btn.active-module {
    color: #1d4ed8;
    border-bottom-color: #1d4ed8;
}
.module-chevron { display: inline-block; }
.module-btn.active-module .module-chevron,
.module-btn[aria-expanded="true"] .module-chevron {
    transform: rotate(180deg);
}

.module-dropdown {
    position: fixed;
    z-index: 9999;
    min-width: 260px;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.12), 0 2px 8px rgba(0,0,0,0.06);
    padding: 6px;
    animation: dropIn 0.15s ease-out;
}
@keyframes dropIn {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.mdrop-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.12s;
    text-decoration: none;
    color: inherit;
}
.mdrop-item:hover { background: #f1f5f9; }
.mdrop-item.active-item { background: #eff6ff; }

.mdrop-icon {
    width: 36px; height: 36px;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-size: 15px;
    flex-shrink: 0;
}
.mdrop-title {
    font-size: 13px;
    font-weight: 600;
    color: #1e293b;
    line-height: 1.2;
}
.mdrop-desc {
    font-size: 11px;
    color: #94a3b8;
    margin-top: 1px;
}

/* Mobile: dropdowns se convierten en menú de pantalla completa desde abajo */
@media (max-width: 767px) {
    .module-dropdown {
        position: fixed;
        left: 8px !important;
        right: 8px !important;
        bottom: 72px !important;
        top: auto !important;
        min-width: unset;
        width: auto;
        border-radius: 16px;
        padding: 8px;
    }
    .module-btn .module-chevron { display: none; }
}

/* Quitar botón nativo de revelar contraseña */
input[type="password"]::-ms-reveal,
input[type="password"]::-ms-clear { display: none; }
input[type="password"]::-webkit-credentials-auto-fill-button { display: none !important; }

/* Animación de entrada */
.fade-in { animation: fadeIn 0.35s ease-in-out; }
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Scrollbar personalizada (desktop) */
::-webkit-scrollbar        { width: 6px; height: 6px; }
::-webkit-scrollbar-track  { background: #f1f5f9; }
::-webkit-scrollbar-thumb  { background: #cbd5e1; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* Ocultar durante impresión PDF */
@media print {
    .no-print { display: none !important; }
    body { background-color: white !important; }
    .shadow-sm, .shadow-lg, .shadow-xl { box-shadow: none !important; }
}

/* Badges de estado */
.badge-mora  { background-color: #fee2e2; color: #991b1b; }
.badge-aldia { background-color: #dcfce3; color: #166534; }


/* ═══════════════════════════════════════════════════════════════════════════
   TABS — HORIZONTALMENTE DESPLAZABLES
   ═══════════════════════════════════════════════════════════════════════════ */

.tabs-nav {
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
    /* sombra derecha como indicador de scroll */
    background: linear-gradient(to right, white 85%, transparent 100%) local,
                linear-gradient(to right, transparent, rgba(0,0,0,0.06)) scroll;
}
.tabs-nav::-webkit-scrollbar { display: none; }

/* Tabs: no se comprimen nunca */
.admin-tab { flex-shrink: 0 !important; }

/* En mobile: icono siempre visible, texto solo en tablet+ */
.tab-label { display: inline; }

@media (max-width: 767px) {
    .tab-label    { display: none; }
    .admin-tab    { padding: 14px 12px; font-size: 15px; }
    /* El icono ya está en el HTML, así que no necesitamos cambiar nada más */
}


/* ═══════════════════════════════════════════════════════════════════════════
   TOUCH TARGETS MÍNIMOS (iOS / Android)
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    /* iOS hace zoom si font-size < 16px en un input enfocado */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="date"],
    input[type="tel"],
    input[type="search"],
    input[type="file"],
    select,
    textarea {
        font-size: 16px !important;
    }

    /* Touch targets mínimos de 44px */
    button, [role="button"] {
        min-height: 40px;
    }
    select, input[type="text"], input[type="email"],
    input[type="password"], input[type="number"],
    input[type="date"] {
        min-height: 44px;
        padding-top: 10px;
        padding-bottom: 10px;
    }
}


/* ═══════════════════════════════════════════════════════════════════════════
   TABLAS — SCROLL HORIZONTAL EN MOBILE
   ═══════════════════════════════════════════════════════════════════════════ */

.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    /* mín 400px para que la tabla sea usable */
    min-width: 0;
}

/* Filas tocables — feedback visual */
#tbody-admin-mora tr { transition: background-color 0.12s; }
#tbody-admin-mora tr:hover { background-color: #EFF6FF; }
#tbody-admin-mora tr:active { background-color: #DBEAFE; }

/* Reducir padding de celdas en mobile */
@media (max-width: 640px) {
    .tabla-compacta th { padding: 8px 10px !important; font-size: 11px !important; }
    .tabla-compacta td { padding: 8px 10px !important; font-size: 12px !important; }

    /* Tabla de cartera del vendedor */
    #tabla-cartera       { min-width: 520px; }
    /* Tabla de mora admin */
    #tbody-admin-mora tr td,
    #tbody-admin-mora tr th { padding: 10px 12px; font-size: 12px; }
    /* Historial */
    #tbody-admin-mora tr:active { background-color: #BFDBFE; }
    #tbody-admin-historico td { padding: 10px 12px; font-size: 12px; }
    /* Email logs */
    #tbody-email-logs td { padding: 8px 10px; font-size: 12px; }
}


/* ═══════════════════════════════════════════════════════════════════════════
   MODALES — BOTTOM SHEET EN MOBILE
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 639px) {
    /* Bottom sheet genérico: se desliza desde abajo */
    .modal-sheet {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        top: auto !important;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        border-radius: 20px 20px 0 0 !important;
        max-height: 92dvh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        /* Añadimos handle visual */
    }
    .modal-sheet::before {
        content: '';
        display: block;
        width: 36px; height: 4px;
        background: #e2e8f0;
        border-radius: 2px;
        margin: 10px auto 0;
    }

    /* CRM modal: full-screen en mobile (es muy complejo para bottom sheet) */
    .crm-full-mobile {
        position: fixed !important;
        inset: 0 !important;
        border-radius: 0 !important;
        width: 100vw !important;
        max-width: 100vw !important;
        max-height: 100dvh !important;
        margin: 0 !important;
    }

    /* Ocultar el spacer de alineación centrada (no aplica en mobile bottom sheet) */
    .modal-spacer { display: none !important; }
}


/* ═══════════════════════════════════════════════════════════════════════════
   FORMULARIO CRM — ORDEN EN MOBILE
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 767px) {
    /* En mobile el formulario de gestión va PRIMERO (más importante en campo) */
    .crm-col-form    { order: -1; }
    .crm-col-facturas { order: 0; }
    .crm-col-timeline { order: 1; }
}


/* ═══════════════════════════════════════════════════════════════════════════
   DASHBOARD ADMIN — AJUSTES MOBILE
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 640px) {
    /* Header del dashboard más compacto */
    #view-dashboard-admin > div:first-child h1 { font-size: 1.35rem; }

    /* Botones de acción más pequeños */
    #view-dashboard-admin .btn-accion {
        padding: 8px 12px;
        font-size: 12px;
    }

    /* Panel de tareas: columna única forzada */
    #panel-tareas-vendedor .grid-cols-3 { grid-template-columns: 1fr !important; }

    /* Cards de estadísticas admin: padding reducido */
    .stat-card-admin { padding: 16px !important; }

    /* Panel admin: más espacio para mostrar tareas agrupadas por vendedor */
    #panel-tareas-admin { max-height: 320px; }
}


/* ═══════════════════════════════════════════════════════════════════════════
   FILTROS MORA — WRAP EN MOBILE
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 640px) {
    .filtros-wrap {
        flex-wrap: wrap !important;
    }
    .filtros-wrap > * {
        flex: 1 1 calc(50% - 8px);
        min-width: 140px;
    }
    /* Selector de página (pagination) más compacto */
    .pagination-compact button { padding: 6px 10px; font-size: 12px; }
}


/* ═══════════════════════════════════════════════════════════════════════════
   DROPDOWN VENDEDOR/CLIENTE (FILTROS)
   ═══════════════════════════════════════════════════════════════════════════ */

/* Dropdown posicionado via JS con position:fixed */
.mora-dropdown {
    display: flex;
    flex-direction: column;
}
.mora-dropdown.hidden {
    display: none !important;
}

@media (max-width: 640px) {
    /* En mobile: ancho completo y pegado al borde izquierdo */
    .mora-dropdown {
        left: 8px !important;
        right: 8px !important;
        width: auto !important;
    }
}


/* ═══════════════════════════════════════════════════════════════════════════
   NAVBAR — MOBILE
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 640px) {
    /* Reducir padding lateral del main en mobile */
    main.flex-grow { padding: 8px !important; }

    /* Navbar más compacto */
    nav#navbar .h-16 { height: 52px; }
    #nav-user-name { max-width: 100px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
}


/* ═══════════════════════════════════════════════════════════════════════════
   MODAL NUEVA FACTURA — GRID EN MOBILE
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 480px) {
    /* Los campos en grid-cols-2 pasan a 1 columna en móviles muy pequeños */
    #form-nueva-factura .grid.grid-cols-2 {
        grid-template-columns: 1fr !important;
    }
}


/* ═══════════════════════════════════════════════════════════════════════════
   TEXTO EN TABLAS — TRUNCADO EN MOBILE
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 640px) {
    .nombre-cliente-cell {
        max-width: 120px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}


/* ═══════════════════════════════════════════════════════════════════════════
   VENDOR CARTERA — BOTÓN ACCIÓN
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 640px) {
    /* Botón "Registrar Abono" más compacto */
    #tabla-cartera .btn-abono {
        font-size: 12px;
        padding: 6px 10px;
    }
}


/* ═══════════════════════════════════════════════════════════════════════════
   LISTA DE VENDEDORES ADMIN — MOBILE
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 640px) {
    #list-admin-vendedores li {
        padding: 12px;
    }
    #list-admin-vendedores .flex.items-center.gap-2 {
        flex-wrap: wrap;
        gap: 8px;
    }
}


/* ═══════════════════════════════════════════════════════════════════════════
   TIMELINE CRM — MOBILE
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 640px) {
    #crm-timeline-interacciones {
        margin-left: 8px;
    }
    #crm-timeline-interacciones .relative > div:last-child {
        padding-left: 8px;
    }
}


/* ═══════════════════════════════════════════════════════════════════════════
   MODAL CHEQUE — GRID EN MOBILE
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 480px) {
    #crm-cheque-container .grid.grid-cols-2 {
        grid-template-columns: 1fr !important;
    }
}


/* ═══════════════════════════════════════════════════════════════════════════
   PRESENTACIÓN — ya tiene su propio CSS inline
   ═══════════════════════════════════════════════════════════════════════════ */


/* ═══════════════════════════════════════════════════════════════════════════
   FASE 6: OPTIMIZACIONES DE ESPACIADO Y RESPONSIVE
   ═══════════════════════════════════════════════════════════════════════════ */

/* Aumentar ancho máximo en desktop para más espacio */
@media (min-width: 1400px) {
    main.flex-grow {
        max-width: 1400px !important;
        margin: 0 auto !important;
    }
    .max-w-5xl { max-width: 90% !important; }
    .max-w-7xl { max-width: 95% !important; }
}

/* Padding adicional en desktop grande */
@media (min-width: 1200px) {
    main.flex-grow {
        padding-left: 24px !important;
        padding-right: 24px !important;
    }
}

/* Mobile: mejorar espaciado en pequeñas pantallas */
@media (max-width: 480px) {
    main.flex-grow {
        padding: 6px !important;
        padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px)) !important;
    }

    /* Cards y panels más aireados */
    .bg-white.rounded {
        border-radius: 12px;
        margin-bottom: 12px;
    }

    /* Formularios con mejor espacio */
    form > div { margin-bottom: 14px; }
    form > .grid { gap: 12px !important; }

    /* Modales con mejor padding */
    .modal-sheet { padding: 16px !important; }
    .modal-sheet > form { padding: 12px !important; }
}

/* Tablet: balance entre espacio y densidad */
@media (min-width: 768px) and (max-width: 1023px) {
    main.flex-grow { padding: 16px !important; }

    /* Grids más espaciosos */
    .grid-cols-2 { gap: 16px !important; }
    .grid-cols-3 { gap: 16px !important; }
}

/* Estado de Cuenta: optimización de vista */
@media (max-width: 768px) {
    #ec-contenido {
        padding: 12px !important;
    }
    #ec-contenido > .space-y-6 > div {
        margin-bottom: 12px !important;
    }
    .tabla-estado-cuenta { min-width: 480px; }
}

/* Tablas: mejor legibilidad sin truncado excesivo */
@media (min-width: 1024px) {
    .tabla-compacta {
        font-size: 13px;
    }
    .tabla-compacta th,
    .tabla-compacta td {
        padding: 12px !important;
    }
}

/* Dropdowns: ancho apropiado en diferentes pantallas */
@media (min-width: 768px) {
    .mora-dropdown {
        width: 300px !important;
        max-height: 400px;
    }
}

/* Inputs y selects: mejor tamaño de toque */
@media (max-width: 768px) {
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="date"],
    select,
    textarea {
        min-height: 48px;
        padding: 12px !important;
        font-size: 16px;
    }
    button, [role="button"] {
        min-height: 48px;
    }
}
