/* BAuto: graphite surfaces, indigo controls, quiet data-first hierarchy.
   Craft principles adapted from Unslop by Damir Sokolovsky (@heydamir), CC BY 4.0.
   https://github.com/heydamir/unslop */

body.crm-theme {
    --primary: #4f46e5;
    --primary-light: #6366f1;
    --primary-dark: #3730a3;
    --primary-gradient: #4f46e5;
    --primary-gradient-soft: #eef0ff;
    --accent-color: #4f46e5;
    --interactive: #4f46e5;
    --interactive-hover: #4338ca;
    --focus-ring: rgba(79, 70, 229, .24);
    --bg-body: #f4f5f7;
    --bg-body-alt: #eef0f3;
    --bg-card: #ffffff;
    --bg-card-solid: #ffffff;
    --bg-glass: #ffffff;
    --bg-glass-hover: #f0f1f5;
    --bg-hover: #eef0f5;
    --text-primary: #252933;
    --text-secondary: #535b6b;
    --text-muted: #687181;
    --border-color: #dfe3e9;
    --border-glass: #dfe3e9;
    --sidebar-bg: #20232c;
    --sidebar-text: #c7ccd8;
    --sidebar-active: #34374d;
    --surface-1: var(--bg-card-solid);
    --surface-2: var(--bg-body-alt);
    --table-bg: var(--bg-card-solid);
    --table-color: var(--text-primary);
    --table-stripe: rgba(37, 41, 51, .025);
    --table-hover: rgba(79, 70, 229, .045);
    --radius-sm: 6px;
    --radius: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --shadow-sm: 0 1px 2px rgba(20, 24, 35, .035);
    --shadow: 0 2px 8px rgba(20, 24, 35, .045);
    --shadow-lg: 0 8px 24px rgba(20, 24, 35, .09);
    --shadow-xl: 0 16px 40px rgba(20, 24, 35, .12);
    --shadow-glass: var(--shadow-sm);
    --transition: color .16s ease-out, background-color .16s ease-out, border-color .16s ease-out;
    --transition-fast: var(--transition);
    --transition-slow: var(--transition);
    --content-max: 1600px;
    --bs-primary: #4f46e5;
    --bs-primary-rgb: 79, 70, 229;
    --bs-link-color: #4f46e5;
    --bs-link-hover-color: #3730a3;
    --bs-body-color: var(--text-primary);
    --bs-body-bg: var(--bg-body);
    --bs-secondary-color: var(--text-muted);
    --bs-border-color: var(--border-color);
    background: var(--bg-body);
    color: var(--text-primary);
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    font-size: 14px;
    line-height: 1.55;
}

body.crm-theme.dark-theme {
    --primary: #a5a6ff;
    --primary-light: #c1c2ff;
    --primary-dark: #8183e8;
    --primary-gradient: #6366f1;
    --primary-gradient-soft: #2a2d46;
    --accent-color: #a5a6ff;
    --interactive: #575bd8;
    --interactive-hover: #4b4ec4;
    --focus-ring: rgba(165, 166, 255, .3);
    --bg-body: #17191f;
    --bg-body-alt: #20232b;
    --bg-card: #22252d;
    --bg-card-solid: #22252d;
    --bg-glass: #22252d;
    --bg-glass-hover: #2c303a;
    --bg-hover: #2c303a;
    --text-primary: #edeef3;
    --text-secondary: #bdc3d0;
    --text-muted: #9ba4b6;
    --border-color: #363b47;
    --border-glass: #363b47;
    --sidebar-bg: #12141a;
    --sidebar-active: #292d42;
    --shadow-sm: none;
    --shadow: none;
    --shadow-glass: none;
    --bs-primary-rgb: 165, 166, 255;
    --bs-link-color: #a5a6ff;
    --bs-link-hover-color: #c1c2ff;
}

body.crm-theme .workspace-page {
    --workspace-accent: var(--primary) !important;
    --workspace-accent-soft: var(--primary-gradient-soft) !important;
}
body.crm-theme :is(h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6) {
    font-weight: 600;
    letter-spacing: 0;
    line-height: 1.3;
}
body.crm-theme :is(h1, .workspace-title, .task-detail-hero .workspace-title) {
    font-size: clamp(25px, 2.5vw, 32px);
    font-weight: 500;
    line-height: 1.25;
    letter-spacing: -.015em;
}
body.crm-theme :is(.workspace-kicker, .toolbar-card .form-label, .table th, .client-360-data dt) {
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0;
    text-transform: none;
}
body.crm-theme .workspace-kicker { display: flex; margin-bottom: 8px; color: var(--text-muted); }
body.crm-theme .workspace-header { gap: 16px; margin-bottom: 20px; }
body.crm-theme .workspace-subtitle { margin-top: 8px; font-size: 14px; line-height: 1.5; }
body.crm-theme :is(.summary-value, .metric-value, .stat-value, .report-value) { font-variant-numeric: tabular-nums; font-weight: 600; }
body.crm-theme :is(.summary-value, .stat-value) { font-size: 26px; line-height: 1.2; }
body.crm-theme :is(.summary-label, .dashboard-panel-title, .dashboard-task-title, .data-panel-title, .form-label) { font-weight: 500; }
body.crm-theme .summary-label { font-size: 12px; }
body.crm-theme .summary-note { margin-top: 4px; font-size: 12px; color: var(--text-muted); }

/* Stable controls and surfaces. Semantic success/warning/error colors remain distinct. */
body.crm-theme :is(.btn, .workspace-primary-action, .form-control, .form-select) {
    border-radius: 8px;
    font-weight: 500;
    letter-spacing: 0;
    transition: var(--transition);
}
body.crm-theme :is(.btn, .workspace-primary-action):is(:hover, :active) { transform: none; box-shadow: none; }
body.crm-theme .btn:not(.btn-sm) { padding: 8px 16px; }
body.crm-theme .workspace-primary-action { min-height: 40px; padding: 8px 16px; box-shadow: none; }
body.crm-theme :is(.btn-primary, .workspace-primary-action) { background: var(--interactive) !important; border-color: var(--interactive) !important; color: #fff !important; }
body.crm-theme :is(.btn-primary, .workspace-primary-action):hover { background: var(--interactive-hover) !important; border-color: var(--interactive-hover) !important; }
body.crm-theme .btn-outline-primary { color: var(--primary); border-color: var(--primary); background: transparent; }
body.crm-theme .btn-outline-primary:hover { color: var(--primary); background: var(--primary-gradient-soft); }
body.crm-theme :is(.form-control, .form-select) { background-color: var(--bg-card-solid); color: var(--text-primary); border-color: var(--border-color); min-height: 40px; font-size: 14px; }
body.crm-theme :is(.form-control, .form-select):focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--focus-ring); }
body.crm-theme .form-control::placeholder { color: var(--text-muted); opacity: 1; }
/* Bootstrap's light addon background must follow the active theme too. */
body.crm-theme .input-group-text {
    background-color: var(--bg-body-alt);
    color: var(--text-secondary);
    border-color: var(--border-color);
    --bs-body-color: var(--text-secondary);
    --bs-tertiary-bg: var(--bg-body-alt);
}
body.crm-theme .input-group-text :is(.fa-search, .fa-magnifying-glass) { color: inherit; }
body.crm-theme :is(.search-field, .global-search-field, .admin-settings-search) > :is(.fa-search, .fa-magnifying-glass) { color: var(--text-secondary); }
body.crm-theme :is(.search-field, .global-search-field, .admin-settings-search):focus-within > :is(.fa-search, .fa-magnifying-glass) { color: var(--primary); }
body.crm-theme input[type="file"]::file-selector-button {
    color: var(--text-primary);
    background-color: var(--bg-body-alt);
    border: 0;
    border-inline-end: 1px solid var(--border-color);
    padding: 8px 12px;
    font: inherit;
    cursor: pointer;
    transition: var(--transition);
}
body.crm-theme input[type="file"]:hover:not(:disabled)::file-selector-button {
    color: var(--primary);
    background-color: var(--primary-gradient-soft);
}
body.crm-theme input[type="file"]:disabled::file-selector-button {
    color: var(--text-muted);
    cursor: not-allowed;
}
body.crm-theme.dark-theme input[type="file"] { color-scheme: dark; }
body.crm-theme :is(.form-check-input:checked, .pagination .page-item.active .page-link) { background-color: var(--interactive); border-color: var(--interactive); }
body.crm-theme :is(.card, .data-panel, .workflow-card, .dashboard-panel, .toolbar-card, .summary-card) { border-color: var(--border-color); background: var(--bg-card-solid); box-shadow: var(--shadow-sm); backdrop-filter: none; }
body.crm-theme :is(.card, .data-panel, .workflow-card, .dashboard-panel, .summary-card):hover { transform: none; box-shadow: var(--shadow-sm); border-color: var(--border-color); }
body.crm-theme :is(.card, .data-panel, .dashboard-panel, .toolbar-card) { border-radius: 12px; }
body.crm-theme .card-body { padding: 20px; }
body.crm-theme .card-header { padding: 12px 20px; font-weight: 500; border-bottom-color: var(--border-color); }
body.crm-theme .card-header.bg-primary { background: var(--bg-body-alt) !important; color: var(--text-primary) !important; }
body.crm-theme .card-header :is(h2, h3, h4, h5) { color: inherit; }
body.crm-theme .dashboard-panel { padding: 20px; }
body.crm-theme .dashboard-panel-header { gap: 12px; margin-bottom: 16px; }
body.crm-theme .dashboard-panel-subtitle { margin-top: 4px; font-size: 13px; }
body.crm-theme .dashboard-task:hover { transform: none; border-color: var(--primary); }
body.crm-theme .toolbar-card { padding: 16px; }
body.crm-theme .summary-grid { gap: 12px; margin-bottom: 16px; }
body.crm-theme .summary-card { gap: 12px; padding: 12px 16px; min-height: 80px; }
body.crm-theme .summary-icon { width: 32px; height: 32px; flex-basis: 32px; border-radius: 8px; background: var(--bg-body-alt) !important; color: var(--text-secondary) !important; }
body.crm-theme .summary-icon i { font-size: 16px; }
body.crm-theme .summary-card-action.is-selected { border-color: var(--primary); background: var(--primary-gradient-soft); }
body.crm-theme .summary-card-action::after { display: none; }
body.crm-theme .badge.bg-success { background: #24745c !important; }
body.crm-theme .badge.bg-warning { background: #9c681e !important; color: #fff; }
body.crm-theme .badge.bg-danger { background: #b74455 !important; }
body.crm-theme .badge.bg-info { background: #3b6aa0 !important; color: #fff; }
body.crm-theme .summary-mobile-toggle { font-weight: 500; background: var(--bg-card-solid); }
body.crm-theme .section-tabs { gap: 4px; padding: 4px; box-shadow: none; }
body.crm-theme .section-tabs .btn { color: var(--text-secondary); background: transparent; border: 0; border-radius: 8px; }
body.crm-theme .section-tabs .btn.active { color: var(--primary); background: var(--primary-gradient-soft); box-shadow: none; }
body.crm-theme .section-tabs .badge { color: var(--text-secondary); background: var(--bg-body-alt) !important; font-weight: 500; border-radius: 6px; }
body.crm-theme .section-tabs .btn.active .badge { color: var(--primary); background: var(--bg-card-solid) !important; }
body.crm-theme :is(.table-tools, .data-panel-header) { padding: 12px 16px; }
body.crm-theme :is(.table-row-count, .status-pill, .badge) { font-weight: 500; }
body.crm-theme .table { font-variant-numeric: tabular-nums; }
body.crm-theme .table thead th { background: var(--bg-body-alt); color: var(--text-secondary); padding-top: 12px; padding-bottom: 12px; }
body.crm-theme code { background: var(--bg-body-alt); color: var(--text-secondary); border-radius: 4px; }
body.crm-theme .global-search-field { border-radius: 10px; min-height: 44px; box-shadow: none; background: var(--bg-card-solid); }
body.crm-theme .mobile-brand-mark { background: var(--interactive); color: #fff; box-shadow: none; }
body.crm-theme :is(.news-kind-event, .news-kind-update) { color: var(--primary); background: var(--primary-gradient-soft); }
body.crm-theme .news-title-link:hover { color: var(--primary); }
body.crm-theme .news-kind { font-weight: 500; }

/* Compact navigation; keep the existing collapse/drawer behavior. */
body.crm-theme .sidebar { padding-top: 12px; padding-bottom: 12px; }
body.crm-theme .sidebar .nav-link { min-height: 36px; margin: 2px 12px; padding: 8px 12px; gap: 12px; border-radius: 8px; font-size: 13px; font-weight: 400; letter-spacing: 0; transition: var(--transition); }
body.crm-theme .sidebar .nav-link i { width: 18px; flex: 0 0 18px; font-size: 16px; color: inherit; }
body.crm-theme .sidebar .nav-link:hover { background: rgba(255, 255, 255, .06); transform: none; }
body.crm-theme .sidebar .nav-link.active { background: var(--sidebar-active); color: #eef0ff !important; box-shadow: inset 3px 0 #9698ff; font-weight: 500; }
body.crm-theme .sidebar .nav-link.active i { color: #b9baff; }
body.crm-theme .sidebar-user-details .text-muted { color: #aab2c4 !important; font-size: 12px; }
body.crm-theme .sidebar-user-details .fw-semibold { font-weight: 500 !important; }
body.crm-theme .avatar-circle { width: 44px; height: 44px; margin-bottom: 8px; border: 1px solid rgba(255, 255, 255, .14); border-radius: 12px; background: #383b59; color: #dedfff; font-size: 18px; font-weight: 500; box-shadow: none; }
body.crm-theme .avatar-circle:hover { transform: none; box-shadow: none; }
body.crm-theme .avatar-circle img { border-radius: 11px; }
body.crm-theme .sidebar hr { margin-top: 16px; margin-bottom: 16px; }

/* Retain purposeful state changes; remove decorative entrances and hover jumps. */
body.crm-theme .fade-in { animation: none; opacity: 1; }
body.crm-theme :is(.stat-card, .action-card, .report-card, .card-dashboard, .workflow-card, .summary-card, .dashboard-panel, .avatar-circle) { animation: none; transition: var(--transition); }
body.crm-theme :is(.stat-card, .action-card, .report-card, .card-dashboard, .workflow-card):hover { transform: none; box-shadow: var(--shadow-sm); }
body.crm-theme .card-dashboard::before { display: none; }
body.crm-theme :is(.stat-number, .card-dashboard .display-6) { font-weight: 500; letter-spacing: 0; font-variant-numeric: tabular-nums; }
body.crm-theme .card-dashboard .card-title { font-weight: 500; letter-spacing: 0; text-transform: none; }
body.crm-theme :is(.stat-icon, .action-icon, .client-360-avatar, .related-chat-mark, .settings-panel-icon) { background: var(--bg-body-alt); color: var(--text-secondary); box-shadow: none; }
body.crm-theme .client-360-hero { background: var(--bg-card-solid); box-shadow: var(--shadow-sm); }
body.crm-theme .client-360-avatar { border-radius: 12px; font-weight: 500; }
body.crm-theme :focus-visible { outline: 2px solid var(--primary); outline-offset: 3px; }

body.crm-theme.crm-auth { min-height: 100svh; height: auto; padding: 24px; }
body.crm-theme.crm-auth :is(.login-card, .register-card) { padding: 32px; border: 1px solid var(--border-color); border-radius: 16px; background: var(--bg-card-solid); box-shadow: var(--shadow-sm); }
body.crm-theme.crm-auth .auth-brand { margin-bottom: 24px; font-size: 15px; font-weight: 600; color: var(--text-secondary); }
body.crm-theme.crm-auth .auth-brand-mark { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; margin-right: 8px; border-radius: 8px; background: var(--interactive); color: #fff; font-size: 12px; }

@media (min-width: 769px) {
    /* A shared center line for the collapsed rail; no absolute icon offsets. */
    html.sidebar-collapsed body.crm-theme .sidebar { scrollbar-gutter: stable both-edges; }
    html.sidebar-collapsed body.crm-theme .sidebar > :is(.sidebar-collapse-row, .text-center.py-2) { width: var(--sidebar-rail-content, 100%); max-width: var(--sidebar-rail-content, 100%); flex-shrink: 0; }
    html.sidebar-collapsed body.crm-theme .sidebar .nav-link {
        display: grid;
        grid-template-columns: 44px minmax(0, 1fr);
        justify-content: start;
        align-items: center;
        width: calc(100% - 2 * var(--sidebar-rail-inset, 12px));
        min-height: 44px;
        height: 44px;
        padding: 0;
        margin: 4px var(--sidebar-rail-inset, 12px);
        gap: 0;
        flex: 0 0 44px;
    }
    html.sidebar-collapsed body.crm-theme .sidebar .nav-link i,
    html.sidebar-collapsed body.crm-theme .sidebar > .px-3 .btn i {
        position: static;
        inset: auto;
        transform: none;
        width: 20px;
        flex: 0 0 20px;
        margin: 0;
        line-height: 1;
        text-align: center;
        justify-self: center;
    }
    html.sidebar-collapsed body.crm-theme .avatar-circle { width: 40px; height: 40px; margin: 0 auto 8px; }
    html.sidebar-collapsed body.crm-theme #notif-icon { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 32px; }
    html.sidebar-collapsed body.crm-theme .sidebar > .px-3 { padding-inline: 0 !important; }
    html.sidebar-collapsed body.crm-theme .sidebar > .px-3 :is(.btn, .nav-link) { display: grid; grid-template-columns: 44px minmax(0, 1fr); justify-content: start; align-items: center; width: calc(100% - 2 * var(--sidebar-rail-inset, 12px)) !important; height: 44px; padding: 0; margin: 4px var(--sidebar-rail-inset, 12px); }
    html.sidebar-collapsed body.crm-theme .sidebar .nav-link .sidebar-label,
    html.sidebar-collapsed body.crm-theme .sidebar > .px-3 .btn .sidebar-label { position: static; inset: auto; transform: none; padding: 0 12px 0 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; }
    html:not(.sidebar-collapsed) body.crm-theme .sidebar { flex: 0 0 240px; width: 240px; max-width: 240px; }
    html:not(.sidebar-collapsed) body.crm-theme .main-content { flex: 1 1 0; width: calc(100% - 240px); max-width: calc(100% - 240px); }
    body.crm-theme .main-content { padding: 24px; }
}
@media (max-width: 768px) {
    body.crm-theme .main-content { padding: 16px; }
    body.crm-theme .sidebar .nav-link { min-height: 40px; font-size: 14px; }
    body.crm-theme .workspace-header { gap: 12px; margin-bottom: 16px; }
    body.crm-theme :is(h1, .workspace-title) { font-size: 25px; }
    body.crm-theme :is(.card-body, .dashboard-panel) { padding: 16px; }
    body.crm-theme .card-header { padding: 12px 16px; }
    body.crm-theme .summary-card { min-height: 72px; padding: 12px; }
    body.crm-theme .summary-value { font-size: 24px; }
}
/* Bootstrap's default tooltip text follows --bs-body-bg, which is dark here. */
body.crm-theme .tooltip {
    --bs-tooltip-color: #f8f9fc;
    --bs-tooltip-bg: #303540;
    --bs-tooltip-opacity: 1;
}
body.crm-theme .tooltip .tooltip-inner {
    color: #f8f9fc;
    background-color: #303540;
    border: 1px solid #596170;
}

.stock-days-warning { background-color: #765500; color: #fff4cc !important; }
body.dark-theme .stock-days-warning { background-color: #55421c; color: #ffe3a3 !important; }

@media print {
    body.crm-theme .main-content { width: 100%; max-width: 100%; }
}
