/* ===== Mobile Sidebar Drawer ===== */
.mobile-sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1040;
    backdrop-filter: blur(2px);
}

.mobile-sidebar-overlay.active {
    display: block;
}

@media (max-width: 900px) {
    .mobile-menu-btn {
        display: inline-flex;
    }

    .sidebar {
        position: fixed;
        left: -270px;
        margin-left: 0 !important;
        /* .app-footer-bar is 1050 too: coming before it in the DOM, it stayed
           underneath at the same z-index and cut off the user badge. An open
           menu must always be on top. */
        z-index: 1060;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .sidebar.mobile-open {
        left: 0;
        margin-left: 0 !important;
        width: 260px !important;
        min-width: 260px !important;
        max-width: 260px !important;
    }

    .sidebar.mobile-open .brand,
    .sidebar.mobile-open .nav-menu {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
        width: auto;
        height: auto;
    }

    .app-footer-bar {
        left: 0;
        height: auto;
        min-height: 40px;
        padding: 6px 12px;
        flex-wrap: wrap;
        row-gap: 6px;
    }

    .footer-left-group,
    .footer-right-group {
        display: flex;
        align-items: center;
        gap: 6px;
    }

    /* The mobile margin override of .content-area moved to style.css (this
       file loads before ui/*.css, so the rule here never took effect
       — see style.css). */

    .card {
        --card-pad: 16px;
        padding: var(--card-pad);
        border-radius: 12px;
        margin-bottom: 16px;
    }

    .card-header {
        margin-bottom: 16px;
        padding-left: 10px;
    }

    .page-header-card {
        --card-pad: 14px;
        margin-bottom: 16px;
        border-radius: 12px;
    }

    .top-bar {
        --topbar-control-size: 36px;
        height: auto;
        min-height: 56px;
        padding: 8px 10px;
    }

    .top-bar-left {
        column-gap: 6px;
        flex: 1 1 auto;
        min-width: 0;
    }

    .top-bar-right {
        margin-left: 6px;
        gap: 6px;
    }

    .top-bar :is(.sidebar-toggle-btn, .header-phone-status-pill, .topbar-btn, .header-sync-btn) {
        box-sizing: border-box;
        width: var(--topbar-control-size);
        height: var(--topbar-control-size);
        padding: 0;
        border-radius: 10px;
        flex-shrink: 0;
        justify-content: center;
        font-size: 14px;
        line-height: 1;
    }

    .header-quick-dial-wrapper,
    .header-quick-dial-wrapper > div {
        flex: 1 1 auto;
        min-width: 0;
    }

    #header-incoming-controls,
    #header-active-controls {
        flex-wrap: wrap;
    }

    .header-quick-dial-input {
        width: 100%;
        min-width: 0;
        height: var(--topbar-control-size);
        box-sizing: border-box;
        padding: 0 10px;
        font-size: 12px;
    }

    .header-phone-status-pill .status-text,
    .topbar-btn-label,
    .header-sync-label,
    .top-bar .header-sync-arrow {
        display: none;
    }

    .header-sync-btn {
        position: relative;
    }

    .top-bar :is(.header-notices-count, .header-sync-count) {
        position: absolute;
        top: -4px;
        right: -3px;
        padding: 1px 4px;
        font-size: 10px;
        line-height: 1.2;
    }

    .top-bar .header-sync-count {
        background: var(--warning);
        box-shadow: 0 0 0 1px var(--bg-sidebar);
    }

    .top-bar .header-notices-btn.has-new::after {
        top: auto;
        bottom: 4px;
    }

    /* Dozens of form pages use inline "display:grid;
       grid-template-columns: 1fr 1fr[ 1fr]" — side-by-side columns look good
       on desktop, but on mobile they squeezed the fields and left a narrow,
       empty-looking layout. Inline styles have the highest specificity, so
       they can only be overridden with !important. */
    [style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }
}

/* ===== Responsive Utility & Helpers ===== */
.d-none { display: none !important; }
.d-block { display: block !important; }
.d-inline { display: inline !important; }
.d-inline-flex { display: inline-flex !important; }
.d-flex { display: flex !important; }

@media (min-width: 769px) {
    .d-md-none { display: none !important; }
    .d-md-block { display: block !important; }
    .d-md-inline { display: inline !important; }
    .d-md-inline-flex { display: inline-flex !important; }
    .d-md-flex { display: flex !important; }
}

@media (max-width: 900px) {
    .col-hide-mobile {
        display: none !important;
    }
}

@media (max-width: 768px) {
    /* A button bar whose buttons take the whole width on a phone (e.g. Apply on Pending Changes). */
    .u-mobile-wide:not(#u):not(#u) { justify-content: stretch; }
    .u-mobile-wide > .btn:not(#u):not(#u) { width: 100%; justify-content: center; padding: 12px; font-size: 14px; }

    .d-mobile-none { display: none !important; }
    .d-mobile-block { display: block !important; }
    .d-mobile-inline { display: inline !important; }
    .d-mobile-inline-flex { display: inline-flex !important; }
    .d-mobile-flex { display: flex !important; }

    /* Make modals fit the screen fully and comfortably on mobile */
    .modal-overlay {
        padding: 10px !important;
    }
    .modal-card {
        width: 96% !important;
        max-width: 96% !important;
        margin: 8px auto !important;
        border-radius: 12px !important;
    }
    .modal-header {
        padding: 12px 16px !important;
    }
    .modal-body {
        padding: 14px 16px !important;
        max-height: 82dvh !important;
    }
    .modal-footer {
        padding: 12px 16px !important;
        flex-wrap: wrap !important;
        gap: 8px !important;
    }
    .modal-footer button {
        flex: 1 1 auto !important;
    }

    /* Card & header wrapping on mobile */
    .card {
        --card-pad: 12px;
        padding: 14px 12px;
        border-radius: 12px;
        margin-bottom: 14px;
    }
    .card-header {
        flex-wrap: wrap;
        gap: 10px;
        margin-bottom: 14px;
        padding-left: 10px;
    }
    .card-title {
        font-size: 15px;
        min-width: 0;
    }

    /* Compact table cells & sticky actions column on mobile */
    .table-responsive {
        -webkit-overflow-scrolling: touch;
        border-radius: 8px;
    }
    .data-table thead th,
    .portal-table thead th,
    .table thead th {
        padding: 9px 10px;
        font-size: 11px;
    }
    .data-table tbody td,
    .portal-table tbody td,
    .table tbody td {
        padding: 9px 10px;
        font-size: 12.5px;
    }
    .data-table th.text-right,
    .data-table td.text-right,
    .portal-table th.text-right,
    .portal-table td.text-right {
        padding-left: 6px;
        padding-right: 6px;
    }

    /* Mobile DataTable search & pagination controls */
    .dt-controls-bar {
        gap: 8px;
        margin-bottom: 10px;
    }
    .dt-search-box {
        min-width: 140px;
        max-width: none;
        flex: 1 1 150px;
    }
    .dt-search-box input {
        height: 36px;
        font-size: 14px !important;
    }
    .dt-length-box select {
        height: 36px;
        font-size: 13px !important;
        padding: 4px 8px;
    }
    .dt-pagination-bar {
        gap: 10px;
        margin-top: 10px;
        padding-top: 10px;
    }
    .dt-pagination-nav {
        flex-wrap: wrap;
        justify-content: center;
    }

    /* Keep header & footer popovers within viewport on small phones */
    .header-sync-dropdown,
    .user-profile-dropdown {
        max-width: calc(100vw - 20px);
    }
}
