/**
 * ==============================================================================
 * UNIVERSAL MOBILE & TABLET RESPONSIVENESS CORE
 * Ctrl TASQ Multi-Channel Platform
 * ==============================================================================
 */

/* 1. Universal Zero Horizontal Overflow & Base Resets */
html, body {
    max-width: 100vw !important;
    overflow-x: hidden !important;
    position: relative;
    -webkit-text-size-adjust: 100%;
}

*, *::before, *::after {
    box-sizing: border-box;
}

/* 2. Fluid Media Scaling */
img, video, iframe, embed, object, canvas, svg {
    max-width: 100% !important;
    height: auto;
}

/* 3. Universal Table Responsiveness */
.table-responsive {
    width: 100% !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    margin-bottom: 1rem;
}

/* Ensure raw tables inside containers don't break layout on mobile */
@media (max-width: 768px) {
    table:not(.table-responsive table):not(.table-fixed) {
        display: block;
        width: 100% !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }
}

.table th, .table td, .wa-custom-table th, .wa-custom-table td {
    vertical-align: middle;
}

/* Action button clusters in tables */
.action-buttons, .table-action-buttons, .btn-action-group {
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
    flex-wrap: nowrap;
}

/* 4. Horizontal Scrollable Tab Bars & Navs on Mobile */
.nav-tabs, .nav-pills, .wa-nav-tabs, .sub-nav-tabs, .action-pill-bar, .scrollable-pills {
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    scroll-behavior: smooth;
    gap: 6px;
    padding-bottom: 6px !important;
    scrollbar-width: thin;
    scrollbar-color: rgba(138, 66, 255, 0.2) transparent;
}

.nav-tabs::-webkit-scrollbar, 
.nav-pills::-webkit-scrollbar, 
.wa-nav-tabs::-webkit-scrollbar,
.sub-nav-tabs::-webkit-scrollbar,
.action-pill-bar::-webkit-scrollbar,
.scrollable-pills::-webkit-scrollbar {
    height: 4px;
}

.nav-tabs::-webkit-scrollbar-thumb, 
.nav-pills::-webkit-scrollbar-thumb, 
.wa-nav-tabs::-webkit-scrollbar-thumb,
.sub-nav-tabs::-webkit-scrollbar-thumb,
.action-pill-bar::-webkit-scrollbar-thumb,
.scrollable-pills::-webkit-scrollbar-thumb {
    background: rgba(138, 66, 255, 0.25);
    border-radius: 4px;
}

.nav-tabs .nav-link, .nav-pills .nav-link, .wa-nav-tabs .nav-link {
    white-space: nowrap !important;
    flex-shrink: 0;
}

/* 5. Mobile Modals Optimization */
@media (max-width: 576px) {
    .modal-dialog {
        margin: 0.5rem !important;
        max-width: calc(100% - 1rem) !important;
    }
    
    .modal-content {
        border-radius: 16px !important;
    }
    
    .modal-body {
        max-height: 75vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 1rem !important;
    }
    
    .modal-header, .modal-footer {
        padding: 0.75rem 1rem !important;
    }
}

/* 6. Form Controls & Touch Targets */
@media (max-width: 768px) {
    .form-control, .form-select, .btn {
        min-height: 38px;
    }
    
    .btn-sm, .form-control-sm, .form-select-sm {
        min-height: 32px;
    }
    
    .input-group {
        flex-wrap: wrap;
    }
}

/* Prevent iOS input focus zoom */
@media screen and (max-width: 768px) {
    input[type="text"],
    input[type="number"],
    input[type="email"],
    input[type="tel"],
    input[type="search"],
    input[type="password"],
    input[type="url"],
    input[type="date"],
    select,
    textarea {
        font-size: 16px !important;
    }
}

/* 7. Card & Widget Grid Auto-Stacking */
@media (max-width: 768px) {
    .dashboard__wrapper {
        padding: 14px !important;
    }
    
    .dashboard__content {
        padding: 12px 0 !important;
    }
    
    .card {
        border-radius: 12px !important;
        margin-bottom: 14px;
    }
    
    .card-body {
        padding: 14px !important;
    }

    /* Stat Cards */
    .stat-card, .metric-card, .stats-box {
        margin-bottom: 12px;
    }
    
    /* Breadcrumbs & Page Titles */
    .page__header, .breadcrumb-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 8px;
        margin-bottom: 16px !important;
    }
}

/* 8. Dashboard Topbar Mobile Tuning */
@media (max-width: 768px) {
    .dashboard__header {
        padding: 8px 12px !important;
        min-height: 56px;
    }
    
    .header-balance-card {
        padding: 4px 8px !important;
        gap: 6px !important;
    }
    
    .balance-icon-wrap {
        width: 30px !important;
        height: 30px !important;
        font-size: 13px !important;
    }
    
    .header-icon-circle {
        width: 36px !important;
        height: 36px !important;
    }
    
    .notification-dropdown-menu, .header-profile-dropdown, .dropdown-menu {
        max-width: 92vw !important;
        width: 320px;
        right: 0 !important;
        left: auto !important;
    }
}

@media (max-width: 480px) {
    .dashboard__header__widgets {
        gap: 6px !important;
    }
    
    .btn-product-tour-trigger span,
    .header-action-pill span:not(.badge) {
        display: none !important;
    }
}

/* 9. Sidebar Mobile Overlay & Transitions */
@media (max-width: 991px) {
    .dashboard__sidebar {
        position: fixed !important;
        top: 0 !important;
        bottom: 0 !important;
        left: 0 !important;
        width: 270px !important;
        max-width: 85vw !important;
        z-index: 1100 !important;
        transform: translateX(-100%) !important;
        transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1) !important;
        box-shadow: 0 0 30px rgba(0,0,0,0.25) !important;
        height: 100vh !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    .dashboard__sidebar.active {
        transform: translateX(0) !important;
    }
    
    .sidebar__close {
        display: flex !important;
        position: absolute;
        top: 15px;
        right: 15px;
        width: 34px;
        height: 34px;
        align-items: center;
        justify-content: center;
        background: rgba(255,255,255,0.1);
        border-radius: 50%;
        color: #fff;
        cursor: pointer;
        z-index: 10;
    }
    
    .sidebar__open {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        font-size: 20px;
    }
    
    .overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(15, 23, 42, 0.6);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
        z-index: 1090;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
    }
    
    .overlay.active {
        opacity: 1;
        visibility: visible;
    }
}

/* 10. Floating Quick Actions / Helpers on Mobile */
@media (max-width: 576px) {
    .btn-group-responsive {
        display: flex;
        flex-direction: column;
        width: 100%;
        gap: 6px;
    }
    
    .btn-group-responsive .btn {
        width: 100%;
        border-radius: 8px !important;
    }
}
