/* Intranet ASI — base : reset, typographie, formulaires, tableaux, boutons, dialogues */

*, *::before, *::after { box-sizing: border-box; }

html { height: 100%; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: "kern", "liga", "calt";
}

h1, h2, h3, h4 { margin: 0; font-family: var(--font-heading); letter-spacing: -.018em; font-weight: 600; line-height: 1.2; text-wrap: balance; }
h1 { font-size: 27px; letter-spacing: -.025em; }
h2 { font-size: 19px; }
h3 { font-size: 16px; }
p { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }
figure { margin: 0; }
img, svg, video, canvas { display: block; max-width: 100%; }
svg { fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--space-4) 0; }
code, kbd, pre, .mono { font-family: var(--mono); font-size: 13px; }
pre { margin: 0; white-space: pre-wrap; word-break: break-word; }
small, .meta { font-size: 13px; color: var(--text-2); }
.muted { color: var(--text-muted); }
.num, td.num, th.num, .tabular { font-variant-numeric: tabular-nums; }
td.num, th.num { text-align: right; }

a { color: var(--accent-strong); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus { outline: none; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--radius-s); }

::selection { background: var(--blue-subtle); color: var(--text); }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Boutons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: 36px; padding: 0 var(--space-4);
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font-family: var(--font-heading); font-weight: 600; font-size: 14px; line-height: 1;
  cursor: pointer; white-space: nowrap; text-decoration: none;
  box-shadow: var(--shadow-sm);
  transition: background-color var(--duration) var(--ease), border-color var(--duration) var(--ease), color var(--duration) var(--ease), box-shadow var(--duration) var(--ease), transform var(--duration) var(--ease);
}
.btn:hover { background: var(--blue-light); border-color: var(--accent); color: var(--accent); text-decoration: none; }
.btn:active { background: var(--active); transform: translateY(1px) scale(.985); box-shadow: none; transition-duration: 60ms; }
.btn:focus-visible { outline: none; box-shadow: var(--focus-ring); border-color: var(--focus); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: default; pointer-events: none; box-shadow: none; }
/* Principal : léger dégradé et reflet en haut, ombre teintée ; c'est l'action que l'œil doit trouver. */
.btn-primary, .btn-primary:active {
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 88%, #fff) 0%, var(--accent) 60%); border-color: var(--accent-strong); color: var(--on-accent);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .18), 0 1px 2px color-mix(in srgb, var(--accent) 35%, transparent);
}
.btn-primary:hover { background: linear-gradient(180deg, var(--accent) 0%, var(--accent-strong) 100%); border-color: var(--accent-strong); color: var(--on-accent); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .14), 0 3px 8px -2px color-mix(in srgb, var(--accent) 45%, transparent); }
.btn-primary:active { box-shadow: inset 0 1px 2px rgba(0, 0, 0, .15); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); box-shadow: none; }
.btn-ghost:hover { color: var(--accent); border-color: transparent; background: var(--hover); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--border-strong)); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.btn-sm { min-height: 30px; padding: 0 var(--space-3); font-size: 13px; }
.btn-icon { padding: 0; width: 36px; }
.btn-icon.btn-sm { width: 30px; }
.btn .spinner { width: 14px; height: 14px; border-width: 2px; }

/* Champs */
.field { display: flex; flex-direction: column; gap: var(--space-1); min-width: 0; }
.field > label, .field-label { font-size: 13px; font-weight: 500; color: var(--text-2); }
.field-hint { font-size: 12px; color: var(--text-muted); }
.field-error { font-size: 13px; color: var(--danger); }
.field.has-error .input { border-color: var(--danger); }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--space-4); }
.input, select.input, textarea.input {
  width: 100%; min-height: 36px; padding: 6px var(--space-3);
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--input-bg); color: var(--text);
  font: inherit; font-size: 15px;
  box-shadow: inset 0 1px 1px rgba(15, 23, 42, .03);
  transition: border-color var(--duration) var(--ease), box-shadow var(--duration) var(--ease);
}
.input:hover { border-color: var(--text-muted); }
.input:focus-visible { outline: none; border-color: var(--focus); box-shadow: var(--focus-ring); }
.input::placeholder { color: var(--text-muted); }
.input:disabled { opacity: .55; }
textarea.input { min-height: 88px; resize: vertical; line-height: 1.4; }
select.input {
  appearance: none; padding-right: 32px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 20 20' fill='none' stroke='%2364748b' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 8l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}
input[type="date"].input, input[type="month"].input, input[type="time"].input { font-variant-numeric: tabular-nums; }
input[type="checkbox"], input[type="radio"] { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.check { display: inline-flex; align-items: center; gap: var(--space-2); font-size: 14px; cursor: pointer; min-height: 36px; }
.radio-group { display: flex; gap: var(--space-4); flex-wrap: wrap; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { padding: 0; font-size: 13px; font-weight: 500; color: var(--text-2); margin-bottom: var(--space-1); }
.form { display: flex; flex-direction: column; gap: var(--space-4); }
.form-actions { display: flex; gap: var(--space-2); justify-content: flex-end; flex-wrap: wrap; padding-top: var(--space-2); }
.form-error { padding: var(--space-3); border-radius: var(--radius); background: var(--danger-soft); color: var(--text); font-size: 14px; border-left: 2px solid var(--danger); }
.form-notice { padding: var(--space-3); border-radius: var(--radius); background: var(--info-soft); font-size: 14px; border-left: 2px solid var(--info); }

/* Tableaux */
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius-l); background: var(--surface); max-height: calc(100vh - 220px); box-shadow: var(--shadow-sm); }
.table-wrap.table-auto { max-height: none; }
table.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; }
.table th, .table td { padding: 10px var(--space-4); text-align: left; vertical-align: middle; border-bottom: 1px solid var(--border); }
.table th {
  position: sticky; top: 0; z-index: 1;
  background: color-mix(in srgb, var(--surface-2) 92%, var(--surface)); color: var(--text-2);
  font-weight: 600; font-size: 12px; letter-spacing: .03em; text-transform: uppercase; white-space: nowrap;
  box-shadow: inset 0 -1px 0 var(--border);
}
.table th.sortable { cursor: pointer; user-select: none; }
.table th.sortable:hover { color: var(--text); }
.table th .sort-ind { display: inline-block; width: 12px; margin-left: 4px; color: var(--text-muted); }
.table th[aria-sort="ascending"] .sort-ind::after { content: "▲"; font-size: 9px; }
.table th[aria-sort="descending"] .sort-ind::after { content: "▼"; font-size: 9px; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover, .table tbody tr:focus-within { background: var(--hover); }
.table td.actions, .table th.actions { text-align: right; white-space: nowrap; }
.table td.actions .btn { margin-left: var(--space-1); }
.table tfoot td { background: var(--surface-2); font-weight: 500; border-top: 1px solid var(--border-strong); border-bottom: 0; position: sticky; bottom: 0; }
.table .nowrap { white-space: nowrap; }
.table-dense th, .table-dense td { padding: 6px var(--space-2); }

/* Dialogues */
dialog.dialog {
  padding: 0; border: 1px solid var(--border); border-radius: var(--radius-xl);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
  width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
}
dialog.dialog[open] { animation: dialog-in var(--duration-slow) var(--ease-out); }
dialog.dialog.dialog-wide { width: min(760px, calc(100vw - 32px)); }
dialog.dialog::backdrop { background: var(--scrim); backdrop-filter: blur(6px) saturate(.9); -webkit-backdrop-filter: blur(6px) saturate(.9); animation: backdrop-in var(--duration-slow) var(--ease-out); }
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(.985); } to { opacity: 1; transform: none; } }
@keyframes backdrop-in { from { opacity: 0; } to { opacity: 1; } }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-4) var(--space-6) 0; }
.dialog-head h2 { font-size: 18px; }
.dialog-body { padding: var(--space-4) var(--space-6); overflow: auto; max-height: calc(100vh - 180px); }
.dialog-actions { display: flex; justify-content: flex-end; gap: var(--space-2); padding: 0 var(--space-6) var(--space-6); flex-wrap: wrap; }
.dialog-body p + p { margin-top: var(--space-3); }

/* Chargement */
.spinner {
  display: inline-block; width: 18px; height: 18px;
  border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
/* Entrées en douceur : les cartes et blocs de contenu montent d'un rien en apparaissant ; les menus contextuels
   s'ouvrent depuis leur coin ; une valeur qui change (compteur, badge) « pop » un instant. Rapides (≤ 260 ms),
   coupées sous prefers-reduced-motion. */
@keyframes rise-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes menu-in { from { opacity: 0; transform: scale(.96) translateY(-2px); } to { opacity: 1; transform: none; } }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.18); } 100% { transform: scale(1); } }
@keyframes flash-ok { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 45%, transparent); } 100% { box-shadow: 0 0 0 10px transparent; } }
.anim-rise { animation: rise-in .24s var(--ease-out) both; }
.anim-pop { animation: pop .28s var(--ease-out); }
/* Barres de progression : la largeur glisse au lieu de sauter */
.bar > span { transition: width .35s var(--ease-out); }
/* Lignes de tableau et éléments de liste : survol fondu */
tbody tr { transition: background-color .12s var(--ease); }
/* Champs : le contour se tend en douceur */
.input, select.input, textarea.input { transition: border-color var(--duration) var(--ease), box-shadow var(--duration) var(--ease), background-color var(--duration) var(--ease); }
/* Repliables natifs : le contenu apparaît en montant */
details[open] > :not(summary) { animation: rise-in .2s var(--ease-out) both; }
details > summary { transition: color var(--duration) var(--ease); }
input[type="checkbox"], input[type="radio"] { transition: transform .12s var(--ease-out); }
input[type="checkbox"]:active, input[type="radio"]:active { transform: scale(.9); }
.loading { display: flex; align-items: center; gap: var(--space-3); color: var(--text-2); padding: var(--space-4) 0; font-size: 14px; }
/* Squelette : barres au reflet qui glisse, à la place d'un sablier ; dans un dialogue, il prend la largeur */
.skeleton { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 560px; }
.skeleton > span {
  display: block; height: 12px; border-radius: 6px;
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-3) 40%, var(--surface-2) 80%);
  background-size: 200% 100%; animation: shimmer 1.4s ease-in-out infinite;
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton > span { animation: none; background: var(--surface-2); } }

/* Barres de progression */
.bar { position: relative; height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 3px; transition: width var(--duration) var(--ease); }
.bar.bar-warn > span { background: var(--warn); }
.bar.bar-danger > span { background: var(--danger); }
.bar.bar-ok > span { background: var(--ok); }

/* Sélection et scroll */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 5px; border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
  .spinner { animation: none; border-top-color: var(--accent); opacity: .7; }
}

/* Téléphone : chaque ligne de tableau devient une fiche (libellé de colonne devant la valeur). */
@media (max-width: 699px) {
  .table-wrap:not(.table-flat) { max-height: none; }
  .table-wrap:not(.table-flat) .table thead { display: none; }
  .table-wrap:not(.table-flat) .table, .table-wrap:not(.table-flat) .table tbody, .table-wrap:not(.table-flat) .table tr, .table-wrap:not(.table-flat) .table tfoot { display: block; width: 100%; }
  .table-wrap:not(.table-flat) .table tr { padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--border); }
  .table-wrap:not(.table-flat) .table tr:last-child { border-bottom: 0; }
  .table-wrap:not(.table-flat) .table td { display: grid; grid-template-columns: 100px minmax(0, 1fr); gap: var(--space-2); align-items: start; padding: 3px 0; border: 0; text-align: left; white-space: normal; }
  .table-wrap:not(.table-flat) .table td::before { content: attr(data-label); color: var(--text-2); font-size: 12px; padding-top: 2px; }
  .table-wrap:not(.table-flat) .table td[data-label=""] { grid-template-columns: minmax(0, 1fr); }
  .table-wrap:not(.table-flat) .table td[data-label=""]::before { content: none; }
  .table-wrap:not(.table-flat) .table td.actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: var(--space-1); padding-top: var(--space-2); }
  .table-wrap:not(.table-flat) .table td.actions::before { content: none; }
  .table-wrap:not(.table-flat) .table td[colspan] { display: block; }
  .table-wrap:not(.table-flat) .table td.num { text-align: left; }
  .table-wrap:not(.table-flat) .table td:empty { display: none; } /* cellule vide : pas de libellé orphelin */
}
