/* ========== Design system ========== */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-50: #eff6ff;
  --primary-100: #dbeafe;
  --paye: #059669;
  --paye-bg: #ecfdf5;
  --paye-soft: #d1fae5;
  --echu: #dc2626;
  --echu-bg: #fef2f2;
  --echu-soft: #fee2e2;
  --attente: #d97706;
  --attente-bg: #fffbeb;
  --attente-soft: #fef3c7;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .04);
  --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 4px 12px rgba(15, 23, 42, .04);
  --shadow-lg: 0 20px 50px rgba(15, 23, 42, .15);
  --radius: 12px;
  --radius-lg: 16px;
  --radius-sm: 8px;
  --transition: .18s cubic-bezier(.4, 0, .2, 1);
}
html, body {
  font-family: "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  font-feature-settings: "cv11", "ss01", "ss03";
  -webkit-font-smoothing: antialiased;
}
#app { display: flex; height: 100vh; }

/* ========== Sidebar ========== */
.sidebar {
  width: 244px;
  background: linear-gradient(165deg, #4338ca 0%, #2563eb 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 22px 14px 16px;
  position: relative;
}
.sidebar::after {
  content: ''; position: absolute; right: 0; top: 0; bottom: 0; width: 1px;
  background: linear-gradient(180deg, rgba(255,255,255,.2), transparent);
}
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; padding: 0 6px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 11px;
  background: rgba(255,255,255,.18); backdrop-filter: blur(8px);
  color: #fff; font-weight: 800; display: flex; align-items: center; justify-content: center;
  font-size: 17px; box-shadow: inset 0 1px 0 rgba(255,255,255,.25);
}
.brand-title { font-weight: 700; font-size: 15px; letter-spacing: -0.01em; }
.brand-sub { font-size: 11px; opacity: .75; margin-top: 2px; }
nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  background: transparent; border: 0; color: rgba(255,255,255,.85);
  text-align: left; padding: 10px 13px; border-radius: 9px;
  font-size: 13.5px; cursor: pointer; transition: var(--transition);
  font-family: inherit; font-weight: 500;
}
.nav-item:hover { background: rgba(255,255,255,.12); color: #fff; }
.nav-item.active {
  background: #fff; color: var(--primary); font-weight: 600;
  box-shadow: 0 4px 12px rgba(15, 23, 42, .15);
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar-footer {
  display: flex; flex-direction: column; gap: 5px; font-size: 11.5px;
  opacity: .9; padding: 12px 6px 0; border-top: 1px solid rgba(255,255,255,.15);
}
.legend { display: flex; align-items: center; gap: 8px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot-paye { background: #34d399; box-shadow: 0 0 8px rgba(52, 211, 153, .6); }
.dot-echu { background: #f87171; box-shadow: 0 0 8px rgba(248, 113, 113, .6); }
.dot-attente { background: #fbbf24; box-shadow: 0 0 8px rgba(251, 191, 36, .6); }

/* ========== Layout ========== */
.content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 28px; background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 21px; font-weight: 700; letter-spacing: -0.02em; }
#topbar-actions { display: flex; gap: 8px; align-items: center; }
#view-root { flex: 1; overflow: auto; padding: 24px 28px; }
#view-root::-webkit-scrollbar { width: 10px; height: 10px; }
#view-root::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 8px; }
#view-root::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ========== Boutons ========== */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid transparent; border-radius: 9px;
  padding: 9px 15px; font-size: 13.5px; font-weight: 600;
  cursor: pointer; transition: var(--transition); font-family: inherit;
  white-space: nowrap;
}
.btn:focus-visible { outline: 3px solid rgba(37, 99, 235, .3); outline-offset: 1px; }
.btn svg { width: 15px; height: 15px; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-1px); box-shadow: var(--shadow); }
.btn-light {
  background: var(--surface-2); color: var(--text); border-color: var(--border);
}
.btn-light:hover { background: #eef2f7; border-color: var(--border-strong); }
.btn-danger { background: var(--echu-bg); color: var(--echu); border-color: var(--echu-soft); }
.btn-danger:hover { background: var(--echu-soft); }
.btn-success { background: var(--paye-bg); color: var(--paye); border-color: var(--paye-soft); }
.btn-success:hover { background: var(--paye-soft); }
.btn-ghost { background: transparent; color: var(--muted); border-color: transparent; padding: 6px 10px; }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: 6px 10px; font-size: 12px; gap: 5px; }
.btn-sm svg { width: 13px; height: 13px; }

/* ========== Cards stats ========== */
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 22px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 18px 20px;
  box-shadow: var(--shadow-sm); transition: var(--transition);
  position: relative; overflow: hidden;
}
.card:hover { box-shadow: var(--shadow); transform: translateY(-2px); }
.card .card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.card .label { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.card .card-icon {
  width: 34px; height: 34px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
}
.card .card-icon svg { width: 18px; height: 18px; }
.card .value { font-size: 22px; font-weight: 800; letter-spacing: -0.025em; }
.card .sub { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.card.total .card-icon { background: var(--primary-100); color: var(--primary); }
.card.paye .card-icon { background: var(--paye-soft); color: var(--paye); }
.card.echu .card-icon { background: var(--echu-soft); color: var(--echu); }
.card.attente .card-icon { background: var(--attente-soft); color: var(--attente); }
.card.echu { border-color: var(--echu-soft); }

/* Mini progression */
.mini-bar { margin-top: 10px; height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.mini-bar > span { display: block; height: 100%; border-radius: 999px; transition: width .6s ease; }
.mini-bar.paye > span { background: var(--paye); }
.mini-bar.echu > span { background: var(--echu); }
.mini-bar.attente > span { background: var(--attente); }

/* Tableau de bord — bloc 2 colonnes */
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 1100px) { .dash-grid { grid-template-columns: 1fr; } }

/* ========== Panels & tables ========== */
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  gap: 12px; flex-wrap: wrap;
}
.panel-head h2 { font-size: 15px; font-weight: 700; letter-spacing: -0.01em; }
.panel-head .panel-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.panel-head > svg {
  width: 22px; height: 22px;
  color: var(--muted);
  flex-shrink: 0;
  padding: 6px; box-sizing: content-box;
  background: var(--surface-2);
  border-radius: 10px;
}
.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.filters select, .filters input { padding: 7px 10px; font-size: 13px; }
.panel + .panel { margin-top: 18px; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 16px; text-align: left; font-size: 13px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th {
  background: var(--surface-2); color: var(--muted);
  font-weight: 600; text-transform: uppercase;
  font-size: 10.5px; letter-spacing: .04em;
  position: sticky; top: 0; z-index: 1;
}
tbody tr { transition: background .15s; }
tbody tr:hover { background: var(--surface-2); }
.row-paye { background: var(--paye-bg) !important; }
.row-echu { background: var(--echu-bg) !important; }
.row-attente { background: var(--attente-bg) !important; }
.client-group td {
  background: var(--primary-50);
  font-weight: 700; color: var(--primary);
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em;
  padding: 10px 16px;
}

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.01em;
}
.badge svg { width: 11px; height: 11px; }
.badge-paye { background: var(--paye-soft); color: var(--paye); }
.badge-echu { background: var(--echu-soft); color: var(--echu); }
.badge-attente { background: var(--attente-soft); color: var(--attente); }
.badge-annule { background: #e2e8f0; color: var(--muted); }
.badge-alert {
  background: var(--echu); color: #fff;
  padding: 2px 7px; font-size: 10.5px; margin-left: 6px;
  border-radius: 999px;
}

.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.empty { padding: 48px 24px; text-align: center; color: var(--muted); font-size: 14px; }

/* Top clients */
.top-list { padding: 8px 0; }
.top-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 20px; border-bottom: 1px solid var(--border);
  transition: var(--transition);
}
.top-item:last-child { border-bottom: 0; }
.top-item:hover { background: var(--surface-2); }
.top-rank {
  width: 26px; height: 26px; border-radius: 8px;
  background: var(--primary-100); color: var(--primary);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 12px; margin-right: 12px;
}
.top-rank.gold { background: #fef3c7; color: #b45309; }
.top-rank.silver { background: #e2e8f0; color: #475569; }
.top-rank.bronze { background: #fce7d3; color: #9a3412; }
.top-info { flex: 1; }
.top-name { font-weight: 600; font-size: 13.5px; }
.top-meta { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.top-amount { font-weight: 700; font-size: 14px; }

/* Alertes factures à surveiller */
.alert-list { padding: 4px 0; }
.alert-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 20px; border-bottom: 1px solid var(--border);
  border-left: 3px solid var(--echu);
}
.alert-item:last-child { border-bottom: 0; }
.alert-num { font-weight: 700; color: var(--text); font-size: 13px; }
.alert-meta { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.alert-days {
  color: var(--echu); font-weight: 700; font-size: 12px;
  background: var(--echu-bg); padding: 3px 9px; border-radius: 999px;
}

/* ========== Forms ========== */
input, select, textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: 13.5px;
  font-family: inherit; background: #fff; color: var(--text);
  transition: var(--transition);
}
input:hover, select:hover, textarea:hover { border-color: var(--border-strong); }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}
label {
  display: block; font-size: 12.5px; font-weight: 600;
  margin-bottom: 6px; color: var(--text);
}
label small { font-weight: 400; }
.field { margin-bottom: 14px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }

/* ========== Modal ========== */
#modal-root.show { display: flex; animation: fadeIn .15s ease; }
#modal-root {
  display: none; position: fixed; inset: 0;
  background: rgba(15, 23, 42, .5); backdrop-filter: blur(4px);
  align-items: flex-start; justify-content: center; z-index: 50;
  overflow: auto; padding: 40px 16px;
}
.modal {
  background: #fff; border-radius: var(--radius-lg);
  width: 100%; max-width: 760px;
  box-shadow: var(--shadow-lg);
  animation: slideUp .2s cubic-bezier(.4, 0, .2, 1);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(15px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.modal-body { padding: 22px; max-height: 65vh; overflow: auto; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 16px 22px; border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.x-close {
  background: none; border: 0; cursor: pointer; color: var(--muted);
  padding: 6px; border-radius: 8px; transition: var(--transition);
  display: flex;
}
.x-close:hover { background: var(--surface-2); color: var(--text); }
.x-close svg { width: 18px; height: 18px; }

/* Lignes facture */
.lignes-table { width: 100%; margin-bottom: 10px; }
.lignes-table th, .lignes-table td { padding: 6px; border: 0; background: transparent; }
.lignes-table th { padding-top: 0; }
.lignes-table input { padding: 7px 9px; font-size: 13px; }
.line-total { font-weight: 700; padding: 8px; font-size: 13.5px; }
.totaux-box {
  margin-top: 12px; text-align: right; font-size: 13px;
  padding: 14px 16px; background: var(--surface-2);
  border-radius: var(--radius-sm); color: var(--muted);
}
.totaux-box .grand {
  display: block; margin-top: 6px;
  font-size: 19px; font-weight: 800;
  color: var(--primary); letter-spacing: -0.02em;
}

/* Toast */
#toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 100;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast-item {
  background: var(--text); color: #fff;
  padding: 12px 18px; border-radius: var(--radius-sm);
  font-size: 13.5px; box-shadow: var(--shadow-lg);
  animation: slidein .25s ease;
  display: flex; align-items: center; gap: 8px;
  pointer-events: auto;
}
.toast-item.error { background: var(--echu); }
.toast-item.success { background: var(--paye); }
@keyframes slidein { from { transform: translateX(50px); opacity: 0; } to { transform: none; opacity: 1; } }

.input-sm { display: inline-block; width: auto; min-width: 160px; }

/* Spinner pour le chargement bootstrap */
.loader-spin {
  width: 38px; height: 38px; margin: 14px auto 8px;
  border: 3px solid rgba(37, 99, 235, .15);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ========== Écran de verrouillage ========== */
#lock-screen {
  position: fixed; inset: 0; z-index: 200;
  background: linear-gradient(135deg, #1e3a8a 0%, #3730a3 100%);
  display: none; align-items: center; justify-content: center;
  padding: 24px;
}
#lock-screen.show { display: flex; animation: fadeIn .25s ease; }
.lock-card {
  background: var(--surface); border-radius: 18px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .3);
  padding: 38px 32px; width: 100%; max-width: 380px;
  animation: slideUp .3s cubic-bezier(.4, 0, .2, 1);
}
.lock-logo {
  width: 64px; height: 64px; border-radius: 18px;
  background: linear-gradient(135deg, #4338ca, #2563eb);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 22px; margin: 0 auto 20px;
  box-shadow: 0 10px 25px rgba(37, 99, 235, .35);
}
.lock-title { text-align: center; font-size: 19px; font-weight: 700; letter-spacing: -0.02em; }
.lock-sub { text-align: center; color: var(--muted); font-size: 13px; margin-top: 6px; margin-bottom: 24px; }
.lock-card .field { margin-bottom: 16px; }
.lock-card input { padding: 12px 14px; font-size: 14.5px; }
.lock-card .btn { width: 100%; justify-content: center; padding: 11px 16px; font-size: 14.5px; }
.lock-error { color: var(--echu); font-size: 12.5px; min-height: 18px; margin-top: -4px; margin-bottom: 6px; text-align: center; }
.lock-foot { text-align: center; color: rgba(255,255,255,.65); font-size: 11.5px; margin-top: 18px; }

/* Bouton verrouiller dans la topbar */
.btn-lock {
  background: transparent; color: var(--muted);
  border: 1px solid var(--border);
}
.btn-lock:hover { background: var(--echu-bg); color: var(--echu); border-color: var(--echu-soft); }
.section-title {
  font-size: 12.5px; font-weight: 700; color: var(--primary);
  text-transform: uppercase; letter-spacing: .06em;
  padding: 18px 0 10px; border-top: 1px dashed var(--border);
  margin-top: 14px;
}
.section-title:first-of-type { border-top: 0; padding-top: 4px; margin-top: 0; }
.hr { height: 1px; background: var(--border); margin: 18px 0; }
.muted { color: var(--muted); font-size: 12.5px; }
