/* =========================================
   RESPONSIVE MÓVIL — F03-PRSP-02
   Optimizado para smartphones y tablets
   ========================================= */

/* ============================================================
   BARRA INFERIOR MÓVIL
   ============================================================ */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: 64px;
    background: white;
    border-top: 1px solid #e2e8f0;
    z-index: 300;
    box-shadow: 0 -4px 20px rgba(0,0,0,.08);
    padding-bottom: env(safe-area-inset-bottom);
}

.mobile-bottom-nav .mbn-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    flex: 1;
    font-size: 10px;
    font-weight: 600;
    color: #94a3b8;
    text-decoration: none;
    cursor: pointer;
    position: relative;
    padding: 8px 4px;
    transition: color .2s;
    -webkit-tap-highlight-color: transparent;
}

.mobile-bottom-nav .mbn-item i {
    font-size: 20px;
    transition: transform .2s;
}

.mobile-bottom-nav .mbn-item.active {
    color: #1e40af;
}

.mobile-bottom-nav .mbn-item.active i {
    transform: translateY(-2px);
}

.mbn-badge {
    position: absolute;
    top: 4px; right: calc(50% - 18px);
    background: #dc2626;
    color: white;
    font-size: 9px;
    font-weight: 800;
    width: 16px; height: 16px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ============================================================
   MENÚ SLIDE-UP MÓVIL
   ============================================================ */
.mobile-menu-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 400;
    animation: fadeIn .2s ease;
}

.mobile-menu-sheet {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: white;
    border-radius: 24px 24px 0 0;
    z-index: 401;
    padding: 12px 20px 80px;
    max-height: 80vh;
    overflow-y: auto;
    animation: slideUp .3s ease;
    box-shadow: 0 -8px 30px rgba(0,0,0,.15);
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
}

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

.mobile-menu-handle {
    width: 40px; height: 4px;
    background: #e2e8f0;
    border-radius: 4px;
    margin: 0 auto 16px;
}

.mobile-menu-title {
    font-size: 16px;
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.mobile-menu-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.mmg-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 16px 8px;
    border-radius: 16px;
    background: #f8fafc;
    border: 1.5px solid #e2e8f0;
    cursor: pointer;
    text-decoration: none;
    color: #1e293b;
    transition: all .15s;
    -webkit-tap-highlight-color: transparent;
    position: relative;
}

.mmg-item:active { transform: scale(.95); background: #eff6ff; }

.mmg-item i {
    font-size: 24px;
    color: #1e40af;
}

.mmg-item span {
    font-size: 11px;
    font-weight: 600;
    text-align: center;
    line-height: 1.3;
}

.mmg-badge {
    position: absolute;
    top: 8px; right: 8px;
    background: #dc2626;
    color: white;
    font-size: 9px;
    font-weight: 800;
    width: 16px; height: 16px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ============================================================
   PANTALLA MÓVIL < 768px
   ============================================================ */
@media (max-width: 768px) {

    /* Ocultar sidebar en móvil */
    .sidebar {
        transform: translateX(-100%);
        width: 280px !important;
    }
    .sidebar.mobile-open {
        transform: translateX(0);
        box-shadow: 4px 0 30px rgba(0,0,0,.3);
    }

    /* Main sin margen del sidebar */
    .main-content {
        margin-left: 0 !important;
        padding-bottom: 70px; /* espacio barra inferior */
    }

    /* Mostrar botón hamburguesa */
    .btn-icon { display: flex !important; }

    /* Mostrar barra inferior activa */
    .mobile-bottom-nav.nav-visible { display: flex !important; }

    /* Topbar compacto */
    .topbar {
        padding: 0 14px;
        height: 56px;
    }
    .page-title { font-size: 15px; }

    #btnExportarExcel span { display: none; }
    #btnExportarExcel { padding: 8px 10px; }
    #btnIrReportes span { display: none; }
    #btnIrReportes { padding: 8px 10px; }
    .hide-xs { display: none !important; }

    /* Ocultar campana en móvil (se ve en menú) */
    .alert-bell { display: none !important; }

    /* View container */
    .view-container { padding: 14px 12px; }

    /* Stats grid: 2 columnas en móvil */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px;
    }

    .stat-card { padding: 14px 12px; gap: 10px; }
    .stat-icon { width: 40px; height: 40px; font-size: 18px; border-radius: 10px; }
    .stat-number { font-size: 22px; }
    .stat-label { font-size: 11px; }

    /* Dashboard grid: 1 columna */
    .dashboard-grid {
        grid-template-columns: 1fr !important;
    }

    /* Cards */
    .card-header {
        padding: 12px 14px;
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    .card-header h3 { font-size: 14px; }
    .card-actions { width: 100%; flex-wrap: wrap; }
    .card-body { padding: 14px; }

    /* Tablas: scroll horizontal */
    .table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .data-table { min-width: 600px; }
    .data-table thead th { font-size: 10px; padding: 8px 10px; }
    .data-table tbody td { padding: 10px; font-size: 12px; }

    /* Ocultar columnas no esenciales en tablas de historial/unidades */
    .col-hide-mobile { display: none !important; }

    /* Formularios */
    .form-grid {
        grid-template-columns: 1fr !important;
        gap: 12px;
    }
    .form-full { grid-column: 1 !important; }

    input[type="text"],
    input[type="date"],
    input[type="time"],
    input[type="number"],
    select, textarea {
        font-size: 16px !important; /* evita zoom en iOS */
        padding: 11px 12px;
    }

    /* Botones más grandes para táctil */
    .btn { padding: 10px 14px; font-size: 13px; }
    .btn-sm { padding: 8px 12px; font-size: 12px; }

    /* CHECKLIST — ítems táctiles */
    .checklist-item-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
        padding: 14px 12px;
    }

    .radio-group { width: 100%; justify-content: space-between; gap: 8px; }

    .radio-btn {
        width: 100%;
        height: 40px;
        font-size: 13px;
        border-radius: 8px;
        flex: 1;
    }

    .checklist-items-grid {
        grid-template-columns: 1fr !important;
    }

    /* Modal fullscreen en móvil */
    .modal-overlay { padding: 0; align-items: flex-end; }
    .modal {
        max-width: 100% !important;
        border-radius: 24px 24px 0 0;
        max-height: 92vh;
    }

    /* Filtros en columna */
    .filtros-historial,
    .filtros-servicios {
        flex-direction: column;
        gap: 10px;
    }
    .filtros-historial .form-group,
    .filtros-servicios .form-group { width: 100%; min-width: unset; }

    .filtros-historial .btn,
    .filtros-servicios .btn { width: 100%; justify-content: center; }

    /* Unidades grid */
    .unidades-grid {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 8px;
    }
    .unidad-card { padding: 10px 6px; }
    .unidad-num { font-size: 13px; }
    .unidad-repartidor { font-size: 10px; }
    .unidad-status { font-size: 9px; padding: 1px 6px; }

    /* Aprobaciones */
    .aprobacion-header { flex-direction: column; }
    .aprobacion-meta { gap: 8px; }

    /* Alertas taller */
    .atcard-title { flex-direction: column; align-items: flex-start; gap: 4px; }
    .atcard-actions { flex-wrap: wrap; }

    /* Detalle unidad */
    .detalle-unidad-header { flex-direction: column; gap: 12px; }
    .du-info { flex-direction: column; align-items: flex-start; }
    .du-acciones { width: 100%; }
    .du-acciones .btn { flex: 1; justify-content: center; }

    /* Login card */
    .login-card { padding: 28px 20px; border-radius: 20px; }
    .login-logo h1 { font-size: 17px; }
    .login-tab { font-size: 11px; padding: 9px 6px; }

    /* Conductor banner */
    .conductor-banner { padding: 10px 14px; }
    .conductor-banner span { font-size: 15px; }

    /* Toast centrado abajo */
    .toast {
        bottom: 80px;
        right: 12px;
        left: 12px;
        text-align: center;
        max-width: unset;
    }

    /* Modal footer en columna */
    .modal-footer { flex-direction: column; gap: 8px; }
    .modal-footer .btn { width: 100%; justify-content: center; }
    .modal-footer .form-group { width: 100%; }

    /* Import zone */
    .import-zone { padding: 32px 16px; }
    .import-icon { font-size: 40px; }

    /* Charts con altura fija */
    #chartEstadoHoy { max-height: 220px; }
    #chartSemana    { max-height: 200px; }
}

/* ============================================================
   TABLET < 1024px
   ============================================================ */
@media (max-width: 1024px) and (min-width: 769px) {

    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .dashboard-grid { grid-template-columns: 1fr; }

    .sidebar { width: 220px; }
    .main-content { margin-left: 220px; }

    .form-grid { grid-template-columns: repeat(2, 1fr); }

    .unidades-grid { grid-template-columns: repeat(4, 1fr) !important; }

    /* Modal no fullscreen en tablet */
    .modal-overlay { padding: 20px; align-items: center; }
    .modal { border-radius: 16px; }
}

/* ============================================================
   PANTALLAS MUY PEQUEÑAS < 380px
   ============================================================ */
@media (max-width: 380px) {
    .unidades-grid { grid-template-columns: repeat(2, 1fr) !important; }
    .stats-grid { grid-template-columns: 1fr 1fr !important; }
    .stat-number { font-size: 20px; }
    .login-tabs { flex-direction: column; }
    .login-tab { border-radius: 8px; }
    .mobile-menu-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ============================================================
   SAFE AREA (iPhone X+)
   ============================================================ */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .mobile-bottom-nav {
        padding-bottom: env(safe-area-inset-bottom);
        height: calc(64px + env(safe-area-inset-bottom));
    }
    @media (max-width: 768px) {
        .main-content {
            padding-bottom: calc(70px + env(safe-area-inset-bottom));
        }
    }
}

/* ============================================================
   REPORTES Y BACKUP RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
    .reportes-grid { grid-template-columns: 1fr; }
    .backup-grid { grid-template-columns: 1fr; }
    .backup-checks { grid-template-columns: 1fr 1fr; }
    .reporte-card { flex-direction: column; text-align: center; padding: 14px; }
    .reporte-badge { position: static; margin-top: 6px; }
    .modal-tab { font-size: 10px; padding: 7px 4px; }
    .modal-tab i { display: none; }
}
@media (max-width: 480px) {
    .reportes-grid { grid-template-columns: 1fr; }
    .backup-checks { grid-template-columns: 1fr; }
}

/* ============================================================
   MEJORAS ADICIONALES PARA EXPERIENCIA MÓVIL
   ============================================================ */

/* Activo visual con borde superior */
.mobile-bottom-nav .mbn-item.active::before {
    content: '';
    position: absolute;
    top: 0; left: 20%; right: 20%;
    height: 3px;
    background: #1e40af;
    border-radius: 0 0 3px 3px;
}

/* Animación de tap */
.mobile-bottom-nav .mbn-item:active {
    transform: scale(.92);
}

/* Scroll suave en vistas */
.view-container {
    scroll-behavior: smooth;
}

/* Impedir que los checkboxes de radio sean demasiado pequeños en móvil */
@media (max-width: 768px) {
    .radio-btn input[type="radio"] {
        width: 18px;
        height: 18px;
    }

    /* Íconos de acción más grandes */
    .btn-sm i { font-size: 14px; }

    /* Scrollbar delgado en webkit */
    ::-webkit-scrollbar { width: 4px; height: 4px; }
    ::-webkit-scrollbar-track { background: transparent; }
    ::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }

    /* Select nativos más legibles */
    select {
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2364748b' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 12px center;
        appearance: none;
        -webkit-appearance: none;
    }

    /* Toast más prominente */
    .toast {
        font-size: 14px;
        padding: 14px 18px;
    }

    /* Conductor banner más compacto */
    .conductor-banner > i { display: none; }
}
