:root {
  --kb-primary: #1e40af;
  --kb-primary-dark: #1e3a8a;
  --kb-primary-light: #dbeafe;
  --kb-accent: #0891b2;
  --kb-text: #0f172a;
  --kb-muted: #64748b;
  --kb-bg: #f1f5f9;
  --kb-surface: #ffffff;
  --kb-border: #e2e8f0;
  --kb-danger: #b91c1c;
  --kb-warn: #d97706;
  --kb-ok: #16a34a;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: 'Nunito Sans', -apple-system, BlinkMacSystemFont, sans-serif; background: var(--kb-bg); color: var(--kb-text); }

/* ═══ HEADER ═══ */
.kb-mega-header { background: white; border-bottom: 1px solid var(--kb-border); box-shadow: 0 1px 3px rgba(0,0,0,0.04); position: sticky; top: 0; z-index: 100; }
.mega-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 24px; gap: 12px; flex-wrap: wrap; }
.mega-row-top { border-bottom: 1px solid var(--kb-border); }
.mega-left, .mega-right { display: flex; align-items: center; gap: 12px; }
.logo { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; }
.logo-img { width: 32px; height: 32px; background: linear-gradient(135deg, var(--kb-primary), var(--kb-primary-dark)); color: white; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 16px; }
.logo-text { font-weight: 800; font-size: 14px; letter-spacing: 0.3px; }
.logo-text small { display: block; font-size: 9px; color: var(--kb-muted); font-weight: 600; letter-spacing: 0.5px; }
.section-divider { color: var(--kb-muted); font-weight: 300; }
.section-title { font-weight: 700; font-size: 15px; color: var(--kb-primary-dark); }
.cabinet-selector select { border: 1px solid var(--kb-border); border-radius: 6px; padding: 5px 8px; font-size: 12px; background: white; }
.cabinet-selector label { font-size: 12px; color: var(--kb-muted); font-weight: 600; }
.vsep { width: 1px; height: 20px; background: var(--kb-border); }
.cross-nav a { color: var(--kb-muted); font-size: 12px; text-decoration: none; padding: 4px 10px; border-radius: 6px; }
.cross-nav a:hover { background: #f1f5f9; color: var(--kb-text); }
.user-info { font-size: 12px; color: var(--kb-muted); font-weight: 600; }
.logout-link { text-decoration: none; color: var(--kb-danger); font-size: 16px; padding: 4px 8px; border-radius: 6px; }
.logout-link:hover { background: #fee2e2; }
.mega-row-bottom { padding: 10px 24px; font-size: 12px; color: var(--kb-muted); background: #fafcfd; align-items: center; }

/* ═══ TOOLBAR (nouveau LM, filtres, bulk) ═══ */
.kb-lm-toolbar { display: flex; align-items: center; gap: 10px; flex: 1; flex-wrap: wrap; }
.kb-lm-btn-primary { background: var(--kb-primary); color: white; border: none; border-radius: 6px; padding: 7px 14px; font-size: 13px; font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.kb-lm-btn-primary:hover { background: var(--kb-primary-dark); }
.kb-lm-btn-ghost { background: white; color: var(--kb-primary-dark); border: 1px solid var(--kb-border); border-radius: 6px; padding: 7px 14px; font-size: 13px; font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.kb-lm-btn-ghost:hover { background: var(--kb-primary-light); }
.kb-lm-btn-primary-sm { background: var(--kb-primary); color: white; border: none; border-radius: 5px; padding: 4px 10px; font-size: 11px; font-weight: 700; cursor: pointer; }
.kb-lm-btn-primary-sm:hover { background: var(--kb-primary-dark); }
.kb-lm-btn-secondary { background: white; color: var(--kb-text); border: 1px solid var(--kb-border); border-radius: 6px; padding: 7px 14px; font-size: 13px; font-weight: 600; cursor: pointer; }
.kb-lm-btn-secondary:hover { background: #f8fafc; border-color: var(--kb-primary); color: var(--kb-primary); }
.kb-lm-btn-secondary-sm { background: white; color: var(--kb-primary); border: 1px dashed var(--kb-primary); border-radius: 5px; padding: 4px 10px; font-size: 12px; font-weight: 600; cursor: pointer; margin-top: 6px; }
.kb-lm-btn-icon { background: transparent; border: none; cursor: pointer; padding: 4px 6px; font-size: 15px; border-radius: 4px; }
.kb-lm-btn-icon:hover { background: var(--kb-primary-light); }

/* Bulk dropdown */
.kb-lm-bulk-wrap { position: relative; }
.kb-lm-bulk-menu { position: absolute; top: 100%; right: 0; margin-top: 4px; background: white; border: 1px solid var(--kb-border); border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.1); min-width: 220px; padding: 6px; z-index: 200; display: none; }
.kb-lm-bulk-menu.open { display: block; }
.kb-lm-bulk-menu button { display: block; width: 100%; text-align: left; background: transparent; border: none; padding: 8px 12px; font-size: 13px; cursor: pointer; border-radius: 5px; color: var(--kb-text); }
.kb-lm-bulk-menu button:hover { background: var(--kb-primary-light); color: var(--kb-primary-dark); }

.kb-lm-search { border: 1px solid var(--kb-border); border-radius: 6px; padding: 6px 10px; font-size: 13px; width: 260px; background: white; }
.kb-lm-select { border: 1px solid var(--kb-border); border-radius: 6px; padding: 6px 8px; font-size: 12px; background: white; }
.kb-lm-select-label { font-size: 11px; color: var(--kb-muted); font-weight: 600; margin-right: 4px; }

/* ═══ KPI BANDEAU (compact) ═══ */
main { padding: 14px 20px; max-width: 1400px; margin: 0 auto; }
#kb-lm-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; margin-bottom: 12px; }
.kb-lm-kpi { background: var(--kb-surface); border: 1px solid var(--kb-border); border-left: 4px solid var(--kb-primary); border-radius: 8px; padding: 8px 12px; box-shadow: 0 1px 2px rgba(0,0,0,0.03); }
.kb-lm-kpi-title { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--kb-muted); font-weight: 700; margin-bottom: 2px; }
.kb-lm-kpi-value { font-size: 22px; font-weight: 800; margin-bottom: 1px; line-height: 1.15; }
.kb-lm-kpi-sub { font-size: 10.5px; color: var(--kb-muted); line-height: 1.2; }

/* ═══ MATRICE (compacte) ═══ */
#kb-lm-matrix { background: var(--kb-surface); border: 1px solid var(--kb-border); border-radius: 10px; overflow: hidden; box-shadow: 0 1px 2px rgba(0,0,0,0.03); }
.kb-lm-table { width: 100%; border-collapse: collapse; font-size: 12.5px; line-height: 1.25; }
.kb-lm-table thead th { background: #f8fafc; text-align: left; padding: 6px 10px; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--kb-muted); border-bottom: 1px solid var(--kb-border); font-weight: 700; }
.kb-lm-table tbody td { padding: 5px 10px; border-bottom: 1px solid #eef2f7; vertical-align: middle; }
.kb-lm-table tbody tr:hover { background: #fafcff; }
.kb-lm-table tbody tr:last-child td { border-bottom: none; }
.kb-lm-name { font-weight: 600; line-height: 1.2; }
.kb-lm-sub { font-size: 10.5px; color: var(--kb-muted); line-height: 1.2; margin-top: 1px; }
.kb-lm-code { font-family: 'JetBrains Mono', ui-monospace, monospace; font-size: 12px; color: var(--kb-primary-dark); font-weight: 700; }

.kb-lm-badge { display: inline-block; padding: 2px 8px; border-radius: 9999px; font-size: 10.5px; font-weight: 700; }

/* ═══ DOSSIERS NUS ═══ */
.kb-lm-nus { padding: 16px; border-top: 2px solid var(--kb-warn); background: #fffbeb; }
.kb-lm-nus-head { font-weight: 700; color: #78350f; font-size: 13px; margin-bottom: 12px; }
.kb-lm-nus-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 8px; }
.kb-lm-nu { display: flex; justify-content: space-between; align-items: center; background: white; padding: 10px 12px; border-radius: 6px; border: 1px solid #fde68a; }

/* ═══ MODAL (mov = overlay, mp = panel) ═══ */
.kb-lm-mov { position: fixed; inset: 0; background: rgba(15,23,42,0.55); backdrop-filter: blur(4px); z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 20px; }
.kb-lm-mp { background: var(--kb-surface); width: 100%; max-width: 640px; max-height: 92vh; border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; box-shadow: 0 25px 50px rgba(0,0,0,0.3); }
.kb-lm-mp-head { background: linear-gradient(135deg, var(--kb-primary), var(--kb-primary-dark)); color: white; padding: 14px 20px; display: flex; justify-content: space-between; align-items: center; font-size: 15px; font-weight: 700; flex-shrink: 0; }
.kb-lm-mp-head .kb-lm-close { background: rgba(255,255,255,0.2); border: none; color: white; width: 30px; height: 30px; border-radius: 6px; cursor: pointer; font-size: 16px; }
.kb-lm-mp-body { padding: 20px; overflow-y: auto; flex: 1; }
.kb-lm-mp-foot { padding: 12px 20px; border-top: 1px solid var(--kb-border); display: flex; gap: 10px; justify-content: flex-end; align-items: center; background: #fafcfd; }
.kb-lm-input { width: 100%; border: 1px solid var(--kb-border); border-radius: 6px; padding: 7px 10px; font-size: 13px; box-sizing: border-box; }

.kb-lm-select-list { max-height: 400px; overflow-y: auto; border: 1px solid var(--kb-border); border-radius: 6px; margin-top: 10px; }
.kb-lm-select-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--kb-border); cursor: pointer; }
.kb-lm-select-row:hover { background: var(--kb-primary-light); }
.kb-lm-select-row:last-child { border-bottom: none; }

.kb-lm-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.kb-lm-grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 12px; }
.kb-lm-field { display: flex; flex-direction: column; }
.kb-lm-field label { font-size: 11px; font-weight: 600; color: #374151; margin-bottom: 4px; }
.kb-lm-field input, .kb-lm-field select { border: 1px solid var(--kb-border); border-radius: 5px; padding: 7px 9px; font-size: 13px; background: white; }
.kb-lm-section { font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--kb-primary-dark); margin: 18px 0 10px; font-weight: 800; }

.kb-lm-prestations { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.kb-lm-chk { display: flex; align-items: center; gap: 6px; font-size: 12px; padding: 5px 8px; background: #f8fafc; border-radius: 5px; cursor: pointer; }
.kb-lm-chk input { margin: 0; }

/* Bloc SCI dans le modal */
.kb-lm-sci-block { margin-top: 12px; padding: 10px 12px; background: #f0f9ff; border: 1px solid #bae6fd; border-radius: 6px; }
.kb-lm-sci-title { font-size: 11px; font-weight: 800; color: #0c4a6e; text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 8px; }
.kb-lm-sci-block .kb-lm-chk { background: white; }

/* Badge forme juridique — unifié pour toutes les formes */
.kb-lm-form-badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 10.5px; font-weight: 800; letter-spacing: 0.4px; text-transform: uppercase; white-space: nowrap; }

/* Badge TVA compact (M/T/A/S/—) */
.kb-lm-tva-badge { display: inline-block; width: 22px; text-align: center; padding: 2px 0; border-radius: 4px; font-size: 11px; font-weight: 800; letter-spacing: 0.3px; cursor: help; }

/* Bloc info TVA readonly en tête de modal LM */
.kb-lm-tva-info { background: #f0f9ff; border-left: 3px solid #0891b2; padding: 8px 12px; border-radius: 0 6px 6px 0; margin-bottom: 14px; font-size: 12px; color: #0c4a6e; }
.kb-lm-tva-info strong { color: #075985; }

.kb-lm-actions-cell { display: flex; align-items: center; gap: 2px; white-space: nowrap; }

/* Cellule + badges d'alerte (flags) */
.kb-lm-flags-cell { white-space: nowrap; text-align: center; }
.kb-lm-flag { display: inline-block; padding: 2px 6px; margin: 0 1px; border-radius: 4px; font-size: 11px; cursor: help; line-height: 1; }
.kb-lm-flag:hover { transform: scale(1.15); transition: transform 0.1s; }

/* Badge période (Mois/Trimestre/Année) */
.kb-lm-period-badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 10.5px; font-weight: 700; letter-spacing: 0.3px; }

/* Ligne de filtres par colonne */
.kb-lm-table thead th[data-sort] { user-select: none; }
.kb-lm-table thead th[data-sort]:hover { background: #eef2ff; }
.kb-lm-filter-row th { padding: 4px 6px !important; background: #fafcfd; }
.kb-lm-col-filter { width: 100%; box-sizing: border-box; border: 1px solid var(--kb-border); border-radius: 4px; padding: 3px 6px; font-size: 11px; background: white; font-family: inherit; }
.kb-lm-col-filter:focus { outline: none; border-color: var(--kb-primary); box-shadow: 0 0 0 2px rgba(30,64,175,0.08); }
select.kb-lm-col-filter { padding: 2px 4px; }

/* Menu contextuel (clic droit) */
.kb-lm-ctx { position: fixed; z-index: 2000; min-width: 200px; background: white; border: 1px solid var(--kb-border); border-radius: 8px; box-shadow: 0 10px 24px rgba(15,23,42,0.14); padding: 4px; user-select: none; }
.kb-lm-ctx-item { display: block; width: 100%; text-align: left; background: transparent; border: none; padding: 7px 12px; font-size: 12.5px; cursor: pointer; border-radius: 5px; color: var(--kb-text); font-family: inherit; }
.kb-lm-ctx-item:hover { background: var(--kb-primary-light); color: var(--kb-primary-dark); }
.kb-lm-ctx-item.danger { color: var(--kb-danger); }
.kb-lm-ctx-item.danger:hover { background: #fee2e2; color: var(--kb-danger); }
.kb-lm-ctx-sep { height: 1px; background: var(--kb-border); margin: 4px 6px; }

.lmf-tarif-row { display: grid; grid-template-columns: 1fr 130px 40px; gap: 6px; margin-bottom: 6px; align-items: center; }
.lmf-tarif-row input { border: 1px solid var(--kb-border); border-radius: 5px; padding: 6px 9px; font-size: 12px; }

@media (max-width: 640px) {
  .kb-lm-grid-2, .kb-lm-grid-3 { grid-template-columns: 1fr; }
  .kb-lm-search { width: 100%; }
}

/* ── Création : boutons d'action de ligne + curseur tri ── */
.kb-lm-table thead th[data-sort] { cursor: pointer; }
.kb-lm-actions-cell { justify-content: center; }
.kb-lm-actions-cell button {
  width: 28px; height: 28px; border: 1px solid var(--kb-border);
  background: white; border-radius: 5px; cursor: pointer;
  color: var(--kb-muted); font-size: 14px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
  transition: all 0.12s;
}
.kb-lm-actions-cell button:hover { background: var(--kb-primary-light); border-color: var(--kb-primary); color: var(--kb-primary-dark); }
