/* ============================================================================
   UIGSYNC — CSS EXCLUSIVO PARA MÓVILES (<= 768px)
   Estilo app nativa (inspirado en TripSync) con identidad oficial UIG (#c91e2b)
   - Fuerza tema claro institucional UIG (elimina auto-dark en iOS/Android)
   - Barra de navegación inferior fija con botón central elevado "+"
   - Bottom sheets táctiles para Acciones Rápidas y Menú Completo de Módulos
   - Desktop (> 768px) permanece 100% intacto
   ============================================================================ */

/* Ocultar elementos exclusivos móviles en Desktop */
.uig-mobile-brand,
.uig-mobile-nav,
.uig-mobile-sheet-backdrop {
    display: none;
}

@media (max-width: 768px) {
    /* 1. Forzar tema claro UIG en móvil (sin dark mode forzado por el sistema) */
    :root,
    :root[data-theme="dark"],
    html,
    body,
    :root[data-theme="dark"] body {
        background: #fafbfc !important;
        color: #0f172a !important;
        color-scheme: light !important;
        overflow-x: hidden !important;
    }

    :root[data-theme="dark"] .card,
    :root[data-theme="dark"] .dash-card,
    :root[data-theme="dark"] .stat-card,
    :root[data-theme="dark"] .top-header,
    :root[data-theme="dark"] .adm-bento-card,
    :root[data-theme="dark"] .adm-filter-card,
    :root[data-theme="dark"] .adm-table-card,
    :root[data-theme="dark"] .pipe-toolbar,
    :root[data-theme="dark"] .pipe-card,
    :root[data-theme="dark"] .fin-campus-bar,
    :root[data-theme="dark"] .chrome-workspace-container {
        background: #ffffff !important;
        color: #0f172a !important;
        border-color: #e2e8f0 !important;
    }

    :root[data-theme="dark"] h1,
    :root[data-theme="dark"] h2,
    :root[data-theme="dark"] h3,
    :root[data-theme="dark"] h4,
    :root[data-theme="dark"] .page-title,
    :root[data-theme="dark"] .stat-card__value,
    :root[data-theme="dark"] .adm-bento-num,
    :root[data-theme="dark"] .dash-card__header h3 {
        color: #0f172a !important;
    }

    /* 2. Ocultar sidebar de escritorio y liberar 100% del ancho */
    .sidebar {
        display: none !important;
    }

    .app-layout {
        display: block !important;
        min-height: 100dvh;
        width: 100% !important;
        background: #fafbfc !important;
    }

    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
        min-width: 0 !important;
        min-height: 100dvh;
        padding: 0 !important;
        background: #fafbfc !important;
    }

    /* 3. Topbar móvil limpia y nativa */
    .top-header {
        position: sticky !important;
        top: 0 !important;
        z-index: 45 !important;
        height: 58px !important;
        min-height: 58px !important;
        padding: 0 14px !important;
        background: rgba(255, 255, 255, 0.96) !important;
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
        border-bottom: 1px solid #e2e8f0 !important;
        box-shadow: 0 2px 10px rgba(15, 23, 42, 0.04) !important;
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        gap: 10px !important;
    }

    .uig-mobile-brand {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
        text-decoration: none;
    }

    .uig-mobile-brand img {
        height: 28px;
        width: auto;
        object-fit: contain;
    }

    .page-heading-block {
        display: flex !important;
        align-items: center !important;
        gap: 8px !important;
        min-width: 0 !important;
        flex: 1 !important;
    }

    .page-breadcrumb,
    .page-title-icon,
    .impersonate-selector-wrap {
        display: none !important;
    }

    .page-title-row {
        min-width: 0 !important;
        gap: 6px !important;
    }

    .top-header .page-title {
        font-size: 15px !important;
        font-weight: 800 !important;
        color: #0f172a !important;
        margin: 0 !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }

    .header-actions {
        display: flex !important;
        align-items: center !important;
        gap: 8px !important;
        flex-shrink: 0 !important;
    }

    .header-actions .env-badge {
        font-size: 10.5px !important;
        padding: 3px 8px !important;
        background: #fef2f2 !important;
        color: #c91e2b !important;
        border: 1px solid #fecaca !important;
        border-radius: 9999px !important;
        font-weight: 700 !important;
    }

    .notif-bell {
        color: #334155 !important;
        width: 34px;
        height: 34px;
        border-radius: 10px;
        background: #f8fafc;
        border: 1px solid #e2e8f0;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* 4. Contenido principal con espacio inferior para la barra flotante */
    .page-content {
        padding: 12px 12px calc(92px + env(safe-area-inset-bottom, 0px)) 12px !important;
        max-width: 100% !important;
        overflow-x: hidden !important;
    }

    .chrome-workspace-container {
        padding: 12px !important;
        border-radius: 14px !important;
        border: 1px solid #e2e8f0 !important;
        background: #ffffff !important;
    }

    /* 5. Pestañas y pills deslizables horizontalmente sin scroll visible */
    .chrome-tabbar,
    .adm-pill-switcher,
    .fin-campus-pills {
        display: flex !important;
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        gap: 6px !important;
        padding-bottom: 4px !important;
    }

    .chrome-tabbar::-webkit-scrollbar,
    .adm-pill-switcher::-webkit-scrollbar,
    .fin-campus-pills::-webkit-scrollbar {
        display: none;
    }

    .chrome-tab,
    .adm-pill-item,
    .fin-campus-pill {
        flex-shrink: 0 !important;
        white-space: nowrap !important;
    }

    /* 6. Grids responsivos (KPIs en 2 columnas, gráficas/tablas en 1 columna) */
    .stats-grid,
    .adm-bento-grid,
    .fin-kpi-grid-5 {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 10px !important;
    }

    .adm-bento-card,
    .stat-card {
        padding: 12px !important;
        border-radius: 14px !important;
    }

    .adm-bento-num {
        font-size: 18px !important;
    }

    .uig-charts-grid-3,
    .fin-split-grid,
    .dashboard-grid,
    .split-grid-asym {
        display: grid !important;
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }

    /* 7. Pipeline móvil (toolbar compacta + columnas snap-scroll) */
    .pipe-header-row,
    .adm-header-row,
    .fin-campus-bar {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 10px !important;
    }

    .pipe-title {
        font-size: 19px !important;
    }

    .pipe-header-actions {
        width: 100%;
        justify-content: space-between;
    }

    .pipe-toolbar {
        flex-direction: column !important;
        align-items: stretch !important;
        padding: 10px !important;
    }

    .pipe-toolbar-left {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 8px !important;
    }

    .pipe-search-wrap {
        grid-column: 1 / -1 !important;
        max-width: none !important;
    }

    .pipe-select {
        width: 100% !important;
        max-width: none !important;
    }

    .pipe-toolbar-right {
        justify-content: space-between !important;
        width: 100% !important;
    }

    .pipe-board-scroll {
        scroll-snap-type: x mandatory;
        padding-bottom: 12px !important;
    }

    .pipe-col {
        flex: 0 0 84vw !important;
        width: 84vw !important;
        scroll-snap-align: start;
        max-height: 62vh !important;
    }

    .pipe-drawer {
        max-width: 100% !important;
        width: 100% !important;
    }

    .pipe-assistant-bar {
        flex-direction: column !important;
        align-items: stretch !important;
        padding: 12px 14px !important;
    }

    .pipe-assistant-actions {
        width: 100%;
        justify-content: flex-end;
    }

    /* Galería Community Manager y Kanban Diseño en 1 columna móvil */
    #agencyTabContent [style*="grid-template-columns:repeat(3"],
    #agencyTabContent [style*="grid-template-columns:repeat(4"] {
        grid-template-columns: 1fr !important;
    }

    /* 8. BARRA INFERIOR APP NATIVA UIG CON BOTÓN CENTRAL "+" */
    .uig-mobile-nav {
        display: grid !important;
        grid-template-columns: 1fr 1fr 68px 1fr 1fr;
        align-items: center;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 80;
        background: rgba(255, 255, 255, 0.97);
        backdrop-filter: blur(16px);
        -webkit-backdrop-filter: blur(16px);
        border-top: 1px solid #e2e8f0;
        box-shadow: 0 -6px 24px rgba(15, 23, 42, 0.08);
        padding: 6px 6px calc(8px + env(safe-area-inset-bottom, 0px));
    }

    .uig-mobile-nav__item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        text-decoration: none;
        border: none;
        background: transparent;
        color: #64748b;
        font-size: 10px;
        font-weight: 700;
        padding: 4px 2px;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    .uig-mobile-nav__item .material-symbols-outlined {
        font-size: 22px;
    }

    .uig-mobile-nav__item.active {
        color: #c91e2b;
    }

    .uig-mobile-nav__fab-slot {
        display: flex;
        align-items: center;
        justify-content: center;
        position: relative;
        height: 44px;
    }

    .uig-mobile-fab {
        position: absolute;
        top: -22px;
        width: 54px;
        height: 54px;
        border-radius: 9999px;
        border: 4px solid #ffffff;
        background: linear-gradient(135deg, #d3121e 0%, #991b1b 100%);
        color: #ffffff;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 10px 22px -4px rgba(201, 30, 43, 0.5);
        cursor: pointer;
        transition: transform 0.15s ease;
        -webkit-tap-highlight-color: transparent;
    }

    .uig-mobile-fab:active {
        transform: scale(0.92);
    }

    .uig-mobile-fab .material-symbols-outlined {
        font-size: 28px;
        font-weight: 700;
    }

    /* 9. BOTTOM SHEETS (ACCIONES RÁPIDAS "+" Y MENÚ COMPLETO) */
    .uig-mobile-sheet-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        z-index: 95;
        background: rgba(15, 23, 42, 0.5);
        backdrop-filter: blur(3px);
        -webkit-backdrop-filter: blur(3px);
        align-items: flex-end;
        justify-content: center;
    }

    .uig-mobile-sheet-backdrop.open {
        display: flex !important;
    }

    .uig-mobile-sheet {
        width: 100%;
        max-height: 82dvh;
        background: #ffffff;
        border-radius: 22px 22px 0 0;
        padding: 10px 16px calc(22px + env(safe-area-inset-bottom, 0px));
        box-shadow: 0 -14px 40px rgba(15, 23, 42, 0.2);
        overflow-y: auto;
        animation: uigSheetUp 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    }

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

    .uig-mobile-sheet__handle {
        width: 40px;
        height: 4px;
        border-radius: 9999px;
        background: #cbd5e1;
        margin: 0 auto 12px;
    }

    .uig-mobile-sheet__header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 14px;
    }

    .uig-mobile-sheet__title {
        font-size: 16px;
        font-weight: 800;
        color: #0f172a;
        margin: 0;
    }

    .uig-mobile-sheet__grid {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }

    .uig-mobile-tile {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
        padding: 13px 12px;
        border-radius: 14px;
        border: 1px solid #e2e8f0;
        background: #f8fafc;
        color: #0f172a;
        text-decoration: none;
        text-align: left;
        cursor: pointer;
    }

    .uig-mobile-tile:active {
        background: #fef2f2;
        border-color: #fecaca;
    }

    .uig-mobile-tile__icon {
        width: 36px;
        height: 36px;
        border-radius: 10px;
        background: #fef2f2;
        color: #c91e2b;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .uig-mobile-tile__title {
        font-size: 13px;
        font-weight: 800;
        color: #0f172a;
        line-height: 1.2;
    }

    .uig-mobile-tile__sub {
        font-size: 11px;
        color: #64748b;
        line-height: 1.25;
    }
}
