/* ============================================================
   Plateforme Compta Fockedey - feuille de style
   Palette : bleu nuit (#0f1f33) / bleu (#2563eb) / gris chauds
   ============================================================ */

:root {
    --pc-nuit: #0f1f33;
    --pc-nuit-2: #16294a;
    --pc-bleu: #2563eb;
    --pc-bleu-clair: #e8eef7;
    --pc-vert: #059669;
    --pc-orange: #d97706;
    --pc-rouge: #dc2626;
    --pc-violet: #7c3aed;
    --pc-gris-fond: #f4f6f9;
    --pc-gris-texte: #64748b;
    --pc-bordure: #e5e7eb;
    --pc-bordure-2: #f1f3f5;
    --pc-surface: #ffffff;        /* cartes, topbar, formulaires */
    --pc-surface-2: #f8fafc;      /* en-tetes de tableau, survols */
    --pc-surface-3: #fafafa;      /* lignes ecartees */
    --pc-texte: #1f2937;
    --pc-texte-faible: #9ca3af;
    --pc-ombre: rgba(15,31,51,.05);
    --pc-sidebar: #0f1f33;         /* barre laterale : toujours bleu nuit, quel que soit le theme */
    --pc-sidebar-2: #0b1728;
    --pc-titre: #0f1f33;           /* titres et boutons sombres : s'inversent en mode sombre */
    --sidebar-w: 240px;
}

/* ---------- Mode sombre (switch dans la barre du haut, memorise dans le navigateur) ---------- */
[data-bs-theme="dark"] {
    --pc-nuit: #e5edf7;           /* titres : clair sur fond sombre */
    --pc-nuit-2: #223a5e;
    --pc-sidebar: #0b1526;
    --pc-sidebar-2: #070e1a;
    --pc-titre: #e5edf7;
    --pc-bleu: #4f8ff7;
    --pc-bleu-clair: #1c2a44;
    --pc-vert: #34d399;
    --pc-orange: #fbbf24;
    --pc-rouge: #f87171;
    --pc-violet: #a78bfa;
    --pc-gris-fond: #0f1623;
    --pc-gris-texte: #9aa8bd;
    --pc-bordure: #263247;
    --pc-bordure-2: #1e2a3d;
    --pc-surface: #172033;
    --pc-surface-2: #1c2740;
    --pc-surface-3: #131b2b;
    --pc-texte: #dbe3ee;
    --pc-texte-faible: #6b7a90;
    --pc-ombre: rgba(0,0,0,.35);
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--pc-gris-fond);
    color: var(--pc-texte);
    font-size: .92rem;
}

/* ---------- Sidebar ---------- */
.sidebar {
    width: var(--sidebar-w);
    min-height: 100vh;
    position: sticky;
    top: 0;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, var(--pc-sidebar) 0%, var(--pc-sidebar-2) 100%);
    color: white;
}

.sidebar-brand {
    padding: 1.1rem 1rem .9rem;
    border-bottom: 1px solid rgba(255,255,255,.08);
}

.sidebar-brand img {
    height: 30px;
    filter: brightness(0) invert(1);
}

.sidebar-brand .brand-title {
    font-weight: 700;
    font-size: .9rem;
    line-height: 1.2;
    margin-top: .55rem;
}

.sidebar-brand .brand-sub {
    font-size: .62rem;
    color: rgba(255,255,255,.45);
    letter-spacing: .1em;
    text-transform: uppercase;
}

.sidebar .nav-link {
    color: rgba(255,255,255,.78);
    padding: .5rem .8rem;
    font-size: .86rem;
    border-radius: .45rem;
    display: flex;
    align-items: center;
    gap: .55rem;
    transition: background-color .15s, color .15s;
}

.sidebar .nav-link:hover {
    background: rgba(255,255,255,.08);
    color: white;
}

.sidebar .nav-link.active {
    background: var(--pc-bleu);
    color: white;
    font-weight: 600;
}

.sidebar .nav-link svg {
    flex-shrink: 0;
    opacity: .8;
}

.sidebar .nav-section {
    font-size: .62rem;
    text-transform: uppercase;
    letter-spacing: .12em;
    color: rgba(255,255,255,.35);
    padding: .9rem .9rem .3rem;
    font-weight: 600;
}

.sidebar .nav-sub {
    margin-left: 1.3rem;
    border-left: 1px solid rgba(255,255,255,.12);
    padding-left: .4rem;
}

.sidebar .nav-sub .nav-link {
    font-size: .8rem;
    padding: .32rem .7rem;
}

.sidebar-user {
    margin-top: auto;
    padding: .8rem 1rem;
    border-top: 1px solid rgba(255,255,255,.08);
    font-size: .78rem;
}

.sidebar-user .avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--pc-bleu);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: .8rem;
}

.sidebar-user a {
    color: rgba(255,255,255,.55);
    text-decoration: none;
    font-size: .72rem;
}

.sidebar-user a:hover { color: white; }

/* ---------- Contenu ---------- */
.main-content {
    min-height: 100vh;
    min-width: 0;
}

.topbar {
    background: var(--pc-surface);
    border-bottom: 1px solid var(--pc-bordure);
    padding: .65rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 20;
}

.topbar .page-title {
    font-weight: 700;
    font-size: 1rem;
    color: var(--pc-nuit);
    margin: 0;
}

.topbar .breadcrumb {
    margin: 0;
    font-size: .75rem;
}

.content {
    padding: 1.5rem;
}

/* ---------- Cartes ---------- */
.card-pc {
    background: var(--pc-surface);
    border-radius: .7rem;
    border: 1px solid var(--pc-bordure);
    box-shadow: 0 1px 3px var(--pc-ombre);
}

.card-pc-header {
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--pc-bordure-2);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
}

.card-pc-header h6 {
    margin: 0;
    font-size: .85rem;
    font-weight: 700;
    color: var(--pc-nuit);
}

.card-pc-body { padding: 1rem; }

/* ---------- KPI ---------- */
.kpi {
    background: var(--pc-surface);
    border-radius: .7rem;
    border: 1px solid var(--pc-bordure);
    padding: .9rem 1rem;
    display: flex;
    align-items: center;
    gap: .8rem;
    height: 100%;
}

.kpi-icon {
    width: 42px;
    height: 42px;
    border-radius: .55rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.kpi-label {
    font-size: .7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--pc-gris-texte);
}

.kpi-value {
    font-size: 1.2rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--pc-nuit);
    line-height: 1.15;
}

/* ---------- Tuiles d'accueil ---------- */
.tuile {
    display: block;
    background: var(--pc-surface);
    border-radius: .9rem;
    border: 1px solid var(--pc-bordure);
    padding: 1.3rem;
    height: 100%;
    text-decoration: none;
    color: inherit;
    position: relative;
    overflow: hidden;
    transition: transform .15s, box-shadow .15s, border-color .15s;
}

.tuile::before {
    content: '';
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 5px;
    background: var(--accent, var(--pc-bleu));
}

.tuile:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 28px rgba(15,31,51,.12);
    border-color: var(--accent, var(--pc-bleu));
    color: inherit;
}

.tuile.tuile-bientot {
    opacity: .6;
    cursor: default;
}

.tuile.tuile-bientot:hover { transform: none; box-shadow: none; border-color: var(--pc-bordure); }

.tuile-icon {
    width: 48px;
    height: 48px;
    border-radius: .7rem;
    background: color-mix(in srgb, var(--accent, var(--pc-bleu)) 12%, var(--pc-surface));
    color: var(--accent, var(--pc-bleu));
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: .9rem;
}

.tuile h5 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--pc-nuit);
    margin-bottom: .35rem;
}

.tuile p {
    font-size: .8rem;
    color: var(--pc-gris-texte);
    margin: 0;
}

.tuile .badge-statut {
    position: absolute;
    top: .9rem;
    right: .9rem;
    font-size: .6rem;
    letter-spacing: .05em;
}

/* ---------- Tableaux ---------- */
.table-pc {
    font-size: .82rem;
    margin-bottom: 0;
}

.table-pc th {
    background: var(--pc-surface-2);
    color: var(--pc-gris-texte);
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    font-weight: 600;
    border-bottom: 1px solid var(--pc-bordure);
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 1;
}

.table-pc td { vertical-align: middle; }

.table-pc .row-total {
    font-weight: 700;
    background: var(--pc-bleu-clair);
}

.table-pc tfoot .row-total { position: sticky; bottom: 0; }

.table-pc tr.ligne-ecartee td {
    color: var(--pc-texte-faible);
    text-decoration: line-through;
    background: var(--pc-surface-3);
}

.table-pc tr.ligne-ecartee td .motif {
    text-decoration: none;
    color: var(--pc-orange);
    font-style: italic;
}

.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* ---------- Statuts ---------- */
.statut {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    font-size: .7rem;
    font-weight: 600;
    padding: .2rem .55rem;
    border-radius: 999px;
    letter-spacing: .02em;
}

.statut::before {
    content: '';
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
}

.statut-brouillon { background: #f1f5f9; color: #64748b; }
.statut-controlee { background: #fef3c7; color: #b45309; }
.statut-validee   { background: #dbeafe; color: #1d4ed8; }
.statut-facturee  { background: #d1fae5; color: #047857; }

[data-bs-theme="dark"] .statut-brouillon { background: #2a3448; color: #b6c2d4; }
[data-bs-theme="dark"] .statut-controlee { background: #3d2f0d; color: #fcd34d; }
[data-bs-theme="dark"] .statut-validee   { background: #16294a; color: #93c5fd; }
[data-bs-theme="dark"] .statut-facturee  { background: #0f3327; color: #6ee7b7; }

/* Audit : lignes d'etape d'un controle, liseret de couleur selon leur statut
   (classe distincte de .etape, deja prise par la frise Periode > Chargement > ... des refacturations) */
.ligne-controle td:first-child { border-left: 3px solid transparent; }
.ligne-controle-ok td:first-child { border-left-color: #10b981; }
.ligne-controle-anomalie td:first-child { border-left-color: #dc2626; }
.ligne-controle-sans_objet td:first-child { border-left-color: #94a3b8; }
.ligne-controle-sans_objet { opacity: .75; }

/* Pastilles KPI (couleurs pastel posees en ligne dans les templates) : fond attenue en sombre */
[data-bs-theme="dark"] .kpi-icon { background: rgba(255,255,255,.07) !important; }
[data-bs-theme="dark"] .kpi-icon[style*="#2563eb"] { color: #7fb0ff !important; }
[data-bs-theme="dark"] .kpi-icon[style*="#7c3aed"] { color: #b69cff !important; }
[data-bs-theme="dark"] .kpi-icon[style*="#b45309"] { color: #fbbf24 !important; }
[data-bs-theme="dark"] .kpi-icon[style*="#047857"] { color: #34d399 !important; }
[data-bs-theme="dark"] .kpi-icon[style*="#1d4ed8"] { color: #93c5fd !important; }

/* Bootstrap : liens/textes sombres et fonds clairs poses par classe */
[data-bs-theme="dark"] a.text-dark, [data-bs-theme="dark"] .text-dark:not(.badge):not([class*="bg-"]) { color: var(--pc-texte) !important; }
[data-bs-theme="dark"] .badge.bg-light { background-color: #2a3448 !important; color: #dbe3ee !important; border-color: #3a4a66 !important; }
[data-bs-theme="dark"] .alert-light { background-color: var(--pc-surface); color: var(--pc-texte); border-color: var(--pc-bordure); }
[data-bs-theme="dark"] .btn-outline-secondary { --bs-btn-color: #b6c2d4; --bs-btn-border-color: #3a4a66; }
[data-bs-theme="dark"] .sidebar-brand img { filter: brightness(0) invert(1); }
[data-bs-theme="dark"] .nav-tabs .nav-link.active { background: var(--pc-surface); border-color: var(--pc-bordure) var(--pc-bordure) var(--pc-surface); }
[data-bs-theme="dark"] .form-control, [data-bs-theme="dark"] .form-select { background-color: var(--pc-surface-2); border-color: var(--pc-bordure); color: var(--pc-texte); }
[data-bs-theme="dark"] .form-control::placeholder { color: var(--pc-texte-faible); }

/* Interrupteur clair / sombre (topbar) */
.theme-switch {
    border: 1px solid var(--pc-bordure);
    background: var(--pc-surface);
    color: var(--pc-gris-texte);
    border-radius: 999px;
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}

.theme-switch:hover { color: var(--pc-bleu); border-color: var(--pc-bleu); }
.theme-switch .icone-lune { display: none; }
[data-bs-theme="dark"] .theme-switch .icone-lune { display: inline; }
[data-bs-theme="dark"] .theme-switch .icone-soleil { display: none; }

/* ---------- Etapes du workflow ---------- */
.etapes {
    display: flex;
    gap: 0;
    counter-reset: etape;
}

.etape {
    flex: 1;
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .5rem .8rem;
    font-size: .75rem;
    color: var(--pc-gris-texte);
    background: var(--pc-surface);
    border: 1px solid var(--pc-bordure);
    border-right: none;
}

.etape:first-child { border-radius: .5rem 0 0 .5rem; }
.etape:last-child { border-radius: 0 .5rem .5rem 0; border-right: 1px solid var(--pc-bordure); }

.etape::before {
    counter-increment: etape;
    content: counter(etape);
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--pc-bordure);
    color: var(--pc-gris-texte);
    font-size: .68rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.etape.faite { color: var(--pc-vert); }
.etape.faite::before { background: var(--pc-vert); color: white; content: '\2713'; }
.etape.courante { color: var(--pc-bleu); font-weight: 600; background: var(--pc-bleu-clair); }
.etape.courante::before { background: var(--pc-bleu); color: white; }

/* ---------- Boutons ---------- */
.btn-fockedey {
    background: var(--pc-sidebar);
    border: none;
    color: white;
    padding: .7rem;
    font-weight: 500;
    letter-spacing: .3px;
}

.btn-fockedey:hover { background: #16294a; color: white; }

.btn-primary { background: var(--pc-bleu); border-color: var(--pc-bleu); }

/* ---------- Divers ---------- */
[x-cloak] { display: none !important; }

.form-section {
    background: var(--pc-surface);
    border-radius: .7rem;
    border: 1px solid var(--pc-bordure);
    padding: 1.4rem;
    margin-bottom: 1.2rem;
}

.form-section h6 {
    font-weight: 700;
    color: var(--pc-nuit);
    margin-bottom: 1rem;
}

.htmx-progress {
    position: fixed;
    top: 0; left: 0;
    width: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--pc-bleu), #60a5fa);
    z-index: 9999;
    transition: width .4s ease;
}

.htmx-progress.active { animation: htmx-fill 2s ease-out forwards; }
.htmx-progress.done { width: 100% !important; opacity: 0; transition: width .2s, opacity .4s .2s; }

@keyframes htmx-fill {
    0% { width: 0; } 20% { width: 30%; } 50% { width: 60%; } 80% { width: 85%; } 100% { width: 92%; }
}

.htmx-request .htmx-indicator { display: inline-block; }
.htmx-indicator { display: none; }

/* ---------- Filtre annee / mois de la barre du haut ---------- */
.filtre-periode {
    display: flex;
    align-items: center;
    gap: .4rem;
    background: var(--pc-surface-2);
    border: 1px solid var(--pc-bordure);
    border-radius: .55rem;
    padding: .2rem .5rem;
}

.filtre-periode label {
    font-size: .68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--pc-gris-texte);
    margin: 0;
}

.filtre-periode select {
    appearance: none;
    background: transparent;
    border: none;
    color: var(--pc-nuit);
    font-size: .9rem;
    font-weight: 700;
    padding: .25rem 1.1rem .25rem .3rem;
    cursor: pointer;
    /* chevron dessine a la main : aucune ressource externe */
    background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                      linear-gradient(135deg, currentColor 50%, transparent 50%);
    background-position: right .5rem center, right .28rem center;
    background-size: .3rem .3rem, .3rem .3rem;
    background-repeat: no-repeat;
}

/* Le menu deroulant natif n'herite pas du fond transparent : on le repeint */
.filtre-periode option { background: var(--pc-surface); color: var(--pc-texte); font-weight: 400; }
.filtre-periode select:focus { outline: 2px solid var(--pc-bleu); outline-offset: 1px; border-radius: .3rem; }
.filtre-periode label + select { margin-right: .35rem; }

/* ---------- Liste des periodes : une carte par mois, une ligne par type ---------- */
.mois-card {
    background: var(--pc-surface);
    border-radius: .7rem;
    border: 1px solid var(--pc-bordure);
    box-shadow: 0 1px 3px var(--pc-ombre);
    overflow: hidden;
}

.mois-card-header {
    display: flex;
    align-items: baseline;
    gap: .6rem;
    padding: .7rem 1rem;
    background: var(--pc-surface-2);
    color: var(--pc-nuit);
    cursor: pointer;
    user-select: none;
    list-style: none;               /* on remplace le triangle natif par le notre */
}

.mois-card-header::-webkit-details-marker { display: none; }
.mois-card-header:hover { background: color-mix(in srgb, var(--pc-bleu) 7%, var(--pc-surface-2)); }
.mois-card[open] .mois-card-header { border-bottom: 1px solid var(--pc-bordure); }

.mois-chevron {
    align-self: center;
    width: .42rem;
    height: .42rem;
    border-right: 2px solid var(--pc-gris-texte);
    border-bottom: 2px solid var(--pc-gris-texte);
    transform: rotate(-45deg);
    transition: transform .15s ease;
}

.mois-card[open] .mois-chevron { transform: rotate(45deg); }

.mois-titre {
    font-weight: 700;
    font-size: 1.02rem;
    letter-spacing: -.01em;
}

.mois-annee { color: var(--pc-gris-texte); font-weight: 600; }

.mois-code {
    font-size: .68rem;
    font-weight: 600;
    letter-spacing: .04em;
    color: var(--pc-gris-texte);
    background: color-mix(in srgb, var(--pc-gris-texte) 14%, transparent);
    border-radius: 999px;
    padding: .1rem .45rem;
}

.mois-meta { font-size: .75rem; color: var(--pc-gris-texte); margin-left: auto; }

.mois-total {
    font-weight: 700;
    font-size: .9rem;
    color: var(--pc-nuit);
}

/* Grille commune a toutes les lignes : les colonnes s'alignent d'une carte a l'autre */
/* Une seule grille pour l'en-tete et les lignes : 7 colonnes, aucune ne deborde sur la suivante */
.mois-card .periode-row,
.mois-card .periode-entete {
    display: grid;
    grid-template-columns: 82px minmax(0, 1fr) 104px minmax(0, 290px) 132px 92px 72px;
    align-items: center;
    gap: .75rem;
    padding: .55rem 1rem .55rem calc(1rem - 4px);
    border-left: 4px solid var(--moteur, transparent);
    border-bottom: 1px solid var(--pc-bordure-2);
    text-decoration: none;
    color: inherit;
    font-size: .83rem;
}

.mois-card .periode-entete {
    padding-top: .35rem;
    padding-bottom: .35rem;
    border-left-color: transparent;
    font-size: .68rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--pc-gris-texte);
}

.mois-card .periode-entete span:nth-child(3),
.mois-card .periode-entete span:nth-child(4),
.mois-card .periode-entete span:nth-child(5),
.mois-card .periode-entete span:nth-child(7) { text-align: right; }

.mois-card .periode-row:last-child { border-bottom: none; }
.mois-card .periode-row:hover { background: color-mix(in srgb, var(--moteur, var(--pc-bleu)) 7%, var(--pc-surface)); }

.periode-moteur {
    justify-self: start;
    font-size: .67rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--moteur, var(--pc-bleu));
    background: color-mix(in srgb, var(--moteur, var(--pc-bleu)) 13%, transparent);
    border-radius: 999px;
    padding: .15rem .5rem;
    white-space: nowrap;
}

.periode-nom {
    font-weight: 600;
    color: var(--pc-nuit);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.periode-volume { font-size: .76rem; color: var(--pc-gris-texte); text-align: right; }
.periode-detail {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    column-gap: .6rem;
    font-size: .76rem;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.periode-total { font-weight: 700; font-size: .88rem; }
.periode-total-estime { font-weight: 600; color: var(--pc-gris-texte); }
.periode-libelle { font-size: .7rem; font-weight: 400; color: var(--pc-gris-texte); }
.periode-statut { justify-self: start; }
.periode-factures { font-size: .75rem; color: var(--pc-gris-texte); text-align: right; white-space: nowrap; }

/* Une couleur par moteur, reprise par la liste des types */
.moteur-fiches_travail { --moteur: var(--pc-bleu); }
.moteur-import         { --moteur: #6366f1; }
.moteur-carburant      { --moteur: var(--pc-orange); }
.moteur-peages         { --moteur: var(--pc-violet); }
.moteur-location       { --moteur: #0d9488; }
.moteur-pieces         { --moteur: #b45309; }
.moteur-lavages        { --moteur: #0284c7; }
.moteur-ensemble       { --moteur: #65a30d; }
.moteur-techno         { --moteur: #9333ea; }
[data-bs-theme="dark"] .moteur-import   { --moteur: #a5b4fc; }
[data-bs-theme="dark"] .moteur-location { --moteur: #2dd4bf; }

.type-row {
    padding: .5rem 1rem .5rem calc(1rem - 4px);
    border-left: 4px solid var(--moteur, transparent);
    border-bottom: 1px solid var(--pc-bordure-2);
    font-size: .8rem;
}

.type-row:last-child { border-bottom: none; }
.type-row .fw-semibold { color: var(--moteur, var(--pc-nuit)); }

/* Ecrans etroits : la grille fixe ne tient plus, on revient a un flux souple */
@media (max-width: 1100px) {
    .mois-card .periode-row {
        display: flex;
        flex-wrap: wrap;
        column-gap: .75rem;
        row-gap: .25rem;
    }
    .mois-card .periode-entete { display: none; }
    .periode-nom { flex: 1 1 12rem; }
    .periode-volume { text-align: left; }
    .periode-detail { justify-content: flex-start; }
    .periode-factures { text-align: left; }
}

@media print {
    .sidebar, .topbar, .no-print { display: none !important; }
    .content { padding: 0; }
}

@media (max-width: 900px) {
    .sidebar { display: none; }
}

/* ---------- Planning annuel des refacturations ---------- */
.planning-scroll { overflow-x: auto; }

.planning {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: .78rem;
    min-width: 1560px;      /* 12 colonnes de mois lisibles, defilement horizontal au besoin */
}

.planning th, .planning td {
    border-bottom: 1px solid var(--pc-bordure-2);
    border-right: 1px solid var(--pc-bordure-2);
    padding: 0;
    vertical-align: top;
}

.planning thead th {
    background: var(--pc-surface-2);
    color: var(--pc-gris-texte);
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    text-align: center;
    padding: .5rem .3rem;
    position: sticky;
    top: 0;
    z-index: 2;
}

.planning .planning-mm {
    display: block;
    font-size: .64rem;
    font-weight: 500;
    letter-spacing: 0;
    text-transform: none;
    color: var(--pc-texte-faible);
}

/* Premiere colonne collante : le type reste lisible quand on fait defiler les mois */
.planning .planning-type {
    position: sticky;
    left: 0;
    z-index: 1;
    background: var(--pc-surface);
    text-align: left;
    min-width: 230px;
    max-width: 230px;
    padding: .5rem .75rem .5rem calc(.75rem - 4px);
    border-left: 4px solid var(--moteur, transparent);
    font-weight: 600;
    color: var(--pc-nuit);
}

.planning thead .planning-type { z-index: 3; background: var(--pc-surface-2); border-left-color: transparent; }
.planning tfoot .planning-type { border-left-color: transparent; }
.planning .planning-type .periode-moteur { display: inline-block; margin-bottom: .2rem; }
.planning-nom { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.planning-calendrier { display: block; font-size: .66rem; font-weight: 400; color: var(--pc-gris-texte); }
.planning-inactif .planning-nom { color: var(--pc-gris-texte); font-style: italic; }

.planning td.planning-courant, .planning th.planning-courant {
    background: color-mix(in srgb, var(--pc-bleu) 6%, var(--pc-surface));
}

.planning tfoot td, .planning tfoot th {
    background: var(--pc-surface-2);
    font-weight: 700;
    padding: .45rem .4rem;
    font-variant-numeric: tabular-nums;
}
.planning .planning-total { padding: .5rem .5rem; font-weight: 700; white-space: nowrap; }
.planning tbody .planning-total .planning-mm { text-align: right; }

/* Une case : un lien plein, l'icone de note en coin */
.plan-cell {
    position: relative;
    min-height: 62px;
    height: 100%;
    min-width: 100px;
}
.plan-cell .statut { white-space: nowrap; }

.plan-lien {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: .2rem;
    padding: .45rem 1.3rem .45rem .45rem;
    min-height: 62px;
    text-decoration: none;
    color: inherit;
}

a.plan-lien:hover { background: color-mix(in srgb, var(--moteur, var(--pc-bleu)) 9%, var(--pc-surface)); }
.plan-muet { opacity: .55; }
.plan-montant { font-weight: 700; color: var(--pc-nuit); font-variant-numeric: tabular-nums; white-space: nowrap; }
.plan-detail { font-size: .66rem; color: var(--pc-gris-texte); white-space: nowrap; }

/* Teinte de fond selon l'etat : lisible en un balayage, sans lire les pastilles */
.plan-facturee            { background: color-mix(in srgb, #059669 8%, transparent); }
.plan-validee             { background: color-mix(in srgb, #2563eb 7%, transparent); }
.plan-controlee           { background: color-mix(in srgb, #d97706 8%, transparent); }
.plan-cell.etat-retard    { background: color-mix(in srgb, #dc2626 10%, transparent); box-shadow: inset 0 0 0 1px color-mix(in srgb, #dc2626 45%, transparent); }
.plan-cell.etat-a_faire:not([class*="plan-brouillon"]):not([class*="plan-controlee"]):not([class*="plan-validee"]) {
    background: color-mix(in srgb, #d97706 10%, transparent);
}

.statut-absente { background: var(--pc-surface-2); color: var(--pc-texte-faible); }
.statut-a_faire { background: #fef3c7; color: #b45309; }
.statut-retard  { background: #fee2e2; color: #b91c1c; }
[data-bs-theme="dark"] .statut-absente { background: #1c2740; color: #7a8aa3; }
[data-bs-theme="dark"] .statut-a_faire { background: #3d2f0d; color: #fcd34d; }
[data-bs-theme="dark"] .statut-retard  { background: #3f1d1d; color: #fca5a5; }

/* Note : discrete (coin, gris), franche quand elle existe */
.plan-note {
    position: absolute;
    top: .3rem;
    right: .3rem;
    border: none;
    background: transparent;
    color: var(--pc-texte-faible);
    padding: .1rem;
    line-height: 1;
    border-radius: 4px;
    opacity: .35;
    cursor: pointer;
}
.plan-cell:hover .plan-note { opacity: 1; }
.plan-note:hover { background: color-mix(in srgb, var(--pc-bleu) 12%, transparent); color: var(--pc-bleu); }
.plan-note-pleine { opacity: 1; color: var(--pc-orange); }
.plan-note-texte {
    font-size: .64rem;
    color: #92400e;
    background: #fffbeb;
    border-top: 1px dashed #fcd34d;
    padding: .25rem .45rem;
    line-height: 1.25;
}
[data-bs-theme="dark"] .plan-note-texte { color: #fcd34d; background: #2a220c; border-top-color: #92400e; }

.plan-editeur { padding: .45rem; min-width: 240px; background: var(--pc-surface); box-shadow: 0 6px 20px var(--pc-ombre); z-index: 4; }
.plan-editeur-titre { font-size: .7rem; font-weight: 600; color: var(--pc-gris-texte); margin-bottom: .3rem; }
.plan-editeur-actions { display: flex; gap: .35rem; align-items: center; margin-top: .35rem; }

.legende { display: flex; gap: .35rem; flex-wrap: wrap; }

/* Liste « a traiter » en tete de page */
.a-traiter-row {
    display: grid;
    grid-template-columns: 86px minmax(0, 1fr) 130px 130px 190px;
    align-items: center;
    gap: .75rem;
    padding: .5rem 1rem .5rem calc(1rem - 4px);
    border-left: 4px solid var(--moteur, transparent);
    border-bottom: 1px solid var(--pc-bordure-2);
    text-decoration: none;
    color: inherit;
    font-size: .83rem;
}
.a-traiter-row:last-child { border-bottom: none; }
.a-traiter-row:hover { background: color-mix(in srgb, var(--moteur, var(--pc-bleu)) 7%, var(--pc-surface)); }
.a-traiter-mois { font-weight: 600; }
.a-traiter-echeance { font-size: .76rem; text-align: right; color: var(--pc-gris-texte); }
.a-traiter-row.etat-retard .a-traiter-echeance { color: #b91c1c; font-weight: 600; }

/* Notes de l'annee */
.note-row {
    display: grid;
    grid-template-columns: 86px 260px minmax(0, 1fr) 160px;
    gap: .75rem;
    align-items: start;
    padding: .5rem 1rem .5rem calc(1rem - 4px);
    border-left: 4px solid var(--moteur, transparent);
    border-bottom: 1px solid var(--pc-bordure-2);
    font-size: .8rem;
}
.note-row:last-child { border-bottom: none; }
.note-quand { color: var(--pc-gris-texte); }
.note-texte { white-space: pre-wrap; }
.note-meta { font-size: .7rem; color: var(--pc-texte-faible); text-align: right; }

/* Verification des sources dans la case du planning */
.plan-source {
    font-size: .64rem;
    line-height: 1.25;
    padding: .2rem .45rem;
    border-top: 1px solid var(--pc-bordure-2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.plan-source-complet   { color: #047857; }
.plan-source-incomplet, .plan-source-vide, .plan-source-erreur { color: #b91c1c; font-weight: 600; background: color-mix(in srgb, #dc2626 8%, transparent); }
.plan-source-inconnue  { color: var(--pc-texte-faible); font-style: italic; }
[data-bs-theme="dark"] .plan-source-complet { color: #6ee7b7; }
[data-bs-theme="dark"] .plan-source-incomplet, [data-bs-theme="dark"] .plan-source-vide, [data-bs-theme="dark"] .plan-source-erreur { color: #fca5a5; }
[x-cloak] { display: none !important; }

/* ── Instance de consultation (VPS) ── */
.bandeau-consultation { display: flex; align-items: center; gap: .5rem; padding: .45rem 1.5rem; font-size: .8rem;
    background: color-mix(in srgb, #f59e0b 14%, var(--pc-surface)); border-bottom: 1px solid color-mix(in srgb, #f59e0b 40%, transparent);
    color: var(--pc-texte); }

/* ── Documentation du groupe ── */
.doc-schema-zone { background: #fff; border: 1px solid var(--pc-bordure); border-radius: 10px; padding: .5rem; overflow-x: auto; color: #0f1f33; }
.doc-schema { display: block; width: 100%; height: auto; min-width: 760px; }
.doc-schema .doc-fleche:hover line { stroke-width: 4; }
.doc-lecture { max-width: 1100px; }
.doc-chapitre { margin-bottom: 2.25rem; }
.doc-chapitre h4 { color: var(--pc-titre); font-weight: 700; margin-bottom: .75rem; }
.doc-corps p, .doc-corps li { max-width: 85ch; }
.doc-bref { background: var(--pc-bleu-clair); border-left: 4px solid var(--pc-bleu); border-radius: 6px; padding: .65rem 1rem; margin-bottom: 1rem; }
.doc-bref p { margin: 0; }
.doc-encadre { background: color-mix(in srgb, #f59e0b 10%, var(--pc-surface)); border-left: 4px solid #f59e0b; border-radius: 6px; padding: .55rem .9rem; margin: .5rem 0 1rem; max-width: 85ch; }
.doc-intertitre { color: var(--pc-bleu); font-weight: 700; margin-top: 1.1rem; }
.doc-sommaire { columns: 2; column-gap: 2.5rem; }
.doc-table td { font-size: .8rem; vertical-align: top; }
.doc-groupe td { background: var(--pc-bleu-clair) !important; font-weight: 700; text-transform: uppercase; font-size: .72rem; letter-spacing: .03em; }
.doc-question { border-bottom: 1px solid var(--pc-bordure-2); padding: .5rem 0; }
.doc-question summary { font-weight: 600; cursor: pointer; }
.doc-question div { padding: .4rem 0 0 1rem; }
.doc-glossaire dt { margin-top: .5rem; }
.doc-glossaire dd { margin-left: 1rem; color: var(--pc-gris-texte); }
.doc-reference { font-size: .78rem; color: var(--pc-gris-texte); background: var(--pc-surface-2); border: 1px dashed var(--pc-bordure); border-radius: 6px; padding: .35rem .6rem; margin-bottom: .35rem; max-height: 9rem; overflow-y: auto; }
.doc-cases { max-height: 14rem; overflow-y: auto; border: 1px solid var(--pc-bordure); border-radius: 6px; padding: .35rem .6rem; }
.doc-etat { display: inline-block; font-size: .64rem; font-weight: 600; padding: .1rem .4rem; border-radius: 999px; }
.doc-etat-source { background: #e2e8f0; color: #334155; }
.doc-etat-ok { background: #d1fae5; color: #047857; }
.doc-etat-a_revoir { background: #fef3c7; color: #b45309; }
.doc-etat-manquante { background: #fee2e2; color: #b91c1c; }
