/**
 * =============================================================================
 * Pocket Solutions - Ultra Mobile Architecture (iOS & Android 100% Certified)
 * Native App-Like Responsiveness, Zero Horizontal Scrolling, Safe-Area Support
 * =============================================================================
 */

/* 1. Global Viewport & Touch Ergonomics */
html, body {
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden !important;
    position: relative;
    -webkit-text-size-adjust: 100%;
    overscroll-behavior-x: none;
    -webkit-tap-highlight-color: transparent;
}

body.sidebar-locked {
    overflow: hidden !important;
    touch-action: none;
}

/* Visibility Utilities */
.hide-mobile {
    display: inherit;
}
.show-mobile {
    display: none;
}

/* 2. Mobile Bottom Navigation Bar (iOS Safe Area & Android Nav Bar Aware) */
.mobile-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(62px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: #ffffff;
    border-top: 1px solid var(--border-subtle);
    z-index: 999;
    justify-content: space-around;
    align-items: center;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
    box-shadow: 0 -4px 18px rgba(0, 0, 0, 0.06);
    backdrop-filter: blur(12px);
}

.mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-dim);
    font-size: 0.72rem;
    font-weight: 600;
    text-decoration: none;
    padding: 0.35rem 0.65rem;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    gap: 0.2rem;
    min-width: 52px;
    touch-action: manipulation;
}

.mobile-nav-item svg, .mobile-nav-item i {
    font-size: 1.25rem;
    width: 20px;
    height: 20px;
}

.mobile-nav-item.active, .mobile-nav-item:hover {
    color: var(--primary);
}

/* 3. Mobile Sidebar Backdrop & Drawer Overlay */
.sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 95;
    opacity: 0;
    transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.sidebar-backdrop.active {
    display: block;
    opacity: 1;
}

.sidebar-close-btn {
    display: none;
    background: #f1f5f9;
    border: 1px solid var(--border-subtle);
    color: var(--text-main);
    border-radius: var(--radius-sm);
    padding: 0.35rem 0.55rem;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    touch-action: manipulation;
}

.sidebar-close-btn:hover {
    background: #e2e8f0;
}

/* 4. Phone Screen Optimizations (< 992px Tablet / Mobile) */
@media (max-width: 992px) {
    .hide-mobile {
        display: none !important;
    }

    .show-mobile {
        display: inline-flex !important;
    }

    /* Admin Sidebar Drawer Animation */
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.32s cubic-bezier(0.16, 1, 0.3, 1);
        z-index: 100;
        box-shadow: none;
        width: 285px;
        max-width: 85vw;
    }

    .sidebar.open {
        transform: translateX(0) !important;
        box-shadow: 4px 0 28px rgba(0, 0, 0, 0.22);
    }

    .sidebar-header {
        justify-content: space-between;
    }

    .customer-nav {
        display: none !important;
    }

    .main-content {
        margin-left: 0 !important;
        max-width: 100vw !important;
        width: 100% !important;
    }

    .menu-toggle {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        width: 38px;
        height: 38px;
        min-height: 38px;
        touch-action: manipulation;
    }
}

/* 5. Mobile Handset Optimizations (< 768px iOS / Android Phones) */
@media (max-width: 768px) {
    /* Touch Targets & iOS Zoom Prevention (16px avoids auto-zoom in Safari) */
    .form-control, .form-select, textarea.form-control {
        font-size: 16px !important;
        min-height: 44px;
        border-radius: var(--radius-md);
        box-sizing: border-box;
        max-width: 100%;
    }

    .btn {
        min-height: 44px;
        padding: 0.65rem 1.15rem;
        touch-action: manipulation;
    }

    .btn-sm {
        min-height: 38px;
        padding: 0.45rem 0.85rem;
    }

    .mobile-nav {
        display: flex;
    }

    body {
        padding-bottom: calc(76px + env(safe-area-inset-bottom, 0px)) !important;
    }

    .container {
        padding: 0 0.85rem;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    .topbar {
        min-height: 56px !important;
        height: auto !important;
        padding: 0.55rem 0.75rem !important;
        width: 100% !important;
        max-width: 100vw !important;
        box-sizing: border-box !important;
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        gap: 0.5rem !important;
        position: sticky !important;
        top: 0 !important;
        z-index: 90 !important;
        background: rgba(255, 255, 255, 0.98) !important;
        backdrop-filter: blur(12px) !important;
        border-bottom: 1px solid var(--border-subtle) !important;
    }

    .topbar > div:first-child, .topbar .topbar-left {
        display: flex !important;
        align-items: center !important;
        gap: 0.5rem !important;
        min-width: 0 !important;
        flex: 1 1 auto !important;
    }

    .page-title {
        min-width: 0 !important;
        flex: 1 1 auto !important;
    }

    .page-title h1 {
        font-size: 1.05rem !important;
        font-weight: 700 !important;
        line-height: 1.25 !important;
        margin: 0 !important;
        max-width: 100% !important;
        word-break: break-word !important;
        overflow-wrap: anywhere !important;
        color: var(--text-main) !important;
    }

    .page-title > span:not(.greeting-badge),
    .page-title > p,
    .page-title > small {
        display: none !important;
    }

    .topbar .btn {
        min-height: 34px !important;
        height: 34px !important;
        padding: 0.35rem 0.6rem !important;
        font-size: 0.78rem !important;
        flex-shrink: 0 !important;
        white-space: nowrap !important;
        gap: 0.3rem !important;
    }

    .topbar .btn svg, .topbar .btn i {
        width: 14px !important;
        height: 14px !important;
    }

    .topbar-actions {
        display: flex !important;
        align-items: center !important;
        gap: 0.4rem !important;
        flex-shrink: 0 !important;
    }

    .content-body {
        padding: 1rem 0.75rem !important;
        width: 100% !important;
        max-width: 100vw !important;
        box-sizing: border-box;
    }

    .card {
        padding: 1.1rem 0.9rem !important;
        border-radius: var(--radius-md);
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box;
    }

    .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.65rem;
    }

    .profile-card {
        flex-direction: column;
        text-align: center;
        gap: 1rem;
        padding: 1.25rem 1rem !important;
    }

    .profile-meta {
        justify-content: center;
        flex-wrap: wrap;
    }

    .license-banner {
        flex-direction: column;
        align-items: flex-start;
        gap: 1.25rem;
        padding: 1.25rem 1rem !important;
    }

    .license-banner .btn {
        width: 100%;
    }

    /* Table Mobile Card Transformation (Zero horizontal scroll on phone) */
    .table-responsive {
        overflow-x: visible;
        width: 100% !important;
        max-width: 100% !important;
    }

    .table-mobile-cards {
        display: block;
        width: 100% !important;
        max-width: 100% !important;
        border: none;
    }

    .table-mobile-cards thead {
        display: none !important;
    }

    .table-mobile-cards tbody {
        display: block;
        width: 100% !important;
    }

    .table-mobile-cards tr {
        display: block;
        margin-bottom: 0.85rem;
        background: #ffffff;
        border: 1px solid var(--border-subtle);
        border-radius: var(--radius-md);
        padding: 0.85rem 1rem;
        box-shadow: var(--shadow-sm);
        width: 100% !important;
        box-sizing: border-box;
    }

    .table-mobile-cards td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        border-bottom: 1px solid #f1f5f9;
        padding: 0.55rem 0;
        font-size: 0.85rem;
        word-break: break-word;
        overflow-wrap: anywhere;
        min-width: 0;
        width: 100%;
        box-sizing: border-box;
    }

    .table-mobile-cards td:last-child {
        border-bottom: none;
        padding-top: 0.75rem;
        justify-content: flex-end;
        flex-wrap: wrap;
        gap: 0.35rem;
    }

    .table-mobile-cards td::before {
        content: attr(data-label);
        font-weight: 700;
        color: var(--text-dim);
        font-size: 0.72rem;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        margin-right: 0.75rem;
        text-align: left;
        flex-shrink: 0;
        max-width: 42%;
    }

    .filter-bar {
        flex-direction: column !important;
        align-items: stretch !important;
        padding: 0.75rem !important;
        gap: 0.65rem !important;
    }

    .filter-bar > div, .filter-bar .filter-search, .filter-bar select, .filter-bar input, .filter-bar .btn {
        width: 100% !important;
        min-width: 100% !important;
    }

    /* Landing Page Mobile Fixes */
    .landing-header {
        padding: 0.5rem 0 !important;
    }

    .landing-header-inner {
        padding: 0 0.75rem !important;
    }

    .landing-logo {
        height: 30px !important;
        max-width: 115px !important;
    }

    .landing-actions .btn {
        min-height: 34px !important;
        height: 34px !important;
        padding: 0.35rem 0.55rem !important;
        font-size: 0.76rem !important;
        gap: 0.25rem !important;
    }

    .landing-hero-wrap {
        margin: 1.5rem auto 2rem !important;
        padding: 0 0.5rem !important;
    }

    .landing-hero-title {
        font-size: 1.65rem !important;
        line-height: 1.25 !important;
        margin-bottom: 0.85rem !important;
    }

    .landing-hero-desc {
        font-size: 0.88rem !important;
        line-height: 1.5 !important;
        margin-bottom: 1.5rem !important;
    }

    .hero-btn-row {
        flex-direction: column !important;
        width: 100% !important;
        gap: 0.65rem !important;
    }

    .hero-btn-row .btn {
        width: 100% !important;
        min-height: 46px !important;
        font-size: 0.95rem !important;
        justify-content: center !important;
    }

    /* Metric KPI Cards in Single or 2-column Compact Grid */
    .metric-card {
        padding: 1.1rem;
    }

    .metric-card h3 {
        font-size: 1.45rem;
    }

    .query-tracker {
        overflow-x: auto;
        padding-bottom: 0.75rem;
        -webkit-overflow-scrolling: touch;
    }

    .track-step {
        min-width: 80px;
    }
}

/* 6. Extra Small Screens (< 420px iPhone SE, Galaxy Z Flip) */
@media (max-width: 420px) {
    .page-title h1 {
        font-size: 0.95rem !important;
    }

    .greeting-badge {
        font-size: 0.72rem !important;
        padding: 0.22rem 0.5rem !important;
    }

    .topbar {
        padding: 0.45rem 0.55rem !important;
    }

    .topbar .btn {
        padding: 0.3rem 0.48rem !important;
        font-size: 0.74rem !important;
    }

    .landing-logo {
        height: 26px !important;
        max-width: 100px !important;
    }

    .landing-actions .btn {
        padding: 0.28rem 0.45rem !important;
        font-size: 0.72rem !important;
    }

    .landing-hero-title {
        font-size: 1.45rem !important;
    }

    .card {
        padding: 0.85rem 0.7rem !important;
    }
}
