/* ===========================================================================
   Optimisation de planning — design system
   Principe : chrome neutre (monochrome), la couleur est reservee aux DONNEES.
   - Teinte  = service (Accueil, Secretariat, Comptabilite, Direction)
   - Forme + libelle = etat (deplace, manuel, retire, absence, non couvert)
   Aucune couleur de service n'est reutilisee pour un etat.
   =========================================================================== */

/*
 * Themes : les tokens de COULEUR sont dans ce bloc (redefinis par [data-theme]).
 * Tout le reste du fichier consomme ces tokens (var() / color-mix()) et n'a
 * donc pas besoin d'etre duplique entre les deux themes.
 *
 * --state-edit / --ink derivent de --text / --bg : le bouton primaire et la
 * bulle "moi" du chat sont donc toujours une inversion exacte du theme actif.
 */
:root {
    color-scheme: dark;

    /* Chrome neutre */
    --bg: #0a0d15;
    --panel: #10141f;
    --panel-2: #171c2b;
    --field: #0c101a;
    --line: rgba(148, 163, 184, .14);
    --line-strong: rgba(148, 163, 184, .28);
    --text: #e8ecf5;
    --muted: #8b94a9;
    --state-edit: var(--text);    /* deplace & manuel : anneau + libelle ; fond du bouton primaire */
    --ink: var(--bg);             /* texte sur bouton primaire / bulle "moi" du chat */

    /* Couleurs de service (uniquement pour les creneaux + legende) — identiques dans les deux themes */
    --sk-accueil: #4da3ff;
    --sk-secretariat: #b78aff;
    --sk-comptabilite: #35d49b;
    --sk-direction: #f2c14e;

    /* Couleurs d'etat (jamais partagees avec un service) */
    --state-removed: #ff6b81;     /* retire / absence / non couvert */

    /* Feedback score */
    --ok: #3ddfa9;
    --warn: #ffd166;
    --bad: #ff6b81;

    /* Surfaces derivees (translucides, recessed) */
    --surface-translucent: rgba(16, 20, 31, .85);
    --dock-bg: rgba(16, 20, 31, .96);
    --surface-recessed: rgba(5, 7, 12, .45);
    --surface-recessed-strong: #12151f;
    --fieldset-bg: rgba(23, 28, 43, .5);
    --overlay-scrim: rgba(5, 7, 12, .65);
    --glow-1: rgba(77, 163, 255, .07);
    --glow-2: rgba(183, 138, 255, .05);

    --radius: 10px;
    --radius-lg: 14px;
    --font-display: "Bricolage Grotesque", "Segoe UI", sans-serif;
    --font-body: "Instrument Sans", "Segoe UI", system-ui, sans-serif;
    --font-mono: "Spline Sans Mono", "Cascadia Mono", monospace;
}

:root[data-theme="light"] {
    color-scheme: light;

    --bg: #f3f4f9;
    --panel: #ffffff;
    --panel-2: #eef0f6;
    --field: #ffffff;
    --line: rgba(15, 23, 42, .1);
    --line-strong: rgba(15, 23, 42, .2);
    --text: #14161f;
    --muted: #656c7e;

    --state-removed: #cc2955;

    --ok: #0e9468;
    --warn: #a3690a;
    --bad: #cc2955;

    --surface-translucent: rgba(255, 255, 255, .82);
    --dock-bg: rgba(255, 255, 255, .96);
    --surface-recessed: rgba(15, 23, 42, .04);
    --surface-recessed-strong: #eceef4;
    --fieldset-bg: rgba(15, 23, 42, .025);
    --overlay-scrim: rgba(15, 23, 42, .4);
    --glow-1: rgba(77, 163, 255, .06);
    --glow-2: rgba(183, 138, 255, .05);
}

* { box-sizing: border-box; }

/* L'attribut hidden doit primer sur les regles display (flex, etc.). */
[hidden] { display: none !important; }

body {
    margin: 0;
    font-family: var(--font-body);
    background:
        radial-gradient(1100px 520px at 88% -12%, var(--glow-1), transparent 60%),
        radial-gradient(900px 480px at -8% 112%, var(--glow-2), transparent 60%),
        var(--bg);
    background-attachment: fixed;
    color: var(--text);
    min-height: 100vh;
    font-size: 14px;
    line-height: 1.45;
    transition: background-color .2s, color .2s;
}

::selection { background: color-mix(in srgb, var(--state-edit) 22%, transparent); }

/* ---------------------------------------------------------------------------
   En-tete
--------------------------------------------------------------------------- */

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 24px;
    background: var(--surface-translucent);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
    flex-wrap: wrap;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 30;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 {
    font-family: var(--font-display);
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -.01em;
    margin: 0;
}
.brand .subtitle { color: var(--muted); font-size: 12px; }

/* Pastille de marque : les 4 services en un glyphe. */
.brand .dot {
    width: 16px;
    height: 16px;
    border-radius: 5px;
    background: conic-gradient(
        var(--sk-accueil) 0 25%,
        var(--sk-secretariat) 25% 50%,
        var(--sk-comptabilite) 50% 75%,
        var(--sk-direction) 75% 100%);
    box-shadow: 0 0 16px rgba(77, 163, 255, .35);
}

.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------------------------------------------------------------------------
   Boutons — hierarchie monochrome : primaire blanc, le reste s'efface.
--------------------------------------------------------------------------- */

.btn {
    border: 1px solid var(--line-strong);
    background: transparent;
    color: var(--text);
    padding: 8px 14px;
    border-radius: var(--radius);
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, border-color .15s, opacity .15s, transform .1s;
}
.btn:hover:not(:disabled) {
    background: color-mix(in srgb, var(--text) 8%, transparent);
    border-color: color-mix(in srgb, var(--text) 40%, transparent);
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .35; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid color-mix(in srgb, var(--text) 60%, transparent); outline-offset: 2px; }

.btn.primary {
    background: var(--state-edit);
    color: var(--ink);
    border-color: transparent;
}
.btn.primary:hover:not(:disabled) { opacity: .85; background: var(--state-edit); border-color: transparent; }

.btn.danger {
    background: transparent;
    color: var(--bad);
    border-color: color-mix(in srgb, var(--state-removed) 45%, transparent);
}
.btn.danger:hover:not(:disabled) {
    background: color-mix(in srgb, var(--state-removed) 12%, transparent);
    border-color: var(--bad);
}

.btn.ghost { border-color: transparent; color: var(--muted); }
.btn.ghost:hover:not(:disabled) {
    color: var(--text);
    background: color-mix(in srgb, var(--text) 7%, transparent);
    border-color: transparent;
}

/* Bascule theme clair/sombre : icone soleil/lune animee, pilotee en CSS pur
   via l'attribut [data-theme] sur <html> (l'etat AFFICHE est le theme ACTUEL). */
.theme-toggle {
    position: relative;
    width: 34px;
    height: 34px;
    padding: 0;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
}
.theme-toggle svg {
    position: absolute;
    transition: opacity .25s ease, transform .35s cubic-bezier(.34, 1.56, .64, 1);
}
.theme-toggle .icon-sun { opacity: 0; transform: rotate(90deg) scale(.5); }
.theme-toggle .icon-moon { opacity: 1; transform: rotate(0deg) scale(1); }
[data-theme="light"] .theme-toggle .icon-sun { opacity: 1; transform: rotate(0deg) scale(1); }
[data-theme="light"] .theme-toggle .icon-moon { opacity: 0; transform: rotate(-90deg) scale(.5); }

/* ---------------------------------------------------------------------------
   Panneaux depliables (import, regles, replanification)
--------------------------------------------------------------------------- */

.import-panel {
    padding: 16px 24px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.import-panel > strong { font-family: var(--font-display); font-size: 14px; letter-spacing: .01em; }
.import-panel label { font-size: 13px; color: var(--muted); }
.import-panel textarea {
    width: 100%;
    background: var(--field);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 10px 12px;
    font-family: var(--font-body);
    font-size: 13px;
    resize: vertical;
    transition: border-color .15s;
}
.import-panel textarea:focus { outline: none; border-color: color-mix(in srgb, var(--state-edit) 45%, transparent); }
.import-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.import-status { font-size: 13px; color: var(--muted); }

.rules-panel {
    padding: 16px 24px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 14px;
}
.rules-panel fieldset {
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--fieldset-bg);
    padding: 12px 16px;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.rules-panel legend {
    padding: 2px 10px;
    font-family: var(--font-display);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--text);
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 999px;
}
.rules-panel label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    flex-wrap: wrap;
    color: var(--text);
}
.rules-panel input[type="number"] {
    width: 72px;
    background: var(--field);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 4px 6px;
    font-family: var(--font-mono);
    font-size: 12px;
}
.rules-panel input[type="number"]:focus { outline: none; border-color: color-mix(in srgb, var(--state-edit) 45%, transparent); }
.rules-panel input[type="checkbox"] { accent-color: var(--state-edit); }
.rules-note { font-size: 12px; color: var(--muted); }

/* ---------------------------------------------------------------------------
   Barre de statut — tuiles de chiffres
--------------------------------------------------------------------------- */

.status-bar {
    display: flex;
    /* Ecart vertical resserre : le detail du score s'ouvre sur une ligne a lui. */
    column-gap: 36px;
    row-gap: 14px;
    align-items: center;
    padding: 14px 24px;
    background: transparent;
    border-bottom: 1px solid var(--line);
    flex-wrap: wrap;
}
.status-item { display: flex; flex-direction: column; gap: 2px; }
.status-item .label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--muted);
}
.status-item .value {
    font-family: var(--font-display);
    font-size: 19px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: -.01em;
}

/*
 * Score : le verdict est un bouton (accessible au clavier et annonce comme depliant)
 * qui garde l'allure d'une valeur de la barre de statut.
 */
.score-verdict {
    background: none;
    border: 0;
    padding: 0;
    margin: 0;
    color: inherit;
    text-align: left;
    cursor: pointer;
}
.score-verdict:hover { text-decoration: underline dotted; }
.score-verdict:focus-visible {
    outline: 2px solid var(--line-strong);
    outline-offset: 3px;
    border-radius: 4px;
}
.score-gain {
    font-size: 11px;
    color: var(--muted);
}

.score-detail {
    flex-basis: 100%;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface-recessed);
    font-size: 12.5px;
}
.score-technical {
    margin: 0 0 8px;
    color: var(--muted);
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
}
.score-detail-title {
    margin: 0 0 6px;
    font-weight: 600;
}
.score-detail-empty {
    margin: 0;
    color: var(--muted);
}
.score-items {
    margin: 0;
    padding: 0;
    list-style: none;
}
.score-items li {
    display: flex;
    align-items: baseline;
    gap: 10px;
    padding: 4px 0;
    border-bottom: 1px dashed var(--line);
}
.score-items li:last-child { border-bottom: 0; }
.score-item-label { flex: 1; }
.score-item-count {
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.spinner {
    width: 18px;
    height: 18px;
    border: 2.5px solid var(--line-strong);
    border-top-color: var(--text);
    border-radius: 50%;
    animation: spin .7s linear infinite;
    margin-left: auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------------------
   Zone principale + legende
--------------------------------------------------------------------------- */

main { padding: 18px 24px 32px; }

.empty {
    text-align: center;
    color: var(--muted);
    padding: 90px 20px;
    border: 1px dashed var(--line-strong);
    border-radius: var(--radius-lg);
    font-size: 14px;
}

/* Legende au-dessus de la grille : services (couleur) puis etats (forme). */
.legend-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    padding: 0 2px 12px;
}
.legend { display: inline-flex; gap: 14px 18px; flex-wrap: wrap; align-items: center; }
.legend .lg {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--muted);
}
.legend .lg::before {
    content: "";
    width: 10px;
    height: 10px;
    border-radius: 3px;
}
.legend .lg-Accueil::before { background: var(--sk-accueil); }
.legend .lg-Secretariat::before { background: var(--sk-secretariat); }
.legend .lg-Comptabilite::before { background: var(--sk-comptabilite); }
.legend .lg-Direction::before { background: var(--sk-direction); }

.legend .legend-sep {
    width: 1px;
    height: 16px;
    background: var(--line-strong);
}

/* Echantillons d'etats : memes codes visuels que sur les cartes. */
.legend .lg-state {
    display: inline-flex;
    align-items: center;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    padding: 2px 8px;
    border-radius: 999px;
}
.legend .lg-state::before { display: none; }
.legend .lg-moved {
    color: var(--state-edit);
    border: 1px solid color-mix(in srgb, var(--state-edit) 55%, transparent);
    background: color-mix(in srgb, var(--state-edit) 8%, transparent);
}
.legend .lg-manual { color: var(--state-edit); border: 1px dashed color-mix(in srgb, var(--state-edit) 55%, transparent); }
.legend .lg-removed {
    color: var(--state-removed);
    border: 1px dashed color-mix(in srgb, var(--state-removed) 55%, transparent);
    text-decoration: line-through;
}
.legend .lg-absence {
    color: var(--state-removed);
    border: 1px solid color-mix(in srgb, var(--state-removed) 40%, transparent);
    background: color-mix(in srgb, var(--state-removed) 10%, transparent);
}

/* ---------------------------------------------------------------------------
   Grille de planning
--------------------------------------------------------------------------- */

#board-wrap {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--panel);
}

table {
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
    min-width: 1000px;
}
th, td {
    border-bottom: 1px solid var(--line);
    border-right: 1px solid var(--line);
    padding: 6px;
    vertical-align: top;
    text-align: left;
}
th:last-child, td:last-child { border-right: none; }
tbody tr:last-child th, tbody tr:last-child td { border-bottom: none; }

thead th {
    background: var(--panel-2);
    position: sticky;
    top: 0;
    z-index: 3;
    font-family: var(--font-display);
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: .03em;
    text-transform: capitalize;
    color: var(--muted);
    white-space: nowrap;
    padding: 9px 10px;
}

/* Colonne agents figee au defilement horizontal. */
tbody th {
    background: var(--panel);
    position: sticky;
    left: 0;
    z-index: 2;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    width: 132px;
    min-width: 132px;
    padding: 8px 12px;
    box-shadow: 1px 0 0 var(--line);
}
thead th:first-child {
    position: sticky;
    left: 0;
    z-index: 4;
    background: var(--panel-2);
}

td { height: 46px; min-width: 128px; }

tbody tr:hover td { background: color-mix(in srgb, var(--text) 2.5%, transparent); }

.emp-sub {
    font-size: 11px;
    font-weight: 400;
    color: var(--muted);
    margin-top: 2px;
    font-variant-numeric: tabular-nums;
}

tbody th.clickable { cursor: pointer; border-radius: 6px; transition: box-shadow .15s; }
tbody th.clickable:hover { box-shadow: inset 0 0 0 999px color-mix(in srgb, var(--text) 6%, transparent); }
tbody th.clickable:hover div:first-child { text-decoration: underline; text-underline-offset: 3px; }

/* Week-ends et feries : colonnes assombries, marqueur discret en en-tete. */
th.weekend, td.weekend { background: var(--surface-recessed); }
thead th.weekend { background: var(--surface-recessed-strong); color: var(--muted); }
th.holiday, td.holiday { background: var(--surface-recessed); }
thead th.holiday { background: var(--surface-recessed-strong); }
thead th.holiday::after {
    content: "férié";
    display: inline-block;
    margin-left: 6px;
    font-size: 9px;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--muted);
    border: 1px solid var(--line-strong);
    border-radius: 999px;
    padding: 0 5px;
}

/* ---------------------------------------------------------------------------
   Cartes de creneau — la teinte vient du service, l'etat vient des badges.
--------------------------------------------------------------------------- */

.shift {
    --sk: #64748b;
    position: relative;
    border-radius: 8px;
    padding: 5px 8px 6px;
    margin-bottom: 5px;
    font-size: 12px;
    line-height: 1.35;
    background: color-mix(in srgb, var(--sk) 13%, var(--panel-2));
    border-left: 3px solid var(--sk);
    cursor: grab;
    transition: transform .12s, box-shadow .12s, filter .12s;
}
.shift:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(0, 0, 0, .4);
    filter: brightness(1.08);
}
.shift .time {
    font-family: var(--font-mono);
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: -.01em;
}
.shift .loc { color: var(--muted); font-size: 11px; }

.shift.skill-Accueil { --sk: var(--sk-accueil); }
.shift.skill-Secretariat { --sk: var(--sk-secretariat); }
.shift.skill-Comptabilite { --sk: var(--sk-comptabilite); }
.shift.skill-Direction { --sk: var(--sk-direction); }

/* Badge d'etat pose sur une carte : libelle texte, jamais une simple couleur. */
.shift .state-chip {
    display: inline-block;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: .07em;
    text-transform: uppercase;
    padding: 1px 6px;
    margin-bottom: 3px;
    border-radius: 999px;
    color: var(--state-edit);
    background: color-mix(in srgb, var(--state-edit) 10%, transparent);
    border: 1px solid color-mix(in srgb, var(--state-edit) 50%, transparent);
}

/* Creneau deplace / recu lors de la derniere replanification : anneau argent. */
.shift.changed {
    box-shadow:
        0 0 0 1.5px color-mix(in srgb, var(--state-edit) 75%, transparent),
        0 0 14px color-mix(in srgb, var(--state-edit) 12%, transparent);
    animation: settle .5s ease-out;
}
@keyframes settle {
    from {
        box-shadow:
            0 0 0 4px color-mix(in srgb, var(--state-edit) 0%, transparent),
            0 0 22px color-mix(in srgb, var(--state-edit) 30%, transparent);
    }
}

/* Creneau touche a la main (avant recalcul) : anneau argent pointille. */
.shift.manual {
    box-shadow: none;
    outline: 1.5px dashed color-mix(in srgb, var(--state-edit) 65%, transparent);
    outline-offset: 1px;
}
.shift.manual .state-chip { border-style: dashed; }

.shift.dragging { opacity: .35; cursor: grabbing; }

/* Creneau retire : carte fantome barree chez l'ancien titulaire. */
.shift.ghost {
    background: color-mix(in srgb, var(--state-removed) 5%, transparent);
    border: 1px dashed color-mix(in srgb, var(--state-removed) 50%, transparent);
    border-left: 3px dashed var(--state-removed);
    cursor: default;
}
.shift.ghost:hover { transform: none; box-shadow: none; filter: none; }
.shift.ghost .time { text-decoration: line-through; color: var(--muted); }
.shift.ghost .loc { color: var(--muted); }
.shift.ghost .state-chip {
    color: var(--state-removed);
    background: color-mix(in srgb, var(--state-removed) 10%, transparent);
    border-color: color-mix(in srgb, var(--state-removed) 50%, transparent);
}

/* Creneaux non couverts (ligne "Non affectes"). */
.unassigned th { color: var(--state-removed); }
.unassigned .shift {
    --sk: var(--state-removed);
    background: color-mix(in srgb, var(--state-removed) 7%, transparent);
    border-left-style: dashed;
}

/* Badge d'absence dans une cellule. */
.abs-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: .05em;
    padding: 2px 7px;
    margin-bottom: 4px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--state-removed) 10%, transparent);
    color: var(--state-removed);
    border: 1px solid color-mix(in srgb, var(--state-removed) 40%, transparent);
}
.abs-badge.clickable-badge { cursor: pointer; transition: background .15s; }
.abs-badge.clickable-badge:hover { background: color-mix(in srgb, var(--state-removed) 22%, transparent); }

/* Cellule receptrice pendant un glisser-deposer. */
td.drop-target {
    background: color-mix(in srgb, var(--state-edit) 7%, transparent) !important;
    box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--state-edit) 65%, transparent);
}

/* ---------------------------------------------------------------------------
   Barre "Modifications manuelles"
--------------------------------------------------------------------------- */

.manual-panel {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    padding: 12px 24px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    border-left: 3px solid var(--state-edit);
}
.manual-panel strong { color: var(--text); font-size: 13px; font-family: var(--font-display); }
.manual-objective { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.manual-objective select {
    background: var(--field);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 5px 6px;
    font-family: var(--font-body);
    font-size: 13px;
}

/* ---------------------------------------------------------------------------
   Encart d'impact de la replanification
--------------------------------------------------------------------------- */

.diff-panel {
    padding: 14px 24px 16px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
}
.diff-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.diff-head strong { font-family: var(--font-display); font-size: 14px; }
.diff-head .btn { margin-left: auto; }
.diff-employees { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.diff-emp {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 8px 14px;
    background: var(--panel-2);
    font-size: 12px;
    min-width: 170px;
}
.diff-emp .diff-name { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.diff-emp .diff-added, .diff-emp .diff-removed {
    display: flex;
    align-items: center;
    gap: 6px;
    font-variant-numeric: tabular-nums;
}
.diff-emp .diff-added::before, .diff-emp .diff-removed::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
}
.diff-emp .diff-added { color: var(--ok); }
.diff-emp .diff-added::before { background: var(--ok); }
.diff-emp .diff-removed { color: var(--state-removed); }
.diff-emp .diff-removed::before { background: var(--state-removed); }

/* ---------------------------------------------------------------------------
   Formulaire de replanification
--------------------------------------------------------------------------- */

.replan-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 10px;
}
.replan-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.replan-grid input, .replan-grid select {
    background: var(--field);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 7px 8px;
    font-size: 13px;
    font-family: var(--font-body);
}
.replan-grid input:focus, .replan-grid select:focus { outline: none; border-color: color-mix(in srgb, var(--state-edit) 45%, transparent); }
#preset-select {
    background: var(--field);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 4px 6px;
    font-size: 13px;
    font-family: var(--font-body);
}

/* Tableau compact de l'effectif minimum dans le panneau Regles. */
.mini-table { border-collapse: collapse; width: 100%; min-width: 0; }
.mini-table th, .mini-table td {
    border: 1px solid var(--line);
    padding: 4px 6px;
    font-size: 12px;
    text-align: left;
    height: auto;
    min-width: 0;
    position: static;
    background: transparent;
    box-shadow: none;
    width: auto;
}
.mini-table thead th { text-transform: none; font-family: var(--font-body); color: var(--muted); }
.mini-table input[type="number"] { width: 56px; }

/* ---------------------------------------------------------------------------
   Menu contextuel flottant
--------------------------------------------------------------------------- */

.ctx-menu {
    position: fixed;
    z-index: 60;
    min-width: 240px;
    background: var(--dock-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    box-shadow: 0 16px 48px rgba(0, 0, 0, .6);
    padding: 6px;
    display: flex;
    flex-direction: column;
    animation: menuIn .12s ease-out;
}
@keyframes menuIn {
    from { opacity: 0; transform: translateY(4px) scale(.98); }
}
.ctx-menu .ctx-title {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--muted);
    padding: 6px 10px;
    border-bottom: 1px solid var(--line);
    margin-bottom: 4px;
}
.ctx-menu .ctx-item {
    text-align: left;
    background: transparent;
    color: var(--text);
    border: none;
    border-radius: 6px;
    padding: 8px 10px;
    font-size: 13px;
    font-family: var(--font-body);
    cursor: pointer;
}
.ctx-menu .ctx-item:hover:not(:disabled) { background: color-mix(in srgb, var(--text) 8%, transparent); }
.ctx-menu .ctx-item:disabled { color: var(--muted); cursor: default; }
.ctx-menu .ctx-item.danger { color: var(--bad); }
.ctx-menu .ctx-item.danger:hover:not(:disabled) { background: color-mix(in srgb, var(--state-removed) 12%, transparent); }

/* ---------------------------------------------------------------------------
   Modale generique (listes plannings / presets)
--------------------------------------------------------------------------- */

.overlay {
    position: fixed;
    inset: 0;
    background: var(--overlay-scrim);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
}
.overlay-card {
    background: var(--panel);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-lg);
    width: min(560px, 92vw);
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 24px 80px rgba(0, 0, 0, .5);
    animation: menuIn .15s ease-out;
}
.overlay-head {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
}
.overlay-head strong { font-family: var(--font-display); font-size: 15px; }
.overlay-head .btn { margin-left: auto; }
.overlay-list { padding: 8px 16px 16px; overflow-y: auto; }
.overlay-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 8px;
    border-bottom: 1px solid var(--line);
}
.overlay-row:last-child { border-bottom: none; }
.overlay-row .row-main { flex: 1; }
.overlay-row .row-main .row-title { font-size: 14px; font-weight: 600; }
.overlay-row .row-main .row-sub { font-size: 12px; color: var(--muted); }
.overlay-empty { color: var(--muted); font-size: 13px; padding: 12px 0; }

/* ---------------------------------------------------------------------------
   Indicateur des traitements longs (solveur, import IA)
--------------------------------------------------------------------------- */

.busy-indicator {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 40;            /* sous la modale generique (50) : une liste ouverte passe devant */
    pointer-events: none;   /* n'intercepte aucun clic : bouton Arreter et grille restent accessibles */
}
/* Import IA : appel unique, rien a observer pendant l'attente — on voile l'interface. */
.busy-indicator.blocking {
    background: var(--overlay-scrim);
    backdrop-filter: blur(4px);
    pointer-events: auto;
}
.busy-card {
    display: flex;
    align-items: center;
    gap: 14px;
    max-width: min(420px, 92vw);
    padding: 16px 20px;
    background: var(--panel);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-lg);
    box-shadow: 0 24px 80px rgba(0, 0, 0, .5);
    animation: menuIn .15s ease-out;
}
/* .spinner porte `margin-left: auto` pour la barre de statut : neutralise dans la carte. */
.busy-card .spinner { margin-left: 0; flex: none; }
.busy-text { display: flex; flex-direction: column; gap: 2px; }
.busy-label { font-family: var(--font-display); font-size: 15px; }
.busy-hint { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------------------
   Assistant conversationnel
--------------------------------------------------------------------------- */

.chat-dock {
    position: fixed;
    right: 20px;
    bottom: 20px;
    width: min(400px, 92vw);
    max-height: min(560px, 80vh);
    display: flex;
    flex-direction: column;
    background: var(--dock-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 60px rgba(0, 0, 0, .55);
    z-index: 40;
}
.chat-head {
    display: flex;
    align-items: center;
    padding: 10px 14px;
    border-bottom: 1px solid var(--line);
}
.chat-head strong { font-family: var(--font-display); font-size: 14px; }
.chat-head .btn { margin-left: auto; padding: 5px 10px; font-size: 12px; }
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 160px;
}
.chat-msg {
    max-width: 88%;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.45;
    white-space: pre-wrap;
    overflow-wrap: break-word;
}
.chat-msg.user {
    align-self: flex-end;
    background: var(--state-edit);
    color: var(--ink);
    border-bottom-right-radius: 4px;
}
.chat-msg.bot {
    align-self: flex-start;
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-bottom-left-radius: 4px;
}
.chat-msg.warn { border-color: color-mix(in srgb, var(--warn) 50%, transparent); }
.chat-msg .chat-actions-list { margin: 8px 0 0; padding-left: 18px; }
.chat-msg .chat-actions-list li { margin-bottom: 2px; }
.chat-confirm-row { display: flex; gap: 8px; margin-top: 10px; }
.chat-confirm-row .btn { padding: 6px 12px; font-size: 12px; }
.chat-input-row {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--line);
}
.chat-input-row textarea {
    flex: 1;
    background: var(--field);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px;
    font-family: var(--font-body);
    font-size: 13px;
    resize: none;
}
.chat-input-row textarea:focus { outline: none; border-color: color-mix(in srgb, var(--state-edit) 45%, transparent); }
.chat-typing { color: var(--muted); font-style: italic; }

/* ---------------------------------------------------------------------------
   Page de connexion (demonstrateur en ligne)
--------------------------------------------------------------------------- */

.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.login-card {
    width: min(380px, 92vw);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: 0 24px 80px rgba(0, 0, 0, .35);
    padding: 28px;
    display: flex;
    flex-direction: column;
    gap: 22px;
    animation: menuIn .2s ease-out;
}
.login-card .brand { align-items: flex-start; }
.login-card .brand .dot { margin-top: 3px; }
.login-card h1 { font-family: var(--font-display); font-size: 17px; font-weight: 700; margin: 0; }
.login-card .subtitle { color: var(--muted); font-size: 12px; }

.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-form label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .02em;
    color: var(--muted);
}
.login-form input {
    background: var(--field);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 9px 11px;
    font-family: var(--font-body);
    font-size: 14px;
    transition: border-color .15s;
}
.login-form input:focus { outline: none; border-color: color-mix(in srgb, var(--state-edit) 45%, transparent); }
.login-form .btn { margin-top: 4px; padding: 10px 14px; }

.login-error {
    font-size: 13px;
    color: var(--bad);
    background: color-mix(in srgb, var(--state-removed) 8%, transparent);
    border: 1px solid color-mix(in srgb, var(--state-removed) 35%, transparent);
    border-radius: 8px;
    padding: 8px 10px;
}

/* ---------------------------------------------------------------------------
   Accessibilite
--------------------------------------------------------------------------- */

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

/* ---------------------------------------------------------------------------
   Page d'administration (comptes utilisateurs & cles API)
--------------------------------------------------------------------------- */

.admin-main {
    max-width: 1080px;
    margin: 0 auto;
    padding: 18px 22px 48px;
    display: flex;
    flex-direction: column;
    gap: 22px;
}

.admin-panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 20px 22px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.admin-panel h2 {
    font-family: var(--font-display);
    font-size: 16px;
    font-weight: 700;
    margin: 0;
}

.admin-note {
    color: var(--muted);
    font-size: 12px;
    margin: 4px 0 0;
}
.admin-note code, .admin-table code {
    font-family: var(--font-mono);
    font-size: 11px;
    background: var(--surface-recessed);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 1px 5px;
}

.admin-form {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    flex-wrap: wrap;
}
.admin-form label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .02em;
    color: var(--muted);
    min-width: 180px;
}
.admin-form input, .admin-form select {
    background: var(--field);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 10px;
    font-family: var(--font-body);
    font-size: 13px;
    transition: border-color .15s;
}
.admin-form input:focus, .admin-form select:focus {
    outline: none;
    border-color: color-mix(in srgb, var(--state-edit) 45%, transparent);
}

.admin-table td { vertical-align: middle; }
.admin-table .admin-actions-col { width: 1%; white-space: nowrap; }
.admin-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.admin-actions .btn { padding: 4px 10px; font-size: 12px; }
.admin-row-disabled td:not(.admin-actions) { opacity: .55; }
.admin-empty { color: var(--muted); font-style: italic; }

.admin-badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .03em;
    border-radius: 999px;
    padding: 1px 8px;
    border: 1px solid var(--line-strong);
    color: var(--muted);
}
.admin-badge.on {
    color: var(--ok);
    border-color: color-mix(in srgb, var(--ok) 45%, transparent);
}
.admin-badge.off {
    color: var(--bad);
    border-color: color-mix(in srgb, var(--state-removed) 45%, transparent);
}

.key-reveal {
    border: 1px solid color-mix(in srgb, var(--ok) 40%, transparent);
    background: color-mix(in srgb, var(--ok) 7%, transparent);
    border-radius: var(--radius);
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.key-reveal-title { font-size: 12px; font-weight: 600; }
.key-reveal-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.key-reveal-row code {
    font-family: var(--font-mono);
    font-size: 13px;
    background: var(--surface-recessed);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 6px 10px;
    user-select: all;
    word-break: break-all;
}

a.admin-back { text-decoration: none; display: inline-flex; align-items: center; }
