/* Shared visual contract. Loaded after module styles; do not recolor status badges.
   !important is limited to rules that must supersede legacy important overrides. */
:root {
    --crm-bg: #e9edf4;
    --crm-surface: #fff;
    --crm-surface-soft: #f3f5f9;
    --crm-border: #ced7e5;
    --crm-border-strong: var(--crm-border);
    --crm-text: #172033;
    --crm-muted: #526176;
    --crm-muted-2: var(--crm-muted);
    --crm-sidebar-bg: #17243e;
    --crm-sidebar-active: #253659;
    --crm-section-gap: 24px;
    --crm-component-gap: 16px;
    --crm-control-gap: 10px;
    --crm-shadow-soft: 0 6px 20px rgb(22 32 48 / 5%);
    --market-bg: var(--crm-bg);
    --market-surface: var(--crm-surface);
    --market-border: var(--crm-border);
    --market-text: var(--crm-text);
    --market-muted: var(--crm-muted);
    --bs-body-color: var(--crm-text);
    --bs-secondary-color: var(--crm-muted);
    --bs-border-color: var(--crm-border);
    --bs-link-color: var(--crm-primary-dark);
    --dental-lab-primary: var(--crm-primary);
    --dental-lab-primary-deep: var(--crm-primary-dark);
    --dental-lab-primary-rgb: var(--crm-primary-rgb);
    --dental-lab-primary-soft: var(--crm-primary-soft);
    --dental-lab-bg: var(--crm-bg);
    --dental-lab-surface: var(--crm-surface);
    --dental-lab-surface-soft: var(--crm-surface-soft);
    --dental-lab-text: var(--crm-text);
    --dental-lab-muted: var(--crm-muted);
    --dental-lab-border: var(--crm-border);
}
html { font-family: var(--crm-font-family); background: var(--crm-bg); }
body.crm-market-ui {
    color: var(--crm-text);
    background: var(--crm-bg);
    line-height: 1.8;
}
.crm-market-ui :is(input, select, textarea, button) { font-family: inherit; }
.crm-skip-link { position: fixed; top: 8px; inset-inline-start: 16px; z-index: 2000; transform: translateY(-160%); padding: 12px 20px; background: var(--crm-surface); color: var(--crm-primary-dark); border: 2px solid var(--crm-primary-dark); border-radius: 10px; }
.crm-skip-link:focus { transform: translateY(0); }
.crm-market-ui .crm-main { background: var(--crm-bg); }
.crm-market-ui .crm-topbar {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap;
    align-items: center;
    background: var(--crm-surface-soft) !important;
    border-bottom: 1px solid var(--crm-border);
    box-shadow: 0 2px 10px rgb(22 32 48 / 4%);
}
.crm-market-ui .crm-topbar .crm-topbar-title { flex: 0 0 auto; }
.crm-market-ui .crm-topbar .crm-topbar-tools { flex-wrap: nowrap; margin-top: 0 !important; margin-inline-start: 0; }
.crm-market-ui .crm-topbar .crm-account-cluster .crm-user-meta { align-items: flex-start !important; }
.crm-market-ui .crm-topbar .crm-user-meta small { color: var(--crm-muted); font-size: 12px; }
.crm-market-ui .crm-search-mobile-trigger, .crm-market-ui .crm-search-mobile-close { display: none !important; }
/* Mobile-only controls must not become extra grid items on desktop, even when
   older module styles assign display to buttons inside the shared topbar. */
@media (min-width: 992px) {
    .crm-market-ui .crm-topbar .crm-search-control .crm-global-search > :is(.crm-search-mobile-trigger, .crm-search-mobile-close) { display: none !important; }
    .crm-market-ui .crm-topbar .crm-search-control .crm-global-search { grid-template-columns: 22px minmax(0, 1fr) auto 44px; }
}
.crm-market-ui .crm-sidebar {
    color: #e5ecf6;
    background: var(--crm-sidebar-bg) !important;
    border-color: rgb(255 255 255 / 12%);
    scrollbar-color: #7b8ba5 var(--crm-sidebar-bg);
}
.crm-market-ui .crm-sidebar-brand { background: var(--crm-sidebar-bg); border-color: rgb(255 255 255 / 18%); }
.crm-market-ui .crm-sidebar-footer { background: var(--crm-sidebar-bg); border-color: rgb(255 255 255 / 18%); }
.crm-market-ui .crm-sidebar-brand strong { color: #fff; }
.crm-market-ui .crm-sidebar small { color: #c7d2e3 !important; font-size: 12px; }
.crm-market-ui .crm-sidebar .crm-nav-group summary {
    color: #d6e0ed;
    background: transparent;
    min-height: 44px;
    padding-block: 10px;
    font-size: 12px;
}
.crm-market-ui .crm-sidebar .crm-nav-group summary::after { color: #e5ecf6; background: rgb(255 255 255 / 9%); border-color: rgb(255 255 255 / 15%); font-size: 16px; }
.crm-market-ui .crm-sidebar .crm-nav-group summary:hover { background: rgb(255 255 255 / 7%); }
.crm-market-ui .crm-sidebar a.crm-nav-link {
    color: #e5ecf6;
    min-height: 44px;
    font-size: 13px;
}
.crm-market-ui .crm-sidebar a.crm-nav-link:hover,
.crm-market-ui .crm-sidebar a.crm-nav-link.active {
    color: #fff !important;
    background: var(--crm-sidebar-active) !important;
    border-color: rgb(255 255 255 / 16%) !important;
    box-shadow: inset -3px 0 0 var(--crm-primary-soft-strong) !important;
}
.crm-market-ui .crm-sidebar .crm-menu-icon,
.crm-market-ui .crm-sidebar .crm-nav-link.active .crm-menu-icon {
    color: #f5f8ff !important;
    background: rgb(255 255 255 / 9%) !important;
}
.crm-market-ui .crm-sidebar .crm-menu-icon img { filter: brightness(0) invert(1); }
.crm-market-ui .crm-sidebar .crm-logo--image { background: var(--crm-surface) !important; box-shadow: none; }
.crm-market-ui .crm-sidebar .crm-logout-link {
    color: #ffcad4 !important;
    background: rgb(255 255 255 / 6%) !important;
    border-color: rgb(255 202 212 / 22%) !important;
    min-height: 44px;
}
.crm-market-ui :is(.crm-panel, .crm-card, .card, .market-card, .market-panel-pro, .market-kpi-pro, .crm-stat-card, .stat-card, .crm-finance-kpi, .crm-activity-kpi) {
    background: var(--crm-surface) !important;
    border-color: var(--crm-border) !important;
    box-shadow: var(--crm-shadow-soft) !important;
}
.crm-market-ui :is(.crm-sales-hero, .crm-activity-hero) {
    background: linear-gradient(120deg, var(--crm-surface), var(--crm-surface-soft)) !important;
}
.crm-market-ui :is(.market-welcome, .market-hero-pro) {
    background: linear-gradient(118deg, var(--crm-primary-darker), var(--crm-primary-dark)) !important;
    color: #fff;
}
.crm-market-ui .market-hero-copy-pro h1 {
    margin: 12px 0;
    color: #fff;
    font-size: clamp(24px, 3vw, 36px);
    font-weight: 800;
    line-height: 1.6;
}
.crm-market-ui .market-hero-pro .market-hero-copy-pro p { color: #fff !important; opacity: .92; font-size: 14px; }
.crm-market-ui :is(.crm-page-head, .crm-page-header, .page-header) h1 {
    font-size: 22px !important;
    line-height: 1.6;
}
.crm-market-ui :is(.crm-sales-head-copy, .crm-activity-head-copy) h1 { font-weight: 800; }
.crm-market-ui :is(.text-muted, .crm-sales-muted, .crm-sales-cell-subtitle, .crm-activity-cell-subtitle,
    .crm-page-head p, .crm-page-header p, .page-header p, .crm-section-head p,
    .crm-sales-head-copy p, .crm-activity-head-copy p, .market-kpi-pro-body > span,
    .market-kpi-pro-body small, .market-panel-head-pro > div > span,
    .crm-user-meta small, .market-trend-summary span) {
    color: var(--crm-muted) !important;
    font-size: 12px;
    line-height: 1.8;
}
.crm-market-ui :is(.crm-finance-kpi small, .crm-finance-kpi-meta, .crm-activity-kpi small, .market-trend-legend b) { color: var(--crm-muted) !important; font-size: 12px; }
.crm-market-ui :is(.crm-sales-eyebrow, .crm-activity-eyebrow, .crm-section-kicker,
    .text-primary, .link-primary, .market-panel-head-pro > a) { color: var(--crm-primary-dark) !important; }
.crm-market-ui :is(.crm-form-label, label.form-label) {
    display: block;
    margin-bottom: 6px;
    color: var(--crm-muted);
    font-size: 13px;
    font-weight: 700;
}
.crm-market-ui :is(.crm-input, .form-control, .form-select) {
    min-height: 44px;
    background-color: var(--crm-surface);
    border-color: var(--crm-border);
    color: var(--crm-text);
}
.crm-market-ui :is(.crm-input, .form-control, input[type="search"])::placeholder { color: var(--crm-muted); opacity: 1; }
.crm-market-ui :is(.crm-btn, .btn, .crm-shell-button, .crm-icon-button, .crm-search-scope-toggle, .crm-page-link) {
    min-height: 44px !important;
    min-width: 44px !important;
    font-size: 13px;
}
.crm-market-ui .crm-btn:not(.crm-btn-light):not(.crm-btn-danger):not(.crm-btn-secondary),
.crm-market-ui .btn-primary,
.crm-market-ui input[type="submit"] {
    color: #fff !important;
    background: var(--crm-primary-dark) !important;
    border-color: var(--crm-primary-dark) !important;
    box-shadow: 0 3px 8px rgb(22 32 48 / 10%) !important;
}
.crm-market-ui .crm-btn:not(.crm-btn-light):not(.crm-btn-danger):not(.crm-btn-secondary):hover,
.crm-market-ui .btn-primary:hover { background: var(--crm-primary-darker) !important; }
.crm-market-ui :is(.crm-btn-light, .crm-btn-secondary, .btn-outline-primary) {
    color: var(--crm-primary-dark) !important;
    background: var(--crm-surface) !important;
    border: 1px solid var(--crm-border) !important;
    box-shadow: none !important;
}
.crm-market-ui :is(.crm-btn-light, .crm-btn-secondary, .btn-outline-primary):hover {
    background: var(--crm-surface-soft) !important;
    border-color: var(--crm-primary-dark) !important;
}
.crm-market-ui .crm-btn-danger { color: #a01835 !important; background: #fff0f3 !important; border-color: #edbac5 !important; }
.crm-market-ui :is(button, input, select, textarea):disabled,
.crm-market-ui [aria-disabled="true"] { cursor: not-allowed; opacity: .65; }
.crm-market-ui :focus-visible { outline: 3px solid var(--crm-primary-dark); outline-offset: 3px; }
.crm-market-ui .crm-sidebar :focus-visible { outline-color: #fff; }
.crm-market-ui .market-hero-pro :focus-visible { outline-color: #fff; }
.crm-market-ui :is(.table-responsive, .table-wrap) { background: var(--crm-surface); border-color: var(--crm-border); }
.crm-market-ui table { --bs-table-color: var(--crm-text); --bs-table-border-color: var(--crm-border); }
.crm-market-ui table thead th { color: var(--crm-muted); background: var(--crm-surface-soft) !important; font-size: 12px; }
.crm-market-ui table tbody td { font-size: 13px; line-height: 1.8; }
.crm-market-ui table thead th, .crm-market-ui table tbody td { text-align: start; }
.crm-market-ui table :is(th, td)[dir="ltr"] { text-align: left; }
.crm-market-ui table .crm-money-cell { font-variant-numeric: tabular-nums; }
/* Never turn a table cell into flex: its content must stay under its header. */
.crm-market-ui table td.crm-actions { display: table-cell !important; }
.crm-market-ui table td.crm-actions > * { margin: 4px; }
.crm-market-ui .table-responsive table thead th.crm-actions-heading { position: sticky; left: 0; z-index: 4; min-width: 132px; text-align: center; background: var(--crm-surface-soft) !important; }
.crm-market-ui table tbody td.crm-actions { text-align: center; }
.crm-market-ui table tbody tr:hover td { background-color: var(--crm-surface-soft) !important; }
.crm-market-ui .crm-page-shell { gap: var(--crm-section-gap); }
.crm-market-ui :is(.crm-sales-page, .crm-activity-page, .market-dashboard-pro) { gap: var(--crm-section-gap); }
.crm-market-ui .crm-page-head { flex-wrap: wrap; }
.crm-market-ui :is(.crm-card-head, .crm-section-head) h3 { font-size: 18px; font-weight: 800; line-height: 1.6; margin: 0; }
.crm-market-ui .crm-card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.crm-market-ui .crm-card-head > a { flex: 0 0 auto; white-space: nowrap; min-height: 44px; display: inline-flex; align-items: center; color: var(--crm-primary-dark); font-size: 12px; }
.crm-market-ui :is(.lab-accounting-stats, .lab-inventory-stats) .crm-metric-card { display: grid !important; grid-template-columns: minmax(0, 1fr) 44px; align-items: center; justify-content: stretch; gap: 12px; min-height: 100px; padding: 18px !important; }
.crm-market-ui .crm-metric-card::before, .crm-market-ui .crm-metric-card::after { display: none; }
.crm-market-ui .crm-metric-copy { display: grid; gap: 4px; min-width: 0; text-align: start; }
.crm-market-ui .crm-metric-copy > span { color: var(--crm-muted); font-size: 13px; line-height: 1.7; }
.crm-market-ui .crm-metric-copy > strong { margin: 0 !important; font-size: 24px !important; overflow-wrap: anywhere; }
.crm-market-ui :is(.lab-accounting-stats, .lab-inventory-stats) .crm-metric-card .crm-metric-icon { display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; background: var(--crm-primary-soft); color: var(--crm-primary-dark); }
.crm-market-ui .crm-metric-icon .crm-icon { width: 24px; height: 24px; }
.crm-market-ui .crm-actions-inline { display: flex; flex-wrap: wrap; gap: var(--crm-control-gap); }
.crm-market-ui :is(.crm-actions, .crm-form-action, .crm-search-actions) { flex-wrap: wrap; gap: var(--crm-control-gap); }
.crm-market-ui .crm-search-scope-panel { background: var(--crm-surface); border-color: var(--crm-border); }
.crm-market-ui .crm-main .crm-page-shell .text-muted { color: var(--crm-muted) !important; font-size: 12px; }
.crm-market-ui .crm-search-scope-option:has(input:checked) { color: var(--crm-primary-dark); background: var(--crm-primary-soft); border-color: var(--crm-primary-dark); }
.crm-market-ui .market-panel-head-pro > a { min-height: 44px; display: inline-flex; align-items: center; font-size: 12px; }
@media (max-width: 767.98px) {
    :root { --crm-section-gap: 18px; --crm-component-gap: 14px; }
    .crm-market-ui :is(.crm-btn, .btn, .crm-btn-sm) { min-height: 44px; white-space: normal; }
    .crm-market-ui :is(.crm-input, .form-control, .form-select) { font-size: 16px; }
    .crm-market-ui .crm-page-head { align-items: flex-start; }
    .crm-market-ui .crm-page-head > .crm-actions { margin-inline-start: 0; width: 100%; }
    .crm-market-ui :is(.crm-panel, .crm-card) { padding: 16px !important; }
    .crm-market-ui :is(.crm-sales-stage-form, .crm-activity-status-form) { min-width: 180px; }
    .crm-market-ui table[data-crm-mobile-cards="1"] td::before { color: var(--crm-muted); font-size: 12px; }
    .crm-market-ui table[data-crm-mobile-cards="1"] td.crm-actions { position: static; box-shadow: none; text-align: start; }
}
@media (max-width: 991.98px) {
    .crm-market-ui .lab-inventory-page .crm-grid-2 { grid-template-columns: minmax(0, 1fr) !important; }
    .crm-market-ui :is(.lab-accounting-stats, .lab-inventory-stats) .crm-metric-card { min-height: 88px; padding: 14px 16px !important; }
    .crm-market-ui .crm-topbar { min-height: 72px !important; gap: 8px; }
    .crm-market-ui .crm-topbar .crm-topbar-tools { gap: 8px; }
    .crm-market-ui .crm-topbar .crm-account-cluster { min-width: 0; gap: 8px; }
    .crm-market-ui .crm-topbar .crm-account-cluster .crm-user-card { max-width: none; flex-shrink: 1; }
    .crm-market-ui .crm-topbar .crm-account-cluster .crm-user-meta { display: flex !important; max-width: clamp(72px, calc(100vw - 280px), 150px); }
    .crm-market-ui .crm-topbar .crm-account-cluster .crm-user-meta small { display: block !important; }
    .crm-market-ui .crm-topbar .crm-topbar-tools > .crm-search-control { flex: 0 0 44px; min-width: 44px; width: 44px; }
    .crm-market-ui .crm-topbar .crm-search-control:not(.is-mobile-expanded) .crm-global-search { display: grid; grid-template-columns: 44px; place-items: center; padding: 0; width: 44px; height: 44px; min-height: 44px; }
    .crm-market-ui .crm-topbar .crm-search-control:not(.is-mobile-expanded) :is(input[type="search"], kbd, .crm-search-scope-toggle, .crm-search-main-icon, .crm-search-mobile-close) { display: none !important; }
    .crm-market-ui .crm-topbar .crm-search-mobile-trigger { display: inline-grid !important; place-items: center; width: 44px; height: 44px; padding: 0; border: 0; border-radius: 11px; background: var(--crm-surface); color: var(--crm-muted); }
    .crm-market-ui .crm-topbar .crm-search-control.is-mobile-expanded .crm-global-search { position: fixed; top: 80px; inset-inline: 12px; width: calc(100% - 24px); min-height: 56px; height: auto; grid-template-columns: 20px minmax(0, 1fr) 44px 44px; padding: 5px 8px; gap: 6px; z-index: 1100; background: var(--crm-surface); box-shadow: var(--crm-shadow-soft); }
    .crm-market-ui .crm-topbar .crm-search-control.is-mobile-expanded :is(.crm-search-mobile-trigger, kbd) { display: none !important; }
    .crm-market-ui .crm-topbar .crm-search-control.is-mobile-expanded input[type="search"] { display: block !important; font-size: 16px; }
    .crm-market-ui .crm-topbar .crm-search-control.is-mobile-expanded :is(.crm-search-scope-toggle, .crm-search-mobile-close) { display: inline-grid !important; place-items: center; width: 44px; height: 44px; border: 0; background: var(--crm-surface-soft); color: var(--crm-muted); border-radius: 10px; }
    .crm-market-ui .crm-topbar .crm-search-control.is-mobile-expanded .crm-search-main-icon { display: block !important; }
    .crm-market-ui .crm-topbar .crm-search-scope-panel { position: fixed; top: 144px; inset-inline: 12px; width: calc(100% - 24px); max-height: calc(100dvh - 160px); overflow-y: auto; }
}
@media (prefers-reduced-motion: reduce) {
    .crm-market-ui *, .crm-market-ui *::before, .crm-market-ui *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
        scroll-behavior: auto !important;
    }
}
