/* =====================================================================
   THIER UNIVERS — OUTILS DU PILIER PILOTAGE (v1.4)
   Feuille commune à tous les outils du pilier Pilotage.
   v1.2 : onglets en pastilles sur petit écran (tous visibles) ;
   les éléments d'un panneau ne débordent plus de la page.
   v1.3 : liens lisibles, à la couleur d'accent, dans les deux thèmes.
   v1.4 : sur téléphone, les tableaux défilent dans leur cadre et les blocs de
   formulaire rétrécissent : la page garde la largeur de l'écran.
   Même charte que le simulateur de bulletin de paie.
   ===================================================================== */

:root,
[data-theme="dark"] {
    --fond: #0c1a27;
    --surface: #12263a;
    --surface-2: #183049;
    --trait: #26435d;
    --texte: #e7eef5;
    --texte-doux: #93a9bd;
    --balise: #2ec4b6;
    --balise-fonce: #179a8e;
    --sur-balise: #04221f;
    --fanal: #f4b942;
    --alerte: #ff7b72;
    --ombre: 0 18px 40px rgba(0, 0, 0, 0.35);
    --vert: #3fb27f;
    --jaune: #e2c044;
    --orange: #f08c3c;
    --rouge: #e5534b;
    --police-ui: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --police-lecture: 'IBM Plex Serif', Georgia, 'Times New Roman', serif;
}

[data-theme="light"] {
    --fond: #f2f5f8;
    --surface: #ffffff;
    --surface-2: #e7eef4;
    --trait: #cdd8e2;
    --texte: #10212f;
    --texte-doux: #4c6378;
    --balise: #0f8f84;
    --balise-fonce: #0b7168;
    --sur-balise: #ffffff;
    --fanal: #b7791f;
    --alerte: #c53030;
    --ombre: 0 12px 30px rgba(16, 33, 47, 0.10);
    --vert: #2f855a;
    --jaune: #b7950b;
    --orange: #c05621;
    --rouge: #c53030;
}

*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--fond);
    color: var(--texte);
    font-family: var(--police-ui);
    font-size: 16px;
    line-height: 1.55;
}

.evitement {
    position: absolute;
    left: -9999px;
    top: 8px;
    padding: 8px 14px;
    background: var(--balise);
    color: var(--sur-balise);
    border-radius: 6px;
    z-index: 100;
}
.evitement:focus { left: 8px; }

.visuellement-cache {
    position: absolute !important;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0);
    white-space: nowrap; border: 0;
}

:focus-visible { outline: 3px solid var(--fanal); outline-offset: 2px; }

/* ---------- Barre du haut ---------- */
.barre {
    position: sticky;
    top: 0;
    z-index: 20;
    background: color-mix(in srgb, var(--fond) 92%, transparent);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--trait);
}
.barre-interieur {
    max-width: 1240px;
    margin: 0 auto;
    padding: 12px 20px;
    display: flex;
    align-items: center;
    gap: 18px;
}
.barre-retour {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--texte-doux);
    text-decoration: none;
    font-weight: 600;
}
.barre-retour svg { width: 18px; height: 18px; }
.barre-retour:hover { color: var(--texte); }
.barre-nom { font-weight: 700; }

/* ---------- Page ---------- */
.page { max-width: 1240px; margin: 0 auto; padding: 28px 20px 60px; }
.page h1 { font-size: clamp(1.8rem, 3.4vw, 2.6rem); line-height: 1.15; margin: 0 0 10px; }
.chapeau { font-family: var(--police-lecture); font-size: 1.12rem; color: var(--texte-doux); max-width: 760px; margin: 0 0 8px; }
.note-confidentialite { font-size: 0.88rem; color: var(--texte-doux); margin: 0 0 22px; }

/* ---------- Boutons ---------- */
.bouton {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 42px;
    padding: 9px 16px;
    border-radius: 999px;
    border: 1px solid var(--trait);
    background: var(--surface);
    color: var(--texte);
    font: inherit;
    font-weight: 600;
    font-size: 0.93rem;
    cursor: pointer;
    text-decoration: none;
}
.bouton:hover { border-color: var(--texte-doux); }
.bouton.principal { background: var(--balise); border-color: var(--balise); color: var(--sur-balise); }
.bouton.principal:hover { background: var(--balise-fonce); border-color: var(--balise-fonce); }
.bouton.discret { background: transparent; }
.bouton.danger { color: var(--alerte); }
.bouton:disabled { opacity: 0.5; cursor: default; }
.bouton-icone {
    width: 34px; height: 34px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 8px;
    border: 1px solid var(--trait);
    background: transparent;
    color: var(--texte-doux);
    cursor: pointer;
    font: inherit;
}
.bouton-icone:hover { color: var(--alerte); border-color: var(--alerte); }

.outils-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 0 0 22px; }

/* ---------- Fiche du projet ---------- */
.fiche-projet {
    display: grid;
    grid-template-columns: minmax(220px, 2fr) minmax(160px, 1fr) minmax(160px, 1fr);
    gap: 14px;
    margin-bottom: 22px;
}
.champ { display: grid; gap: 6px; }
.champ label, .champ .libelle { font-size: 0.86rem; font-weight: 600; color: var(--texte-doux); }
input[type="text"], input[type="number"], input[type="date"], select, textarea {
    width: 100%;
    min-height: 40px;
    padding: 8px 10px;
    border: 1px solid var(--trait);
    border-radius: 8px;
    background: var(--surface);
    color: var(--texte);
    font: inherit;
    font-size: 0.95rem;
}
input[aria-invalid="true"] { border-color: var(--alerte); }
@media (max-width: 760px) { .fiche-projet { grid-template-columns: 1fr; } }

/* ---------- Onglets ---------- */
.onglets {
    display: flex;
    gap: 6px;
    border-bottom: 1px solid var(--trait);
    margin-bottom: 20px;
    overflow-x: auto;
}
.onglet {
    padding: 11px 18px;
    border: 0;
    border-bottom: 3px solid transparent;
    background: none;
    color: var(--texte-doux);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
}
.onglet[aria-selected="true"] { color: var(--texte); border-bottom-color: var(--balise); }
.onglet:hover { color: var(--texte); }
/* Sur petit écran, les onglets passent à la ligne en pastilles : tous restent visibles. */
@media (max-width: 640px) {
    .onglets { flex-wrap: wrap; overflow-x: visible; gap: 8px; border-bottom: 0; }
    .onglet { flex: 1 1 auto; padding: 9px 14px; border: 1px solid var(--trait); border-radius: 999px; white-space: normal; text-align: center; }
    .onglet[aria-selected="true"] { border-color: var(--balise); background: color-mix(in srgb, var(--balise) 16%, transparent); }
}

.panneau { display: grid; gap: 18px; }
/* Liens du contenu : couleur d'accent lisible dans les deux thèmes (v1.3) */
.page a:not(.bouton), .page a:not(.bouton):visited { color: var(--balise); text-decoration: underline; text-underline-offset: 2px; }
.page a:not(.bouton):hover { color: var(--texte); }
.panneau[hidden] { display: none; }
.panneau > * { min-width: 0; }
.defilement { position: relative; max-width: 100%; }
fieldset { min-width: 0; }
.carte {
    background: var(--surface);
    border: 1px solid var(--trait);
    border-radius: 14px;
    padding: 18px;
}
.carte h2 { margin: 0 0 6px; font-size: 1.15rem; }
.carte .aide { margin: 0 0 14px; color: var(--texte-doux); font-size: 0.92rem; }

/* ---------- Messages ---------- */
.messages { display: grid; gap: 8px; }
.message {
    margin: 0;
    padding: 10px 14px;
    border-radius: 8px;
    border-left: 4px solid var(--fanal);
    background: color-mix(in srgb, var(--fanal) 10%, transparent);
    font-size: 0.92rem;
}
.message.erreur { border-left-color: var(--alerte); background: color-mix(in srgb, var(--alerte) 10%, transparent); }
.message.succes { border-left-color: var(--vert); background: color-mix(in srgb, var(--vert) 10%, transparent); }

/* ---------- Tableaux de saisie ---------- */
.defilement { overflow-x: auto; }
.tableau-saisie { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.tableau-saisie th {
    text-align: left;
    padding: 8px;
    font-size: 0.8rem;
    color: var(--texte-doux);
    border-bottom: 1px solid var(--trait);
    white-space: nowrap;
}
.tableau-saisie td { padding: 6px; border-bottom: 1px solid var(--trait); vertical-align: middle; }
.tableau-saisie td.numero { width: 36px; color: var(--texte-doux); font-weight: 700; text-align: center; }
.tableau-saisie .col-duree { width: 90px; }
.tableau-saisie .col-deps { width: 120px; }
.tableau-saisie .col-avance { width: 90px; }
.tableau-saisie .col-action { width: 44px; }
.tableau-saisie tr.critique td.numero { color: var(--rouge); }
.pastille-critique {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
    background: color-mix(in srgb, var(--rouge) 18%, transparent);
    color: var(--rouge);
}
.marge { color: var(--texte-doux); font-size: 0.85rem; white-space: nowrap; }

/* ---------- Diagramme de Gantt ---------- */
.gantt-resume { display: flex; flex-wrap: wrap; gap: 10px 22px; margin: 0 0 14px; font-size: 0.93rem; }
.gantt-resume strong { color: var(--texte); }
.gantt {
    overflow-x: auto;
    border: 1px solid var(--trait);
    border-radius: 10px;
    background: var(--surface);
}
.gantt-grille {
    display: grid;
    grid-template-columns: minmax(190px, 260px) repeat(var(--colonnes), minmax(30px, 1fr));
    min-width: calc(220px + var(--colonnes) * 30px);
    position: relative;
}
.gantt-entete {
    position: sticky;
    top: 0;
    padding: 8px 4px;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--texte-doux);
    text-align: center;
    border-bottom: 1px solid var(--trait);
    background: var(--surface-2);
}
.gantt-entete.nom { text-align: left; padding-left: 12px; }
.gantt-nom {
    padding: 8px 12px;
    font-size: 0.86rem;
    border-bottom: 1px solid var(--trait);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.gantt-nom.jalon-nom { font-weight: 700; color: var(--fanal); }
.gantt-case {
    border-bottom: 1px solid var(--trait);
    min-height: 38px;
}
.gantt-barre {
    align-self: center;
    height: 22px;
    margin: 0 2px;
    border-radius: 6px;
    background: color-mix(in srgb, var(--balise) 55%, var(--surface-2));
    position: relative;
    overflow: hidden;
    z-index: 1;
}
.gantt-barre.critique { background: color-mix(in srgb, var(--rouge) 60%, var(--surface-2)); }
.gantt-avance { position: absolute; inset: 0 auto 0 0; background: rgba(255, 255, 255, 0.28); }
.gantt-jalon {
    align-self: center;
    justify-self: end;
    width: 16px; height: 16px;
    margin-right: -8px;
    transform: rotate(45deg);
    background: var(--fanal);
    z-index: 2;
}
.gantt-aujourdhui {
    width: 2px;
    background: var(--alerte);
    z-index: 3;
    pointer-events: none;
}
.legende { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 10px; font-size: 0.85rem; color: var(--texte-doux); }
.legende span { display: inline-flex; align-items: center; gap: 6px; }
.legende i { display: inline-block; width: 18px; height: 10px; border-radius: 3px; }

/* ---------- Matrice RACI ---------- */
.raci-roles { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.raci-role { display: inline-flex; align-items: center; gap: 4px; }
.raci-role input { width: 190px; }
.raci select { min-width: 64px; font-weight: 700; text-align: center; }
.raci select[data-valeur="R"] { background: color-mix(in srgb, var(--balise) 22%, var(--surface)); }
.raci select[data-valeur="A"] { background: color-mix(in srgb, var(--fanal) 26%, var(--surface)); }
.raci select[data-valeur="C"] { background: color-mix(in srgb, #7c8cf8 22%, var(--surface)); }
.raci select[data-valeur="I"] { background: var(--surface-2); }
.etat-ligne { font-size: 0.82rem; white-space: nowrap; }
.etat-ligne.ok { color: var(--vert); }
.etat-ligne.ko { color: var(--alerte); }

/* ---------- Risques ---------- */
.zone { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.78rem; font-weight: 700; white-space: nowrap; }
.zone-verte { background: color-mix(in srgb, var(--vert) 22%, transparent); color: var(--vert); }
.zone-jaune { background: color-mix(in srgb, var(--jaune) 24%, transparent); color: var(--jaune); }
.zone-orange { background: color-mix(in srgb, var(--orange) 24%, transparent); color: var(--orange); }
.zone-rouge { background: color-mix(in srgb, var(--rouge) 24%, transparent); color: var(--rouge); }
.matrice {
    display: grid;
    grid-template-columns: 90px repeat(4, minmax(56px, 1fr));
    gap: 4px;
    max-width: 560px;
    font-size: 0.82rem;
}
.matrice-axe { color: var(--texte-doux); font-weight: 600; display: flex; align-items: center; justify-content: center; text-align: center; }
.matrice-case {
    min-height: 56px;
    border-radius: 8px;
    padding: 6px;
    display: flex; flex-wrap: wrap; gap: 4px; align-content: flex-start;
}
.matrice-risque {
    display: inline-block;
    min-width: 26px;
    padding: 1px 6px;
    border-radius: 6px;
    background: var(--surface);
    color: var(--texte);
    font-weight: 700;
    text-align: center;
}

/* ---------- Questionnaires ---------- */
.questions { display: grid; gap: 14px; }
.question {
    background: var(--surface);
    border: 1px solid var(--trait);
    border-radius: 12px;
    padding: 16px 18px;
}
.question.non-repondue { border-color: var(--alerte); }
.question legend, .question .intitule { font-weight: 600; margin-bottom: 10px; padding: 0; }
.question fieldset { border: 0; margin: 0; padding: 0; }
.choix { display: grid; gap: 8px; }
.choix label {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 9px 12px;
    border: 1px solid var(--trait);
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.95rem;
}
.choix input { margin-top: 4px; accent-color: var(--balise); }
.choix label:has(input:checked) { border-color: var(--balise); background: color-mix(in srgb, var(--balise) 10%, transparent); }
.echelle { display: flex; flex-wrap: wrap; gap: 6px; }
.echelle label {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 12px;
    border: 1px solid var(--trait);
    border-radius: 999px;
    cursor: pointer;
    font-size: 0.88rem;
}
.echelle label:has(input:checked) { border-color: var(--balise); background: color-mix(in srgb, var(--balise) 14%, transparent); }
.echelle input { accent-color: var(--balise); }
.progression-questionnaire { font-size: 0.9rem; color: var(--texte-doux); margin: 0; }

.resultat { display: grid; gap: 16px; }
.resultat h2 { margin: 0; }
.barres { display: grid; gap: 10px; }
.barre-score { display: grid; grid-template-columns: 150px 1fr auto; gap: 10px; align-items: center; font-size: 0.92rem; }
.barre-score .jauge { height: 14px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.barre-score .jauge i { display: block; height: 100%; background: var(--balise); border-radius: 999px; }
.barre-score.dominant .jauge i { background: var(--fanal); }
.barre-score strong { text-align: right; white-space: nowrap; }
.portrait { border-left: 4px solid var(--fanal); padding: 12px 16px; border-radius: 8px; background: color-mix(in srgb, var(--fanal) 8%, transparent); }
.portrait h3 { margin: 0 0 6px; }
.portrait p { margin: 4px 0; }
@media (max-width: 560px) { .barre-score { grid-template-columns: 110px 1fr auto; } }

/* ---------- Impression (PDF) ---------- */
#vue-impression { display: none; }
@media print {
    @page { size: A4 landscape; margin: 12mm; }
    body { background: #fff; color: #111; font-size: 11px; }
    .barre, .page > *:not(#vue-impression) { display: none !important; }
    #vue-impression { display: block; }
    #vue-impression h1 { font-size: 18px; margin: 0 0 4px; }
    #vue-impression h2 { font-size: 14px; margin: 14px 0 6px; page-break-after: avoid; }
    #vue-impression table { width: 100%; border-collapse: collapse; page-break-inside: auto; }
    #vue-impression th, #vue-impression td { border: 1px solid #999; padding: 3px 5px; text-align: left; }
    #vue-impression th { background: #eee; }
    #vue-impression tr { page-break-inside: avoid; }
    #vue-impression .imp-barre { background: #2c7a7b; height: 10px; }
    #vue-impression .imp-barre.critique { background: #c53030; }
    #vue-impression .imp-jalon { color: #b7791f; font-weight: 700; }
    #vue-impression .section-imp { page-break-inside: avoid; }
    * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}