:root {
    --ink: #0f172a;
    --muted: #64748b;
    --line: #e2e8f0;
    --surface: #ffffff;
    --canvas: #f1f5f9;
    --primary: #2a5bd7;
    --primary-soft: #eff6ff;
    --success: #059669;
    --warning: #d97706;
    --danger: #dc2626;
    --shadow: 0 18px 50px -30px rgba(15, 23, 42, .35);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
    margin: 0;
    color: var(--ink);
    background: var(--canvas);
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select, textarea { font: inherit; }

.crm-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 248px minmax(0, 1fr);
}

.crm-sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 28px 20px;
    color: #cbd5e1;
    background: linear-gradient(180deg, #101b33, #07101f);
}

.crm-brand {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-bottom: 34px;
    color: white;
    font-size: 1.15rem;
    font-weight: 800;
}

.crm-brand-mark {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border-radius: 13px;
    background: linear-gradient(135deg, #2a5bd7, #0ea5e9);
}

.crm-nav {
    display: grid;
    gap: 8px;
}

.crm-nav button {
    width: 100%;
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 12px 14px;
    color: #94a3b8;
    background: transparent;
    border: 0;
    border-radius: 11px;
    cursor: pointer;
    text-align: left;
}

.crm-nav button:hover,
.crm-nav button.active {
    color: white;
    background: rgba(255,255,255,.09);
}

.crm-sidebar-footer {
    position: absolute;
    right: 20px;
    bottom: 24px;
    left: 20px;
}

.crm-main {
    min-width: 0;
    padding: 30px;
}

.crm-topbar,
.section-heading,
.toolbar,
.modal-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.crm-topbar {
    margin-bottom: 28px;
}

.eyebrow {
    margin: 0 0 5px;
    color: var(--primary);
    font-size: .76rem;
    font-weight: 800;
    letter-spacing: .12em;
    text-transform: uppercase;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.8rem, 3vw, 2.4rem); }
h2 { margin-bottom: 6px; }
.muted { color: var(--muted); }

.btn {
    border: 0;
    border-radius: 10px;
    padding: 10px 15px;
    font-weight: 700;
    cursor: pointer;
}

.btn-primary { color: white; background: var(--primary); }
.btn-secondary { color: var(--ink); background: #e2e8f0; }
.btn-danger { color: white; background: var(--danger); }
.btn-ghost { color: var(--muted); background: transparent; }
.btn-sm { padding: 7px 10px; font-size: .82rem; }
.btn:disabled { opacity: .55; cursor: wait; }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat {
    padding: 20px;
    border: 1px solid var(--line);
    border-radius: 17px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.stat span { display: block; color: var(--muted); font-size: .84rem; }
.stat strong { display: block; margin-top: 6px; font-size: 1.8rem; }

.panel {
    padding: 22px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.section-heading { margin-bottom: 18px; }
.view { display: none; }
.view.active { display: block; }

.toolbar {
    margin-bottom: 16px;
    justify-content: flex-start;
    flex-wrap: wrap;
}

.toolbar input,
.toolbar select,
.field input,
.field select,
.field textarea {
    width: 100%;
    padding: 10px 12px;
    color: var(--ink);
    background: white;
    border: 1px solid #cbd5e1;
    border-radius: 9px;
}

.toolbar input { max-width: 300px; }
.toolbar select { width: auto; min-width: 160px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 13px 11px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-size: .76rem; letter-spacing: .04em; text-transform: uppercase; }
td { font-size: .9rem; }

.badge {
    display: inline-flex;
    padding: 5px 9px;
    border-radius: 999px;
    color: #1e40af;
    background: #dbeafe;
    font-size: .76rem;
    font-weight: 800;
    text-transform: capitalize;
}

.badge.success { color: #065f46; background: #d1fae5; }
.badge.warning { color: #92400e; background: #fef3c7; }
.badge.danger { color: #991b1b; background: #fee2e2; }
.badge.muted { color: #475569; background: #e2e8f0; }

.action-row { display: flex; gap: 6px; align-items: center; }
.empty { padding: 40px 12px; color: var(--muted); text-align: center; }

.login-screen {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(circle at 20% 20%, rgba(14,165,233,.22), transparent 30%),
        linear-gradient(135deg, #111c35, #050b16);
}

.login-card {
    width: min(440px, 100%);
    padding: 34px;
    border-radius: 24px;
    background: white;
    box-shadow: 0 35px 90px -30px rgba(0,0,0,.65);
}

.login-card .crm-brand { color: var(--ink); margin-bottom: 26px; }

.field { display: grid; gap: 7px; margin-bottom: 15px; }
.field label { font-size: .84rem; font-weight: 700; }
.field textarea { min-height: 95px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .span-2 { grid-column: span 2; }

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: none;
    place-items: center;
    padding: 20px;
    background: rgba(2, 6, 23, .66);
}

.modal-backdrop.open { display: grid; }
.modal {
    width: min(680px, 100%);
    max-height: 90vh;
    overflow-y: auto;
    padding: 24px;
    border-radius: 20px;
    background: white;
}

.toast {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 40;
    max-width: 360px;
    padding: 13px 16px;
    color: white;
    background: var(--ink);
    border-radius: 11px;
    box-shadow: var(--shadow);
    transform: translateY(120px);
    opacity: 0;
    transition: .25s ease;
}

.toast.show { transform: translateY(0); opacity: 1; }
.toast.error { background: var(--danger); }

@media (max-width: 1050px) {
    .stats-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
    .crm-shell { display: block; }
    .crm-sidebar { position: static; height: auto; padding: 15px; }
    .crm-brand { margin-bottom: 14px; }
    .crm-nav { display: flex; overflow-x: auto; }
    .crm-nav button { width: auto; white-space: nowrap; }
    .crm-sidebar-footer { position: static; margin-top: 14px; }
    .crm-main { padding: 20px 14px; }
    .crm-topbar { align-items: flex-start; }
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .form-grid { grid-template-columns: 1fr; }
    .form-grid .span-2 { grid-column: auto; }
}
