/* ==========================================================================
   Arcavio PWA & Mobile View Optimization Stylesheet
   Obsidian & Electric Indigo Design System
   ========================================================================== */

:root {
    --pwa-primary: #6366f1;
    --pwa-primary-hover: #4f46e5;
    --pwa-gradient: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
    --pwa-card-bg: rgba(15, 23, 42, 0.92);
    --pwa-border: rgba(99, 102, 241, 0.3);
    --pwa-glow: 0 10px 30px -5px rgba(99, 102, 241, 0.35);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top: env(safe-area-inset-top, 0px);
}

/* --------------------------------------------------------------------------
   1. Mobile Viewport & Touch Optimization Fixes
   -------------------------------------------------------------------------- */
html, body {
    overflow-x: hidden !important;
    max-width: 100vw;
    -webkit-tap-highlight-color: rgba(99, 102, 241, 0.15);
}

/* Prevent auto-zoom on iOS when tapping form fields */
@media screen and (max-width: 767px) {
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="search"],
    input[type="tel"],
    input[type="number"],
    select,
    textarea {
        font-size: 16px !important;
    }
}

/* Responsive logo scaling for mobile header */
@media (max-width: 768px) {
    .tv-header .header-logo img,
    .sticky-header .header-logo img {
        height: 44px !important;
        width: auto !important;
        transition: height 0.2s ease;
    }
    
    .tv-header.header-style2 .menu-area {
        padding-top: 10px !important;
        padding-bottom: 10px !important;
    }
    
    .sticky-header .menu-area {
        padding-top: 8px !important;
        padding-bottom: 8px !important;
    }

    /* Polish hamburger button touch target */
    .menu-toggle.sidebar-btn {
        width: 44px !important;
        height: 44px !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        border-radius: 10px !important;
        background: rgba(255, 255, 255, 0.05) !important;
        border: 1px solid rgba(255, 255, 255, 0.1) !important;
    }
}

/* Mobile Menu Area Polish: wider drawer on small screens & safe area support */
@media (max-width: 575.98px) {
    .mobile-menu-wrapper .mobile-menu-area {
        width: 86vw !important;
        max-width: 320px !important;
        padding-bottom: calc(30px + var(--safe-bottom)) !important;
    }

    .mobile-menu-wrapper .mobile-logo img {
        height: 38px !important;
    }
}

/* --------------------------------------------------------------------------
   2. PWA Buttons in Header & Drawer
   -------------------------------------------------------------------------- */

/* Header Install Button (Desktop) */
.pwa-header-install-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 16px;
    border-radius: 999px;
    background: rgba(99, 102, 241, 0.12);
    border: 1px solid rgba(99, 102, 241, 0.35);
    color: #e0e7ff !important;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.2px;
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(8px);
}

.pwa-header-install-btn i {
    color: #818cf8;
    font-size: 13px;
    transition: transform 0.3s ease;
}

.pwa-header-install-btn:hover {
    background: var(--pwa-gradient);
    color: #ffffff !important;
    border-color: transparent;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
    transform: translateY(-1px);
}

.pwa-header-install-btn:hover i {
    color: #ffffff;
    transform: translateY(1px);
}

/* Header Install Button (Mobile Pill) */
.pwa-mobile-header-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 20px;
    background: var(--pwa-gradient);
    border: none;
    color: #ffffff !important;
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
    box-shadow: 0 2px 10px rgba(99, 102, 241, 0.35);
    cursor: pointer;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.pwa-mobile-header-btn i {
    font-size: 11px;
}

.pwa-mobile-header-btn:active {
    transform: scale(0.96);
}

/* Drawer Install Button */
.mobile-install-btn {
    width: 100%;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 8px !important;
    padding: 13px 20px !important;
    border-radius: 999px !important;
    background: var(--pwa-gradient) !important;
    color: #ffffff !important;
    font-size: 14px !important;
    font-weight: 700 !important;
    border: none !important;
    box-shadow: 0 4px 18px rgba(99, 102, 241, 0.35) !important;
    margin-top: 4px;
    transition: all 0.3s ease !important;
}

.mobile-install-btn i {
    font-size: 15px;
}

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

/* --------------------------------------------------------------------------
   3. Floating Mobile PWA Install Banner / Bottom Sheet
   -------------------------------------------------------------------------- */
.pwa-install-banner {
    position: fixed;
    bottom: calc(16px + var(--safe-bottom));
    left: 14px;
    right: 14px;
    max-width: 440px;
    margin: 0 auto;
    z-index: 99998;
    background: var(--pwa-card-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--pwa-border);
    border-radius: 18px;
    padding: 12px 14px;
    box-shadow: 0 16px 40px -10px rgba(0, 0, 0, 0.75), 0 0 24px rgba(99, 102, 241, 0.25);
    animation: pwaBannerSlideUp 0.45s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes pwaBannerSlideUp {
    from {
        transform: translateY(120%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.pwa-install-banner.pwa-banner-dismissing {
    animation: pwaBannerSlideDown 0.35s ease forwards;
}

@keyframes pwaBannerSlideDown {
    from {
        transform: translateY(0);
        opacity: 1;
    }
    to {
        transform: translateY(120%);
        opacity: 0;
    }
}

.pwa-banner-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.pwa-banner-icon {
    width: 46px;
    height: 46px;
    border-radius: 12px;
    object-fit: cover;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    background: #020617;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.pwa-banner-text {
    flex: 1;
    min-width: 0;
}

.pwa-banner-title {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    font-weight: 700;
    color: #ffffff;
    margin: 0 0 2px 0;
    line-height: 1.2;
}

.pwa-banner-badge {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 2px 6px;
    border-radius: 6px;
    background: rgba(99, 102, 241, 0.25);
    color: #a5b4fc;
    border: 1px solid rgba(99, 102, 241, 0.4);
}

.pwa-banner-desc {
    font-size: 12px;
    color: #94a3b8;
    margin: 0;
    line-height: 1.35;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pwa-banner-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.pwa-banner-action-btn {
    background: var(--pwa-gradient);
    border: none;
    color: #ffffff;
    padding: 7px 16px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.2px;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(99, 102, 241, 0.4);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.pwa-banner-action-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.6);
}

.pwa-banner-close-btn {
    background: transparent;
    border: none;
    color: #64748b;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0;
}

.pwa-banner-close-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
}

/* Adjust scroll-to-top button on mobile so it doesn't get obscured */
@media (max-width: 768px) {
    .scrollToTop {
        bottom: calc(76px + var(--safe-bottom)) !important;
        right: 18px !important;
        width: 44px !important;
        height: 44px !important;
        line-height: 44px !important;
    }
}

/* --------------------------------------------------------------------------
   4. iOS Safari Guided Install Modal
   -------------------------------------------------------------------------- */
.pwa-ios-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.8);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 100000;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    animation: pwaFadeIn 0.3s ease forwards;
}

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

.pwa-ios-sheet {
    width: 100%;
    max-width: 480px;
    background: #0f172a;
    border: 1px solid rgba(99, 102, 241, 0.3);
    border-radius: 24px 24px 0 0;
    padding: 24px 22px calc(24px + var(--safe-bottom)) 22px;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.7);
    color: #ffffff;
    animation: pwaSheetSlideUp 0.35s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

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

.pwa-ios-handle {
    width: 44px;
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.2);
    margin: 0 auto 18px auto;
}

.pwa-ios-header {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 20px;
}

.pwa-ios-header img {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}

.pwa-ios-title h4 {
    margin: 0 0 4px 0;
    font-size: 18px;
    font-weight: 700;
    color: #ffffff;
}

.pwa-ios-title p {
    margin: 0;
    font-size: 13px;
    color: #94a3b8;
}

.pwa-ios-steps {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-bottom: 24px;
}

.pwa-ios-step {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.pwa-ios-step-num {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: rgba(99, 102, 241, 0.25);
    border: 1px solid rgba(99, 102, 241, 0.5);
    color: #c7d2fe;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
}

.pwa-ios-step-text {
    font-size: 13px;
    line-height: 1.5;
    color: #cbd5e1;
}

.pwa-ios-step-text strong {
    color: #ffffff;
}

.pwa-ios-icon-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 1px 6px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.12);
    color: #38bdf8;
    margin: 0 2px;
}

.pwa-ios-btn-close {
    width: 100%;
    padding: 13px;
    border-radius: 14px;
    background: var(--pwa-gradient);
    border: none;
    color: #ffffff;
    font-weight: 700;
    font-size: 15px;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
    transition: transform 0.2s ease;
}

.pwa-ios-btn-close:active {
    transform: scale(0.98);
}

/* --------------------------------------------------------------------------
   5. Standalone App Polish (when running installed on phone or desktop)
   -------------------------------------------------------------------------- */
body.is-pwa-standalone {
    user-select: none;
}

/* Extra safe-area padding in standalone mode */
body.is-pwa-standalone .tv-header {
    padding-top: var(--safe-top);
}

body.is-pwa-standalone .pwa-install-banner,
body.is-pwa-standalone .pwa-install-trigger {
    display: none !important;
}

/* --------------------------------------------------------------------------
   6. Comprehensive Mobile View & Layout Responsiveness Polish
   -------------------------------------------------------------------------- */

/* Remove harsh 30px lateral margins on mobile devices to prevent content squeezing */
@media (max-width: 768px) {
    .mx-30,
    .-mx-30,
    .hero-inner.mx-30,
    .brand-inner.mx-30 {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    .container {
        padding-left: 16px !important;
        padding-right: 16px !important;
    }

    /* Polish section titles on mobile */
    .sec-title {
        word-wrap: break-word;
        hyphens: auto;
    }
}

/* Signal Lab interactive panel mobile polish */
@media (max-width: 575.98px) {
    .signal-lab-panel {
        padding: 1rem 0.85rem !important;
        border-radius: 16px !important;
    }

    .signal-lab-chart-wrap canvas {
        height: 180px !important;
    }

    .signal-lab-regime-pills {
        gap: 6px !important;
        justify-content: flex-start !important;
    }

    .signal-lab-pill {
        padding: 5px 10px !important;
        font-size: 11px !important;
    }

    .signal-lab-score-bars {
        grid-template-columns: 1fr !important;
        gap: 8px !important;
    }

    .signal-lab-consensus-action {
        font-size: 1.65rem !important;
    }

    .signal-lab-stat {
        padding: 10px 6px !important;
    }

    .signal-lab-stat-value {
        font-size: 1.15rem !important;
    }
}

/* Prevent accidental horizontal overflow from long words/links in tables and text */
.table-responsive {
    -webkit-overflow-scrolling: touch;
    overflow-x: auto;
}

/* Smooth touch scrolling */
* {
    -webkit-overflow-scrolling: touch;
}
