:root {
  --fond: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --bord: #e2e6ee;
  --texte: #1b2333;
  --texte-2: #4d586b;
  --texte-3: #7b8597;
  --primaire: #1d5fd1;
  --primaire-fonce: #174ca8;
  --primaire-doux: #e8effc;
  --barre: #2a6fe0;
  --danger: #c62828;
  --danger-doux: #fdecec;
  --ok: #1e7d43;
  --interne: #fff7e0;
  --interne-bord: #f0c44c;
  --nav: #13213d;
  --nav-texte: #c4cde0;
  --ombre: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --rayon: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fond: #0f1420;
    --surface: #171e2d;
    --surface-2: #1c2436;
    --bord: #2a3448;
    --texte: #e6eaf2;
    --texte-2: #b3bccd;
    --texte-3: #8691a6;
    --primaire: #5b8ff0;
    --primaire-fonce: #79a3f3;
    --primaire-doux: #1d2a45;
    --barre: #5b8ff0;
    --danger: #f07171;
    --danger-doux: #3a1d22;
    --ok: #57c285;
    --interne: #2e2814;
    --interne-bord: #8a6d1c;
    --nav: #0b101b;
    --ombre: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 14px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background: var(--fond);
  color: var(--texte);
}
a { color: var(--primaire); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0; font-weight: 600; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; }
.muted { color: var(--texte-3); }
.petit { font-size: 12px; }

/* ---------- mise en page */
.cadre { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.nav { background: var(--nav); color: var(--nav-texte); padding: 18px 12px; display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100vh; }
.marque { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 17px; padding: 0 8px 18px; }
.marque img { width: 30px; height: 30px; }
.nav a { color: var(--nav-texte); padding: 8px 12px; border-radius: 8px; display: flex; gap: 10px; align-items: center; }
.nav a:hover { background: rgba(255, 255, 255, .07); text-decoration: none; color: #fff; }
.nav a.actif { background: rgba(91, 143, 240, .22); color: #fff; }
.nav .section { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #7d89a3; padding: 14px 12px 4px; }
.nav .bas { margin-top: auto; border-top: 1px solid rgba(255, 255, 255, .08); padding-top: 12px; }
.nav .qui { padding: 0 12px 8px; font-size: 13px; }
.nav .qui b { color: #fff; display: block; }
.principal { padding: 24px 28px 40px; min-width: 0; }
.entete { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.entete .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.burger { display: none; }

@media (max-width: 860px) {
  .cadre { grid-template-columns: 1fr; }
  .nav { position: fixed; inset: 0 auto 0 0; width: 240px; z-index: 20; transform: translateX(-100%); transition: transform .2s; }
  .nav.ouvert { transform: none; }
  .burger { display: inline-flex; }
  .principal { padding: 16px; }
}

/* ---------- composants */
.carte { background: var(--surface); border: 1px solid var(--bord); border-radius: var(--rayon); box-shadow: var(--ombre); padding: 18px; }
.carte + .carte { margin-top: 16px; }
.grille > .carte + .carte { margin-top: 0; }
.grille { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

button, .bouton {
  font: inherit; border: 1px solid var(--bord); background: var(--surface); color: var(--texte);
  padding: 7px 14px; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
button:hover, .bouton:hover { border-color: var(--texte-3); text-decoration: none; }
button.primaire, .bouton.primaire { background: var(--primaire); border-color: var(--primaire); color: #fff; }
button.primaire:hover { background: var(--primaire-fonce); }
button.danger { color: var(--danger); }
button:disabled { opacity: .55; cursor: default; }
button.lien { border: none; background: none; color: var(--primaire); padding: 0; }

label { display: block; font-size: 12px; font-weight: 600; color: var(--texte-2); margin-bottom: 4px; }
input, select, textarea {
  font: inherit; width: 100%; padding: 8px 10px; border: 1px solid var(--bord); border-radius: 8px;
  background: var(--surface); color: var(--texte);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primaire-doux); border-color: var(--primaire); }
textarea { min-height: 110px; resize: vertical; }
input[type=checkbox] { width: auto; }
.champ { margin-bottom: 14px; }
.ligne-champs { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.case { display: inline-flex; align-items: center; gap: 6px; font-weight: 400; font-size: 13px; color: var(--texte); margin: 0; }

.filtres { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.filtres > * { width: auto; min-width: 150px; }
.filtres input[type=search] { flex: 1; min-width: 200px; }

.table-zone { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--texte-3); padding: 8px 10px; border-bottom: 1px solid var(--bord); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--bord); vertical-align: middle; }
tr.cliquable { cursor: pointer; }
tr.cliquable:hover td { background: var(--surface-2); }
td.titre { font-weight: 500; max-width: 380px; min-width: 180px; }
td:first-child { white-space: nowrap; }
.vide { text-align: center; padding: 40px; color: var(--texte-3); }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; border: 1px solid transparent; }
.st-ouvert { background: #e3edfd; color: #1a4fa8; }
.st-en-cours { background: #ece7fb; color: #5232a8; }
.st-en-attente-client { background: #fdf1d8; color: #8a5a00; }
.st-resolu { background: #e0f4e7; color: #1c6b3b; }
.st-ferme { background: #eceef2; color: #4d586b; }
.pr-basse { background: transparent; border-color: var(--bord); color: var(--texte-2); }
.pr-normale { background: transparent; border-color: #9bb8ec; color: #1a4fa8; }
.pr-haute { background: #fdebd9; color: #9a4a00; }
.pr-urgente { background: #fde2e2; color: #a61b1b; }
@media (prefers-color-scheme: dark) {
  .st-ouvert { background: #1f3460; color: #a9c5fa; }
  .st-en-cours { background: #33285c; color: #c8b9fb; }
  .st-en-attente-client { background: #4a3810; color: #f4cf7d; }
  .st-resolu { background: #17402a; color: #8fdcab; }
  .st-ferme { background: #2a3142; color: #b3bccd; }
  .pr-normale { border-color: #3d5d98; color: #a9c5fa; }
  .pr-haute { background: #4a2b10; color: #f7b67a; }
  .pr-urgente { background: #4d1c1c; color: #f5a3a3; }
}
.retard { color: var(--danger); font-weight: 600; }

/* ---------- tableau de bord */
.tuiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; margin-bottom: 16px; }
.tuile { background: var(--surface); border: 1px solid var(--bord); border-radius: var(--rayon); padding: 14px 16px; box-shadow: var(--ombre); display: block; color: inherit; }
a.tuile:hover { text-decoration: none; border-color: var(--primaire); }
.tuile .lib { font-size: 12px; color: var(--texte-3); font-weight: 600; }
.tuile .val { font-size: 28px; font-weight: 600; line-height: 1.2; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tuile .val.alerte { color: var(--danger); }
.tuile .sous { font-size: 12px; color: var(--texte-3); }

.histo { position: relative; display: flex; align-items: flex-end; gap: 6px; height: 170px; padding: 0 2px; border-bottom: 1px solid var(--bord); }
.histo .col { flex: 1; height: 100%; display: flex; align-items: flex-end; justify-content: center; position: relative; cursor: default; }
.histo .col:hover { background: var(--surface-2); border-radius: 4px 4px 0 0; }
.histo .barre { width: 70%; max-width: 26px; background: var(--barre); border-radius: 4px 4px 0 0; min-height: 0; }
.histo .col:hover .barre { filter: brightness(1.12); }
.histo-axe { display: flex; gap: 6px; padding: 4px 2px 0; }
.histo-axe span { flex: 1; text-align: center; font-size: 11px; color: var(--texte-3); }
.infobulle { position: absolute; bottom: calc(100% + 4px); left: 50%; transform: translateX(-50%); background: var(--texte); color: var(--surface); font-size: 12px; padding: 4px 8px; border-radius: 6px; white-space: nowrap; pointer-events: none; display: none; z-index: 2; }
.histo .col:hover .infobulle { display: block; }
.liste-compteurs { list-style: none; margin: 0; padding: 0; }
.liste-compteurs li { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--bord); }
.liste-compteurs li:last-child { border-bottom: none; }
.liste-compteurs b { font-variant-numeric: tabular-nums; }

/* ---------- ticket */
.ticket-grille { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
@media (max-width: 1050px) { .ticket-grille { grid-template-columns: 1fr; } }
.fil { display: flex; flex-direction: column; gap: 12px; }
.message { border: 1px solid var(--bord); border-radius: var(--rayon); padding: 12px 14px; background: var(--surface); }
.message.support { border-left: 3px solid var(--primaire); }
.message.interne { background: var(--interne); border-color: var(--interne-bord); }
.message .meta { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; color: var(--texte-3); margin-bottom: 6px; flex-wrap: wrap; }
.message .meta b { color: var(--texte); }
.corps { white-space: pre-wrap; word-wrap: break-word; }
.pieces { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.piece { font-size: 12px; border: 1px solid var(--bord); border-radius: 6px; padding: 3px 8px; background: var(--surface-2); }
.proprietes .champ { margin-bottom: 12px; }
.proprietes dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 13px; }
.proprietes dt { color: var(--texte-3); }
.proprietes dd { margin: 0; text-align: right; }
.histo-liste { list-style: none; padding: 0; margin: 0; font-size: 12px; }
.histo-liste li { padding: 6px 0; border-bottom: 1px dashed var(--bord); }
.etoiles { display: flex; gap: 4px; }
.etoiles button { font-size: 20px; padding: 2px 6px; color: #d0a000; }
.boutons-reponse { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; align-items: center; margin-top: 10px; }
.boutons-reponse .case { margin-right: auto; }

/* ---------- FAQ */
details.faq { border: 1px solid var(--bord); border-radius: var(--rayon); background: var(--surface); margin-bottom: 8px; }
details.faq summary { cursor: pointer; padding: 12px 14px; font-weight: 500; display: flex; justify-content: space-between; gap: 10px; }
details.faq .contenu { padding: 0 14px 14px; }

/* ---------- connexion */
.connexion { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(135deg, #13213d, #1d5fd1); }
.connexion .carte { width: 100%; max-width: 380px; padding: 28px; }
.connexion .marque { color: var(--texte); padding: 0 0 18px; justify-content: center; font-size: 20px; }
.erreur { background: var(--danger-doux); color: var(--danger); padding: 8px 12px; border-radius: 8px; margin-bottom: 12px; font-size: 13px; }

#toasts { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: var(--texte); color: var(--surface); padding: 10px 16px; border-radius: 8px; box-shadow: 0 4px 14px rgba(0, 0, 0, .2); max-width: 360px; }
.toast.err { background: var(--danger); color: #fff; }
.chargement { padding: 40px; text-align: center; color: var(--texte-3); }
