/* ==========================================================================
   Avix Treims - Progressive Web Application & Mobile App Theme
   Styles for Standalone Mode, Safe Area Insets, App Navigation, and Prompts
   ========================================================================== */

/* 1. Universal Touch & Mobile App Foundations */
html.pwa-standalone-active,
body.pwa-standalone-active,
@media (display-mode: standalone) {
    /* Prevent accidental pull-to-refresh bounce in standalone mode */
    overscroll-behavior-y: contain;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

/* Standalone Full-Height Fix for iOS Safari & Android WebViews */
html.pwa-standalone-active,
body.pwa-standalone-active {
    min-height: 100vh;
    min-height: -webkit-fill-available;
    min-height: 100dvh;
}

/* Standalone Safe Area Inset Support (Notch & Home Bar) */
@supports (padding-top: env(safe-area-inset-top)) {
    body.pwa-standalone-active header,
    body.pwa-standalone-active .navbar,
    body.pwa-standalone-active .mobile-top-bar {
        padding-top: max(14px, env(safe-area-inset-top)) !important;
    }

    body.pwa-standalone-active .app-main {
        padding-bottom: calc(90px + env(safe-area-inset-bottom)) !important;
    }
}

/* Smooth Tap Response */
a, button, input, select, textarea {
    touch-action: manipulation;
}

/* UI Elements: Prevent Text Selection in App Mode */
body.pwa-standalone-active .sidebar-nav,
body.pwa-standalone-active .mobile-top-bar,
body.pwa-standalone-active .pwa-mobile-nav,
body.pwa-standalone-active .btn,
body.pwa-standalone-active .icon-btn-round {
    user-select: none;
    -webkit-user-select: none;
}

/* 2. Floating Mobile App Install Banner */
.pwa-install-banner {
    position: fixed;
    bottom: max(18px, env(safe-area-inset-bottom));
    left: 16px;
    right: 16px;
    max-width: 480px;
    margin: 0 auto;
    background: linear-gradient(135deg, rgba(14, 22, 17, 0.96) 0%, rgba(9, 14, 11, 0.98) 100%);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(204, 255, 0, 0.3);
    border-radius: 20px;
    padding: 14px 18px;
    display: none;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.75), 0 0 24px rgba(204, 255, 0, 0.15);
    z-index: 99999;
    animation: pwaSlideUp 0.35s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

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

.pwa-install-content {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

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

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

.pwa-banner-title {
    font-weight: 800;
    font-size: 0.95rem;
    color: #ffffff;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pwa-banner-sub {
    font-size: 0.76rem;
    color: #94a3b8;
    line-height: 1.25;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

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

.pwa-install-btn {
    background: #ccff00;
    color: #000000;
    font-weight: 700;
    font-size: 0.82rem;
    border: none;
    border-radius: 999px;
    padding: 8px 16px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
    box-shadow: 0 4px 14px rgba(204, 255, 0, 0.35);
}

.pwa-install-btn:hover,
.pwa-install-btn:active {
    background: #d8ff33;
    transform: scale(0.97);
}

.pwa-close-btn {
    background: rgba(255, 255, 255, 0.08);
    color: #94a3b8;
    border: none;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

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

/* 3. iOS Add to Home Screen Modal Instruction */
.pwa-ios-modal-overlay,
.pwa-android-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.78);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 100000;
    display: none;
    align-items: flex-end;
    justify-content: center;
}

.pwa-ios-modal,
.pwa-android-modal {
    background: #0f1612;
    border: 1px solid rgba(204, 255, 0, 0.35);
    border-bottom: none;
    border-radius: 26px 26px 0 0;
    width: 100%;
    max-width: 520px;
    padding: 24px 22px calc(24px + env(safe-area-inset-bottom)) 22px;
    color: #ffffff;
    box-shadow: 0 -12px 50px rgba(0, 0, 0, 0.9), 0 0 30px rgba(204, 255, 0, 0.12);
    animation: pwaSlideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.pwa-ios-modal-header,
.pwa-android-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 18px;
}

.pwa-ios-modal-title,
.pwa-android-modal-title {
    font-size: 1.15rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    gap: 10px;
    color: #ffffff;
}

.pwa-ios-step,
.pwa-android-step {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    margin-bottom: 14px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    padding: 13px 15px;
    border-radius: 16px;
}

.pwa-ios-step-num,
.pwa-android-step-num {
    background: #ccff00;
    color: #000;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.82rem;
    flex-shrink: 0;
    box-shadow: 0 0 10px rgba(204, 255, 0, 0.4);
}

.pwa-ios-step-text,
.pwa-android-step-text {
    font-size: 0.88rem;
    line-height: 1.45;
    color: #e2e8f0;
}

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

.ios-safari-arrow-indicator {
    text-align: center;
    margin-top: 14px;
    margin-bottom: 8px;
    font-size: 0.84rem;
    color: #38bdf8;
    font-weight: 700;
    animation: bounceDown 1.2s infinite ease-in-out;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

@keyframes bounceDown {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(6px); }
}

/* ==========================================================================
   5. Dedicated In-Dashboard "Install Mobile App" Card
   ========================================================================== */
.pwa-dashboard-install-card {
    background: linear-gradient(135deg, rgba(20, 28, 23, 0.95) 0%, rgba(13, 19, 15, 0.98) 100%);
    border: 1px solid rgba(204, 255, 0, 0.35);
    border-radius: 20px;
    padding: 16px 18px;
    margin-bottom: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4), 0 0 20px rgba(204, 255, 0, 0.12);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    position: relative;
    overflow: hidden;
    animation: pwaFadeIn 0.35s ease;
}

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

.pwa-dash-left {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.pwa-dash-icon-box {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    overflow: hidden;
    flex-shrink: 0;
    border: 1px solid rgba(204, 255, 0, 0.4);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
    background: #090e0b;
}

.pwa-dash-icon-box img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.pwa-dash-info {
    min-width: 0;
}

.pwa-dash-title {
    font-weight: 800;
    font-size: 0.98rem;
    color: #ffffff;
    display: flex;
    align-items: center;
    gap: 8px;
    line-height: 1.2;
}

.pwa-dash-pill {
    font-size: 0.65rem;
    font-weight: 800;
    background: rgba(204, 255, 0, 0.15);
    color: var(--primary-accent, #ccff00);
    border: 1px solid rgba(204, 255, 0, 0.35);
    padding: 2px 7px;
    border-radius: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.pwa-dash-sub {
    font-size: 0.78rem;
    color: #94a3b8;
    margin-top: 3px;
    line-height: 1.3;
}

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

.pwa-dash-btn {
    background: var(--primary-accent, #ccff00);
    color: #000000;
    font-weight: 800;
    font-size: 0.84rem;
    border: none;
    border-radius: 12px;
    padding: 10px 18px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 4px 15px rgba(204, 255, 0, 0.35);
    transition: all 0.2s ease;
    white-space: nowrap;
}

.pwa-dash-btn:hover,
.pwa-dash-btn:active {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(204, 255, 0, 0.5);
}

.pwa-dash-close {
    background: rgba(255, 255, 255, 0.08);
    color: #94a3b8;
    border: none;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.15rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.pwa-dash-close:hover {
    background: rgba(255, 255, 255, 0.16);
    color: #ffffff;
}

/* Hide install UI completely when running in installed standalone app */
.pwa-standalone-active .pwa-dashboard-install-card,
.pwa-standalone-active .pwa-install-banner,
.pwa-standalone-active .pwa-install-nav-item,
.pwa-standalone-active .pwa-mobile-header-btn {
    display: none !important;
}

@media (max-width: 600px) {
    .pwa-dashboard-install-card {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        padding: 14px 16px;
    }

    .pwa-dash-actions {
        width: 100%;
        justify-content: space-between;
    }

    .pwa-dash-btn {
        flex: 1;
        justify-content: center;
        padding: 11px;
    }
}

/* 4. Native Mobile App Bottom Navigation Dock (Dashboard) */
.pwa-mobile-dock {
    display: none;
}

@media (max-width: 900px), (display-mode: standalone) {
    .pwa-mobile-dock {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: calc(64px + env(safe-area-inset-bottom));
        padding-bottom: env(safe-area-inset-bottom);
        background: rgba(12, 17, 14, 0.94);
        backdrop-filter: blur(18px);
        -webkit-backdrop-filter: blur(18px);
        border-top: 1px solid rgba(255, 255, 255, 0.09);
        z-index: 995;
        align-items: center;
        justify-content: space-around;
        box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.5);
    }

    .pwa-dock-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 4px;
        color: #7d8f85;
        text-decoration: none;
        flex: 1;
        height: 100%;
        padding: 6px 0;
        transition: all 0.2s ease;
        position: relative;
    }

    .pwa-dock-item i {
        font-size: 1.15rem;
        transition: transform 0.2s ease, color 0.2s ease;
    }

    .pwa-dock-item span {
        font-size: 0.68rem;
        font-weight: 600;
        letter-spacing: -0.2px;
        transition: color 0.2s ease;
    }

    .pwa-dock-item.active {
        color: #ccff00;
    }

    .pwa-dock-item.active i {
        color: #ccff00;
        transform: translateY(-2px);
    }

    .pwa-dock-item.active::after {
        content: '';
        position: absolute;
        bottom: calc(4px + env(safe-area-inset-bottom));
        width: 16px;
        height: 3px;
        background: #ccff00;
        border-radius: 99px;
        box-shadow: 0 0 8px #ccff00;
    }

    .pwa-dock-item:active {
        transform: scale(0.92);
    }

    /* Adjust floating WhatsApp icon so it floats above the bottom dock */
    .app-container ~ a[title*="WhatsApp"],
    body a[href*="wa.me"] {
        bottom: calc(76px + env(safe-area-inset-bottom)) !important;
    }
}
