/* ==========================================================================
   components.css : composants de la famille Rivia (v1, 14/11/2026)
   Dépend de tokens.css (à charger avant). Aucune valeur en dur : tout vient des jetons.
   Mode d'emploi et règles : DA-RIVIA-APPS.md. Rendu de chaque composant : reference.html.
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }
h1, h2, h3, h4, p { margin: 0; }
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand-text); text-underline-offset: 0.18em; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: var(--focus-w) solid var(--focus); outline-offset: var(--focus-offset); border-radius: var(--r-s); }
::selection { background: var(--brand); color: var(--on-brand); }
.icon { width: var(--icon); height: var(--icon); flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.tnum { font-variant-numeric: tabular-nums lining-nums; }

/* ---------- Texte ---------- */
.t-page { font-size: var(--fs-page); line-height: var(--lh-title); font-weight: var(--fw-bold); letter-spacing: var(--ls-title); color: var(--text); text-wrap: balance; }
.t-section { font-size: var(--fs-section); line-height: var(--lh-section); font-weight: var(--fw-bold); letter-spacing: var(--ls-title); color: var(--text); text-wrap: balance; }
.t-body { font-size: var(--fs-body); line-height: var(--lh-body); color: var(--text); max-width: var(--measure); }
.t-lead { font-size: var(--fs-body); line-height: var(--lh-body); color: var(--text-2); max-width: var(--measure); }
.t-ui { font-size: var(--fs-ui); line-height: var(--lh-ui); font-weight: var(--fw-ui); color: var(--text-2); }
.t-meta { font-size: var(--fs-meta); line-height: var(--lh-ui); color: var(--text-3); }
.t-kpi { font-size: var(--fs-kpi); line-height: 1.1; font-weight: var(--fw-bold); letter-spacing: var(--ls-title); font-variant-numeric: tabular-nums lining-nums; color: var(--text); }

/* ---------- Bouton ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2); min-height: var(--hit); padding: var(--sp-2) var(--sp-5); border: var(--bw) solid transparent; border-radius: var(--r-m); font-size: var(--fs-body); line-height: 1.2; font-weight: var(--fw-semibold); text-decoration: none; text-align: center; max-width: 100%; cursor: pointer; transition: background-color var(--dur-fast) var(--ease-std), border-color var(--dur-fast) var(--ease-std), transform var(--dur-fast) var(--ease-out); -webkit-tap-highlight-color: transparent; }
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--brand); color: var(--on-brand); }
.btn-primary:hover { background: var(--brand-hover); }
.btn-primary:active { background: var(--brand-active); }
:root[data-theme="dark"] .btn-primary { border-color: var(--brand-border); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--brand-text); padding: var(--sp-2) var(--sp-4); }
.btn-ghost:hover { background: var(--active-bg); color: var(--active-text); }
.btn-danger { background: var(--danger-solid); color: var(--on-solid); }
.btn-danger:hover { filter: brightness(0.92); }
.btn[disabled], .btn[aria-disabled="true"] { background: var(--surface-2); color: var(--text-3); border-color: var(--border); cursor: not-allowed; transform: none; filter: none; }
.btn[aria-busy="true"] { cursor: progress; }
.btn[aria-busy="true"]::before { content: ""; width: 1em; height: 1em; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.btn-sm { min-height: 2.25rem; padding: var(--sp-1) var(--sp-4); font-size: var(--fs-ui); }
.btn-icon { width: var(--hit); padding: 0; }
.btn-block { width: 100%; }
@media (pointer: coarse) { .btn-sm { min-height: var(--hit-min); } }

/* ---------- Champ ---------- */
.field { display: grid; gap: var(--sp-2); }
.label { font-size: var(--fs-ui); line-height: var(--lh-ui); font-weight: var(--fw-semibold); color: var(--text); }
.input, .select, .textarea { width: 100%; min-height: var(--hit); padding: 0 var(--sp-4); background: var(--surface); color: var(--text); border: var(--bw) solid var(--border-strong); border-radius: var(--r-m); font-size: var(--fs-body); line-height: var(--lh-body); transition: border-color var(--dur-fast) var(--ease-std); }
.textarea { padding: var(--sp-3) var(--sp-4); min-height: 6rem; resize: vertical; }
.select { appearance: none; padding-right: var(--sp-7); background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right var(--sp-3) center; background-size: 1.25rem; }
.input::placeholder, .textarea::placeholder { color: var(--text-3); opacity: 1; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-2); }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible { outline: var(--focus-w) solid var(--focus); outline-offset: 0; border-color: var(--focus); }
.input[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--danger-solid); border-width: 2px; }
.input[disabled], .select[disabled] { background: var(--surface-2); color: var(--text-3); cursor: not-allowed; }
.help { font-size: var(--fs-meta); line-height: var(--lh-ui); color: var(--text-3); }
.error-text { display: flex; gap: var(--sp-2); align-items: flex-start; font-size: var(--fs-ui); line-height: var(--lh-ui); font-weight: var(--fw-medium); color: var(--danger); }
.error-text .icon { width: 1rem; height: 1rem; margin-top: 0.1rem; }
.check { display: flex; gap: var(--sp-3); align-items: center; min-height: var(--hit); font-size: var(--fs-body); cursor: pointer; }
.check input:not(.switch) { appearance: none; flex: none; width: 1.375rem; height: 1.375rem; margin: 0; border: 2px solid var(--border-strong); border-radius: var(--r-xs); background: var(--surface); display: grid; place-content: center; cursor: pointer; }
.check input[type="radio"] { border-radius: 50%; }
.check input:not(.switch):checked { background: var(--brand); border-color: var(--brand); }
.check input[type="checkbox"]:not(.switch):checked::after { content: ""; width: 0.375rem; height: 0.7rem; border: solid var(--on-brand); border-width: 0 2.5px 2.5px 0; transform: translateY(-1px) rotate(45deg); }
.check input[type="radio"]:checked::after { content: ""; width: 0.5rem; height: 0.5rem; border-radius: 50%; background: var(--on-brand); }
.switch { appearance: none; flex: none; width: 3rem; height: 1.75rem; margin: 0; border-radius: var(--r-pill); background: var(--surface-2); border: 2px solid var(--border-strong); position: relative; cursor: pointer; transition: background-color var(--dur-base) var(--ease-std); }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 1.125rem; height: 1.125rem; border-radius: 50%; background: var(--text-2); transition: transform var(--dur-base) var(--ease-out); }
.switch:checked { background: var(--brand); border-color: var(--brand); }
.switch:checked::after { background: var(--on-brand); transform: translateX(1.25rem); }

/* ---------- Carte (jamais une carte dans une carte) ---------- */
.card { background: var(--surface); border: var(--bw) solid var(--border); border-radius: var(--r-l); padding: var(--sp-5); box-shadow: var(--shadow-1); min-width: 0; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-4); margin-bottom: var(--sp-4); }
.card-flush { padding: 0; overflow: hidden; }
.stat { display: grid; gap: var(--sp-2); align-content: start; }
.stat .t-ui { color: var(--text-2); }
.delta { display: inline-flex; align-items: center; gap: var(--sp-1); font-size: var(--fs-meta); font-weight: var(--fw-semibold); color: var(--success); }
.delta.neg { color: var(--danger); }
.grid { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr)); }

/* ---------- Pastille (statut) : toujours une icône ou un mot, jamais la couleur seule ---------- */
.pill { display: inline-flex; align-items: center; gap: var(--sp-1); min-height: 1.5rem; padding: 0 var(--sp-3) 0 var(--sp-2); border: 1px solid var(--border); border-radius: var(--r-pill); background: var(--surface-2); color: var(--text-2); font-size: var(--fs-meta); line-height: 1; font-weight: var(--fw-semibold); white-space: nowrap; }
.pill .icon { width: 0.875rem; height: 0.875rem; stroke-width: 2.5; }
.pill-success { background: var(--success-soft); border-color: var(--success-border); color: var(--success); }
.pill-warning { background: var(--warning-soft); border-color: var(--warning-border); color: var(--warning); }
.pill-danger { background: var(--danger-soft); border-color: var(--danger-border); color: var(--danger); }
.pill-brand { background: var(--brand-soft); border-color: var(--brand-border); color: var(--brand-soft-text); }
:root[data-theme="sun"] .pill { border-width: 2px; }

/* ---------- Tableau ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: inherit; }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-ui); line-height: var(--lh-ui); }
.table th { position: sticky; top: 0; padding: var(--sp-3) var(--sp-4); text-align: left; white-space: nowrap; font-size: var(--fs-meta); font-weight: var(--fw-semibold); color: var(--text-2); background: var(--surface-2); border-bottom: var(--bw) solid var(--border); }
.table td { white-space: nowrap; padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border); vertical-align: middle; color: var(--text); height: 3.5rem; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums lining-nums; white-space: nowrap; }
.table .cell-main { font-weight: var(--fw-semibold); }
.table .cell-sub { display: block; font-size: var(--fs-meta); color: var(--text-3); font-weight: var(--fw-regular); }
.table tfoot td { background: var(--surface-2); font-weight: var(--fw-bold); border-top: var(--bw) solid var(--border); border-bottom: 0; }
.table .trunc { max-width: 18rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table-meta { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3); padding: var(--sp-4); flex-wrap: wrap; }

/* ---------- Navigation ---------- */
.nav { display: grid; gap: var(--sp-1); }
.nav-group + .nav-group { margin-top: var(--sp-5); }
.nav-label { padding: 0 var(--sp-3); margin-bottom: var(--sp-2); font-size: var(--fs-meta); font-weight: var(--fw-semibold); color: var(--text-3); }
.nav a { display: flex; align-items: center; gap: var(--sp-3); min-height: var(--hit); padding: 0 var(--sp-3); border-radius: var(--r-m); border: var(--bw) solid transparent; color: var(--text-2); font-size: var(--fs-ui); font-weight: var(--fw-medium); text-decoration: none; transition: background-color var(--dur-fast) var(--ease-std); }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a[aria-current="page"] { background: var(--active-bg); color: var(--active-text); font-weight: var(--fw-bold); }
.nav .count { margin-left: auto; font-size: var(--fs-meta); font-variant-numeric: tabular-nums; }
.tabs { display: flex; gap: var(--sp-1); border-bottom: var(--bw) solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tab { display: inline-flex; align-items: center; min-height: var(--hit); padding: 0 var(--sp-4); background: none; border: 0; border-bottom: 3px solid transparent; margin-bottom: -1px; color: var(--text-2); font-size: var(--fs-ui); font-weight: var(--fw-semibold); white-space: nowrap; cursor: pointer; border-radius: var(--r-s) var(--r-s) 0 0; }
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab[aria-selected="true"] { color: var(--brand-text); border-bottom-color: var(--brand); font-weight: var(--fw-bold); }
.tabbar { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; min-height: var(--tabbar-h); padding-bottom: var(--safe-bottom); background: var(--surface); border-top: var(--bw) solid var(--border); }
.tabbar a { display: grid; place-items: center; align-content: center; gap: 2px; min-height: var(--hit-min); color: var(--text-2); font-size: var(--fs-meta); font-weight: var(--fw-semibold); text-decoration: none; }
.tabbar a[aria-current="page"] { color: var(--brand-text); font-weight: var(--fw-bold); }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); min-height: var(--topbar-h); padding: 0 var(--gutter); background: var(--surface); border-bottom: var(--bw) solid var(--border); }
.logo { display: inline-flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-section); font-weight: var(--fw-bold); letter-spacing: var(--ls-title); color: var(--text); text-decoration: none; }
.logo-mark { display: grid; place-items: center; width: 2rem; height: 2rem; border-radius: var(--r-s); background: var(--brand); color: var(--on-brand); font-size: var(--fs-ui); font-weight: var(--fw-bold); }
.segmented { display: inline-flex; padding: var(--sp-1); gap: var(--sp-1); background: var(--surface-2); border: var(--bw) solid var(--border); border-radius: var(--r-m); }
.segmented button { min-height: 2.25rem; padding: 0 var(--sp-3); border: 0; border-radius: var(--r-s); background: none; color: var(--text-2); font-size: var(--fs-ui); font-weight: var(--fw-semibold); cursor: pointer; }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); outline: var(--bw) solid var(--border-strong); }
@media (pointer: coarse) { .segmented button { min-height: var(--hit-min); } }

/* ---------- État vide, chargement, message, notification ---------- */
.empty { display: grid; justify-items: center; gap: var(--sp-3); padding: var(--sp-7) var(--sp-5); text-align: center; }
.empty .t-lead { max-width: 28rem; }
.empty-icon { display: grid; place-items: center; width: 3.5rem; height: 3.5rem; border-radius: 50%; background: var(--active-bg); color: var(--active-text); }
.empty-icon .icon { width: 1.75rem; height: 1.75rem; }
.skeleton { display: block; border: 1px solid var(--border); height: 1rem; border-radius: var(--r-xs); background: var(--surface-2); background-image: linear-gradient(90deg, transparent, var(--shine), transparent); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.alert { display: grid; grid-template-columns: auto 1fr auto; gap: var(--sp-3); align-items: start; padding: var(--sp-4); border: var(--bw) solid var(--brand-border); border-radius: var(--r-m); background: var(--brand-soft); color: var(--text); font-size: var(--fs-ui); line-height: var(--lh-ui); }
.alert .icon { margin-top: 0.1rem; color: var(--brand-soft-text); }
.alert-title { font-weight: var(--fw-bold); font-size: var(--fs-body); line-height: var(--lh-section); color: var(--brand-soft-text); }
.alert p { margin-top: var(--sp-1); color: var(--text); font-size: var(--fs-ui); }
.alert-actions { display: flex; flex-wrap: wrap; gap: var(--sp-3); margin-top: var(--sp-3); grid-column: 2 / -1; }
.alert-success { background: var(--success-soft); border-color: var(--success-border); }
.alert-success .icon, .alert-success .alert-title { color: var(--success); }
.alert-warning { background: var(--warning-soft); border-color: var(--warning-border); }
.alert-warning .icon, .alert-warning .alert-title { color: var(--warning); }
.alert-danger { background: var(--danger-soft); border-color: var(--danger-border); }
.alert-danger .icon, .alert-danger .alert-title { color: var(--danger); }
.toast { display: flex; align-items: center; gap: var(--sp-3); width: fit-content; max-width: 100%; padding: var(--sp-3) var(--sp-4); background: var(--raised); color: var(--text); border: var(--bw) solid var(--border-strong); border-radius: var(--r-m); box-shadow: var(--shadow-2); font-size: var(--fs-ui); font-weight: var(--fw-semibold); }
.toast .icon { color: var(--success); }

/* ---------- Fenêtre modale ---------- */
.modal-backdrop { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: var(--sp-4); background: var(--overlay); }
dialog.modal { padding: 0; border: 0; background: transparent; color: var(--text); max-width: calc(100vw - 2rem); }
dialog.modal::backdrop { background: var(--overlay); }
.modal-panel { width: min(30rem, 100%); padding: var(--sp-5); background: var(--raised); border: var(--bw) solid var(--border); border-radius: var(--r-l); box-shadow: var(--shadow-3); display: grid; gap: var(--sp-4); }
.modal-panel .t-body { color: var(--text-2); }
.modal-actions { display: flex; gap: var(--sp-3); justify-content: flex-end; flex-wrap: wrap; }
@media (max-width: 767px) { .modal-actions { flex-direction: column-reverse; } .modal-actions .btn { width: 100%; } }
dialog.modal[open] .modal-panel { animation: rise var(--dur-slow) var(--ease-out); }
@keyframes rise { from { opacity: 0; transform: translateY(0.75rem); } to { opacity: 1; transform: none; } }

/* ---------- Mise en page ---------- */
.container { width: 100%; max-width: var(--content-max); margin-inline: auto; padding-inline: calc(var(--gutter) + var(--safe-left)) calc(var(--gutter) + var(--safe-right)); }
.stack { display: grid; gap: var(--sp-4); }
.stack-lg { display: grid; gap: var(--sp-6); }
.row { display: flex; gap: var(--sp-3); flex-wrap: wrap; align-items: center; }
.page-head { display: grid; gap: var(--sp-2); margin-bottom: var(--sp-6); }
.bar { display: grid; grid-template-columns: 7rem 1fr auto; gap: var(--sp-3); align-items: center; font-size: var(--fs-ui); }
.bar-track { height: 0.75rem; border-radius: var(--r-pill); background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: var(--r-pill); background: var(--viz-1); }

/* Réactivité (15/11/2026, règles Apple WWDC « Designing Fluid Interfaces ») : retour dès l'appui, pas de délai de tap, pas de survol collé au doigt. */
a, button, summary, [role="button"], [role="tab"], .btn, .nav a, .tabbar a, .tabs a, .pill, label[for] { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.nav a:active, .tabbar a:active, .tabs [role="tab"]:active, .tabs a:active { transform: scale(0.97); transition-duration: 0ms; }
@media (prefers-reduced-motion: reduce) { .btn:active, .nav a:active, .tabbar a:active { transform: none; } }
