/* ============================================================
   CG CARS — Plateforme CRM Leads
   Charte graphique : Blanc / Rouge / Noir
   ------------------------------------------------------------
   NOTE : les variables CSS (--red, --gray-500, etc.) ont été
   remplacées par leurs valeurs réelles dans toutes les règles
   ci-dessous, car certains hébergeurs (dont Hostinger) rejettent
   var(--xxx) dans des propriétés de couleur. La palette de
   référence reste listée ici en commentaire pour la maintenance :

   --red:        #E10E1E
   --red-dark:   #A80B18
   --red-light:  #FDE7E8
   --black:      #131315
   --black-soft: #1E1E21
   --gray-900:   #26262a
   --gray-700:   #4b4b52
   --gray-500:   #8a8a92
   --gray-300:   #d7d7dc
   --gray-200:   #e7e7ea
   --gray-100:   #f2f2f4
   --gray-50:    #f9f9fb
   --white:      #ffffff
   --green:      #1f9d55
   --green-bg:   #e7f7ee
   --orange:     #c9740a
   --orange-bg:  #fdf1de
   --blue:       #1c64d1
   --blue-bg:    #e8f0fd
   --radius:     14px
   --radius-sm:  8px
   --shadow-sm:  0 1px 3px rgba(20,20,22,.08)
   --shadow-md:  0 8px 24px rgba(20,20,22,.10)
   --shadow-lg:  0 20px 45px rgba(20,20,22,.18)
   --sidebar-w:  250px
   --topbar-h:   68px
   --transition: .18s ease
   ============================================================ */

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: 'Inter', 'Segoe UI', Arial, sans-serif;
  background: #f9f9fb;
  color: #131315;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; font-weight: 700; letter-spacing: -.01em; }
p { margin: 0; }
button { font-family: inherit; cursor: pointer; }
a { color: inherit; }
.hidden { display: none !important; }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #d7d7dc; border-radius: 20px; }
::-webkit-scrollbar-thumb:hover { background: #8a8a92; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 20px; border-radius: 8px; border: none;
  font-weight: 600; font-size: .92rem; transition: .18s ease;
  white-space: nowrap;
}
.btn-primary { background: #E10E1E; color: #fff; }
.btn-primary:hover { background: #A80B18; transform: translateY(-1px); }
.btn-dark { background: #131315; color: #fff; }
.btn-dark:hover { background: #26262a; }
.btn-outline { background: transparent; border: 1.5px solid #d7d7dc; color: #131315; }
.btn-outline:hover { border-color: #E10E1E; color: #E10E1E; }
.btn-danger { background: #FDE7E8; color: #A80B18; }
.btn-danger:hover { background: #E10E1E; color: #fff; }
.btn-sm { padding: 7px 12px; font-size: .8rem; border-radius: 7px; }
.btn-block { width: 100%; }
.btn-icon { padding: 9px; border-radius: 9px; background: #f2f2f4; border: none; color: #4b4b52; }
.btn-icon:hover { background: #e7e7ea; color: #131315; }
.btn-link { background: none; border: none; color: #E10E1E; font-weight: 600; font-size: .85rem; margin-top: 14px; }
.btn-link:hover { text-decoration: underline; }

/* ---------- Auth Screens ---------- */
.auth-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(circle at 15% 20%, rgba(225,14,30,.10), transparent 40%),
    radial-gradient(circle at 85% 80%, rgba(19,19,21,.08), transparent 40%),
    #f9f9fb;
  padding: 20px;
}
.auth-card {
  background: #fff; width: 420px; max-width: 100%; padding: 40px 36px;
  border-radius: 20px; box-shadow: 0 20px 45px rgba(20,20,22,.18); text-align: center;
  border-top: 5px solid #E10E1E;
}
.auth-logo { max-width: 190px; margin: 0 auto 22px; display: block; }
.auth-card h1 { font-size: 1.5rem; margin-bottom: 6px; }
.auth-card .subtitle { color: #8a8a92; font-size: .92rem; margin-bottom: 26px; display: block; }
.auth-card p { color: #4b4b52; font-size: .87rem; line-height: 1.5; margin-bottom: 18px; }
.auth-card label { display: block; text-align: left; font-size: .8rem; font-weight: 600; margin: 14px 0 6px; color: #4b4b52; }
.auth-card input[type="text"], .auth-card input[type="password"] {
  width: 100%; padding: 12px 14px; border-radius: 8px; border: 1.5px solid #e7e7ea;
  font-size: .95rem; outline: none; transition: .18s ease;
}
.auth-card input:focus { border-color: #E10E1E; box-shadow: 0 0 0 3px #FDE7E8; }
.auth-card form { margin-top: 4px; }
.form-error {
  background: #FDE7E8; color: #A80B18; padding: 10px 12px; border-radius: 8px;
  font-size: .82rem; margin: 14px 0; text-align: left; font-weight: 500;
}
.hint { font-size: .76rem !important; color: #8a8a92 !important; margin-top: 16px !important; }

/* ---------- App Shell ---------- */
#app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 250px; background: #131315; color: #fff; flex-shrink: 0;
  display: flex; flex-direction: column; position: fixed; top: 0; bottom: 0; left: 0; z-index: 40;
  transition: transform .25s ease;
}
.sidebar-logo { padding: 26px 22px 18px; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar-logo img { max-width: 140px; filter: brightness(0) invert(1); }
.sidebar-nav { flex: 1; padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 12px; background: transparent; border: none;
  color: rgba(255,255,255,.72); padding: 12px 14px; border-radius: 10px; font-size: .9rem; font-weight: 500;
  text-align: left; transition: .18s ease;
}
.nav-item i { width: 18px; text-align: center; font-size: .95rem; }
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: #E10E1E; color: #fff; }
.sidebar-footer { padding: 16px; border-top: 1px solid rgba(255,255,255,.08); }
#logout-btn {
  width: 100%; background: rgba(255,255,255,.06); color: #fff; border: none; padding: 11px;
  border-radius: 10px; font-size: .85rem; font-weight: 600; display: flex; align-items: center; justify-content: center; gap: 8px;
}
#logout-btn:hover { background: #E10E1E; }

.main-wrap { margin-left: 250px; flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: 68px; background: #fff; border-bottom: 1px solid #e7e7ea;
  display: flex; align-items: center; justify-content: space-between; padding: 0 28px;
  position: sticky; top: 0; z-index: 30;
}
.topbar h2 { font-size: 1.15rem; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.user-chip { display: flex; align-items: center; gap: 8px; background: #f2f2f4; padding: 7px 14px; border-radius: 30px; font-size: .85rem; font-weight: 600; }
.user-chip .fa-circle-user { color: #E10E1E; font-size: 1.3rem; }
.role-badge { background: #131315; color: #fff; font-size: .68rem; padding: 2px 9px; border-radius: 20px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
.mobile-menu-btn { display: none; background: none; border: none; font-size: 1.2rem; }

.content { padding: 26px 28px 60px; }
.page { display: none; animation: fadein .25s ease; }
.page.active { display: block; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px);} to { opacity: 1; transform: translateY(0);} }

.page-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 22px; }
.page-header h3 { font-size: 1.3rem; }
.page-header .subtitle { color: #8a8a92; font-size: .88rem; margin-top: 4px; }

/* ---------- KPI Cards ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 24px; }
.kpi-card {
  background: #fff; border-radius: 14px; padding: 20px; box-shadow: 0 1px 3px rgba(20,20,22,.08);
  border: 1px solid #e7e7ea; position: relative; overflow: hidden;
}
.kpi-card::before { content: ''; position: absolute; top: 0; left: 0; width: 4px; height: 100%; background: #E10E1E; }
.kpi-card .kpi-icon { width: 40px; height: 40px; border-radius: 10px; display: flex; align-items: center; justify-content: center; background: #FDE7E8; color: #E10E1E; font-size: 1.05rem; margin-bottom: 14px; }
.kpi-card .kpi-value { font-size: 1.7rem; font-weight: 800; line-height: 1; }
.kpi-card .kpi-label { color: #8a8a92; font-size: .8rem; margin-top: 6px; font-weight: 600; }
.kpi-card-dark { background: linear-gradient(135deg, #131315 0%, #1f1f24 100%); border-color: #131315; }
.kpi-card-dark::before { background: #ffffff; }
.kpi-card-dark .kpi-icon { background: rgba(255,255,255,.1); color: #fff; }
.kpi-card-dark .kpi-value, .kpi-card-dark .kpi-label { color: #fff; }

.charts-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; margin-bottom: 20px; }
.charts-grid.two-col { grid-template-columns: 1fr 1fr; }
.chart-card { background: #fff; border-radius: 14px; padding: 20px; box-shadow: 0 1px 3px rgba(20,20,22,.08); border: 1px solid #e7e7ea; }
.chart-card h4 { font-size: .95rem; margin-bottom: 16px; }
.chart-card .chart-wrap { position: relative; height: 280px; }
.chart-card .chart-wrap.small { height: 220px; }

.upcoming-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; max-height: 280px; overflow-y: auto; }
.upcoming-list li { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; background: #f9f9fb; border-radius: 10px; font-size: .85rem; border-left: 3px solid #E10E1E; }
.upcoming-list .u-name { font-weight: 700; }
.upcoming-list .u-meta { color: #8a8a92; font-size: .76rem; }
.empty-state { text-align: center; color: #8a8a92; font-size: .85rem; padding: 30px 10px; }

/* ---------- Toolbar / Filters ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 18px; background: #fff; padding: 14px; border-radius: 14px; border: 1px solid #e7e7ea; }
.toolbar input, .toolbar select {
  padding: 9px 12px; border-radius: 8px; border: 1.5px solid #e7e7ea; font-size: .85rem; outline: none; background: #fff;
}
.toolbar input:focus, .toolbar select:focus { border-color: #E10E1E; }
.toolbar .search-box { flex: 1; min-width: 180px; position: relative; }
.toolbar .search-box i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: #8a8a92; font-size: .8rem; }
.toolbar .search-box input { width: 100%; padding-left: 34px; }
.toolbar .spacer { flex: 1; }
.results-count { font-size: .8rem; color: #8a8a92; font-weight: 600; }

/* ---------- Table ---------- */
.table-card { background: #fff; border-radius: 14px; border: 1px solid #e7e7ea; overflow: hidden; box-shadow: 0 1px 3px rgba(20,20,22,.08); }
.table-scroll { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: .83rem; min-width: 1450px; }
.data-table thead th {
  background: #131315; color: #fff; text-align: left; padding: 12px 14px; font-weight: 600;
  font-size: .74rem; text-transform: uppercase; letter-spacing: .03em; position: sticky; top: 0; white-space: nowrap;
}
.data-table tbody td { padding: 11px 14px; border-bottom: 1px solid #f2f2f4; white-space: nowrap; color: #26262a; vertical-align: middle; }
.data-table tbody .cell-wrap { max-width: 220px; white-space: normal; word-break: break-word; line-height: 1.35; }
.data-table tbody tr:hover { background: #f9f9fb; }
.data-table tbody tr:last-child td { border-bottom: none; }
.table-footer { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-top: 1px solid #e7e7ea; font-size: .8rem; color: #8a8a92; flex-wrap: wrap; gap: 10px; }
.pagination { display: flex; gap: 6px; }
.pagination button { padding: 6px 12px; border-radius: 7px; border: 1px solid #e7e7ea; background: #fff; font-size: .78rem; }
.pagination .active { background: #E10E1E; color: #fff; border-color: #E10E1E; }

.badge { display: inline-flex; align-items: center; padding: 4px 11px; border-radius: 20px; font-size: .73rem; font-weight: 700; white-space: nowrap; }
.badge-green { background: #e7f7ee; color: #1f9d55; }
.badge-red { background: #FDE7E8; color: #A80B18; }
.badge-orange { background: #fdf1de; color: #c9740a; }
.badge-blue { background: #e8f0fd; color: #1c64d1; }
.badge-gray { background: #f2f2f4; color: #4b4b52; }
.badge-black { background: #131315; color: #fff; }

.avatar-chip { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.avatar-chip .dot { width: 7px; height: 7px; border-radius: 50%; background: #E10E1E; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(19,19,21,.55); display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px; backdrop-filter: blur(2px);
}
.modal-box { background: #fff; border-radius: 18px; width: 100%; max-width: 720px; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 45px rgba(20,20,22,.18); }
.modal-box.modal-sm { max-width: 460px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 26px; border-bottom: 1px solid #e7e7ea; position: sticky; top: 0; background: #fff; z-index: 2; }
.modal-header h3 { font-size: 1.1rem; }
.modal-close { background: #f2f2f4; border: none; width: 32px; height: 32px; border-radius: 50%; font-size: 1rem; color: #4b4b52; }
.modal-close:hover { background: #E10E1E; color: #fff; }
.modal-body { padding: 24px 26px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 18px 26px; border-top: 1px solid #e7e7ea; }

.lead-summary { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px 20px; background: #f9f9fb; border-radius: 12px; padding: 16px 18px; margin-bottom: 20px; font-size: .84rem; }
.lead-summary div .k { display: block; color: #8a8a92; font-size: .72rem; text-transform: uppercase; font-weight: 700; margin-bottom: 3px; letter-spacing: .02em; }
.lead-summary div .v { font-weight: 600; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-field label { display: block; font-size: .78rem; font-weight: 700; margin-bottom: 6px; color: #4b4b52; }
.form-field select, .form-field input, .form-field textarea {
  width: 100%; padding: 10px 12px; border-radius: 9px; border: 1.5px solid #e7e7ea; font-size: .87rem; outline: none; font-family: inherit; background: #fff;
}
.form-field select:focus, .form-field input:focus, .form-field textarea:focus { border-color: #E10E1E; box-shadow: 0 0 0 3px #FDE7E8; }
.form-field textarea { resize: vertical; min-height: 70px; }

/* ---------- Settings / Agents cards ---------- */
.settings-card { background: #fff; border-radius: 14px; padding: 24px; border: 1px solid #e7e7ea; max-width: 560px; margin-bottom: 20px; }
.settings-card h4 { margin-bottom: 14px; }
.info-box { background: #e8f0fd; color: #17427f; border-radius: 10px; padding: 12px 14px; font-size: .82rem; margin-top: 12px; line-height: 1.5; }
.danger-box { background: #FDE7E8; color: #A80B18; border-radius: 10px; padding: 12px 14px; font-size: .82rem; margin-top: 12px; line-height: 1.5; }

/* ---------- Toast ---------- */
#toast-container { position: fixed; top: 20px; right: 20px; z-index: 999; display: flex; flex-direction: column; gap: 10px; }
.toast { background: #131315; color: #fff; padding: 13px 18px; border-radius: 10px; font-size: .85rem; box-shadow: 0 8px 24px rgba(20,20,22,.10); display: flex; align-items: center; gap: 10px; min-width: 240px; animation: slidein .25s ease; }
.toast.success { border-left: 4px solid #1f9d55; }
.toast.error { border-left: 4px solid #E10E1E; }
@keyframes slidein { from { opacity: 0; transform: translateX(30px);} to { opacity: 1; transform: translateX(0);} }

/* ---------- Loader ---------- */
.loader-overlay { position: fixed; inset: 0; background: rgba(255,255,255,.7); display: flex; align-items: center; justify-content: center; z-index: 200; }
.spinner { width: 46px; height: 46px; border: 4px solid #e7e7ea; border-top-color: #E10E1E; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Notifications & Bell ---------- */
.topbar-bell { position: relative; background: #f2f2f4; border: none; width: 40px; height: 40px; border-radius: 50%; color: #4b4b52; font-size: 1rem; display: flex; align-items: center; justify-content: center; }
.topbar-bell:hover { background: #FDE7E8; color: #E10E1E; }
.bell-badge { position: absolute; top: -4px; right: -4px; background: #E10E1E; color: #fff; font-size: .62rem; font-weight: 800; min-width: 17px; height: 17px; border-radius: 20px; display: flex; align-items: center; justify-content: center; padding: 0 4px; border: 2px solid #fff; }
.nav-badge { background: #E10E1E; color: #fff; font-size: .65rem; font-weight: 800; min-width: 18px; height: 18px; border-radius: 20px; display: inline-flex; align-items: center; justify-content: center; padding: 0 5px; margin-left: auto; }

.notif-list { display: flex; flex-direction: column; gap: 10px; }
.notif-item { background: #fff; border: 1px solid #e7e7ea; border-left: 4px solid #d7d7dc; border-radius: 12px; padding: 14px 16px; display: flex; align-items: center; gap: 14px; box-shadow: 0 1px 3px rgba(20,20,22,.08); }
.notif-item.severity-high { border-left-color: #E10E1E; background: #FDE7E8; }
.notif-item.severity-medium { border-left-color: #c9740a; background: #fdf1de; }
.notif-item.severity-low { border-left-color: #1c64d1; }
.notif-icon { width: 38px; height: 38px; border-radius: 10px; background: rgba(0,0,0,.06); display: flex; align-items: center; justify-content: center; flex-shrink: 0; color: #131315; }
.notif-item.severity-high .notif-icon { background: rgba(225,14,30,.15); color: #A80B18; }
.notif-item.severity-medium .notif-icon { background: rgba(201,116,10,.15); color: #c9740a; }
.notif-body { flex: 1; min-width: 0; }
.notif-title { font-weight: 700; font-size: .9rem; }
.notif-detail { font-size: .78rem; color: #8a8a92; margin-top: 2px; }

/* ---------- Ligne RDV à J-2 (surlignage rouge clair) ---------- */
.data-table tbody .row-j2 { background: #ffe2e4; }
.data-table tbody .row-j2:hover { background: #ffd0d3; }
.upcoming-list .upcoming-j2 { background: #ffe2e4; border-left-color: #A80B18; }

/* ---------- Pointeuse ---------- */
.pointeuse-card {
  background: linear-gradient(135deg, #131315 0%, #1f1f24 100%);
  border-radius: 20px;
  padding: 44px 32px;
  max-width: 480px;
  margin: 0 auto;
  text-align: center;
  color: #fff;
  box-shadow: 0 20px 45px rgba(20,20,22,.18);
}
.pointeuse-status { display: flex; align-items: center; justify-content: center; gap: 8px; font-size: .82rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: #8a8a92; margin-bottom: 20px; }
.pointeuse-dot { width: 10px; height: 10px; border-radius: 50%; background: #8a8a92; transition: background .2s ease, box-shadow .2s ease; }
.pointeuse-dot.on { background: #1f9d55; box-shadow: 0 0 0 4px rgba(31,157,85,.25); }
.pointeuse-clock { font-size: 3.1rem; font-weight: 800; letter-spacing: .02em; font-variant-numeric: tabular-nums; }
.pointeuse-date { color: #8a8a92; font-size: .88rem; margin-top: 6px; text-transform: capitalize; }
.pointeuse-session { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 28px 0 8px; padding: 18px 8px; background: rgba(255,255,255,.07); border-radius: 14px; }
.pointeuse-session-value { font-size: 1.2rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.pointeuse-session-label { font-size: .68rem; color: #8a8a92; margin-top: 4px; text-transform: uppercase; letter-spacing: .03em; }
.pointeuse-btn { margin-top: 22px; padding: 14px; font-size: .95rem; }
@media (max-width: 560px) {
  .pointeuse-card { padding: 32px 20px; }
  .pointeuse-clock { font-size: 2.4rem; }
  .pointeuse-session { grid-template-columns: 1fr; }
}

/* ---------- Listes statistiques (voiture / wilaya) avec pourcentage ---------- */
.stat-list { list-style: none; margin: 16px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow-y: auto; }
.stat-item { display: flex; align-items: center; gap: 8px; font-size: .82rem; padding: 6px 8px; border-radius: 8px; }
.stat-item:hover { background: #f9f9fb; }
.stat-item.empty { color: #8a8a92; justify-content: center; }
.stat-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.stat-name { flex: 1; font-weight: 600; color: #26262a; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-value { font-weight: 800; color: #131315; }
.stat-pct { color: #8a8a92; font-weight: 600; font-size: .78rem; min-width: 52px; text-align: right; }

/* ---------- Heatmap Algérie (Leaflet) ---------- */
#algeria-heatmap { border: 1px solid #e7e7ea; }
.heatmap-legend { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 12px; font-size: .8rem; color: #4b4b52; font-weight: 600; }
.heatmap-legend .legend-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.leaflet-tooltip { font-family: 'Inter', sans-serif; font-size: .78rem; }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .charts-grid, .charts-grid.two-col { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .lead-summary { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-wrap { margin-left: 0; }
  .mobile-menu-btn { display: inline-flex; }
}
@media (max-width: 520px) {
  .auth-card { padding: 30px 22px; }
  .content { padding: 18px 14px 50px; }
  .topbar { padding: 0 14px; }
  .user-chip span:not(.role-badge) { display: none; }
}