/* ==========================================================
   Tech Brain CRM — Design System
   Palette:  Navy #12172B (sidebar) / BG #F6F7FB / Indigo #5B5FEF (brand)
             Emerald #16A34A (on-target) / Amber #F59E0B (at risk) / Rose #E11D48 (off-track)
   Type:     Plus Jakarta Sans (nav/headings) / Inter (body) / JetBrains Mono (all numbers)
   ========================================================== */

:root {
    --navy: #12172B;
    --navy-soft: #1B2140;
    --bg: #F6F7FB;
    --surface: #FFFFFF;
    --border: #E7E9F2;
    --text: #1E2233;
    --text-muted: #6B7186;
    --indigo: #5B5FEF;
    --indigo-soft: #EEEEFD;
    --emerald: #16A34A;
    --emerald-soft: #E9F9EF;
    --amber: #F59E0B;
    --amber-soft: #FFF6E5;
    --rose: #E11D48;
    --rose-soft: #FDECEF;
    --blue: #3B82F6;
    --blue-soft: #EAF2FE;
    --radius: 12px;
    --shadow: 0 1px 2px rgba(18,23,43,.04), 0 4px 16px rgba(18,23,43,.06);
    --sidebar-w: 260px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 14.5px;
    line-height: 1.5;
}

h1, h2, h3, h4, .brand, .nav-link, .stat-label, .section-title {
    font-family: 'Plus Jakarta Sans', 'Inter', sans-serif;
}

.mono, .stat-value, .money, td.num, .kpi-num {
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-variant-numeric: tabular-nums;
}

a { color: var(--indigo); text-decoration: none; }
a:hover { text-decoration: underline; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #D7DAE8; border-radius: 8px; }

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
    width: var(--sidebar-w);
    background: var(--navy);
    color: #C7CAE8;
    position: fixed;
    top: 0; bottom: 0; left: 0;
    display: flex;
    flex-direction: column;
    z-index: 40;
    transition: transform .25s ease;
}
.sidebar-brand {
    display: flex; align-items: center; gap: 10px;
    padding: 20px 20px 16px;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-brand .logo-mark {
    width: 34px; height: 34px; border-radius: 9px;
    background: linear-gradient(135deg, var(--indigo), #8B8FF8);
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-weight: 700; font-family: 'Plus Jakarta Sans', sans-serif;
    flex-shrink: 0;
}
.sidebar-brand .brand { color: #fff; font-weight: 700; font-size: 16px; }
.sidebar-brand .brand small { display: block; color: #8B90B8; font-weight: 400; font-size: 11px; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 14px 12px; }
.nav-section-label {
    font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em;
    color: #5F6590; margin: 18px 10px 8px; font-weight: 600;
}
.nav-section-label:first-child { margin-top: 4px; }

.nav-link {
    display: flex; align-items: center; gap: 11px;
    padding: 9px 12px; border-radius: 9px;
    color: #C7CAE8; font-size: 13.5px; font-weight: 500;
    margin-bottom: 2px; cursor: pointer;
}
.nav-link i { width: 18px; text-align: center; font-size: 15px; opacity: .85; }
.nav-link:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav-link.active { background: var(--indigo); color: #fff; }
.nav-link.active i { opacity: 1; }
.nav-link .badge-count {
    margin-left: auto; background: rgba(255,255,255,.12);
    padding: 1px 7px; border-radius: 20px; font-size: 11px;
}

.sidebar-user {
    padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.08);
    display: flex; align-items: center; gap: 10px;
}
.sidebar-user .avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--indigo-soft); color: var(--indigo);
    display: flex; align-items: center; justify-content: center; font-weight: 700;
    flex-shrink: 0;
}
.sidebar-user .uname { color: #fff; font-size: 13px; font-weight: 600; }
.sidebar-user .urole { color: #8B90B8; font-size: 11px; }
.sidebar-user a.logout { margin-left: auto; color: #8B90B8; font-size: 16px; }

/* ---------- Main content ---------- */
.main {
    margin-left: var(--sidebar-w);
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}
.topbar {
    height: 64px; background: var(--surface); border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 24px; position: sticky; top: 0; z-index: 30;
}
.topbar .page-title { font-size: 17px; font-weight: 700; }
.topbar .page-subtitle { font-size: 12px; color: var(--text-muted); font-weight: 400; }
.hamburger {
    display: none; background: none; border: none; font-size: 20px;
    color: var(--text); cursor: pointer; margin-right: 12px;
}
.topbar-actions { display: flex; align-items: center; gap: 14px; }

.content { padding: 22px 24px 60px; }

/* ---------- Cards & stat tiles ---------- */
.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-body { padding: 18px 20px; }
.card-header {
    padding: 16px 20px; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
}
.section-title { font-size: 15px; font-weight: 700; margin: 0; }

.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }

.stat-tile {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 16px 18px; box-shadow: var(--shadow);
}
.stat-tile .stat-label { font-size: 12px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.stat-tile .stat-value { font-size: 24px; font-weight: 700; margin-top: 6px; }
.stat-tile .stat-delta { font-size: 12px; margin-top: 4px; font-weight: 600; }
.stat-tile .stat-delta.up { color: var(--emerald); }
.stat-tile .stat-delta.down { color: var(--rose); }
.stat-tile.accent-indigo { border-top: 3px solid var(--indigo); }
.stat-tile.accent-emerald { border-top: 3px solid var(--emerald); }
.stat-tile.accent-amber { border-top: 3px solid var(--amber); }
.stat-tile.accent-rose { border-top: 3px solid var(--rose); }

/* ---------- Run-rate bar (signature element) ---------- */
.runrate {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 18px 20px; box-shadow: var(--shadow);
}
.runrate-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.runrate-head .label { font-size: 12px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.runrate-head .pct { font-size: 20px; font-weight: 700; }
.runrate-track { height: 10px; background: #EEF0F7; border-radius: 20px; overflow: hidden; position: relative; }
.runrate-fill { height: 100%; border-radius: 20px; background: linear-gradient(90deg, var(--indigo), #8B8FF8); transition: width .4s ease; }
.runrate-fill.status-good { background: linear-gradient(90deg, #16A34A, #4ADE80); }
.runrate-fill.status-warn { background: linear-gradient(90deg, #F59E0B, #FBBF24); }
.runrate-fill.status-bad  { background: linear-gradient(90deg, #E11D48, #FB7185); }
.runrate-foot { display: flex; justify-content: space-between; margin-top: 8px; font-size: 12px; color: var(--text-muted); }
.runrate-foot .mono { color: var(--text); font-weight: 600; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 9px 16px; border-radius: 9px; border: 1px solid transparent;
    font-size: 13.5px; font-weight: 600; cursor: pointer; font-family: inherit;
}
.btn-primary { background: var(--indigo); color: #fff; }
.btn-primary:hover { background: #4A4EDB; text-decoration: none; color: #fff; }
.btn-secondary { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-secondary:hover { background: #F1F2F8; text-decoration: none; }
.btn-danger { background: var(--rose-soft); color: var(--rose); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-icon { padding: 8px; }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 16px; }
label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.form-control, select.form-control, textarea.form-control {
    width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px;
    font-size: 13.5px; font-family: inherit; background: var(--surface); color: var(--text);
}
.form-control:focus { outline: none; border-color: var(--indigo); box-shadow: 0 0 0 3px var(--indigo-soft); }
.form-hint { font-size: 11.5px; color: var(--text-muted); margin-top: 4px; }
.form-row { display: flex; gap: 14px; flex-wrap: wrap; }
.form-row > .form-group { flex: 1; min-width: 200px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data-table th {
    text-align: left; padding: 10px 14px; background: #FAFBFD; color: var(--text-muted);
    font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em;
    border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.data-table td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data-table tbody tr:hover { background: #FAFBFF; }
table.data-table td.num { text-align: right; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 700; }
.badge-slate  { background: #F1F2F8; color: #556; }
.badge-blue   { background: var(--blue-soft); color: var(--blue); }
.badge-indigo { background: var(--indigo-soft); color: var(--indigo); }
.badge-green  { background: var(--emerald-soft); color: var(--emerald); }
.badge-amber  { background: var(--amber-soft); color: #B45309; }
.badge-rose   { background: var(--rose-soft); color: var(--rose); }

/* ---------- Kanban (pipeline) ---------- */
.kanban { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 12px; }
.kanban-col { min-width: 270px; max-width: 270px; background: #F1F2F8; border-radius: var(--radius); padding: 10px; flex-shrink: 0; }
.kanban-col-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 6px 10px; }
.kanban-col-head .name { font-weight: 700; font-size: 13px; display: flex; align-items: center; gap: 7px; }
.kanban-col-head .dot { width: 9px; height: 9px; border-radius: 50%; }
.kanban-col-head .count { font-size: 11px; color: var(--text-muted); background: #fff; padding: 1px 8px; border-radius: 20px; }
.kanban-col-total { font-size: 11px; color: var(--text-muted); padding: 0 6px 8px; }
.kanban-card {
    background: var(--surface); border-radius: 9px; padding: 12px; margin-bottom: 8px;
    box-shadow: var(--shadow); cursor: grab; border: 1px solid var(--border);
}
.kanban-card.dragging { opacity: .4; }
.kanban-col.drag-over { background: var(--indigo-soft); }
.kanban-card .opp-name { font-weight: 700; font-size: 13px; margin-bottom: 4px; }
.kanban-card .opp-account { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }
.kanban-card .opp-amount { font-size: 14px; font-weight: 700; color: var(--indigo); }
.kanban-card .opp-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; font-size: 11px; color: var(--text-muted); }

/* ---------- Empty states ---------- */
.empty-state { text-align: center; padding: 50px 20px; color: var(--text-muted); }
.empty-state i { font-size: 34px; color: #D7DAE8; margin-bottom: 12px; display: block; }
.empty-state h4 { color: var(--text); margin: 0 0 6px; }

/* ---------- Alerts / flash ---------- */
.alert { padding: 12px 16px; border-radius: 9px; font-size: 13.5px; margin-bottom: 16px; display: flex; align-items: center; gap: 9px; }
.alert-success { background: var(--emerald-soft); color: #15803D; }
.alert-error { background: var(--rose-soft); color: #BE123C; }

/* ---------- Modal ---------- */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(18,23,43,.45);
    display: none; align-items: center; justify-content: center; z-index: 100; padding: 16px;
}
.modal-backdrop.open { display: flex; }
.modal-box { background: #fff; border-radius: var(--radius); width: 100%; max-width: 420px; padding: 22px; }

/* ---------- Mobile ---------- */
.sidebar-overlay { display: none; }

@media (max-width: 960px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main { margin-left: 0; }
    .hamburger { display: inline-flex; }
    .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr 1fr; }
    .sidebar-overlay {
        display: block; position: fixed; inset: 0; background: rgba(18,23,43,.4);
        z-index: 39; opacity: 0; pointer-events: none; transition: opacity .2s;
    }
    .sidebar-overlay.open { opacity: 1; pointer-events: auto; }
}

@media (max-width: 640px) {
    .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
    .content { padding: 16px; }
    .topbar { padding: 0 14px; }
    .form-row { flex-direction: column; }
}
