:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #eef2ff;
  --bg: #f4f5fb;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #1f2937;
  --text-muted: #6b7280;
  --success: #16a34a;
  --success-bg: #ecfdf5;
  --warning: #d97706;
  --warning-bg: #fffbeb;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --info: #0284c7;
  --info-bg: #eff6ff;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.04);
  --sidebar-w: 248px;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

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; left: 0; bottom: 0;
  z-index: 50;
  transition: transform .25s ease;
}

.sidebar-header {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-header .logo-icon { flex-shrink: 0; }
.sidebar-header .brand { font-weight: 700; font-size: 17px; }
.sidebar-header .brand small { display:block; font-weight: 400; color: var(--text-muted); font-size: 12px; }

.sidebar-nav { padding: 12px; flex: 1; overflow-y: auto; }
.nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px;
  border-radius: 10px;
  color: var(--text);
  font-weight: 500;
  margin-bottom: 2px;
  transition: background .15s, color .15s;
}
.nav-link:hover { background: var(--bg); text-decoration: none; }
.nav-link.active { background: var(--primary-light); color: var(--primary); }
.nav-link svg { flex-shrink: 0; }

.sidebar-footer { padding: 14px 20px; border-top: 1px solid var(--border); }
.user-box { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; flex-shrink: 0;
}
.user-box .u-name { font-weight: 600; font-size: 14px; }
.user-box .u-role { font-size: 12px; color: var(--text-muted); }

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

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 22px; gap: 16px; flex-wrap: wrap;
}
.topbar h2 { font-size: 22px; font-weight: 700; }
.topbar .sub { color: var(--text-muted); font-size: 14px; }

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

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

.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); }

/* KPI */
.kpi { display: flex; flex-direction: column; gap: 6px; }
.kpi .kpi-label { color: var(--text-muted); font-size: 13px; font-weight: 500; }
.kpi .kpi-value { font-size: 28px; font-weight: 700; letter-spacing: -.5px; }
.kpi .kpi-foot { font-size: 12px; color: var(--text-muted); }
.kpi-icon {
  width: 40px; height: 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 6px;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 15px; border-radius: 9px; border: 1px solid transparent;
  font-size: 14px; font-weight: 600; cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--bg); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: .9; }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.btn-block { width: 100%; justify-content: center; }
.btn-icon { padding: 6px; border-radius: 8px; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--border); }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--text-muted); font-weight: 600; background: #fafafa; }
tbody tr:hover { background: #f9fafb; }
td .actions { display: flex; gap: 6px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
}
.badge-actif, .badge-gagne { background: var(--success-bg); color: var(--success); }
.badge-inactif, .badge-perdu { background: var(--danger-bg); color: var(--danger); }
.badge-nouveau { background: var(--info-bg); color: var(--info); }
.badge-contacte, .badge-qualifie { background: var(--info-bg); color: var(--info); }
.badge-proposition, .badge-negociation { background: var(--warning-bg); color: var(--warning); }
.badge-appel { background: var(--info-bg); color: var(--info); }
.badge-rdv { background: var(--primary-light); color: var(--primary); }
.badge-visio { background: #f5f3ff; color: #7c3aed; }

/* ---------- Forms ---------- */
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
input, select, textarea {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 9px;
  font-size: 14px; font-family: inherit; color: var(--text);
  background: var(--surface); transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,.12);
}
textarea { resize: vertical; min-height: 80px; }
.form-row { margin-bottom: 14px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

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

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(17,24,39,.5);
  display: none; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface); border-radius: var(--radius);
  width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto;
  padding: 24px; box-shadow: 0 20px 50px rgba(0,0,0,.2);
}
.modal h3 { font-size: 18px; margin-bottom: 16px; }

/* ---------- Kanban ---------- */
.kanban { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 10px; align-items: flex-start; }
.kanban-col {
  min-width: 220px; flex: 1; background: #f0f1f8;
  border-radius: var(--radius); padding: 12px;
}
.kanban-col-head {
  display: flex; align-items: center; justify-content: space-between;
  font-weight: 600; font-size: 13px; padding: 0 4px 10px;
}
.kanban-col-head .count { background: var(--surface); border-radius: 999px; padding: 2px 9px; font-size: 12px; color: var(--text-muted); }
.kanban-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px; margin-bottom: 10px; cursor: grab;
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.kanban-card:active { cursor: grabbing; }
.kanban-card.dragging { opacity: .5; }
.kanban-card .k-name { font-weight: 600; font-size: 14px; }
.kanban-card .k-comp { font-size: 12px; color: var(--text-muted); }
.kanban-card .k-value { font-size: 13px; font-weight: 600; color: var(--primary); margin-top: 6px; }
.kanban-col.drag-over { outline: 2px dashed var(--primary); outline-offset: -4px; }

/* ---------- Agenda ---------- */
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.cal-dow { text-align: center; font-size: 12px; font-weight: 600; color: var(--text-muted); padding: 6px 0; }
.cal-cell {
  min-height: 96px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px; cursor: pointer; position: relative;
  transition: background .15s;
}
.cal-cell:hover { background: #f9fafb; }
.cal-cell.other-month { background: #fafafa; color: var(--text-muted); }
.cal-cell.today { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.cal-cell .day-num { font-size: 13px; font-weight: 600; }
.cal-cell .day-num.today-num { color: var(--primary); }
.cal-event {
  display: block; font-size: 11px; background: var(--primary-light); color: var(--primary);
  border-radius: 6px; padding: 2px 6px; margin-top: 4px; overflow: hidden;
  white-space: nowrap; text-overflow: ellipsis;
}

/* ---------- Toasts ---------- */
.toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast {
  padding: 12px 18px; border-radius: 10px; color: #fff; font-weight: 500;
  box-shadow: 0 8px 24px rgba(0,0,0,.15); animation: slideIn .25s ease;
  max-width: 340px;
}
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
@keyframes slideIn { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Alerts ---------- */
.alert { padding: 12px 14px; border-radius: 9px; font-size: 14px; margin-bottom: 14px; }
.alert-error { background: var(--danger-bg); color: var(--danger); border: 1px solid #fecaca; }

/* ---------- Login ---------- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%); padding: 20px; }
.login-wrap { width: 100%; max-width: 400px; }
.login-card { background: var(--surface); border-radius: 16px; padding: 32px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.login-logo { text-align: center; margin-bottom: 24px; }
.login-logo h1 { font-size: 22px; margin: 12px 0 4px; }
.login-logo p { color: var(--text-muted); font-size: 14px; }
.login-form label { margin-top: 14px; }
.login-form input { margin-bottom: 4px; }
.login-form .btn { margin-top: 20px; }
.login-hint { margin-top: 20px; text-align: center; font-size: 12px; color: var(--text-muted); border-top: 1px solid var(--border); padding-top: 16px; }
.login-hint code { display: inline-block; background: var(--bg); padding: 4px 8px; border-radius: 6px; margin-top: 4px; font-size: 12px; }

/* ---------- Chart container ---------- */
.chart-box { position: relative; height: 280px; }

/* ---------- Empty state ---------- */
.empty { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.empty svg { margin-bottom: 12px; color: #d1d5db; }

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 820px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: 0 0 30px rgba(0,0,0,.2); }
  .main { margin-left: 0; padding: 18px 16px 32px; }
  .hamburger { display: block; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .cal-grid { grid-template-columns: repeat(7, 1fr); font-size: 12px; }
  .cal-cell { min-height: 70px; padding: 5px; }
  .cal-event { font-size: 10px; padding: 1px 4px; }
}
