/* =========================================================================
   PREFOREST — Système de design des pages autonomes
   Style « Data-Dense Dashboard » · thème vert forêt · light + dark (WCAG AA)
   ========================================================================= */

:root {
    /* Marque (vert forêt) */
    --brand-50: #f0fdf4;
    --brand-100: #dcfce7;
    --brand-600: #16a34a;
    --brand-700: #15803d;
    --brand-800: #166534;
    --brand-900: #14532d;
    --brand: var(--brand-800);
    --brand-ink: var(--brand-900);
    --on-brand: #ffffff;

    /* Accent (ambre) */
    --accent: #b45309;
    --accent-soft: #fffbeb;

    /* Surfaces & texte */
    --bg: #eef2f6;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e2e8f0;
    --text: #0f172a;
    --text-muted: #64748b;
    --text-soft: #94a3b8;

    /* Sémantique */
    --success-bg: #ecfdf5; --success-fg: #065f46; --success-bd: #a7f3d0;
    --warning-bg: #fffbeb; --warning-fg: #92400e; --warning-bd: #fde68a;
    --danger-bg: #fef2f2; --danger-fg: #991b1b; --danger-bd: #fecaca;
    --danger: #b91c1c;

    /* Rayons */
    --r-sm: 8px; --r: 12px; --r-lg: 16px; --r-full: 999px;

    /* Ombres */
    --sh-sm: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .08);
    --sh: 0 4px 14px rgba(15, 23, 42, .08);
    --sh-lg: 0 14px 40px rgba(15, 23, 42, .14);
    --ring: 0 0 0 3px rgba(22, 101, 52, .22);

    --nav-active-bg: #f0fdf4;

    --font: 'Fira Sans', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --font-mono: 'Fira Code', ui-monospace, "SFMono-Regular", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
    :root {
        --brand: #16a34a;
        --brand-ink: #4ade80;
        --accent: #f59e0b;
        --accent-soft: #26200f;
        --bg: #0b1120;
        --surface: #111a2e;
        --surface-2: #0e1626;
        --border: #223049;
        --text: #e5eaf1;
        --text-muted: #97a3b6;
        --text-soft: #64748b;
        --success-bg: #06281f; --success-fg: #6ee7b7; --success-bd: #12503c;
        --warning-bg: #2a1f07; --warning-fg: #fcd34d; --warning-bd: #4d3a10;
        --danger-bg: #2a1113; --danger-fg: #fca5a5; --danger-bd: #5a1f22;
        --sh-sm: 0 1px 2px rgba(0, 0, 0, .4);
        --sh: 0 6px 18px rgba(0, 0, 0, .45);
        --sh-lg: 0 16px 44px rgba(0, 0, 0, .6);
        --ring: 0 0 0 3px rgba(34, 197, 94, .3);
        --nav-active-bg: rgba(34, 197, 94, .14);
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    line-height: 1.55;
}

a { color: var(--brand-700); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, .h1 { font-size: 1.5rem; font-weight: 700; color: var(--brand-ink); margin: 0 0 .25rem; letter-spacing: -.01em; }
h2, .h2 { font-size: 1.05rem; font-weight: 600; color: var(--brand-ink); margin: 1.5rem 0 .7rem; }
.muted { color: var(--text-muted); }
.tnum { font-variant-numeric: tabular-nums; }

/* ---- Coquille : barre d'application ---- */
.app-bar {
    position: sticky; top: 0; z-index: 50;
    display: flex; align-items: center; gap: 1rem;
    padding: .7rem 1.25rem;
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: saturate(1.4) blur(8px);
    border-bottom: 1px solid var(--border);
}
.app-bar__brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; color: var(--brand-ink); }
.app-bar__brand img { height: 30px; width: auto; border-radius: 6px; }
.app-bar__title { color: var(--text-muted); font-weight: 500; border-left: 1px solid var(--border); padding-left: 1rem; }
.app-bar__spacer { flex: 1; }
.app-bar a.back { color: var(--text-muted); font-weight: 600; font-size: .85rem; }

.container { max-width: 1080px; margin: 0 auto; padding: 1.75rem 1.25rem 3rem; }
.container--narrow { max-width: 720px; }

/* ---- Coquille avec barre latérale ---- */
.shell { display: flex; min-height: 100dvh; }
.sidebar {
    width: 244px; flex-shrink: 0;
    background: var(--surface); border-right: 1px solid var(--border);
    position: sticky; top: 0; height: 100dvh; overflow-y: auto;
    /* Colonne, pour que le pied (compte + déconnexion) tombe en bas.
       La réserve en bas dégage la barre de debug Symfony, qui recouvre le bas
       de la fenêtre en dev et masquerait sinon le lien de déconnexion. */
    display: flex; flex-direction: column;
    padding: 1rem .75rem 2.75rem;
}
/* Poussé en bas, sans espace mort après lui. Menu long, espace nul : le pied
   suit simplement le dernier lien. */
.sidebar__foot { margin-top: auto; padding-top: 1rem; border-top: 1px solid var(--border); }
.sidebar__user { font-size: .76rem; color: var(--text-soft); padding: .1rem .7rem .4rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar__version { font-size: .7rem; color: var(--text-soft); padding: .5rem .7rem 0; font-variant-numeric: tabular-nums; }
.nav-badge { margin-left: auto; min-width: 1.4em; padding: 0 .4em; border-radius: 999px; background: var(--danger); color: #fff; font-size: .72rem; font-weight: 700; line-height: 1.5; text-align: center; }
.nav-link--logout { color: var(--danger); }
.nav-link--logout:hover { background: var(--danger-bg); color: var(--danger-fg); }
.sidebar__brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; color: var(--brand-ink); padding: .35rem .5rem .8rem; }
.sidebar__brand img { height: 30px; width: auto; border-radius: 7px; }
.nav-sec { text-transform: uppercase; font-size: .68rem; color: var(--text-soft); letter-spacing: .06em; margin: 1rem .6rem .3rem; font-weight: 600; }
.nav-link { display: flex; align-items: center; gap: .6rem; padding: .5rem .7rem; border-radius: var(--r-sm); color: var(--text-muted); font-weight: 500; font-size: .9rem; margin-bottom: 1px; }
.nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--nav-active-bg); color: var(--brand-700); font-weight: 600; }
.nav-link .icon { opacity: .8; }
.main-area { flex: 1; min-width: 0; }

@media (max-width: 820px) {
    .shell { flex-direction: column; }
    .sidebar { width: auto; height: auto; position: static; border-right: 0; border-bottom: 1px solid var(--border); display: flex; flex-direction: row; align-items: center; gap: .25rem; overflow-x: auto; padding: .5rem .6rem; }
    .sidebar__brand { padding: .35rem .6rem; border-right: 1px solid var(--border); margin-right: .3rem; white-space: nowrap; }
    .nav-sec { display: none; }
    .nav-link { white-space: nowrap; padding: .45rem .6rem; }
    /* En barre horizontale, le pied se colle à droite et perd sa séparation. */
    .sidebar__foot { margin: 0 0 0 auto; padding-top: 0; border-top: 0; display: flex; align-items: center; gap: .25rem; }
    .sidebar__user { display: none; }
    .sidebar__version { display: none; }
}

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }

/* ---- Cartes / panneaux ---- */
.card, .panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r);
    box-shadow: var(--sh-sm);
}
.card { padding: 1.25rem 1.4rem; }
.panel { padding: 1.1rem 1.3rem; }
.card + .card, .panel + .panel { margin-top: 1rem; }

/* ---- KPI ---- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: 1.05rem 1.2rem; box-shadow: var(--sh-sm); }
.stat__n { font-size: 1.85rem; font-weight: 700; color: var(--brand-ink); font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat__l { color: var(--text-muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; margin-top: .2rem; }

/* ---- Boutons ---- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
    padding: .6rem 1.15rem; min-height: 42px;
    border: 1px solid transparent; border-radius: var(--r-sm);
    font: inherit; font-weight: 600; font-size: .95rem; cursor: pointer;
    transition: background-color .18s ease, box-shadow .18s ease, border-color .18s ease, transform .05s ease;
    text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn--primary { background: var(--brand); color: var(--on-brand); }
.btn--primary:hover:not(:disabled) { background: var(--brand-900); text-decoration: none; }
.btn--secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn--secondary:hover:not(:disabled) { background: var(--border); text-decoration: none; }
.btn--danger { background: var(--danger); color: #fff; }
.btn--danger:hover:not(:disabled) { background: #991b1b; text-decoration: none; }
.btn--block { width: 100%; }
.btn--sm { min-height: 34px; padding: .35rem .75rem; font-size: .85rem; }

/* ---- Formulaires ---- */
.field { margin-bottom: 1rem; }
.field > label, .label { display: block; font-weight: 600; font-size: .82rem; margin-bottom: .35rem; color: var(--text); }
.hint { color: var(--text-soft); font-size: .82rem; margin-top: .25rem; }
.req { color: var(--danger); }
/* ⚠️ `input:not([type])` n'est pas une précaution théorique : un `<input name="x">`
   sans attribut `type` se comporte comme du texte pour le navigateur, mais le
   sélecteur d'attribut `[type=text]` ne le retient pas — l'attribut est absent du
   DOM. Les six champs texte de la recherche multicritère s'affichaient ainsi nus
   au milieu de listes déroulantes stylées, et rien dans le gabarit ne le
   laissait deviner. */
input:not([type]),
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=time], input[type=datetime-local], input[type=tel], input[type=search], select, textarea {
    width: 100%; padding: .6rem .7rem;
    background: var(--surface); color: var(--text);
    border: 1px solid var(--border); border-radius: var(--r-sm);
    font: inherit; font-size: 1rem;
    transition: border-color .15s ease, box-shadow .15s ease;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
input::placeholder, textarea::placeholder { color: var(--text-soft); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: .5rem 1rem; }
.actions { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin-top: 1.1rem; }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--sh-sm); }
table.data { width: 100%; border-collapse: collapse; background: var(--surface); }
table.data th, table.data td { padding: .6rem .85rem; text-align: left; border-bottom: 1px solid var(--border); font-size: .9rem; }
table.data thead th { background: var(--surface-2); font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); font-weight: 600; }
table.data tbody tr { transition: background-color .12s ease; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---- Badges / pills ---- */
.badge { display: inline-flex; align-items: center; padding: .12rem .55rem; border-radius: var(--r-full); font-size: .76rem; font-weight: 600; }
.badge--neutral { background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); }
.badge--success { background: var(--success-bg); color: var(--success-fg); }
.badge--warning { background: var(--warning-bg); color: var(--warning-fg); }
.badge--danger { background: var(--danger-bg); color: var(--danger-fg); }

/* ---- Alertes ---- */
.alert { padding: .75rem 1rem; border-radius: var(--r-sm); font-size: .9rem; border: 1px solid transparent; }
.alert + .alert { margin-top: .5rem; }
.alert--success { background: var(--success-bg); color: var(--success-fg); border-color: var(--success-bd); }
.alert--warning { background: var(--warning-bg); color: var(--warning-fg); border-color: var(--warning-bd); }
.alert--danger { background: var(--danger-bg); color: var(--danger-fg); border-color: var(--danger-bd); }

/* Pastille de présence (§3). Le point seul ne dit rien à un lecteur d'écran ni
   à qui distingue mal le vert : il est toujours accompagné d'un mot. */
.presence { display: inline-block; width: .6rem; height: .6rem; border-radius: 50%; margin-right: .35rem; vertical-align: baseline; }
.presence--online { background: var(--success-fg, #1a7f37); box-shadow: 0 0 0 .18rem var(--success-bg, #d7f5de); }
.alert ul { margin: .3rem 0 0; padding-left: 1.1rem; }

/* ---- Barres (stats) ---- */
.bar-row { display: flex; align-items: center; gap: .7rem; margin: .4rem 0; font-size: .88rem; }
.bar-row .bar-lbl { width: 180px; color: var(--text-muted); flex-shrink: 0; }
.bar-track { flex: 1; height: 16px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-full); overflow: hidden; }
.bar-track > span { display: block; height: 100%; background: var(--brand); border-radius: var(--r-full); }
.bar-row .bar-val { width: 60px; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.split { display: flex; height: 28px; border-radius: var(--r-sm); overflow: hidden; font-size: .8rem; color: #fff; font-weight: 600; }
.split .a { background: var(--brand); }
.split .b { background: var(--accent); }
.split .a, .split .b { display: flex; align-items: center; justify-content: center; min-width: 2.5rem; }

/* ---- Icônes inline ---- */
.icon { width: 1.05em; height: 1.05em; vertical-align: -0.15em; flex-shrink: 0; }

/* ---- Indicateurs à tonalité : un liseré, jamais la couleur seule (le libellé dit le sens) ---- */
.stat--danger { border-left: 4px solid var(--danger); }
.stat--warning { border-left: 4px solid var(--warning-fg); }
.stat--neutral { border-left: 4px solid var(--border); }
.stat__hint { color: var(--text-soft); font-size: .78rem; margin-top: .15rem; }

/* Lu par les lecteurs d'écran, invisible à l'œil (en-tête d'une colonne d'action, par exemple). */
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---- Section titrée ---- */
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: .5rem 1rem; flex-wrap: wrap; margin: 2rem 0 .8rem; }
.section-head h2 { margin: 0; }
.section-head p { margin: 0; }

/* ---- Puces (critères, références) ---- */
.chip { display: inline-flex; align-items: center; gap: .3rem; padding: .1rem .5rem; border-radius: var(--r-full); background: var(--surface-2); border: 1px solid var(--border); color: var(--text-muted); font-size: .74rem; font-weight: 500; white-space: nowrap; }
.chip-list { display: flex; flex-wrap: wrap; gap: .3rem; }

/* ---- Jauge de score : décorative, le nombre reste écrit à côté ---- */
.meter { display: inline-flex; align-items: center; gap: .5rem; font-variant-numeric: tabular-nums; font-weight: 600; }
.meter__track { width: 56px; height: 6px; border-radius: var(--r-full); background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
.meter__fill { display: block; height: 100%; background: var(--warning-fg); }
.meter--danger .meter__fill { background: var(--danger); }

/* ---- État vide : dire ce qui se passe et ce qui viendra ---- */
.empty-state { display: flex; gap: .9rem; align-items: flex-start; padding: 1.25rem 1.4rem; }
.empty-state .icon { width: 28px; height: 28px; color: var(--brand-700); margin-top: .1rem; }
.empty-state strong { display: block; color: var(--text); }
.empty-state p { margin: .2rem 0 0; color: var(--text-muted); }

/* ---- Pagination : les quatre boutons gardent leur place, désactivés aux bornes ---- */
.pager { display: flex; justify-content: space-between; align-items: center; gap: .75rem 1rem; flex-wrap: wrap; margin-top: .9rem; }
.pager__links { display: flex; gap: .5rem; flex-wrap: wrap; }
.pager__links .btn { min-height: 44px; min-width: 44px; }
.pager__links .btn[aria-disabled=true] { opacity: .45; pointer-events: none; }
.pager__current { min-height: 44px; display: inline-flex; align-items: center; padding: 0 .8rem; border-radius: var(--r-sm); background: var(--nav-active-bg); color: var(--brand-700); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---- Tableau empilé en cartes sur téléphone (pas de défilement horizontal) ---- */
@media (max-width: 640px) {
    table.data--stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
    table.data--stack, table.data--stack tbody, table.data--stack tr, table.data--stack td { display: block; width: 100%; }
    table.data--stack tr { padding: .6rem .3rem; border-bottom: 1px solid var(--border); }
    table.data--stack tbody tr:last-child { border-bottom: 0; }
    table.data--stack td { border: 0; padding: .3rem .6rem; text-align: left; }
    table.data--stack td.num { text-align: left; }
    table.data--stack td[data-label]::before { content: attr(data-label); display: block; font-size: .7rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); font-weight: 600; }
    table.data--stack td.actions-cell .btn { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}

@media (max-width: 640px) {
    .bar-row .bar-lbl { width: 120px; }
    .app-bar__title { display: none; }
}

/* ---- Menu « … » d'une ligne de tableau ---- */
.row-menu { position: relative; display: inline-block; }
.row-menu > summary { list-style: none; cursor: pointer; }
.row-menu > summary::-webkit-details-marker { display: none; }
.row-menu__list { position: absolute; right: 0; top: calc(100% + .3rem); z-index: 50; min-width: 15rem; margin: 0; padding: .35rem 0; list-style: none; text-align: left;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: 0 8px 24px rgba(15,23,42,.14); }
.row-menu__list a { display: flex; align-items: center; gap: .6rem; padding: .5rem .9rem; color: var(--text); text-decoration: none; font-size: .9rem; white-space: nowrap; }
.row-menu__list a:hover, .row-menu__list a:focus-visible { background: var(--surface-2); color: var(--brand); outline: none; }
.row-menu__list .icon { color: var(--text-muted); }
