:root {
    --bm-primary: #2563eb;
    --bm-primary-dark: #1d4ed8;
    --bm-success: #16a34a;
    --bm-warning: #f59e0b;
    --bm-danger: #dc2626;
    --bm-info: #0891b2;
    --bm-sidebar: #111827;
    --bm-sidebar-hover: #1f2937;
    --bm-sidebar-text: #cbd5e1;
    --bm-sidebar-muted: #64748b;
    --bm-page-bg: #f5f7fb;
    --bm-border: #e5e7eb;
    --bm-text: #1f2937;
    --bm-muted: #64748b;
    --bm-sidebar-width: 260px;
    --bm-sidebar-compact-width: 82px;
    --bm-mobile-sidebar-width: 300px;
    --bm-topbar-height: 72px;
}

html {
    min-height: 100%;
    font-size: 14px;
}

@media (min-width: 768px) {
    html {
        font-size: 16px;
    }
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--bm-text);
    background-color: var(--bm-page-bg);
    font-family: Inter, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* =========================================================
   APP SHELL
   ========================================================= */

.app-shell {
    min-height: 100vh;
}

.app-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1030;
    width: var(--bm-sidebar-width);
    overflow-x: hidden;
    overflow-y: auto;
    color: #fff;
    background: var(--bm-sidebar);
    overscroll-behavior: contain;
}

/* =========================================================
   SIDEBAR
   ========================================================= */

.sidebar-brand {
    display: flex;
    align-items: center;
    min-height: var(--bm-topbar-height);
    padding: 0 1.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-brand-link {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 0.75rem;
    color: #fff;
    text-decoration: none;
}

    .sidebar-brand-link:hover,
    .sidebar-brand-link:focus {
        color: #fff;
    }

    .sidebar-brand-link img {
        display: block;
        max-width: 100%;
        max-height: 48px;
        object-fit: contain;
    }

.sidebar-brand-icon {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--bm-primary);
    font-size: 1.25rem;
}

.sidebar-brand-text {
    overflow: hidden;
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-content {
    padding: 1.25rem 0.85rem 2rem;
}

.sidebar-section-label {
    margin: 1.25rem 0.75rem 0.55rem;
    color: var(--bm-sidebar-muted);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

    .sidebar-section-label:first-child {
        margin-top: 0;
    }

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.sidebar-link {
    position: relative;
    display: flex;
    min-width: 0;
    min-height: 46px;
    align-items: center;
    gap: 0.85rem;
    padding: 0.7rem 0.85rem;
    color: var(--bm-sidebar-text);
    border-radius: 10px;
    text-decoration: none;
    touch-action: manipulation;
    transition: color 0.15s ease, background-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

    .sidebar-link i {
        flex: 0 0 auto;
        width: 22px;
        font-size: 1.15rem;
        text-align: center;
    }

    .sidebar-link > span:not( .sidebar-coming-soon) {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .sidebar-link:hover,
    .sidebar-link:focus-visible {
        color: #fff;
        background: var(--bm-sidebar-hover);
        transform: translateX(2px);
    }

    .sidebar-link.active {
        color: #fff;
        background: var(--bm-primary);
        box-shadow: 0 8px 18px rgba(37, 99, 235, 0.24);
    }

        .sidebar-link.active::before {
            position: absolute;
            top: 9px;
            bottom: 9px;
            left: -0.85rem;
            width: 4px;
            border-radius: 0 4px 4px 0;
            background: #93c5fd;
            content: "";
        }

    .sidebar-link.disabled {
        cursor: not-allowed;
        opacity: 0.5;
        pointer-events: none;
    }

.sidebar-coming-soon {
    flex: 0 0 auto;
    margin-left: auto;
    padding: 0.12rem 0.4rem;
    border-radius: 999px;
    color: #bfdbfe;
    background: rgba(37, 99, 235, 0.22);
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
}

/* =========================================================
   MAIN CONTENT
   ========================================================= */

.app-main {
    min-height: 100vh;
    margin-left: var(--bm-sidebar-width);
}

.app-topbar {
    position: sticky;
    top: 0;
    z-index: 1020;
    display: flex;
    min-height: var(--bm-topbar-height);
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    border-bottom: 1px solid var(--bm-border);
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 1px 4px rgba(15, 23, 42, 0.04);
    backdrop-filter: blur(10px);
}

.topbar-left,
.topbar-right {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 0.75rem;
}

.topbar-page-title {
    overflow: hidden;
    color: var(--bm-text);
    font-size: 1rem;
    font-weight: 650;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.topbar-page-context {
    display: flex;
    min-width: 0;
    flex-direction: column;
    justify-content: center;
    line-height: 1.15;
}

.topbar-section-label {
    overflow: hidden;
    margin-bottom: 0.15rem;
    color: var(--bm-muted);
    font-size: 0.66rem;
    font-weight: 750;
    letter-spacing: 0.08em;
    text-overflow: ellipsis;
    text-transform: uppercase;
    white-space: nowrap;
}

.topbar-create-button {
    display: inline-flex;
    min-height: 40px;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    padding: 0.45rem 0.8rem;
    color: #fff;
    border: 1px solid var(--bm-primary);
    border-radius: 10px;
    background: var(--bm-primary);
    font-size: 0.86rem;
    font-weight: 700;
    line-height: 1;
    transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.topbar-create-button:hover,
.topbar-create-button:focus-visible,
.topbar-create-button[aria-expanded="true"] {
    color: #fff;
    border-color: var(--bm-primary-dark);
    background: var(--bm-primary-dark);
    box-shadow: 0 0 0 0.2rem rgba(37, 99, 235, 0.12);
    outline: none;
}

.topbar-create-button::after {
    margin-left: 0.1rem;
}

.topbar-create-menu {
    min-width: 14rem;
    padding: 0.45rem;
}

.topbar-create-menu .dropdown-header {
    margin: 0;
    padding: 0.45rem 0.65rem 0.35rem;
    color: var(--bm-muted);
    font-size: 0.7rem;
    font-weight: 750;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.topbar-create-menu .dropdown-item {
    display: flex;
    min-height: 40px;
    align-items: center;
    border-radius: 8px;
    font-weight: 600;
}

.topbar-menu-button {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    color: var(--bm-text);
    border: 0;
    border-radius: 10px;
    background: transparent;
    font-size: 1.75rem;
}

    .topbar-menu-button:hover,
    .topbar-menu-button:focus-visible {
        color: var(--bm-primary);
        background: #eff6ff;
        outline: none;
    }

.topbar-icon-button {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    color: var(--bm-muted);
    border: 1px solid var(--bm-border);
    border-radius: 50%;
    background: #fff;
}

    .topbar-icon-button:hover {
        color: var(--bm-primary);
        background: #eff6ff;
    }

    .topbar-icon-button:disabled {
        cursor: default;
        opacity: 0.65;
    }

.topbar-user .nav-link,
.topbar-user a {
    color: var(--bm-text) !important;
    font-weight: 600;
}

    .topbar-user .nav-link:hover,
    .topbar-user a:hover {
        color: var(--bm-primary) !important;
    }

.app-page {
    min-width: 0;
    padding: 2rem;
}

/* =========================================================
   GENERAL UI
   ========================================================= */

.card {
    border: 1px solid rgba(229, 231, 235, 0.8);
    border-radius: 15px;
    background: #fff;
    box-shadow: 0 5px 18px rgba(15, 23, 42, 0.05);
}

.card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--bm-border);
    border-radius: 15px 15px 0 0 !important;
    background: #fff;
}

.card-footer {
    border-top: 1px solid var(--bm-border);
    border-radius: 0 0 15px 15px !important;
}

.btn {
    border-radius: 9px;
    font-weight: 600;
}

.btn-primary {
    border-color: var(--bm-primary);
    background-color: var(--bm-primary);
}

    .btn-primary:hover,
    .btn-primary:focus {
        border-color: var(--bm-primary-dark);
        background-color: var(--bm-primary-dark);
    }

.form-control,
.form-select {
    min-height: 42px;
    border-color: #d1d5db;
    border-radius: 9px;
}

    .form-control:focus,
    .form-select:focus {
        border-color: #93c5fd;
        box-shadow: 0 0 0 0.2rem rgba(37, 99, 235, 0.12);
    }

.table > :not(caption) > * > * {
    padding: 0.85rem 0.9rem;
}

.table thead th {
    color: #64748b;
    font-size: 0.76rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.table-responsive {
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
}

.text-muted {
    color: var(--bm-muted) !important;
}

/* =========================================================
   DASHBOARD
   ========================================================= */

.dashboard-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.dashboard-title {
    margin: 0;
    font-size: 1.75rem;
    font-weight: 750;
    letter-spacing: -0.03em;
}

.dashboard-subtitle {
    margin: 0.3rem 0 0;
    color: var(--bm-muted);
}

.metric-card {
    position: relative;
    min-height: 148px;
    overflow: hidden;
}

    .metric-card .card-body {
        padding: 1.35rem;
    }

.metric-label {
    margin-bottom: 0.45rem;
    color: var(--bm-muted);
    font-size: 0.74rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.metric-value {
    margin-bottom: 0.25rem;
    font-size: 2rem;
    font-weight: 750;
    letter-spacing: -0.04em;
}

.metric-description {
    color: var(--bm-muted);
    font-size: 0.82rem;
}

.metric-icon {
    position: absolute;
    top: 1.25rem;
    right: 1.25rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: 13px;
    font-size: 1.35rem;
}

.metric-icon-primary {
    color: var(--bm-primary);
    background: #dbeafe;
}

.metric-icon-success {
    color: var(--bm-success);
    background: #dcfce7;
}

.metric-icon-warning {
    color: #d97706;
    background: #fef3c7;
}

.metric-icon-danger {
    color: var(--bm-danger);
    background: #fee2e2;
}

.metric-icon-info {
    color: var(--bm-info);
    background: #cffafe;
}

.widget-card {
    height: 100%;
}

    .widget-card .card-body {
        padding: 0;
    }

.widget-header-title {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    font-weight: 700;
}

    .widget-header-title i {
        color: var(--bm-primary);
    }

.dashboard-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.dashboard-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid #eef2f7;
}

    .dashboard-list-item:last-child {
        border-bottom: 0;
    }

    .dashboard-list-item:hover {
        background: #f8fafc;
    }

.dashboard-list-main {
    min-width: 0;
}

.dashboard-list-title {
    overflow: hidden;
    margin-bottom: 0.15rem;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dashboard-list-subtitle {
    overflow: hidden;
    color: var(--bm-muted);
    font-size: 0.83rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dashboard-list-meta {
    flex-shrink: 0;
    text-align: right;
}

.quick-action-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
    padding: 1.25rem;
}

.quick-action {
    display: flex;
    min-height: 104px;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    padding: 1rem;
    color: var(--bm-text);
    border: 1px solid var(--bm-border);
    border-radius: 12px;
    background: #fff;
    text-decoration: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

    .quick-action:hover {
        color: var(--bm-primary);
        border-color: #bfdbfe;
        box-shadow: 0 8px 20px rgba(37, 99, 235, 0.08);
        transform: translateY(-2px);
    }

    .quick-action.disabled {
        cursor: not-allowed;
        opacity: 0.55;
        pointer-events: none;
    }

.quick-action-icon {
    margin-bottom: 0.65rem;
    color: var(--bm-primary);
    font-size: 1.45rem;
}

.quick-action-title {
    font-size: 0.9rem;
    font-weight: 700;
}

.activity-list {
    margin: 0;
    padding: 0.5rem 1.25rem;
    list-style: none;
}

.activity-item {
    position: relative;
    display: flex;
    gap: 0.9rem;
    padding: 0.85rem 0;
    border-bottom: 1px solid #eef2f7;
}

    .activity-item:last-child {
        border-bottom: 0;
    }

.activity-icon {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    color: #fff;
    border-radius: 50%;
}

.activity-content {
    min-width: 0;
}

.activity-description {
    margin-bottom: 0.2rem;
    color: var(--bm-text);
    font-size: 0.88rem;
}

.activity-date {
    color: var(--bm-muted);
    font-size: 0.75rem;
}

.dashboard-empty {
    padding: 2.75rem 1.25rem;
    color: var(--bm-muted);
    text-align: center;
}

    .dashboard-empty i {
        display: block;
        margin-bottom: 0.75rem;
        font-size: 2.2rem;
    }

.status-badge {
    padding: 0.38rem 0.6rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
}

/* =========================================================
   MOBILE NAVIGATION OVERLAY
   ========================================================= */

/*
 * Both elements are completely removed from rendering until
 * JavaScript adds is-mounted. They cannot move page content
 * or appear beneath the current page.
 */

.mobile-nav-backdrop {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: none;
    opacity: 0;
    background: rgba(15, 23, 42, 0.68);
    backdrop-filter: blur(2px);
    transition: opacity 0.25s ease;
}

    .mobile-nav-backdrop.is-mounted {
        display: block;
    }

    .mobile-nav-backdrop.is-visible {
        opacity: 1;
    }

.mobile-nav-drawer {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 2010;
    display: none;
    width: min( 86vw, var(--bm-mobile-sidebar-width));
    max-width: 320px;
    height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
    color: #fff;
    background: var(--bm-sidebar);
    box-shadow: 18px 0 45px rgba(15, 23, 42, 0.38);
    overscroll-behavior: contain;
    transform: translate3d(-105%, 0, 0);
    will-change: transform;
    -webkit-overflow-scrolling: touch;
    transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}

    .mobile-nav-drawer.is-mounted {
        display: block;
    }

    .mobile-nav-drawer.is-open {
        transform: translate3d(0, 0, 0);
    }

    .mobile-nav-drawer .sidebar-brand {
        padding-right: 4.5rem;
    }

    .mobile-nav-drawer .sidebar-content {
        padding-bottom: calc( 2rem + env(safe-area-inset-bottom));
    }

.mobile-nav-close {
    position: absolute;
    top: 15px;
    right: 14px;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    padding: 0;
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.08);
    font-size: 1.15rem;
}

    .mobile-nav-close:hover,
    .mobile-nav-close:focus-visible {
        color: #fff;
        background: rgba(255, 255, 255, 0.16);
        outline: none;
    }

body.mobile-nav-open {
    overflow: hidden;
}

    body.mobile-nav-open .app-shell {
        /*
     * Prevents touch scrolling and interaction with the
     * application beneath the drawer.
     */
        pointer-events: none;
        user-select: none;
    }

    body.mobile-nav-open
    .mobile-nav-drawer,
    body.mobile-nav-open
    .mobile-nav-backdrop {
        pointer-events: auto;
        user-select: auto;
    }

/* =========================================================
   RESPONSIVE
   ========================================================= */

@media (max-width: 991.98px) {
    .app-sidebar {
        display: none;
    }

    .app-main {
        margin-left: 0;
    }

    .app-topbar {
        padding: 0 max( 1rem, env(safe-area-inset-right)) 0 max( 0.75rem, env(safe-area-inset-left));
    }

    .app-page {
        padding: 1.25rem;
    }

    .dashboard-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .topbar-right {
        gap: 0.4rem;
    }
}

@media (min-width: 992px) {
    .mobile-nav-drawer,
    .mobile-nav-backdrop {
        display: none !important;
    }
}

@media (max-width: 575.98px) {
    .topbar-section-label {
        display: none;
    }

    .topbar-page-context {
        max-width: min(42vw, 12rem);
    }

    .topbar-create-button {
        width: 38px;
        min-height: 38px;
        padding: 0;
        border-radius: 50%;
    }

    .app-page {
        padding: 1rem 0.75rem calc( 1rem + env(safe-area-inset-bottom));
    }

    .topbar-page-title {
        font-size: 1.05rem;
    }

    .topbar-icon-button {
        width: 38px;
        height: 38px;
    }

    .quick-action-grid {
        grid-template-columns: 1fr;
    }

    .dashboard-list-item {
        align-items: flex-start;
        flex-direction: column;
    }

    .dashboard-list-meta {
        text-align: left;
    }
}

/* =========================================================
   REDUCED MOTION
   ========================================================= */

@media (prefers-reduced-motion: reduce) {
    .mobile-nav-drawer,
    .mobile-nav-backdrop,
    .sidebar-link,
    .quick-action {
        transition: none;
    }
}

/* =========================================================
   VALIDATION
   ========================================================= */

.field-validation-error {
    display: block;
    margin-top: 0.25rem;
    font-size: 0.82rem;
}

.input-validation-error {
    border-color: var(--bm-danger);
}

/* =========================================================
   CLICKABLE RECORD LINKS
   ========================================================= */

/*
 * Keep customer names and invoice numbers visually consistent
 * with ordinary table text. The adjacent blue icon identifies
 * the value as clickable, and the pointer cursor remains visible
 * on hover.
 */
a.bm-record-link,
a.bm-record-link:link,
a.bm-record-link:visited,
a.customer-quick-card-trigger,
a.customer-quick-card-trigger:link,
a.customer-quick-card-trigger:visited {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    color: inherit !important;
    font-weight: inherit;
    text-decoration: none !important;
    cursor: pointer;
}

a.bm-record-link:hover,
a.bm-record-link:active,
a.bm-record-link:focus,
a.bm-record-link:focus-visible,
a.customer-quick-card-trigger:hover,
a.customer-quick-card-trigger:active,
a.customer-quick-card-trigger:focus,
a.customer-quick-card-trigger:focus-visible {
    color: inherit !important;
    text-decoration: none !important;
    cursor: pointer;
}

a.bm-record-link:focus-visible,
a.customer-quick-card-trigger:focus-visible {
    border-radius: 0.25rem;
    outline: 3px solid rgba(37, 99, 235, 0.22);
    outline-offset: 3px;
}

.bm-record-link-icon {
    flex: 0 0 auto;
    color: var(--bm-primary);
    font-size: 0.82rem;
    line-height: 1;
    opacity: 0.9;
    text-decoration: none !important;
    transition: opacity 0.15s ease, transform 0.15s ease;
}

a.bm-record-link:hover .bm-record-link-icon,
a.bm-record-link:focus-visible .bm-record-link-icon,
a.customer-quick-card-trigger:hover .bm-record-link-icon,
a.customer-quick-card-trigger:focus-visible .bm-record-link-icon {
    opacity: 1;
    transform: translateX(2px);
}

a.bm-record-link *,
a.customer-quick-card-trigger * {
    text-decoration: none !important;
}

@media (prefers-reduced-motion: reduce) {
    .bm-record-link-icon {
        transition: none;
    }

    a.bm-record-link:hover .bm-record-link-icon,
    a.bm-record-link:focus-visible .bm-record-link-icon,
    a.customer-quick-card-trigger:hover .bm-record-link-icon,
    a.customer-quick-card-trigger:focus-visible .bm-record-link-icon {
        transform: none;
    }
}


.topbar-user .dropdown-toggle {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
}

.topbar-user-identity {
    display: inline-flex;
    align-items: center;
    min-width: 0;
    white-space: nowrap;
}

.topbar-user-name {
    font-weight: 700;
}

.topbar-user-subtitle {
    margin-left: .3rem;
    color: var(--bs-secondary-color);
    font-size: .82rem;
    font-weight: 600;
}

@media (max-width: 767.98px) {
    .topbar-user-subtitle { display: none; }
}

/* Compact, card-style identity control used by the dashboard header. */
.topbar-user-button {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    min-height: 38px;
    max-width: min(360px, 42vw);
    padding: .35rem .75rem .35rem .4rem;
    color: var(--bs-emphasis-color);
    background: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color);
    border-radius: 999px;
    box-shadow: 0 .15rem .5rem rgba(15, 23, 42, .04);
    font: inherit;
    line-height: 1;
    transition: border-color .15s ease, box-shadow .15s ease, background-color .15s ease;
}

.topbar-user-button:hover,
.topbar-user-button:focus-visible,
.topbar-user-button[aria-expanded="true"] {
    color: var(--bs-emphasis-color);
    background: var(--bs-tertiary-bg);
    border-color: rgba(37, 99, 235, .35);
    box-shadow: 0 0 0 .2rem rgba(37, 99, 235, .08);
}

.topbar-user-button::after {
    margin-left: .1rem;
    border-top-width: .32em;
    border-right-width: .32em;
    border-left-width: .32em;
}

.topbar-user-avatar {
    display: inline-grid;
    place-items: center;
    width: 1.75rem;
    height: 1.75rem;
    flex: 0 0 1.75rem;
    color: #2563eb;
    background: rgba(37, 99, 235, .1);
    border-radius: 50%;
    font-size: .82rem;
}

.topbar-user-button .topbar-user-identity {
    overflow: hidden;
}

.topbar-user-button .topbar-user-name {
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: .86rem;
    font-weight: 700;
}

.topbar-user-button .topbar-user-subtitle {
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: .76rem;
    font-weight: 600;
}

@media (max-width: 575.98px) {
    .topbar-user-button {
        max-width: 190px;
        padding-right: .55rem;
    }
}


/* =========================================================
   DESKTOP COMPACT SIDEBAR (ICON ONLY + TOOLTIPS)
   ========================================================= */
@media (min-width: 992px) {
    .app-sidebar,
    .app-main {
        transition: width 0.2s ease, margin-left 0.2s ease;
    }

    body.sidebar-compact .app-sidebar {
        width: var(--bm-sidebar-compact-width);
        overflow-x: visible;
        overflow-y: auto;
    }

    body.sidebar-compact .app-main {
        margin-left: var(--bm-sidebar-compact-width);
    }

    body.sidebar-compact .app-sidebar .sidebar-brand {
        justify-content: center;
        padding-inline: 0.75rem;
    }

    body.sidebar-compact .app-sidebar .sidebar-brand-link {
        justify-content: center;
        gap: 0;
    }

    body.sidebar-compact .app-sidebar .sidebar-brand-text {
        display: none;
    }

    body.sidebar-compact .app-sidebar .sidebar-content {
        padding: 1rem 0.65rem 2rem;
    }

    body.sidebar-compact .app-sidebar .sidebar-section-label {
        height: 1px;
        margin: 0.8rem 0.35rem;
        overflow: hidden;
        background: rgba(255, 255, 255, 0.09);
        color: transparent;
        font-size: 0;
    }

    body.sidebar-compact .app-sidebar .sidebar-section-label:first-child {
        margin-top: 0;
    }

    body.sidebar-compact .app-sidebar .sidebar-nav {
        gap: 0.35rem;
    }

    body.sidebar-compact .app-sidebar .sidebar-link {
        position: relative;
        justify-content: center;
        width: 54px;
        min-height: 52px;
        margin-inline: auto;
        padding: 0;
        gap: 0;
        border-radius: 13px;
        overflow: visible;
    }

    body.sidebar-compact .app-sidebar .sidebar-link > i {
        width: auto;
        font-size: 1.28rem;
    }

    body.sidebar-compact .app-sidebar .sidebar-link > span {
        display: none;
    }

    body.sidebar-compact .app-sidebar .sidebar-link:hover,
    body.sidebar-compact .app-sidebar .sidebar-link:focus-visible {
        transform: none;
    }

    body.sidebar-compact .app-sidebar .sidebar-link.active::before {
        top: 10px;
        bottom: 10px;
        left: -0.65rem;
    }

    /* Tooltip is rendered under <body> so the scrollable sidebar cannot clip it. */
    .sidebar-floating-tooltip {
        position: fixed;
        z-index: 2000;
        max-width: 240px;
        padding: 0.5rem 0.7rem;
        border: 1px solid rgba(255, 255, 255, 0.1);
        border-radius: 8px;
        background: #0f172a;
        box-shadow: 0 10px 28px rgba(15, 23, 42, 0.28);
        color: #fff;
        font-size: 0.8rem;
        font-weight: 600;
        line-height: 1.2;
        opacity: 0;
        pointer-events: none;
        transform: translateX(4px);
        transition: opacity 0.12s ease, transform 0.12s ease;
        white-space: nowrap;
    }

    .sidebar-floating-tooltip.is-visible {
        opacity: 1;
        transform: translateX(0);
    }

    #desktopSidebarToggle i {
        transition: transform 0.2s ease;
    }

    body.sidebar-compact #desktopSidebarToggle i {
        transform: scaleX(-1);
    }
}


/* =========================================================
   ACCOUNT MENU + NOTIFICATIONS
   ========================================================= */
.topbar-user-menu { min-width: 260px; padding-top: .45rem; padding-bottom: .45rem; }
.topbar-user-menu .dropdown-item { display:flex; align-items:center; padding:.58rem .9rem; }
.notification-bell-button { position:relative; }
.notification-unread-count { position:absolute; top:-.2rem; right:-.25rem; display:grid; place-items:center; min-width:1.15rem; height:1.15rem; padding:0 .25rem; border:2px solid var(--bs-body-bg); border-radius:999px; color:#fff; background:#dc2626; font-size:.62rem; font-weight:800; line-height:1; }
.notification-dropdown { width:min(390px,calc(100vw - 1.5rem)); overflow:hidden; border-radius:.9rem; box-shadow:0 1rem 2.6rem rgba(15,23,42,.16); }
.notification-dropdown-header { display:flex; align-items:center; justify-content:space-between; gap:1rem; padding:1rem; border-bottom:1px solid var(--bs-border-color); }
.notification-empty-state { padding:2rem 1.25rem; text-align:center; }
.notification-empty-icon { display:grid; place-items:center; width:3rem; height:3rem; margin:0 auto; border-radius:50%; color:#2563eb; background:rgba(37,99,235,.1); font-size:1.25rem; }
.notification-list { max-height:360px; overflow-y:auto; }
.notification-item { display:flex; gap:.75rem; padding:.9rem 1rem; color:var(--bs-body-color); text-decoration:none; border-bottom:1px solid var(--bs-border-color); }
.notification-item:hover { background:var(--bs-tertiary-bg); }
.notification-item-icon { display:grid; place-items:center; width:2rem; height:2rem; flex:0 0 2rem; border-radius:.55rem; color:#2563eb; background:rgba(37,99,235,.09); }
.notification-item-content { display:grid; min-width:0; }
.notification-item-title { font-weight:750; }
.notification-item-message,.notification-item-time { color:var(--bs-secondary-color); font-size:.8rem; }
.notification-dropdown-footer { padding:.75rem 1rem; text-align:center; background:var(--bs-tertiary-bg); border-top:1px solid var(--bs-border-color); }

/* Theme overrides use the existing ApplicationUser.Theme field; no schema change. */
html[data-bm-theme="dark"] {
    --bm-page-bg:#0f172a;
    --bm-border:#334155;
    --bm-text:#e5e7eb;
    --bm-muted:#94a3b8;
}

/* =========================================================
   MOBILE + PERFORMANCE HARDENING
   ========================================================= */
html {
    text-size-adjust: 100%;
    -webkit-text-size-adjust: 100%;
}

img,
svg {
    max-width: 100%;
}

.bm-page-container {
    contain: layout style;
}

.table-responsive {
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
}

.notification-item-title,
.notification-item-message {
    overflow-wrap: anywhere;
}

html[data-notifications-connected="false"] .notification-bell-button::after {
    content: "";
    position: absolute;
    right: .08rem;
    bottom: .08rem;
    width: .45rem;
    height: .45rem;
    border: 1px solid var(--bs-body-bg);
    border-radius: 50%;
    background: var(--bs-secondary-color);
}

@media (max-width: 767.98px) {
    .app-page {
        padding-inline: .75rem;
    }

    .bm-page-container {
        width: 100%;
        min-width: 0;
    }

    .card,
    .bm-card,
    .report-card {
        max-width: 100%;
    }

    .table-responsive > .table {
        min-width: 680px;
    }

    .notification-dropdown {
        position: fixed !important;
        top: 4.25rem !important;
        right: .75rem !important;
        left: .75rem !important;
        width: auto;
        max-height: calc(100dvh - 5rem);
        transform: none !important;
    }

    .notification-list {
        max-height: min(52dvh, 420px);
    }
}

@media (max-width: 575.98px) {
    .topbar-page-title {
        max-width: 42vw;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .topbar-user-button .topbar-user-identity,
    .topbar-user-button::after {
        display: none;
    }

    .topbar-user-button {
        width: 2.4rem;
        min-width: 2.4rem;
        padding: .3rem;
        justify-content: center;
    }

    .topbar-user-avatar {
        margin: 0;
    }
}

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

/* ============================================================
   PHASE 6 - REAL-TIME NOTIFICATIONS
   ============================================================ */
.notification-clear-button {
    padding-inline: .25rem;
    font-weight: 650;
}

.notification-dropdown-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
}

.notification-connection-status {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    color: var(--bs-secondary-color);
    font-size: .78rem;
    white-space: nowrap;
}

.notification-connection-status > .bi-circle-fill {
    color: var(--bs-secondary-color);
    font-size: .45rem;
}

.notification-connection-status[data-status="connected"] > .bi-circle-fill {
    color: var(--bs-success);
}

.notification-connection-status[data-status="connecting"] > .bi-circle-fill,
.notification-connection-status[data-status="reconnecting"] > .bi-circle-fill {
    color: var(--bs-warning);
}

.notification-connection-status[data-status="disconnected"] > .bi-circle-fill,
.notification-connection-status[data-status="unavailable"] > .bi-circle-fill {
    color: var(--bs-danger);
}

@media (max-width: 575.98px) {
    .notification-dropdown-header {
        align-items: flex-start;
    }

    .notification-dropdown-footer {
        align-items: flex-start;
        flex-direction: column-reverse;
    }
}


/* ============================================================
   PHASE 7 - MOBILE + PERFORMANCE HARDENING
   ============================================================ */
:where(button, .btn, a, input, select, textarea) {
    -webkit-tap-highlight-color: transparent;
}

:where(.btn, .page-link, .dropdown-item, .sidebar-link) {
    touch-action: manipulation;
}

.table-responsive {
    scrollbar-gutter: stable;
}

@media (max-width: 767.98px) {
    .app-page {
        padding-bottom: max(1.25rem, env(safe-area-inset-bottom));
    }

    .bm-page-header {
        min-width: 0;
        gap: .85rem;
    }

    .bm-page-header .bm-page-title,
    .bm-page-header .bm-page-subtitle {
        overflow-wrap: anywhere;
    }

    .bm-page-header .bm-page-actions {
        width: 100%;
        min-width: 0;
    }

    .bm-page-header .bm-page-actions > .btn,
    .bm-page-header .bm-page-actions > .dropdown {
        flex: 1 1 auto;
    }

    .form-control,
    .form-select,
    .input-group > .btn,
    .btn:not(.btn-sm),
    .page-link {
        min-height: 44px;
    }

    .btn-sm,
    .bm-table-actions .btn {
        min-width: 40px;
        min-height: 40px;
    }

    .bm-table-actions {
        gap: .35rem;
    }

    .table-responsive {
        margin-inline: -.25rem;
        padding-inline: .25rem;
        scroll-padding-inline: .75rem;
    }

    .operations-sticky-actions,
    .customer-sticky-actions,
    .employee-sticky-actions,
    .estimate-sticky-actions,
    .invoice-editor-actions {
        bottom: env(safe-area-inset-bottom);
    }
}

@media (max-width: 575.98px) {
    .bm-page-header .bm-page-actions {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
    }

    .bm-page-header .bm-page-actions > .btn,
    .bm-page-header .bm-page-actions > .dropdown,
    .bm-page-header .bm-page-actions > .dropdown > .btn {
        width: 100%;
    }

    .pagination {
        flex-wrap: wrap;
        row-gap: .35rem;
    }
}


/* ==========================================================
   AJAX / PARTIAL-PAGE NAVIGATION
   ========================================================== */

#main-content {
    position: relative;
}

#main-content.bm-ajax-loading {
    cursor: progress;
}

#main-content.bm-ajax-loading::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    z-index: 2000;
    background: currentColor;
    opacity: .7;
    animation: bm-ajax-progress 900ms ease-in-out infinite alternate;
    transform-origin: left center;
}

#main-content.bm-ajax-loading .bm-page-container {
    opacity: .72;
    transition: opacity 120ms ease;
}

@keyframes bm-ajax-progress {
    from { transform: scaleX(.18); }
    to { transform: scaleX(.82); }
}

@media (prefers-reduced-motion: reduce) {
    #main-content.bm-ajax-loading::before {
        animation: none;
        transform: scaleX(.65);
    }

    #main-content.bm-ajax-loading .bm-page-container {
        transition: none;
    }
}


/* ==========================================================
   MOBILE FILTER / SEARCH TOOLBAR COMPACTION
   ========================================================== */

/*
   .bm-toolbar-main uses a 600px flex-basis on desktop. When the toolbar
   changes to flex-direction: column, that basis becomes vertical space.
   Reset it at responsive breakpoints so filters size to their content.
*/
@media (max-width: 991.98px) {
    .bm-toolbar > .bm-toolbar-main,
    .operations-crud-page .bm-toolbar > .bm-toolbar-main,
    .customer-page .bm-toolbar > .bm-toolbar-main,
    .invoice-filter-toolbar > .bm-toolbar-main,
    .bm-schedule-list-toolbar > .bm-toolbar-main {
        flex: 0 0 auto;
        width: 100%;
        min-height: 0;
        align-content: flex-start;
    }
}

@media (max-width: 767.98px) {
    .bm-toolbar {
        gap: .8rem;
        padding: .9rem;
    }

    .bm-toolbar > .bm-toolbar-main {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        gap: .75rem;
    }

    .bm-toolbar > .bm-toolbar-main > *,
    .bm-toolbar .bm-search {
        width: 100%;
        min-width: 0;
        flex: none;
    }

    .bm-toolbar-actions {
        margin-top: 0;
        gap: .6rem;
    }
}

@media (min-width: 576px) and (max-width: 767.98px) {
    .bm-toolbar > .bm-toolbar-main {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .bm-toolbar > .bm-toolbar-main > .bm-search,
    .bm-toolbar > .bm-toolbar-main > .bm-toolbar-search {
        grid-column: 1 / -1;
    }
}


/* ==========================================================
   MOBILE INDEX TABLES - VERTICAL CARD LAYOUT
   ========================================================== */

@media (max-width: 767.98px) {
    /*
       The generic mobile table rule previously kept a 680px minimum width.
       That forced horizontal scrolling even after .bm-responsive-table
       switched to the stacked/card presentation.
    */
    .table-responsive > .bm-responsive-table {
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100%;
        margin-bottom: 0;
    }

    .table-responsive:has(> .bm-responsive-table) {
        overflow-x: clip;
    }

    .bm-responsive-table,
    .bm-responsive-table tbody,
    .bm-responsive-table tr,
    .bm-responsive-table td {
        max-width: 100%;
        min-width: 0;
    }

    .bm-responsive-table tbody {
        padding: .6rem;
    }

    .bm-responsive-table tr {
        overflow: hidden;
        margin-bottom: .75rem;
        padding: .75rem;
    }

    .bm-responsive-table td {
        grid-template-columns: minmax(88px, .34fr) minmax(0, .66fr);
        gap: .65rem;
        align-items: start;
        overflow: hidden;
        text-align: left !important;
    }

    .bm-responsive-table td::before {
        min-width: 0;
    }

    .bm-responsive-table td > *,
    .bm-responsive-table td a,
    .bm-responsive-table td strong,
    .bm-responsive-table td span,
    .bm-responsive-table td div {
        min-width: 0;
        max-width: 100%;
        overflow-wrap: anywhere;
        word-break: break-word;
    }

    .bm-responsive-table .bm-table-primary,
    .bm-responsive-table .bm-table-secondary,
    .bm-responsive-table .customer-quick-card-trigger {
        white-space: normal;
    }

    .bm-responsive-table .bm-table-actions {
        display: flex;
        width: 100%;
        flex-wrap: wrap;
        gap: .4rem;
    }

    .bm-responsive-table td.bm-table-actions-cell {
        overflow: visible;
    }
}

@media (max-width: 420px) {
    .bm-responsive-table td {
        display: block;
        padding: .5rem 0 !important;
    }

    .bm-responsive-table td::before {
        display: block;
        margin-bottom: .25rem;
    }

    .bm-responsive-table td.bm-table-actions-cell::before {
        display: none;
    }
}


/* ==========================================================
   STANDARDIZED LIST FILTER TOOLBARS
   ========================================================== */

/*
   Keep filter fields completely independent from the conditional action buttons.
   The field area always receives the full toolbar width, so showing/hiding Clear
   Filters cannot resize or reflow the filters. This class is intentionally
   presentation-only; existing names, data-bm-* hooks, and form submission/AJAX
   behavior remain unchanged.
*/
.bm-list-filter-toolbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: end;
    gap: 1rem;
}

.bm-list-filter-toolbar > .bm-toolbar-main {
    width: 100%;
    min-width: 0;
    flex: none;
}

.bm-list-filter-toolbar > .bm-toolbar-actions {
    display: flex;
    width: 100%;
    min-width: 0;
    margin: 0;
    align-items: center;
    justify-content: flex-end;
    gap: .65rem;
}

.bm-list-filter-toolbar > .bm-toolbar-actions .btn {
    min-height: 46px;
    border-radius: 12px;
    white-space: nowrap;
}

.bm-list-filter-toolbar > .bm-toolbar-actions .btn-outline-secondary {
    min-width: 150px;
}

.bm-list-filter-toolbar > .bm-toolbar-actions .btn-primary {
    min-width: 128px;
}

/* Tablet: field wrapping stays module-specific; actions never steal field width. */
@media (max-width: 991.98px) {
    .bm-list-filter-toolbar > .bm-toolbar-main {
        width: 100%;
        min-height: 0;
    }

    .bm-list-filter-toolbar > .bm-toolbar-actions {
        width: 100%;
        justify-content: flex-end;
    }
}

/* Mobile: use full-width actions and preserve comfortable touch targets. */
@media (max-width: 575.98px) {
    .bm-list-filter-toolbar {
        gap: .8rem;
    }

    .bm-list-filter-toolbar > .bm-toolbar-actions {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        gap: .65rem;
    }

    .bm-list-filter-toolbar > .bm-toolbar-actions .btn,
    .bm-list-filter-toolbar > .bm-toolbar-actions .btn-outline-secondary,
    .bm-list-filter-toolbar > .bm-toolbar-actions .btn-primary {
        width: 100%;
        min-width: 0;
    }
}


/* =========================================================
   BUSINESS PROFILE RECOMMENDATIONS - DESKTOP SHELL ALIGNMENT
   ========================================================= */
/*
 * Keep this page on the same desktop shell geometry as standard list pages.
 * Do not assign an explicit calc() width to .app-main: its normal block width
 * already accounts for the sidebar margin. The previous page-level width
 * override could make the topbar and document wider than the viewport.
 */
@media (min-width: 992px) {
    body[data-current-controller="BusinessProfileRecommendations"] .app-main {
        min-width: 0;
        width: auto;
        max-width: none;
        overflow-x: clip;
    }

    body[data-current-controller="BusinessProfileRecommendations"] .app-topbar,
    body[data-current-controller="BusinessProfileRecommendations"] .app-page,
    body[data-current-controller="BusinessProfileRecommendations"] .bm-page-container {
        min-width: 0;
        max-width: 100%;
    }

    /* Match the horizontal search position used by short standard page titles
       such as Customers. Long page titles truncate instead of pushing search
       and the user controls to the right. */
    body[data-current-controller="BusinessProfileRecommendations"] .topbar-left {
        flex: 0 1 164px;
        width: 164px;
    }

    body[data-current-controller="BusinessProfileRecommendations"] .topbar-page-context {
        min-width: 0;
        max-width: 108px;
    }

    body[data-current-controller="BusinessProfileRecommendations"] .topbar-page-title,
    body[data-current-controller="BusinessProfileRecommendations"] .topbar-section-label {
        max-width: 100%;
    }

    body[data-current-controller="BusinessProfileRecommendations"] .global-search {
        min-width: 0;
    }
}

/* =========================================================
   SHARED DESKTOP SIDEBAR EDGE TOGGLE
   Business shell follows the Platform Administration collapse affordance:
   inline on the expanded dark sidebar, floating on the compact sidebar.
   Mobile navigation remains owned by #mobileNavigationToggle.
   ========================================================= */
@media (min-width: 992px) {
    #desktopSidebar .sidebar-brand {
        padding-right: 3.6rem;
    }

    .sidebar-edge-toggle {
        position: absolute;
        top: 20px;
        right: 16px;
        z-index: 1045;
        width: 32px;
        height: 32px;
        align-items: center;
        justify-content: center;
        padding: 0;
        color: #aeb9cc;
        border: 0;
        border-radius: 8px;
        background: transparent;
        font-size: 1.15rem;
        line-height: 1;
        transition: left .2s ease, right .2s ease, color .15s ease,
                    background-color .15s ease, border-color .15s ease,
                    box-shadow .15s ease;
    }

    .sidebar-edge-toggle:hover,
    .sidebar-edge-toggle:focus-visible {
        color: #fff;
        background: rgba(255, 255, 255, .08);
        outline: none;
    }

    .sidebar-edge-toggle:focus-visible {
        box-shadow: 0 0 0 .2rem rgba(147, 197, 253, .28);
    }

    #desktopSidebarToggle i {
        transition: transform .2s ease;
    }

    body.sidebar-compact #desktopSidebar .sidebar-brand {
        padding-inline: .75rem;
    }

    body.sidebar-compact #desktopSidebarToggle {
        position: fixed;
        top: 24px;
        right: auto;
        left: calc(var(--bm-sidebar-compact-width) - 14px);
        color: #344054;
        border: 1px solid #e4e7ec;
        background: #fff;
        box-shadow: 0 2px 6px rgba(16, 24, 40, .12);
    }

    body.sidebar-compact #desktopSidebarToggle:hover,
    body.sidebar-compact #desktopSidebarToggle:focus-visible {
        color: #172033;
        border-color: #cfd5df;
        background: #f8fafc;
    }

    body.sidebar-compact #desktopSidebarToggle i {
        transform: rotate(180deg);
    }
}
