/* ==========================================================================
   Jetons de design ("Grand Livre") — palette, typographie, ombres.
   Inspires du registre comptable : papier gris-bleu froid, encre marine,
   vert-teal pour le positif, rouille pour le negatif/depassement.
   ========================================================================== */
:root {
  --ink: #1C2333;
  --ink-soft: #2A3247;
  --paper: #EEF1F3;
  --surface: #FFFFFF;
  --line: #D7DCE1;
  --line-strong: #C2C9D1;
  --accent: #1F6F5C;
  --accent-strong: #175747;
  --rust: #A64B3A;
  --rust-strong: #8A3C2E;
  --amber: #B58A3A;
  --slate-blue: #3D6A8A;
  --muted: #5B6570;
  --text: #1C2333;
  --shadow-sm: 0 1px 2px rgba(28, 35, 51, 0.05);
  --shadow-md: 0 12px 28px rgba(28, 35, 51, 0.14), 0 2px 6px rgba(28, 35, 51, 0.08);

  --font-display: 'Space Grotesk', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ==========================================================================
   Reskin de Bootstrap : on ne recopie pas les composants, on redefinit ses
   variables CSS. La plupart des composants (cartes, tableaux, alertes,
   badges, DataTables bs5) en derivent directement.
   ========================================================================== */
:root,
[data-bs-theme=light] {
  --bs-body-bg: var(--paper);
  --bs-body-color: var(--text);
  --bs-body-color-rgb: 28, 35, 51;
  --bs-body-font-family: var(--font-body);
  --bs-emphasis-color: var(--ink);
  --bs-emphasis-color-rgb: 28, 35, 51;
  --bs-border-color: var(--line);
  --bs-border-color-translucent: var(--line);

  --bs-link-color: var(--accent);
  --bs-link-color-rgb: 31, 111, 92;
  --bs-link-hover-color: var(--accent-strong);
  --bs-link-hover-color-rgb: 23, 87, 71;

  --bs-primary: var(--accent);
  --bs-primary-rgb: 31, 111, 92;
  --bs-secondary-rgb: 91, 101, 112;
  --bs-success-rgb: 31, 111, 92;
  --bs-danger-rgb: 166, 75, 58;
  --bs-warning-rgb: 181, 138, 58;
  --bs-info-rgb: 61, 106, 138;
  --bs-dark: var(--ink);
  --bs-dark-rgb: 28, 35, 51;
  --bs-light-rgb: 238, 241, 243;

  --bs-focus-ring-color: rgba(31, 111, 92, 0.25);
}

/* Elements dont Bootstrap fige la couleur en dur plutot que de la deriver
   des variables ci-dessus. */
.btn-primary {
  --bs-btn-bg: var(--accent);
  --bs-btn-border-color: var(--accent);
  --bs-btn-hover-bg: var(--accent-strong);
  --bs-btn-hover-border-color: var(--accent-strong);
  --bs-btn-active-bg: var(--accent-strong);
  --bs-btn-active-border-color: var(--accent-strong);
  --bs-btn-disabled-bg: var(--accent);
  --bs-btn-disabled-border-color: var(--accent);
  --bs-btn-focus-shadow-rgb: 31, 111, 92;
}
.btn-outline-primary {
  --bs-btn-color: var(--accent);
  --bs-btn-border-color: var(--accent);
  --bs-btn-hover-bg: var(--accent);
  --bs-btn-hover-border-color: var(--accent);
  --bs-btn-active-bg: var(--accent-strong);
  --bs-btn-active-border-color: var(--accent-strong);
  --bs-btn-focus-shadow-rgb: 31, 111, 92;
}
.btn-success {
  --bs-btn-bg: var(--accent);
  --bs-btn-border-color: var(--accent);
  --bs-btn-hover-bg: var(--accent-strong);
  --bs-btn-hover-border-color: var(--accent-strong);
  --bs-btn-active-bg: var(--accent-strong);
  --bs-btn-active-border-color: var(--accent-strong);
  --bs-btn-disabled-bg: var(--accent);
  --bs-btn-disabled-border-color: var(--accent);
  --bs-btn-focus-shadow-rgb: 31, 111, 92;
}
.btn-danger {
  --bs-btn-bg: var(--rust);
  --bs-btn-border-color: var(--rust);
  --bs-btn-hover-bg: var(--rust-strong);
  --bs-btn-hover-border-color: var(--rust-strong);
  --bs-btn-active-bg: var(--rust-strong);
  --bs-btn-active-border-color: var(--rust-strong);
  --bs-btn-disabled-bg: var(--rust);
  --bs-btn-disabled-border-color: var(--rust);
  --bs-btn-focus-shadow-rgb: 166, 75, 58;
}
.btn-warning {
  --bs-btn-color: var(--ink);
  --bs-btn-bg: var(--amber);
  --bs-btn-border-color: var(--amber);
  --bs-btn-hover-color: var(--ink);
  --bs-btn-hover-bg: #a17b31;
  --bs-btn-hover-border-color: #a17b31;
  --bs-btn-active-color: var(--ink);
  --bs-btn-active-bg: #a17b31;
  --bs-btn-active-border-color: #a17b31;
  --bs-btn-disabled-color: var(--ink);
  --bs-btn-disabled-bg: var(--amber);
  --bs-btn-disabled-border-color: var(--amber);
  --bs-btn-focus-shadow-rgb: 181, 138, 58;
}
.btn-info {
  --bs-btn-color: #fff;
  --bs-btn-bg: var(--slate-blue);
  --bs-btn-border-color: var(--slate-blue);
  --bs-btn-hover-color: #fff;
  --bs-btn-hover-bg: #2f5570;
  --bs-btn-hover-border-color: #2f5570;
  --bs-btn-active-color: #fff;
  --bs-btn-active-bg: #2f5570;
  --bs-btn-active-border-color: #2f5570;
  --bs-btn-disabled-color: #fff;
  --bs-btn-disabled-bg: var(--slate-blue);
  --bs-btn-disabled-border-color: var(--slate-blue);
  --bs-btn-focus-shadow-rgb: 61, 106, 138;
}
.btn-secondary {
  --bs-btn-bg: var(--muted);
  --bs-btn-border-color: var(--muted);
  --bs-btn-hover-bg: #46505a;
  --bs-btn-hover-border-color: #46505a;
  --bs-btn-active-bg: #46505a;
  --bs-btn-active-border-color: #46505a;
  --bs-btn-disabled-bg: var(--muted);
  --bs-btn-disabled-border-color: var(--muted);
  --bs-btn-focus-shadow-rgb: 91, 101, 112;
}
.btn-dark {
  --bs-btn-bg: var(--ink);
  --bs-btn-border-color: var(--ink);
  --bs-btn-hover-bg: var(--ink-soft);
  --bs-btn-hover-border-color: var(--ink-soft);
  --bs-btn-active-bg: var(--ink-soft);
  --bs-btn-active-border-color: var(--ink-soft);
  --bs-btn-disabled-bg: var(--ink);
  --bs-btn-disabled-border-color: var(--ink);
  --bs-btn-focus-shadow-rgb: 28, 35, 51;
}

.dropdown-item.active, .dropdown-item:active { --bs-dropdown-link-active-bg: var(--accent); }
.page-item.active .page-link { --bs-pagination-active-bg: var(--accent); --bs-pagination-active-border-color: var(--accent); }
.progress-bar.bg-warning { color: var(--ink); }

/* Bootstrap fige la couleur de focus des champs en dur (bleu), independamment
   de --bs-focus-ring-color : on la reprend ici. */
.form-control:focus, .form-select:focus, .form-check-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 0.25rem rgba(31, 111, 92, 0.25);
}
.btn:focus, .btn:active:focus, .btn-link.nav-link:focus {
  box-shadow: 0 0 0 0.1rem var(--paper), 0 0 0 0.25rem var(--accent);
}

/* ==========================================================================
   Typographie
   ========================================================================== */
html { font-size: 14px; }
@media (min-width: 768px) {
  html { font-size: 16px; }
}

body { font-family: var(--font-body); }

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.01em;
}

h1 { font-weight: 700; margin-bottom: 1.25rem; }

/* Colonnes de montants : chiffres tabulaires, alignes comme sur un releve. */
.table td.text-end, .table th.text-end {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* ==========================================================================
   Navbar
   ========================================================================== */
html {
  position: relative;
  min-height: 100%;
}

body {
  margin-bottom: 60px;
}

.app-navbar {
  background-color: var(--ink);
  border-bottom: 1px solid var(--ink-soft);
}
.app-navbar .navbar-brand {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #fff;
}
.app-navbar .nav-link {
  color: rgba(255, 255, 255, 0.72);
  border-bottom: 2px solid transparent;
  transition: color .15s ease, border-color .15s ease;
}
.app-navbar .nav-link:hover,
.app-navbar .nav-link:focus {
  color: #fff;
}
.app-navbar .nav-link.active {
  color: #fff;
  border-bottom-color: var(--accent-strong);
}
.app-navbar .dropdown-menu {
  border-color: var(--line);
  box-shadow: var(--shadow-sm), 0 8px 24px -12px rgba(28, 35, 51, 0.35);
}
.app-navbar .dropdown-header {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.app-navbar .navbar-toggler {
  border-color: rgba(255, 255, 255, 0.35);
}
.app-navbar .navbar-toggler-icon {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba(255,255,255,0.85)' stroke-width='2' stroke-linecap='round' stroke-miterlimit='10' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
}

/* ==========================================================================
   Cartes et divers
   ========================================================================== */
.card {
  /* --bs-card-bg herite de --bs-body-bg (= --paper, gris) : sans surcharge,
     la carte se fond dans le fond de page au lieu de s'en detacher. */
  background: var(--surface);
  border-color: var(--line);
  box-shadow: var(--shadow-sm);
}

.panel-title {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 14px;
}

/* ==========================================================================
   Tableau de bord : en-tete, filtres, tuiles de synthese, onglets segmentes
   ========================================================================== */
.page-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-end;
  gap: 20px;
  margin-bottom: 24px;
}
.eyebrow {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 6px;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  position: relative; /* ancre du panneau flottant .panneau-personnalise */
}

.pill-group {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
  box-shadow: var(--shadow-sm);
}
.pill {
  border: none;
  background: none;
  padding: 7px 16px;
  border-radius: 999px;
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  text-decoration: none;
  line-height: 1.2;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.pill:hover:not(.active) {
  color: var(--ink);
  text-decoration: none;
}
.pill.active {
  background: var(--accent);
  color: #fff;
}
.pill .chevron {
  font-size: 0.62rem;
  transition: transform 0.15s ease;
}
.pill.active .chevron {
  transform: rotate(180deg);
}

/* Panneau "Personnalisé" : flottant et ancré sous la pastille, pour ne jamais
   pousser la ligne des pastilles ni le titre (contrairement à un formulaire
   inséré dans le flux de .filters). */
.panneau-personnalise {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 20;
  width: 420px;
  max-width: calc(100vw - 48px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  padding: 18px 18px 16px;
}
.panneau-personnalise::before {
  content: "";
  position: absolute;
  top: -6px;
  right: 28px;
  width: 12px;
  height: 12px;
  background: var(--surface);
  border-left: 1px solid var(--line);
  border-top: 1px solid var(--line);
  transform: rotate(45deg);
}
.panneau-titre {
  font-family: var(--font-display);
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--ink);
  margin: 0 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.panneau-fermer {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 6px;
}
.panneau-fermer:hover {
  color: var(--ink);
  background: var(--paper);
}
.panneau-personnalise .champ {
  margin-bottom: 0;
}
.panneau-personnalise label {
  display: block;
  font-size: 0.76rem;
  color: var(--muted);
  font-weight: 500;
  margin-bottom: 5px;
}
.panneau-personnalise select {
  width: 100%;
  font-family: var(--font-body);
  font-size: 0.85rem;
  color: var(--text);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 8px 7px 10px;
}
.ligne-champs {
  display: flex;
  gap: 10px;
}
.ligne-champs .champ-annee {
  flex: 0 0 78px;
}
.ligne-champs .champ-mois {
  flex: 1;
  min-width: 0;
}
.panneau-actions {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
}
.btn-appliquer {
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 18px;
  cursor: pointer;
}
.btn-appliquer:hover {
  background: var(--accent-strong);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}
.stat-tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px 18px 14px;
  box-shadow: var(--shadow-sm);
}
.stat-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 8px;
}
.stat-label {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
}
.leader {
  flex: 1;
  border-bottom: 1px dotted var(--line-strong);
  height: 1px;
  transform: translateY(-4px);
}
.stat-value {
  font-family: var(--font-mono);
  font-size: 1.4rem;
  font-weight: 600;
  margin: 0;
  color: var(--text);
}
.stat-sub {
  margin: 4px 0 0;
  font-size: 0.78rem;
  font-family: var(--font-mono);
  color: var(--muted);
}
.stat-sub.positive { color: var(--accent); }
.stat-sub.negative { color: var(--rust); }

.gauge-ring-wrap { display: flex; align-items: center; gap: 12px; }
.gauge-ring {
  --pct: 0;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: conic-gradient(var(--accent) calc(var(--pct) * 1%), var(--line) 0);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.gauge-ring.over {
  background: conic-gradient(var(--rust) calc(var(--pct) * 1%), var(--line) 0);
}
.gauge-ring::after {
  content: '';
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--surface);
}

.stat-grid.stat-grid-3 { grid-template-columns: repeat(3, 1fr); }

@media (max-width: 960px) {
  .stat-grid, .stat-grid.stat-grid-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 560px) {
  .stat-grid, .stat-grid.stat-grid-3 { grid-template-columns: 1fr; }
}

/* Tuile "Budget vs reel par categorie" : liste compacte avec jauge lineaire,
   distincte du tableau detaille par categorie/monnaie plus bas sur la page. */
.ledger-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.ledger-list > li {
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}
.ledger-list > li:last-child {
  border-bottom: none;
  padding-bottom: 0;
}
.ledger-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 7px;
}
.ledger-row .cat-name {
  font-size: 0.88rem;
  font-weight: 500;
  white-space: nowrap;
}
.ledger-row .mono {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--muted);
  white-space: nowrap;
}
.ledger-row .mono.over {
  color: var(--rust);
  font-weight: 600;
}
.ledger-row .mono a {
  color: inherit;
  text-decoration: none;
}
.ledger-row .mono a:hover {
  text-decoration: underline;
}
.gauge {
  height: 6px;
  border-radius: 3px;
  background: var(--paper);
  border: 1px solid var(--line);
  overflow: hidden;
}
.gauge-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px 0 0 3px;
  transition: width 1s ease;
}
.gauge-fill.over {
  background: var(--rust);
}

/* Liste des ecritures : remplace le <table> de Transaction/Index. Chaque ecriture est un
   <details>/<summary> natif (depli au clic et au clavier, sans JavaScript). La ligne principale
   reprend le motif .ledger-row / .leader / .mono deja utilise pour "Budget vs reel". */
.ecriture-liste {
  list-style: none;
  margin: 0;
  padding: 0;
}
.ecriture-liste li {
  list-style: none;
}

details.ecriture {
  border-bottom: 1px solid var(--line);
}
details.ecriture:last-child {
  border-bottom: none;
}

summary.ecriture-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 6px 13px 0;
  cursor: pointer;
  list-style: none;
  position: relative;
  min-height: 44px;
}
summary.ecriture-row::-webkit-details-marker {
  display: none;
}
summary.ecriture-row:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  border-radius: 6px;
}
summary.ecriture-row:hover .ecriture-desc {
  color: var(--accent-strong);
}

/* Fanion de couleur = type de categorie (Revenu/Depense/Autre/A classifier), jamais l'identite
   d'une categorie individuelle (Category.ColorCode a ete supprime, commit 69634e8). */
.ecriture-fanion {
  flex: 0 0 4px;
  align-self: stretch;
  border-radius: 3px;
  background: var(--line-strong);
}
.ecriture-fanion--expense { background: var(--rust); }
.ecriture-fanion--income { background: var(--accent); }
.ecriture-fanion--other { background: var(--slate-blue); }
.ecriture-fanion--unclassified { background: var(--amber); }

.ecriture-corps {
  flex: 1;
  min-width: 0;
}

.ecriture-entete {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 6px;
}
.ecriture-desc {
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 46ch;
}
.amt {
  font-family: var(--font-mono);
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.amt.neg { color: var(--rust); }
.amt.pos { color: var(--accent); }
.amt .flag-icon {
  font-size: 0.78em;
  margin-left: 3px;
  cursor: help;
}

/* Ligne meta : categorie / compte / date / montant converti — s'enroule librement sur mobile,
   rien n'est masque, tout reste lisible. */
.ecriture-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px 10px;
  font-size: 0.78rem;
  color: var(--muted);
}
.chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
}
.chip--expense { background: rgba(166,75,58,0.1); color: var(--rust-strong); }
.chip--income { background: rgba(31,111,92,0.1); color: var(--accent-strong); }
.chip--other { background: rgba(61,106,138,0.12); color: var(--slate-blue); }
.chip--unclassified { background: rgba(181,138,58,0.14); color: var(--amber); }
.ecriture-meta .sep { color: var(--line-strong); }
.ecriture-base {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.ecriture-chevron {
  flex: 0 0 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  transition: transform 0.18s ease;
}
@media (prefers-reduced-motion: reduce) {
  .ecriture-chevron { transition: none; }
}
.ecriture-chevron::before {
  content: "▾";
  font-size: 0.72rem;
}
details.ecriture[open] > summary .ecriture-chevron {
  transform: rotate(180deg);
  color: var(--accent);
}

/* Panneau de detail : infos secondaires + actions, replie par defaut. */
.ecriture-detail {
  padding: 2px 6px 16px 16px;
  margin-left: 4px;
  border-left: 2px solid var(--line);
  animation: unfurl 0.15s ease;
}
@media (prefers-reduced-motion: reduce) {
  .ecriture-detail { animation: none; }
}
@keyframes unfurl {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.ecriture-detail dl {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px 20px;
  margin: 6px 0 12px;
}
.ecriture-detail dt {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin: 0 0 2px;
}
.ecriture-detail dd {
  font-size: 0.84rem;
  color: var(--ink);
  margin: 0;
}

.ecriture-avertissement {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  font-size: 0.8rem;
  color: var(--rust-strong);
  background: rgba(166,75,58,0.07);
  border: 1px solid rgba(166,75,58,0.2);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 12px;
}
.ecriture-info {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  font-size: 0.8rem;
  color: var(--ink-soft);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 12px;
}

.ecriture-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.btn-ghost, .btn-solid {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 600;
  text-decoration: none;
  padding: 7px 14px;
  border-radius: 7px;
  border: 1px solid var(--line-strong);
  color: var(--ink);
  background: var(--surface);
  cursor: pointer;
  min-height: 44px;
}
.btn-ghost:hover { background: var(--paper); }
.btn-ghost.danger { color: var(--rust-strong); border-color: rgba(166,75,58,0.35); }
.btn-ghost.danger:hover { background: rgba(166,75,58,0.06); }
.btn-solid.danger { background: var(--rust); border-color: var(--rust); color: #fff; }
.btn-solid.danger:hover { background: var(--rust-strong); border-color: var(--rust-strong); }
.btn-ghost:focus-visible, .btn-solid:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Suppression inline : la barre d'actions bascule en confirmation, sans quitter la liste. */
.etat-normal { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.etat-confirmation { display: none; align-items: center; flex-wrap: wrap; gap: 8px; }
.ecriture-actions.confirmation .etat-normal { display: none; }
.ecriture-actions.confirmation .etat-confirmation { display: flex; animation: fondu 0.15s ease; }
@keyframes fondu {
  from { opacity: 0; }
  to { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .ecriture-actions.confirmation .etat-confirmation { animation: none; }
}
.confirm-texte { font-size: 0.82rem; font-weight: 600; color: var(--rust-strong); }

/* Ligne qui vient d'etre modifiee : surbrillance breve au retour de la page Edit. */
details.ecriture.surbrillance > summary {
  animation: surligner 2.4s ease forwards;
}
@keyframes surligner {
  0%, 45% { background: rgba(31,111,92,0.1); }
  100% { background: transparent; }
}
@media (prefers-reduced-motion: reduce) {
  details.ecriture.surbrillance > summary { animation: none; }
}

/* ---------- barre de tri / filtre : etat porte par l'URL, tri cote serveur ---------- */
.list-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 14px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--line);
}
.toolbar-group { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.field-search { position: relative; display: inline-flex; }
.field-search input {
  font-family: var(--font-body);
  font-size: 0.84rem;
  color: var(--text);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 12px 7px 30px;
  width: 230px;
  max-width: 100%;
}
.field-search::before {
  content: "⌕";
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 1rem;
  pointer-events: none;
}
.select-sm {
  font-family: var(--font-body);
  font-size: 0.82rem;
  color: var(--text);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  min-height: 44px;
}
.toolbar-label { font-size: 0.78rem; color: var(--muted); }
.btn-sens {
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 8px;
  padding: 6px 10px;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--ink);
  cursor: pointer;
  min-height: 44px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

/* ---------- pied de liste : pagination serveur ---------- */
.list-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0 6px;
  border-top: 1px solid var(--line);
}
.list-count { font-family: var(--font-mono); font-size: 0.76rem; color: var(--muted); margin: 0; }
.pager { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.pager a, .pager span.ellipsis {
  font-size: 0.8rem;
  text-decoration: none;
  color: var(--ink);
  padding: 6px 11px;
  border-radius: 7px;
  border: 1px solid transparent;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}
.pager a:hover { background: var(--paper); }
.pager a.active { background: var(--accent); color: #fff; font-weight: 600; }
.pager a.disabled { color: var(--line-strong); pointer-events: none; }
.pager span.ellipsis { color: var(--muted); padding: 6px 4px; }

/* Message one-shot apres suppression (TempData du motif Post/Redirect/Get). */
.flash {
  display: none;
  align-items: center;
  gap: 10px;
  font-size: 0.84rem;
  color: var(--accent-strong);
  background: rgba(31,111,92,0.08);
  border: 1px solid rgba(31,111,92,0.25);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 14px;
}
.flash.visible { display: flex; animation: fondu 0.2s ease; }

/* Variante d'erreur (identifiants invalides, compte désactivé, etc.) — le .flash de base n'a
   qu'un état succès vert. */
.flash.erreur {
  color: var(--rust-strong);
  background: rgba(166,75,58,0.08);
  border-color: rgba(166,75,58,0.25);
}

/* Écran de connexion : carte étroite et centrée, calquée sur le reste de l'application. */
.auth-shell {
  max-width: 420px;
  margin: 40px auto 0;
}

@media (max-width: 560px) {
  summary.ecriture-row { flex-wrap: wrap; row-gap: 4px; }
  .ecriture-desc { max-width: 60vw; }
  .ecriture-entete { flex: 1 1 100%; }
  .ecriture-meta { flex: 1 1 100%; }
  .field-search input { width: 100%; }
  .field-search { flex: 1 1 100%; }
  .list-toolbar, .list-footer { justify-content: flex-start; }
  .ecriture-actions .btn-ghost, .ecriture-actions .btn-solid { flex: 1 1 auto; text-align: center; justify-content: center; }
}

/* Onglets du tableau de bord rendus en controle segmente plutot qu'en onglets classiques. */
.seg-tabs {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px;
  box-shadow: var(--shadow-sm);
}
.seg-tabs.nav-tabs { border-bottom: 1px solid var(--line); }
.seg-tabs .nav-item { margin-bottom: 0; }
.seg-tabs .nav-link {
  border: none;
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 500;
  padding: 7px 14px;
  background: transparent;
}
.seg-tabs .nav-link:hover {
  border: none;
  isolation: auto;
  color: var(--ink);
}
.seg-tabs .nav-link.active {
  background: var(--accent);
  color: #fff;
}

.form-floating > .form-control-plaintext::placeholder, .form-floating > .form-control::placeholder {
  color: var(--bs-secondary-color);
  text-align: end;
}

.form-floating > .form-control-plaintext:focus::placeholder, .form-floating > .form-control:focus::placeholder {
  text-align: start;
}

/* ==========================================================================
   Pages d'edition : formulaire en sections + apercu collant ("Grand Livre").
   Introduit sur ClassificationRule/Edit, destine a etre repris sur toutes
   les vues d'edition au fil de leur conversion.
   ========================================================================== */
.head-links {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.link-retour {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  min-height: 44px;
}
.link-retour:hover {
  color: var(--ink);
  text-decoration: none;
}

.form-shell {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 22px;
  align-items: start;
}
.form-main {
  padding: 0;
}

.form-section {
  padding: 22px 26px;
  border-bottom: 1px solid var(--line);
}
.form-section:last-of-type {
  border-bottom: none;
}
.form-section-head {
  margin-bottom: 16px;
}
.form-section-title {
  font-family: var(--font-display);
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--ink);
  margin: 0 0 2px;
}
.form-section-sub {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 18px 20px;
}
.field-grid.cols-3 {
  grid-template-columns: repeat(3, 1fr);
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.field.span-2 {
  grid-column: span 2;
}
.field-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 0;
}
.field-label .req {
  color: var(--rust);
  margin-left: 2px;
}
.field-label .opt {
  font-weight: 500;
  color: var(--muted);
}
.field-hint {
  font-size: 0.76rem;
  color: var(--muted);
}

/* Bootstrap reskin, scope aux formulaires convertis pour ne pas alterer les
   pages non encore migrees (filtres compacts du dashboard, listes, etc.). */
.form-section .form-control,
.form-section .form-select {
  font-size: 0.9rem;
  background: var(--paper);
  border-color: var(--line);
  border-radius: 8px;
  min-height: 44px;
  padding: 9px 12px;
}
.form-section textarea.form-control {
  min-height: 64px;
  line-height: 1.45;
}
.form-section .form-control:focus,
.form-section .form-select:focus {
  background: var(--surface);
}
.form-section .form-control.mono,
.form-section .form-select.mono {
  font-family: var(--font-mono);
  font-size: 0.86rem;
}

/* Interrupteurs, agrandis par rapport au form-switch Bootstrap par defaut. */
.switch-line {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 0;
}
.switch-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.switch {
  position: relative;
  flex: 0 0 40px;
  width: 40px;
  height: 24px;
  margin: 0;
}
.switch input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}
.switch .track {
  position: absolute;
  inset: 0;
  background: var(--line-strong);
  border-radius: 999px;
  transition: background 0.15s ease;
}
.switch .track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease;
}
/* Combinateur general (~), pas adjacent (+) : asp-for sur une propriete bool
   insere un <input type="hidden"> juste apres la case a cocher, entre elle
   et .track. */
.switch input:checked ~ .track {
  background: var(--accent);
}
.switch input:checked ~ .track::after {
  transform: translateX(16px);
}
.switch input:focus-visible ~ .track {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.switch-text {
  font-size: 0.86rem;
  color: var(--ink);
  font-weight: 500;
}
.switch-text small {
  display: block;
  font-weight: 400;
  color: var(--muted);
  font-size: 0.76rem;
  margin-top: 1px;
}

/* Visuel de plage (montant / date) sous les paires min/max. */
.range-visual {
  margin-top: 4px;
}
.range-track {
  position: relative;
  height: 6px;
  border-radius: 3px;
  background: var(--paper);
  border: 1px solid var(--line);
  overflow: hidden;
}
.range-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  background: var(--accent);
  border-radius: 3px;
  transition: left 0.12s ease, right 0.12s ease;
}
.range-caption {
  margin-top: 7px;
  font-size: 0.78rem;
  color: var(--muted);
  font-family: var(--font-mono);
}

/* Apercu collant : traduit les champs du formulaire en phrase lisible. */
.form-aside {
  position: sticky;
  top: 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.preview-card {
  padding: 20px 22px 22px;
}
.preview-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.priority-badge {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--muted);
}
.preview-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--ink);
  margin: 0 0 14px;
}
.preview-sentence {
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--ink-soft);
  margin: 0;
  padding: 14px;
  background: var(--paper);
  border: 1px dashed var(--line-strong);
  border-radius: 10px;
}
.preview-sentence mark {
  background: none;
  color: var(--accent-strong);
  font-weight: 600;
  font-family: var(--font-mono);
  font-size: 0.86em;
  padding: 0;
}
.preview-sentence .cat-mark {
  color: var(--rust-strong);
  font-weight: 600;
  font-family: var(--font-body);
}
.preview-warning {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  font-size: 0.8rem;
  color: var(--amber);
  background: rgba(181, 138, 58, 0.1);
  border: 1px solid rgba(181, 138, 58, 0.3);
  border-radius: 8px;
  padding: 9px 11px;
  margin-top: 12px;
}
.preview-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px 10px;
  margin-top: 14px;
  font-size: 0.78rem;
  color: var(--muted);
}
.preview-meta .sep {
  color: var(--line-strong);
}
.preview-foot {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-size: 0.76rem;
  color: var(--muted);
  line-height: 1.5;
}

/* Barre d'actions : collee en bas du viewport sur mobile pour rester atteignable. */
.form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  padding: 18px 26px;
  border-top: 1px solid var(--line);
  background: var(--surface);
  border-radius: 0 0 12px 12px;
}
.form-actions .btn,
.form-actions .btn-ghost {
  min-height: 44px;
}
.form-actions-buttons {
  display: flex;
  gap: 10px;
}
.form-actions-note {
  font-size: 0.78rem;
  color: var(--muted);
}

@media (max-width: 960px) {
  .form-shell {
    grid-template-columns: 1fr;
  }
  .form-aside {
    position: static;
    order: -1;
  }
  .field-grid,
  .field-grid.cols-3 {
    grid-template-columns: 1fr;
  }
  .field.span-2 {
    grid-column: span 1;
  }
  .form-actions {
    position: sticky;
    bottom: 0;
    z-index: 5;
    box-shadow: 0 -6px 16px -8px rgba(28, 35, 51, 0.25);
    border-radius: 0;
  }
}
@media (max-width: 560px) {
  .form-section {
    padding: 18px 16px;
  }
  .form-actions {
    padding: 14px 16px;
    flex-direction: column-reverse;
    align-items: stretch;
  }
  .form-actions-buttons {
    flex-direction: column;
  }
  .form-actions-buttons .btn,
  .form-actions-buttons .btn-ghost {
    justify-content: center;
  }
  .preview-card {
    padding: 16px;
  }
}
@media (prefers-reduced-motion: reduce) {
  .switch .track,
  .switch .track::after,
  .range-fill {
    transition: none;
  }
}
