:root {
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-light: #eef2ff;
    --bg: #f6f7fb;
    --surface: #ffffff;
    --surface-2: #f1f3f9;
    --text: #1e2233;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --success: #16a34a;
    --success-light: #dcfce7;
    --warning: #d97706;
    --warning-light: #fef3c7;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --info: #0284c7;
    --info-light: #e0f2fe;
    --sidebar-w: 240px;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(16, 24, 40, 0.06), 0 1px 2px rgba(16, 24, 40, 0.04);
    --shadow-lg: 0 10px 30px rgba(16, 24, 40, 0.12);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

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

html, body { height: 100%; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

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

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

.sidebar {
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; bottom: 0; left: 0;
    z-index: 100;
    transition: transform .25s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 22px;
    border-bottom: 1px solid var(--border);
}
.sidebar-brand h1 { font-size: 20px; font-weight: 700; letter-spacing: -0.5px; }
.sidebar-brand span { color: var(--primary); }

.nav { padding: 14px 12px; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 9px;
    color: var(--text-muted);
    font-weight: 500;
    transition: background .15s, color .15s;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--primary-light); color: var(--primary); }
.nav a svg { flex-shrink: 0; }

.sidebar-user {
    padding: 16px 18px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
}
.sidebar-user .avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--primary); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 15px; flex-shrink: 0;
}
.sidebar-user .meta { min-width: 0; flex: 1; }
.sidebar-user .name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user .email { font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user .logout { color: var(--text-muted); }
.sidebar-user .logout:hover { color: var(--danger); }

.main {
    flex: 1;
    margin-left: var(--sidebar-w);
    padding: 26px 32px;
    min-width: 0;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}
.topbar h2 { font-size: 24px; font-weight: 700; letter-spacing: -0.5px; }
.topbar .sub { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

.burger {
    display: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 8px 10px;
    cursor: pointer;
}

/* ---------- Cards & grids ---------- */
.grid { display: grid; gap: 20px; }
.grid-stats { grid-template-columns: repeat(4, 1fr); }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
}
.card h3 { font-size: 15px; font-weight: 600; margin-bottom: 14px; }
.card .card-head {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 14px; gap: 10px;
}

.stat-card {
    display: flex;
    align-items: center;
    gap: 16px;
}
.stat-icon {
    width: 48px; height: 48px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.stat-icon.primary { background: var(--primary-light); color: var(--primary); }
.stat-icon.success { background: var(--success-light); color: var(--success); }
.stat-icon.warning { background: var(--warning-light); color: var(--warning); }
.stat-icon.info { background: var(--info-light); color: var(--info); }
.stat-card .value { font-size: 26px; font-weight: 700; letter-spacing: -0.5px; line-height: 1.1; }
.stat-card .label { color: var(--text-muted); font-size: 13px; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 16px;
    border-radius: 9px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    transition: all .15s;
    font-family: var(--font);
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { background: #15803d; }
.btn-sm { padding: 6px 11px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }
.btn-icon { padding: 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text-muted); cursor: pointer; }
.btn-icon:hover { background: var(--surface-2); color: var(--text); }
.btn-icon.danger:hover { color: var(--danger); background: var(--danger-light); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}
td { padding: 12px; border-bottom: 1px solid var(--border); font-size: 13px; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface-2); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ---------- Badges ---------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-planifie { background: var(--info-light); color: var(--info); }
.badge-confirme { background: var(--success-light); color: var(--success); }
.badge-annule { background: var(--danger-light); color: var(--danger); }
.badge-termine { background: var(--surface-2); color: var(--text-muted); }
.badge-nouveau { background: var(--info-light); color: var(--info); }
.badge-contacte { background: var(--warning-light); color: var(--warning); }
.badge-qualifie { background: var(--primary-light); color: var(--primary); }
.badge-proposition { background: #f3e8ff; color: #9333ea; }
.badge-gagne { background: var(--success-light); color: var(--success); }
.badge-perdu { background: var(--danger-light); color: var(--danger); }

/* ---------- Forms ---------- */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 5px; }
input, select, textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 9px;
    font-size: 13px;
    font-family: var(--font);
    color: var(--text);
    background: var(--surface);
    transition: border .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}
textarea { resize: vertical; min-height: 70px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------- Modal ---------- */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(16, 24, 40, 0.5);
    display: none;
    align-items: center; justify-content: center;
    z-index: 200;
    padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 24px;
}
.modal h3 { font-size: 18px; font-weight: 700; margin-bottom: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; top: 20px; right: 20px; z-index: 300; display: flex; flex-direction: column; gap: 10px; }
.toast {
    padding: 12px 16px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    animation: slideIn .25s ease;
    max-width: 340px;
}
.toast-success { background: var(--success); color: #fff; }
.toast-error { background: var(--danger); color: #fff; }
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }

/* ---------- Pipeline (kanban) ---------- */
.pipeline {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 12px;
    overflow-x: auto;
    padding-bottom: 8px;
}
.pipeline-col {
    background: var(--surface-2);
    border-radius: var(--radius);
    padding: 12px;
    min-width: 180px;
    min-height: 300px;
}
.pipeline-col.drag-over { outline: 2px dashed var(--primary); background: var(--primary-light); }
.pipeline-col-head {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 10px; padding: 0 2px;
}
.pipeline-col-head .count {
    background: var(--surface);
    border-radius: 999px;
    font-size: 11px; font-weight: 700;
    padding: 2px 8px; color: var(--text-muted);
}
.pipeline-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 12px;
    margin-bottom: 8px;
    cursor: grab;
    box-shadow: var(--shadow);
    transition: box-shadow .15s, transform .15s;
}
.pipeline-card:hover { box-shadow: var(--shadow-lg); }
.pipeline-card.dragging { opacity: 0.5; }
.pipeline-card .p-name { font-weight: 600; font-size: 13px; }
.pipeline-card .p-company { color: var(--text-muted); font-size: 12px; }
.pipeline-card .p-contact { color: var(--text-muted); font-size: 11px; margin-top: 4px; }

/* ---------- Agenda ---------- */
.cal-nav { display: flex; align-items: center; gap: 12px; }
.cal-nav .month { font-size: 16px; font-weight: 700; min-width: 150px; text-align: center; }
.calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.cal-day-head { background: var(--surface); padding: 10px; text-align: center; font-weight: 600; font-size: 12px; color: var(--text-muted); text-transform: uppercase; }
.cal-cell { background: var(--surface); min-height: 110px; padding: 8px; cursor: pointer; position: relative; }
.cal-cell.other { background: var(--surface-2); }
.cal-cell.today { outline: 2px solid var(--primary); outline-offset: -2px; }
.cal-cell .day-num { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.cal-cell.today .day-num { color: var(--primary); }
.cal-event {
    background: var(--primary-light);
    color: var(--primary);
    border-radius: 5px;
    font-size: 11px;
    padding: 2px 6px;
    margin-top: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cal-event.statut-annule { background: var(--danger-light); color: var(--danger); text-decoration: line-through; }
.cal-event.statut-termine { background: var(--surface-2); color: var(--text-muted); }

/* ---------- Login ---------- */
.login-body {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    padding: 20px;
}
.login-wrap {
    display: flex;
    align-items: stretch;
    gap: 40px;
    width: 100%;
    max-width: 960px;
    flex-wrap: wrap;
    justify-content: center;
}
.login-hero {
    flex: 1;
    min-width: 300px;
    color: #fff;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 12px 0;
}
.login-brand {
    display: flex; align-items: center; gap: 12px;
    margin-bottom: 18px;
}
.login-brand h1 { font-size: 28px; font-weight: 800; letter-spacing: -0.5px; }
.login-hero h2 { font-size: 26px; font-weight: 700; letter-spacing: -0.5px; line-height: 1.25; margin-bottom: 14px; }
.login-desc { color: rgba(255, 255, 255, 0.88); font-size: 15px; line-height: 1.6; margin-bottom: 22px; max-width: 480px; }
.login-features { list-style: none; display: flex; flex-direction: column; gap: 12px; }
.login-features li {
    display: flex; align-items: center; gap: 12px;
    font-size: 14px; font-weight: 500; color: rgba(255, 255, 255, 0.95);
}
.login-features svg { flex-shrink: 0; opacity: 0.9; }
.login-card {
    background: var(--surface);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    padding: 36px;
    width: 100%;
    max-width: 400px;
    flex-shrink: 0;
}
.login-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.login-logo h1 { font-size: 24px; font-weight: 800; letter-spacing: -0.5px; }
.login-subtitle { color: var(--text-muted); margin-bottom: 24px; font-size: 14px; }
.login-form { margin-top: 8px; }
.login-hint { text-align: center; color: var(--text-muted); font-size: 12px; margin-top: 18px; }

/* ---------- Empty state ---------- */
.empty { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.empty svg { margin-bottom: 12px; opacity: 0.5; }
.empty p { font-size: 14px; }

/* ---------- Visio link ---------- */
.visio-link { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; }
.visio-link svg { flex-shrink: 0; }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.toolbar .search { flex: 1; min-width: 200px; position: relative; }
.toolbar .search input { padding-left: 34px; }
.toolbar .search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-muted); }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
    .grid-stats { grid-template-columns: repeat(2, 1fr); }
    .grid-2 { grid-template-columns: 1fr; }
    .grid-3 { grid-template-columns: 1fr; }
    .pipeline { grid-template-columns: repeat(6, 220px); }
}
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main { margin-left: 0; padding: 64px 16px 18px; }
    .burger {
        display: inline-flex;
        position: fixed;
        top: 14px;
        left: 14px;
        z-index: 150;
    }
    .grid-stats { grid-template-columns: 1fr; }
    .form-row { grid-template-columns: 1fr; }
    .topbar h2 { font-size: 20px; }
}
