/* ============================================
   PARIDAD MÓVIL = PC - IAFiscal PWA v2.0
   Todas las funcionalidades disponibles en móvil
   ============================================ */

/* ========== VARIABLES CSS ========== */
:root {
    --mobile-spacing: 12px;
    --touch-target-min: 44px;
    --mobile-font-base: 16px;
    --header-height-mobile: 60px;
    --bottom-nav-height: 65px;
    --sidebar-width: 280px;
    --primary-color: #4f46e5;
    --secondary-color: #7c3aed;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --dark-bg: #1a1a2e;
    --card-bg: #16213e;
}

/* ========== PWA INSTALL BANNER ========== */
.pwa-install-banner {
    display: none;
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    padding: 15px 25px;
    border-radius: 15px;
    box-shadow: 0 10px 40px rgba(79, 70, 229, 0.4);
    z-index: 9999;
    animation: slideUp 0.5s ease;
    max-width: calc(100vw - 40px);
}

.pwa-install-banner.show {
    display: flex;
    align-items: center;
    gap: 15px;
}

@keyframes slideUp {
    from { transform: translateX(-50%) translateY(100px); opacity: 0; }
    to { transform: translateX(-50%) translateY(0); opacity: 1; }
}

/* ========== MÓVIL BASE (hasta 768px) ========== */
@media (max-width: 768px) {
    /* Reset y base */
    * {
        -webkit-tap-highlight-color: transparent;
    }

    html {
        font-size: var(--mobile-font-base);
        scroll-behavior: smooth;
        -webkit-text-size-adjust: 100%;
    }

    body {
        padding-bottom: var(--bottom-nav-height);
        overflow-x: hidden;
    }

    /* ========== LAYOUT PRINCIPAL ========== */
    .container-fluid {
        padding: var(--mobile-spacing) !important;
    }

    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
        padding-top: var(--header-height-mobile);
    }

    /* ========== HEADER MÓVIL FIJO ========== */
    .mobile-header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: var(--header-height-mobile);
        background: var(--dark-bg);
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0 var(--mobile-spacing);
        z-index: 1000;
        box-shadow: 0 2px 15px rgba(0,0,0,0.3);
    }

    .mobile-header .logo {
        font-size: 1.2rem;
        font-weight: bold;
        color: white;
    }

    .mobile-header-actions {
        display: flex;
        gap: 10px;
    }

    /* ========== SIDEBAR MÓVIL (DRAWER) ========== */
    .sidebar {
        position: fixed !important;
        top: 0;
        left: -100%;
        width: var(--sidebar-width);
        height: 100vh;
        background: var(--dark-bg);
        z-index: 1050;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        overflow-y: auto;
        padding-top: 20px;
    }

    .sidebar.open {
        left: 0;
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.6);
        z-index: 1040;
        backdrop-filter: blur(3px);
    }

    .sidebar-overlay.show {
        display: block;
    }

    /* Botón menú hamburguesa */
    .menu-toggle {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: var(--touch-target-min);
        height: var(--touch-target-min);
        background: transparent;
        border: none;
        color: white;
        font-size: 24px;
        cursor: pointer;
    }

    /* ========== NAVEGACIÓN INFERIOR (BOTTOM NAV) ========== */
    .bottom-nav {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: var(--bottom-nav-height);
        background: var(--dark-bg);
        display: flex;
        justify-content: space-around;
        align-items: center;
        z-index: 1000;
        box-shadow: 0 -2px 15px rgba(0,0,0,0.3);
        padding-bottom: env(safe-area-inset-bottom, 0);
    }

    .bottom-nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        flex: 1;
        height: 100%;
        color: #a0aec0;
        text-decoration: none;
        font-size: 10px;
        transition: color 0.2s;
        padding: 5px;
    }

    .bottom-nav-item i {
        font-size: 22px;
        margin-bottom: 3px;
    }

    .bottom-nav-item.active,
    .bottom-nav-item:hover {
        color: var(--primary-color);
    }

    .bottom-nav-item .badge {
        position: absolute;
        top: 5px;
        right: 50%;
        transform: translateX(15px);
        min-width: 18px;
        height: 18px;
        font-size: 10px;
        background: var(--danger-color);
    }

    /* ========== TIPOGRAFÍA RESPONSIVE ========== */
    h1, .h1 { font-size: 1.75rem !important; }
    h2, .h2 { font-size: 1.5rem !important; }
    h3, .h3 { font-size: 1.25rem !important; }
    h4, .h4 { font-size: 1.1rem !important; }

    .page-title {
        font-size: 1.4rem;
        margin-bottom: 15px;
    }

    /* ========== CARDS OPTIMIZADAS ========== */
    .card {
        margin-bottom: var(--mobile-spacing);
        border-radius: 12px;
        overflow: hidden;
    }

    .card-header {
        padding: 12px 15px;
        font-size: 0.95rem;
    }

    .card-body {
        padding: 15px;
    }

    /* Stats cards horizontales */
    .stat-card {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 15px;
    }

    .stat-card .stat-icon {
        width: 45px;
        height: 45px;
        border-radius: 10px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 20px;
    }

    .stat-card .stat-value {
        font-size: 1.4rem;
        font-weight: bold;
    }

    .stat-card .stat-label {
        font-size: 0.8rem;
        color: #a0aec0;
    }

    /* ========== FORMULARIOS TÁCTILES ========== */
    input, select, textarea, .form-control {
        font-size: 16px !important; /* Previene zoom en iOS */
        min-height: var(--touch-target-min);
        padding: 12px 15px;
        border-radius: 10px;
    }

    .form-label {
        font-size: 0.9rem;
        margin-bottom: 6px;
    }

    .form-group, .mb-3 {
        margin-bottom: 15px;
    }

    /* Select estilizado para móvil */
    select.form-control {
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 15px center;
        padding-right: 40px;
    }

    /* ========== BOTONES TÁCTILES ========== */
    .btn {
        min-height: var(--touch-target-min);
        padding: 12px 20px;
        font-size: 15px;
        border-radius: 10px;
        font-weight: 500;
    }

    .btn-sm {
        min-height: 36px;
        padding: 8px 14px;
        font-size: 13px;
    }

    .btn-lg {
        min-height: 52px;
        padding: 14px 28px;
        font-size: 17px;
    }

    /* Botón flotante de acción (FAB) */
    .fab {
        position: fixed;
        bottom: calc(var(--bottom-nav-height) + 20px);
        right: 20px;
        width: 56px;
        height: 56px;
        border-radius: 50%;
        background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
        color: white;
        border: none;
        font-size: 24px;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 4px 20px rgba(79, 70, 229, 0.4);
        z-index: 100;
        transition: transform 0.2s;
    }

    .fab:active {
        transform: scale(0.95);
    }

    /* Grupo de botones apilado */
    .btn-group-mobile {
        display: flex;
        flex-direction: column;
        gap: 10px;
    }

    .btn-group-mobile .btn {
        width: 100%;
    }

    /* ========== TABLAS RESPONSIVE ========== */
    .table-responsive {
        margin: 0 calc(-1 * var(--mobile-spacing));
        padding: 0 var(--mobile-spacing);
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table {
        min-width: 600px;
    }

    th, td {
        padding: 12px 10px;
        font-size: 0.85rem;
        white-space: nowrap;
    }

    /* Tabla cards en móvil */
    .table-cards-mobile {
        display: block;
    }

    .table-cards-mobile thead {
        display: none;
    }

    .table-cards-mobile tbody tr {
        display: block;
        background: var(--card-bg);
        border-radius: 10px;
        margin-bottom: 10px;
        padding: 15px;
    }

    .table-cards-mobile td {
        display: flex;
        justify-content: space-between;
        padding: 8px 0;
        border-bottom: 1px solid rgba(255,255,255,0.1);
    }

    .table-cards-mobile td:last-child {
        border-bottom: none;
    }

    .table-cards-mobile td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #a0aec0;
    }

    /* ========== MODALES MÓVIL ========== */
    .modal-dialog {
        margin: 0;
        max-width: 100%;
        height: 100%;
    }

    .modal-content {
        height: 100%;
        border-radius: 0;
        border: none;
    }

    .modal-header {
        padding: 15px;
        position: sticky;
        top: 0;
        z-index: 10;
    }

    .modal-body {
        padding: 15px;
        overflow-y: auto;
    }

    .modal-footer {
        padding: 15px;
        position: sticky;
        bottom: 0;
        z-index: 10;
    }

    /* Modal media pantalla */
    .modal-half {
        height: auto;
        margin-top: auto;
    }

    .modal-half .modal-dialog {
        height: auto;
        margin: 0;
    }

    .modal-half .modal-content {
        height: auto;
        border-radius: 20px 20px 0 0;
        max-height: 85vh;
    }

    /* ========== LISTAS SWIPEABLES ========== */
    .swipeable-list {
        list-style: none;
        padding: 0;
        margin: 0;
    }

    .swipeable-item {
        background: var(--card-bg);
        border-radius: 10px;
        margin-bottom: 10px;
        overflow: hidden;
        position: relative;
    }

    .swipeable-content {
        padding: 15px;
        background: var(--card-bg);
        position: relative;
        z-index: 2;
    }

    .swipeable-actions {
        position: absolute;
        right: 0;
        top: 0;
        bottom: 0;
        display: flex;
        z-index: 1;
    }

    .swipeable-action {
        width: 70px;
        display: flex;
        align-items: center;
        justify-content: center;
        color: white;
    }

    .swipeable-action.edit { background: var(--warning-color); }
    .swipeable-action.delete { background: var(--danger-color); }

    /* ========== PESTAÑAS MÓVILES ========== */
    .nav-tabs-mobile {
        display: flex;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-bottom: 2px solid rgba(255,255,255,0.1);
        margin-bottom: 15px;
        scrollbar-width: none;
    }

    .nav-tabs-mobile::-webkit-scrollbar {
        display: none;
    }

    .nav-tabs-mobile .nav-link {
        white-space: nowrap;
        padding: 12px 20px;
        border: none;
        border-bottom: 3px solid transparent;
        color: #a0aec0;
        font-weight: 500;
    }

    .nav-tabs-mobile .nav-link.active {
        color: var(--primary-color);
        border-bottom-color: var(--primary-color);
    }

    /* ========== BÚSQUEDA MÓVIL ========== */
    .search-mobile {
        position: relative;
        margin-bottom: 15px;
    }

    .search-mobile input {
        padding-left: 45px;
        padding-right: 45px;
        border-radius: 25px;
    }

    .search-mobile .search-icon {
        position: absolute;
        left: 15px;
        top: 50%;
        transform: translateY(-50%);
        color: #a0aec0;
    }

    .search-mobile .clear-search {
        position: absolute;
        right: 15px;
        top: 50%;
        transform: translateY(-50%);
        background: none;
        border: none;
        color: #a0aec0;
        padding: 5px;
    }

    /* ========== CHAT WIDGET MÓVIL ========== */
    .chat-widget {
        bottom: calc(var(--bottom-nav-height) + 10px) !important;
        right: 15px !important;
    }

    .chat-button {
        width: 50px !important;
        height: 50px !important;
    }

    .chat-box {
        position: fixed !important;
        inset: 0 !important;
        width: 100% !important;
        height: 100% !important;
        border-radius: 0 !important;
        z-index: 2000 !important;
    }

    .chat-box-header {
        padding: 15px;
        padding-top: calc(15px + env(safe-area-inset-top, 0));
    }

    .chat-input-area {
        padding-bottom: calc(15px + env(safe-area-inset-bottom, 0));
    }

    /* ========== NOTIFICACIONES/TOASTS ========== */
    .toast-container {
        position: fixed;
        top: calc(var(--header-height-mobile) + 10px);
        left: 50%;
        transform: translateX(-50%);
        z-index: 9999;
        width: calc(100% - 30px);
        max-width: 400px;
    }

    .toast {
        width: 100%;
        margin-bottom: 10px;
        border-radius: 12px;
    }

    /* ========== PULL TO REFRESH ========== */
    .ptr-wrapper {
        position: relative;
        overflow: hidden;
    }

    .ptr-indicator {
        position: absolute;
        top: -50px;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 40px;
        border-radius: 50%;
        background: var(--card-bg);
        display: flex;
        align-items: center;
        justify-content: center;
        transition: top 0.2s;
    }

    .ptr-indicator.visible {
        top: 10px;
    }

    .ptr-indicator.loading {
        animation: spin 1s linear infinite;
    }

    @keyframes spin {
        from { transform: translateX(-50%) rotate(0deg); }
        to { transform: translateX(-50%) rotate(360deg); }
    }

    /* ========== CALENDARIO MÓVIL ========== */
    .calendar-mobile {
        font-size: 0.85rem;
    }

    .calendar-mobile th,
    .calendar-mobile td {
        padding: 8px 4px;
        text-align: center;
    }

    .calendar-day {
        width: 36px;
        height: 36px;
        border-radius: 50%;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .calendar-day.today {
        background: var(--primary-color);
        color: white;
    }

    .calendar-day.has-event::after {
        content: '';
        position: absolute;
        bottom: 2px;
        width: 4px;
        height: 4px;
        border-radius: 50%;
        background: var(--warning-color);
    }

    /* ========== GRÁFICOS RESPONSIVE ========== */
    .chart-container {
        height: 250px !important;
        margin-bottom: 15px;
    }

    /* ========== ALERTAS ========== */
    .alert {
        padding: 12px 15px;
        border-radius: 10px;
        font-size: 0.9rem;
    }

    /* ========== BADGES ========== */
    .badge {
        padding: 5px 10px;
        font-size: 0.8rem;
        border-radius: 6px;
    }

    /* ========== ACORDEONES ========== */
    .accordion-button {
        padding: 15px;
        font-size: 0.95rem;
    }

    .accordion-body {
        padding: 15px;
    }

    /* ========== DROPDOWNS ========== */
    .dropdown-menu {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        top: auto !important;
        transform: none !important;
        border-radius: 20px 20px 0 0;
        padding: 10px 0;
        max-height: 70vh;
        overflow-y: auto;
    }

    .dropdown-item {
        padding: 15px 20px;
        font-size: 1rem;
    }

    /* ========== UTILIDADES MÓVIL ========== */
    .hide-mobile { display: none !important; }
    .show-mobile { display: block !important; }
    .flex-mobile { display: flex !important; }

    .text-center-mobile { text-align: center !important; }

    .mt-mobile { margin-top: var(--mobile-spacing) !important; }
    .mb-mobile { margin-bottom: var(--mobile-spacing) !important; }
    .p-mobile { padding: var(--mobile-spacing) !important; }

    /* Stack en móvil */
    .stack-mobile {
        flex-direction: column !important;
    }

    .stack-mobile > * {
        width: 100% !important;
        margin-bottom: 10px;
    }

    /* Columnas a full width */
    .col-md-3, .col-md-4, .col-md-6, .col-md-8, .col-lg-3, .col-lg-4, .col-lg-6, .col-lg-8 {
        width: 100% !important;
        max-width: 100% !important;
        flex: 0 0 100% !important;
    }
}

/* ========== TABLET (769px - 1024px) ========== */
@media (min-width: 769px) and (max-width: 1024px) {
    .container-fluid {
        padding: 20px !important;
    }

    .sidebar {
        width: 220px;
    }

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

    .col-md-6 {
        width: 50% !important;
    }

    .col-md-4 {
        width: 50% !important;
    }

    .bottom-nav {
        display: none;
    }

    body {
        padding-bottom: 0;
    }
}

/* ========== DESKTOP (>1024px) ========== */
@media (min-width: 1025px) {
    .mobile-header,
    .bottom-nav,
    .menu-toggle,
    .sidebar-overlay {
        display: none !important;
    }

    .show-mobile { display: none !important; }
    .hide-mobile { display: block !important; }

    body {
        padding-bottom: 0;
    }
}

/* ========== IOS SAFE AREAS ========== */
@supports (padding: max(0px)) {
    .bottom-nav {
        padding-bottom: max(10px, env(safe-area-inset-bottom));
        height: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px));
    }

    .mobile-header {
        padding-top: env(safe-area-inset-top, 0);
        height: calc(var(--header-height-mobile) + env(safe-area-inset-top, 0px));
    }

    .main-content {
        padding-top: calc(var(--header-height-mobile) + env(safe-area-inset-top, 0px));
    }
}

/* ========== LANDSCAPE MÓVIL ========== */
@media (max-width: 900px) and (orientation: landscape) {
    .bottom-nav {
        flex-direction: row;
        height: 50px;
    }

    .bottom-nav-item {
        flex-direction: row;
        gap: 8px;
    }

    .bottom-nav-item i {
        margin-bottom: 0;
    }

    .modal-content {
        max-height: 100vh;
    }
}

/* ========== DARK MODE MÓVIL ========== */
@media (prefers-color-scheme: dark) {
    .search-mobile input {
        background: var(--card-bg);
        border-color: rgba(255,255,255,0.1);
        color: white;
    }

    .dropdown-menu {
        background: var(--card-bg);
        border-color: rgba(255,255,255,0.1);
    }
}

/* ========== ANIMACIONES SUAVES ========== */
@media (prefers-reduced-motion: no-preference) {
    .sidebar {
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .btn, .card, .swipeable-content {
        transition: transform 0.2s, box-shadow 0.2s;
    }

    .btn:active {
        transform: scale(0.98);
    }
}

/* ========== PRINT ========== */
@media print {
    .bottom-nav,
    .mobile-header,
    .sidebar,
    .fab,
    .chat-widget {
        display: none !important;
    }

    .main-content {
        margin: 0 !important;
        padding: 0 !important;
    }
}
