:root {
    --fond: #f4f6f8;
    --carte: #ffffff;
    --texte: #1f2933;
    --doux: #6b7785;
    --bord: #e1e6eb;
    --accent: #0b6e8a;
    --accent-clair: #e3f1f5;
    --vert: #1f8a4c;
    --rouge: #c0392b;
    --orange: #b7791f;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    font-size: 14px;
    color: var(--texte);
    background: var(--fond);
}

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

/* --- Structure ------------------------------------------------------------ */

.entete {
    display: flex;
    align-items: center;
    gap: 28px;
    padding: 0 24px;
    height: 56px;
    background: #0d3b4c;
    color: #fff;
}
.entete .marque { font-weight: 700; font-size: 17px; letter-spacing: .5px; color: #fff; padding: 8px 12px; margin-left: -12px; border-radius: 6px; }
.entete .marque:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.entete .marque.actif { background: rgba(255,255,255,.15); }
.entete nav { display: flex; gap: 4px; flex: 1; }
.entete nav a {
    color: #cfe3ea;
    padding: 8px 12px;
    border-radius: 6px;
}
.entete nav a:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.entete nav a.actif { background: rgba(255,255,255,.15); color: #fff; }
.entete .utilisateur { display: flex; align-items: center; gap: 12px; color: #cfe3ea; }
.entete .utilisateur button {
    background: none; border: 1px solid rgba(255,255,255,.3); color: #fff;
    padding: 5px 10px; border-radius: 6px; cursor: pointer; font: inherit;
}

main { max-width: 1280px; margin: 0 auto; padding: 24px; }

h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
.sous-titre { color: var(--doux); margin: 0 0 20px; }

.titre-page { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.titre-page .sous-titre { margin: 0; }

.carte {
    background: var(--carte);
    border: 1px solid var(--bord);
    border-radius: 10px;
    padding: 18px 20px;
    margin-bottom: 20px;
}

.grille { display: grid; gap: 20px; }
.grille-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grille-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) { .grille-2, .grille-4 { grid-template-columns: 1fr; } }

/* --- Chiffres clés ---------------------------------------------------------- */

.chiffre { background: var(--carte); border: 1px solid var(--bord); border-radius: 10px; padding: 16px 18px; }
.chiffre .libelle { color: var(--doux); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.chiffre .valeur { font-size: 24px; font-weight: 600; margin-top: 6px; font-variant-numeric: tabular-nums; }
.chiffre .detail { font-size: 12px; margin-top: 4px; color: var(--doux); }
.hausse { color: var(--vert); }
.baisse { color: var(--rouge); }

/* --- Tableaux ------------------------------------------------------------- */

table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--bord); text-align: left; vertical-align: top; }
th { font-size: 12px; color: var(--doux); font-weight: 600; text-transform: uppercase; letter-spacing: .3px; background: #fafbfc; }
tbody tr:hover { background: #f8fafb; }
td.nombre, th.nombre { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tfoot td { font-weight: 600; background: #fafbfc; }
.carte table { margin: 0 -4px; width: calc(100% + 8px); }
.vide { color: var(--doux); text-align: center; padding: 28px; }

/* --- Formulaires -------------------------------------------------------- */

.filtres { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 16px; }
.filtres label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--doux); }
input, select {
    font: inherit; padding: 7px 10px; border: 1px solid #c9d1d9; border-radius: 6px; background: #fff; color: var(--texte);
}
input[type=search] { min-width: 280px; }
input:focus, select:focus { outline: 2px solid var(--accent-clair); border-color: var(--accent); }
.bouton {
    display: inline-block; font: inherit; padding: 7px 14px; border-radius: 6px; cursor: pointer;
    border: 1px solid var(--accent); background: var(--accent); color: #fff;
}
.bouton:hover { text-decoration: none; filter: brightness(1.08); }
.bouton.secondaire { background: #fff; color: var(--accent); }

/* --- Petits éléments ---------------------------------------------------- */

.etiquette { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; background: #eef1f4; color: var(--doux); }
.etiquette.paye { background: #e4f4ea; color: var(--vert); }
.etiquette.encours { background: #fdf3e1; color: var(--orange); }
.etiquette.annule { background: #fbe9e7; color: var(--rouge); }
.code { font-family: Consolas, monospace; font-size: 13px; color: var(--doux); }
.onglets { display: flex; gap: 6px; margin-bottom: 14px; }
.onglets a { padding: 6px 12px; border-radius: 6px; border: 1px solid var(--bord); background: #fff; }
.onglets a.actif { background: var(--accent); color: #fff; border-color: var(--accent); }

dl.fiche { display: grid; grid-template-columns: 160px 1fr; gap: 6px 12px; margin: 0; }
dl.fiche dt { color: var(--doux); }
dl.fiche dd { margin: 0; }

.totaux { margin-left: auto; width: 340px; }
.totaux td { border: none; padding: 4px 10px; }
.totaux tr.final td { font-size: 16px; font-weight: 700; border-top: 2px solid var(--texte); }

/* Histogramme du chiffre d'affaires mensuel */
.histogramme { display: flex; align-items: flex-end; gap: 8px; height: 180px; padding-top: 10px; }
.histogramme .barre { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.histogramme .barre div { width: 100%; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; }
a.barre:hover { text-decoration: none; }
a.barre:hover div { background: #0d8fb3; }
.histogramme .barre span { font-size: 11px; color: var(--doux); margin-top: 4px; }

.pagination { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; color: var(--doux); }
.pagination .liens { display: flex; gap: 6px; }
.pagination .liens span { padding: 6px 12px; border: 1px solid var(--bord); border-radius: 6px; color: #b0b8c1; }

.alerte { padding: 10px 14px; border-radius: 6px; background: #fbe9e7; color: var(--rouge); margin-bottom: 14px; }

/* --- Connexion ---------------------------------------------------------- */

.page-connexion { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: #0d3b4c; }
.page-connexion form { width: 360px; background: #fff; border-radius: 12px; padding: 32px; }
.page-connexion h1 { text-align: center; margin-bottom: 4px; }
.page-connexion p { text-align: center; color: var(--doux); margin-top: 0; }
.page-connexion label { display: block; margin: 14px 0 4px; font-size: 13px; color: var(--doux); }
.page-connexion input[type=email], .page-connexion input[type=password] { width: 100%; }
.page-connexion .bouton { width: 100%; margin-top: 20px; padding: 10px; }
.page-connexion .souvenir { display: flex; align-items: center; gap: 6px; }

/* --- Saisie des documents ------------------------------------------------ */

.champs { display: grid; grid-template-columns: 2fr 160px 1fr 1fr; gap: 14px; }
.champs label, label.bloc { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--doux); }
.champs input, .champs select { width: 100%; font-size: 14px; color: var(--texte); }
@media (max-width: 900px) { .champs { grid-template-columns: 1fr; } }
.info-client { margin: 10px 0 0; font-size: 13px; color: var(--doux); min-height: 1em; }
.alerte-texte { color: var(--rouge); }
label.case { display: flex; align-items: center; gap: 8px; margin-top: 14px; }

table.saisie td { padding: 4px; border-bottom: 1px solid var(--bord); vertical-align: middle; }
table.saisie input, table.saisie select { width: 100%; padding: 6px 8px; }
table.saisie input.nombre { text-align: right; }
table.saisie .total-ligne { font-weight: 600; }
button.supprimer { background: none; border: none; color: #b0b8c1; cursor: pointer; font-size: 15px; padding: 4px 8px; }
button.supprimer:hover { color: var(--rouge); }

.message { padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; }
.message.succes { background: #e4f4ea; color: var(--vert); }
.message.erreur { background: #fbe9e7; color: var(--rouge); }

.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.bouton.danger { background: #fff; color: var(--rouge); border-color: #e3b5af; }

.champs-article { grid-template-columns: repeat(4, 1fr); }
.champs-article .large { grid-column: span 2; }
.champs input.nombre { text-align: right; }
.champs-paiement { grid-template-columns: 1fr 1fr 160px 1fr 1fr 160px; }
@media (max-width: 1100px) { .champs-paiement { grid-template-columns: 1fr 1fr 1fr; } }
.bouton.petit { padding: 3px 9px; font-size: 12px; }
.actions-ligne { display: flex; gap: 6px; align-items: center; justify-content: flex-end; }
.actions-ligne form { display: flex; gap: 4px; align-items: center; margin: 0; }
.actions-ligne input[type=date] { padding: 2px 4px; font-size: 12px; }
tr.en-retard td { background: #fdf3e1; }
.alerte-orange { color: var(--orange); }
.peremption { font-size: 12px; margin-top: 2px; min-height: 0; }
.peremption:empty { display: none; }
table.saisie select:disabled { color: #b0b8c1; }

/* --- Articles regroupés par marque et par famille ------------------------- */

table.table-groupee tr.entete-groupe td {
    background: #0d3b4c; color: #fff; font-weight: 700; letter-spacing: .5px; padding: 8px 10px;
}
table.table-groupee tr.entete-groupe a { color: #fff; }
table.table-groupee tr.entete-famille td {
    background: var(--accent-clair); color: var(--accent); font-weight: 600; padding: 6px 10px 6px 22px;
}
.marques { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 16px; }
.marque h2 { display: flex; justify-content: space-between; align-items: baseline; }
.marque table td { padding: 5px 6px; }
.marque select, .marque input { font-size: 12px; padding: 3px 6px; }

.arbre-familles { display: flex; flex-direction: column; gap: 10px; }
details.famille-mere { background: var(--carte); border: 1px solid var(--bord); border-radius: 10px; overflow: hidden; }
details.famille-mere summary {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    padding: 14px 18px; cursor: pointer; list-style: none; font-size: 15px;
}
details.famille-mere summary::-webkit-details-marker { display: none; }
details.famille-mere summary::before { content: '▸'; color: var(--accent); margin-right: 4px; transition: transform .15s; }
details.famille-mere[open] summary::before { transform: rotate(90deg); }
details.famille-mere summary:hover { background: #f8fafb; }
details.famille-mere .nom-marque { flex: 1; font-weight: 700; color: #0d3b4c; letter-spacing: .5px; }
details.famille-mere .compte { color: var(--doux); font-size: 13px; }
details.famille-mere ul { list-style: none; margin: 0; padding: 0 0 8px; border-top: 1px solid var(--bord); }
details.famille-mere li { display: flex; justify-content: space-between; padding: 8px 18px 8px 44px; border-bottom: 1px solid #f0f2f4; }
details.famille-mere li:last-child { border-bottom: none; }
details.famille-mere li:hover { background: #f8fafb; }
details.famille-mere li.toute-la-marque a { font-weight: 600; }
.entete .utilisateur a.lien-reglages { color: #cfe3ea; font-size: 18px; padding: 2px 8px; border-radius: 6px; text-decoration: none; }
.entete .utilisateur a.lien-reglages:hover, .entete .utilisateur a.lien-reglages.actif { background: rgba(255,255,255,.15); color: #fff; }

/* --- Réglages : listes à réordonner --------------------------------------- */

.liste-ordre { list-style: none; margin: 0; padding: 0; }
.liste-ordre li { border: 1px solid var(--bord); border-radius: 8px; margin-bottom: 6px; background: #fff; }
.liste-ordre > li:not(.marque-ordre), .ligne-marque { display: flex; align-items: center; gap: 10px; padding: 8px 10px; }
.liste-ordre li.glisse { opacity: .4; }
.liste-ordre li.deplace { background: var(--accent-clair); }
.liste-ordre .poignee { cursor: grab; color: #9aa4ae; font-size: 16px; }
.liste-ordre .libelle { flex: 1; }
.liste-ordre .fleches button, .liste-ordre .deplier {
    background: none; border: 1px solid var(--bord); border-radius: 5px; cursor: pointer; padding: 2px 7px; margin-left: 3px; color: var(--accent);
}
.liste-ordre .fleches button:hover, .liste-ordre .deplier:hover { background: var(--accent-clair); }
.liste-ordre .deplier { font-size: 12px; }
.sous-liste { margin: 0 10px 10px 34px !important; }
.sous-liste li { background: #fafbfc; }

/* --- TEJ ------------------------------------------------------------------ */

.bouton-tej { background: #b3261e; border-color: #b3261e; padding: 10px 18px; font-weight: 600; }
.entete nav a.lien-tej { background: rgba(179, 38, 30, .85); color: #fff; font-weight: 600; }
.entete nav a.lien-tej.actif, .entete nav a.lien-tej:hover { background: #b3261e; }
.etapes-tej ol { margin: 0 0 14px; padding-left: 20px; line-height: 1.8; }
.depot-tej { display: flex; gap: 12px; align-items: stretch; }
.zone-depot {
    flex: 1; display: flex; align-items: center; justify-content: center; padding: 18px; cursor: pointer;
    border: 2px dashed #c9d1d9; border-radius: 10px; color: var(--doux); background: #fafbfc; text-align: center;
}
.zone-depot.survol { border-color: var(--accent); background: var(--accent-clair); }
.zone-depot input { display: none; }
.cellule-rapprochement { min-width: 280px; }
.action-tej { display: flex; gap: 6px; margin-top: 6px; align-items: center; }
.action-tej select, .action-tej input { font-size: 12px; padding: 4px 6px; max-width: 260px; }
.lien-bouton { background: none; border: none; padding: 0; color: var(--accent); cursor: pointer; font: inherit; font-size: 12px; text-decoration: underline; }
.lien-bouton.discret { color: #9aa4ae; }

/* --- Assistant IA --------------------------------------------------------- */

.assistant-bouton {
    position: fixed; left: 20px; bottom: 20px; z-index: 1000;
    display: flex; align-items: center; gap: 6px;
    padding: 12px 16px; border: none; border-radius: 30px; cursor: pointer;
    background: linear-gradient(135deg, #0b6e8a, #6b3fa0); color: #fff;
    font: 600 15px "Segoe UI", sans-serif; box-shadow: 0 6px 18px rgba(13, 59, 76, .35);
}
.assistant-bouton:hover { filter: brightness(1.1); }
.assistant-bouton.actif { box-shadow: 0 0 0 3px #fff, 0 6px 18px rgba(13, 59, 76, .35); }

.assistant-fenetre {
    position: fixed; left: 20px; bottom: 84px; z-index: 1000;
    width: min(460px, calc(100vw - 40px)); height: min(640px, calc(100vh - 110px));
    display: flex; flex-direction: column;
    background: #fff; border-radius: 14px; box-shadow: 0 12px 40px rgba(0, 0, 0, .25); overflow: hidden;
}
.assistant-fenetre[hidden] { display: none; }
.assistant-fenetre header {
    display: flex; justify-content: space-between; align-items: center; padding: 12px 14px;
    background: linear-gradient(135deg, #0b6e8a, #6b3fa0); color: #fff;
}
.assistant-fenetre header small { display: block; opacity: .85; font-size: 12px; }
.assistant-entete-boutons button { background: none; border: none; color: #fff; font-size: 17px; cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.assistant-entete-boutons button:hover { background: rgba(255, 255, 255, .15); }

.assistant-messages { flex: 1; overflow-y: auto; padding: 14px; background: #f6f8fa; }
.assistant-accueil p { color: var(--doux); margin-top: 0; }
.assistant-suggestions { display: flex; flex-direction: column; gap: 6px; }
.assistant-suggestions button {
    text-align: left; font: inherit; font-size: 13px; padding: 8px 10px; cursor: pointer;
    border: 1px solid var(--bord); border-radius: 8px; background: #fff; color: var(--accent);
}
.assistant-suggestions button:hover { border-color: var(--accent); }

.assistant-message { margin-bottom: 10px; padding: 9px 12px; border-radius: 10px; line-height: 1.5; max-width: 92%; overflow-x: auto; }
.assistant-message.utilisateur { background: var(--accent); color: #fff; margin-left: auto; white-space: pre-wrap; }
.assistant-message.assistant { background: #fff; border: 1px solid var(--bord); }
.assistant-message.erreur { border-color: #e3b5af; background: #fdf3f2; }
.assistant-message p { margin: 0 0 8px; }
.assistant-message p:last-child { margin-bottom: 0; }
.assistant-message ul, .assistant-message ol { margin: 4px 0 8px; padding-left: 20px; }
.assistant-message table { font-size: 12px; margin: 6px 0; width: auto; }
.assistant-message th, .assistant-message td { padding: 4px 6px; }
.assistant-message code { background: #eef1f4; padding: 1px 4px; border-radius: 4px; }
.assistant-joint { font-size: 12px; opacity: .85; margin-top: 4px; }
.assistant-message.attente { color: var(--doux); }
.points i { display: inline-block; width: 6px; height: 6px; margin-right: 3px; border-radius: 50%; background: var(--accent); animation: points 1s infinite; }
.points i:nth-child(2) { animation-delay: .15s; }
.points i:nth-child(3) { animation-delay: .3s; }
@keyframes points { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.assistant-formulaire { border-top: 1px solid var(--bord); padding: 10px; background: #fff; }
.assistant-saisie { display: flex; gap: 8px; align-items: flex-end; }
.assistant-saisie textarea { flex: 1; resize: none; font: inherit; padding: 8px 10px; border: 1px solid #c9d1d9; border-radius: 8px; }
.assistant-joindre { cursor: pointer; font-size: 20px; padding: 6px; }
.assistant-piece { font-size: 12px; margin-bottom: 6px; color: var(--doux); }
.assistant-piece button { background: none; border: none; cursor: pointer; color: var(--rouge); }
.assistant-avertissement { margin: 6px 0 0; font-size: 11px; color: #9aa4ae; text-align: center; }

.message.brouillon-ia { background: #f1ecf8; color: #4b2a78; border: 1px solid #d9cbee; }

@media print {
    .entete, .filtres, .pagination, .ne-pas-imprimer { display: none !important; }
    body { background: #fff; }
    main { padding: 0; max-width: none; }
    .carte { border: none; padding: 0; }
}

/* Comptes des utilisateurs */
.entete .utilisateur a.lien-compte { color: #cfe3ea; padding: 4px 8px; border-radius: 6px; text-decoration: none; }
.entete .utilisateur a.lien-compte:hover, .entete .utilisateur a.lien-compte.actif { background: rgba(255,255,255,.15); color: #fff; }
tr.ligne-inactive td { color: var(--doux); }
