/* ─── Fonts ─────────────────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@600;700&family=DM+Sans:wght@300;400;500;600&display=swap');

/* ─── Variables ──────────────────────────────────────────────────────────────── */
:root {
    --ink:      #0f1923;
    --ink-2:    #2d3748;
    --ink-3:    #64748b;
    --cream:    #faf8f5;
    --white:    #ffffff;
    --gold:     #c9902a;
    --gold-lt:  #f5e6c8;
    --rust:     #c0392b;
    --rust-lt:  #fdf0ef;
    --green:    #1a7f54;
    --green-lt: #e8f5ef;
    --amber:    #d97706;
    --amber-lt: #fef3c7;
    --blue:     #1e5fa8;
    --blue-lt:  #e8f0fc;
    --border:   #e8e4de;
    --shadow:   0 2px 12px rgba(15,25,35,.07);
    --shadow-lg:0 8px 32px rgba(15,25,35,.12);
    --radius:   12px;
    --radius-sm:8px;
    --sidebar-w:240px;
    --font-head: 'Playfair Display', Georgia, serif;
    --font-body: 'DM Sans', system-ui, sans-serif;
}

/* ─── Reset & Base ───────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    background: var(--cream);
    font-family: var(--font-body);
    color: var(--ink);
    font-size: 14px;
    line-height: 1.6;
}

/* ─── Layout ─────────────────────────────────────────────────────────────────── */
.layout { display: flex; min-height: 100vh; }

/* ─── Sidebar ────────────────────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--ink);
    color: #fff;
    display: flex;
    flex-direction: column;
    padding: 0;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    overflow-y: auto;
}

.sidebar-brand {
    padding: 28px 24px 20px;
    border-bottom: 1px solid rgba(255,255,255,.08);
}

.sidebar-brand-name {
    font-family: var(--font-head);
    font-size: 20px;
    font-weight: 700;
    color: var(--gold);
    letter-spacing: -.3px;
    line-height: 1.2;
}

.sidebar-brand-sub {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: rgba(255,255,255,.4);
    margin-top: 3px;
}

.sidebar-nav { flex: 1; padding: 16px 12px; }

.sidebar-section {
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: rgba(255,255,255,.3);
    padding: 16px 12px 6px;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    color: rgba(255,255,255,.65);
    text-decoration: none;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    margin-bottom: 2px;
    font-size: 13.5px;
    font-weight: 400;
    transition: all .18s ease;
}

.sidebar-nav a:hover {
    background: rgba(255,255,255,.08);
    color: #fff;
}

.sidebar-nav a.active {
    background: var(--gold);
    color: var(--ink);
    font-weight: 600;
}

.sidebar-nav a .icon { font-size: 15px; width: 20px; text-align: center; }

.sidebar-footer {
    padding: 16px 12px;
    border-top: 1px solid rgba(255,255,255,.08);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    margin-bottom: 6px;
}

.sidebar-avatar {
    width: 32px; height: 32px;
    background: var(--gold);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700;
    font-size: 13px;
    color: var(--ink);
    flex-shrink: 0;
}

.sidebar-user-name { font-size: 13px; font-weight: 500; color: #fff; }
.sidebar-user-role { font-size: 11px; color: rgba(255,255,255,.4); text-transform: capitalize; }

/* ─── Main Content ───────────────────────────────────────────────────────────── */
.main {
    margin-left: var(--sidebar-w);
    flex: 1;
    padding: 36px 40px;
    max-width: calc(100% - var(--sidebar-w));
}

/* ─── Page Header ────────────────────────────────────────────────────────────── */
.page-header { margin-bottom: 28px; }
.page-title {
    font-family: var(--font-head);
    font-size: 28px;
    font-weight: 700;
    color: var(--ink);
    line-height: 1.2;
}
.page-subtitle { color: var(--ink-3); font-size: 14px; margin-top: 4px; }

/* ─── Cards ──────────────────────────────────────────────────────────────────── */
.card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.card-body { padding: 24px; }
.card-header-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 24px;
    border-bottom: 1px solid var(--border);
}
.card-title { font-weight: 600; font-size: 15px; color: var(--ink); }

/* ─── Stat Cards ─────────────────────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 16px; margin-bottom: 28px; }

.stat-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 20px 22px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
}

.stat-card.gold::before  { background: var(--gold); }
.stat-card.rust::before  { background: var(--rust); }
.stat-card.amber::before { background: var(--amber); }
.stat-card.blue::before  { background: var(--blue); }
.stat-card.green::before { background: var(--green); }

.stat-icon {
    width: 40px; height: 40px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px;
    margin-bottom: 14px;
}
.stat-icon.gold  { background: var(--gold-lt); }
.stat-icon.rust  { background: var(--rust-lt); }
.stat-icon.amber { background: var(--amber-lt); }
.stat-icon.blue  { background: var(--blue-lt); }
.stat-icon.green { background: var(--green-lt); }

.stat-label { font-size: 12px; color: var(--ink-3); font-weight: 500; text-transform: uppercase; letter-spacing: .8px; }
.stat-value { font-size: 26px; font-weight: 700; color: var(--ink); line-height: 1.1; margin-top: 4px; font-family: var(--font-head); }
.stat-sub { font-size: 12px; color: var(--ink-3); margin-top: 4px; }

/* ─── Badges / Status ────────────────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: .2px;
}

.badge-status { }
.badge-hot    { background: var(--rust-lt); color: var(--rust); }
.badge-new    { background: var(--blue-lt); color: var(--blue); }
.badge-contacted { background: #f0e8fc; color: #6d28d9; }
.badge-followup  { background: var(--amber-lt); color: var(--amber); }
.badge-closed    { background: var(--green-lt); color: var(--green); }
.badge-lost      { background: #f1f5f9; color: #64748b; }

.status-active  { background: var(--green-lt); color: var(--green); }
.status-warn    { background: var(--amber-lt); color: var(--amber); }
.status-overdue { background: var(--rust-lt); color: var(--rust); }
.status-done    { background: #f1f5f9; color: #64748b; }

/* ─── Table ──────────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

table.crm-table {
    width: 100%;
    border-collapse: collapse;
}

table.crm-table th {
    background: #f8f7f4;
    padding: 10px 14px;
    text-align: left;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
    color: var(--ink-3);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

table.crm-table td {
    padding: 12px 14px;
    border-bottom: 1px solid #f0ede8;
    vertical-align: middle;
    font-size: 13.5px;
}

table.crm-table tbody tr:hover { background: #faf8f5; }
table.crm-table tbody tr:last-child td { border-bottom: none; }
table.crm-table .row-hot { background: #fff8f7; }
table.crm-table .row-hot:hover { background: #fff0ee; }

.customer-name { font-weight: 600; color: var(--ink); font-size: 14px; }
.customer-phone { color: var(--ink-3); font-size: 12px; margin-top: 1px; }

/* ─── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    text-decoration: none;
    transition: all .16s ease;
    white-space: nowrap;
}

.btn-primary { background: var(--ink); color: #fff; }
.btn-primary:hover { background: var(--ink-2); color: #fff; }

.btn-gold { background: var(--gold); color: var(--ink); }
.btn-gold:hover { background: #b8821f; color: var(--ink); }

.btn-ghost { background: transparent; color: var(--ink-3); border: 1px solid var(--border); }
.btn-ghost:hover { background: #f8f7f4; color: var(--ink); }

.btn-wa { background: #25D366; color: #fff; }
.btn-wa:hover { background: #1db954; color: #fff; }

.btn-warn { background: var(--amber-lt); color: var(--amber); border: 1px solid #fcd34d; }
.btn-warn:hover { background: #fef3c7; }

.btn-danger { background: var(--rust); color: #fff; }
.btn-danger:hover { background: #a93226; color: #fff; }

.btn-outline-danger { background: transparent; color: var(--rust); border: 1px solid var(--rust); }
.btn-outline-danger:hover { background: var(--rust-lt); }

.btn-sm { padding: 5px 11px; font-size: 12px; }
.btn-xs { padding: 3px 8px; font-size: 11px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }

/* ─── Forms ──────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .5px; }
.form-control, .form-select {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 13.5px;
    color: var(--ink);
    background: var(--white);
    transition: border-color .15s;
    outline: none;
}
.form-control:focus, .form-select:focus {
    border-color: var(--gold);
    box-shadow: 0 0 0 3px rgba(201,144,42,.1);
}
textarea.form-control { resize: vertical; min-height: 80px; }

/* ─── Modal ──────────────────────────────────────────────────────────────────── */
.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(15,25,35,.5);
    backdrop-filter: blur(2px);
    z-index: 200;
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding: 60px 20px;
    overflow-y: auto;
}
.modal-backdrop.open { display: flex; }

.modal-box {
    background: var(--white);
    border-radius: 16px;
    width: 100%;
    max-width: 640px;
    box-shadow: var(--shadow-lg);
    animation: modal-in .2s ease;
}
.modal-box.modal-lg { max-width: 800px; }

@keyframes modal-in {
    from { opacity: 0; transform: translateY(-16px); }
    to   { opacity: 1; transform: translateY(0); }
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-title { font-family: var(--font-head); font-size: 20px; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--ink-3); padding: 4px 8px; border-radius: 6px; }
.modal-close:hover { background: var(--border); }
.modal-body { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* ─── Grid helpers ───────────────────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4,1fr); gap: 16px; }
.col-span-2 { grid-column: span 2; }

/* ─── Alerts ─────────────────────────────────────────────────────────────────── */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    border-left: 4px solid;
}
.alert-info    { background: var(--blue-lt); border-color: var(--blue); color: #1e3a5f; }
.alert-warn    { background: var(--amber-lt); border-color: var(--amber); color: #7c4a00; }
.alert-success { background: var(--green-lt); border-color: var(--green); color: #0f4733; }
.alert-danger  { background: var(--rust-lt); border-color: var(--rust); color: #7b1a14; }

/* ─── Progress bar ───────────────────────────────────────────────────────────── */
.progress-bar-wrap { background: #f0ede8; border-radius: 99px; height: 8px; overflow: hidden; }
.progress-bar-fill { height: 100%; border-radius: 99px; transition: width .4s ease; }
.progress-bar-fill.green  { background: var(--green); }
.progress-bar-fill.amber  { background: var(--amber); }
.progress-bar-fill.danger { background: var(--rust); }

/* ─── Leaderboard card ───────────────────────────────────────────────────────── */
.leader-card {
    background: linear-gradient(135deg,#0d1f3c 0%,#162847 100%);
    border-radius: var(--radius);
    padding: 28px 32px;
    color: #fff;
    margin-bottom: 28px;
    position: relative;
    overflow: hidden;
}
.leader-card::after {
    content: '🏆';
    position: absolute;
    right: 32px; top: 50%;
    transform: translateY(-50%);
    font-size: 64px;
    opacity: .15;
}
.leader-eyebrow { font-size: 10px; text-transform: uppercase; letter-spacing: 2px; color: var(--gold); font-weight: 600; }
.leader-name { font-family: var(--font-head); font-size: 30px; font-weight: 700; margin: 6px 0 8px; }
.leader-meta { font-size: 14px; color: rgba(255,255,255,.7); }
.leader-meta strong { color: #fff; }

/* ─── Rep card ───────────────────────────────────────────────────────────────── */
.rep-cards { display: grid; grid-template-columns: repeat(3,1fr); gap: 16px; margin-top: 20px; }
.rep-card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}
.rep-rank { font-size: 28px; margin-bottom: 6px; }
.rep-name { font-weight: 700; font-size: 15px; }
.rep-stat { display: flex; justify-content: space-between; margin-top: 8px; font-size: 13px; }
.rep-stat-label { color: var(--ink-3); }
.rep-stat-value { font-weight: 600; }

/* ─── Flex helpers ───────────────────────────────────────────────────────────── */
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-center  { display: flex; align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.text-muted { color: var(--ink-3); }
.text-sm { font-size: 12px; }
.fw-600 { font-weight: 600; }

/* ─── Search/filter bar ──────────────────────────────────────────────────────── */
.filter-bar {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.filter-bar .form-control, .filter-bar .form-select { width: auto; }
.search-input { min-width: 240px; }

/* ─── Empty state ────────────────────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 60px 24px;
    color: var(--ink-3);
}
.empty-state-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state-title { font-weight: 600; font-size: 16px; color: var(--ink-2); }
.empty-state-text { font-size: 13px; margin-top: 4px; }

/* ─── Toast ──────────────────────────────────────────────────────────────────── */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 999; display: flex; flex-direction: column; gap: 8px; }
.toast {
    background: var(--ink);
    color: #fff;
    padding: 12px 18px;
    border-radius: 10px;
    font-size: 13.5px;
    box-shadow: var(--shadow-lg);
    animation: toast-in .25s ease;
    min-width: 240px;
}
.toast.success { background: var(--green); }
.toast.error   { background: var(--rust); }
@keyframes toast-in { from { opacity:0; transform: translateY(12px); } to { opacity:1; transform:translateY(0); } }

/* ─── Login page ─────────────────────────────────────────────────────────────── */
.login-page {
    min-height: 100vh;
    display: flex;
    background: var(--ink);
}
.login-art {
    flex: 1;
    background: linear-gradient(160deg, #0d1f3c 0%, #1a3a5c 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px;
    color: #fff;
    position: relative;
    overflow: hidden;
}
.login-art::before {
    content: '';
    position: absolute;
    width: 400px; height: 400px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(201,144,42,.15) 0%, transparent 70%);
    top: -100px; right: -100px;
}
.login-art-brand { font-family: var(--font-head); font-size: 42px; color: var(--gold); font-weight: 700; }
.login-art-tagline { font-size: 16px; color: rgba(255,255,255,.5); margin-top: 8px; max-width: 280px; text-align: center; line-height: 1.7; }
.login-form-wrap {
    width: 420px;
    background: var(--cream);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px 48px;
}
.login-box { width: 100%; }
.login-title { font-family: var(--font-head); font-size: 28px; font-weight: 700; margin-bottom: 4px; }
.login-sub { color: var(--ink-3); font-size: 14px; margin-bottom: 28px; }

/* ─── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
    .sidebar { width: 200px; }
    .main { margin-left: 200px; padding: 24px 20px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .rep-cards { grid-template-columns: 1fr 1fr; }
    .grid-3 { grid-template-columns: 1fr 1fr; }
}

/* ─── Mobile nav bar ─────────────────────────────────────────────────────────── */
.mobile-nav {
    display: none;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: var(--ink);
    z-index: 200;
    padding: 6px 0 8px;
    border-top: 1px solid rgba(255,255,255,.1);
}
.mobile-nav-items {
    display: flex;
    justify-content: space-around;
    align-items: center;
}
.mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    color: rgba(255,255,255,.5);
    text-decoration: none;
    font-size: 10px;
    padding: 4px 8px;
    border-radius: 8px;
    min-width: 52px;
    text-align: center;
}
.mobile-nav-item.active { color: var(--gold); }
.mobile-nav-item:hover { color: #fff; }
.mobile-nav-icon { font-size: 20px; line-height: 1; }

/* ─── Mobile top bar ─────────────────────────────────────────────────────────── */
.mobile-topbar {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0;
    background: var(--ink);
    z-index: 150;
    padding: 14px 20px;
    align-items: center;
    justify-content: space-between;
}
.mobile-topbar-brand {
    font-family: var(--font-head);
    font-size: 18px;
    font-weight: 700;
    color: var(--gold);
}
.mobile-topbar-user {
    width: 32px; height: 32px;
    background: var(--gold);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 13px;
    color: var(--ink);
}

@media (max-width: 640px) {
    /* Hide desktop sidebar */
    .sidebar { display: none; }

    /* Show mobile bars */
    .mobile-nav { display: block; }
    .mobile-topbar { display: flex; }

    /* Push main content below topbar and above bottom nav */
    .main {
        margin-left: 0;
        padding: 76px 16px 90px;
        max-width: 100%;
    }

    /* Stack all grids */
    .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .rep-cards { grid-template-columns: 1fr; }
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
    .col-span-2 { grid-column: span 1; }

    /* Tighter stat cards on mobile */
    .stat-card { padding: 14px 16px; }
    .stat-value { font-size: 20px; }
    .page-title { font-size: 22px; }

    /* Tables scroll horizontally */
    .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    table.crm-table { min-width: 600px; }

    /* Modals full screen on mobile */
    .modal-backdrop { padding: 0; align-items: flex-end; }
    .modal-box { border-radius: 16px 16px 0 0; max-width: 100%; max-height: 90vh; overflow-y: auto; }

    /* Filter bar stacks */
    .filter-bar { flex-direction: column; align-items: stretch; }
    .filter-bar .form-control,
    .filter-bar .form-select,
    .search-input { width: 100%; min-width: unset; }

    /* Grid helpers */
    .flex-between { flex-wrap: wrap; gap: 10px; }

    /* Login page */
    .login-art { display: none; }
    .login-form-wrap { width: 100%; padding: 40px 24px; }
    .login-title { font-size: 22px; }

    /* Leader card */
    .leader-card { padding: 20px; }
    .leader-name { font-size: 22px; }

    /* Page header */
    .page-header { margin-bottom: 16px; }
    .page-subtitle { font-size: 12px; }
}
