/* ════════════════════════════════════════════════════════════════════
   Ecites Konnect portal: responsive layer (laptop, tablet, phone)
   Loaded last (portal/layouts/master.blade.php), after every page's own
   <style>, so equal-specificity rules here win. The JS half is
   assets/js/portal-mobile.js (app bar, tab bar, stories, menu sheet,
   table-to-card labels).

   Breakpoints
     ≥1200px      desktop: the portal as designed, untouched
     769–1199px   tablet / small laptop: sidebar becomes an icon rail
     ≤768px       phone: Instagram-style app shell, cards instead of tables
   ════════════════════════════════════════════════════════════════════ */

/* Mobile-only chrome is built by portal-mobile.js; hidden everywhere else */
.m-appbar, .m-tabbar, .m-stories, .m-sheet-head, .m-sheet-foot, .m-sheet-empty { display: none; }

/* ════════════════════════════════════════════════════════════════════
   TABLET / SMALL LAPTOP (769–1199px): icon rail sidebar
   ════════════════════════════════════════════════════════════════════ */
@media (min-width: 769px) and (max-width: 1199px) {
    :root { --sidebar-w: 76px; }

    .portal-sidebar,
    .portal-sidebar.collapsed {
        width: var(--sidebar-w);
        border-right: 1px solid var(--border);
        overflow: visible;
        transition: width .22s cubic-bezier(.4, 0, .2, 1), box-shadow .22s ease;
    }
    .portal-sidebar.collapsed .sidebar-scroll,
    .portal-sidebar.collapsed .sidebar-footer { opacity: 1; pointer-events: auto; }
    body.sidebar-collapsed .portal-content { margin-left: var(--sidebar-w); }
    .sidebar-collapse-btn { display: none; }

    .sidebar-section-label {
        font-size: 0; height: 0; padding: 0;
        margin: 10px 20px; border-top: 1px solid var(--border-light);
    }
    .sidebar-link {
        font-size: 0; gap: 0; justify-content: center;
        padding: 12px 0; white-space: nowrap;
        border-left-width: 3px;
    }
    .sidebar-link i { font-size: 18px; width: auto; }
    .sidebar-link .sidebar-link-content { display: none; }
    .sidebar-link.active::after { display: none; }

    .sidebar-footer { padding: 10px 0; background: var(--surface); }
    .sidebar-footer-user {
        justify-content: center; padding: 4px 0; margin: 0;
        border-color: transparent; background: transparent; box-shadow: none;
    }
    .sidebar-footer-user-info,
    .sidebar-footer-user-chevron,
    .sidebar-footer-copy { display: none; }

    /* Mouse users: the rail opens out over the page on hover */
    @media (hover: hover) and (pointer: fine) {
        .portal-sidebar:hover {
            width: 280px;
            box-shadow: 16px 0 40px -12px rgba(15, 23, 42, .18);
            transition-delay: .12s;
        }
        .portal-sidebar:hover .sidebar-section-label {
            font-size: 10px; height: auto; border: 0; margin: 0; padding: 20px 20px 6px;
        }
        .portal-sidebar:hover .sidebar-link {
            font-size: 14px; gap: 12px; justify-content: flex-start; padding: 10px 20px;
        }
        .portal-sidebar:hover .sidebar-link i { font-size: 14px; width: 20px; }
        .portal-sidebar:hover .sidebar-link .sidebar-link-content { display: flex; }
        .portal-sidebar:hover .sidebar-footer { padding: 12px 14px; background: var(--surface-alt); }
        .portal-sidebar:hover .sidebar-footer-user {
            justify-content: flex-start; padding: 9px 11px; margin-bottom: 8px;
            border-color: rgba(6, 120, 112, .18); background: var(--surface);
        }
        .portal-sidebar:hover .sidebar-footer-user-info,
        .portal-sidebar:hover .sidebar-footer-user-chevron,
        .portal-sidebar:hover .sidebar-footer-copy { display: block; }
    }

    /* Header: icon-only actions so nothing wraps */
    .portal-header-inner { padding: 0 16px 0 13px; }
    .header-brand img { height: 44px; }
    .header-actions { gap: 2px; }
    .header-actions .header-btn { padding: 8px 12px; }
    .header-actions .header-btn span:not(.notif-badge) { display: none; }
    .header-profile-chip .chip-label { max-width: 150px; }

    .content-section { padding: 28px 28px 48px; }
}

/* Tablets: dialogs given a fixed desktop width (e.g. 820px) never run past the screen */
@media (min-width: 769px) and (max-width: 1199px) {
    .swal2-popup:not(.swal2-toast) { max-width: calc(100vw - 48px) !important; }
}

/* Message Center channels stack their tab list above the form at ≤900px;
   stretch the form so it takes the screen width, not its widest row */
@media (max-width: 900px) {
    .smsc-layout, .wapc-layout, .emlc-layout, .hybc-layout { align-items: stretch; }
}

/* Two-pane editors (form + preview) stack once the content area is narrow */
@media (max-width: 1024px) {
    .mtpl-detail-grid, .mtpl-detail-grid.mtpl-no-vars,
    #ccon-tab-paste .ccon-paste-grid, #ccon-tab-saved .ccon-sf-grid, #ccon-tab-upload .ccon-fu-grid,
    .docr-detail-grid, .ems-detail-grid, .incr-grid, .calendar-layout, .uj-progress,
    .dashboard-layout-3 {
        grid-template-columns: minmax(0, 1fr) !important;
    }
}

/* ════════════════════════════════════════════════════════════════════
   PHONE (≤768px): app shell
   ════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    :root {
        --header-h: 56px;
        --m-tabbar-h: 52px;
        --m-ink: #0f1419;
        --m-hair: #e6ebe9;
        --m-ring: linear-gradient(45deg, #f5a623 0%, #14b8a6 55%, #067870 100%);
    }

    html { -webkit-text-size-adjust: 100%; }
    body {
        background: var(--surface);
        -webkit-tap-highlight-color: transparent;
    }
    button, a, [role="button"], label { touch-action: manipulation; }

    /* The desktop header, hamburger drawer and side tab give way to the app shell */
    html body .portal-header { display: none; }   /* beats the header partial's own style, which loads after the early copy */
    .raise-ticket-tab { display: none !important; }

    .portal-content {
        margin-top: calc(var(--header-h) + env(safe-area-inset-top));
        padding-bottom: calc(var(--m-tabbar-h) + env(safe-area-inset-bottom) + 12px);
        min-height: calc(100dvh - var(--header-h));
    }

    /* ── Top app bar ─────────────────────────────────────────────── */
    .m-appbar {
        display: flex; align-items: center; justify-content: space-between;
        position: fixed; top: 0; left: 0; right: 0; z-index: 300;
        height: var(--header-h);
        padding: 0 6px; padding-top: env(safe-area-inset-top);
        box-sizing: content-box;
        background: rgba(255, 255, 255, .96);
        -webkit-backdrop-filter: saturate(180%) blur(14px);
        backdrop-filter: saturate(180%) blur(14px);
        border-bottom: 1px solid transparent;
        transition: border-color .2s ease, box-shadow .2s ease;
    }
    body.m-scrolled .m-appbar { border-bottom-color: var(--m-hair); }
    .m-appbar-btn {
        position: relative;
        width: 44px; height: 44px; flex-shrink: 0;
        display: inline-flex; align-items: center; justify-content: center;
        border: 0; background: transparent; color: var(--m-ink);
        border-radius: 50%; cursor: pointer; padding: 0;
    }
    .m-appbar-btn:active { background: rgba(15, 20, 25, .06); }
    .m-appbar-btn svg { width: 26px; height: 26px; }
    .m-appbar-brand {
        flex: 1; min-width: 0;
        display: inline-flex; align-items: center; justify-content: center; gap: 8px;
        height: 44px; padding: 0 8px;
        border: 0; background: transparent; color: var(--m-ink);
        font-family: 'Inter', sans-serif; cursor: pointer;
    }
    .m-appbar-brand img { height: 30px; width: auto; flex-shrink: 0; }
    .m-appbar-brand .m-brand-name {
        font-size: 19px; font-weight: 700; letter-spacing: -.02em;
        white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0;
    }
    .m-appbar-brand .m-brand-caret { width: 16px; height: 16px; flex-shrink: 0; transition: transform .2s ease; }
    .m-appbar-brand:not(.m-can-switch) .m-brand-caret { display: none; }
    .m-appbar-brand:not(.m-can-switch) { cursor: default; }
    /* Unread count on the bell (same number as the desktop header badge) */
    .m-dot {
        position: absolute; top: 4px; right: 1px;
        min-width: 18px; height: 18px; padding: 0 5px; box-sizing: border-box;
        border-radius: 999px; border: 2px solid #fff;
        background: #ff3040; color: #fff;
        font: 700 10.5px/14px 'Inter', sans-serif; text-align: center; letter-spacing: 0;
        font-variant-numeric: tabular-nums;
        display: none;
    }
    .m-dot.m-on { display: block; }

    /* ── Bottom tab bar ──────────────────────────────────────────── */
    .m-tabbar {
        display: flex; align-items: stretch; justify-content: space-around;
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 300;
        height: var(--m-tabbar-h);
        padding-bottom: env(safe-area-inset-bottom);
        box-sizing: content-box;
        background: rgba(255, 255, 255, .97);
        -webkit-backdrop-filter: saturate(180%) blur(14px);
        backdrop-filter: saturate(180%) blur(14px);
        border-top: 1px solid var(--m-hair);
    }
    .m-tab {
        flex: 1; display: flex; align-items: center; justify-content: center;
        border: 0; background: transparent; color: var(--m-ink);
        cursor: pointer; padding: 0; position: relative;
    }
    .m-tab svg { width: 26px; height: 26px; transition: transform .12s ease; }
    .m-tab:active svg, .m-tab:active .m-tab-avatar { transform: scale(.88); }
    .m-tab .m-ico-on { display: none; }
    .m-tab.m-active .m-ico-on { display: block; }
    .m-tab.m-active .m-ico-off { display: none; }
    .m-tab-avatar {
        width: 28px; height: 28px; border-radius: 50%;
        display: inline-flex; align-items: center; justify-content: center;
        background: linear-gradient(135deg, var(--primary) 0%, #045049 100%);
        color: #fff; font-size: 10.5px; font-weight: 700; letter-spacing: .2px;
        box-shadow: 0 0 0 1px rgba(0, 0, 0, .06);
        transition: transform .12s ease, box-shadow .15s ease;
    }
    .m-tab.m-active .m-tab-avatar { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--m-ink); }
    body.portal-locked .m-tabbar { pointer-events: none; opacity: .5; }

    /* ── Stories row (Home only) ─────────────────────────────────── */
    body.m-home .m-stories { display: block; }
    .m-stories {
        border-bottom: 1px solid var(--m-hair);
        background: var(--surface);
    }
    .m-stories-track {
        display: flex; gap: 14px;
        overflow-x: auto; overflow-y: hidden;
        padding: 12px 14px 10px;
        scroll-padding: 0 14px;
        scroll-snap-type: x proximity;
        scrollbar-width: none; -webkit-overflow-scrolling: touch;
    }
    .m-stories-track::-webkit-scrollbar { display: none; }
    .m-story {
        flex: 0 0 auto; width: 72px;
        display: flex; flex-direction: column; align-items: center; gap: 6px;
        border: 0; background: transparent; padding: 0; cursor: pointer;
        scroll-snap-align: start; font-family: 'Inter', sans-serif;
    }
    .m-story-ring {
        position: relative;
        width: 68px; height: 68px; border-radius: 50%;
        padding: 2.5px; box-sizing: border-box;
        background: var(--m-ring);
        transition: transform .12s ease;
    }
    .m-story:active .m-story-ring { transform: scale(.94); }
    .m-story-face {
        width: 100%; height: 100%; border-radius: 50%;
        border: 3px solid #fff; box-sizing: border-box;
        display: flex; align-items: center; justify-content: center;
        background: var(--primary-bg-light); color: var(--primary);
        font-size: 22px;
    }
    .m-story-own .m-story-ring { background: none; padding: 0; }
    .m-story-own .m-story-face {
        border: 0; background: linear-gradient(135deg, var(--primary) 0%, #045049 100%);
        color: #fff; font-size: 12px; font-weight: 700; letter-spacing: .2px;
    }
    .m-story-plus {
        position: absolute; right: -1px; bottom: -1px;
        width: 22px; height: 22px; border-radius: 50%;
        background: var(--m-ink); color: #fff; border: 3px solid #fff;
        display: flex; align-items: center; justify-content: center;
        font-size: 11px; box-sizing: content-box;
    }
    .m-story-label {
        max-width: 100%; font-size: 12px; color: var(--m-ink);
        white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    }

    /* ── Menu: the sidebar as a bottom sheet ─────────────────────── */
    .sidebar-overlay {
        z-index: 940;
        background: rgba(0, 0, 0, .42);
        -webkit-backdrop-filter: none; backdrop-filter: none;
    }
    .portal-sidebar,
    .portal-sidebar.collapsed {
        top: auto; bottom: 0; left: 0; right: 0;
        width: 100%; max-width: none;
        height: auto; max-height: calc(100dvh - 40px);
        border: 0; border-radius: 22px 22px 0 0;
        overflow: hidden;
        transform: translateY(105%);
        transition: transform .34s cubic-bezier(.32, .72, 0, 1), box-shadow .34s ease;
        z-index: 950;
        box-shadow: none;
    }
    .portal-sidebar.open {
        transform: translateY(0);
        box-shadow: 0 -12px 40px rgba(0, 0, 0, .18);
    }
    .portal-sidebar.m-dragging { transition: none; }
    .portal-sidebar .sidebar-scroll { padding: 0 0 calc(12px + env(safe-area-inset-bottom)); overscroll-behavior: contain; }
    .portal-sidebar .sidebar-footer { display: none; }

    .m-sheet-head { display: block; padding: 0 16px 6px; background: var(--surface); }
    .m-sheet-grip { padding: 8px 0 6px; display: flex; justify-content: center; cursor: grab; }
    .m-sheet-grip span { width: 40px; height: 4px; border-radius: 999px; background: #d4d9d7; }
    .m-sheet-top { display: flex; align-items: center; gap: 12px; padding: 4px 0 14px; }
    .m-sheet-avatar {
        width: 52px; height: 52px; border-radius: 50%; flex-shrink: 0;
        display: flex; align-items: center; justify-content: center;
        background: linear-gradient(135deg, var(--primary) 0%, #045049 100%);
        color: #fff; font-size: 16px; font-weight: 700;
        box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--primary-lighter);
    }
    .m-sheet-who { flex: 1; min-width: 0; }
    .m-sheet-biz {
        font-size: 16px; font-weight: 700; color: var(--m-ink); line-height: 1.25;
        white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    }
    .m-sheet-user {
        font-size: 13px; color: var(--text-muted); line-height: 1.35;
        white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    }
    .m-sheet-close {
        width: 36px; height: 36px; flex-shrink: 0; border-radius: 50%;
        border: 0; background: var(--surface-alt); color: var(--m-ink);
        display: flex; align-items: center; justify-content: center; cursor: pointer;
        font-size: 15px;
    }
    .m-sheet-search { position: relative; margin-bottom: 12px; }
    .m-sheet-search svg {
        position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
        width: 17px; height: 17px; color: var(--text-muted); pointer-events: none;
    }
    .m-sheet-search input {
        width: 100%; height: 40px; box-sizing: border-box;
        padding: 0 14px 0 38px;
        border: 0; border-radius: 10px; outline: none;
        background: #eff2f1; color: var(--m-ink);
        font-size: 16px; font-family: 'Inter', sans-serif;
    }
    .m-sheet-search input::placeholder { color: #8a8f8d; }
    .m-sheet-quick {
        display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px;
        scrollbar-width: none;
    }
    .m-sheet-quick::-webkit-scrollbar { display: none; }
    .m-quick {
        flex: 0 0 auto;
        display: inline-flex; align-items: center; gap: 7px;
        height: 34px; padding: 0 14px;
        border: 0; border-radius: 9px; background: #eff2f1; color: var(--m-ink);
        font-size: 13.5px; font-weight: 600; font-family: 'Inter', sans-serif;
        cursor: pointer; white-space: nowrap;
    }
    .m-quick i { color: var(--primary); font-size: 14px; }
    .m-quick:active { background: #e3e8e6; }
    body:not(.m-has-session) .m-quick[data-auth] { display: none; }

    .portal-sidebar .sidebar-section-label {
        padding: 18px 20px 6px;
        font-size: 11px; letter-spacing: .9px; color: var(--text-muted);
    }
    .portal-sidebar .sidebar-link {
        gap: 14px; padding: 9px 44px 9px 16px; margin: 0 8px;
        border-left: 0; border-radius: 12px;
        font-size: 15px; font-weight: 500; color: var(--m-ink);
    }
    .portal-sidebar .sidebar-link i {
        width: 38px; height: 38px; border-radius: 11px; flex-shrink: 0;
        display: flex; align-items: center; justify-content: center;
        background: #eff4f3; color: var(--primary);
        font-size: 16px; opacity: 1;
    }
    .portal-sidebar .sidebar-link::after,
    .portal-sidebar .sidebar-link.active::after {
        content: ''; position: absolute; right: 20px; top: 50%;
        width: 7px; height: 7px; border-radius: 0; background: none;
        border-top: 2px solid #b9c0bd; border-right: 2px solid #b9c0bd;
        transform: translateY(-50%) rotate(45deg);
    }
    .portal-sidebar .sidebar-link:hover { background: transparent; border-left-color: transparent; color: var(--m-ink); }
    .portal-sidebar .sidebar-link:active { background: var(--surface-alt); }
    .portal-sidebar .sidebar-link.active { background: var(--primary-bg-light); color: var(--primary); font-weight: 600; }
    .portal-sidebar .sidebar-link.active i { background: var(--primary); color: #fff; }
    .portal-sidebar .sidebar-link-subtext { font-size: 12.5px; }
    .portal-sidebar .m-hide { display: none !important; }
    .m-sheet-empty { display: none; padding: 28px 20px; text-align: center; color: var(--text-muted); font-size: 14px; }
    .m-sheet-empty.m-on { display: block; }

    .m-sheet-foot { display: block; padding: 16px 16px 4px; }
    .m-sheet-logout {
        width: 100%; height: 46px; border-radius: 12px;
        border: 1px solid #f3c7c3; background: #fff5f4; color: #d93025;
        font-size: 15px; font-weight: 600; font-family: 'Inter', sans-serif;
        display: flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer;
    }
    body:not(.m-has-session) .m-sheet-logout { display: none; }
    .m-sheet-copy { text-align: center; font-size: 11.5px; color: var(--text-muted); padding: 14px 0 4px; }

    /* ── Page frame ──────────────────────────────────────────────── */
    .content-section { padding: 18px 16px 28px; }
    .content-section h1 { font-size: 21px; letter-spacing: -.02em; }
    .content-section h1 i { font-size: .9em; }
    .content-section .section-intro { font-size: 14px; }
    .section-divider { margin-bottom: 18px; }
    .content-section h2 { margin-top: 24px; }

    /* iPhone/iPad only (Safari zooms into inputs under 16px); Android keeps the compact 14px */
    @supports (-webkit-touch-callout: none) {
        /* :not() with a list counts as one attribute, so the compact toolbar/filter rules below can override it */
        .portal-content input:not([type="checkbox"], [type="radio"], [type="range"]),
        .portal-content select,
        .portal-content textarea,
        .swal2-popup input:not([type="checkbox"]):not([type="radio"]),
        .swal2-popup select,
        .swal2-popup textarea,
        .pss-search, .iti__search-input { font-size: 16px !important; }
    }

    /* Media never wider than the screen */
    .portal-content img, .portal-content video, .portal-content iframe { max-width: 100%; }
    .portal-content [style*="width:800px"], .portal-content [style*="width: 800px"] { width: 100% !important; }

    /* ── Tab rows: one swipeable line ────────────────────────────── */
    .rpt-nav, .ccon-nav, .ems-nav, .wpc-nav, .acct-nav, .cl-tab-nav, .pg-tab-nav,
    .catdet-tab-nav, .auth-tab-nav, .swal-tab-nav,
    .smsc-sidebar, .wapc-sidebar, .emlc-sidebar, .hybc-sidebar {
        display: flex; flex-wrap: nowrap !important;
        overflow-x: auto; overflow-y: hidden;
        scrollbar-width: none; -webkit-overflow-scrolling: touch;
        scroll-snap-type: x proximity;
        gap: 2px; margin-bottom: 16px;
    }
    .rpt-nav::-webkit-scrollbar, .ccon-nav::-webkit-scrollbar, .ems-nav::-webkit-scrollbar,
    .wpc-nav::-webkit-scrollbar, .acct-nav::-webkit-scrollbar, .cl-tab-nav::-webkit-scrollbar,
    .pg-tab-nav::-webkit-scrollbar, .catdet-tab-nav::-webkit-scrollbar, .auth-tab-nav::-webkit-scrollbar,
    .swal-tab-nav::-webkit-scrollbar, .smsc-sidebar::-webkit-scrollbar, .wapc-sidebar::-webkit-scrollbar,
    .emlc-sidebar::-webkit-scrollbar, .hybc-sidebar::-webkit-scrollbar { display: none; }
    .rpt-nav > *, .ccon-nav > *, .ems-nav > *, .wpc-nav > *, .acct-nav > *, .cl-tab-nav > *,
    .pg-tab-nav > *, .catdet-tab-nav > *, .auth-tab-nav > *, .swal-tab-nav > *,
    .smsc-sidebar > *, .wapc-sidebar > *, .emlc-sidebar > *, .hybc-sidebar > * {
        flex: 0 0 auto; white-space: nowrap; scroll-snap-align: start;
    }
    /* Reports sub-views (Message Batches, Recipient Logs, ...): one swipeable row of pills */
    .portal-content .view-toggle {
        flex-wrap: nowrap !important; overflow-x: auto; scrollbar-width: none;
        -webkit-overflow-scrolling: touch; padding-bottom: 2px;
    }
    .portal-content .view-toggle::-webkit-scrollbar { display: none; }
    .portal-content .view-toggle > * { flex: 0 0 auto; white-space: nowrap; }
    .rpt-tab, .ccon-tab, .ems-tab, .wpc-tab, .acct-tab, .cl-tab-btn, .pg-tab-btn,
    .catdet-tab-nav-btn, .auth-tab-btn, .swal-tab-btn {
        padding: 11px 14px !important;
    }

    /* ── Toolbars: actions row, then full-width search, then filters ── */
    .portal-content [class$="-toolbar"], .portal-content [class*="-toolbar "] {
        flex-wrap: wrap !important; gap: 10px !important; padding: 12px !important;
        align-items: stretch !important;
    }
    .portal-content [class$="-toolbar-actions"], .portal-content [class*="-toolbar-actions "],
    .portal-content [class$="-toolbar-search"], .portal-content [class*="-toolbar-search "],
    .portal-content [class$="-toolbar-filters"], .portal-content [class*="-toolbar-filters "] {
        width: 100%; flex: 1 1 100% !important; flex-wrap: wrap !important;
        justify-content: flex-start !important; gap: 8px !important; min-width: 0;
    }
    .portal-content [class$="-toolbar-actions"] > button,
    .portal-content [class*="-toolbar-actions "] > button { flex: 1 1 auto; justify-content: center; }
    /* One compact line: search grows, refresh and any other toolbar buttons sit beside it;
       filter dropdowns are wider than what is left, so they drop to the next row, two to a row */
    .portal-content [class$="-toolbar-search"], .portal-content [class*="-toolbar-search "] { align-items: center !important; }
    .portal-content [class$="-search-wrap"], .portal-content [class*="-search-wrap "] {
        flex: 1 1 140px !important; width: auto !important; max-width: none !important; min-width: 0 !important; order: -3;
    }
    .portal-content [class$="-search-wrap"] input {
        width: 100% !important; height: 38px !important; font-size: 14px !important;
        padding-left: 34px !important; padding-right: 30px !important; text-overflow: ellipsis;
    }
    .portal-content [class$="-search-wrap"] i.fa-search { left: 12px !important; font-size: 13px !important; }
    .portal-content [class$="-toolbar"] .btn-refresh-icon { order: -2; flex: 0 0 38px; width: 38px !important; height: 38px !important; font-size: 14px !important; }
    .portal-content [class$="-toolbar-search"] > button:not(.btn-refresh-icon):not([class$="-search-clear"]) {
        order: -1; flex: 0 0 auto; height: 38px !important; padding: 0 12px !important;
        font-size: 13px !important; gap: 6px !important; justify-content: center;
    }
    .portal-content [class$="-toolbar-search"] > select,
    .portal-content [class$="-toolbar-search"] > [class$="-filter-select"] { flex: 1 1 calc(50% - 4px) !important; height: 38px !important; font-size: 14px !important; }
    .portal-content [class$="-toolbar-actions"] > button { height: 40px; font-size: 14px !important; }
    .portal-content [class$="-filter-select"], .portal-content [class*="-filter-select "] {
        flex: 1 1 calc(50% - 4px) !important; max-width: none !important; min-width: 0 !important; height: 38px; font-size: 14px !important;
    }

    /* Inline "add rows" (New Contacts / Groups / Blacklist / Templates / Users):
       fields stack, the row's remove button becomes a labelled link */
    .ccon-inline-row, .cgrp-inline-row, .cbl-inline-row, .mtpl-inline-row, .pua-inline-row {
        flex-wrap: wrap !important; gap: 18px 10px !important; padding: 20px 12px 10px !important;
    }
    .ccon-inline-row > *, .cgrp-inline-row > *, .cbl-inline-row > *, .mtpl-inline-row > *, .pua-inline-row > * {
        flex: 1 1 100% !important; min-width: 0 !important; max-width: none !important;
    }
    .portal-content [class$="-inline-row-remove"] {
        flex: 0 0 auto !important; width: auto !important; height: 30px; margin-left: auto;
        padding: 0 10px; border-radius: 8px; gap: 6px;
    }
    .portal-content [class$="-inline-row-remove"]::after { content: 'Remove'; font-size: 13px; font-weight: 600; font-family: 'Inter', sans-serif; }
    .portal-content [class$="-toolbar"] .btn-refresh-icon { margin-left: 0; }
    .portal-content [class$="-toolbar"] .btn-refresh-icon::after,
    .portal-content [class$="-toolbar"] .btn-refresh-icon::before { display: none; }
    .btn-refresh-specs { margin-left: 0; }

    /* Headers and action rows wrap instead of overflowing */
    .portal-content [class$="-header"], .portal-content [class*="-header "],
    .portal-content [class$="-actions"], .portal-content [class*="-actions "],
    .portal-content [class$="-head"], .portal-content [class*="-head "] { flex-wrap: wrap; row-gap: 8px; }
    .incident-header-row { align-items: flex-start !important; gap: 0 !important; }
    /* Filter bars (.filters-row): same pattern as the toolbars above */
    .portal-content .filters-row {
        display: flex !important; flex-direction: row !important; flex-wrap: wrap !important;
        align-items: stretch !important; gap: 10px !important;
        padding: 12px !important; overflow: visible !important;
    }
    .portal-content .filters-row > * { flex: 1 1 100% !important; min-width: 0 !important; max-width: none !important; }
    .portal-content .filters-row > [style*="display: flex"],
    .portal-content .filters-row > [style*="display:flex"] { flex-wrap: nowrap !important; gap: 8px !important; }
    .portal-content .filters-row .search-input-wrapper {
        flex: 1 1 calc(100% - 50px) !important; width: auto !important; min-width: 0 !important; max-width: none !important; margin: 0 !important;
    }
    .portal-content .filters-row .search-input-wrapper input { width: 100% !important; height: 38px !important; font-size: 14px !important; box-sizing: border-box; text-overflow: ellipsis; }
    .portal-content .filters-row select, .portal-content .filters-row input.insight-date-filter { height: 38px !important; font-size: 14px !important; }
    .portal-content .filters-row .btn-refresh-icon { flex: 0 0 38px !important; width: 38px !important; height: 38px !important; margin: 0 !important; }
    .portal-content .filters-row .btn-refresh-icon::after,
    .portal-content .filters-row .btn-refresh-icon::before { display: none; }
    .portal-content .filters-row .filter-group {
        display: grid !important; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px !important; width: 100%;
    }
    .portal-content .filters-row .filter-group > select,
    .portal-content .filters-row .filter-group > input,
    .portal-content .filters-row .filter-group > .flatpickr-wrapper {
        width: 100% !important; min-width: 0 !important; max-width: none !important; height: 38px; box-sizing: border-box; margin: 0 !important;
    }
    .portal-content .filters-row .filter-group > button,
    .portal-content .filters-row .filter-group > .btn-clear-filters { grid-column: 1 / -1; justify-content: center; height: 38px; margin: 0 !important; }
    /* Dashboard and Schedules lay their filters straight into the row (display: contents) */
    #dashboardreports-content .filters-row .dbr-search, #dashboardreports-content .filters-row .filter-group,
    #scheduledmessages-content .filters-row .scm-search, #scheduledmessages-content .filters-row .filter-group { display: contents !important; }
    #dashboardreports-content .filters-row select, #dashboardreports-content .filters-row .insight-date-filter,
    #scheduledmessages-content .filters-row select, #scheduledmessages-content .filters-row .insight-date-filter {
        flex: 1 1 120px !important; min-width: 0 !important; width: auto !important; height: 38px;
    }
    #dashboardreports-content .filters-row .btn-clear-filters, #dashboardreports-content .filters-row .btn-export, #dashboardreports-content .filters-row .dbr-chip,
    #scheduledmessages-content .filters-row .btn-clear-filters, #scheduledmessages-content .filters-row .btn-export {
        flex: 1 1 120px !important; justify-content: center; height: 38px;
    }

    /* ── Pagination ──────────────────────────────────────────────── */
    .rpt-pg, .portal-content [class$="-pager"], .portal-content [class*="-pager "],
    .portal-content [class$="-pagination"] {
        flex-wrap: wrap !important; justify-content: center !important;
        gap: 8px !important; text-align: center;
    }

    /* ── Grids: one column; KPI tiles two-up ─────────────────────── */
    .at-actions, .pd, .mtpl-pv-grid, .bacc-detail-grid, .bacc-detail-row,
    .dashboard-layout, .dbr-ov, .ems-row, .itd-row, .scm-ov, .settings-row, .settings-wrapper,
    .sss-fields, .sss-rates, .sss-row, .wab-row, .wab-status-details, .insights-grid,
    .insight-detail-layout, .insight-related-grid, .security-grid, .status-code-grid,
    .portal-content .grid {
        grid-template-columns: minmax(0, 1fr) !important;
    }
    .rpt-stats, .kpi-grid, .wac-stats, .stats-grid, .uj-break,
    #dashboardreports-content .rpt-stats, #scheduledmessages-content .rpt-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 10px !important;
    }
    .rpt-card { padding: 12px; gap: 10px; min-width: 0; }
    .rpt-card > * { min-width: 0; }
    .portal-content [style*="grid-template-columns"] { grid-template-columns: minmax(0, 1fr) !important; }

    /* Cards and panels never force the page wider than the screen */
    .portal-content [class$="-card"], .portal-content [class*="-card "],
    .portal-content [class$="-panel"], .portal-content [class*="-panel "] { min-width: 0 !important; max-width: 100%; }
    .portal-content [class*="-grid-panel"] { border-radius: 14px; }

    /* ── Tables as cards (rows labelled by portal-mobile.js) ─────── */
    table.m-cards { min-width: 0 !important; width: 100% !important; table-layout: auto !important; border: 0 !important; background: transparent !important; margin: 0 !important; }
    table.m-cards, table.m-cards > tbody, table.m-cards > tbody > tr, table.m-cards > tbody > tr > td { display: block; }
    table.m-cards > thead, table.m-cards > tfoot { display: none; }
    table.m-cards > tbody { display: flex; flex-direction: column; gap: 10px; }
    table.m-cards > tbody > tr {
        position: relative;
        background: var(--surface) !important;
        border: 1px solid var(--m-hair); border-radius: 14px;
        box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
        padding: 4px 14px;
    }
    table.m-cards > tbody > tr:hover > td,
    table.m-cards > tbody > tr:nth-child(even) > td,
    table.m-cards > tbody > tr > td { background: transparent !important; }
    table.m-cards > tbody > tr[class*="disabled"] { background: #f8faf9 !important; }
    table.m-cards > tbody > tr[class*="disabled"] > td { opacity: .78; }
    table.m-cards > tbody > tr > td {
        position: relative;
        width: auto !important; max-width: none !important;
        padding: 10px 0 10px 40% !important;
        border: 0 !important; border-top: 1px solid var(--border-light) !important;
        text-align: left !important;
        white-space: normal !important; overflow-wrap: anywhere; word-break: break-word;
        min-height: 40px; box-sizing: border-box;
        font-size: 14px; color: var(--text-secondary);
    }
    table.m-cards > tbody > tr > td::before {
        content: attr(data-label);
        position: absolute; left: 0; top: 11px; width: calc(40% - 12px);
        text-align: left; white-space: normal;
        font-size: 11px; font-weight: 600; letter-spacing: .5px; text-transform: uppercase;
        color: var(--text-muted); line-height: 1.5;
    }
    table.m-cards > tbody > tr > td.m-td-index,
    table.m-cards > tbody > tr > td:empty { display: none; }
    table.m-cards > tbody > tr > td.m-td-title {
        padding: 13px 0 11px !important; border-top: 0 !important;
        text-align: left !important;
        font-size: 16px; font-weight: 700; color: var(--m-ink); line-height: 1.35; letter-spacing: -.01em;
    }
    /* Status (Enabled / Disabled ...) as a small chip in the card's top-right corner */
    table.m-cards > tbody > tr > td.m-td-status {
        position: absolute; top: 12px; right: 14px;
        width: auto !important; min-height: 0; padding: 0 !important;
        border: 0 !important; text-align: right !important; line-height: 1;
    }
    table.m-cards > tbody > tr > td.m-td-status::before { display: none; }
    table.m-cards > tbody > tr:has(> td.m-td-status) > td.m-td-title { padding-right: 104px !important; }
    /* Badges and chips inside cards stay secondary to the title */
    table.m-cards td span[class*="badge"], table.m-cards td span[class*="status"],
    table.m-cards td span[class*="pill"], table.m-cards td span[class*="chip"] {
        font-size: 12px !important; font-weight: 600 !important; padding: 3px 9px !important;
        line-height: 1.4 !important; gap: 4px !important; border-radius: 999px;
    }
    table.m-cards td span[class*="badge"] i, table.m-cards td span[class*="status"] i { font-size: 11px !important; }
    table.m-cards > tbody > tr > td.m-td-title::before,
    table.m-cards > tbody > tr > td.m-td-bare::before,
    table.m-cards > tbody > tr > td.m-td-actions::before,
    table.m-cards > tbody > tr > td.m-td-full::before { display: none; }
    table.m-cards > tbody > tr > td.m-td-bare { padding-left: 0 !important; text-align: left !important; }
    table.m-cards > tbody > tr > td.m-td-actions {
        padding: 10px 0 !important; text-align: right !important;
        display: flex; justify-content: flex-end; align-items: center; flex-wrap: wrap; gap: 6px;
    }
    table.m-cards > tbody > tr > td.m-td-full {
        padding: 22px 8px !important; border-top: 0 !important; text-align: center !important;
    }
    table.m-cards > tbody > tr:has(> td.m-td-full:only-child) { border-style: dashed; box-shadow: none; }
    table.m-cards > tbody > tr > td.m-td-title input,
    table.m-cards > tbody > tr > td.m-td-title textarea { font-size: 16px !important; font-weight: 700 !important; color: var(--m-ink); }
    @supports (field-sizing: content) {
        table.m-cards > tbody > tr > td textarea { field-sizing: content; height: auto !important; }
    }
    /* Wrappers that scrolled the wide table now just hold the cards */
    .portal-content :has(> table.m-cards) {
        overflow: visible !important; min-width: 0 !important;
    }
    [class*="twrap"]:has(> table.m-cards), [class*="table-wrap"]:has(> table.m-cards) {
        background: var(--surface-alt) !important; padding: 10px !important; border: 0 !important;
    }

    /* Tables that stay tables (spreadsheet previews, small lookups) scroll sideways */
    .portal-content table:not(.m-cards) { max-width: 100%; }
    .portal-content :has(> table:not(.m-cards)) { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .portal-content .portal-table:not(.m-cards) { display: block; overflow-x: auto; }

    /* ── Dialogs: SweetAlert as a bottom sheet ───────────────────── */
    .swal2-container:not(.swal2-top):not(.swal2-top-end):not(.swal2-top-start):not(.swal2-bottom-end):not(.swal2-top-right) {
        padding: 0 !important; align-items: flex-end !important;
    }
    .swal2-container .swal2-popup:not(.swal2-toast) {
        width: 100% !important; max-width: 100% !important;
        margin: 0 !important; align-self: flex-end;
        border-radius: 22px 22px 0 0 !important;
        padding: 22px 16px calc(16px + env(safe-area-inset-bottom)) !important;
        max-height: calc(100dvh - 24px); overflow-y: auto; overscroll-behavior: contain;
        box-sizing: border-box;
    }
    .swal2-container .swal2-popup:not(.swal2-toast).swal2-show { animation: m-sheet-up .32s cubic-bezier(.32, .72, 0, 1); }
    .swal2-container .swal2-popup:not(.swal2-toast).swal2-hide { animation: m-sheet-down .2s ease-in forwards; }
    .swal2-popup:not(.swal2-toast)::before {
        content: ''; display: block; width: 40px; height: 4px; border-radius: 999px;
        background: #d4d9d7; margin: -12px auto 10px;
    }
    .swal2-popup .swal2-title { font-size: 19px !important; padding: 0 4px !important; }
    .swal2-popup .swal2-html-container, .swal2-popup .swal2-content { margin: 10px 0 0 !important; padding: 0 !important; }
    .swal2-popup .swal2-actions { width: 100%; flex-wrap: wrap; gap: 8px; margin-top: 18px !important; }
    /* Equal widths when the labels fit; a button is never narrower than its label, so a long one wraps to its own line */
    .swal2-popup .swal2-actions .swal2-styled { flex: 1 1 0; min-width: max-content; margin: 0 !important; height: 46px; }
    .swal2-popup .swal2-actions .swal2-styled { white-space: nowrap; padding: 0 12px !important; font-size: 14px !important; }
    /* Three buttons (e.g. Document Options: View / Download / Cancel): the main one on its own row, the other two under it */
    .swal2-popup .swal2-actions:has(> .swal2-deny:not([style*="display: none"])):has(> .swal2-cancel:not([style*="display: none"])) > .swal2-confirm:not([style*="display: none"]) { flex-basis: 100%; }
    /* Subtitles written as one line for desktop wrap here instead of being cut off */
    .swal2-popup p[style*="white-space:nowrap"], .swal2-popup div[style*="white-space:nowrap"],
    .swal2-popup span[style*="white-space:nowrap"] { white-space: normal !important; }
    /* Scrolling bodies that bleed into the desktop popup's 20px side padding (Complete Your Account) */
    .swal2-popup [style*="margin-right:-20px"] { margin-right: -16px !important; padding-right: 16px !important; }
    /* Rows of side-by-side form fields (County / Constituency / Ward ...) stack, one field per line */
    .swal2-popup [style*="display:flex"]:has(> .floating-label-group ~ .floating-label-group) {
        flex-direction: column !important; flex-wrap: nowrap !important; gap: 0 !important;
    }
    .swal2-popup [style*="display:flex"]:has(> .floating-label-group ~ .floating-label-group) > .floating-label-group {
        width: 100% !important; flex: 0 0 auto !important;
    }
    /* OTP code boxes: bigger touch targets */
    .swal2-popup .otp-box { width: 46px !important; height: 50px !important; margin: 0 4px !important; font-size: 22px !important; }
    .swal2-popup [style*="grid-template-columns"] { grid-template-columns: minmax(0, 1fr) !important; }
    .swal2-popup [style*="display:flex"][style*="gap"]:not([style*="column"]) { flex-wrap: wrap; }
    .swal2-popup table { max-width: 100%; }

    /* Other overlays */
    .portal-preview-modal { padding: 0; }
    .portal-preview-modal .preview-container { border-radius: 0; height: 100%; }
    .portal-preview-modal .preview-header { padding: 10px 12px; padding-top: calc(10px + env(safe-area-inset-top)); gap: 10px; }
    .portal-preview-modal .preview-title { font-size: var(--fs-small); }
    .portal-preview-modal .preview-actions { gap: 6px; }
    .portal-preview-modal .preview-actions .preview-sep { margin: 0 2px; }
    .portal-preview-modal .preview-btn { width: 38px; height: 38px; }
    .portal-preview-modal .preview-btn.close-btn { background: var(--surface-alt); color: var(--text-primary); }
    .introjs-tooltip { min-width: 0; max-width: calc(100vw - 32px); }
    .ss-dropdown-menu, .notif-panel { min-width: 0; max-width: calc(100vw - 24px); }
    .fc .fc-toolbar { flex-wrap: wrap; gap: 8px; }
    .fc .fc-toolbar-title { font-size: 17px !important; }
    .note-editor .note-toolbar { overflow-x: auto; flex-wrap: nowrap; white-space: nowrap; }
    .flatpickr-calendar { max-width: calc(100vw - 16px); }

    /* Toasts sit above the tab bar, never under the app bar */
    .toastify.toastify-bottom { margin-bottom: calc(var(--m-tabbar-h) + env(safe-area-inset-bottom)); }
    .toastify.toastify-top { margin-top: calc(var(--header-h) - 8px); }
    .toastify { max-width: calc(100vw - 24px) !important; }
}

@media (max-width: 380px) {
    .m-story { width: 66px; }
    .m-story-ring { width: 62px; height: 62px; }
    .m-appbar-brand .m-brand-name { font-size: 17px; }
}

@keyframes m-sheet-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes m-sheet-down { from { transform: translateY(0); opacity: 1; } to { transform: translateY(100%); opacity: .6; } }

@media (prefers-reduced-motion: reduce) {
    .portal-sidebar, .m-tab svg, .m-story-ring { transition: none !important; }
    .swal2-container .swal2-popup.swal2-show, .swal2-container .swal2-popup.swal2-hide { animation: none !important; }
}
