:root {
    --crm-primary: var(--primary, #4f46e5);
    --crm-primary-dark: var(--primary-strong, #4338ca);
    --crm-accent: var(--warning, #f59e0b);
    --crm-surface: var(--surface, #ffffff);
    --crm-sidebar: var(--sidebar-bg, #132238);
    --crm-sidebar-muted: var(--sidebar-muted, #94a3b8);
    --crm-sidebar-text: var(--sidebar-text, #f8fafc);
    --crm-sidebar-active: var(--sidebar-active, #ffffff);
    --crm-sidebar-active-bg: var(--sidebar-active-bg, rgba(79, 70, 229, 0.22));
    --crm-text: var(--text, #1b1f2d);
    --crm-bg: var(--bg, #f7f8fb);
    --crm-border: var(--border, #e5e7eb);
    --crm-soft-surface: var(--soft-surface, #eef2ff);
    --crm-soft-surface-strong: var(--soft-surface-strong, #e3e9ff);
    --crm-hover-surface: var(--hover-surface, #f4f6fb);
    --crm-shadow: var(--shadow, 0 12px 30px rgba(15, 23, 42, 0.08));
    --crm-shadow-lg: var(--shadow-lg, 0 18px 44px rgba(15, 23, 42, 0.12));
    --crm-focus-ring: var(--focus-ring, rgba(79, 70, 229, 0.18));
}

body {
    background: var(--crm-bg);
    color: var(--crm-text);
    font-family: var(--font-family, "Segoe UI", Tahoma, Geneva, Verdana, sans-serif);
}

a {
    color: var(--crm-primary);
    text-decoration: none;
}

a:hover {
    color: var(--crm-primary-dark);
}

.text-muted {
    color: var(--muted, #6b7280) !important;
}

.form-label,
label,
thead th {
    color: var(--crm-text);
}

.auth-body {
    min-height: 100vh;
    background:
        radial-gradient(circle at top right, var(--auth-glow-warm, rgba(245, 158, 11, 0.18)), transparent 28%),
        radial-gradient(circle at bottom left, var(--auth-glow-cool, rgba(79, 70, 229, 0.16)), transparent 32%),
        var(--crm-bg);
}

.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.auth-card {
    width: min(960px, 100%);
    border-radius: 1.5rem;
    overflow: hidden;
    border: 1px solid color-mix(in srgb, var(--crm-border) 88%, white 12%);
    background: color-mix(in srgb, var(--crm-surface) 96%, transparent 4%);
    box-shadow: var(--crm-shadow-lg);
    display: grid;
    grid-template-columns: 1fr 1fr;
}

.auth-brand {
    padding: 3rem;
    background: linear-gradient(145deg, var(--auth-panel-start, #2b3e73), var(--auth-panel-end, #1f2a44));
    color: #fff;
    display: flex;
    align-items: end;
}

.auth-content {
    padding: 3rem;
    background: var(--crm-surface);
}

.crm-shell {
    min-height: 100vh;
    display: flex;
    background: var(--crm-bg);
}

.crm-sidebar {
    width: 280px;
    background: linear-gradient(180deg, var(--crm-sidebar) 0%, var(--sidebar-bg-strong, #0d1a2d) 100%);
    color: var(--crm-sidebar-text);
    padding: 1.5rem 1rem;
    position: fixed;
    inset: 0 auto 0 0;
    overflow-y: auto;
    border-right: 1px solid color-mix(in srgb, var(--crm-sidebar-text) 8%, transparent 92%);
    box-shadow: 14px 0 36px color-mix(in srgb, var(--crm-sidebar) 28%, transparent 72%);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    margin-bottom: 2rem;
}

.brand-mark {
    width: 52px;
    height: 52px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    letter-spacing: 0.04em;
    box-shadow: 0 14px 26px color-mix(in srgb, var(--crm-primary) 24%, transparent 76%);
}

.brand-title {
    color: var(--crm-sidebar-text);
    font-weight: 700;
    letter-spacing: 0.03em;
}

.sidebar-brand .text-muted {
    color: var(--crm-sidebar-muted) !important;
}

.sidebar-nav .nav-link {
    color: var(--crm-sidebar-muted);
    border-radius: 0.95rem;
    padding: 0.85rem 1rem;
    margin-bottom: 0.3rem;
    display: flex;
    align-items: center;
    gap: 0.65rem;
    font-weight: 500;
    border: 1px solid transparent;
    transition: background-color 0.18s ease, color 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}

.sidebar-nav .nav-link:hover,
.sidebar-nav .nav-link.active {
    color: var(--crm-sidebar-active);
    background: var(--crm-sidebar-active-bg);
    border-color: color-mix(in srgb, var(--crm-sidebar-active) 10%, transparent 90%);
}

.crm-main {
    width: 100%;
    margin-left: 280px;
    min-height: 100vh;
}

.crm-topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    background: color-mix(in srgb, var(--crm-surface) 88%, transparent 12%);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid color-mix(in srgb, var(--crm-border) 82%, white 18%);
    box-shadow: 0 8px 24px color-mix(in srgb, var(--crm-text) 5%, transparent 95%);
    padding: 1rem 1.5rem;
    margin-left: 0;
}

.crm-topbar .btn-light {
    background: var(--crm-surface);
    border: 1px solid var(--crm-border);
    color: var(--crm-text);
}

.crm-topbar .btn-light:hover {
    background: var(--crm-hover-surface);
    border-color: color-mix(in srgb, var(--crm-primary) 18%, var(--crm-border) 82%);
    color: var(--crm-primary);
}

.crm-topbar .btn-outline-secondary {
    color: var(--crm-text);
    border-color: var(--crm-border);
}

.crm-topbar .btn-outline-secondary:hover {
    background: var(--crm-hover-surface);
    border-color: color-mix(in srgb, var(--crm-primary) 24%, var(--crm-border) 76%);
    color: var(--crm-primary);
}

.dropdown-menu {
    border: 1px solid var(--crm-border);
    border-radius: 14px;
    padding: 0.45rem;
    box-shadow: var(--crm-shadow);
}

.dropdown-item {
    border-radius: 10px;
    color: var(--crm-text);
}

.dropdown-item:hover,
.dropdown-item:focus {
    background: var(--crm-hover-surface);
    color: var(--crm-primary);
}

.page-title {
    font-size: 1.45rem;
    font-weight: 700;
    color: var(--crm-text);
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.dashboard-card,
.content-card {
    border: 1px solid var(--crm-border);
    border-radius: 1.2rem;
    background: var(--crm-surface);
    box-shadow: var(--crm-shadow);
}

.dashboard-card {
    position: relative;
    overflow: hidden;
}

.dashboard-card::before {
    content: "";
    position: absolute;
    inset: 0 0 auto 0;
    height: 4px;
    background: linear-gradient(90deg, var(--crm-primary), color-mix(in srgb, var(--crm-primary) 58%, var(--crm-accent) 42%));
}

.dashboard-card .card-body {
    min-height: 164px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 0.85rem;
}

.dashboard-card .icon-wrap {
    width: 52px;
    height: 52px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--crm-soft-surface-strong);
    border: 1px solid color-mix(in srgb, var(--crm-primary) 12%, transparent 88%);
    color: var(--crm-primary);
    font-size: 1.2rem;
}

.dashboard-card .quick-actions,
.dashboard-card .quick-actions > * {
    position: relative;
    z-index: 2;
}

.dashboard-card .quick-actions .btn-soft {
    font-weight: 600;
}

.kpi-label {
    letter-spacing: 0.03em;
    color: var(--crm-text) !important;
}

.kpi-caption {
    color: var(--muted, #6b7280) !important;
}

.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.table > :not(caption) > * > * {
    padding: 0.95rem 0.85rem;
    vertical-align: middle;
    border-bottom-color: color-mix(in srgb, var(--crm-border) 86%, transparent 14%);
}

.table tbody tr:hover {
    background: var(--crm-hover-surface);
}

.form-control,
.form-select,
textarea,
input,
select {
    color: var(--crm-text);
    background-color: var(--crm-surface);
    border-color: var(--crm-border);
}

.form-control::placeholder,
textarea::placeholder {
    color: var(--muted, #6b7280);
}

.form-control:focus,
.form-select:focus,
textarea:focus,
input:focus,
select:focus {
    color: var(--crm-text);
    background-color: var(--crm-surface);
    border-color: color-mix(in srgb, var(--crm-primary) 42%, var(--crm-border) 58%);
    box-shadow: 0 0 0 0.24rem var(--crm-focus-ring);
}

.form-check-input:checked {
    background-color: var(--crm-primary);
    border-color: var(--crm-primary);
}

.btn-light {
    background: var(--crm-surface);
    border: 1px solid var(--crm-border);
    color: var(--crm-text);
}

.btn-light:hover {
    background: var(--crm-hover-surface);
    border-color: color-mix(in srgb, var(--crm-primary) 18%, var(--crm-border) 82%);
    color: var(--crm-primary);
}

.btn-outline-secondary {
    color: var(--crm-text);
    border-color: var(--crm-border);
}

.btn-outline-secondary:hover {
    background: var(--crm-hover-surface);
    border-color: color-mix(in srgb, var(--crm-primary) 24%, var(--crm-border) 76%);
    color: var(--crm-primary);
}

.stat-number {
    font-size: 1.9rem;
    font-weight: 700;
    color: var(--crm-text);
}

.card-link {
    text-decoration: none;
    color: inherit;
}

.card-link:hover {
    text-decoration: none;
}

.card.dashboard-card {
    cursor: pointer;
}

.card.dashboard-card .quick-actions {
    opacity: 0;
    transition: opacity 0.15s ease;
}

.card.dashboard-card:hover .quick-actions {
    opacity: 1;
}

.timeline {
    position: relative;
    padding-left: 1.25rem;
}

.dashboard-card .text-muted,
.content-card .text-muted {
    color: var(--muted, #6b7280) !important;
}

.timeline::before {
    content: "";
    position: absolute;
    left: 0.35rem;
    top: 0;
    bottom: 0;
    width: 2px;
    background: linear-gradient(180deg, var(--crm-soft-surface-strong), color-mix(in srgb, var(--crm-primary) 24%, transparent 76%));
}

.timeline-item {
    position: relative;
    margin-bottom: 1rem;
    padding-left: 1rem;
}

.timeline-item::before {
    content: "";
    position: absolute;
    left: -0.02rem;
    top: 0.35rem;
    width: 10px;
    height: 10px;
    background: var(--crm-primary);
    border-radius: 50%;
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--crm-primary) 12%, transparent 88%);
}

.badge-soft {
    display: inline-flex;
    align-items: center;
    padding: 0.35rem 0.65rem;
    background: var(--crm-soft-surface-strong);
    color: var(--crm-primary-dark);
    border: 1px solid color-mix(in srgb, var(--crm-primary) 12%, transparent 88%);
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
}

.dashboard-card-link {
    z-index: 1;
}

/* Theme engine helpers */
.btn-soft { border-radius: 10px; }
.btn-gradient { color: #fff; }
.tiny { font-size: 12px; }
.theme-animated * { transition: color .25s ease, background-color .25s ease, border-color .25s ease, box-shadow .25s ease; }
.lift { transition: transform .18s ease, box-shadow .18s ease; }
.lift:hover { transform: translateY(-2px); }
.sidebar-collapsed .crm-sidebar { width: 80px; }
.sidebar-icon .crm-sidebar { width: 72px; }
.sidebar-floating .crm-main { margin-left: 260px; }
.theme-tile .bi-check-circle-fill { opacity: .8; }
.table-theme th { color: var(--muted); font-weight: 600; }
.table-theme tr:hover { background: var(--crm-hover-surface); }
.placeholder {
    min-height: 10px;
    background: linear-gradient(90deg, color-mix(in srgb, var(--crm-border) 72%, white 28%) 25%, var(--crm-hover-surface) 50%, color-mix(in srgb, var(--crm-border) 72%, white 28%) 75%);
    background-size: 200% 100%;
    animation: placeholder 1.4s ease infinite;
    border-radius: 10px;
}
.placeholder-wave .placeholder { border-radius: 10px; }
@keyframes placeholder { 0% { background-position: 200% 0;} 100% { background-position: -200% 0;} }

@media (max-width: 991.98px) {
    .auth-card {
        grid-template-columns: 1fr;
    }

    .crm-sidebar {
        position: static;
        width: 100%;
    }

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

    .crm-shell {
        flex-direction: column;
    }
}

@media (max-width: 768px) {
    .crm-sidebar {
        display: none;
    }
    .crm-main {
        margin-left: 0;
    }
}
