/**
 * Vetmivo Phase 24: Mobile Hardening & Android WebView Styles
 */

:root {
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-left: env(safe-area-inset-left, 0px);
    --safe-area-right: env(safe-area-inset-right, 0px);
    --mobile-nav-height: 64px;
}

/* 1. Global Viewport & Safe Area Protection */
html, body {
    max-width: 100vw;
    overflow-x: hidden;
    -webkit-tap-highlight-color: transparent;
}

body {
    padding-top: var(--safe-area-top);
    padding-left: var(--safe-area-left);
    padding-right: var(--safe-area-right);
}

/* 2. Mobile Touch Targets & Inputs */
@media (max-width: 991.98px) {
    body {
        padding-bottom: calc(var(--mobile-nav-height) + var(--safe-area-bottom) + 16px);
    }

    .btn, .form-control, .form-select, .nav-link {
        min-height: 44px;
        font-size: 15px;
    }

    /* Prevent auto zoom on iOS/Android */
    input[type="text"],
    input[type="email"],
    input[type="tel"],
    input[type="number"],
    input[type="password"],
    select,
    textarea {
        font-size: 16px !important;
    }

    /* Hide desktop sidebar on mobile */
    .sidebar, .app-sidebar {
        display: none !important;
    }

    .app-main, .main-content {
        margin-left: 0 !important;
        width: 100% !important;
        max-width: 100vw !important;
        padding: 12px !important;
    }

    /* Controlled Table Scrolling */
    .table-responsive {
        width: 100%;
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin-bottom: 1rem;
        border-radius: 8px;
    }

    /* Mobile Modals */
    .modal-dialog {
        margin: 0.5rem auto;
        max-width: calc(100vw - 1rem) !important;
    }

    .modal-content {
        border-radius: 16px;
    }
}

/* 3. Mobile Bottom Navigation Bar */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--mobile-nav-height) + var(--safe-area-bottom));
    padding-bottom: var(--safe-area-bottom);
    background: #ffffff;
    border-top: 1px solid #e2e8f0;
    z-index: 1040;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.05);
}

@media (max-width: 991.98px) {
    .mobile-bottom-nav {
        display: flex;
        justify-content: space-around;
        align-items: center;
    }
}

.mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #64748b;
    text-decoration: none;
    font-size: 11px;
    font-weight: 500;
    min-width: 60px;
    min-height: 48px;
    border-radius: 8px;
    transition: color 0.15s ease-in-out;
}

.mobile-nav-item i, .mobile-nav-item svg {
    font-size: 20px;
    margin-bottom: 2px;
}

.mobile-nav-item.active {
    color: #0d9488;
    font-weight: 600;
}

.mobile-nav-item:hover, .mobile-nav-item:focus {
    color: #0f766e;
}

/* 4. Mobile Drawer Menu */
.mobile-drawer-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.5);
    z-index: 1050;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
    backdrop-filter: blur(2px);
}

.mobile-drawer-overlay.open {
    opacity: 1;
    visibility: visible;
}

.mobile-drawer-content {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 85vh;
    background: #ffffff;
    border-radius: 20px 20px 0 0;
    z-index: 1055;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    padding: 1.25rem 1rem calc(1rem + var(--safe-area-bottom)) 1rem;
    overflow-y: auto;
    box-shadow: 0 -10px 25px rgba(0, 0, 0, 0.15);
}

.mobile-drawer-overlay.open .mobile-drawer-content {
    transform: translateY(0);
}

.mobile-drawer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 0.75rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid #f1f5f9;
}

.mobile-drawer-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
}

.mobile-drawer-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0.85rem 0.5rem;
    background: #f8fafc;
    border-radius: 12px;
    color: #334155;
    text-decoration: none;
    font-size: 12px;
    font-weight: 500;
    text-align: center;
    border: 1px solid #e2e8f0;
    min-height: 72px;
}

.mobile-drawer-item i, .mobile-drawer-item svg {
    font-size: 22px;
    color: #0d9488;
    margin-bottom: 6px;
}

.mobile-drawer-item:hover, .mobile-drawer-item:active {
    background: #e6fffa;
    border-color: #99f6e4;
    color: #0f766e;
}

/* 5. WebView Specific Utility & Presentation Classes */
.webview-mode .mobile-pwa-banner,
.webview-mode .install-prompt {
    display: none !important;
}

.webview-only {
    display: none;
}

.webview-mode .webview-only {
    display: block;
}

/* 6. Offline Banner */
.offline-toast {
    position: fixed;
    top: var(--safe-area-top);
    left: 50%;
    transform: translateX(-50%);
    background: #ef4444;
    color: #ffffff;
    font-size: 13px;
    font-weight: 600;
    padding: 8px 16px;
    border-radius: 20px;
    z-index: 9999;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
    display: none;
}
