/* =========================================================
   Lead CRM — Design System
   Display: Space Grotesk | Body: Inter | Data/Mono: IBM Plex Mono
   ========================================================= */

@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=Inter:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

:root {
    --navy-900: #0E1930;
    --navy-800: #16233F;
    --navy-700: #202F52;
    --bg: #F3F5F9;
    --surface: #FFFFFF;
    --border: #E4E8F0;
    --text: #16213A;
    --text-muted: #6C7690;
    --accent: #2F6FED;
    --accent-dark: #1E52C4;
    --accent-soft: #E9F0FF;

    --stage-new: #8892A6;
    --stage-contacted: #2F6FED;
    --stage-qualified: #7B61FF;
    --stage-proposal: #E8A33D;
    --stage-negotiation: #F2784B;
    --stage-won: #16B378;
    --stage-lost: #B23A55;

    --radius: 10px;
    --shadow: 0 1px 2px rgba(14, 25, 48, 0.06), 0 4px 16px rgba(14, 25, 48, 0.04);
}

* { box-sizing: border-box; }

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

h1, h2, h3, h4 {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 600;
    color: var(--navy-900);
    margin: 0 0 4px;
}

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

.mono { font-family: 'IBM Plex Mono', monospace; }

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

.sidebar {
    width: 232px;
    flex-shrink: 0;
    background: var(--navy-900);
    color: #B9C2DA;
    display: flex;
    flex-direction: column;
    padding: 22px 16px;
}

.sidebar .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 8px 22px;
    color: #fff;
}

.sidebar .brand .mark {
    width: 30px; height: 30px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--accent), #7B61FF);
    display: flex; align-items: center; justify-content: center;
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: 15px;
}

.sidebar .brand span { font-family: 'Space Grotesk', sans-serif; font-weight: 600; font-size: 16px; }

.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }

.sidebar .nav-label {
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: #5C6892;
    font-weight: 700;
    padding: 14px 12px 6px;
}
.sidebar .nav-label:first-child { padding-top: 4px; }

.sidebar nav a {
    color: #B9C2DA;
    text-decoration: none;
    padding: 9px 12px;
    border-radius: 8px;
    font-weight: 500;
    font-size: 13.5px;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: background .15s, color .15s;
}

.sidebar nav a svg { width: 16px; height: 16px; flex-shrink: 0; opacity: .85; }
.sidebar nav a:hover { background: var(--navy-800); color: #fff; }
.sidebar nav a:hover svg { opacity: 1; }
.sidebar nav a.active { background: var(--accent); color: #fff; box-shadow: 0 2px 8px rgba(47,111,237,.35); }
.sidebar nav a.active svg { opacity: 1; }
.sidebar nav a.nav-cta { color: #fff; background: var(--navy-800); margin-top: 4px; border: 1px dashed #34426B; }
.sidebar nav a.nav-cta:hover { border-color: var(--accent); background: var(--navy-800); }

.nav-badge {
    background: var(--stage-lost);
    color: #fff;
    font-size: 10.5px;
    font-weight: 700;
    padding: 1px 7px;
    border-radius: 999px;
    line-height: 1.5;
}

.sidebar .user-box {
    border-top: 1px solid var(--navy-700);
    padding-top: 14px;
    margin-top: 10px;
    font-size: 13px;
}
.sidebar .user-box .name { color: #fff; font-weight: 600; }
.sidebar .user-box a { color: #8792AE; font-size: 12.5px; }

.main {
    flex: 1;
    min-width: 0;
    padding: 26px 34px 50px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}

.topbar .eyebrow {
    text-transform: uppercase;
    letter-spacing: .08em;
    font-size: 11.5px;
    color: var(--text-muted);
    font-weight: 600;
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 13.5px;
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    font-family: inherit;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-outline { background: #fff; color: var(--text); border-color: var(--border); }
.btn-outline:hover { background: var(--bg); }
.btn-danger { background: #fff; color: var(--stage-lost); border-color: var(--stage-lost); }
.btn-danger:hover { background: #FBEAEE; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }

/* ---------- Avatars ---------- */
.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: #fff;
    font-weight: 700;
    font-family: 'Space Grotesk', sans-serif;
    flex-shrink: 0;
    line-height: 1;
}
.assignee {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 13px;
}
.assignee.muted { color: var(--text-muted); }

/* ---------- Cards / stats ---------- */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 26px;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-top: 3px solid var(--accent);
    border-radius: var(--radius);
    padding: 16px 18px;
    box-shadow: var(--shadow);
    transition: transform .15s, box-shadow .15s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(14,25,48,.08); }
.stat-card.accent-violet { border-top-color: var(--stage-qualified); }
.stat-card.accent-green { border-top-color: var(--stage-won); }
.stat-card.accent-amber { border-top-color: var(--stage-proposal); }
.stat-card .label { color: var(--text-muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat-card .value { font-family: 'Space Grotesk', sans-serif; font-size: 26px; font-weight: 700; color: var(--navy-900); margin-top: 4px; }
.stat-card .sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

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

/* ---------- Stage pills ---------- */
.pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}
.pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.stage-new         { background: #EEF0F4; color: var(--stage-new); }
.stage-contacted   { background: var(--accent-soft); color: var(--stage-contacted); }
.stage-qualified   { background: #F1EEFF; color: var(--stage-qualified); }
.stage-proposal    { background: #FCF1E0; color: #A66A16; }
.stage-negotiation { background: #FDECE3; color: #C85A2E; }
.stage-won         { background: #E4F8EF; color: var(--stage-won); }
.stage-lost        { background: #FBEAEE; color: var(--stage-lost); }

/* ---------- Kanban pipeline board ---------- */
.pipeline-board {
    display: grid;
    grid-template-columns: repeat(7, minmax(200px, 1fr));
    gap: 12px;
    overflow-x: auto;
    padding-bottom: 8px;
}
.pipeline-col {
    background: #EEF1F6;
    border-radius: var(--radius);
    padding: 12px;
    min-width: 200px;
}
.pipeline-col .col-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding: 0 2px;
}
.pipeline-col .col-head .count {
    background: #fff;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    padding: 1px 8px;
    color: var(--text-muted);
}
.pipeline-card {
    background: #fff;
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 8px;
    border: 1px solid var(--border);
    box-shadow: 0 1px 2px rgba(14,25,48,.05);
    display: block;
    color: var(--text);
    transition: transform .12s, box-shadow .12s, border-color .12s;
}
.pipeline-card:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-2px); box-shadow: 0 6px 16px rgba(14,25,48,.1); }
.pipeline-card .pc-name { font-weight: 600; font-size: 13px; margin-bottom: 2px; }
.pipeline-card .pc-company { color: var(--text-muted); font-size: 12px; margin-bottom: 8px; }
.pipeline-card .pc-foot { display: flex; align-items: center; justify-content: space-between; }
.pipeline-card .pc-value { font-family: 'IBM Plex Mono', monospace; font-size: 12.5px; font-weight: 600; color: var(--navy-900); }

/* Inline quick-assign select used in leads table / pipeline cards */
.quick-assign {
    border: 1px solid transparent;
    background: transparent;
    font-size: 12.5px;
    font-weight: 500;
    color: var(--text-muted);
    padding: 4px 6px;
    border-radius: 6px;
    cursor: pointer;
}
.quick-assign:hover { background: var(--bg); border-color: var(--border); }
.quick-assign:focus { outline: none; border-color: var(--accent); background: #fff; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; }
thead th {
    text-align: left;
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
    font-weight: 600;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
}
tbody td { padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 13.5px; vertical-align: middle; }
tbody tr { transition: background .1s; }
tbody tr:hover { background: #FAFBFD; }
tbody tr:last-child td { border-bottom: none; }
.table-name { font-weight: 600; color: var(--text); }
.table-sub { color: var(--text-muted); font-size: 12px; }

.role-badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .03em;
}
.role-admin { background: #F1EEFF; color: var(--stage-qualified); }
.role-sales_rep { background: var(--accent-soft); color: var(--accent-dark); }
.role-super_admin { background: #FCF1E0; color: #A66A16; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.form-field.full { grid-column: 1 / -1; }
.form-field label { font-size: 12.5px; font-weight: 600; color: var(--text); }
.form-field .hint { font-size: 11.5px; color: var(--text-muted); }
input, select, textarea {
    font-family: inherit;
    font-size: 13.5px;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    width: 100%;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { resize: vertical; min-height: 80px; }

/* ---------- Filters bar ---------- */
.filter-bar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 18px;
    align-items: center;
}
.filter-bar input, .filter-bar select { width: auto; min-width: 140px; }
.filter-bar input[type="text"] { min-width: 220px; }

/* ---------- Flash messages ---------- */
.flash { padding: 11px 16px; border-radius: 8px; font-size: 13.5px; font-weight: 500; margin-bottom: 18px; }
.flash-success { background: #E4F8EF; color: #0E7A50; border: 1px solid #B9EBD3; }
.flash-error { background: #FBEAEE; color: #93233F; border: 1px solid #F3C4D0; }

/* ---------- Follow-up list ---------- */
.followup-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}
.followup-item:last-child { border-bottom: none; }
.followup-item.overdue .fu-date { color: var(--stage-lost); font-weight: 700; }
.followup-item.done { opacity: .5; text-decoration: line-through; }

/* ---------- Notes timeline ---------- */
.timeline-item { padding: 12px 0; border-bottom: 1px solid var(--border); }
.timeline-item:last-child { border-bottom: none; }
.timeline-item .meta { font-size: 11.5px; color: var(--text-muted); margin-top: 4px; }

/* ---------- Empty state ---------- */
.empty-state {
    text-align: center;
    padding: 50px 20px;
    color: var(--text-muted);
}
.empty-state h3 { color: var(--text-muted); }

/* ---------- Login page ---------- */
.login-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--navy-900);
    background-image: radial-gradient(circle at 20% 20%, #16233F 0%, #0E1930 60%);
}
.login-card {
    width: 360px;
    background: var(--surface);
    border-radius: 14px;
    padding: 34px 30px;
    box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.login-card .mark {
    width: 42px; height: 42px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--accent), #7B61FF);
    display: flex; align-items: center; justify-content: center;
    font-family: 'Space Grotesk', sans-serif;
    color: #fff; font-weight: 700; font-size: 19px;
    margin-bottom: 16px;
}
.login-card h1 { font-size: 21px; }
.login-card p.sub { color: var(--text-muted); font-size: 13px; margin-bottom: 22px; }
.login-card .btn { width: 100%; justify-content: center; margin-top: 6px; }
.login-hint { margin-top: 16px; font-size: 12px; color: var(--text-muted); background: var(--bg); padding: 10px 12px; border-radius: 8px; }

/* ---------- Bar chart (dashboard) ---------- */
.bar-chart { display: flex; align-items: flex-end; gap: 14px; height: 150px; padding-top: 10px; }
.bar-chart .bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.bar-chart .bar { width: 100%; border-radius: 6px 6px 0 0; min-height: 4px; }
.bar-chart .bar-label { font-size: 11px; color: var(--text-muted); margin-top: 6px; text-align: center; }
.bar-chart .bar-count { font-size: 11.5px; font-weight: 700; color: var(--navy-900); margin-bottom: 4px; font-family: 'IBM Plex Mono', monospace; }

/* ---------- Detail page ---------- */
.detail-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; align-items: start; }
.detail-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.info-row { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.info-row:last-child { border-bottom: none; }
.info-row .k { color: var(--text-muted); }
.info-row .v { font-weight: 500; text-align: right; }

@media (max-width: 900px) {
    .app-shell { flex-direction: column; }
    .sidebar { width: 100%; flex-direction: row; overflow-x: auto; }
    .sidebar .user-box { display: none; }
    .main { padding: 18px; }
    .form-grid { grid-template-columns: 1fr; }
    .detail-grid { grid-template-columns: 1fr; }
    .pipeline-board { grid-template-columns: repeat(7, 200px); }
}
