/* =============================================================
   ROLLIN HOST 2026 — Mobile App Experience
   Faz o WHMCS parecer um app nativo no celular:
   - Safe area insets (iPhone notch/dynamic island)
   - Bottom navigation fixa
   - Bottom sheets ao invés de modais
   - Touch targets 44px+ (Apple HIG)
   - Momentum scrolling + scroll snap
   - Splash screen
   - PWA standalone mode
   ============================================================= */

/* ===== Safe area insets — iOS notch / Dynamic Island ===== */
:root {
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);

    /* Altura da bottom nav + safe area */
    --mobile-nav-height: 64px;
    --mobile-nav-total: calc(var(--mobile-nav-height) + var(--safe-bottom));
}

/* Quando PWA standalone (instalado) */
@media all and (display-mode: standalone) {
    :root {
        --is-standalone: 1;
    }
    body {
        user-select: none;
        -webkit-user-select: none;
        -webkit-touch-callout: none;
    }
    /* Esconder elementos desnecessários no app instalado */
    .pwa-hide { display: none !important; }
}

/* ===== Reset mobile-friendly ===== */
@media (max-width: 991px) {
    html {
        -webkit-text-size-adjust: 100%;
        text-size-adjust: 100%;
        touch-action: manipulation; /* elimina delay de 300ms */
    }

    body {
        overscroll-behavior-y: contain; /* bloqueia pull-to-refresh nativo */
        -webkit-tap-highlight-color: transparent;
        padding-top: var(--safe-top) !important;
        padding-left: var(--safe-left) !important;
        padding-right: var(--safe-right) !important;
        padding-bottom: var(--mobile-nav-total) !important;
    }

    /* Header mobile-friendly */
    #header,
    .header.navbar-expand-lg {
        padding-top: calc(var(--safe-top) + 8px) !important;
        padding-left: var(--safe-left) !important;
        padding-right: var(--safe-right) !important;
    }

    /* Momentum scrolling iOS */
    .rollin-ai-messages,
    .rollin-bottom-sheet,
    .rollin-scroll-snap,
    .table-responsive {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }

    /* Prevenir zoom em inputs iOS (font-size 16px+) */
    input, textarea, select {
        font-size: 16px !important;
    }
}

/* =============================================================
   BOTTOM NAVIGATION — tipo app nativo
   ============================================================= */

.rollin-mobile-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 9996;

    /* Glass heavy */
    background: rgba(24, 0, 37, 0.85);
    backdrop-filter: blur(30px) saturate(200%);
    -webkit-backdrop-filter: blur(30px) saturate(200%);
    border-top: 1px solid var(--border-subtle);

    /* Safe area padding bottom pra notch/home indicator */
    padding: 8px var(--safe-right) calc(8px + var(--safe-bottom)) var(--safe-left);

    /* Sombra superior sutil pra destacar */
    box-shadow: 0 -4px 30px rgba(0, 0, 0, 0.3);
}

@media (max-width: 991px) {
    .rollin-mobile-nav {
        display: grid;
        grid-template-columns: repeat(5, 1fr);
        gap: 4px;
    }
}

.rollin-nav-item {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 6px 2px;
    min-height: 56px;                 /* touch target confortável */
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 600;
    text-decoration: none;
    border-radius: var(--radius-md);
    transition: all var(--transition-base);
    -webkit-tap-highlight-color: transparent;
    letter-spacing: 0.01em;
}

.rollin-nav-item i,
.rollin-nav-item svg {
    font-size: 22px;
    transition: all var(--transition-base);
}

.rollin-nav-item:active {
    transform: scale(0.92);
    background: rgba(255, 255, 255, 0.06);
}

.rollin-nav-item.active {
    color: var(--accent-pink);
}

.rollin-nav-item.active i {
    transform: translateY(-2px);
    filter: drop-shadow(0 4px 12px rgba(250, 44, 104, 0.6));
}

/* Indicador superior animado */
.rollin-nav-item.active::before {
    content: '';
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 28px;
    height: 3px;
    background: var(--gradient-primary);
    border-radius: 0 0 3px 3px;
    box-shadow: 0 2px 10px rgba(250, 44, 104, 0.5);
    animation: rollinNavIndicator 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes rollinNavIndicator {
    from { width: 0; opacity: 0; }
    to { width: 28px; opacity: 1; }
}

/* Badge de notificação */
.rollin-nav-badge {
    position: absolute;
    top: 4px;
    right: 50%;
    margin-right: -18px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    background: var(--accent-pink);
    color: white;
    border-radius: var(--radius-full);
    font-size: 10px;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--rollin-purple-800);
    box-shadow: 0 2px 8px rgba(250, 44, 104, 0.5);
    animation: rollinBadgePop 400ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes rollinBadgePop {
    from { transform: scale(0); }
    to { transform: scale(1); }
}

/* CTA central destacado (ex: "Contratar") */
.rollin-nav-item.rollin-nav-cta {
    position: relative;
}

.rollin-nav-item.rollin-nav-cta i {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--gradient-primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    box-shadow: var(--shadow-glow-pink);
    margin-bottom: 2px;
    transition: all var(--transition-bounce);
}

.rollin-nav-item.rollin-nav-cta:active i {
    transform: scale(0.88) rotate(-8deg);
}

/* Esconde launcher IA quando a bottom nav está visível (evita sobreposição) */
@media (max-width: 991px) {
    #rollin-ai-launcher {
        bottom: calc(var(--mobile-nav-total) + 16px) !important;
        width: 52px !important;
        height: 52px !important;
        font-size: 22px !important;
    }
    #rollin-ai-panel {
        bottom: calc(var(--mobile-nav-total) + 80px) !important;
        width: calc(100vw - 16px) !important;
        right: 8px !important;
        left: 8px !important;
        height: calc(100vh - var(--mobile-nav-total) - 120px) !important;
        max-height: none !important;
    }
}

/* =============================================================
   BOTTOM SHEET — modais que sobem de baixo tipo iOS
   ============================================================= */

.rollin-sheet-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(6px);
    z-index: 9998;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-base);
}

.rollin-sheet-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

.rollin-bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    background: var(--rollin-purple-700);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    border-top: 1px solid var(--border-default);
    box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.5);
    padding: 8px var(--space-lg) calc(var(--space-lg) + var(--safe-bottom));
    max-height: 90vh;
    overflow-y: auto;
    transform: translateY(100%);
    transition: transform var(--transition-slow);
    touch-action: pan-y;
}

.rollin-bottom-sheet.open {
    transform: translateY(0);
    animation: rollinSheetBounce 500ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes rollinSheetBounce {
    0% { transform: translateY(100%); }
    60% { transform: translateY(-1.5%); }
    100% { transform: translateY(0); }
}

.rollin-sheet-handle {
    display: block;
    width: 40px;
    height: 4px;
    margin: 0 auto var(--space-md);
    background: var(--border-strong);
    border-radius: var(--radius-full);
    cursor: grab;
}

.rollin-sheet-title {
    font-size: var(--fs-lg);
    font-weight: 700;
    margin-bottom: var(--space-md);
    text-align: center;
}

/* =============================================================
   PULL-TO-REFRESH indicator
   ============================================================= */

.rollin-ptr {
    position: fixed;
    top: calc(var(--safe-top) + 8px);
    left: 50%;
    transform: translateX(-50%) translateY(-100%);
    z-index: 9995;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--rollin-purple-700);
    border: 1px solid var(--border-default);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md);
    transition: transform var(--transition-base);
    pointer-events: none;
}

.rollin-ptr.pulling {
    transform: translateX(-50%) translateY(calc(var(--ptr-offset, 0px)));
    transition: none;
}

.rollin-ptr.refreshing {
    transform: translateX(-50%) translateY(20px);
}

.rollin-ptr i {
    color: var(--accent-pink);
    font-size: 18px;
    transition: transform var(--transition-base);
}

.rollin-ptr.refreshing i {
    animation: rollinSpin 900ms linear infinite;
}

@keyframes rollinSpin {
    to { transform: rotate(360deg); }
}

/* =============================================================
   APP-LIKE HEADER (mobile)
   ============================================================= */

@media (max-width: 991px) {
    .rollin-mobile-header {
        position: sticky;
        top: 0;
        z-index: 100;
        padding: 12px var(--space-lg);
        padding-top: calc(var(--safe-top) + 12px);
        background: rgba(24, 0, 37, 0.85);
        backdrop-filter: blur(24px) saturate(180%);
        -webkit-backdrop-filter: blur(24px) saturate(180%);
        border-bottom: 1px solid var(--border-subtle);
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: var(--space-sm);
    }

    .rollin-mobile-header-title {
        font-size: var(--fs-base);
        font-weight: 700;
        color: var(--text-primary);
        margin: 0;
        flex: 1;
        text-align: center;
    }

    .rollin-mobile-header-btn {
        width: 40px;
        height: 40px;
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.06);
        border: 1px solid var(--border-subtle);
        color: var(--text-primary);
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 18px;
        cursor: pointer;
        transition: all var(--transition-fast);
        flex-shrink: 0;
        -webkit-tap-highlight-color: transparent;
    }

    .rollin-mobile-header-btn:active {
        transform: scale(0.9);
        background: rgba(250, 44, 104, 0.15);
    }

    /* Esconde o header desktop no mobile */
    #header:not(.rollin-mobile-header),
    .header.navbar-expand-lg:not(.rollin-mobile-header) {
        display: none !important;
    }
}

/* =============================================================
   SCROLL SNAP — carrossel horizontal de cards (tipo stories)
   ============================================================= */

.rollin-scroll-snap {
    display: flex;
    gap: var(--space-md);
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    scroll-padding: var(--space-lg);
    padding: 0 var(--space-lg) var(--space-md);
    margin: 0 calc(-1 * var(--space-lg));
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.rollin-scroll-snap::-webkit-scrollbar {
    display: none;
}

.rollin-scroll-snap > * {
    scroll-snap-align: start;
    flex-shrink: 0;
}

/* =============================================================
   TOUCH-OPTIMIZED COMPONENTS
   ============================================================= */

@media (max-width: 991px) {
    /* Botões precisam de 44x44 mínimo (Apple HIG) */
    .btn,
    button,
    a.btn,
    .rollin-hero-chip,
    .rollin-qa-card,
    .rollin-filter,
    .rollin-cycle-opt {
        min-height: 44px;
    }

    /* Links de lista (dashboard panel) — larger tap target */
    .rollin-panel-list a,
    .rollin-panel-list > li {
        min-height: 48px;
        padding: 14px var(--space-lg) !important;
    }

    /* Plan card CTA ocupa largura total */
    .rollin-plan-cta {
        min-height: 52px !important;
        font-size: var(--fs-base) !important;
    }

    /* Hero mobile mais compacto */
    .rollin-dashboard-hero {
        padding: var(--space-md) 0;
    }

    .rollin-hero-card {
        padding: var(--space-lg) !important;
        border-radius: var(--radius-lg) !important;
    }

    /* Stats em linha horizontal scrollable */
    .rollin-hero-stats {
        grid-template-columns: repeat(4, minmax(100px, 1fr));
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        scroll-snap-type: x mandatory;
        padding-bottom: 4px;
    }

    .rollin-hero-stats::-webkit-scrollbar {
        display: none;
    }

    .rollin-stat {
        scroll-snap-align: start;
        min-width: 120px;
    }

    /* Feed grid vira stack no mobile */
    .rollin-feed {
        grid-template-columns: 1fr;
    }

    .rollin-feed-item {
        border-radius: var(--radius-md);
    }

    /* Quick actions em 2 colunas */
    .rollin-qa-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-sm);
    }

    .rollin-qa-card {
        flex-direction: column;
        text-align: center;
        padding: var(--space-md);
        min-height: 120px;
    }

    .rollin-qa-card .rollin-qa-arrow {
        display: none;
    }

    .rollin-qa-icon {
        width: 48px;
        height: 48px;
        font-size: 20px;
    }

    .rollin-qa-body h3 {
        font-size: var(--fs-sm);
    }

    .rollin-qa-body p {
        font-size: 11px;
    }

    /* Trust row vertical mobile */
    .rollin-trust-row {
        gap: 2px;
        padding: var(--space-sm);
    }

    .rollin-trust {
        font-size: 10px;
        padding: 6px 10px;
    }

    /* AI CTA mobile */
    .rollin-ai-cta-inner {
        grid-template-columns: 1fr !important;
        text-align: center;
        gap: var(--space-md);
    }

    .rollin-ai-cta-icon {
        margin: 0 auto;
        width: 64px;
        height: 64px;
        font-size: 28px;
    }

    /* Billing cycle em row compacto */
    .rollin-cycle-options {
        width: 100%;
        justify-content: center;
    }

    .rollin-cycle-opt {
        flex: 1;
        justify-content: center;
        padding: 10px 8px;
        font-size: var(--fs-xs);
    }
}

@media (max-width: 480px) {
    /* Feed filter vira scrollable */
    .rollin-feed-filters {
        overflow-x: auto;
        white-space: nowrap;
        scrollbar-width: none;
        padding: 4px;
    }

    .rollin-feed-filters::-webkit-scrollbar {
        display: none;
    }

    .rollin-filter {
        flex-shrink: 0;
        padding: 8px 14px;
    }

    /* Plans 1 coluna com padding menor */
    .rollin-plans-grid {
        gap: var(--space-md);
        padding: 0 var(--space-sm);
    }

    /* Stats 2 por linha fixo */
    .rollin-hero-stats {
        grid-template-columns: repeat(2, 1fr);
        overflow: visible;
    }

    /* Esconde textos muito longos */
    .rollin-greeting-meta {
        font-size: 11px;
    }
}

/* =============================================================
   SKELETON LOADERS (carrega com shimmer)
   ============================================================= */

.rollin-skeleton {
    background: linear-gradient(90deg,
        rgba(255, 255, 255, 0.04) 0%,
        rgba(255, 255, 255, 0.08) 50%,
        rgba(255, 255, 255, 0.04) 100%);
    background-size: 200% 100%;
    animation: rollinShimmer 1.5s ease-in-out infinite;
    border-radius: var(--radius-md);
}

@keyframes rollinShimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* =============================================================
   TOAST NOTIFICATIONS (feedback visual após ações)
   ============================================================= */

#rollin-toast-container {
    position: fixed;
    top: calc(var(--safe-top) + 16px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
    width: 100%;
    max-width: 400px;
    padding: 0 16px;
}

.rollin-toast {
    background: var(--rollin-purple-700);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    color: var(--text-primary);
    font-size: var(--fs-sm);
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 10px;
    pointer-events: auto;
    animation: rollinToastIn 400ms cubic-bezier(0.34, 1.56, 0.64, 1);
    backdrop-filter: blur(20px);
}

.rollin-toast.rollin-toast-success {
    border-color: var(--accent-cyan);
}

.rollin-toast.rollin-toast-success i {
    color: var(--accent-cyan);
}

.rollin-toast.rollin-toast-error {
    border-color: var(--accent-pink);
}

.rollin-toast.rollin-toast-error i {
    color: var(--accent-pink);
}

.rollin-toast.removing {
    animation: rollinToastOut 300ms ease-in forwards;
}

@keyframes rollinToastIn {
    from { transform: translateY(-30px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes rollinToastOut {
    to { transform: translateY(-30px); opacity: 0; }
}

/* =============================================================
   SPLASH SCREEN (PWA standalone)
   ============================================================= */

.rollin-splash {
    position: fixed;
    inset: 0;
    z-index: 99999;
    background: var(--rollin-purple-800);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-lg);
    transition: opacity 500ms ease-out;
}

.rollin-splash.hidden {
    opacity: 0;
    pointer-events: none;
}

.rollin-splash-logo {
    width: 120px;
    height: 120px;
    border-radius: 30px;
    background: var(--gradient-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 56px;
    color: white;
    box-shadow: var(--shadow-glow-pink);
    animation: rollinSplashPulse 2s ease-in-out infinite;
}

@keyframes rollinSplashPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.rollin-splash-text {
    color: var(--text-primary);
    font-size: var(--fs-xl);
    font-weight: 700;
    letter-spacing: 0.02em;
}

.rollin-splash-loader {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--accent-pink);
    border-radius: 50%;
    animation: rollinSpin 900ms linear infinite;
}

/* =============================================================
   INSTALLED PWA — Ajustes quando o app está instalado
   ============================================================= */

@media all and (display-mode: standalone) {
    /* Esconde header desktop completamente, usa só mobile header */
    #header:not(.rollin-mobile-header),
    .header.navbar-expand-lg:not(.rollin-mobile-header) {
        display: none !important;
    }

    /* Esconde footer no app */
    footer,
    #footer,
    .footer {
        display: none !important;
    }

    /* Body não tem scroll-bounce visual */
    html, body {
        overscroll-behavior: none;
    }
}

/* =============================================================
   DARK MODE explicit (usuário do sistema)
   O tema já é dark por padrão, mas garantimos
   ============================================================= */

@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;
    }
}

/* =============================================================
   INSTALL BANNER (convite pra instalar como app)
   ============================================================= */

.rollin-install-banner {
    position: fixed;
    top: calc(var(--safe-top) + 8px);
    left: 8px;
    right: 8px;
    z-index: 9997;
    background: var(--gradient-primary);
    color: white;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    display: none;
    align-items: center;
    gap: 12px;
    box-shadow: var(--shadow-lg);
    animation: rollinInstallIn 500ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.rollin-install-banner.show {
    display: flex;
}

@keyframes rollinInstallIn {
    from { transform: translateY(-100px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.rollin-install-banner i:first-child {
    font-size: 24px;
    flex-shrink: 0;
}

.rollin-install-content {
    flex: 1;
    font-size: var(--fs-sm);
    line-height: 1.3;
}

.rollin-install-content strong {
    display: block;
    font-size: var(--fs-base);
    margin-bottom: 2px;
}

.rollin-install-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.rollin-install-btn {
    padding: 8px 16px;
    background: white;
    color: var(--rollin-purple-800);
    border: none;
    border-radius: var(--radius-full);
    font-size: var(--fs-xs);
    font-weight: 700;
    cursor: pointer;
    transition: transform var(--transition-fast);
}

.rollin-install-btn:active {
    transform: scale(0.95);
}

.rollin-install-dismiss {
    padding: 8px;
    background: transparent;
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    opacity: 0.8;
}

/* =============================================================
   LANDSCAPE MOBILE — ajustes
   ============================================================= */

@media (max-width: 991px) and (orientation: landscape) and (max-height: 500px) {
    .rollin-dashboard-hero {
        padding: var(--space-sm) 0;
    }
    .rollin-hero-card {
        padding: var(--space-md) !important;
    }
    #rollin-ai-panel {
        height: calc(100vh - 80px) !important;
    }
}
