/* CDE ERP — styles communs (en complément de Tailwind CDN + assets/js/tw.js) */

:root {
  --cde: #BE1F2C;
  --cde-fonce: #9A1520;
  --cde-jaune: #FCDD01;
  --ink: #14171C;
  --ligne: #E3E6EA;
}

html { -webkit-text-size-adjust: 100%; }
body { font-feature-settings: 'tnum' 1, 'cv01' 1; }
.font-mono, .num { font-variant-numeric: tabular-nums; }
[x-cloak], [hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--cde); outline-offset: 2px; border-radius: 4px; }
::selection { background: #FBEAEC; color: #6E0F17; }

/* ---------- Boutons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .5rem; height: 2.375rem; padding: 0 1rem; border-radius: .6rem; font-size: .8125rem; font-weight: 600; line-height: 1; white-space: nowrap; transition: background-color .15s, box-shadow .15s, color .15s, border-color .15s, transform .05s; cursor: pointer; border: 1px solid transparent; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; pointer-events: none; }
.btn-primaire { background: var(--cde); color: #fff; box-shadow: 0 1px 2px rgba(110,15,23,.25), inset 0 1px 0 rgba(255,255,255,.12); }
.btn-primaire:hover { background: var(--cde-fonce); box-shadow: 0 8px 20px -8px rgba(190,31,44,.55); }
.btn-secondaire { background: #fff; color: var(--ink); border-color: var(--ligne); box-shadow: 0 1px 2px rgba(20,23,28,.04); }
.btn-secondaire:hover { background: #F7F8F9; border-color: #D3D7DC; }
.btn-fantome { background: transparent; color: #3B414B; }
.btn-fantome:hover { background: #EEF0F2; color: var(--ink); }
.btn-danger { background: #fff; color: #8A1F12; border-color: #F1C9C2; }
.btn-danger:hover { background: #FBE3DF; }
.btn-sm { height: 2rem; padding: 0 .75rem; font-size: .75rem; border-radius: .5rem; }
.btn-lg { height: 2.75rem; padding: 0 1.25rem; font-size: .875rem; }
.btn-icone { width: 2.375rem; padding: 0; }

/* ---------- Champs ---------- */
.champ { display: block; width: 100%; height: 2.5rem; padding: 0 .8rem; border: 1px solid #D5D9DE; border-radius: .6rem; background: #fff; font-size: .875rem; color: var(--ink); transition: border-color .15s, box-shadow .15s; }
.champ::placeholder { color: #9AA1AC; }
.champ:hover { border-color: #C2C7CE; }
.champ:focus { outline: none; border-color: var(--cde); box-shadow: 0 0 0 3px rgba(190,31,44,.12); }
textarea.champ { height: auto; padding: .6rem .8rem; resize: vertical; }
select.champ { appearance: none; padding-right: 2.25rem; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%236A7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' viewBox='0 0 24 24'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .7rem center; }
.champ.invalide { border-color: #D14B38; box-shadow: 0 0 0 3px rgba(209,75,56,.10); }
.etiquette { display: block; margin-bottom: .375rem; font-size: .75rem; font-weight: 600; color: #3B414B; }
.erreur-champ { margin-top: .35rem; font-size: .75rem; color: #8A1F12; display: flex; gap: .3rem; align-items: center; }
.aide-champ { margin-top: .35rem; font-size: .7rem; color: #9AA1AC; }
.groupe-champ { display: flex; align-items: stretch; border: 1px solid #D5D9DE; border-radius: .6rem; background: #fff; overflow: hidden; transition: border-color .15s, box-shadow .15s; }
.groupe-champ:focus-within { border-color: var(--cde); box-shadow: 0 0 0 3px rgba(190,31,44,.12); }
.groupe-champ input { flex: 1; min-width: 0; height: 2.5rem; padding: 0 .8rem; border: 0; outline: none; background: transparent; font-size: .875rem; }
.groupe-champ .suffixe { display: flex; align-items: center; padding: 0 .75rem; background: #F6F7F8; border-left: 1px solid #E3E6EA; color: #6A7280; font-size: .75rem; }

/* Puces de sélection (types de tiers, rôles…) */
.puce { display: inline-flex; align-items: center; gap: .35rem; padding: .35rem .75rem; border-radius: 999px; border: 1px solid #D5D9DE; background: #fff; font-size: .75rem; color: #3B414B; cursor: pointer; transition: all .15s; user-select: none; }
.puce:hover { border-color: #A9B0B9; }
.puce:has(input:checked) { border-color: var(--cde); background: #FBEAEC; color: #9A1520; font-weight: 600; }
.puce input { position: absolute; opacity: 0; pointer-events: none; }
.puce:has(input:focus-visible) { outline: 2px solid var(--cde); outline-offset: 2px; }

/* ---------- Pastilles de statut ---------- */
.pastille { display: inline-flex; align-items: center; gap: .3rem; padding: .15rem .55rem; border-radius: 999px; font-size: .6875rem; font-weight: 600; line-height: 1.1rem; white-space: nowrap; }
.pastille-vert { background: #DFF1E6; color: #14532D; }
.pastille-ambre { background: #FDF0DC; color: #6B3E05; }
.pastille-rouge { background: #FBE3DF; color: #8A1F12; }
.pastille-info { background: #E1ECF7; color: #163A5A; }
.pastille-neutre { background: #EEF0F2; color: #4A515C; }
.pastille-cde { background: #FBEAEC; color: #9A1520; }
.pastille .point { width: .375rem; height: .375rem; border-radius: 999px; background: currentColor; }

/* ---------- Cartes ---------- */
.carte { background: #fff; border: 1px solid var(--ligne); border-radius: 12px; box-shadow: 0 1px 2px rgba(20,23,28,.04), 0 1px 3px rgba(20,23,28,.03); }
.carte-titre { font-size: .875rem; font-weight: 600; color: var(--ink); }

/* ---------- Tableaux ---------- */
.tableau { width: 100%; border-collapse: separate; border-spacing: 0; font-size: .8125rem; }
.tableau thead th { position: sticky; top: 0; z-index: 1; background: #FAFBFB; padding: .65rem .9rem; text-align: left; font-size: .6875rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: #6A7280; border-bottom: 1px solid var(--ligne); white-space: nowrap; }
.tableau thead th:first-child { border-top-left-radius: 12px; }
.tableau thead th:last-child { border-top-right-radius: 12px; }
.tableau tbody td { padding: .75rem .9rem; border-bottom: 1px solid #EEF0F2; vertical-align: middle; color: #3B414B; }
.tableau tbody tr:last-child td { border-bottom: 0; }
.tableau tbody tr { transition: background-color .12s; }
.tableau tbody tr:hover { background: #FAFAFB; }
.tableau tbody tr[data-href], .tableau tbody tr[data-ouvrir] { cursor: pointer; }
.tableau th[data-tri] { cursor: pointer; user-select: none; }
.tableau th[data-tri]:hover { color: var(--ink); }
.tableau th[data-tri]::after { content: ''; display: inline-block; width: .5rem; margin-left: .3rem; opacity: .35; }
.tableau th[aria-sort="ascending"]::after { content: '▲'; font-size: .55rem; opacity: 1; color: var(--cde); }
.tableau th[aria-sort="descending"]::after { content: '▼'; font-size: .55rem; opacity: 1; color: var(--cde); }
.tableau .fin { text-align: right; }

/* ---------- Menu latéral ---------- */
.menu-lien { position: relative; display: flex; align-items: center; gap: .7rem; padding: .5rem .75rem; border-radius: .55rem; font-size: .8125rem; color: #C2C8D0; transition: background-color .15s, color .15s; }
.menu-lien:hover { background: #1E232A; color: #fff; }
.menu-lien svg, .menu-lien i { width: 1.05rem; height: 1.05rem; flex-shrink: 0; color: #7A828D; transition: color .15s; }
.menu-lien:hover svg { color: #C2C8D0; }
.menu-lien.actif { background: linear-gradient(90deg, rgba(190,31,44,.22), rgba(190,31,44,.06)); color: #fff; font-weight: 600; }
.menu-lien.actif::before { content: ''; position: absolute; left: -.625rem; top: .4rem; bottom: .4rem; width: 3px; border-radius: 0 3px 3px 0; background: var(--cde); box-shadow: 0 0 12px rgba(190,31,44,.8); }
.menu-lien.actif svg { color: #FF5A67; }
.menu-lien .badge-bientot { margin-left: auto; font-size: .6rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: #7A828D; border: 1px solid #2D333B; border-radius: 999px; padding: .05rem .4rem; }
.menu-groupe { margin: 1.1rem .75rem .4rem; font-size: .625rem; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; color: #6B737E; }
.menu-defile { scrollbar-width: thin; scrollbar-color: #2A3038 transparent; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; top: 1rem; right: 1rem; z-index: 90; display: flex; flex-direction: column; gap: .5rem; max-width: min(26rem, calc(100vw - 2rem)); }
.toast { display: flex; align-items: flex-start; gap: .65rem; padding: .8rem .9rem; border-radius: .8rem; background: #fff; border: 1px solid var(--ligne); box-shadow: 0 24px 48px -16px rgba(20,23,28,.28); animation: toast-entree .3s cubic-bezier(.2,.9,.3,1.2); font-size: .8125rem; color: var(--ink); }
.toast .icone { flex-shrink: 0; display: flex; width: 1.6rem; height: 1.6rem; align-items: center; justify-content: center; border-radius: 999px; }
.toast-succes .icone { background: #DFF1E6; color: #14532D; }
.toast-erreur .icone { background: #FBE3DF; color: #8A1F12; }
.toast.sortie { animation: toast-sortie .25s ease forwards; }
@keyframes toast-entree { from { opacity: 0; transform: translateY(-8px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes toast-sortie { to { opacity: 0; transform: translateX(16px); } }

/* ---------- Panneaux latéraux (formulaires) ---------- */
dialog.panneau { margin: 0 0 0 auto; height: 100dvh; max-height: 100dvh; width: min(30rem, 100vw); max-width: 100vw; padding: 0; border: 0; background: #fff; box-shadow: -24px 0 48px -16px rgba(20,23,28,.25); }
dialog.panneau[open] { animation: panneau-entree .28s cubic-bezier(.2,.8,.2,1); }
dialog.panneau::backdrop { background: rgba(17,20,24,.45); backdrop-filter: blur(2px); animation: fondu .2s ease; }
dialog.modale { margin: auto; width: min(32rem, calc(100vw - 2rem)); padding: 0; border: 0; border-radius: 16px; box-shadow: 0 24px 48px -16px rgba(20,23,28,.35); }
dialog.modale::backdrop { background: rgba(17,20,24,.45); backdrop-filter: blur(2px); }
@keyframes panneau-entree { from { transform: translateX(40px); opacity: .4; } to { transform: none; opacity: 1; } }
@keyframes fondu { from { opacity: 0; } }

/* Tiroir du menu sur tablette et téléphone */
dialog.tiroir { margin: 0 auto 0 0; height: 100dvh; max-height: 100dvh; width: min(18rem, 86vw); padding: 0; border: 0; background: #111418; }
dialog.tiroir[open] { animation: tiroir-entree .25s cubic-bezier(.2,.8,.2,1); }
dialog.tiroir::backdrop { background: rgba(0,0,0,.5); }
@keyframes tiroir-entree { from { transform: translateX(-30px); opacity: .5; } to { transform: none; opacity: 1; } }

/* Menu déroulant (utilisateur) */
details.deroulant > summary { list-style: none; cursor: pointer; }
details.deroulant > summary::-webkit-details-marker { display: none; }
details.deroulant[open] > .contenu-deroulant { animation: fondu .12s ease; }

/* Barre de progression du chargement de page */
.chargement { position: fixed; top: 0; left: 0; height: 2px; width: 0; background: linear-gradient(90deg, var(--cde), var(--cde-jaune)); z-index: 100; transition: width .4s ease, opacity .3s; }

/* Apparition douce des contenus */
.apparition > * { animation: apparition .35s ease both; }
.apparition > *:nth-child(2) { animation-delay: .04s; }
.apparition > *:nth-child(3) { animation-delay: .08s; }
.apparition > *:nth-child(4) { animation-delay: .12s; }
.apparition > *:nth-child(5) { animation-delay: .16s; }
@keyframes apparition { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

@media print {
  aside, header.barre-haute, .no-print { display: none !important; }
  body { background: #fff !important; }
}
