/* ==========================================================================
   Bilan 2025 — APERÇU DESIGN (transitions + mode sombre)
   Chargé uniquement pour les comptes d'aperçu (condition dans base.html).
   ========================================================================== */

/* ---------- 1. Transitions entre les pages ---------- */
@view-transition { navigation: auto; }
::view-transition-old(root), ::view-transition-new(root) { animation-duration: .28s; animation-timing-function: ease; }
body.tv2 .top-bar { view-transition-name: barre-haut; }
body.tv2 .app-bar { view-transition-name: barre-laterale; }

@keyframes apFondu { from { opacity: 0; } to { opacity: 1; } }
body.tv2 main.main-content { animation: apFondu .3s ease-out both; }

body.tv2 .btn, body.tv2 button, body.tv2 .pill, body.tv2 .stat-card, body.tv2 .app-btn, body.tv2 a {
  transition: background-color .15s ease, color .15s ease, border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
body.tv2 .btn:active, body.tv2 button:active, body.tv2 .pill:active { transform: scale(.97); }
body.tv2 .stat-card:hover { transform: translateY(-2px); }

@media (prefers-reduced-motion: reduce) {
  @view-transition { navigation: none; }
  body.tv2 main.main-content { animation: none; }
  body.tv2 .btn:active, body.tv2 button:active, body.tv2 .pill:active, body.tv2 .stat-card:hover { transform: none; }
}

/* Bouton mode sombre */
#theme-toggle { background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.2); color: #fff; border-radius: 16px;
  width: 34px; height: 30px; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; font-size: 15px; }
#theme-toggle:hover { background: rgba(255,255,255,.22); }

/* ---------- 2. Mode sombre ---------- */
html[data-theme="dark"] { color-scheme: dark; }
html[data-theme="dark"] body.tv2 {
  --bg: #0B1220; --surface: #111A2B; --surface-2: #0F1726; --surface-3: #1A2436;
  --border: #253247; --border-strong: #33425B;
  --text: #E2E8F0; --text-2: #CBD5E1; --text-3: #94A3B8;
  --primary: #60A5FA; --primary-hover: #93C5FD; --primary-soft: #172B46;
  --blue: #60A5FA; --blue-soft: #1E3A5F;
  --t-gris-bg: #1E293B; --t-gris-fg: #CBD5E1;
  --t-bleu-bg: #1E3A5F; --t-bleu-fg: #BFDBFE;
  --t-ambre-bg: #3D2E0F; --t-ambre-fg: #FCD34D;
  --t-vert-bg: #10301F; --t-vert-fg: #86EFAC;
  --t-rouge-bg: #3A1515; --t-rouge-fg: #FCA5A5;
  --t-violet-bg: #2A1F4A; --t-violet-fg: #C4B5FD;
  --t-ardoise-bg: #1E293B; --t-ardoise-fg: #CBD5E1;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow-hover: 0 6px 16px -4px rgba(0,0,0,.5);
  --bs-body-bg: #111A2B; --bs-body-bg-rgb: 17, 26, 43;
  --bs-body-color: #E2E8F0; --bs-body-color-rgb: 226, 232, 240;
  --bs-emphasis-color: #F8FAFC; --bs-secondary-color: #94A3B8; --bs-tertiary-color: #94A3B8;
  --bs-secondary-bg: #1A2436; --bs-tertiary-bg: #0F1726; --bs-border-color: #253247;
  --bs-table-bg: transparent; --bs-table-color: #E2E8F0;
  background: var(--bg) !important; color: var(--text) !important;
}

/* Surfaces : cartes, tableaux, menus, fenêtres */
html[data-theme="dark"] body.tv2 :is(.card, .modal-content, .dropdown-menu, .pill-menu, .list-group-item, .offcanvas, .toast) {
  background-color: var(--surface) !important; color: var(--text) !important; border-color: var(--border) !important;
}
html[data-theme="dark"] body.tv2 :is(input, select, textarea, .form-control, .form-select):not([type="checkbox"]):not([type="radio"]):not([type="range"]) {
  background-color: var(--surface-2) !important; color: var(--text) !important; border-color: var(--border-strong) !important;
}
html[data-theme="dark"] body.tv2 ::placeholder { color: #64748B !important; }
html[data-theme="dark"] body.tv2 table { color: var(--text) !important; }
html[data-theme="dark"] body.tv2 table thead th { background-color: var(--surface-2) !important; color: var(--text-2) !important; border-color: var(--border) !important; }
html[data-theme="dark"] body.tv2 table tbody tr { background-color: var(--surface) !important; }
html[data-theme="dark"] body.tv2 table tbody td { color: var(--text) !important; border-color: var(--border) !important; }
html[data-theme="dark"] body.tv2 table tbody tr:hover > td { background-color: var(--surface-3) !important; }

/* Pastilles et cartes des onglets (AGO, TVA, Impôts, Mail, To-Do, filtres) */
html[data-theme="dark"] body.tv2 :is(.ago-cell-pill, .imp-cell-pill, .ago-th-pill, .imp-th-pill, .stat-card, .search-input-box,
  .imp-input, .imp-comment, .ml-list, .ml-read, .ml-search, .ml-item, .ml-folder:not(.active), .ml-cf, .ml-pj, .ml-classer button:not(.on),
  .ml-actions button, .rap-form, .rap-chip:not(.on), .rap-urg-btn:not(.on), .tache-item, .todo-detail, .imp-pill-select:not(.active),
  .pill:not(.active), .imp-stat, .ml-compose, .ml-config) {
  background-color: var(--surface) !important; color: var(--text) !important; border-color: var(--border-strong) !important;
}
html[data-theme="dark"] body.tv2 :is(.ml-item:hover, .tache-item:hover) { background-color: var(--surface-3) !important; }
html[data-theme="dark"] body.tv2 .ml-item.c-rouge { background-color: #2A1414 !important; }
html[data-theme="dark"] body.tv2 .ml-item.c-orange { background-color: #2A2110 !important; }
html[data-theme="dark"] body.tv2 .imp-input.imp-dette { background-color: #3A1515 !important; color: #FCA5A5 !important; }
html[data-theme="dark"] body.tv2 #imp-table tfoot tr, html[data-theme="dark"] body.tv2 #imp-table tfoot td { background-color: #14532D !important; }

/* Couleurs codées en dur dans les gabarits (style="...") */
html[data-theme="dark"] body.tv2 :is([style*="background:#fff"], [style*="background: #fff"], [style*="background:#FFF"], [style*="background: #FFF"],
  [style*="background:white"], [style*="background: white"], [style*="background-color:#fff"], [style*="background-color: #fff"],
  [style*="background:#f8f9fa"], [style*="background:#f5f5f5"], [style*="background:#fafafa"], [style*="background: #FAFAFA"]) {
  background: var(--surface) !important;
}
html[data-theme="dark"] body.tv2 :is([style*="color:#2D2D2D"], [style*="color: #2D2D2D"], [style*="color:#333"], [style*="color: #333"],
  [style*="color:#1E293B"], [style*="color:#111"], [style*="color:#000"], [style*="color: #000"], [style*="color:#2D3436"]) {
  color: var(--text) !important;
}
html[data-theme="dark"] body.tv2 :is([style*="color:#666"], [style*="color: #666"], [style*="color:#999"], [style*="color:#888"]) { color: var(--text-3) !important; }
html[data-theme="dark"] body.tv2 :is(h1, h2, h3, h4, h5, h6, label, strong, b) { color: inherit; }
html[data-theme="dark"] body.tv2 .text-muted { color: var(--text-3) !important; }
html[data-theme="dark"] body.tv2 .btn-outline-secondary, html[data-theme="dark"] body.tv2 .btn-light {
  background-color: var(--surface-3) !important; color: var(--text) !important; border-color: var(--border-strong) !important;
}
html[data-theme="dark"] body.tv2 .alert { filter: brightness(.85); }
html[data-theme="dark"] body.tv2 #hscroll-flottant { background: rgba(15,23,38,.96); border-top-color: var(--border); }
html[data-theme="dark"] body.tv2 #global-search-results { background: var(--surface) !important; color: var(--text) !important; }

/* ---------- 3. Mode sombre : correctifs de contraste (v2) ---------- */
/* Bouton mode sombre : suit le theme (visible en clair comme en sombre) */
#theme-toggle { background: var(--surface-3) !important; border: 1px solid var(--border-strong) !important; color: var(--text) !important; }
#theme-toggle:hover { background: var(--primary-soft) !important; color: var(--primary) !important; }
html[data-theme="dark"] #theme-toggle { color: #FCD34D !important; }

/* Pastilles (noms de societes, SIREN, valeurs) : contraste fort */
html[data-theme="dark"] body.tv2 #ago-table thead th > span.ago-th-pill,
html[data-theme="dark"] body.tv2 #imp-table thead th > span.imp-th-pill,
html[data-theme="dark"] body.tv2 .ago-cell-pill,
html[data-theme="dark"] body.tv2 .av-comment-pill,
html[data-theme="dark"] body.tv2 .av-date-pill,
html[data-theme="dark"] body.tv2 .av-field-pill,
html[data-theme="dark"] body.tv2 .bq-cell-pill,
html[data-theme="dark"] body.tv2 .btn-pill.back,
html[data-theme="dark"] body.tv2 .btn-pill.recalc,
html[data-theme="dark"] body.tv2 .cell-pill,
html[data-theme="dark"] body.tv2 .dossier-cell-pill,
html[data-theme="dark"] body.tv2 .ent-pill,
html[data-theme="dark"] body.tv2 .ged-nb,
html[data-theme="dark"] body.tv2 .imp-cell-pill,
html[data-theme="dark"] body.tv2 .imp-pill-select,
html[data-theme="dark"] body.tv2 .juri-cell-pill,
html[data-theme="dark"] body.tv2 .num-pill,
html[data-theme="dark"] body.tv2 .pill,
html[data-theme="dark"] body.tv2 .pill-menu,
html[data-theme="dark"] body.tv2 .rap-chip,
html[data-theme="dark"] body.tv2 .vip-pill {
  background-color: #18233A !important; color: #F1F5F9 !important; border-color: #3B5B8C !important;
}

html[data-theme="dark"] body.tv2 :is([class*="cell-pill-strong"], .dossier-cell-pill-strong) { color: #FFFFFF !important; border-color: #60A5FA !important; font-weight: 700; }
html[data-theme="dark"] body.tv2 a[class*="cell-pill"]:hover { background-color: #22345A !important; border-color: #93C5FD !important; }

/* Surfaces (lignes, cartes, menus, barres) */
html[data-theme="dark"] body.tv2 #ago-table tbody input.ago-comment,
html[data-theme="dark"] body.tv2 #ago-table tbody input.ago-date-field,
html[data-theme="dark"] body.tv2 #ago-table tbody tr,
html[data-theme="dark"] body.tv2 #chatbot-panel,
html[data-theme="dark"] body.tv2 #dossier-table tbody td input.monday-comment,
html[data-theme="dark"] body.tv2 #dossier-table tbody td input.monday-date,
html[data-theme="dark"] body.tv2 #dossier-table tbody td select.monday-dropdown,
html[data-theme="dark"] body.tv2 #dossier-table tbody tr,
html[data-theme="dark"] body.tv2 #dossier-table thead th > span,
html[data-theme="dark"] body.tv2 #dossier-table thead th a,
html[data-theme="dark"] body.tv2 #entreprise-table tbody tr,
html[data-theme="dark"] body.tv2 #entreprise-table thead th a,
html[data-theme="dark"] body.tv2 #imp-table tbody tr,
html[data-theme="dark"] body.tv2 #offcanvas-perso,
html[data-theme="dark"] body.tv2 #vip-table tbody tr,
html[data-theme="dark"] body.tv2 .add-input,
html[data-theme="dark"] body.tv2 .ago-paiement-dd.paiement-hidden option,
html[data-theme="dark"] body.tv2 .ago-section-nav,
html[data-theme="dark"] body.tv2 .alert-card,
html[data-theme="dark"] body.tv2 .autocomplete-list,
html[data-theme="dark"] body.tv2 .av-table tbody tr,
html[data-theme="dark"] body.tv2 .av-table tfoot tr,
html[data-theme="dark"] body.tv2 .av-table thead th .th-inner,
html[data-theme="dark"] body.tv2 .av-tabs .av-tab,
html[data-theme="dark"] body.tv2 .banque-table tbody tr,
html[data-theme="dark"] body.tv2 .banque-table thead tr:first-child th[rowspan] > *,
html[data-theme="dark"] body.tv2 .btn-archives,
html[data-theme="dark"] body.tv2 .btn-refresh,
html[data-theme="dark"] body.tv2 .ctx-menu,
html[data-theme="dark"] body.tv2 .ctx-menu .ctx-sub-menu,
html[data-theme="dark"] body.tv2 .cy-card,
html[data-theme="dark"] body.tv2 .cy-empty,
html[data-theme="dark"] body.tv2 .cy-head,
html[data-theme="dark"] body.tv2 .cy-tab,
html[data-theme="dark"] body.tv2 .cyl-btn,
html[data-theme="dark"] body.tv2 .cyl-empty,
html[data-theme="dark"] body.tv2 .cyl-wrap,
html[data-theme="dark"] body.tv2 .detail-section,
html[data-theme="dark"] body.tv2 .filter-bar,
html[data-theme="dark"] body.tv2 .ged-menu,
html[data-theme="dark"] body.tv2 .ged-table-wrap,
html[data-theme="dark"] body.tv2 .imp-comment,
html[data-theme="dark"] body.tv2 .imp-input,
html[data-theme="dark"] body.tv2 .inpi-vide,
html[data-theme="dark"] body.tv2 .juri-field,
html[data-theme="dark"] body.tv2 .juri-table tbody tr,
html[data-theme="dark"] body.tv2 .ml-actions button,
html[data-theme="dark"] body.tv2 .ml-cancel,
html[data-theme="dark"] body.tv2 .ml-cf,
html[data-theme="dark"] body.tv2 .ml-classer button,
html[data-theme="dark"] body.tv2 .ml-compose input,
html[data-theme="dark"] body.tv2 .ml-compose textarea,
html[data-theme="dark"] body.tv2 .ml-folder,
html[data-theme="dark"] body.tv2 .ml-list,
html[data-theme="dark"] body.tv2 .ml-read,
html[data-theme="dark"] body.tv2 .ml-search,
html[data-theme="dark"] body.tv2 .monday-dropdown option,
html[data-theme="dark"] body.tv2 .new-user-form,
html[data-theme="dark"] body.tv2 .perso-footer,
html[data-theme="dark"] body.tv2 .rap-urg-btn,
html[data-theme="dark"] body.tv2 .search-input-box,
html[data-theme="dark"] body.tv2 .search-wrap,
html[data-theme="dark"] body.tv2 .stat-card,
html[data-theme="dark"] body.tv2 .stats-bar .stat-item,
html[data-theme="dark"] body.tv2 .sticky-col,
html[data-theme="dark"] body.tv2 .tache-item,
html[data-theme="dark"] body.tv2 .todo-center,
html[data-theme="dark"] body.tv2 .todo-layout,
html[data-theme="dark"] body.tv2 .tva-table tbody td input.tva-comment,
html[data-theme="dark"] body.tv2 .tva-table tbody td select.tva-field-dropdown,
html[data-theme="dark"] body.tv2 .tva-table tbody tr,
html[data-theme="dark"] body.tv2 table.ged td.sticky-col,
html[data-theme="dark"] body.tv2 table.ged th.sticky-col {
  background-color: var(--surface) !important; color: var(--text) !important; border-color: var(--border-strong) !important;
}

/* Etats actifs / focus : ressortent en bleu */
html[data-theme="dark"] body.tv2 #dossier-table tbody td input[type="text"]:focus,
html[data-theme="dark"] body.tv2 #dossier-table tbody td select:focus,
html[data-theme="dark"] body.tv2 .add-tache-bar input:focus,
html[data-theme="dark"] body.tv2 .cell-input:focus,
html[data-theme="dark"] body.tv2 .monday-comment:focus,
html[data-theme="dark"] body.tv2 .monday-date:focus,
html[data-theme="dark"] body.tv2 .new-list-form input:focus,
html[data-theme="dark"] body.tv2 .step.active,
html[data-theme="dark"] body.tv2 .todo-detail .detail-header .detail-titre:focus,
html[data-theme="dark"] body.tv2 .todo-sidebar .sidebar-item.active,
html[data-theme="dark"] body.tv2 .tva-table tbody td input.tva-comment:focus,
html[data-theme="dark"] body.tv2 .tva-table tbody td select.tva-field-dropdown:focus {
  background-color: #172B46 !important; color: #FFFFFF !important; border-color: #60A5FA !important;
}

/* La feuille A4 de l editeur de PV reste blanche (papier) */
html[data-theme="dark"] body.tv2 .ed-page { background: #FFFFFF !important; color: #111 !important; }
html[data-theme="dark"] body.tv2 .ed-page-scroll { background: #0F1726 !important; }
