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

:root {
    --bg: #F8F7F4;
    --bg-subtle: #F0EFEB;
    --card: #FFFFFF;
    --card-hover: #FAFAF9;
    --primary: #6D5DD3;
    --primary-hover: #5B4BB8;
    --primary-subtle: rgba(109, 93, 211, 0.08);
    --danger: #CF222E;
    --success: #2DA44E;
    --warning: #CF8700;
    --muted: #8B949E;
    --border: #D0D7DE;
    --border-subtle: #E8EAED;
    --text: #24292F;
    --text-secondary: #656D76;
    --text-bright: #24292F;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    --font: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

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

/* App Layout — Sidebar + Main */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 240px;
    min-height: 100vh;
    background: var(--card);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 24px 16px;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 100;
}

.sidebar-top { display: flex; flex-direction: column; gap: 28px; }

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 8px;
}
.brand-icon {
    width: 28px;
    height: 28px;
    background: linear-gradient(135deg, #6D5DD3, #8B7BE8);
    border-radius: 7px;
    flex-shrink: 0;
}
.sidebar-brand span {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.03em;
}

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

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.15s;
}
.nav-item:hover { color: var(--text); background: var(--bg); text-decoration: none; }
.nav-item.active {
    color: var(--primary);
    background: var(--primary-subtle);
    font-weight: 600;
}
.nav-item svg, .nav-item img { width: 18px; height: 18px; }

.sidebar-bottom {
    border-top: 1px solid var(--border-subtle);
    padding-top: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
}
.sidebar-user .avatar {
    width: 32px;
    height: 32px;
    background: var(--primary);
    border-radius: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 600;
    color: #fff;
    flex-shrink: 0;
}
.sidebar-user .user-name { font-size: 0.8rem; font-weight: 600; color: var(--text); }
.sidebar-user .user-role { font-size: 0.7rem; color: var(--muted); }

/* Main content */
main {
    flex: 1;
    margin-left: 240px;
    padding: 32px;
    max-width: 100%;
    overflow-x: hidden;
}

/* Page header */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}
.page-header h2 { font-size: 1.4rem; font-weight: 700; color: var(--text); letter-spacing: -0.03em; }

/* Card */
.card {
    background: var(--card);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

h2 { font-size: 1.1rem; margin-bottom: 12px; color: var(--text); }
h3 { font-size: 0.95rem; margin: 16px 0 8px; color: var(--text); }

.muted { color: var(--muted); font-size: 0.875rem; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    font-size: 0.875rem;
    font-weight: 500;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--card);
    color: var(--text);
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s;
    font-family: inherit;
}
.btn:hover { background: var(--bg); border-color: var(--muted); text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { opacity: 0.9; }
.btn-sm { padding: 4px 10px; font-size: 0.8rem; }
.btn-lg { padding: 12px 24px; font-size: 1rem; }
.btn-full { width: 100%; justify-content: center; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Forms */
label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 4px;
    margin-top: 12px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="tel"],
input[type="url"],
input[type="datetime-local"],
textarea,
select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-family: inherit;
    background: var(--card);
    color: var(--text);
    transition: border-color 0.15s;
}
input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-subtle);
}
textarea { resize: vertical; min-height: 80px; }
select { cursor: pointer; }

.error-msg { color: var(--danger); font-size: 0.85rem; margin-top: 8px; }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border-subtle); }
th { font-weight: 600; color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; }
tbody tr { transition: background 0.1s; }
tbody tr:hover { background: var(--bg); }

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}
.stat-card {
    background: var(--card);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow);
}
.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
}
.stat-label {
    font-size: 0.75rem;
    color: var(--muted);
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 500;
}

/* Pipeline bar */
.pipeline-bar {
    display: flex;
    height: 28px;
    border-radius: 6px;
    overflow: hidden;
    gap: 2px;
}
.pipeline-bar .segment {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 600;
    color: #fff;
    min-width: 30px;
    transition: flex 0.3s;
}

/* Pipeline board (Kanban) */
.pipeline-board {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding-bottom: 12px;
}
.pipeline-column {
    min-width: 220px;
    max-width: 280px;
    flex: 1;
    background: var(--card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}
.pipeline-column-header {
    padding: 14px 16px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.pipeline-column-header .count {
    background: var(--bg);
    border-radius: 100px;
    padding: 2px 8px;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-secondary);
}
.pipeline-column-body {
    padding: 8px;
    min-height: 100px;
}
.pipeline-column-body.drag-over {
    background: var(--primary-subtle);
}

.lead-card {
    background: var(--card-hover);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 8px;
    cursor: grab;
    transition: all 0.15s;
}
.lead-card:hover { border-color: var(--primary); box-shadow: 0 2px 8px rgba(109,93,211,0.1); }
.lead-card.dragging { opacity: 0.5; }
.lead-card .lead-name { font-weight: 600; font-size: 0.875rem; color: var(--text); }
.lead-card .lead-phone { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }
.lead-card .lead-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
    font-size: 0.75rem;
    color: var(--muted);
}

/* Badge */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 600;
}
.badge-new { background: var(--primary-subtle); color: var(--primary); }
.badge-converted { background: rgba(45, 164, 78, 0.1); color: var(--success); }
.badge-lost { background: rgba(207, 34, 46, 0.1); color: var(--danger); }
.badge-followup { background: rgba(207, 135, 0, 0.1); color: var(--warning); }

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    backdrop-filter: blur(4px);
}
.modal-overlay.hidden { display: none; }
.modal {
    background: var(--card);
    border-radius: var(--radius-lg);
    padding: 24px;
    width: 100%;
    max-width: 440px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}
.modal h3 { margin: 0 0 16px; color: var(--text); }
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 20px;
}

/* Activity feed */
.activity-item {
    padding: 10px 0;
    border-bottom: 1px solid var(--border-subtle);
}
.activity-item:last-child { border-bottom: none; }
.activity-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}
.activity-lead {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text);
}
.activity-body { font-size: 0.85rem; }

/* Login */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
}
.login-card {
    background: var(--card);
    border-radius: 16px;
    padding: 48px 40px;
    width: 100%;
    max-width: 420px;
    text-align: center;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
}
.login-card h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
}
.login-card .muted { margin-bottom: 24px; }
.login-card input { margin-bottom: 12px; }
.login-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 8px;
}
.login-brand .brand-icon { width: 36px; height: 36px; border-radius: 10px; }

/* Status dot */
.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
}
.status-dot.active { background: var(--success); }
.status-dot.inactive { background: var(--danger); }

/* Lead detail */
.lead-detail-grid {
    display: grid;
    grid-template-columns: 400px 1fr;
    gap: 20px;
    margin-bottom: 16px;
}
.lead-detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}
.lead-detail-header h2 { margin: 0; }
.lead-detail-fields {
    display: grid;
    gap: 8px;
}
.detail-field {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-subtle);
    font-size: 0.875rem;
}
.detail-label { color: var(--muted); font-weight: 500; }

/* Stage progress */
.stage-progress {
    display: flex;
    gap: 4px;
    margin: 12px 0;
    flex-wrap: wrap;
}
.stage-dot {
    flex: 1;
    min-width: 60px;
    padding: 6px 4px;
    text-align: center;
    border-radius: var(--radius);
    background: var(--bg);
    border: 1px solid var(--border-subtle);
    transition: all 0.15s;
}
.stage-dot.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}
.stage-dot.done {
    background: var(--primary-subtle);
    border-color: var(--primary);
}
.stage-dot-label { font-size: 0.65rem; font-weight: 500; text-transform: uppercase; letter-spacing: 0.03em; }

/* Stage move buttons */
.stage-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

/* Timeline */
.timeline-item {
    padding: 10px 0;
    border-bottom: 1px solid var(--border-subtle);
}
.timeline-item:last-child { border-bottom: none; }
.timeline-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2px;
}
.timeline-action { font-size: 0.875rem; }
.timeline-meta { font-size: 0.8rem; }

/* Utilities */
.hidden { display: none !important; }
.flex { display: flex; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-12 { margin-top: 12px; }
.mt-20 { margin-top: 20px; }
.text-center { text-align: center; }

/* Responsive */
@media (max-width: 768px) {
    .sidebar { display: none; }
    main { margin-left: 0; padding: 16px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .pipeline-board { flex-direction: column; }
    .pipeline-column { max-width: 100%; min-width: auto; }
    .lead-detail-grid { grid-template-columns: 1fr; }
}
