/*
 * Blackhawk UI refinement layer
 * Uiverse-inspired interaction patterns, adapted for the CRM's existing markup.
 * Kept dependency-free so the application does not depend on uiverse.io at runtime.
 */

:root {
    --bh-ui-bg: #f6f7fb;
    --bh-ui-surface: #ffffff;
    --bh-ui-surface-soft: #f8fafc;
    --bh-ui-text: #0f172a;
    --bh-ui-muted: #64748b;
    --bh-ui-border: #e2e8f0;
    --bh-ui-border-strong: #cbd5e1;
    --bh-ui-danger: #dc2626;
    --bh-ui-success: #16a34a;
    --bh-ui-warning: #d97706;
    --bh-ui-radius: 12px;
    --bh-ui-shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px rgba(15, 23, 42, .05);
    --bh-ui-shadow-hover: 0 2px 4px rgba(15, 23, 42, .06), 0 12px 28px rgba(15, 23, 42, .08);
}

body {
    background: var(--bh-ui-bg);
    color: var(--bh-ui-text);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* Shared header */
#perfex-header {
    height: 62px;
    background: rgba(255, 255, 255, .97);
    border-bottom: 1px solid var(--bh-ui-border);
    box-shadow: 0 1px 0 rgba(15, 23, 42, .02);
    backdrop-filter: blur(12px);
}

.header-inner { gap: 8px; padding: 0 18px; }

/* Keep the global-search field and action on one line. */
.header-search {
    display: flex !important;
    align-items: center;
    gap: 8px;
    flex: 1 1 360px;
    width: min(520px, 100%);
    max-width: 520px !important;
    min-width: 180px;
    margin: 0 12px !important;
    position: relative;
}
.header-search input,
#global-search-input {
    flex: 1 1 auto;
    width: auto !important;
    min-width: 0;
    height: 40px !important;
    padding: 0 14px 0 34px !important;
    border: 1px solid var(--bh-ui-border-strong) !important;
    border-radius: 11px !important;
    background: var(--bh-ui-surface-soft) !important;
    box-shadow: inset 0 1px 0 rgba(255,255,255,.7);
    transition: border-color .18s ease, box-shadow .18s ease, background .18s ease !important;
}
.header-search input:focus,
#global-search-input:focus {
    background: #fff !important;
    border-color: var(--pfx-primary) !important;
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--pfx-primary) 14%, transparent) !important;
}
#global-search-btn {
    position: static !important;
    flex: 0 0 auto;
    height: 40px;
    min-height: 40px;
    padding: 0 16px;
    border: 1px solid var(--pfx-primary);
    border-radius: 10px !important;
    background: var(--pfx-primary);
    color: #fff;
    font-family: 'Inter', sans-serif;
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(15,23,42,.12);
    transition: transform .15s ease, box-shadow .15s ease, filter .15s ease;
}
#global-search-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(15,23,42,.13);
    filter: brightness(.97);
}
#global-search-btn:active { transform: scale(.98); }

/* The result palette belongs under the field/button group and must not consume a flex slot. */
.header-search .bh-global-search-results {
    left: 0;
    right: 0;
}

.header-btn,
.bh-header-action,
.sidebar-toggle-btn {
    width: 38px;
    height: 38px;
    min-width: 38px;
    padding: 0;
    border: 1px solid var(--bh-ui-border);
    border-radius: 10px;
    background: var(--bh-ui-surface);
    color: #475569;
    box-shadow: 0 1px 2px rgba(15,23,42,.04);
    transition: transform .15s ease, border-color .15s ease, background .15s ease, box-shadow .15s ease;
}
.header-btn:hover,
.bh-header-action:hover,
.sidebar-toggle-btn:hover {
    background: var(--bh-ui-surface-soft);
    border-color: var(--bh-ui-border-strong);
    color: var(--bh-ui-text);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(15,23,42,.07);
    text-decoration: none;
}
.header-btn:active,
.bh-header-action:active,
.sidebar-toggle-btn:active { transform: translateY(0) scale(.96); }
.bh-header-action { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; font-size: 15px; }
.bh-header-action i { color: inherit !important; }
.bh-mobile-menu-button { display: none; }

.header-user-chip {
    min-height: 40px;
    border: 1px solid transparent;
    border-radius: 11px;
    padding: 4px 10px 4px 5px;
}
.header-user-chip:hover { border-color: var(--bh-ui-border); background: var(--bh-ui-surface-soft); }
.header-user-avatar { width: 30px; height: 30px; box-shadow: inset 0 0 0 1px rgba(255,255,255,.3); }
.header-dropdown-panel { border-color: var(--bh-ui-border); border-radius: 14px; box-shadow: 0 18px 45px rgba(15,23,42,.14); }
.header-divider { background: var(--bh-ui-border); }

/* Sidebar */
#perfex-sidebar { padding-left: 8px; padding-right: 8px; }
.sidebar-logo-area { height: 62px; padding: 0 12px; }
.sidebar-nav { margin-top: 12px; }
.sidebar-nav li a {
    min-height: 38px;
    border-radius: 9px;
    padding: 8px 12px;
    margin-top: 3px;
    transition: background .16s ease, color .16s ease, transform .16s ease;
}
.sidebar-nav li a:hover { transform: translateX(2px); }
.sidebar-nav > li.active { border-left-color: transparent; }
.sidebar-nav > li.active > a,
.sidebar-nav > li.current-menu-item > a {
    background: color-mix(in srgb, var(--pfx-sidebar-active) 18%, transparent);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--pfx-sidebar-active) 32%, transparent);
}
#perfex-sidebar .submenu li a { border-radius: 8px; margin: 2px 4px; }
.submenu-row { border-radius: 8px; margin: 2px 2px 0; }

/* Page titles */
#perfex-content { padding: 26px 26px 44px; }
.page-title-area { margin-bottom: 20px; }
.page-title-area h1 { font-size: 22px !important; letter-spacing: -.02em; font-weight: 750 !important; }
.page-title-area .page-subtitle,
.bh-page-welcome { color: var(--bh-ui-muted) !important; }
.bh-page-icon {
    display: inline-flex;
    width: 34px;
    height: 34px;
    align-items: center;
    justify-content: center;
    margin-right: 10px;
    border-radius: 10px;
    background: color-mix(in srgb, var(--pfx-primary) 11%, white);
    color: var(--pfx-primary) !important;
    vertical-align: middle;
}

/* Uiverse-inspired tactile buttons */
.btn {
    min-height: 38px;
    border-radius: 10px;
    border-width: 1px;
    font-weight: 650;
    letter-spacing: -.005em;
    box-shadow: 0 1px 2px rgba(15,23,42,.05);
    transition: transform .15s ease, box-shadow .15s ease, filter .15s ease, border-color .15s ease;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 5px 14px rgba(15,23,42,.09); }
.btn:active { transform: translateY(0) scale(.98); box-shadow: 0 1px 2px rgba(15,23,42,.05); }
.btn-primary { background: var(--pfx-primary); border-color: var(--pfx-primary); }
.btn-primary:hover { background: var(--pfx-primary); border-color: var(--pfx-primary); filter: brightness(.94); }
.btn-secondary { background: #fff; color: #334155; border-color: var(--bh-ui-border-strong); }
.btn-secondary:hover { background: #f8fafc; color: #0f172a; border-color: #94a3b8; }
.btn-danger { background: #fff; color: var(--bh-ui-danger); border-color: #fecaca; }
.btn-danger:hover { background: #fef2f2; color: #b91c1c; border-color: #fca5a5; }
.btn-success { box-shadow: 0 1px 2px rgba(22,163,74,.10); }
.btn-sm { min-height: 34px; border-radius: 9px; }
.btn-icon { width: 38px; height: 38px; padding: 0; }

/* Cards */
.card,
.bh-module-card {
    border: 1px solid var(--bh-ui-border) !important;
    border-radius: 14px !important;
    background: var(--bh-ui-surface);
    box-shadow: var(--bh-ui-shadow);
}
.card-header {
    padding: 15px 18px;
    border-bottom: 1px solid var(--bh-ui-border);
    background: transparent;
}
.card-title { font-weight: 700; letter-spacing: -.01em; }
.card-body { padding: 18px; }
.card-footer { border-top: 1px solid var(--bh-ui-border); background: #fbfcfe; }

.stat-cards-row { gap: 14px; }
.bh-stat-link { display: block; min-width: 0; text-decoration: none !important; }
.stat-card {
    min-height: 118px;
    border: 1px solid var(--bh-ui-border) !important;
    border-left: 3px solid var(--stat-accent, var(--pfx-primary)) !important;
    border-radius: 14px !important;
    background: var(--bh-ui-surface);
    box-shadow: var(--bh-ui-shadow);
    transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.bh-stat-link:hover .stat-card,
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--bh-ui-shadow-hover); border-color: var(--bh-ui-border-strong) !important; }
.stat-card-label { color: var(--bh-ui-muted); font-size: 12px; font-weight: 650; letter-spacing: .01em; }
.stat-card-value { color: var(--bh-ui-text); font-size: 28px; letter-spacing: -.035em; }
.stat-card-sub { color: #94a3b8; }

/* Forms */
.form-control,
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="tel"], input[type="url"], input[type="date"], input[type="time"], input[type="search"],
select, textarea {
    border: 1px solid var(--bh-ui-border-strong);
    border-radius: 10px;
    background: #fff;
    color: var(--bh-ui-text);
    transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}
.form-control:focus,
input[type="text"]:focus, input[type="email"]:focus, input[type="password"]:focus, input[type="number"]:focus,
input[type="tel"]:focus, input[type="url"]:focus, input[type="date"]:focus, input[type="time"]:focus, input[type="search"]:focus,
select:focus, textarea:focus {
    border-color: var(--pfx-primary) !important;
    outline: none;
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--pfx-primary) 13%, transparent) !important;
}
label { color: #334155; }

/* Toggle: retain markup, improve tactility */
.bh-toggle { width: 44px; height: 24px; }
.bh-toggle-slider { background: #cbd5e1; box-shadow: inset 0 0 0 1px rgba(15,23,42,.06); }
.bh-toggle-slider:before { width: 18px; height: 18px; left: 3px; bottom: 3px; box-shadow: 0 1px 4px rgba(15,23,42,.22); }
.bh-toggle input:checked + .bh-toggle-slider { background: var(--pfx-primary); }
.bh-toggle input:checked + .bh-toggle-slider:before { transform: translateX(20px); }
.bh-toggle input:focus-visible + .bh-toggle-slider { outline: 3px solid color-mix(in srgb, var(--pfx-primary) 25%, transparent); outline-offset: 2px; }

/* Tables: undo the accumulating hard-border overrides in app.css */
.table-container {
    margin: 14px 0 0 !important;
    padding: 0 !important;
    overflow: hidden;
    border: 1px solid var(--bh-ui-border) !important;
    border-radius: 14px !important;
    background: #fff;
    box-shadow: var(--bh-ui-shadow) !important;
}
.perfex-table { border: 0 !important; border-collapse: separate !important; border-spacing: 0 !important; }
.perfex-table thead tr { background: #f8fafc !important; }
.perfex-table thead th {
    padding: 11px 14px !important;
    color: #64748b !important;
    font-size: 11px !important;
    font-weight: 750 !important;
    letter-spacing: .055em !important;
    text-transform: uppercase;
    border-top: 0 !important;
    border-bottom: 1px solid var(--bh-ui-border) !important;
}
.perfex-table tbody td {
    padding: 11px 14px !important;
    border-top: 1px solid #eef2f7 !important;
    color: #334155;
}
.perfex-table tbody tr:first-child td { border-top: 0 !important; }
.perfex-table tbody tr:hover td { background: #f8fafc !important; }

/* Badges and status chips */
.badge,
.inv-status-badge {
    border-radius: 999px !important;
    font-weight: 700;
    letter-spacing: .01em;
    border: 1px solid transparent;
}
.badge-primary { border-color: #bfdbfe; }
.badge-success { border-color: #bbf7d0; }
.badge-warning { border-color: #fde68a; }
.badge-danger { border-color: #fecaca; }
.badge-info { border-color: #bae6fd; }
.badge-secondary { border-color: #e2e8f0; }
.badge-purple { border-color: #ddd6fe; }

/* Alerts */
.alert {
    border-radius: 12px;
    box-shadow: 0 1px 2px rgba(15,23,42,.04);
    border-width: 1px;
}
.alert-dismiss { width: 32px; height: 32px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; }
.alert-dismiss:hover { background: rgba(15,23,42,.06); }

/* Modals */
.modal-overlay { background: rgba(15,23,42,.52); backdrop-filter: blur(4px); }
.modal-dialog { border-radius: 16px; border: 1px solid var(--bh-ui-border); box-shadow: 0 24px 70px rgba(15,23,42,.22); }
.modal-header, .modal-footer { border-color: var(--bh-ui-border); }
.modal-close { width: 36px; height: 36px; border-radius: 9px; }
.modal-close:hover { background: #f1f5f9; }

/* Uploads / empty states */
.bh-upload-zone {
    border-color: var(--bh-ui-border-strong);
    border-radius: 14px;
    background: #fbfcfe;
}
.bh-upload-zone:hover {
    border-color: var(--pfx-primary);
    background: color-mix(in srgb, var(--pfx-primary) 5%, white);
}
.bh-empty-state { text-align: center; padding: 52px 24px; }
.bh-empty-icon {
    width: 64px;
    height: 64px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
    border-radius: 18px;
    background: #f1f5f9;
    color: #94a3b8;
    font-size: 28px;
}

/* Pagination */
.bh-pagination { gap: 6px; }
.bh-pag-btn { min-width: 36px; height: 36px; border-radius: 9px; border-color: var(--bh-ui-border); font-weight: 650; }
.bh-pag-btn:hover { background: #f8fafc; border-color: var(--bh-ui-border-strong); }
.bh-pag-btn.active { background: var(--pfx-primary); border-color: var(--pfx-primary); }

/* Keyboard focus */
a:focus-visible, button:focus-visible, [role="button"]:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--pfx-primary) 28%, transparent);
    outline-offset: 2px;
}

@media (max-width: 768px) {
    #perfex-header { height: 58px; }
    .header-inner { padding: 0 10px; gap: 6px; }
    .bh-mobile-menu-button { display: inline-flex !important; }
    .header-mobile-logo { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
    #perfex-content { padding: 14px 12px 32px !important; }
    .page-title-area { padding: 4px 0 !important; }
    .page-title-area h1 { font-size: 19px !important; }
    .stat-cards-row { gap: 10px; }
    .stat-card { min-height: 104px; }
    .table-container { margin: 12px 0 0 !important; overflow-x: auto !important; }
    .modal-dialog { width: calc(100% - 20px) !important; max-width: calc(100% - 20px) !important; height: auto !important; margin: 10px !important; border-radius: 14px !important; }
    .modal-content, .pfx-modal-content { min-height: 0 !important; border-radius: 14px !important; }
}

@media (max-width: 480px) {
    .header-user-name, .header-user-caret { display: none; }
    .header-user-chip { padding-right: 5px; }
    .page-title-actions { width: 100%; }
    .page-title-actions .btn { flex: 1 1 auto; }
    .stat-cards-row { grid-template-columns: 1fr !important; }
}


@media (max-width: 1100px) and (min-width: 769px) {
    .header-search {
        flex-basis: 280px;
        max-width: 390px !important;
        margin-left: 6px !important;
        margin-right: 6px !important;
    }
    #global-search-btn { padding-left: 13px; padding-right: 13px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}

/* Secondary authentication and error pages */
.bh-login-wrap { background: #f6f7fb; }
.bh-login-card {
    border: 1px solid var(--bh-ui-border);
    border-radius: 18px;
    box-shadow: 0 2px 4px rgba(15,23,42,.04), 0 22px 60px rgba(15,23,42,.10);
}
.bh-login-header {
    background: #0f172a;
    padding: 30px 32px;
}
.bh-login-body { padding: 30px 32px; }

/* Global search result palette */
.bh-global-search-results {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    z-index: 9999;
    max-height: 430px;
    overflow-y: auto;
    padding: 6px;
    border: 1px solid var(--bh-ui-border);
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 20px 45px rgba(15,23,42,.15);
}
.bh-global-search-results.open { display: block; }
.bh-search-state { padding: 14px 12px; color: var(--bh-ui-muted); font-size: 12px; text-align: center; }
.bh-search-result {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 11px;
    border-radius: 9px;
    color: var(--bh-ui-text);
    text-decoration: none;
}
.bh-search-result:hover,
.bh-search-result.active { background: #f1f5f9; color: var(--bh-ui-text); text-decoration: none; }
.bh-search-result-icon {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 32px;
    border-radius: 9px;
    background: color-mix(in srgb, var(--pfx-primary) 10%, white);
    color: var(--pfx-primary);
}
.bh-search-result-copy { min-width: 0; flex: 1; }
.bh-search-result-title { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 700; }
.bh-search-result-sub { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 1px; color: var(--bh-ui-muted); font-size: 11px; }


/* ==========================================================================
   Mobile usability pass v4 (1.1.11)
   ========================================================================== */
.bh-mobile-search-button,
.bh-mobile-sidebar-close { display: none; }

@media (max-width: 768px) {
    html { -webkit-text-size-adjust: 100%; width:100%; max-width:100%; overflow-x:hidden; }
    body { width:100%; max-width:100%; overflow-x:hidden !important; }
    body.sidebar-mobile-open { overflow: hidden; }

    /* A flex item's min-content width was allowing the header/search to make the
       entire application wider than the phone. Keep the app shell pinned to the viewport. */
    #perfex-wrapper { width:100%; max-width:100%; min-width:0; overflow-x:hidden; }
    #perfex-main { margin-left:0 !important; width:100% !important; max-width:100% !important; min-width:0 !important; flex:1 1 100%; overflow-x:hidden; }
    #perfex-header { width:100% !important; max-width:100% !important; min-width:0 !important; }
    .header-inner { width:100%; max-width:100%; min-width:0; }

    /* The desktop search declaration above uses !important, so explicitly hide it
       on phones until the magnifier button opens the dedicated search row. */
    .header-search { display:none !important; }

    /* Off-canvas navigation uses transforms instead of negative margins. */
    #perfex-sidebar {
        width: min(88vw, 310px) !important;
        max-width: 310px;
        margin-left: 0 !important;
        transform: translateX(-100%);
        transition: transform .24s ease, box-shadow .24s ease !important;
        padding-bottom: calc(18px + env(safe-area-inset-bottom));
        overscroll-behavior: contain;
    }
    body.sidebar-mobile-open #perfex-sidebar {
        margin-left: 0 !important;
        transform: translateX(0);
        box-shadow: 12px 0 36px rgba(15,23,42,.22);
    }
    .mobile-sidebar-overlay {
        background: rgba(15,23,42,.46) !important;
        backdrop-filter: blur(2px);
    }
    .sidebar-logo-area {
        position: sticky;
        top: 0;
        padding-right: 54px !important;
    }
    .bh-mobile-sidebar-close {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        position: absolute;
        right: 10px;
        top: 50%;
        transform: translateY(-50%);
        width: 40px;
        height: 40px;
        border: 1px solid var(--pfx-sidebar-border, rgba(255,255,255,.14));
        border-radius: 10px;
        background: var(--pfx-sidebar-widget-bg, rgba(255,255,255,.08));
        color: var(--pfx-sidebar-text, #fff);
        font-size: 17px;
        cursor: pointer;
    }
    #perfex-sidebar .sidebar-nav li a,
    #perfex-sidebar .submenu-row,
    #perfex-sidebar .submenu li a {
        min-height: 44px;
    }

    /* Compact mobile app bar. Search opens as a full-width second row. */
    #perfex-header { height: 58px !important; overflow: visible; }
    .header-inner {
        padding-left: calc(8px + env(safe-area-inset-left)) !important;
        padding-right: calc(8px + env(safe-area-inset-right)) !important;
        gap: 6px !important;
        min-width: 0;
    }
    .bh-mobile-menu-button,
    .bh-mobile-search-button {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        flex: 0 0 40px;
        width: 40px;
        height: 40px;
        min-width: 40px;
        border: 1px solid var(--bh-ui-border);
        border-radius: 10px;
        background: var(--bh-ui-surface);
        color: #475569;
        box-shadow: 0 1px 2px rgba(15,23,42,.04);
        cursor: pointer;
    }
    .header-mobile-logo {
        display: flex !important;
        align-items: center;
        flex: 1 1 auto;
        min-width: 0;
        max-width: 180px;
        overflow: hidden;
        text-overflow: ellipsis;
        font-size: .95rem;
    }
    .header-mobile-logo img {
        max-width: 145px !important;
        max-height: 30px !important;
        object-fit: contain;
    }
    .bh-header-actions { flex: 0 0 auto; min-width: 0; }
    .header-user-chip { min-width: 40px; min-height: 40px; }

    /* mobile.css hides this by default; the search button reveals it. */
    body.mobile-search-open .header-search {
        box-sizing:border-box;
        display: flex !important;
        position: absolute !important;
        top: 100%;
        left: 0;
        right: 0;
        width: 100% !important;
        max-width: none !important;
        min-width: 0 !important;
        margin: 0 !important;
        padding: 10px calc(12px + env(safe-area-inset-right)) 10px calc(12px + env(safe-area-inset-left));
        gap: 8px;
        background: #fff;
        border-bottom: 1px solid var(--bh-ui-border);
        box-shadow: 0 8px 22px rgba(15,23,42,.10);
        z-index: 1002;
    }
    body.mobile-search-open .header-search-icon {
        left: calc(24px + env(safe-area-inset-left));
    }
    body.mobile-search-open #global-search-input {
        height: 42px !important;
        min-height: 42px;
        font-size: 16px !important;
    }
    body.mobile-search-open #global-search-btn {
        height: 42px;
        min-height: 42px;
        padding-left: 15px;
        padding-right: 15px;
    }
    body.mobile-search-open .bh-global-search-results {
        top: calc(100% + 4px);
        left: calc(10px + env(safe-area-inset-left));
        right: calc(10px + env(safe-area-inset-right));
        max-height: 420px;
        border-radius: 12px;
    }

    /* Keep account menus inside the viewport. */
    .header-dropdown-panel {
        position: fixed !important;
        top: 54px !important;
        right: calc(8px + env(safe-area-inset-right)) !important;
        left: auto !important;
        width: min(320px, calc(100vw - 16px)) !important;
        max-width: calc(100vw - 16px) !important;
    }

    /* Content rhythm and touch-friendly controls. */
    #perfex-content {
        box-sizing:border-box;
        width:100% !important;
        max-width:100% !important;
        min-width:0 !important;
        overflow-x:hidden;
        padding:14px 12px calc(32px + env(safe-area-inset-bottom)) !important;
    }
    #perfex-content > * { box-sizing:border-box; min-width:0 !important; max-width:100% !important; }
    #perfex-content .row, #perfex-content [class*="layout"], #perfex-content [class*="wrapper"] { min-width:0; max-width:100%; }
    .card, .panel, .pfx-card, .data-card { max-width: 100% !important; }
    .card-header, .panel-heading {
        gap: 8px;
        flex-wrap: wrap;
    }
    .form-control,
    input[type=text], input[type=email], input[type=password], input[type=number],
    input[type=tel], input[type=url], input[type=date], input[type=time],
    input[type=search], select, textarea {
        font-size: 16px !important; /* avoids iOS focus zoom */
        min-height: 44px;
    }
    textarea { min-height: 110px; }
    .btn, button.btn, a.btn {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 7px;
    }

    /* Page actions wrap instead of falling off-screen. */
    .page-title-area {
        width: 100%;
        gap: 10px !important;
        margin-bottom: 14px !important;
    }
    .page-title-actions {
        width: 100%;
        display: flex !important;
        flex-wrap: wrap;
        gap: 8px;
    }
    .page-title-actions .btn,
    .page-title-actions > a,
    .page-title-actions > button {
        flex: 1 1 140px;
        min-width: 0;
    }

    /* Tables stay contained and have smooth horizontal touch scrolling. */
    .table-container, .table-responsive, .table-wrap,
    .card:has(> table), .panel:has(> table) {
        max-width: 100% !important;
        overflow-x: auto !important;
        overscroll-behavior-inline: contain;
        -webkit-overflow-scrolling: touch;
    }
    .table-container table, .table-responsive table, .table-wrap table {
        margin-bottom: 0;
    }

    /* Dialogs behave like roomy mobile sheets, not edge-to-edge desktop boxes. */
    .modal-overlay { padding: 10px !important; }
    .modal-dialog, .pfx-modal-dialog, [role="dialog"] {
        width: calc(100% - 20px) !important;
        max-width: calc(100% - 20px) !important;
        max-height: calc(100% - 20px);
        margin: 10px !important;
    }
    .modal-header, .modal-footer { padding-left: 14px !important; padding-right: 14px !important; }
    .modal-footer { display: flex; flex-wrap: wrap; gap: 8px; }
    .modal-footer .btn { flex: 1 1 120px; }

    /* Common filter/tool rows may wrap freely. */
    .filters, .filter-row, .toolbar, .table-toolbar, .list-toolbar,
    .search-row, .card-actions, .action-buttons {
        max-width: 100%;
        flex-wrap: wrap !important;
        gap: 8px !important;
    }
}

@media (max-width: 560px) {
    /* Most inline multi-column content grids are desktop layouts. Collapse them
       at phone width while keeping the known compact KPI grids below. */
    #perfex-content [style*="grid-template-columns"][style*="1fr 1fr"]:not(.stat-cards-row):not(.project-stats-grid):not(.tuesday-stats):not(.project-kpi-grid),
    #perfex-content [style*="grid-template-columns"][style*="1fr 2fr"],
    #perfex-content [style*="grid-template-columns"][style*="2fr 1fr"],
    #perfex-content [style*="grid-template-columns"][style*="200px 1fr"],
    #perfex-content [style*="grid-template-columns"][style*="1fr 240px"],
    #perfex-content [style*="grid-template-columns"][style*="1fr 260px"],
    #perfex-content [style*="grid-template-columns"][style*="1fr 280px"],
    #perfex-content [style*="grid-template-columns"][style*="1fr 300px"],
    #perfex-content [style*="grid-template-columns"][style*="1fr 320px"],
    #perfex-content [style*="grid-template-columns"][style*="1fr 340px"],
    #perfex-content [style*="grid-template-columns"][style*="1fr 360px"],
    #perfex-content [style*="grid-template-columns"][style*="1fr 40px 1fr"],
    #perfex-content [style*="grid-template-columns"][style*="2fr 1fr 1fr 1fr"],
    #perfex-content [style*="grid-template-columns"][style*="1fr 1fr 1fr"] {
        grid-template-columns: minmax(0, 1fr) !important;
    }

    /* KPI/stat groups remain compact at two columns where practical. */
    #perfex-content .stat-cards-row,
    #perfex-content .project-stats-grid,
    #perfex-content .tuesday-stats,
    #perfex-content .project-kpi-grid,
    #perfex-content [style*="repeat(4,1fr)"],
    #perfex-content [style*="repeat(4, 1fr)"],
    #perfex-content [style*="repeat(5,1fr)"],
    #perfex-content [style*="repeat(5, 1fr)"] {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 10px !important;
    }

    .stat-card { min-width: 0 !important; padding: 14px !important; }
    .stat-card-value { font-size: 21px !important; overflow-wrap: anywhere; }

    /* Header prioritizes navigation, search and account controls on phones. */
    .bh-header-actions > .bh-header-action,
    .bh-header-actions > .header-divider {
        display: none !important;
    }
    .header-mobile-logo { max-width: 150px; }
    .header-user-name, .header-user-caret { display: none !important; }
    .header-user-chip { padding: 4px !important; }

    .page-title-actions .btn,
    .page-title-actions > a,
    .page-title-actions > button { flex-basis: calc(50% - 4px); }
}

@media (max-width: 390px) {
    .header-mobile-logo { max-width: 112px; font-size: .85rem; }
    .header-mobile-logo img { max-width: 105px !important; }
    #perfex-content { padding-left: 9px !important; padding-right: 9px !important; }
    .page-title-actions .btn,
    .page-title-actions > a,
    .page-title-actions > button { flex-basis: 100%; }
}

@media (max-width: 350px) {
    #perfex-content .stat-cards-row,
    #perfex-content .project-stats-grid,
    #perfex-content .tuesday-stats,
    #perfex-content .project-kpi-grid,
    #perfex-content [style*="repeat(4,1fr)"],
    #perfex-content [style*="repeat(4, 1fr)"],
    #perfex-content [style*="repeat(5,1fr)"],
    #perfex-content [style*="repeat(5, 1fr)"] {
        grid-template-columns: minmax(0, 1fr) !important;
    }
}

/* --------------------------------------------------------------------------
   Shared hub cards (Sales Center / Finance Center / Misc)
   1.1.16: class-based hover state prevents inline-style reserialization from
   defeating dark-mode selectors after mouse interaction.
   -------------------------------------------------------------------------- */
.bh-hub-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 18px;
}

.bh-hub-card {
    min-width: 0;
    display: flex;
    flex-direction: column;
    padding: 22px;
    border: 1px solid #e5e7eb;
    border-radius: 14px;
    background: #fff;
    color: #111827;
    text-decoration: none !important;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .025);
    transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease, background-color .16s ease;
}

.bh-hub-card:hover,
.bh-hub-card:focus-visible {
    background: #fff;
    border-color: #cbd5e1;
    color: #111827;
    text-decoration: none !important;
    transform: translateY(-2px);
    box-shadow: 0 10px 24px -12px rgba(15, 23, 42, .22);
}

.bh-hub-card:focus-visible {
    outline: 3px solid rgba(59, 130, 246, .28);
    outline-offset: 2px;
}

.bh-hub-card-icon {
    width: 64px;
    height: 64px;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 14px;
    border-radius: 12px;
    background: var(--bh-hub-icon-bg, #eff6ff);
}

.bh-hub-card-icon i {
    font-size: 28px;
    color: var(--bh-hub-accent, #3b82f6);
}

.bh-hub-card-title {
    margin-bottom: 6px;
    color: #111827;
    font-size: 15px;
    font-weight: 700;
}

.bh-hub-card-desc {
    flex: 1;
    color: #6b7280;
    font-size: 13px;
    line-height: 1.6;
}

.bh-hub-card-stat {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid #f3f4f6;
    color: var(--bh-hub-accent, #3b82f6);
    font-size: 12px;
    font-weight: 600;
}

@media (max-width: 1200px) {
    .bh-hub-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
    .bh-hub-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 560px) {
    .bh-hub-grid { grid-template-columns: 1fr; gap: 12px; }
    .bh-hub-card { padding: 18px; }
    .bh-hub-card-icon { width: 54px; height: 54px; }
    .bh-hub-card-icon i { font-size: 24px; }
}
