/* ============================================================
   ImpulsoWeb PWA Install + Strict Push Onboarding + Native Mobile App Shell
   Compatible con Barra Top (40px) de Marketing Universal
   ============================================================ */

/* 1. Ajuste limpio para Barra Top fija sobre .navbar y body */
html.mkt-con-barra body {
    padding-top: calc(var(--iw-body-base-pt, 88px) + var(--mkt-barra-h, 0px)) !important;
}

html.mkt-con-barra .navbar,
html.mkt-con-barra header.navbar,
html.mkt-con-barra .navbar.navbar {
    top: var(--mkt-barra-h, 0px) !important;
}

@media (max-width: 768px) {
    html.mkt-con-barra body {
        padding-top: calc(var(--iw-body-base-pt, 80px) + var(--mkt-barra-h, 0px)) !important;
    }
    html.mkt-con-barra .nav-actions {
        height: calc(100dvh - var(--mkt-barra-h, 0px)) !important;
    }
}

/* Seguridad por si alguna copia antigua dejara botón en navbar: siempre oculto */
.iw-nav-pwa-btn,
#iwNavPwaBtn {
    display: none !important;
}

.iw-pwa-card [hidden],
.iw-app-bottom-nav[hidden],
.iw-app-sheet[hidden],
.iw-app-sheet-backdrop[hidden] {
    display: none !important;
}

/* 2. Modal centrado de Instalación y Activación de Notificaciones */
.iw-pwa-overlay {
    position: fixed;
    inset: 0;
    z-index: 200500;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
    background: rgba(5, 8, 18, 0.74);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    opacity: 0;
    transition: opacity 0.22s ease;
}

.iw-pwa-overlay.is-visible {
    opacity: 1;
}

.iw-pwa-card {
    position: relative;
    width: 100%;
    max-width: 420px;
    max-height: min(90dvh, 620px);
    overflow-y: auto;
    background: #0F172A;
    color: #F8FAFC;
    border: 1px solid rgba(245, 158, 11, 0.35);
    border-radius: 20px;
    padding: 28px 24px 22px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.05) inset;
    font-family: 'Inter', system-ui, sans-serif;
    transform: translateY(10px) scale(0.97);
    transition: transform 0.24s cubic-bezier(0.16, 1, 0.3, 1);
    box-sizing: border-box;
}

.iw-pwa-overlay.is-visible .iw-pwa-card {
    transform: translateY(0) scale(1);
}

html[data-theme="light"] .iw-pwa-card {
    background: #FFFFFF;
    color: #0F172A;
    border-color: rgba(37, 99, 235, 0.25);
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.22);
}

.iw-pwa-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.06);
    color: #CBD5E1;
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.iw-pwa-close:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #FFFFFF;
    transform: scale(1.05);
}

.iw-pwa-close:focus-visible {
    outline: 2px solid #F59E0B;
    outline-offset: 2px;
}

html[data-theme="light"] .iw-pwa-close {
    background: #F1F5F9;
    border-color: #E2E8F0;
    color: #475569;
}

html[data-theme="light"] .iw-pwa-close:hover {
    background: #E2E8F0;
    color: #0F172A;
}

.iw-pwa-head {
    display: flex;
    align-items: center;
    gap: 14px;
    padding-right: 40px;
    margin-bottom: 14px;
}

.iw-pwa-app-icon {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    background: #0B0F1A;
    border: 1px solid rgba(255, 255, 255, 0.14);
    padding: 6px;
    flex-shrink: 0;
    object-fit: contain;
}

.iw-pwa-badge {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 3px 9px;
    border-radius: 999px;
    background: rgba(245, 158, 11, 0.16);
    color: #FBBF24;
    border: 1px solid rgba(245, 158, 11, 0.35);
    margin-bottom: 5px;
}

html[data-theme="light"] .iw-pwa-badge {
    background: #FEF3C7;
    color: #9A5B0A;
    border-color: rgba(217, 119, 6, 0.35);
}

.iw-pwa-title {
    margin: 0;
    font-family: 'Plus Jakarta Sans', 'Inter', sans-serif;
    font-size: 1.2rem;
    font-weight: 800;
    line-height: 1.25;
    color: inherit;
}

.iw-pwa-desc {
    margin: 0 0 14px;
    font-size: 0.92rem;
    line-height: 1.55;
    color: #CBD5E1;
}

html[data-theme="light"] .iw-pwa-desc {
    color: #475569;
}

.iw-pwa-benefits {
    list-style: none;
    margin: 0 0 18px;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 9px;
}

.iw-pwa-benefits li {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.87rem;
    line-height: 1.4;
    color: #E2E8F0;
}

html[data-theme="light"] .iw-pwa-benefits li {
    color: #1E293B;
}

.iw-pwa-benefits svg {
    width: 18px;
    height: 18px;
    color: #F59E0B;
    flex-shrink: 0;
}

.iw-pwa-steps {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 14px;
    padding: 14px;
    margin: 0 0 16px;
}

html[data-theme="light"] .iw-pwa-steps {
    background: #F8FAFC;
    border-color: #E2E8F0;
}

.iw-pwa-steps-title {
    margin: 0 0 10px;
    font-size: 0.85rem;
    font-weight: 700;
    color: #FBBF24;
}

html[data-theme="light"] .iw-pwa-steps-title {
    color: #1E40AF;
}

.iw-pwa-step {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-size: 0.86rem;
    line-height: 1.45;
    margin-bottom: 8px;
}

.iw-pwa-step:last-child {
    margin-bottom: 0;
}

.iw-pwa-step-num {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #2563EB;
    color: #FFFFFF;
    font-size: 0.75rem;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 1px;
}

.iw-pwa-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.iw-pwa-btn-primary {
    width: 100%;
    min-height: 48px;
    padding: 12px 18px;
    border: 0;
    border-radius: 12px;
    background: #F59E0B;
    color: #0B0F1A;
    font-family: 'Plus Jakarta Sans', 'Inter', sans-serif;
    font-size: 0.96rem;
    font-weight: 800;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 8px 20px rgba(245, 158, 11, 0.28);
    transition: transform 0.16s ease, filter 0.16s ease;
}

.iw-pwa-btn-primary svg,
.iw-pwa-btn-secondary svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.iw-pwa-btn-primary:hover {
    filter: brightness(1.06);
    transform: translateY(-1px);
}

.iw-pwa-btn-primary:focus-visible {
    outline: 2px solid #2563EB;
    outline-offset: 2px;
}

.iw-pwa-btn-primary.is-blue {
    background: #2563EB;
    color: #FFFFFF;
    box-shadow: 0 8px 20px rgba(37, 99, 235, 0.3);
}

.iw-pwa-btn-secondary {
    width: 100%;
    min-height: 44px;
    padding: 10px 16px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: transparent;
    color: #CBD5E1;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.iw-pwa-btn-secondary:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #FFFFFF;
}

html[data-theme="light"] .iw-pwa-btn-secondary {
    border-color: #CBD5E1;
    color: #475569;
}

html[data-theme="light"] .iw-pwa-btn-secondary:hover {
    background: #F1F5F9;
    color: #0F172A;
}

.iw-pwa-status {
    margin-top: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 0.84rem;
    line-height: 1.45;
    background: rgba(16, 185, 129, 0.14);
    border: 1px solid rgba(16, 185, 129, 0.35);
    color: #6EE7B7;
}

html[data-theme="light"] .iw-pwa-status {
    color: #065F46;
}

/* ============================================================
   3. NATIVE MOBILE APP SHELL (html.iw-pwa-app)
      - Contenedor fijo sin movimiento lateral ni rebote
      - Barra superior compacta sin hamburguesa
      - Barra inferior fija con los 7 menús
   ============================================================ */
html.iw-pwa-app {
    height: 100%;
    width: 100%;
    overflow: hidden !important;
    overscroll-behavior: none !important;
}

html.iw-pwa-app body {
    position: fixed !important;
    inset: 0 !important;
    width: 100% !important;
    max-width: 100vw !important;
    height: 100dvh !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain !important;
    touch-action: pan-y pinch-zoom;
    padding-top: calc(60px + var(--mkt-barra-h, 0px)) !important;
    padding-bottom: calc(84px + env(safe-area-inset-bottom, 0px)) !important;
    margin: 0 !important;
    box-sizing: border-box !important;
}

html.iw-pwa-app main,
html.iw-pwa-app section,
html.iw-pwa-app footer {
    max-width: 100% !important;
    overflow-x: clip;
}

/* Barra superior estilo App Nativa: compacta, fija, limpia */
html.iw-pwa-app .navbar,
html.iw-pwa-app header.navbar {
    position: fixed !important;
    top: var(--mkt-barra-h, 0px) !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    min-height: 60px !important;
    height: 60px !important;
    padding: 0 14px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    z-index: 100000 !important;
    box-sizing: border-box !important;
}

html.iw-pwa-app .navbar .nav-inner {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

html.iw-pwa-app .navbar .logo img,
html.iw-pwa-app .navbar .nav-logo img {
    height: 30px !important;
    width: auto !important;
    max-height: 30px !important;
}

/* Ocultar menús superiores, hamburguesa y drawer deslizante cuando corre como App */
html.iw-pwa-app #hamburgerMenu,
html.iw-pwa-app #menuToggleBtn,
html.iw-pwa-app .hamburger,
html.iw-pwa-app .hamburger-btn,
html.iw-pwa-app #navActions,
html.iw-pwa-app .nav-actions,
html.iw-pwa-app #navScrim,
html.iw-pwa-app .nav-scrim,
html.iw-pwa-app .navbar .nav-links-pill,
html.iw-pwa-app #mobileDrawer,
html.iw-pwa-app #mobileOverlay {
    display: none !important;
}

html.iw-pwa-app .theme-toggle-btn {
    margin-left: auto !important;
    position: static !important;
}

/* Botones flotantes WhatsApp/Telegram encima de la barra inferior */
html.iw-pwa-app .floating-contact {
    bottom: calc(80px + env(safe-area-inset-bottom, 0px)) !important;
    right: 12px !important;
    z-index: 99980 !important;
}

html.iw-pwa-app #campanaModal {
    z-index: 190000 !important;
}

/* Barra de Navegación Inferior Fija (7 Menús) */
.iw-app-bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 100010;
    width: 100%;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
    background: rgba(11, 15, 26, 0.96);
    border-top: 1px solid rgba(148, 163, 184, 0.22);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    box-shadow: 0 -8px 28px rgba(0, 0, 0, 0.35);
    box-sizing: border-box;
    touch-action: manipulation;
}

html[data-theme="light"] .iw-app-bottom-nav {
    background: rgba(255, 255, 255, 0.97);
    border-top: 1px solid #E2E8F0;
    box-shadow: 0 -6px 24px rgba(15, 23, 42, 0.1);
}

.iw-app-bottom-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    align-items: stretch;
    gap: 2px;
    max-width: 720px;
    margin: 0 auto;
    width: 100%;
}

.iw-app-tab {
    appearance: none;
    background: transparent;
    border: 0;
    border-radius: 10px;
    padding: 5px 1px;
    min-height: 52px;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    color: #94A3B8;
    text-decoration: none;
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 9.5px;
    font-weight: 600;
    line-height: 1.05;
    letter-spacing: -0.02em;
    cursor: pointer;
    position: relative;
    transition: color 0.16s ease, background 0.16s ease, transform 0.12s ease;
    -webkit-tap-highlight-color: transparent;
}

html[data-theme="light"] .iw-app-tab {
    color: #475569;
}

.iw-app-tab svg {
    width: 19px;
    height: 19px;
    flex-shrink: 0;
    stroke-width: 2;
}

.iw-app-tab-label {
    display: block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.iw-app-tab:active {
    transform: scale(0.95);
}

.iw-app-tab.is-active,
.iw-app-tab[aria-expanded="true"] {
    color: #F59E0B;
    background: rgba(245, 158, 11, 0.12);
    font-weight: 700;
}

html[data-theme="light"] .iw-app-tab.is-active,
html[data-theme="light"] .iw-app-tab[aria-expanded="true"] {
    color: #1D4ED8;
    background: rgba(37, 99, 235, 0.1);
}

.iw-app-tab.is-active::before {
    content: '';
    position: absolute;
    top: 2px;
    width: 18px;
    height: 2.5px;
    border-radius: 999px;
    background: currentColor;
}

/* Hoja inferior nativa (Bottom Sheet) para submenús (Redes, Servicios, Campañas) */
.iw-app-sheet-backdrop {
    position: fixed;
    inset: 0;
    z-index: 100020;
    background: rgba(5, 8, 18, 0.62);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.iw-app-sheet-backdrop.is-open {
    opacity: 1;
}

.iw-app-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 100021;
    max-width: 540px;
    margin: 0 auto;
    max-height: min(72dvh, 520px);
    background: #0F172A;
    color: #F8FAFC;
    border-top: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 22px 22px 0 0;
    padding: 10px 18px calc(22px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -16px 48px rgba(0, 0, 0, 0.52);
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform 0.24s cubic-bezier(0.16, 1, 0.3, 1);
    box-sizing: border-box;
    font-family: 'Inter', system-ui, sans-serif;
}

.iw-app-sheet.is-open {
    transform: translateY(0);
}

html[data-theme="light"] .iw-app-sheet {
    background: #FFFFFF;
    color: #0F172A;
    border-top-color: #E2E8F0;
}

.iw-app-sheet-handle {
    width: 40px;
    height: 4px;
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.4);
    margin: 0 auto 12px;
    flex-shrink: 0;
}

.iw-app-sheet-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.18);
}

.iw-app-sheet-head h3 {
    margin: 0;
    font-family: 'Plus Jakarta Sans', 'Inter', sans-serif;
    font-size: 1.05rem;
    font-weight: 800;
}

.iw-app-sheet-close {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid rgba(148, 163, 184, 0.25);
    background: transparent;
    color: inherit;
    display: grid;
    place-items: center;
    cursor: pointer;
}

.iw-app-sheet-list {
    overflow-y: auto;
    display: grid;
    gap: 8px;
    padding: 2px 0;
}

.iw-app-sheet-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 46px;
    padding: 10px 14px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.09);
    color: #F8FAFC;
    text-decoration: none;
    font-size: 0.92rem;
    font-weight: 600;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.iw-app-sheet-link:hover,
.iw-app-sheet-link:active {
    background: rgba(245, 158, 11, 0.14);
    border-color: rgba(245, 158, 11, 0.45);
}

html[data-theme="light"] .iw-app-sheet-link {
    background: #F8FAFC;
    border-color: #E2E8F0;
    color: #0F172A;
}

html[data-theme="light"] .iw-app-sheet-link:hover,
html[data-theme="light"] .iw-app-sheet-link:active {
    background: #EFF6FF;
    border-color: #93C5FD;
}

.iw-app-sheet-link svg {
    width: 16px;
    height: 16px;
    opacity: 0.65;
    flex-shrink: 0;
}

@media (max-width: 480px) {
    .iw-pwa-card {
        padding: 24px 18px 18px;
        border-radius: 18px;
    }
    .iw-pwa-title {
        font-size: 1.1rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .iw-pwa-overlay,
    .iw-pwa-card,
    .iw-app-tab,
    .iw-app-sheet,
    .iw-app-sheet-backdrop {
        transition: none;
    }
}
