/* GED Factures — charte OSTRA / Horizon Santé Travail
   Accent : bleu OSTRA #006ab6, appuis teal #2e9e93 et orange #f19003,
   alerte #d93a3f, validation #2e8b57. */

:root {
    --encre: #006ab6;
    --encre-clair: #0a82d8;
    --encre-fonce: #063b5b;
    --teal: #2e9e93;
    --orange: #f19003;
    --papier: #f6f9fc;
    --carte: #ffffff;
    --regle: #d6e2ec;
    --texte: #1a2733;
    --muted: #6a7986;
    --alerte: #d93a3f;
    --ok: #2e8b57;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--papier);
    color: var(--texte);
    font: 15px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
}

/* ------- barre haute ------- */
.topbar { background: #fff; border-bottom: 3px solid var(--encre); box-shadow: 0 1px 6px rgba(6,59,91,.06); }
.topbar-inner {
    max-width: 1180px; margin: 0 auto; padding: 0 20px;
    display: flex; align-items: center; gap: 28px; height: 68px;
}
.brand { display: flex; align-items: center; gap: 14px; text-decoration: none; }
.logo-ostra { height: 38px; width: auto; display: block; }
.logo-ahst  { height: 42px; width: auto; display: block; }
.brand-sep { width: 1px; height: 34px; background: var(--regle); }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a {
    color: var(--encre-fonce); text-decoration: none; padding: 7px 14px;
    border-radius: 5px; font-size: 14px; font-weight: 500;
}
.topbar nav a:hover { background: #eaf3fb; color: var(--encre); }
.topbar nav a.on { background: var(--encre); color: #fff; }

.wrap { max-width: 1180px; margin: 28px auto 64px; padding: 0 20px; }

h1 { font-size: 22px; margin: 0 0 18px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
h2 { font-size: 16px; margin: 0 0 12px; }

/* ------- formulaires ------- */
.filters, .card {
    background: var(--carte); border: 1px solid var(--regle);
    border-radius: 6px; padding: 16px 18px; margin-bottom: 18px;
}
.filters-row { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; }
.filters-row + .filters-row { margin-top: 12px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.grow { flex: 1 1 280px; }
input, select {
    font: inherit; padding: 7px 10px; border: 1px solid var(--regle);
    border-radius: 4px; background: #fff; color: var(--texte); min-width: 120px;
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
    outline: 2px solid var(--encre-clair); outline-offset: 1px;
}
button {
    font: inherit; font-weight: 600; padding: 8px 18px; cursor: pointer;
    background: var(--encre); color: #fff; border: 0; border-radius: 4px;
}
button:hover { background: var(--encre-clair); }
.btn-reset { align-self: center; font-size: 13px; color: var(--muted); margin-left: 4px; }
.card label { margin-bottom: 10px; }
.card .grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.two-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }

/* ------- tableau ------- */
.result-count { color: var(--muted); font-size: 13px; margin: 4px 2px 8px; }
table.docs {
    width: 100%; border-collapse: collapse; background: var(--carte);
    border: 1px solid var(--regle); border-radius: 6px; overflow: hidden;
    font-variant-numeric: tabular-nums;
}
.docs th, .docs td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--regle); }
.docs th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: #f5f3ee; }
.docs td.num, .docs th.num { text-align: right; }
.docs tr:hover td { background: #f8f7f3; }
.docs tr.current td { background: #eef2f8; }
.docs.compact td, .docs.compact th { padding: 6px 10px; font-size: 13.5px; }
.docs .actions a { margin-right: 10px; }
td.overdue { color: var(--alerte); font-weight: 600; }
a { color: var(--encre-clair); }

/* Onglets de classement : la signature visuelle — un liseré par type de pièce */
.tag {
    display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 9px;
    border-radius: 3px; border-left: 4px solid; background: #f1efe9; white-space: nowrap;
}
.tag-facture       { border-color: #1d3557; color: #1d3557; }
.tag-devis         { border-color: #8a6d1d; color: #6e5615; }
.tag-bon_commande  { border-color: #2e6b46; color: #2e6b46; }
.tag-bon_livraison { border-color: #7a4a8c; color: #6a3c7c; }
.tag-autre         { border-color: #9a9a9a; color: #6e7178; }

.statut { font-size: 12.5px; }
.statut-a_verifier { color: #8a6d1d; }
.statut-valide     { color: var(--ok); }
.statut-paye       { color: var(--muted); }

/* extrait plein texte */
.snippet-row td { background: #fffdf4; padding-top: 0; }
.snippet { font-size: 13px; color: var(--muted); padding: 4px 2px 8px; }
.snippet mark { background: #ffe89b; color: var(--texte); padding: 0 2px; }

/* ------- divers ------- */
.flash { padding: 10px 14px; border-radius: 4px; margin-bottom: 12px; font-size: 14px; }
.flash-ok   { background: #e7f2ea; color: var(--ok); border: 1px solid #bcd9c5; }
.flash-warn { background: #fbf3da; color: #6e5615; border: 1px solid #e7d79a; }
.flash-err  { background: #fae8e6; color: var(--alerte); border: 1px solid #e7b6b1; }
.empty {
    background: var(--carte); border: 1px dashed var(--regle); border-radius: 6px;
    padding: 36px; text-align: center; color: var(--muted);
}
.muted { color: var(--muted); font-weight: 400; font-size: 13px; }
code { background: #f1efe9; padding: 1px 5px; border-radius: 3px; font-size: 13px; }

.pager { margin-top: 14px; display: flex; gap: 6px; }
.pager a {
    padding: 4px 10px; border: 1px solid var(--regle); border-radius: 4px;
    text-decoration: none; background: var(--carte);
}
.pager a.on { background: var(--encre); color: #fff; border-color: var(--encre); }

/* ------- connexion ------- */
.login-body {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; background: var(--encre);
}
.login-box {
    background: var(--carte); border-radius: 8px; padding: 32px 36px;
    width: 100%; max-width: 380px; box-shadow: 0 8px 32px rgba(0,0,0,.25);
}
.login-brand {
    font-size: 22px; font-weight: 700; color: var(--encre);
    letter-spacing: .04em; text-align: center; margin-bottom: 22px;
}
.login-brand span { font-weight: 300; opacity: .7; }
.login-logos { display: flex; align-items: center; justify-content: center; gap: 16px; margin-bottom: 8px; }
.login-logos img { height: 46px; width: auto; }
.login-sub { text-align: center; color: var(--muted); font-size: 13px; margin: 0 0 22px; }
.login-box label { margin-bottom: 12px; }
.login-box input { min-width: 0; width: 100%; }
.login-box button { width: 100%; margin-top: 6px; }

/* ------- barre : utilisateur connecté ------- */
.userbox { margin-left: auto; color: var(--muted); font-size: 13px; }
.userbox a { color: var(--encre); font-weight: 600; }
.role-tag {
    display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px;
    border-radius: 9px; background: #eaf3fb; color: var(--encre); margin-left: 2px;
}
.inline-menu { display: inline-block; }
.inline-menu summary { cursor: pointer; color: var(--encre-clair); list-style: none; }
.inline-menu summary::-webkit-details-marker { display: none; }
.mini-form { display: flex; gap: 6px; margin-top: 6px; }
.mini-form input { min-width: 0; width: 140px; }
.role-help { margin-top: 16px; border-top: 1px solid var(--regle); padding-top: 12px; }
.role-help p { margin: 4px 0; font-size: 12.5px; }

/* ------- zone de suppression ------- */
.danger-zone { border-color: #e7b6b1; }
.danger-zone h2 { color: var(--alerte); }
.btn-danger { background: var(--alerte); }
.btn-danger:hover { background: #8f1e17; }

/* ------- zone de dépôt upload ------- */
.dropzone {
    display: block; border: 2px dashed var(--regle); border-radius: 6px;
    padding: 26px; text-align: center; cursor: pointer; margin: 12px 0 16px;
    background: #faf9f5; transition: border-color .15s, background .15s;
}
.dropzone.over { border-color: var(--encre); background: #eef2f8; }
.dropzone input[type=file] { display: block; margin: 0 auto 10px; }
.dropzone-text { color: var(--muted); font-size: 14px; }
.filelist { list-style: none; margin: 14px 0 0; padding: 0; text-align: left; }
.filelist li {
    padding: 5px 8px; border-bottom: 1px solid var(--regle); font-size: 13.5px;
    display: flex; justify-content: space-between; align-items: center;
}
.filelist li:last-child { border-bottom: 0; }
.badge {
    font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 3px;
    background: #e7f2ea; color: var(--ok); white-space: nowrap;
}
.badge-none { background: #f1efe9; color: var(--muted); font-weight: 400; }

/* ------- dossier lié (fiche document) ------- */
.flow { display: flex; gap: 6px; margin: 4px 0 14px; }
.flow-step {
    flex: 1; text-align: center; font-size: 12px; font-weight: 600;
    padding: 6px 4px; border-radius: 4px; position: relative;
}
.flow-step.on  { background: #e7f2ea; color: var(--ok); border: 1px solid #bcd9c5; }
.flow-step.off { background: #f5f3ee; color: #b8b3a6; border: 1px dashed var(--regle); }
.flow-step.off::after { content: " ✕"; }
.flow-step.on::after  { content: " ✓"; }

.dossier-list { list-style: none; margin: 0 0 10px; padding: 0; }
.dossier-list li {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    padding: 9px 10px; border: 1px solid var(--regle); border-radius: 5px;
    margin-bottom: 6px; background: #fff;
}
.dossier-list li.current { background: #eef2f8; border-color: var(--encre-clair); }
.dossier-info { color: var(--muted); font-size: 13px; flex: 1; }
.dossier-list a { font-weight: 600; white-space: nowrap; }
.dossier-total { text-align: right; font-size: 14px; margin: 4px 0 0; }

/* badge "nombre de pièces liées" dans la liste de recherche */
.link-badge {
    display: inline-block; min-width: 18px; text-align: center;
    font-size: 11px; font-weight: 700; line-height: 18px;
    padding: 0 5px; margin-left: 5px; border-radius: 9px;
    background: var(--encre); color: #fff; vertical-align: middle;
}

/* ------- fiche document : saisie à gauche, PDF en grand à droite ------- */
.doc-layout {
    display: grid; grid-template-columns: minmax(400px, 480px) 1fr;
    gap: 18px; align-items: start;
}
.doc-left .card { margin-bottom: 18px; }
.doc-right { position: sticky; top: 16px; }
.doc-right object {
    display: block; width: 100%;
    height: calc(100vh - 110px); min-height: 520px;
    border: 1px solid var(--regle); border-radius: 6px; background: #f1efe9;
}
@media (max-width: 1024px) {
    .doc-layout { grid-template-columns: 1fr; }
    .doc-right { position: static; }
    .doc-right object { height: 70vh; }
}

/* ------- onglets d'aperçu des pièces du dossier ------- */
.preview-tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.preview-tab {
    background: #f1efe9; color: var(--texte); border: 1px solid var(--regle);
    border-bottom: 3px solid transparent; border-radius: 4px 4px 0 0;
    padding: 6px 12px; font-size: 13px; font-weight: 600; cursor: pointer;
    display: flex; flex-direction: column; align-items: flex-start; line-height: 1.25;
}
.preview-tab small { font-weight: 400; color: var(--muted); font-size: 11px; }
.preview-tab:hover { background: #e9e6dd; }
.preview-tab.active { background: #fff; border-bottom-width: 3px; }
.preview-tab.active small { color: var(--encre-clair); }
/* liseré coloré par type, repris de la charte des tags */
.tag-border-facture.active       { border-bottom-color: #1d3557; }
.tag-border-devis.active         { border-bottom-color: #8a6d1d; }
.tag-border-bon_commande.active  { border-bottom-color: #2e6b46; }
.tag-border-bon_livraison.active { border-bottom-color: #7a4a8c; }
.tag-border-autre.active         { border-bottom-color: #9a9a9a; }
.preview-hint { font-size: 12px; margin: 8px 2px 0; }

/* bouton qui ressemble à un lien (suppression fournisseur) */
.link-like {
    background: none; border: 0; padding: 0; margin: 0; cursor: pointer;
    color: var(--alerte); font: inherit; font-weight: 400; text-decoration: underline;
}
.link-like:hover { color: #a52a2e; background: none; }

/* ------- page réception email ------- */
.check { flex-direction: row; align-items: center; gap: 8px; font-size: 14px; color: var(--texte); margin-bottom: 12px; }
.check input { min-width: 0; width: auto; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.btn-secondary { background: #fff; color: var(--encre); border: 1px solid var(--encre); }
.btn-secondary:hover { background: #eaf3fb; }
.card h2 { margin-top: 0; }
.card p { font-size: 13.5px; line-height: 1.55; }
.card.muted code { display: inline-block; }

/* ------- rapprochement devis/facture ------- */
.rappro {
    padding: 9px 12px; border-radius: 5px; font-size: 13.5px; margin: 4px 0 12px;
    border-left: 4px solid;
}
.rappro-ok          { background: #e7f3ec; border-color: var(--ok); color: #1f6b40; }
.rappro-depassement { background: #fbe9e7; border-color: var(--alerte); color: #a3271f; }
.rappro-sous        { background: #fff4e0; border-color: var(--orange); color: #8a5a00; }

/* ------- carte ré-analyse ------- */
.reanalyze-card { border-color: #cfe3f3; }
.reanalyze-card h2 { color: var(--encre); }

/* ------- barre de progression ------- */
.progress { height: 10px; background: var(--regle); border-radius: 6px; overflow: hidden; margin: 14px 0 8px; }
.progress-bar { height: 100%; width: 0; background: var(--encre); transition: width .2s; }

/* ------- galerie des pièces du dossier ------- */
.gallery {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 12px; margin-top: 12px;
}
.gallery-item { margin: 0; cursor: pointer; }
.gallery-thumb {
    position: relative; height: 170px; border: 1px solid var(--regle);
    border-radius: 6px; overflow: hidden; background: #f1efe9;
}
.gallery-thumb object { width: 100%; height: 100%; pointer-events: none; }
.gallery-zoom {
    position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
    background: rgba(6,59,91,.0); color: #fff; font-size: 13px; font-weight: 600;
    opacity: 0; transition: opacity .15s, background .15s;
}
.gallery-item:hover .gallery-zoom { opacity: 1; background: rgba(6,59,91,.45); }
.gallery-item:hover .gallery-thumb { border-color: var(--encre); }
.gallery-item figcaption {
    display: flex; align-items: center; justify-content: space-between;
    gap: 6px; margin-top: 5px; font-size: 11px; color: var(--muted);
}

/* ------- lightbox de zoom ------- */
.lightbox {
    position: fixed; inset: 0; z-index: 1000; background: rgba(10,20,30,.82);
    display: flex; flex-direction: column; padding: 24px;
}
.lightbox-bar {
    display: flex; align-items: center; justify-content: space-between;
    color: #fff; padding: 4px 4px 12px; font-size: 14px; font-weight: 600;
}
.lightbox-actions { display: flex; align-items: center; gap: 16px; }
.lightbox-actions a { color: #cfe3f3; font-weight: 500; }
#lightbox-close {
    background: rgba(255,255,255,.15); color: #fff; border: 0; border-radius: 5px;
    width: 32px; height: 32px; font-size: 16px; cursor: pointer; line-height: 1;
}
#lightbox-close:hover { background: rgba(255,255,255,.3); }
.lightbox object {
    flex: 1; width: 100%; border: 0; border-radius: 6px; background: #fff;
}

/* ------- page galerie en popup ------- */
.gallery-page { background: var(--papier); margin: 0; padding: 0; }
.gallery-page-head {
    display: flex; align-items: center; gap: 14px;
    padding: 12px 18px; background: #fff; border-bottom: 2px solid var(--encre);
    position: sticky; top: 0; z-index: 5;
}
.gallery-page-head button { margin-left: auto; }
.gallery-large {
    padding: 18px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}
.gallery-large .gallery-thumb { height: 260px; }

@media (max-width: 860px) {
    .two-cols { grid-template-columns: 1fr; }
    .docs th:nth-child(7), .docs td:nth-child(7) { display: none; }
}
@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}
