/* ===== CRM Base ===== */
:root {
    --crm-primary: #4f46e5;
    --crm-primary-hover: #4338ca;
    --crm-sidebar-bg: #0f172a;
    --crm-sidebar-text: #94a3b8;
    --crm-sidebar-active: #4f46e5;
    --crm-sidebar-width: 240px;
    --crm-topbar-h: 52px;
    --crm-bg: #f1f5f9;
    --crm-card-bg: #ffffff;
    --crm-border: #e2e8f0;
    --crm-text: #1e293b;
    --crm-muted: #64748b;
    --crm-radius: 10px;
    --crm-shadow: 0 1px 4px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.04);
}

html, body {
    font-family: 'Inter', 'Segoe UI', Helvetica, Arial, sans-serif;
    background: var(--crm-bg);
    color: var(--crm-text);
    height: 100%;
    margin: 0;
}

/* ===== Layout ===== */
.crm-layout {
    display: flex;
    min-height: 100vh;
}

.crm-sidebar {
    width: var(--crm-sidebar-width);
    background: var(--crm-sidebar-bg);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    overflow-y: auto;
}

.crm-main {
    flex: 1;
    margin-left: var(--crm-sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.crm-topbar {
    height: var(--crm-topbar-h);
    background: var(--crm-card-bg);
    border-bottom: 1px solid var(--crm-border);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,.05);
    position: sticky;
    top: 0;
    z-index: 50;
}

.crm-content {
    padding: 1.5rem;
    flex: 1;
}

/* ===== Sidebar ===== */
.sidebar-brand {
    padding: 1.25rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,.08);
}

.brand-link {
    display: flex;
    align-items: center;
    gap: .625rem;
    text-decoration: none;
    color: #fff;
}

.brand-icon {
    font-size: 1.5rem;
    color: var(--crm-primary);
}

.brand-name {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: .5px;
}

.sidebar-nav {
    padding: 1rem .75rem;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-section-label {
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: #475569;
    padding: .5rem .5rem .25rem;
    font-weight: 600;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .55rem .75rem;
    border-radius: 7px;
    color: var(--crm-sidebar-text);
    text-decoration: none;
    font-size: .875rem;
    transition: background .15s, color .15s;
    border: none;
    background: none;
    cursor: pointer;
    width: 100%;
    text-align: left;
}

.sidebar-link i { font-size: 1rem; min-width: 1.1rem; }

.sidebar-link:hover {
    background: rgba(255,255,255,.07);
    color: #fff;
}

.sidebar-link.active {
    background: var(--crm-primary);
    color: #fff;
}

.sidebar-logout { color: #f87171 !important; }
.sidebar-logout:hover { background: rgba(248,113,113,.1) !important; }

/* Hide checkbox toggler */
.navbar-toggler { display: none; }
.nav-toggle-label { display: none; }

/* ===== Page header ===== */
.crm-page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: .75rem;
}

.crm-title {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--crm-text);
    display: flex;
    align-items: center;
    gap: .5rem;
    margin: 0;
}

/* ===== Card ===== */
.crm-card {
    background: var(--crm-card-bg);
    border-radius: var(--crm-radius);
    box-shadow: var(--crm-shadow);
    padding: 1.25rem;
    border: 1px solid var(--crm-border);
}

.crm-section-title {
    font-weight: 600;
    font-size: .85rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--crm-muted);
    margin-bottom: .75rem;
}

/* ===== Stats ===== */
.crm-stat-card {
    background: var(--crm-card-bg);
    border-radius: var(--crm-radius);
    box-shadow: var(--crm-shadow);
    border: 1px solid var(--crm-border);
    padding: 1.1rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.crm-stat-icon {
    width: 48px; height: 48px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    font-size: 1.3rem;
    flex-shrink: 0;
}

.crm-stat-value { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.crm-stat-label { font-size: .8rem; color: var(--crm-muted); }

/* ===== Table ===== */
.crm-table {
    font-size: .875rem;
    margin: 0;
}

.crm-table thead th {
    font-weight: 600;
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--crm-muted);
    border-bottom: 2px solid var(--crm-border);
    padding: .6rem .75rem;
    background: transparent;
}

.crm-table tbody td {
    padding: .65rem .75rem;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
}

.crm-table tbody tr:last-child td { border-bottom: none; }
.crm-table tbody tr:hover td { background: #f8fafc; }

/* ===== Badges ===== */
.crm-badge {
    display: inline-flex; align-items: center;
    padding: .2rem .55rem;
    border-radius: 20px;
    font-size: .72rem;
    font-weight: 600;
    background: #e0e7ff;
    color: #4338ca;
}

.crm-badge-success { background: #dcfce7; color: #16a34a; }
.crm-badge-warning { background: #fef9c3; color: #b45309; }
.crm-badge-danger  { background: #fee2e2; color: #dc2626; }
.crm-badge-muted   { background: #f1f5f9; color: #64748b; }

/* ===== Buttons ===== */
.crm-btn-primary {
    background: var(--crm-primary);
    color: #fff;
    border: none;
    border-radius: 7px;
    padding: .45rem 1rem;
    font-size: .875rem;
    font-weight: 500;
    transition: background .15s;
    display: inline-flex; align-items: center;
}
.crm-btn-primary:hover { background: var(--crm-primary-hover); color: #fff; }
.crm-btn-primary:disabled { opacity: .65; }

.crm-btn-outline {
    background: transparent;
    color: var(--crm-primary);
    border: 1.5px solid var(--crm-primary);
    border-radius: 7px;
    padding: .45rem 1rem;
    font-size: .875rem;
    font-weight: 500;
    transition: all .15s;
    display: inline-flex; align-items: center;
    text-decoration: none;
}
.crm-btn-outline:hover { background: var(--crm-primary); color: #fff; }

.crm-btn-latest {
    background: #fff;
    color: #b45309;
    border: 1.5px solid #fde68a;
    border-radius: 7px;
    padding: .35rem .7rem;
    font-size: .8rem;
    font-weight: 600;
    transition: all .15s;
    display: inline-flex;
    align-items: center;
}
.crm-btn-latest:hover {
    background: #f59e0b;
    color: #fff;
    border-color: #f59e0b;
}

.crm-btn-danger {
    background: #fff;
    color: #dc2626;
    border: 1.5px solid #fecaca;
    border-radius: 7px;
    padding: .35rem .7rem;
    font-size: .8rem;
    font-weight: 600;
    transition: all .15s;
    display: inline-flex;
    align-items: center;
}
.crm-btn-danger:hover {
    background: #dc2626;
    color: #fff;
    border-color: #dc2626;
}

.crm-btn-action {
    border-radius: 999px;
    padding: .35rem .75rem;
    font-size: .78rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    border: 1px solid transparent;
    transition: all .15s ease;
    text-decoration: none;
}

.crm-btn-action-edit {
    background: #eef2ff;
    color: #4338ca;
    border-color: #c7d2fe;
}

.crm-btn-action-edit:hover {
    background: #4f46e5;
    color: #fff;
    border-color: #4f46e5;
}

.crm-btn-action-delete {
    background: #fff1f2;
    color: #be123c;
    border-color: #fecdd3;
}

.crm-btn-action-delete:hover {
    background: #e11d48;
    color: #fff;
    border-color: #e11d48;
}

/* ===== Search ===== */
.crm-search {
    border-radius: 8px;
    border: 1.5px solid var(--crm-border);
    padding: .5rem 1rem;
    font-size: .875rem;
}
.crm-search:focus { border-color: var(--crm-primary); box-shadow: 0 0 0 3px rgba(79,70,229,.1); }

/* ===== Info rows ===== */
.crm-info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: .35rem 0;
    border-bottom: 1px solid #f1f5f9;
    font-size: .875rem;
}
.crm-info-row:last-child { border-bottom: none; }
.crm-info-row > span:first-child { color: var(--crm-muted); min-width: 90px; }

/* ===== Link ===== */
.crm-link { color: var(--crm-primary); text-decoration: none; font-weight: 500; }
.crm-link:hover { text-decoration: underline; }

/* ===== Loading / Empty ===== */
.crm-loading {
    display: flex; align-items: center; gap: .75rem;
    padding: 2rem; color: var(--crm-muted);
}
.crm-spinner { color: var(--crm-primary); }

.crm-empty {
    text-align: center; padding: 3rem;
    color: var(--crm-muted);
}
.crm-empty-icon { font-size: 3rem; display: block; margin-bottom: .75rem; }
.crm-empty-small { color: var(--crm-muted); font-size: .875rem; display: flex; align-items: center; gap: .5rem; }

/* ===== Modal ===== */
.crm-modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(15,23,42,.5);
    z-index: 1000;
    display: flex; align-items: center; justify-content: center;
    backdrop-filter: blur(2px);
}
.crm-modal {
    background: var(--crm-card-bg);
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0,0,0,.2);
    padding: 1.75rem;
    max-width: 480px;
    width: 90%;
    animation: slideUp .2s ease;
}
@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}

/* ===== API block ===== */
.crm-api-block {
    background: #0f172a;
    border-radius: 8px;
    padding: .875rem 1rem;
    color: #94a3b8;
    font-size: .82rem;
}
.crm-api-row {
    display: flex; align-items: center; gap: .5rem; margin-bottom: .3rem;
}
.crm-method {
    background: #1e3a5f;
    color: #60a5fa;
    padding: .1rem .4rem;
    border-radius: 4px;
    font-size: .7rem;
    font-weight: 700;
}
.crm-api-block code { color: #a5f3fc; }

/* ===== License active ===== */
.crm-license-active { background: #f0fdf4; border-radius: 8px; padding: .75rem; }

/* ===== Forms ===== */
.form-control:focus, .form-select:focus {
    border-color: var(--crm-primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,.12);
}

.crm-json-editor {
    font-family: "JetBrains Mono", "Cascadia Mono", Consolas, "Courier New", monospace;
    font-size: .84rem;
    line-height: 1.45;
    background: #0f172a;
    color: #e2e8f0;
    border: 1px solid #334155;
    border-radius: 10px;
    white-space: pre;
    tab-size: 2;
}

.crm-json-editor:focus {
    background: #0f172a;
    color: #f8fafc;
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99,102,241,.2);
}

/* ===== Error UI ===== */
#blazor-error-ui {
    background: #fef2f2;
    border-top: 2px solid #dc2626;
    color: #dc2626;
    padding: .75rem 1.5rem;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 9999;
}
#blazor-error-ui .reload { color: var(--crm-primary); text-decoration: underline; }
#blazor-error-ui .dismiss { margin-left: auto; cursor: pointer; font-size: 1.1rem; }
/* ===== Responsive ===== */
@media (max-width: 768px) {
    .crm-sidebar { transform: translateX(-100%); transition: transform .25s; }
    .crm-main { margin-left: 0; }
    .nav-toggle-btn { cursor: pointer; }
}

/* Form controls base */
.valid.modified:not([type=checkbox]) { outline: 1px solid #16a34a; }
.invalid { outline: 1px solid #dc2626; }
.validation-message { color: #dc2626; font-size: .8rem; }
/* ===== Revenue Chart ===== */
.crm-revenue-chart {
    display: flex;
    flex-direction: column;
    gap: .45rem;
}

.crm-revenue-row {
    display: grid;
    grid-template-columns: 70px 1fr 90px;
    gap: .6rem;
    align-items: center;
}

.crm-revenue-label {
    font-size: .75rem;
    color: var(--crm-muted);
    text-align: right;
}

.crm-revenue-bar-wrap {
    height: 12px;
    background: #e2e8f0;
    border-radius: 999px;
    overflow: hidden;
}

.crm-revenue-bar {
    height: 100%;
    background: linear-gradient(90deg, #4f46e5, #22c55e);
    border-radius: 999px;
}

.crm-revenue-value {
    font-size: .75rem;
    font-weight: 600;
    color: var(--crm-text);
    text-align: right;
}