/* =====================================================================================
   CRM V2 design system
   Built on Bootstrap 5.3. Tokens are CSS custom properties with light and dark themes.
   ===================================================================================== */

@font-face {
    font-family: "Inter";
    font-style: normal;
    font-display: swap;
    font-weight: 100 900;
    src: url("../lib/inter/inter-latin-wght-normal.woff2") format("woff2-variations");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+20B9, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
    font-family: "Inter";
    font-style: normal;
    font-display: swap;
    font-weight: 100 900;
    src: url("../lib/inter/inter-latin-ext-wght-normal.woff2") format("woff2-variations");
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
    --crm-font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

    --crm-primary: #4f46e5;
    --crm-primary-hover: #4338ca;
    --crm-primary-rgb: 79, 70, 229;
    --crm-primary-soft: #eef2ff;
    --crm-primary-text: #3730a3;

    --crm-success: #16a34a;
    --crm-success-soft: #dcfce7;
    --crm-success-text: #166534;
    --crm-warning: #d97706;
    --crm-warning-soft: #fef3c7;
    --crm-warning-text: #92400e;
    --crm-danger: #dc2626;
    --crm-danger-soft: #fee2e2;
    --crm-danger-text: #991b1b;
    --crm-info: #0284c7;
    --crm-info-soft: #e0f2fe;
    --crm-info-text: #075985;
    --crm-neutral-soft: #f1f5f9;
    --crm-neutral-text: #475569;

    --crm-bg: #f5f6fa;
    --crm-surface: #ffffff;
    --crm-surface-2: #f8fafc;
    --crm-surface-hover: #f8f9fe;
    --crm-border: #e6e8ef;
    --crm-border-strong: #d4d8e3;
    --crm-text: #111827;
    --crm-text-2: #374151;
    --crm-muted: #6b7280;
    --crm-subtle: #9ca3af;

    --crm-sidebar-bg: #0f1629;
    --crm-sidebar-bg-2: #151d35;
    --crm-sidebar-text: #aeb6cc;
    --crm-sidebar-text-strong: #ffffff;
    --crm-sidebar-muted: #6b7591;
    --crm-sidebar-active: rgba(99, 102, 241, .16);
    --crm-sidebar-width: 256px;
    --crm-sidebar-collapsed: 72px;
    --crm-topbar-h: 60px;

    --crm-radius-sm: 6px;
    --crm-radius: 10px;
    --crm-radius-lg: 14px;
    --crm-shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
    --crm-shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
    --crm-shadow-lg: 0 12px 32px -8px rgba(16, 24, 40, .18), 0 4px 8px -4px rgba(16, 24, 40, .06);
    --crm-focus: 0 0 0 3px rgba(var(--crm-primary-rgb), .22);

    /* Bootstrap bridge */
    --bs-body-font-family: var(--crm-font);
    --bs-body-font-size: .875rem;
    --bs-body-color: var(--crm-text);
    --bs-body-bg: var(--crm-bg);
    --bs-border-color: var(--crm-border);
    --bs-primary: var(--crm-primary);
    --bs-primary-rgb: var(--crm-primary-rgb);
    --bs-link-color: var(--crm-primary);
    --bs-link-color-rgb: var(--crm-primary-rgb);
    --bs-link-hover-color: var(--crm-primary-hover);
    --bs-border-radius: var(--crm-radius-sm);
    --bs-border-radius-lg: var(--crm-radius);
    --bs-secondary-color: var(--crm-muted);
    --bs-tertiary-bg: var(--crm-surface-2);
    --bs-emphasis-color: var(--crm-text);
    color-scheme: light;
}

[data-theme="dark"] {
    --crm-primary: #818cf8;
    --crm-primary-hover: #a5b4fc;
    --crm-primary-rgb: 129, 140, 248;
    --crm-primary-soft: rgba(129, 140, 248, .14);
    --crm-primary-text: #c7d2fe;
    --crm-success-soft: rgba(34, 197, 94, .14);
    --crm-success-text: #86efac;
    --crm-warning-soft: rgba(245, 158, 11, .14);
    --crm-warning-text: #fcd34d;
    --crm-danger-soft: rgba(239, 68, 68, .15);
    --crm-danger-text: #fca5a5;
    --crm-info-soft: rgba(14, 165, 233, .14);
    --crm-info-text: #7dd3fc;
    --crm-neutral-soft: rgba(148, 163, 184, .12);
    --crm-neutral-text: #cbd5e1;
    --crm-bg: #0b1020;
    --crm-surface: #121a2e;
    --crm-surface-2: #0f1628;
    --crm-surface-hover: #172039;
    --crm-border: #232d47;
    --crm-border-strong: #2e3a5a;
    --crm-text: #e5e9f5;
    --crm-text-2: #c4cbe0;
    --crm-muted: #8b95b2;
    --crm-subtle: #64708f;
    --crm-sidebar-bg: #0a0f1d;
    --crm-sidebar-bg-2: #0f1628;
    --crm-shadow: 0 1px 3px rgba(0, 0, 0, .4);
    --crm-shadow-lg: 0 16px 40px -8px rgba(0, 0, 0, .6);
    --bs-body-color: var(--crm-text);
    --bs-body-bg: var(--crm-bg);
    --bs-border-color: var(--crm-border);
    --bs-emphasis-color: var(--crm-text);
    --bs-secondary-bg: var(--crm-surface-2);
    --bs-tertiary-bg: var(--crm-surface-2);
    color-scheme: dark;
}

/* ---------------------------------------------------------------- Base */

html { font-size: 16px; }

body {
    font-family: var(--crm-font);
    font-size: .875rem;
    line-height: 1.5;
    color: var(--crm-text);
    background: var(--crm-bg);
    -webkit-font-smoothing: antialiased;
    font-feature-settings: "cv11", "ss01";
}

h1, h2, h3, h4, h5, h6 { color: var(--crm-text); font-weight: 650; letter-spacing: -.01em; }
a { color: var(--crm-primary); text-decoration: none; }
a:hover { color: var(--crm-primary-hover); }
hr { border-color: var(--crm-border); opacity: 1; }
::selection { background: rgba(var(--crm-primary-rgb), .18); }
.text-muted, .text-secondary { color: var(--crm-muted) !important; }
.text-subtle { color: var(--crm-subtle) !important; }
.fw-semibold { font-weight: 600 !important; }
.small, small { font-size: .8125rem; }
.xsmall { font-size: .75rem; }
.tabular { font-variant-numeric: tabular-nums; }
.min-w-0 { min-width: 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
:focus-visible { outline: none; box-shadow: var(--crm-focus); border-radius: 4px; }

/* ---------------------------------------------------------------- Shell */

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

.sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 1040;
    width: var(--crm-sidebar-width);
    background: linear-gradient(180deg, var(--crm-sidebar-bg) 0%, var(--crm-sidebar-bg-2) 100%);
    color: var(--crm-sidebar-text);
    display: flex; flex-direction: column;
    transition: width .2s ease, transform .25s ease;
    border-right: 1px solid rgba(255, 255, 255, .04);
}

.sidebar-brand {
    height: var(--crm-topbar-h);
    display: flex; align-items: center; gap: .7rem;
    padding: 0 1.1rem;
    color: var(--crm-sidebar-text-strong);
    border-bottom: 1px solid rgba(255, 255, 255, .06);
    flex-shrink: 0;
}
.sidebar-brand:hover { color: #fff; }
.brand-mark {
    width: 34px; height: 34px; border-radius: 10px; flex-shrink: 0;
    display: grid; place-items: center;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 55%, #ec4899 120%);
    color: #fff; font-weight: 800; font-size: 1rem; letter-spacing: -.03em;
    box-shadow: 0 6px 16px -6px rgba(99, 102, 241, .8);
}
.brand-mark img { width: 100%; height: 100%; object-fit: cover; border-radius: 10px; }
.brand-text { line-height: 1.15; min-width: 0; }
.brand-name { font-weight: 700; font-size: 1rem; display: block; }
.brand-org { font-size: .72rem; color: var(--crm-sidebar-muted); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 170px; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: .75rem .65rem 1rem; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.12) transparent; }
.nav-group-label {
    font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; font-weight: 600;
    color: var(--crm-sidebar-muted); padding: .9rem .75rem .35rem;
}
.nav-link-crm {
    display: flex; align-items: center; gap: .75rem;
    padding: .55rem .75rem; margin: 1px 0;
    border-radius: 8px; color: var(--crm-sidebar-text);
    font-weight: 500; font-size: .86rem; position: relative;
    transition: background .15s, color .15s;
}
.nav-link-crm i { font-size: 1.05rem; width: 20px; text-align: center; opacity: .9; flex-shrink: 0; }
.nav-link-crm:hover { background: rgba(255, 255, 255, .05); color: #fff; }
.nav-link-crm.active { background: var(--crm-sidebar-active); color: #fff; }
.nav-link-crm.active::before {
    content: ""; position: absolute; left: -.65rem; top: 8px; bottom: 8px; width: 3px;
    border-radius: 0 3px 3px 0; background: #818cf8;
}
.nav-link-crm .nav-badge {
    margin-left: auto; font-size: .68rem; font-weight: 700; padding: .1rem .45rem; border-radius: 999px;
    background: rgba(239, 68, 68, .9); color: #fff;
}
.nav-label { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

.sidebar-footer {
    padding: .75rem; border-top: 1px solid rgba(255, 255, 255, .06);
    font-size: .72rem; color: var(--crm-sidebar-muted);
    display: flex; align-items: center; justify-content: space-between;
}
.sidebar-collapse-btn {
    border: 0; background: rgba(255,255,255,.05); color: var(--crm-sidebar-text);
    width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
}
.sidebar-collapse-btn:hover { background: rgba(255,255,255,.1); color: #fff; }

.main { margin-left: var(--crm-sidebar-width); min-height: 100vh; display: flex; flex-direction: column; transition: margin-left .2s ease; }

@media (min-width: 992px) {
    body.sidebar-collapsed .sidebar { width: var(--crm-sidebar-collapsed); }
    body.sidebar-collapsed .main { margin-left: var(--crm-sidebar-collapsed); }
    body.sidebar-collapsed .brand-text,
    body.sidebar-collapsed .nav-label,
    body.sidebar-collapsed .nav-group-label,
    body.sidebar-collapsed .nav-badge,
    body.sidebar-collapsed .sidebar-footer .sidebar-version { display: none; }
    body.sidebar-collapsed .nav-link-crm { justify-content: center; padding: .6rem; }
    body.sidebar-collapsed .sidebar-brand { justify-content: center; padding: 0; }
    body.sidebar-collapsed .sidebar-footer { justify-content: center; }
    body.sidebar-collapsed .sidebar-collapse-btn i { transform: rotate(180deg); }
}

@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); box-shadow: var(--crm-shadow-lg); }
    body.sidebar-open .sidebar { transform: translateX(0); }
    .main { margin-left: 0; }
    .sidebar-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 1035; display: none; }
    body.sidebar-open .sidebar-backdrop { display: block; }
    .sidebar-collapse-btn { display: none; }
}

/* ---------------------------------------------------------------- Topbar */

.topbar {
    position: sticky; top: 0; z-index: 1030;
    height: var(--crm-topbar-h);
    background: color-mix(in srgb, var(--crm-surface) 88%, transparent);
    backdrop-filter: saturate(160%) blur(10px);
    border-bottom: 1px solid var(--crm-border);
    display: flex; align-items: center; gap: .75rem;
    padding: 0 1.25rem;
}
.topbar-btn {
    width: 38px; height: 38px; border-radius: 10px; border: 1px solid transparent;
    background: transparent; color: var(--crm-text-2);
    display: inline-grid; place-items: center; position: relative; flex-shrink: 0;
}
.topbar-btn:hover { background: var(--crm-neutral-soft); color: var(--crm-text); }
.topbar-btn .dot:empty { display: none; }
.topbar-btn .dot {
    position: absolute; top: 6px; right: 6px; min-width: 17px; height: 17px; padding: 0 4px;
    border-radius: 999px; background: var(--crm-danger); color: #fff; font-size: .62rem; font-weight: 700;
    display: grid; place-items: center; border: 2px solid var(--crm-surface);
}

.global-search { position: relative; flex: 1; max-width: 520px; }
.global-search .form-control {
    padding-left: 2.3rem; padding-right: 3.5rem; height: 38px;
    background: var(--crm-surface-2); border-color: var(--crm-border);
    border-radius: 10px;
}
.global-search .form-control:focus { background: var(--crm-surface); }
.global-search .search-icon { position: absolute; left: .8rem; top: 50%; transform: translateY(-50%); color: var(--crm-subtle); pointer-events: none; }
.global-search kbd {
    position: absolute; right: .6rem; top: 50%; transform: translateY(-50%);
    font-size: .68rem; background: var(--crm-surface); color: var(--crm-muted);
    border: 1px solid var(--crm-border); box-shadow: none; padding: .1rem .35rem; border-radius: 5px; font-family: var(--crm-font);
}
.search-results {
    position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 1050;
    background: var(--crm-surface); border: 1px solid var(--crm-border); border-radius: var(--crm-radius);
    box-shadow: var(--crm-shadow-lg); max-height: 70vh; overflow-y: auto; padding: .35rem;
}
.search-group-label { font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; color: var(--crm-muted); padding: .5rem .6rem .25rem; font-weight: 600; }
.search-item { display: flex; gap: .7rem; align-items: center; padding: .5rem .6rem; border-radius: 8px; color: var(--crm-text); }
.search-item:hover, .search-item.active { background: var(--crm-primary-soft); color: var(--crm-text); }
.search-item i { color: var(--crm-muted); width: 18px; text-align: center; }
.search-item .title { font-weight: 550; line-height: 1.25; }
.search-item .sub { font-size: .75rem; color: var(--crm-muted); }

.user-chip { display: flex; align-items: center; gap: .55rem; padding: .25rem .5rem .25rem .25rem; border-radius: 999px; border: 1px solid var(--crm-border); background: var(--crm-surface); color: var(--crm-text); }
.user-chip:hover { border-color: var(--crm-border-strong); }
.user-chip .name { font-weight: 600; font-size: .8rem; max-width: 140px; line-height: 1.1; }
.user-chip .role { font-size: .68rem; color: var(--crm-muted); }

.org-switch { font-size: .78rem; border: 1px dashed var(--crm-warning); color: var(--crm-warning-text); background: var(--crm-warning-soft); border-radius: 999px; padding: .25rem .7rem; white-space: nowrap; }

/* ---------------------------------------------------------------- Page */

.content { padding: 1.5rem 1.5rem 3rem; flex: 1; width: 100%; max-width: 1680px; margin: 0 auto; }
@media (max-width: 575.98px) { .content { padding: 1rem 1rem 2.5rem; } .topbar { padding: 0 .75rem; gap: .4rem; } }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-head .titles { min-width: 0; }
.page-title { font-size: 1.45rem; font-weight: 700; margin: 0; letter-spacing: -.02em; }
.page-subtitle { color: var(--crm-muted); margin: .2rem 0 0; font-size: .875rem; }
.page-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.crumbs { font-size: .78rem; color: var(--crm-muted); margin-bottom: .3rem; display: flex; gap: .35rem; align-items: center; flex-wrap: wrap; }
.crumbs a { color: var(--crm-muted); }
.crumbs a:hover { color: var(--crm-primary); }
.crumbs .sep { color: var(--crm-subtle); }

/* ---------------------------------------------------------------- Cards */

.card-crm { background: var(--crm-surface); border: 1px solid var(--crm-border); border-radius: var(--crm-radius-lg); box-shadow: var(--crm-shadow-sm); }
.card-crm + .card-crm { margin-top: 1rem; }
.card-crm .card-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .95rem 1.15rem; border-bottom: 1px solid var(--crm-border); flex-wrap: wrap; }
.card-crm .card-head h2, .card-crm .card-head h3, .card-crm .card-head .card-title { font-size: .95rem; font-weight: 650; margin: 0; display: flex; align-items: center; gap: .5rem; }
.card-crm .card-head .card-title i { color: var(--crm-muted); }
.card-crm .card-body { padding: 1.15rem; }
.card-crm .card-body.p-0 { padding: 0; }
.card-crm .card-foot { padding: .75rem 1.15rem; border-top: 1px solid var(--crm-border); background: var(--crm-surface-2); border-radius: 0 0 var(--crm-radius-lg) var(--crm-radius-lg); }
.card-section-title { font-size: .72rem; text-transform: uppercase; letter-spacing: .07em; color: var(--crm-muted); font-weight: 650; margin: 0 0 .75rem; }

/* KPI tiles */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 1rem; }
.kpi {
    background: var(--crm-surface); border: 1px solid var(--crm-border); border-radius: var(--crm-radius-lg);
    padding: 1rem 1.1rem; display: flex; gap: .9rem; align-items: flex-start; box-shadow: var(--crm-shadow-sm);
    color: inherit; transition: border-color .15s, transform .15s;
}
a.kpi:hover { border-color: var(--crm-border-strong); color: inherit; transform: translateY(-1px); }
.kpi-icon { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; font-size: 1.15rem; flex-shrink: 0; }
.kpi-label { font-size: .78rem; color: var(--crm-muted); font-weight: 550; }
.kpi-value { font-size: 1.45rem; font-weight: 750; letter-spacing: -.02em; line-height: 1.2; font-variant-numeric: tabular-nums; }
.kpi-meta { font-size: .74rem; color: var(--crm-muted); margin-top: .1rem; }
.kpi-meta .up { color: var(--crm-success); font-weight: 600; }
.kpi-meta .down { color: var(--crm-danger); font-weight: 600; }

.tone-primary { background: var(--crm-primary-soft); color: var(--crm-primary-text); }
.tone-success { background: var(--crm-success-soft); color: var(--crm-success-text); }
.tone-warning { background: var(--crm-warning-soft); color: var(--crm-warning-text); }
.tone-danger { background: var(--crm-danger-soft); color: var(--crm-danger-text); }
.tone-info { background: var(--crm-info-soft); color: var(--crm-info-text); }
.tone-neutral { background: var(--crm-neutral-soft); color: var(--crm-neutral-text); }

/* ---------------------------------------------------------------- Badges / pills */

.badge-soft {
    display: inline-flex; align-items: center; gap: .35rem; font-size: .72rem; font-weight: 600;
    padding: .22rem .55rem; border-radius: 999px; line-height: 1.2; white-space: nowrap; border: 1px solid transparent;
}
.badge-soft.primary { background: var(--crm-primary-soft); color: var(--crm-primary-text); }
.badge-soft.success { background: var(--crm-success-soft); color: var(--crm-success-text); }
.badge-soft.warning { background: var(--crm-warning-soft); color: var(--crm-warning-text); }
.badge-soft.danger { background: var(--crm-danger-soft); color: var(--crm-danger-text); }
.badge-soft.info { background: var(--crm-info-soft); color: var(--crm-info-text); }
.badge-soft.neutral { background: var(--crm-neutral-soft); color: var(--crm-neutral-text); }
.badge-soft.outline { background: transparent; border-color: var(--crm-border-strong); color: var(--crm-text-2); }

.dot-pill { display: inline-flex; align-items: center; gap: .4rem; font-size: .78rem; font-weight: 550; color: var(--crm-text-2); white-space: nowrap; }
.dot-pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--pill, var(--crm-subtle)); flex-shrink: 0; }

.count-chip { font-size: .7rem; font-weight: 700; padding: .05rem .45rem; border-radius: 999px; background: var(--crm-neutral-soft); color: var(--crm-neutral-text); }

/* ---------------------------------------------------------------- Avatars */

.avatar {
    width: 32px; height: 32px; border-radius: 50%; display: inline-grid; place-items: center; flex-shrink: 0;
    font-size: .72rem; font-weight: 700; color: #fff; background: var(--av, #6366f1); letter-spacing: .02em; text-transform: uppercase;
}
.avatar.sm { width: 26px; height: 26px; font-size: .64rem; }
.avatar.lg { width: 48px; height: 48px; font-size: 1rem; }
.avatar.xl { width: 64px; height: 64px; font-size: 1.35rem; border-radius: 18px; }
.avatar.square { border-radius: 10px; }

/* ---------------------------------------------------------------- Buttons */

.btn { font-weight: 550; font-size: .85rem; border-radius: 8px; padding: .45rem .9rem; display: inline-flex; align-items: center; gap: .4rem; justify-content: center; }
.btn-sm { padding: .3rem .65rem; font-size: .78rem; border-radius: 7px; }
.btn-lg { padding: .65rem 1.2rem; font-size: .95rem; }
.btn i { font-size: 1em; }
.btn-primary {
    --bs-btn-bg: var(--crm-primary); --bs-btn-border-color: var(--crm-primary);
    --bs-btn-hover-bg: var(--crm-primary-hover); --bs-btn-hover-border-color: var(--crm-primary-hover);
    --bs-btn-active-bg: var(--crm-primary-hover); --bs-btn-active-border-color: var(--crm-primary-hover);
    --bs-btn-disabled-bg: var(--crm-primary); --bs-btn-disabled-border-color: var(--crm-primary);
    --bs-btn-color: #fff; --bs-btn-hover-color: #fff; --bs-btn-active-color: #fff;
    box-shadow: 0 1px 2px rgba(79, 70, 229, .25), inset 0 1px 0 rgba(255,255,255,.12);
}
[data-theme="dark"] .btn-primary { --bs-btn-color: #0b1020; --bs-btn-hover-color: #0b1020; --bs-btn-active-color: #0b1020; }
.btn-light, .btn-outline-secondary {
    --bs-btn-bg: var(--crm-surface); --bs-btn-border-color: var(--crm-border-strong); --bs-btn-color: var(--crm-text-2);
    --bs-btn-hover-bg: var(--crm-surface-hover); --bs-btn-hover-border-color: var(--crm-border-strong); --bs-btn-hover-color: var(--crm-text);
    --bs-btn-active-bg: var(--crm-neutral-soft); --bs-btn-active-border-color: var(--crm-border-strong); --bs-btn-active-color: var(--crm-text);
    box-shadow: var(--crm-shadow-sm);
}
.btn-ghost { background: transparent; border: 1px solid transparent; color: var(--crm-text-2); }
.btn-ghost:hover { background: var(--crm-neutral-soft); color: var(--crm-text); }
.btn-soft-primary { background: var(--crm-primary-soft); color: var(--crm-primary-text); border: 1px solid transparent; }
.btn-soft-primary:hover { background: rgba(var(--crm-primary-rgb), .18); color: var(--crm-primary-text); }
.btn-soft-danger { background: var(--crm-danger-soft); color: var(--crm-danger-text); border: 1px solid transparent; }
.btn-soft-danger:hover { background: var(--crm-danger); color: #fff; }
.btn-soft-success { background: var(--crm-success-soft); color: var(--crm-success-text); border: 1px solid transparent; }
.btn-soft-success:hover { background: var(--crm-success); color: #fff; }
.btn-icon { width: 34px; height: 34px; padding: 0; border-radius: 8px; }
.btn-icon.btn-sm { width: 28px; height: 28px; }
.btn-danger { --bs-btn-bg: var(--crm-danger); --bs-btn-border-color: var(--crm-danger); }
.btn-success { --bs-btn-bg: var(--crm-success); --bs-btn-border-color: var(--crm-success); }
.btn[disabled], .btn.disabled { opacity: .55; }
.btn .spinner-border { width: .9rem; height: .9rem; border-width: 2px; }

/* ---------------------------------------------------------------- Forms */

.form-label { font-size: .8rem; font-weight: 600; color: var(--crm-text-2); margin-bottom: .35rem; }
.form-label .req { color: var(--crm-danger); margin-left: .15rem; }
.form-control, .form-select {
    font-size: .875rem; border-radius: 8px; border-color: var(--crm-border-strong);
    background-color: var(--crm-surface); color: var(--crm-text); padding: .5rem .75rem; min-height: 38px;
}
.form-control::placeholder { color: var(--crm-subtle); }
.form-control:focus, .form-select:focus { border-color: var(--crm-primary); box-shadow: var(--crm-focus); background-color: var(--crm-surface); color: var(--crm-text); }
.form-control-sm, .form-select-sm { min-height: 32px; font-size: .8rem; padding: .3rem .6rem; }
.form-text { font-size: .75rem; color: var(--crm-muted); }
.form-check-input { border-color: var(--crm-border-strong); background-color: var(--crm-surface); }
.form-check-input:checked { background-color: var(--crm-primary); border-color: var(--crm-primary); }
.form-check-input:focus { box-shadow: var(--crm-focus); border-color: var(--crm-primary); }
.form-switch .form-check-input { width: 2.2em; }
.input-group-text { background: var(--crm-surface-2); border-color: var(--crm-border-strong); color: var(--crm-muted); font-size: .85rem; }
.field-validation-error, .invalid-feedback, .text-danger.field { color: var(--crm-danger) !important; font-size: .75rem; margin-top: .3rem; display: block; }
.input-validation-error { border-color: var(--crm-danger) !important; }
.input-validation-error:focus { box-shadow: 0 0 0 3px rgba(220, 38, 38, .18) !important; }
.validation-summary-errors ul { margin: 0; padding-left: 1.1rem; }
.validation-summary-valid { display: none; }

.form-section { padding: 1.15rem 1.25rem; }
.form-section + .form-section { border-top: 1px solid var(--crm-border); }
.form-section-title { font-size: .9rem; font-weight: 650; margin: 0 0 .15rem; display: flex; align-items: center; gap: .5rem; }
.form-section-title i { color: var(--crm-primary); }
.form-section-hint { color: var(--crm-muted); font-size: .78rem; margin: 0 0 1rem; }
.sticky-actions {
    position: sticky; bottom: 0; z-index: 20; background: color-mix(in srgb, var(--crm-surface) 94%, transparent);
    backdrop-filter: blur(8px); border-top: 1px solid var(--crm-border); padding: .8rem 1.25rem;
    display: flex; justify-content: flex-end; gap: .5rem; border-radius: 0 0 var(--crm-radius-lg) var(--crm-radius-lg);
}

/* Tom Select */
.ts-wrapper .ts-control { border-radius: 8px; border-color: var(--crm-border-strong); background: var(--crm-surface); color: var(--crm-text); min-height: 38px; padding: .4rem .65rem; font-size: .875rem; box-shadow: none; }
.ts-wrapper.focus .ts-control { border-color: var(--crm-primary); box-shadow: var(--crm-focus); }
.ts-wrapper.form-select-sm .ts-control, .ts-wrapper.form-control-sm .ts-control { min-height: 32px; padding: .25rem .55rem; font-size: .8rem; }
.ts-dropdown { border-radius: 10px; border-color: var(--crm-border); box-shadow: var(--crm-shadow-lg); background: var(--crm-surface); color: var(--crm-text); font-size: .85rem; z-index: 1060; }
.ts-dropdown .option, .ts-dropdown .create { padding: .45rem .7rem; }
.ts-dropdown .active { background: var(--crm-primary-soft); color: var(--crm-text); }
.ts-dropdown .option .hint { display: block; font-size: .72rem; color: var(--crm-muted); }
.ts-dropdown .optgroup-header { font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; color: var(--crm-muted); font-weight: 650; background: var(--crm-surface); }
.ts-wrapper.multi .ts-control > div { background: var(--crm-primary-soft); color: var(--crm-primary-text); border-radius: 6px; border: 0; padding: .1rem .45rem; }
.ts-wrapper.form-select .ts-control, .ts-wrapper.form-select { background-image: none; }
.ts-wrapper.single .ts-control:after { border-color: var(--crm-subtle) transparent transparent transparent; }
.ts-wrapper.plugin-remove_button .item .remove { border-left-color: rgba(var(--crm-primary-rgb), .25); }
.ts-wrapper.input-validation-error .ts-control { border-color: var(--crm-danger); }

/* ---------------------------------------------------------------- Tables */

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-crm { width: 100%; margin: 0; border-collapse: separate; border-spacing: 0; font-size: .84rem; color: var(--crm-text); }
.table-crm thead th {
    position: sticky; top: 0; z-index: 2; background: var(--crm-surface-2);
    font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--crm-muted); font-weight: 650;
    padding: .65rem .9rem; border-bottom: 1px solid var(--crm-border); white-space: nowrap; text-align: left;
}
.table-crm thead th a { color: inherit; display: inline-flex; gap: .25rem; align-items: center; }
.table-crm thead th a:hover { color: var(--crm-text); }
.table-crm thead th.sorted { color: var(--crm-primary-text); }
.table-crm tbody td { padding: .7rem .9rem; border-bottom: 1px solid var(--crm-border); vertical-align: middle; }
.table-crm tbody tr:last-child td { border-bottom: 0; }
.table-crm tbody tr { transition: background .1s; }
.table-crm tbody tr:hover { background: var(--crm-surface-hover); }
.table-crm tbody tr.is-selected { background: var(--crm-primary-soft); }
.table-crm .col-check { width: 40px; padding-right: 0; }
.table-crm .col-actions { width: 1%; white-space: nowrap; text-align: right; }
.table-crm .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table-crm .cell-title { font-weight: 600; color: var(--crm-text); display: block; line-height: 1.3; }
.table-crm a.cell-title:hover { color: var(--crm-primary); }
.table-crm .cell-sub { font-size: .75rem; color: var(--crm-muted); display: block; margin-top: .1rem; }
.table-crm.compact tbody td { padding: .5rem .75rem; }
.table-crm tfoot td { padding: .65rem .9rem; font-weight: 700; border-top: 1px solid var(--crm-border-strong); background: var(--crm-surface-2); }
.table-crm .record-code { white-space: nowrap; }
.table-crm td[data-label="Created"], .table-crm td[data-label="When"], .table-crm td[data-label="Follow-up"], .table-crm td[data-label="Expected close"] { white-space: nowrap; }
@media (min-width: 768px) { .table-crm td.stack-title { min-width: 220px; max-width: 420px; } }
.row-overdue td:first-child { box-shadow: inset 3px 0 0 var(--crm-danger); }

/* Responsive stacked table (mobile) */
@media (max-width: 767.98px) {
    .table-stack thead { display: none; }
    .table-stack, .table-stack tbody, .table-stack tr, .table-stack td { display: block; width: 100%; }
    .table-stack tr { border-bottom: 1px solid var(--crm-border); padding: .6rem .9rem; }
    .table-stack tbody td { border: 0; padding: .2rem 0; display: flex; justify-content: space-between; gap: 1rem; text-align: right; }
    .table-stack tbody td::before { content: attr(data-label); font-size: .72rem; color: var(--crm-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; text-align: left; flex-shrink: 0; }
    .table-stack tbody td.stack-title { display: block; text-align: left; padding-bottom: .35rem; }
    .table-stack tbody td.stack-title::before { display: none; }
    .table-stack .col-check { display: none !important; }
    .table-stack .col-actions { justify-content: flex-end; width: 100% !important; }
    .table-stack .col-actions::before { display: none; }
}

/* Filter / toolbar */
.toolbar { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; padding: .8rem 1rem; border-bottom: 1px solid var(--crm-border); }
.toolbar .search-box { position: relative; flex: 1 1 240px; max-width: 360px; }
.toolbar .search-box i { position: absolute; left: .7rem; top: 50%; transform: translateY(-50%); color: var(--crm-subtle); }
.toolbar .search-box .form-control { padding-left: 2.1rem; }
.toolbar .form-select, .toolbar .ts-wrapper { width: auto; min-width: 150px; max-width: 220px; }
.filter-panel { padding: .9rem 1rem; border-bottom: 1px solid var(--crm-border); background: var(--crm-surface-2); }
.chip-row { display: flex; gap: .4rem; flex-wrap: wrap; }
.filter-chip { display: inline-flex; align-items: center; gap: .35rem; background: var(--crm-primary-soft); color: var(--crm-primary-text); font-size: .74rem; font-weight: 600; border-radius: 999px; padding: .2rem .35rem .2rem .65rem; }
.filter-chip a { color: inherit; opacity: .7; display: grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; }
.filter-chip a:hover { opacity: 1; background: rgba(var(--crm-primary-rgb), .15); }

.view-tabs { display: flex; gap: .15rem; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--crm-border); padding: 0 .75rem; }
.view-tabs::-webkit-scrollbar { display: none; }
.view-tab { padding: .75rem .8rem; color: var(--crm-muted); font-weight: 600; font-size: .83rem; white-space: nowrap; border-bottom: 2px solid transparent; display: inline-flex; gap: .45rem; align-items: center; margin-bottom: -1px; }
.view-tab:hover { color: var(--crm-text); }
.view-tab.active { color: var(--crm-primary-text); border-bottom-color: var(--crm-primary); }
[data-theme="dark"] .view-tab.active { color: var(--crm-primary); }
.view-tab .count-chip { font-size: .66rem; }
.view-tab.active .count-chip { background: var(--crm-primary-soft); color: var(--crm-primary-text); }

.bulk-bar {
    display: none; align-items: center; gap: .6rem; flex-wrap: wrap; padding: .6rem 1rem; background: var(--crm-primary-soft);
    border-bottom: 1px solid rgba(var(--crm-primary-rgb), .2); font-size: .82rem; color: var(--crm-primary-text); font-weight: 600;
}
.bulk-bar.show { display: flex; }

/* Pager */
.pager { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .75rem 1rem; border-top: 1px solid var(--crm-border); flex-wrap: wrap; font-size: .8rem; color: var(--crm-muted); }
.pager .pages { display: flex; gap: .25rem; align-items: center; }
.pager .page-btn { min-width: 32px; height: 32px; padding: 0 .55rem; border-radius: 8px; display: inline-grid; place-items: center; color: var(--crm-text-2); border: 1px solid var(--crm-border); background: var(--crm-surface); font-weight: 600; font-size: .8rem; }
.pager .page-btn:hover { border-color: var(--crm-border-strong); color: var(--crm-text); }
.pager .page-btn.active { background: var(--crm-primary); border-color: var(--crm-primary); color: #fff; }
.pager .page-btn.disabled { opacity: .45; pointer-events: none; }
.pager .form-select { width: auto; min-height: 32px; padding-top: .25rem; padding-bottom: .25rem; font-size: .8rem; }

/* ---------------------------------------------------------------- Empty states / alerts */

.empty-state { text-align: center; padding: 3rem 1.5rem; color: var(--crm-muted); }
.empty-state .icon { width: 60px; height: 60px; border-radius: 18px; display: grid; place-items: center; margin: 0 auto 1rem; font-size: 1.6rem; background: var(--crm-primary-soft); color: var(--crm-primary-text); }
.empty-state h3 { font-size: 1rem; color: var(--crm-text); margin-bottom: .3rem; }
.empty-state p { max-width: 420px; margin: 0 auto 1rem; font-size: .85rem; }
.empty-inline { padding: 1.25rem; text-align: center; color: var(--crm-muted); font-size: .84rem; }

.alert { border-radius: var(--crm-radius); font-size: .85rem; border: 1px solid transparent; }
.alert-soft-warning { background: var(--crm-warning-soft); color: var(--crm-warning-text); border-color: rgba(217, 119, 6, .2); }
.alert-soft-danger { background: var(--crm-danger-soft); color: var(--crm-danger-text); border-color: rgba(220, 38, 38, .2); }
.alert-soft-info { background: var(--crm-info-soft); color: var(--crm-info-text); border-color: rgba(2, 132, 199, .2); }
.alert-soft-success { background: var(--crm-success-soft); color: var(--crm-success-text); border-color: rgba(22, 163, 74, .2); }
.alert-soft-primary { background: var(--crm-primary-soft); color: var(--crm-primary-text); border-color: rgba(var(--crm-primary-rgb), .2); }

/* ---------------------------------------------------------------- Detail pages */

.record-hero { display: flex; gap: 1rem; align-items: flex-start; padding: 1.25rem; flex-wrap: wrap; }
.record-hero .meta { display: flex; flex-wrap: wrap; gap: .4rem .9rem; color: var(--crm-muted); font-size: .8rem; margin-top: .4rem; }
.record-hero .meta span { display: inline-flex; gap: .35rem; align-items: center; }
.record-title { font-size: 1.3rem; font-weight: 700; margin: 0; letter-spacing: -.02em; word-break: break-word; }
.record-code { font-size: .75rem; font-weight: 650; color: var(--crm-muted); letter-spacing: .04em; }

.stage-track { display: flex; gap: 3px; padding: 0 1.25rem 1.25rem; overflow-x: auto; }
.stage-step {
    flex: 1 1 0; min-width: 96px; position: relative; padding: .55rem .7rem .55rem 1.1rem; font-size: .74rem; font-weight: 650;
    background: var(--crm-neutral-soft); color: var(--crm-muted); text-align: center; border: 0;
    clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 50%, calc(100% - 10px) 100%, 0 100%, 10px 50%);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; transition: filter .15s;
}
.stage-step:first-child { clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 50%, calc(100% - 10px) 100%, 0 100%); border-radius: 8px 0 0 8px; padding-left: .8rem; }
.stage-step:last-child { clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%, 10px 50%); border-radius: 0 8px 8px 0; }
.stage-step.done { background: rgba(var(--crm-primary-rgb), .18); color: var(--crm-primary-text); }
.stage-step.current { background: var(--crm-primary); color: #fff; }
.stage-step.won { background: var(--crm-success); color: #fff; }
.stage-step.lost { background: var(--crm-danger); color: #fff; }
.stage-step:hover { filter: brightness(.96); }
.stage-step[disabled] { cursor: default; }

.info-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem 1.25rem; }
.info-item .label { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--crm-muted); font-weight: 600; margin-bottom: .2rem; display: flex; gap: .35rem; align-items: center; }
.info-item .value { font-weight: 550; color: var(--crm-text); word-break: break-word; }
.info-item .value.empty { color: var(--crm-subtle); font-weight: 400; }
.info-item .source-hint { font-size: .7rem; color: var(--crm-subtle); font-weight: 500; }
.info-list { list-style: none; margin: 0; padding: 0; }
.info-list li { display: flex; justify-content: space-between; gap: 1rem; padding: .55rem 0; border-bottom: 1px dashed var(--crm-border); font-size: .84rem; }
.info-list li:last-child { border-bottom: 0; }
.info-list .k { color: var(--crm-muted); }
.info-list .v { font-weight: 600; text-align: right; word-break: break-word; }

.quick-actions { display: flex; gap: .4rem; flex-wrap: wrap; }

.tabs-crm { display: flex; gap: .15rem; border-bottom: 1px solid var(--crm-border); padding: 0 1rem; overflow-x: auto; scrollbar-width: none; }
.tabs-crm::-webkit-scrollbar { display: none; }
.tabs-crm .nav-link { border: 0; background: none; color: var(--crm-muted); font-weight: 600; font-size: .83rem; padding: .8rem .75rem; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; display: inline-flex; gap: .4rem; align-items: center; border-radius: 0; }
.tabs-crm .nav-link:hover { color: var(--crm-text); }
.tabs-crm .nav-link.active { color: var(--crm-primary-text); border-bottom-color: var(--crm-primary); background: none; }
[data-theme="dark"] .tabs-crm .nav-link.active { color: var(--crm-primary); }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: .25rem 0; position: relative; }
.timeline-item { position: relative; padding: 0 0 1.1rem 2.6rem; }
.timeline-item::before { content: ""; position: absolute; left: 15px; top: 30px; bottom: 0; width: 2px; background: var(--crm-border); }
.timeline-item:last-child::before { display: none; }
.timeline-dot { position: absolute; left: 0; top: 0; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-size: .85rem; border: 3px solid var(--crm-surface); }
.timeline-head { display: flex; justify-content: space-between; gap: .75rem; flex-wrap: wrap; align-items: baseline; }
.timeline-title { font-weight: 650; font-size: .84rem; }
.timeline-time { font-size: .74rem; color: var(--crm-muted); white-space: nowrap; }
.timeline-body { font-size: .84rem; color: var(--crm-text-2); margin-top: .15rem; white-space: pre-line; word-break: break-word; }
.timeline-meta { font-size: .74rem; color: var(--crm-muted); margin-top: .2rem; }
.timeline-change { display: inline-flex; gap: .4rem; align-items: center; flex-wrap: wrap; font-size: .8rem; margin-top: .25rem; }
.timeline-change .old { text-decoration: line-through; color: var(--crm-muted); }
.timeline-change .new { font-weight: 600; color: var(--crm-text); }

/* Notes */
.note { border: 1px solid var(--crm-border); border-radius: var(--crm-radius); padding: .85rem 1rem; background: var(--crm-surface); }
.note + .note { margin-top: .6rem; }
.note.pinned { border-color: rgba(217, 119, 6, .35); background: color-mix(in srgb, var(--crm-warning-soft) 45%, var(--crm-surface)); }
.note-text { white-space: pre-line; word-break: break-word; font-size: .86rem; }
.note-meta { font-size: .74rem; color: var(--crm-muted); display: flex; gap: .5rem; align-items: center; margin-top: .45rem; flex-wrap: wrap; }

/* List rows (follow-ups, tasks) */
.list-rows { list-style: none; margin: 0; padding: 0; }
.list-row { display: flex; gap: .85rem; align-items: flex-start; padding: .8rem 1.1rem; border-bottom: 1px solid var(--crm-border); }
.list-row:last-child { border-bottom: 0; }
.list-row:hover { background: var(--crm-surface-hover); }
.list-row .when { min-width: 64px; text-align: center; border-radius: 10px; padding: .35rem .25rem; background: var(--crm-neutral-soft); line-height: 1.15; }
.list-row .when .d { font-weight: 750; font-size: 1rem; display: block; }
.list-row .when .m { font-size: .66rem; text-transform: uppercase; letter-spacing: .05em; color: var(--crm-muted); font-weight: 650; }
.list-row .when .t { font-size: .68rem; color: var(--crm-muted); display: block; }
.list-row .when.overdue { background: var(--crm-danger-soft); color: var(--crm-danger-text); }
.list-row .when.overdue .m, .list-row .when.overdue .t { color: var(--crm-danger-text); }
.list-row .when.today { background: var(--crm-warning-soft); color: var(--crm-warning-text); }
.list-row .when.today .m, .list-row .when.today .t { color: var(--crm-warning-text); }
.list-row .body { flex: 1; min-width: 0; }
.list-row .row-actions { display: flex; gap: .3rem; flex-shrink: 0; }
.task-check { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--crm-border-strong); background: var(--crm-surface); display: grid; place-items: center; flex-shrink: 0; color: transparent; padding: 0; margin-top: 2px; }
.task-check:hover { border-color: var(--crm-success); color: var(--crm-success); }
.task-check.done { background: var(--crm-success); border-color: var(--crm-success); color: #fff; }
.is-done .task-subject { text-decoration: line-through; color: var(--crm-muted); }

/* ---------------------------------------------------------------- Kanban board */

.board-wrap { overflow-x: auto; padding-bottom: .5rem; }
.board { display: flex; gap: .9rem; align-items: flex-start; min-height: 60vh; }
.board-col { flex: 0 0 290px; min-width: 0; width: 290px; background: var(--crm-surface-2); border: 1px solid var(--crm-border); border-radius: var(--crm-radius-lg); display: flex; flex-direction: column; max-height: calc(100vh - 220px); }
.board-col-head { padding: .8rem .9rem .6rem; border-bottom: 1px solid var(--crm-border); border-top: 3px solid var(--col, var(--crm-primary)); border-radius: var(--crm-radius-lg) var(--crm-radius-lg) 0 0; }
.board-col-title { font-weight: 700; font-size: .84rem; display: flex; justify-content: space-between; gap: .5rem; align-items: center; }
.board-col-sub { font-size: .74rem; color: var(--crm-muted); margin-top: .15rem; display: flex; justify-content: space-between; }
.board-list { padding: .6rem; overflow-y: auto; flex: 1; min-height: 80px; display: flex; flex-direction: column; gap: .55rem; }
.board-card { background: var(--crm-surface); border: 1px solid var(--crm-border); border-radius: var(--crm-radius); padding: .7rem .8rem; box-shadow: var(--crm-shadow-sm); cursor: grab; transition: box-shadow .15s, border-color .15s; }
.board-card:hover { border-color: var(--crm-border-strong); box-shadow: var(--crm-shadow); }
.board-card .title { font-weight: 650; font-size: .84rem; color: var(--crm-text); display: block; line-height: 1.3; }
.board-card .sub { font-size: .75rem; color: var(--crm-muted); margin-top: .15rem; }
.board-card .foot { display: flex; justify-content: space-between; align-items: center; margin-top: .55rem; gap: .4rem; font-size: .74rem; color: var(--crm-muted); }
.board-card .amount { font-weight: 700; color: var(--crm-text); font-variant-numeric: tabular-nums; }
.sortable-ghost { opacity: .4; }
.sortable-drag { box-shadow: var(--crm-shadow-lg) !important; transform: rotate(1.5deg); }
.board-more { font-size: .75rem; text-align: center; color: var(--crm-muted); padding: .25rem; }

/* ---------------------------------------------------------------- Calendar */

.cal { width: 100%; border-collapse: collapse; table-layout: fixed; }
.cal th { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--crm-muted); font-weight: 650; padding: .5rem; text-align: left; border-bottom: 1px solid var(--crm-border); }
.cal td { vertical-align: top; height: 118px; border: 1px solid var(--crm-border); padding: .35rem; background: var(--crm-surface); }
.cal td.other { background: var(--crm-surface-2); }
.cal td.other .cal-day { color: var(--crm-subtle); }
.cal td.today { background: color-mix(in srgb, var(--crm-primary-soft) 55%, var(--crm-surface)); }
.cal-day { font-size: .75rem; font-weight: 700; color: var(--crm-text-2); margin-bottom: .2rem; display: flex; justify-content: space-between; }
.cal td.today .cal-day span:first-child { background: var(--crm-primary); color: #fff; border-radius: 999px; padding: 0 .4rem; }
.cal-event { display: block; font-size: .7rem; padding: .12rem .35rem; border-radius: 5px; margin-bottom: 2px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-weight: 600; }
.cal-event.done { opacity: .55; text-decoration: line-through; }
.cal-more { font-size: .68rem; color: var(--crm-muted); }
@media (max-width: 767.98px) { .cal td { height: 76px; } .cal-event { font-size: .62rem; } }

/* ---------------------------------------------------------------- Charts */

.chart-box { min-height: 280px; }
.chart-box.sm { min-height: 220px; }
.apexcharts-tooltip { border-radius: 8px !important; box-shadow: var(--crm-shadow-lg) !important; border: 1px solid var(--crm-border) !important; background: var(--crm-surface) !important; color: var(--crm-text) !important; }
.apexcharts-tooltip-title { background: var(--crm-surface-2) !important; border-bottom-color: var(--crm-border) !important; }
.apexcharts-text, .apexcharts-legend-text { fill: var(--crm-muted) !important; color: var(--crm-muted) !important; }
.progress { background: var(--crm-neutral-soft); border-radius: 999px; height: 8px; }
.progress-bar { background: var(--crm-primary); border-radius: 999px; }

/* ---------------------------------------------------------------- Dropdowns / modals / toasts */

.dropdown-menu { border-radius: 10px; border-color: var(--crm-border); box-shadow: var(--crm-shadow-lg); padding: .35rem; font-size: .85rem; background: var(--crm-surface); --bs-dropdown-link-color: var(--crm-text); --bs-dropdown-link-hover-bg: var(--crm-surface-hover); --bs-dropdown-link-hover-color: var(--crm-text); --bs-dropdown-link-active-bg: var(--crm-primary-soft); --bs-dropdown-link-active-color: var(--crm-primary-text); --bs-dropdown-divider-bg: var(--crm-border); --bs-dropdown-header-color: var(--crm-muted); }
.dropdown-item { border-radius: 7px; padding: .45rem .7rem; display: flex; align-items: center; gap: .6rem; }
.dropdown-item i { width: 16px; color: var(--crm-muted); text-align: center; }
.dropdown-item.text-danger i { color: inherit; }
.dropdown-header { font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 650; }

.notif-menu { width: min(380px, calc(100vw - 24px)); padding: 0; }
.notif-head { display: flex; justify-content: space-between; align-items: center; padding: .8rem 1rem; border-bottom: 1px solid var(--crm-border); }
.notif-list { max-height: 420px; overflow-y: auto; }
.notif-item { display: flex; gap: .7rem; padding: .75rem 1rem; border-bottom: 1px solid var(--crm-border); color: var(--crm-text); }
.notif-item:hover { background: var(--crm-surface-hover); color: var(--crm-text); }
.notif-item.unread { background: color-mix(in srgb, var(--crm-primary-soft) 55%, var(--crm-surface)); }
.notif-item .ic { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; flex-shrink: 0; }
.notif-item .t { font-weight: 600; font-size: .82rem; line-height: 1.3; }
.notif-item .m { font-size: .76rem; color: var(--crm-muted); }
.notif-item .w { font-size: .7rem; color: var(--crm-subtle); margin-top: .15rem; }

.modal-content { border-radius: var(--crm-radius-lg); border: 1px solid var(--crm-border); box-shadow: var(--crm-shadow-lg); background: var(--crm-surface); color: var(--crm-text); }
.modal-header { padding: 1rem 1.25rem; border-bottom-color: var(--crm-border); }
.modal-title { font-size: 1rem; font-weight: 700; display: flex; gap: .5rem; align-items: center; }
.modal-body { padding: 1.25rem; }
.modal-footer { padding: .8rem 1.25rem; border-top-color: var(--crm-border); background: var(--crm-surface-2); border-radius: 0 0 var(--crm-radius-lg) var(--crm-radius-lg); }
[data-theme="dark"] .btn-close { filter: invert(1) grayscale(100%) brightness(200%); }
.modal-backdrop.show { opacity: .45; }

.toast-stack { position: fixed; top: 1rem; right: 1rem; z-index: 1090; display: flex; flex-direction: column; gap: .5rem; width: min(380px, calc(100vw - 2rem)); }
.toast-crm {
    display: flex; gap: .7rem; align-items: flex-start; padding: .8rem .9rem; border-radius: 12px; background: var(--crm-surface);
    border: 1px solid var(--crm-border); box-shadow: var(--crm-shadow-lg); font-size: .85rem; animation: toast-in .25s ease;
}
.toast-crm .ic { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; flex-shrink: 0; }
.toast-crm .msg { flex: 1; padding-top: .2rem; color: var(--crm-text); word-break: break-word; }
.toast-crm .x { border: 0; background: none; color: var(--crm-muted); padding: .15rem; line-height: 1; }
.toast-crm.hide { animation: toast-out .2s ease forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateX(20px); } }

.loading-overlay { position: absolute; inset: 0; background: color-mix(in srgb, var(--crm-surface) 70%, transparent); display: grid; place-items: center; z-index: 5; border-radius: inherit; }

/* ---------------------------------------------------------------- Auth pages */

.auth-page { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr; background: var(--crm-surface); }
.auth-aside {
    position: relative; overflow: hidden; color: #e0e7ff; padding: 3rem; display: flex; flex-direction: column; justify-content: space-between;
    background: radial-gradient(1200px 600px at -10% -10%, rgba(139, 92, 246, .55), transparent 60%),
                radial-gradient(900px 500px at 110% 110%, rgba(236, 72, 153, .35), transparent 60%),
                linear-gradient(160deg, #111a3a 0%, #1e1b4b 55%, #312e81 100%);
}
.auth-aside h1 { color: #fff; font-size: 2.1rem; font-weight: 750; letter-spacing: -.03em; line-height: 1.15; max-width: 460px; }
.auth-aside p { color: #c7d2fe; max-width: 440px; font-size: .95rem; }
.auth-feature { display: flex; gap: .8rem; align-items: flex-start; margin-top: 1rem; max-width: 420px; }
.auth-feature i { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: rgba(255, 255, 255, .1); color: #fff; flex-shrink: 0; }
.auth-feature strong { color: #fff; display: block; font-size: .9rem; }
.auth-feature span { font-size: .8rem; color: #a5b4fc; }
.auth-main { display: grid; place-items: center; padding: 2.5rem 1.5rem; }
.auth-card { width: 100%; max-width: 400px; }
.auth-card h2 { font-size: 1.5rem; font-weight: 750; letter-spacing: -.02em; margin-bottom: .35rem; }
.auth-card .lead-text { color: var(--crm-muted); margin-bottom: 1.75rem; }
.auth-card .form-control { min-height: 44px; }
.auth-card .btn-lg { width: 100%; min-height: 46px; }
.divider-text { display: flex; align-items: center; gap: .75rem; color: var(--crm-subtle); font-size: .75rem; margin: 1.25rem 0; }
.divider-text::before, .divider-text::after { content: ""; flex: 1; height: 1px; background: var(--crm-border); }
@media (max-width: 991.98px) { .auth-page { grid-template-columns: 1fr; } .auth-aside { display: none; } }

/* ---------------------------------------------------------------- Misc */

.permission-matrix .module-row td { background: var(--crm-surface-2); font-weight: 700; }
.permission-matrix td { padding: .55rem .9rem; border-bottom: 1px solid var(--crm-border); }
.color-swatch { width: 14px; height: 14px; border-radius: 4px; display: inline-block; border: 1px solid rgba(0,0,0,.08); vertical-align: -2px; }
.drag-handle { cursor: grab; color: var(--crm-subtle); }
.drag-handle:hover { color: var(--crm-text); }
.sticky-top-card { position: sticky; top: calc(var(--crm-topbar-h) + 1rem); }
.hover-lift { transition: transform .15s, box-shadow .15s; }
.hover-lift:hover { transform: translateY(-2px); box-shadow: var(--crm-shadow); }
.link-muted { color: var(--crm-muted); }
.link-muted:hover { color: var(--crm-primary); }
.email-frame { width: 100%; min-height: 320px; border: 1px solid var(--crm-border); border-radius: var(--crm-radius); background: #fff; }
.rich-editor { min-height: 220px; max-height: 480px; overflow-y: auto; border: 1px solid var(--crm-border-strong); border-radius: 0 0 8px 8px; padding: .75rem; background: var(--crm-surface); }
.rich-editor:focus { outline: none; border-color: var(--crm-primary); box-shadow: var(--crm-focus); }
.rich-toolbar { display: flex; gap: .15rem; padding: .3rem; border: 1px solid var(--crm-border-strong); border-bottom: 0; border-radius: 8px 8px 0 0; background: var(--crm-surface-2); flex-wrap: wrap; }
.rich-toolbar button { border: 0; background: none; color: var(--crm-text-2); width: 30px; height: 28px; border-radius: 6px; }
.rich-toolbar button:hover { background: var(--crm-neutral-soft); }
.merge-chip { font-size: .72rem; padding: .15rem .45rem; border-radius: 6px; background: var(--crm-neutral-soft); color: var(--crm-text-2); border: 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.merge-chip:hover { background: var(--crm-primary-soft); color: var(--crm-primary-text); }
.checklist { list-style: none; padding: 0; margin: 0; }
.checklist li { display: flex; gap: .55rem; align-items: flex-start; padding: .4rem 0; font-size: .84rem; }
.checklist li i { color: var(--crm-primary); margin-top: .15rem; }
.import-steps { display: flex; gap: .5rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.import-step { display: flex; align-items: center; gap: .5rem; font-size: .8rem; font-weight: 600; color: var(--crm-muted); }
.import-step .n { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; background: var(--crm-neutral-soft); font-size: .72rem; }
.import-step.active { color: var(--crm-primary-text); }
.import-step.active .n { background: var(--crm-primary); color: #fff; }
.import-step.done .n { background: var(--crm-success); color: #fff; }
.import-step + .import-step::before { content: ""; width: 28px; height: 2px; background: var(--crm-border); }
.drop-zone { border: 2px dashed var(--crm-border-strong); border-radius: var(--crm-radius-lg); padding: 2.5rem 1.5rem; text-align: center; background: var(--crm-surface-2); transition: border-color .15s, background .15s; }
.drop-zone.over { border-color: var(--crm-primary); background: var(--crm-primary-soft); }
.code-block { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .75rem; background: var(--crm-surface-2); border: 1px solid var(--crm-border); border-radius: 8px; padding: .6rem .75rem; white-space: pre-wrap; word-break: break-all; max-height: 240px; overflow: auto; }
.status-page { min-height: 70vh; display: grid; place-items: center; text-align: center; }
.status-page .code { font-size: 4.5rem; font-weight: 800; letter-spacing: -.04em; background: linear-gradient(135deg, #6366f1, #ec4899); -webkit-background-clip: text; background-clip: text; color: transparent; line-height: 1; }

@media print {
    .sidebar, .topbar, .page-actions, .toolbar, .pager, .no-print { display: none !important; }
    .main { margin-left: 0 !important; }
    .card-crm { box-shadow: none; }
}
