/**
 * ==============================================================================
 * 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 (< 768px Phones only) */
@media (max-width: 767px) {
    .dashboard__sidebar {
        position: fixed !important;
        top: 0 !important;
        bottom: 0 !important;
        left: 0 !important;
        width: 270px !important;
        max-width: 85vw !important;
        z-index: 1200 !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;
    }
}

/* ==============================================================================
 * 11. UNIVERSAL VIEWPORT-CONSTRAINED MODAL WITH INTERNAL BODY SCROLLING
 * Ensures every modal across the website fits within the screen height.
 * The modal-header and modal-footer remain strictly pinned while the
 * modal-body scrolls smoothly with custom sleek scrollbars.
 * ============================================================================== */

/* Prevent double scrollbar on the backdrop / outer window on standard screens */
@media (min-height: 480px) {
    .modal {
        overflow-y: hidden !important;
    }
}

/* Base Modal Dialog constraints */
.modal-dialog:not(.modal-fullscreen) {
    max-height: calc(100vh - 3rem) !important;
    max-height: calc(100dvh - 3rem) !important;
    margin-top: 1.5rem !important;
    margin-bottom: 1.5rem !important;
}

/* Centered modals: ensure vertical centering while capping height */
.modal-dialog.modal-dialog-centered:not(.modal-fullscreen) {
    min-height: calc(100% - 3rem) !important;
    min-height: calc(100dvh - 3rem) !important;
    max-height: calc(100% - 3rem) !important;
    max-height: calc(100dvh - 3rem) !important;
}

/* Modal Content Container: flex column layout capped at viewport */
.modal-dialog:not(.modal-fullscreen) .modal-content,
.modal-dialog:not(.modal-fullscreen) form.modal-content {
    display: flex !important;
    flex-direction: column !important;
    max-height: calc(100vh - 3rem) !important;
    max-height: calc(100dvh - 3rem) !important;
    overflow: hidden !important;
}

/* Direct Form wrapper inside .modal-content (e.g. confirmation & edit modals) */
.modal-dialog:not(.modal-fullscreen) .modal-content > form {
    display: flex !important;
    flex-direction: column !important;
    flex: 1 1 auto !important;
    min-height: 0 !important;
    max-height: 100% !important;
    overflow: hidden !important;
    margin-bottom: 0 !important;
    width: 100% !important;
}

/* Pinned Modal Header */
.modal-dialog:not(.modal-fullscreen) .modal-header {
    flex-shrink: 0 !important;
    position: relative;
    z-index: 2;
}

/* Pinned Modal Footer */
.modal-dialog:not(.modal-fullscreen) .modal-footer {
    flex-shrink: 0 !important;
    position: relative;
    z-index: 2;
}

/* Scrollable Modal Body */
.modal-dialog:not(.modal-fullscreen) .modal-body {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    overscroll-behavior: contain !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: thin;
    scrollbar-color: rgba(100, 116, 139, 0.4) transparent;
}

/* Sleek WebKit scrollbar styling for .modal-body */
.modal-dialog:not(.modal-fullscreen) .modal-body::-webkit-scrollbar {
    width: 6px;
}

.modal-dialog:not(.modal-fullscreen) .modal-body::-webkit-scrollbar-track {
    background: transparent;
}

.modal-dialog:not(.modal-fullscreen) .modal-body::-webkit-scrollbar-thumb {
    background: rgba(100, 116, 139, 0.35);
    border-radius: 10px;
}

.modal-dialog:not(.modal-fullscreen) .modal-body::-webkit-scrollbar-thumb:hover {
    background: rgba(100, 116, 139, 0.6);
}

/* Mobile & Small Screens Optimization (<= 576px) */
@media (max-width: 576px) {
    .modal-dialog:not(.modal-fullscreen) {
        max-height: calc(100vh - 1rem) !important;
        max-height: calc(100dvh - 1rem) !important;
        margin-top: 0.5rem !important;
        margin-bottom: 0.5rem !important;
        margin-left: auto !important;
        margin-right: auto !important;
        width: calc(100% - 1rem) !important;
    }
    
    .modal-dialog:not(.modal-fullscreen) .modal-content,
    .modal-dialog:not(.modal-fullscreen) form.modal-content {
        max-height: calc(100vh - 1rem) !important;
        max-height: calc(100dvh - 1rem) !important;
    }
    
    .modal-dialog.modal-dialog-centered:not(.modal-fullscreen) {
        min-height: calc(100% - 1rem) !important;
        min-height: calc(100dvh - 1rem) !important;
        max-height: calc(100% - 1rem) !important;
        max-height: calc(100dvh - 1rem) !important;
        margin-top: 0.5rem !important;
        margin-bottom: 0.5rem !important;
    }
}

/* ==============================================================================
 * 12. SITE-WIDE TITLE & INDIVIDUAL NAME CAPITALIZATION
 * Ensures titles and person names always start with capital letters cleanly,
 * without overriding explicit utility classes or altering emails/code blocks.
 * ============================================================================== */
h1, h2, h3, h4, h5, h6,
.card-title, .modal-title, .page-title, .section-title,
.os-suite-title, .user-fullname, .header-profile-name,
#profileName, #viewFullName, #viewDisplayName,
.user-name, .profile-name, .member-name, .lead-name,
.contact-name, .customer-name, .agent-name, .author-name {
    text-transform: capitalize;
}

h1 code, h2 code, h3 code, h4 code, h5 code, h6 code,
h1 pre, h2 pre, h3 pre, h4 pre, h5 pre, h6 pre,
h1 a[href^="mailto:"], h2 a[href^="mailto:"], h3 a[href^="mailto:"],
h4 a[href^="mailto:"], h5 a[href^="mailto:"], h6 a[href^="mailto:"],
.no-capitalize, [data-no-capitalize] {
    text-transform: none;
}
