/* Gégé Trading : thème sombre par défaut, clair si le système le demande */

:root {
  color-scheme: dark;
  --bg: #0e1116;
  --surface: #161b22;
  --surface-2: #1d232c;
  --border: #2a313c;
  --text: #e8ebef;
  --muted: #8d96a3;
  --accent: #338ced;
  --accent-texte: #ffffff;
  --pos: #2fbf55;
  --neg: #f0565a;
  --attention: #fbb315;
  --grille: #262d37;
  --radius: 12px;
  --ombre: 0 8px 30px rgb(0 0 0 / 0.35);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f4f6f9;
    --surface: #ffffff;
    --surface-2: #f0f2f5;
    --border: #dde1e7;
    --text: #191c21;
    --muted: #626b77;
    --accent: #1f6fd1;
    --pos: #0a8a20;
    --neg: #d4282e;
    --attention: #b87800;
    --grille: #e9ecf0;
    --ombre: 0 8px 30px rgb(0 0 0 / 0.12);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 0.8rem; }
h3 { font-size: 1rem; margin: 0; }
.muted { color: var(--muted); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.error { color: var(--neg); background: color-mix(in srgb, var(--neg) 12%, transparent); padding: 0.6rem 0.8rem; border-radius: 8px; }
[hidden] { display: none !important; }

/* ---------- En-tête ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.75rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { font-weight: 800; font-size: 1.15rem; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 0.25rem; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav a { color: var(--muted); padding: 0.4rem 0.75rem; border-radius: 8px; white-space: nowrap; }
.nav a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.nav a.active { color: var(--text); background: var(--surface-2); font-weight: 600; }
.user { display: flex; align-items: center; gap: 1rem; font-size: 0.85rem; color: var(--muted); white-space: nowrap; }

main { width: 100%; max-width: 1280px; margin: 0 auto; padding: 1.5rem; flex: 1; }
.pied { text-align: center; padding: 1rem; font-size: 0.85rem; }
.pied a { color: var(--muted); }

/* ---------- Boutons ---------- */

.btn, .btn-link {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.35rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
.btn-link { padding: 0.3rem 0.7rem; font-size: 0.85rem; }
.btn:hover, .btn-link:hover { border-color: var(--muted); text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-principal { background: var(--accent); border-color: var(--accent); color: var(--accent-texte); }
.btn-principal:hover { filter: brightness(1.1); border-color: var(--accent); }
.btn-danger { color: var(--neg); border-color: color-mix(in srgb, var(--neg) 50%, var(--border)); }
.btn-petit { padding: 0 0.6rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); color: var(--text); cursor: pointer; font: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Mise en page ---------- */

.entete-page { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.boutons { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.carte {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  margin-bottom: 1rem;
  min-width: 0;
}
.carte.vide { text-align: center; padding: 2.5rem 1rem; }
.titre-section { margin: 1.5rem 0 0.8rem; }
.deux-colonnes { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.deux-colonnes > .carte { margin-bottom: 0; }
.deux-colonnes { margin-bottom: 1rem; }
.grille-analyses { display: grid; grid-template-columns: repeat(auto-fit, minmax(460px, 1fr)); gap: 1rem; }
.grille-analyses > .carte { margin-bottom: 0; }
.lien-suite { display: inline-block; margin-top: 0.8rem; font-size: 0.9rem; }
.aide { color: var(--muted); font-size: 0.85rem; margin: -0.4rem 0 0.8rem; }
.resume-liste { color: var(--muted); margin: 0.2rem 0 0.8rem; }

.accueil { max-width: 640px; margin: 3rem auto; text-align: center; padding: 2rem; }
.accueil h2 { font-size: 1.4rem; }
.accueil p { color: var(--muted); margin-bottom: 1.5rem; }

/* ---------- Filtres ---------- */

.ligne-filtres { display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 0.5rem; }
.ligne-filtres .filtres { margin-bottom: 0; }
.filtres { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 1rem; }
.filtres label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.78rem; color: var(--muted); }

input, select, textarea {
  font: inherit;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
  min-width: 0;
  width: 100%;
}
.filtres select, .filtres input { width: auto; min-width: 170px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
textarea { resize: vertical; }

/* ---------- Tuiles de chiffres clés ---------- */

.tuiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0.75rem; margin-bottom: 1rem; }
.tuile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  display: flex; flex-direction: column; gap: 0.2rem;
}
.tuile[title] { cursor: help; }
.tuile-libelle { font-size: 0.8rem; color: var(--muted); }
.tuile-valeur { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.tuile-detail { font-size: 0.8rem; color: var(--muted); }

/* ---------- Cartes de comptes ---------- */

.grille-comptes { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.grille-comptes > .carte { margin-bottom: 0; }
.carte-compte { cursor: pointer; border-left: 4px solid var(--pos); transition: border-color 0.15s; }
.carte-compte:hover { border-color: var(--muted); }
.carte-compte.alerte-attention { border-left-color: var(--attention); }
.carte-compte.alerte-danger { border-left-color: var(--neg); }
.carte-compte.termine { border-left-color: var(--border); opacity: 0.85; }
.carte-compte header { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.5rem; margin-bottom: 0.8rem; }
.carte-compte header .muted { font-size: 0.85rem; }
.badge-alerte { font-size: 0.78rem; padding: 0.2rem 0.55rem; border-radius: 99px; background: var(--surface-2); white-space: nowrap; }
.chiffres-compte { display: flex; flex-wrap: wrap; gap: 0.5rem 1.5rem; margin-bottom: 0.9rem; }
.chiffres-compte div { display: flex; flex-direction: column; min-width: 0; }
.chiffres-compte .peut-perdre { flex-basis: 100%; flex-direction: row; align-items: baseline; gap: 0.5rem;
  padding: 0.45rem 0.65rem; background: var(--surface-2); border-radius: 8px; }
.chiffres-compte .peut-perdre span { font-size: 0.85rem; }
.chiffres-compte span { font-size: 0.78rem; }
.chiffres-compte b { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.details-compte { display: flex; flex-wrap: wrap; gap: 0.4rem 1rem; font-size: 0.85rem; color: var(--muted); margin-top: 0.6rem; }
.violations { margin: 0.6rem 0 0; padding: 0; list-style: none; font-size: 0.85rem; color: var(--neg); }
.pied-carte { font-size: 0.78rem; margin-top: 0.6rem; }

.jauge { margin-bottom: 0.55rem; }
.jauge-texte { display: flex; justify-content: space-between; gap: 0.5rem; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.25rem; flex-wrap: wrap; }
.jauge-texte span:first-child { color: var(--text); }
.jauge-barre { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.jauge-barre i { display: block; height: 100%; border-radius: 99px; background: var(--pos); }
.jauge-attention .jauge-barre i { background: var(--attention); }
.jauge-danger .jauge-barre i { background: var(--neg); }
.jauge-objectif .jauge-barre i { background: var(--accent); }

.statut { font-size: 0.78rem; padding: 0.15rem 0.55rem; border-radius: 99px; background: var(--surface-2); white-space: nowrap; }
.statut-reussi { color: var(--pos); }
.statut-echoue { color: var(--neg); }

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

.table-defile { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th { text-align: left; font-weight: 500; font-size: 0.78rem; color: var(--muted); padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th.num { text-align: right; }
.table td { padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--grille); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.cliquable { cursor: pointer; }
.cliquable:hover td { background: var(--surface-2); }
.sens { font-size: 0.8rem; font-weight: 600; white-space: nowrap; }
.sens-long { color: var(--pos); }
.sens-short { color: var(--neg); }
.erreur-tag { font-size: 0.75rem; color: var(--attention); white-space: nowrap; }
.etoiles-lecture { color: var(--attention); white-space: nowrap; letter-spacing: -1px; }

.table-analyse td:first-child { white-space: nowrap; }
.b-pos { fill: var(--pos); background: var(--pos); }
.b-neg { fill: var(--neg); background: var(--neg); }

/* ---------- Points clés ---------- */

.points-cles { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.6rem; }
.points-cles li { display: flex; gap: 0.7rem; align-items: flex-start; padding: 0.6rem 0.75rem; background: var(--surface-2); border-radius: 8px; }
.points-cles li > span { font-size: 1.15rem; line-height: 1.3; }

/* ---------- Graphiques ---------- */

.graph { position: relative; min-height: 260px; }
.graph svg { display: block; overflow: visible; }
.vide-graph { padding: 4rem 0; text-align: center; }
.grille { stroke: var(--grille); stroke-width: 1; }
.grille.zero { stroke: var(--muted); stroke-opacity: 0.6; }
.axe { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.ligne-solde { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.aire-solde { fill: var(--accent); fill-opacity: 0.08; }
.ligne-plancher { fill: none; stroke: var(--neg); stroke-width: 1.5; stroke-dasharray: 5 4; }
.ligne-objectif { stroke: var(--pos); stroke-width: 1.5; stroke-dasharray: 5 4; }
.curseur { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.curseur[hidden], .point-curseur[hidden] { display: none; }
.point-curseur { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.zone { fill: transparent; cursor: crosshair; touch-action: pan-y; }
.barre { transition: opacity 0.1s; }
.barre.estompe { opacity: 0.35; }
.legende { display: flex; gap: 1rem; flex-wrap: wrap; font-size: 0.8rem; color: var(--muted); margin-top: 0.4rem; }
.legende i { display: inline-block; width: 16px; height: 0; border-top: 2px solid; vertical-align: middle; margin-right: 0.35rem; }
.cle-solde { border-color: var(--accent) !important; }
.cle-plancher { border-color: var(--neg) !important; border-top-style: dashed !important; }
.cle-objectif { border-color: var(--pos) !important; border-top-style: dashed !important; }
.tip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 0.45rem 0.65rem; font-size: 0.8rem; box-shadow: var(--ombre); white-space: nowrap;
}

/* ---------- Calendrier ---------- */

.nav-mois { display: flex; align-items: center; justify-content: center; gap: 1rem; margin-bottom: 0.5rem; }
.nav-mois h2 { margin: 0; min-width: 180px; text-align: center; text-transform: capitalize; }
.nav-mois + .resume-liste { text-align: center; }
.calendrier { width: 100%; border-collapse: separate; border-spacing: 4px; table-layout: fixed; min-width: 640px; }
.calendrier th { font-size: 0.78rem; color: var(--muted); font-weight: 500; padding: 0.2rem; }
.calendrier td { height: 78px; background: var(--surface-2); border-radius: 8px; vertical-align: top; padding: 0; }
.calendrier td.hors-mois { background: transparent; }
.calendrier td > div, .calendrier td > button {
  display: flex; flex-direction: column; width: 100%; height: 100%; padding: 0.35rem 0.45rem;
  background: none; border: 0; color: inherit; font: inherit; text-align: left; border-radius: 8px;
}
.calendrier td > button { cursor: pointer; }
.calendrier td > button:hover { box-shadow: inset 0 0 0 1px var(--muted); }
.calendrier .num-jour { font-size: 0.75rem; color: var(--muted); }
.calendrier b { font-size: 0.88rem; margin-top: auto; font-variant-numeric: tabular-nums; }
.calendrier small { font-size: 0.72rem; color: var(--muted); }
.calendrier .jour-pos { background: color-mix(in srgb, var(--pos) calc(var(--intensite) * 100%), var(--surface-2)); }
.calendrier .jour-neg { background: color-mix(in srgb, var(--neg) calc(var(--intensite) * 100%), var(--surface-2)); }
.calendrier .jour-pos b, .calendrier .jour-neg b, .calendrier .jour-pos .num-jour, .calendrier .jour-neg .num-jour,
.calendrier .jour-pos small, .calendrier .jour-neg small { color: var(--text); }
.calendrier .aujourdhui { box-shadow: inset 0 0 0 2px var(--accent); }
.calendrier .choisi { box-shadow: inset 0 0 0 2px var(--text); }
.calendrier .total-semaine { background: transparent; text-align: right; vertical-align: middle; padding-right: 0.3rem; }

/* ---------- Fenêtre de dialogue et formulaires ---------- */

.dialogue {
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--ombre);
}
.dialogue.large { width: min(860px, calc(100vw - 24px)); }
.dialogue::backdrop { background: rgb(0 0 0 / 0.55); }
.dialogue-tete {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.9rem 1.2rem; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--surface); z-index: 2;
}
.dialogue-tete h2 { margin: 0; }
.fermer { background: none; border: 0; color: var(--muted); font-size: 1.1rem; cursor: pointer; padding: 0.3rem 0.5rem; border-radius: 6px; }
.fermer:hover { color: var(--text); background: var(--surface-2); }
.dialogue-corps { padding: 1rem 1.2rem 1.2rem; }

fieldset { border: 1px solid var(--border); border-radius: 10px; padding: 0.8rem 1rem 1rem; margin: 0 0 1rem; min-width: 0; }
legend { padding: 0 0.4rem; font-weight: 600; }
legend small { font-weight: 400; }
.grille-champs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.75rem; }
.grille-champs .large2 { grid-column: span 2; }
.grille-champs .pleine { grid-column: 1 / -1; }
.grille-champs label, .champ, label.pleine { display: block; font-size: 0.82rem; color: var(--muted); }
.grille-champs label > :is(input, select, textarea, .avec-bouton), label.pleine > :is(input, textarea),
.champ > :is(.bascule, .etoiles, .puces) { margin-top: 0.25rem; }
.grille-champs label > :is(input, select, textarea), label.pleine > :is(input, textarea) { display: block; }
label.pleine { margin-bottom: 0.75rem; }
label small, .champ small { font-size: 0.75rem; cursor: help; }
.avec-bouton { display: flex; gap: 0.35rem; }
.resume-calc { margin: 0.8rem 0 0; font-size: 0.88rem; color: var(--muted); min-height: 1.3em; }
.resume-calc b { color: var(--text); }
.resume-calc b.pos { color: var(--pos); }
.resume-calc b.neg { color: var(--neg); }

.bascule { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.bascule label { flex: 1; display: flex; align-items: center; justify-content: center; padding: 0.5rem; cursor: pointer; color: var(--text); font-size: 0.9rem; }
.bascule label + label { border-left: 1px solid var(--border); }
.bascule input { position: absolute; opacity: 0; pointer-events: none; }
.bascule .b-long:has(input:checked) { background: color-mix(in srgb, var(--pos) 25%, transparent); color: var(--pos); font-weight: 600; }
.bascule .b-short:has(input:checked) { background: color-mix(in srgb, var(--neg) 25%, transparent); color: var(--neg); font-weight: 600; }
.bascule label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: -2px; }

.etoiles { display: flex; flex-direction: row-reverse; justify-content: flex-end; gap: 0.15rem; }
.etoiles label { cursor: pointer; font-size: 1.6rem; line-height: 1; color: color-mix(in srgb, var(--muted) 45%, transparent); }
.etoiles input { position: absolute; opacity: 0; pointer-events: none; }
/* Étoiles inversées : l'étoile cochée et celles « avant » elle s'allument */
.etoiles label:has(input:checked), .etoiles label:has(input:checked) ~ label { color: var(--attention); }
.etoiles label:hover, .etoiles label:hover ~ label { color: var(--attention); }
.etoiles label:has(input:focus-visible) { outline: 2px solid var(--accent); border-radius: 4px; }

.puces { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.puce { cursor: pointer; }
.puce input { position: absolute; opacity: 0; pointer-events: none; }
.puce span { display: inline-block; padding: 0.3rem 0.7rem; border: 1px solid var(--border); border-radius: 99px; font-size: 0.85rem; color: var(--text); }
.puce:has(input:checked) span { background: color-mix(in srgb, var(--attention) 22%, transparent); border-color: var(--attention); }
.puce:has(input:focus-visible) span { outline: 2px solid var(--accent); }
.puce-autre { width: 130px; padding: 0.3rem 0.7rem; border-radius: 99px; font-size: 0.85rem; }

.actions { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin-top: 0.5rem; }
.actions .espace { flex: 1; }

.liste-etat { list-style: none; padding: 0; margin: 0 0 1rem; display: grid; gap: 0.5rem; }
.liste-etat li { display: grid; grid-template-columns: 1.5rem 14rem 1fr; gap: 0.5rem; }

/* ---------- Notification ---------- */

.notif {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%); z-index: 100;
  background: var(--surface-2); border: 1px solid var(--border); border-left: 4px solid var(--pos);
  padding: 0.7rem 1.1rem; border-radius: 10px; box-shadow: var(--ombre); transition: opacity 0.4s;
}
.notif-erreur { border-left-color: var(--neg); }
.notif.sortie { opacity: 0; }

/* ---------- Écrans étroits ---------- */

@media (max-width: 900px) {
  .deux-colonnes { grid-template-columns: 1fr; }
  .deux-colonnes > .carte + .carte { margin-top: 0; }
  .grille-analyses { grid-template-columns: 1fr; }
  .grille-champs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  body { font-size: 14px; }
  .topbar { flex-wrap: wrap; gap: 0.5rem 1rem; padding: 0.6rem 16px; }
  .nav { order: 3; flex-basis: 100%; margin: 0 -16px; padding: 0 12px; }
  .user #user-email { display: none; }
  .user { margin-left: auto; }
  main { padding: 1rem 16px; }
  .grille-comptes { grid-template-columns: 1fr; }
  .tuiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.5rem; }
  .tuile { padding: 0.7rem; }
  .tuile-valeur { font-size: 1.1rem; }
  .filtres { width: 100%; }
  .filtres label { flex: 1 1 140px; }
  .filtres select, .filtres input { min-width: 0; width: 100%; }
  .grille-champs { grid-template-columns: 1fr 1fr; gap: 0.6rem; }
  .grille-champs .large2 { grid-column: 1 / -1; }
  .dialogue { max-height: 100dvh; width: 100vw; max-width: 100vw; margin: 0; border-radius: 0; height: 100dvh; }
  .dialogue.large { width: 100vw; }
  .dialogue-corps { padding: 0.8rem 16px 1rem; }
  fieldset { padding: 0.6rem 0.7rem 0.8rem; }
  .actions .btn { flex: 1 1 auto; }
  .actions .espace { display: none; }
  .liste-etat li { grid-template-columns: 1.5rem 1fr; }
  .liste-etat li .muted { grid-column: 2; }
}
