/**
 * TokoTrack Native Mobile PWA Stylesheet
 * 100% Native Mobile Feel for Apple (iOS), Android, and Huawei (HarmonyOS)
 */

:root {
    --pwa-safe-top: env(safe-area-inset-top, 0px);
    --pwa-safe-bottom: env(safe-area-inset-bottom, 0px);
    --pwa-safe-left: env(safe-area-inset-left, 0px);
    --pwa-safe-right: env(safe-area-inset-right, 0px);
    --pwa-primary: #008b9d;
    --pwa-accent: #ffc700;
}

/* ── 1. Global Elimination of Web Browser Artifacts ──────────────────── */
html, body {
    -webkit-tap-highlight-color: transparent !important;
    touch-action: manipulation;
    overscroll-behavior-y: contain;
}

/* Standalone / PWA Mode Fullscreen Optimization */
@media all and (display-mode: standalone) {
    body {
        user-select: none;
        -webkit-user-select: none;
        padding-top: var(--pwa-safe-top);
        padding-bottom: var(--pwa-safe-bottom);
    }
}

/* Allow text selection only where appropriate */
input, textarea, [contenteditable="true"], .selectable, article, .table td {
    user-select: text !important;
    -webkit-user-select: text !important;
}

/* Disable context menu callouts on interactive elements */
a, button, img, .btn, .nav-link, .pwa-pressable {
    -webkit-touch-callout: none !important;
}

/* ── 2. Native Micro-Press Feedback ───────────────────────────────────── */
.pwa-pressable,
.btn:not(:disabled),
.nav-link,
.card-action,
.dropdown-item,
.pwa-tab-item {
    transition: transform 0.09s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.09s ease;
    will-change: transform, opacity;
}

.pwa-pressable:active,
.btn:not(:disabled):active,
.nav-link:active,
.dropdown-item:active,
.pwa-tab-item:active {
    transform: scale(0.965) !important;
    opacity: 0.88 !important;
}

/* ── 3. Smooth Native Momentum Scrolling ──────────────────────────────── */
.pwa-scrollable,
.table-responsive,
.overflow-auto,
.overflow-scroll,
.sidebar,
#main-content {
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: thin;
}

/* ── 4. Huawei & Android System Gesture Guard ─────────────────────────── */
/* Prevents horizontal swipes near edge from conflicting with system back */
.gesture-safe-area {
    padding-left: max(16px, var(--pwa-safe-left));
    padding-right: max(16px, var(--pwa-safe-right));
}

/* ── 5. Mobile Native Bottom Navigation Bar ──────────────────────────── */
.pwa-bottom-bar {
    display: none;
}

@media (max-width: 991px), (display-mode: standalone) {
    body {
        padding-bottom: calc(72px + var(--pwa-safe-bottom)) !important;
    }

    .pwa-bottom-bar {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: calc(64px + var(--pwa-safe-bottom));
        padding-bottom: var(--pwa-safe-bottom);
        background: rgba(15, 23, 42, 0.92);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border-top: 1px solid rgba(255, 255, 255, 0.08);
        z-index: 1040;
        align-items: center;
        justify-content: space-around;
        box-shadow: 0 -8px 24px -4px rgba(0, 0, 0, 0.25);
    }

    .pwa-tab-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        text-decoration: none;
        color: #94a3b8;
        font-size: 11px;
        font-weight: 600;
        padding: 6px 0;
        position: relative;
    }

    .pwa-tab-item.active {
        color: #ffffff;
    }

    .pwa-tab-item.active .pwa-tab-icon {
        color: var(--pwa-accent);
        transform: translateY(-2px);
    }

    .pwa-tab-icon {
        font-size: 20px;
        margin-bottom: 2px;
        transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), color 0.2s ease;
    }

    .pwa-tab-item.active::after {
        content: '';
        position: absolute;
        bottom: calc(var(--pwa-safe-bottom) + 2px);
        width: 18px;
        height: 3px;
        border-radius: 2px;
        background: var(--pwa-accent);
    }
}

/* ── 6. Native Install Sheets (Android, Apple, Huawei) ────────────────── */
.pwa-sheet-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.pwa-sheet-backdrop.show {
    opacity: 1;
    pointer-events: auto;
}

.pwa-sheet-container {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    max-width: 500px;
    margin: 0 auto;
    background: #0f172a;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 28px 28px 0 0;
    padding: 24px 24px calc(24px + var(--pwa-safe-bottom));
    box-shadow: 0 -20px 40px rgba(0, 0, 0, 0.6);
    z-index: 10000;
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
    color: #ffffff;
}

.pwa-sheet-backdrop.show .pwa-sheet-container {
    transform: translateY(0);
}

.pwa-sheet-drag-handle {
    width: 38px;
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.2);
    margin: 0 auto 20px;
}

.pwa-app-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    background: rgba(0, 139, 157, 0.2);
    border: 1px solid rgba(0, 139, 157, 0.4);
    border-radius: 12px;
    color: #38bdf8;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.pwa-btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 14px 20px;
    background: linear-gradient(135deg, #008b9d, #0d9488);
    color: #ffffff;
    font-size: 15px;
    font-weight: 700;
    border-radius: 16px;
    border: none;
    cursor: pointer;
    box-shadow: 0 8px 20px -4px rgba(0, 139, 157, 0.4);
}

.pwa-btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 12px 20px;
    background: transparent;
    color: #94a3b8;
    font-size: 14px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    margin-top: 6px;
}

/* Apple iOS Instructions Box */
.pwa-step-box {
    background: rgba(30, 41, 59, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 18px;
    padding: 14px 16px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 14px;
}

.pwa-step-number {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--pwa-primary);
    color: #ffffff;
    font-weight: 800;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* ── 7. Floating Network Offline Toast ────────────────────────────────── */
.pwa-network-toast {
    position: fixed;
    top: max(16px, var(--pwa-safe-top));
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    z-index: 10500;
    padding: 10px 20px;
    border-radius: 30px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    font-weight: 700;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
    pointer-events: none;
}

.pwa-network-toast.show {
    transform: translateX(-50%) translateY(0);
}

.pwa-network-toast.offline {
    background: #0f172a;
    border: 1px solid rgba(239, 68, 68, 0.4);
    color: #fca5a5;
}

.pwa-network-toast.online {
    background: #064e3b;
    border: 1px solid rgba(52, 211, 153, 0.4);
    color: #a7f3d0;
}
