#theme-toggle {
  position: fixed; top: 10px; right: 16px; z-index: 1000;
  display: flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 40px;
  background: var(--theme-sidebar); color: #fff;
  border: 1px solid rgba(255,255,255,0.12);
  font-family: 'Inter', sans-serif; font-size: 0.75rem; font-weight: 600;
  cursor: pointer; box-shadow: 0 2px 10px rgba(0,0,0,0.2);
  transition: transform 0.2s, box-shadow 0.2s;
}
#theme-toggle:hover { transform: translateY(1px); box-shadow: 0 4px 16px rgba(0,0,0,0.25); }
#theme-toggle svg { width: 13px; height: 13px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

#theme-panel {
  position: fixed; top: 48px; right: 16px; z-index: 999;
  background: #fff; border: 1px solid #e8e8ed;
  border-radius: 16px; padding: 0;
  box-shadow: 0 12px 40px rgba(0,0,0,0.15);
  width: 320px; overflow: hidden;
  display: none; animation: slideUp 0.2s ease;
}
#theme-panel.open { display: block; }
@keyframes slideUp { from { opacity:0; transform:translateY(10px); } to { opacity:1; transform:translateY(0); } }

.tp-head {
  padding: 14px 16px; border-bottom: 1px solid #e8e8ed;
  display: flex; align-items: center; justify-content: space-between;
}
.tp-head h4 { font-family:'Inter',sans-serif; font-size:0.8rem; font-weight:700; color:#0d0f1a; }
.tp-head button { background:none; border:none; cursor:pointer; color:#7c8098; font-size:1rem; padding:2px 6px; border-radius:5px; }
.tp-head button:hover { background:#f8f8f9; }

.tp-themes { padding: 12px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.theme-card {
  border: 2px solid #e8e8ed; border-radius: 10px;
  overflow: hidden; cursor: pointer; transition: all 0.15s;
}
.theme-card:hover { border-color: #b0b3c6; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,0.08); }
.theme-card.active { border-color: var(--theme-accent); box-shadow: 0 0 0 3px var(--theme-accent-light); }

.tc-preview {
  height: 54px; display: flex; overflow: hidden;
}
.tc-sidebar { width: 28%; display: flex; flex-direction:column; padding: 4px; gap: 3px; }
.tc-sidebar-dot { height: 3px; border-radius: 2px; background: rgba(255,255,255,0.25); }
.tc-sidebar-dot.active { background: rgba(255,255,255,0.7); }
.tc-content { flex:1; padding: 4px; display: flex; flex-direction: column; gap: 3px; }
.tc-bar { height: 3px; border-radius: 2px; }
.tc-bar.w-full { width: 100%; }
.tc-bar.w-half { width: 55%; }
.tc-bar.accent { opacity: 0.9; }

.tc-label {
  padding: 6px 8px;
  font-family: 'Inter', sans-serif; font-size: 0.68rem; font-weight: 600;
  color: #3a3d52; background: #f8f8f9; border-top: 1px solid #e8e8ed;
}

.tp-divider { height: 1px; background: #e8e8ed; margin: 0 12px; }
.tp-footer { padding: 10px 12px; display: flex; gap: 8px; }
.tp-footer button {
  flex:1; padding: 7px; border-radius: 8px;
  font-family:'Inter',sans-serif; font-size:0.73rem; font-weight:600;
  cursor:pointer; transition: all 0.15s;
}
.btn-apply { background: var(--theme-accent); color:#fff; border:none; }
.btn-apply:hover { opacity: 0.88; }
.btn-reset { background: #f8f8f9; color:#3a3d52; border:1px solid #e8e8ed; }
.btn-reset:hover { border-color:#d0d0da; }

/* ══════════════════════════════════════════════════════════════════════
   Onglet Statistiques
   ══════════════════════════════════════════════════════════════════════ */

.stats-wrap { padding: 24px 28px 40px; max-width: 1400px; margin: 0 auto; }

.stats-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 12px; margin-bottom: 22px;
}
.stats-scope-note { font-size: 0.8rem; color: var(--ink3); font-weight: 500; }
.stats-toolbar-right { display: flex; align-items: center; gap: 10px; }
#stats-period, #stats-soc {
  padding: 7px 14px; border-radius: 20px; border: 1.5px solid var(--border);
  font-size: 0.8rem; font-family: inherit; font-weight: 600; color: var(--ink2);
  background: var(--white); cursor: pointer; outline: none;
  transition: border-color .15s;
}
#stats-period:hover, #stats-period:focus,
#stats-soc:hover, #stats-soc:focus { border-color: var(--theme-accent); }

.stats-empty, .stats-loading {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 80px 20px; text-align: center; color: var(--ink3);
}
.stats-empty-icon { font-size: 2.6rem; margin-bottom: 12px; opacity: .6; }
.stats-empty h3 { color: var(--ink2); font-size: 1.05rem; margin-bottom: 6px; }
.stats-empty p { font-size: 0.85rem; max-width: 340px; }

.stats-spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--theme-accent-light); border-top-color: var(--theme-accent);
  animation: stats-spin 0.8s linear infinite; margin-bottom: 14px;
}
@keyframes stats-spin { to { transform: rotate(360deg); } }

/* KPI cards */
.stats-kpi-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 16px; margin-bottom: 24px;
}
.stats-kpi-card {
  background: var(--white); border-radius: var(--r); padding: 18px 20px;
  border: 1px solid var(--border); position: relative; overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
  transition: transform .15s, box-shadow .15s;
}
.stats-kpi-card:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,.08); }
.stats-kpi-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
}
.stats-kpi-teal::before   { background: var(--theme-accent); }
.stats-kpi-gold::before   { background: var(--gold); }
.stats-kpi-violet::before { background: var(--violet); }
.stats-kpi-red::before    { background: var(--red); }
.stats-kpi-green::before  { background: var(--green); }

.stats-kpi-icon { font-size: 1.3rem; margin-bottom: 8px; opacity: .85; }
.stats-kpi-value {
  font-family: 'JetBrains Mono', monospace; font-size: 1.65rem; font-weight: 700;
  color: var(--ink); line-height: 1.1; margin-bottom: 4px;
  font-variant-numeric: tabular-nums;
}
.stats-kpi-label { font-size: 0.74rem; color: var(--ink3); font-weight: 600; letter-spacing: .01em; }

/* Charts grid */
.stats-charts-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px;
}
.stats-chart-card {
  background: var(--white); border-radius: var(--r); padding: 18px 20px;
  border: 1px solid var(--border); box-shadow: 0 1px 3px rgba(0,0,0,.04);
}
.stats-chart-wide { grid-column: 1 / -1; }
.stats-chart-title {
  font-size: 0.85rem; font-weight: 700; color: var(--ink2); margin-bottom: 14px;
}
.stats-chart-canvas-wrap { position: relative; width: 100%; }

@media (max-width: 900px) {
  .stats-charts-grid { grid-template-columns: 1fr; }
  .stats-chart-wide { grid-column: auto; }
}

/* Bouton suppression de document (visible admin uniquement, voir 05_gemini_save.js) */
.btn-delete-doc {
  padding: 8px 16px; border-radius: var(--r-sm); border: 1.5px solid var(--red);
  background: var(--red-light); color: var(--red); font-size: 0.82rem; font-weight: 700;
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  transition: background .15s, color .15s;
}
.btn-delete-doc:hover { background: var(--red); color: #fff; }


/* ══ GALERIE ═══════════════════════════════════════════════ */
#view-galerie { padding: 16px 20px 40px; }
.gal-toolbar {
  position: sticky; top: 0; z-index: 5; display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  padding: 10px 0 14px; background: var(--paper);
}
.gal-select, .gal-search {
  border: 1.5px solid var(--border); border-radius: var(--r-sm); padding: 7px 10px;
  font-family: 'Inter', sans-serif; font-size: 0.85rem; background: var(--white); color: var(--ink); outline: none;
}
.gal-search { flex: 1; min-width: 220px; max-width: 420px; }
.gal-select:focus, .gal-search:focus { border-color: var(--theme-accent); }
.gal-nb { font-size: 0.8rem; color: var(--ink3); font-weight: 600; }
.gal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 16px; }
.gal-card {
  background: var(--white); border: 1px solid var(--border); border-radius: var(--r);
  overflow: hidden; cursor: pointer; display: flex; flex-direction: column;
  transition: transform .12s, box-shadow .12s, border-color .12s; outline: none;
}
.gal-card:hover, .gal-card:focus { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,0,0,0.12); border-color: var(--theme-accent); }
.gal-thumb {
  aspect-ratio: 1 / 1.414; background: #eceae4; display: flex; align-items: center; justify-content: center;
  overflow: hidden; border-bottom: 1px solid var(--border);
}
.gal-thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; }
.gal-load { width: 22px; height: 22px; border: 2px solid rgba(0,0,0,0.12); border-top-color: var(--theme-accent); border-radius: 50%; animation: spin .8s linear infinite; }
.gal-noimg { font-size: 0.75rem; color: var(--ink3); text-align: center; padding: 10px; }
.gal-info { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 4px; }
.gal-fourn { font-size: 0.8rem; font-weight: 700; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gal-meta { display: flex; justify-content: space-between; font-size: 0.74rem; color: var(--ink3); }
.gal-meta strong { color: var(--ink); }
.gal-statut .badge { font-size: 0.66rem; }
.gal-vide { grid-column: 1 / -1; text-align: center; color: var(--ink3); padding: 40px; font-size: 0.9rem; }
#gal-sentinel { grid-column: 1 / -1; height: 1px; }

/* ── Visite guidée (driver.js) : suit le thème ── */
.driver-popover.cv-visite { background: var(--surface, #fff); color: var(--text, #1a1a1a); border: 1.5px solid var(--theme-accent, #c9a84c); border-radius: 12px; font-family: 'Inter', sans-serif; max-width: 340px; }
.driver-popover.cv-visite .driver-popover-title { font-family: 'Syne', 'Inter', sans-serif; font-weight: 800; font-size: 1rem; }
.driver-popover.cv-visite .driver-popover-description { font-size: .85rem; line-height: 1.45; color: var(--text, #1a1a1a); }
.driver-popover.cv-visite .driver-popover-progress-text { color: var(--text-muted, #777); }
.driver-popover.cv-visite button { font-family: inherit; border-radius: 8px; text-shadow: none; }
.driver-popover.cv-visite .driver-popover-next-btn { background: var(--theme-accent, #c9a84c); color: #fff; border: 0; padding: 6px 14px; }
.driver-popover.cv-visite .driver-popover-prev-btn { background: transparent; color: var(--text, #1a1a1a); border: 1px solid var(--border, #ccc); }
.driver-popover.cv-visite .driver-popover-arrow-side-left.driver-popover-arrow, .driver-popover.cv-visite .driver-popover-arrow-side-right.driver-popover-arrow { border-color: transparent; }

/* ══ Modernisation : icônes, boîtes de dialogue, tableau, squelettes de chargement ══ */

/* Icônes Lucide dans le menu (même taille que les anciennes) */
.nav-btn svg.lucide { width: 16px; height: 16px; stroke-width: 1.9; }

/* Boîtes de dialogue SweetAlert2 aux couleurs du thème */
.swal2-container { z-index: 10040; }
.swal2-popup.cv-swal { background: var(--white); color: var(--ink); border-radius: 16px; font-family: 'Inter', sans-serif; padding: 1.6rem 1.4rem 1.3rem; box-shadow: 0 24px 70px rgba(0,0,0,.28); }
.swal2-popup.cv-swal .swal2-title { font-family: 'Syne', 'Inter', sans-serif; font-weight: 800; font-size: 1.15rem; color: var(--ink); }
.swal2-popup.cv-swal .swal2-html-container { color: var(--ink); }
.swal2-popup.cv-swal .swal2-styled { border-radius: 10px; font-weight: 700; font-size: .88rem; padding: 9px 22px; box-shadow: none; }
.swal2-popup.cv-swal .swal2-confirm { background: var(--theme-accent); }
.swal2-popup.cv-swal .swal2-cancel { background: transparent; color: var(--ink); border: 1.5px solid var(--border); }
.swal2-popup.cv-swal .swal2-styled:focus { box-shadow: 0 0 0 3px color-mix(in srgb, var(--theme-accent) 30%, transparent); }

/* Tableau des factures : plus aéré, plus doux */
.cv-dashboard .dataTables_wrapper, .cv-dashboard .dt-container { border-radius: 14px; box-shadow: 0 1px 3px rgba(0,0,0,.05), 0 8px 24px rgba(0,0,0,.04); }
.cv-dashboard table.dataTable { border-collapse: separate; border-spacing: 0; }
.cv-dashboard table.dataTable thead th { padding: 12px 14px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; font-size: .7rem; }
.cv-dashboard table.dataTable thead th:first-child { border-top-left-radius: 10px; }
.cv-dashboard table.dataTable thead th:last-child { border-top-right-radius: 10px; }
.cv-dashboard table.dataTable tbody td { padding: 11px 14px; border-bottom: 1px solid var(--border); border-top: 0; font-size: .85rem; transition: background-color .12s; }
.cv-dashboard table.dataTable tbody tr { cursor: pointer; }
.cv-dashboard table.dataTable tbody tr:hover td { background: color-mix(in srgb, var(--theme-accent) 7%, transparent); }
.cv-dashboard table.dataTable tbody tr:last-child td { border-bottom: 0; }
.cv-dashboard .badge { padding: 4px 10px; font-size: .72rem; letter-spacing: .01em; }
.cv-dashboard .dt-button { border-radius: 10px !important; padding: 8px 16px !important; font-weight: 600 !important; box-shadow: 0 1px 2px rgba(0,0,0,.12) !important; transition: transform .12s, box-shadow .12s !important; }
.cv-dashboard .dt-button:not(:disabled):hover { transform: translateY(-1px); box-shadow: 0 4px 10px rgba(0,0,0,.18) !important; }
.cv-kpi-card { border-radius: 14px; transition: transform .15s, box-shadow .15s; }
.cv-kpi-card:hover { transform: translateY(-2px); box-shadow: 0 8px 22px rgba(0,0,0,.1); }

/* Squelettes de chargement (zones grises animées) */
@keyframes cv-skel-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.cv-skel { background: linear-gradient(90deg, var(--border) 25%, color-mix(in srgb, var(--border) 40%, var(--white)) 50%, var(--border) 75%); background-size: 200% 100%; animation: cv-skel-shimmer 1.4s linear infinite; border-radius: 12px; }
.gal-skel { aspect-ratio: 3 / 4.2; }
@media (prefers-reduced-motion: reduce) { .cv-skel { animation: none; } .cv-kpi-card, .cv-dashboard .dt-button { transition: none; } }

/* ══ En-tête du menu latéral ══ */
#sidebar-toggle { position: absolute; top: 14px; right: 12px; width: 26px; height: 26px; padding: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.06); border: 0; border-radius: 8px; cursor: pointer; color: rgba(255,255,255,.55); font-size: .95rem; line-height: 1; transition: background .15s, color .15s; z-index: 2; }
#sidebar-toggle:hover { background: rgba(255,255,255,.14); color: #fff; }
.sidebar-brand { display: flex; align-items: center; gap: 12px; padding: 0 1.25rem 1.25rem; margin-top: .4rem; }
.sidebar-mark { width: 40px; height: 40px; flex-shrink: 0; margin: 0; border-radius: 12px; color: #fff; font-family: 'Syne', 'Inter', sans-serif; font-weight: 800; font-size: 1rem; letter-spacing: -.04em;
  background: linear-gradient(135deg, var(--theme-accent), color-mix(in srgb, var(--theme-accent) 55%, #000)); box-shadow: 0 4px 14px color-mix(in srgb, var(--theme-accent) 45%, transparent), inset 0 1px 0 rgba(255,255,255,.25); }
.sidebar-brand-txt { min-width: 0; }
.sidebar-brand h2 { font-size: 1.02rem; line-height: 1.15; }
.sidebar-brand p { font-size: .72rem; color: var(--sidebar-text-muted, rgba(255,255,255,.5)); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Menu réduit : la barre fine garde son bouton */
.sidebar.collapsed #sidebar-toggle { position: static; width: 18px; height: 100%; border-radius: 0; background: transparent; }

/* Logo iDemat dans le menu (version blanche, menus sombres) */
.sidebar-brand { display: block; padding: .2rem 1.25rem 1.25rem; margin-top: .9rem; }
.sidebar-logo { display: block; width: 168px; max-width: 100%; height: auto; }
.sidebar-brand p { margin: 8px 0 0 2px; font-size: .68rem; letter-spacing: .16em; text-transform: uppercase; color: rgba(255,255,255,.55); }

/* ══ Tableau de bord : harmonisation (icônes, cartes, boutons, champs) ══ */
.cv-dashboard svg.lucide { width: 14px; height: 14px; stroke-width: 2; vertical-align: -2px; margin-right: 3px; flex-shrink: 0; }
.cv-kpi-label svg.lucide, .cv-dashboard .cv-stat-card h3 svg.lucide { color: var(--theme-accent); }

/* Cartes du haut : même arrondi que les KPI */
.cv-dashboard .cv-stat-card { border-radius: 14px; box-shadow: 0 1px 3px rgba(0,0,0,.05); padding: 16px 18px; }

/* Barre d'outils : boutons en pastille, comme le reste */
.cv-dashboard .cv-reload { border-radius: 20px; padding: 6px 14px; font-size: .8rem; font-weight: 600; }

/* Boutons d'export : une seule couleur (thème) ; "sélection" en contour ; désactivé en gris */
.cv-dashboard .dt-button,
.cv-dashboard .dt-button.export-comptable { background: var(--theme-accent) !important; color: #fff !important; border: 1.5px solid var(--theme-accent) !important; }
.cv-dashboard .dt-button.export-selected { background: var(--white) !important; color: var(--theme-accent) !important; }
.cv-dashboard .dt-button.export-selected:not(:disabled):not(.disabled):hover { background: color-mix(in srgb, var(--theme-accent) 10%, var(--white)) !important; }
.cv-dashboard .dt-button:disabled, .cv-dashboard .dt-button.disabled { background: transparent !important; color: var(--ink3) !important; border-color: var(--border) !important; box-shadow: none !important; opacity: .7; cursor: not-allowed !important; }

/* "Afficher N entrées" et "Rechercher" : même taille et mêmes champs que le reste */
.cv-dashboard .dt-length, .cv-dashboard .dt-search, .cv-dashboard .dt-info, .cv-dashboard .dt-paging { font-size: .82rem; color: var(--ink2); }
.cv-dashboard .dt-length select, .cv-dashboard .dt-search input { font-family: inherit; font-size: .82rem; padding: 6px 10px; border: 1.5px solid var(--border); border-radius: 10px; background: var(--white); color: var(--ink); outline: none; }
.cv-dashboard .dt-search input { min-width: 200px; }
.cv-dashboard .dt-length select:focus, .cv-dashboard .dt-search input:focus,
.cv-dashboard table.dataTable thead tr.filters input:focus { border-color: var(--theme-accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--theme-accent) 18%, transparent); }

/* Filtres de colonnes : police du module (les dates étaient en police machine) */
.cv-dashboard table.dataTable thead tr.filters input, .cv-dashboard input[type=date] { font-family: inherit; border-radius: 8px; padding: 6px 8px; outline: none; }

/* Ligne sélectionnée aux couleurs du thème */
.cv-dashboard table.dataTable tbody tr.selected td { background: color-mix(in srgb, var(--theme-accent) 14%, var(--white)) !important; box-shadow: none !important; color: inherit !important; }
