/* ERP STATION AFRIQUIA — encre bleu nuit, accent bleu piste, orange pour les alertes de niveau */
:root {
  --bg: #f3f5f8; --surface: #ffffff; --sunk: #e9edf2; --ink: #141c28; --muted: #586474; --line: #d6dde6;
  --accent: #1d4f91; --accent-ink: #ffffff; --accent-soft: #e2eaf6;
  --wood: #c48a4f; --wood-dark: #8f5c2c;
  --good: #2c7a4b; --good-soft: #e0f1e6; --warn: #9a5b00; --warn-soft: #fbefd9; --crit: #b3261e; --crit-soft: #fbe3e1;
  --p1: #3b6ea8; --p2: #8f5c2c; --p3: #6b4fa0; --p4: #2f8a8a; --p5: #c48a4f; --p6: #4e7d2c; --p7: #b5527a; --p8: #1f5e4b; --p9: #6b7280;
  --font-display: "Archivo", "Helvetica Neue", Arial, sans-serif;
  --font-body: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) { :root {
  --bg: #0f141b; --surface: #171e28; --sunk: #121821; --ink: #e4e9f0; --muted: #98a4b4; --line: #2a3442;
  --accent: #7fb0ec; --accent-ink: #0b1626; --accent-soft: #1a2a40;
  --good: #6cc08a; --good-soft: #17301f; --warn: #e7ac52; --warn-soft: #33270f; --crit: #f08a82; --crit-soft: #3a1a18;
  color-scheme: dark; } }

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 var(--font-body); }
.shell { display: grid; grid-template-columns: 210px minmax(0, 1fr); min-height: 100vh; }
.nav { background: var(--ink); color: var(--bg); padding: 18px 12px; display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100vh; }
.marque { font-family: var(--font-display); font-size: 17px; padding: 4px 10px 18px; letter-spacing: .02em; }
.marque small { display: block; font-family: var(--font-body); font-size: 11.5px; opacity: .65; letter-spacing: 0; font-weight: 400; }
.nav a { color: inherit; text-decoration: none; padding: 8px 10px; border-radius: 4px; opacity: .8; }
.nav a:hover { opacity: 1; background: rgba(255,255,255,.07); }
.nav a[aria-current="page"] { opacity: 1; background: var(--accent); color: var(--accent-ink); font-weight: 600; }
@media (prefers-color-scheme: dark) { .nav { background: #0a0e14; color: var(--ink); } }
@media (max-width: 820px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .nav { position: static; height: auto; flex-direction: row; flex-wrap: wrap; padding: 10px 16px; }
  .marque { width: 100%; padding: 0 0 6px; }
}
.vue { padding: 22px 28px 60px; min-width: 0; outline: none; }
@media (max-width: 820px) { .vue { padding: 16px; } }

h1 { font-family: var(--font-display); font-size: 24px; margin: 0 0 4px; }
h2 { font-family: var(--font-display); font-size: 15px; margin: 0; }
.entete { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 10px 20px; margin-bottom: 18px; }
.entete p { margin: 0; color: var(--muted); }
.muted { color: var(--muted); }
.mono, .n { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

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

.carte { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; min-width: 0; }
.carte > header { padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 12px; }
.carte > header small { color: var(--muted); }
.carte .corps { padding: 14px 16px; }
.kpi { padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; }
.kpi .k { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.kpi .v { font: 500 22px var(--font-mono); font-variant-numeric: tabular-nums; }
.kpi .s { font-size: 12.5px; color: var(--muted); }

.tbl { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 7px 10px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: var(--sunk); font-weight: 600; white-space: nowrap; }
td.n, th.n { text-align: right; white-space: nowrap; }
tr.sous td { background: var(--bg); font-size: 12.5px; }
tr.cliquable { cursor: pointer; }
tr.cliquable:hover td { background: var(--accent-soft); }

.pill { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 10px; white-space: nowrap; background: var(--sunk); color: var(--muted); }
.pill.ok { background: var(--good-soft); color: var(--good); }
.pill.att { background: var(--warn-soft); color: var(--warn); }
.pill.crit { background: var(--crit-soft); color: var(--crit); }
.pill.acc { background: var(--accent-soft); color: var(--accent); }
.code { font-family: var(--font-mono); font-size: 12px; padding: 1px 6px; border-radius: 3px; color: #fff; }

button, .btn { font: inherit; font-size: 13px; font-weight: 600; padding: 7px 13px; border-radius: 4px; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); cursor: pointer; }
button.ghost { background: transparent; color: var(--accent); }
button.petit { padding: 3px 9px; font-size: 12px; }
button.danger { background: transparent; border-color: var(--crit); color: var(--crit); }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input, select, textarea { font: inherit; font-size: 13px; color: var(--ink); background: var(--sunk); border: 1px solid var(--line); border-radius: 4px; padding: 6px 8px; min-width: 0; }
input[type=number] { font-family: var(--font-mono); width: 90px; }
td input[type=number] { width: 80px; }
textarea { width: 100%; font-family: var(--font-mono); font-size: 12px; }
.form { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px 14px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); }
.form label input, .form label select { width: 100%; }
.form .large { grid-column: 1 / -1; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.toast { position: fixed; right: 20px; bottom: 20px; background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 6px; font-size: 13px; z-index: 20; max-width: 420px; }
.toast.err { background: var(--crit); color: #fff; }
.note { font-size: 12.5px; color: var(--muted); max-width: 80ch; }
details summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 13px; }

/* Station */
.cuves { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; padding: 14px 16px; }
.cuve { display: grid; grid-template-columns: 46px 1fr; gap: 12px; align-items: end; }
.jauge { height: 110px; border: 2px solid var(--line); border-radius: 6px 6px 8px 8px; position: relative; overflow: hidden; background: var(--sunk); }
.jauge i { position: absolute; left: 0; right: 0; bottom: 0; opacity: .85; }
.jauge b { position: absolute; left: 0; right: 0; height: 0; border-top: 2px dashed var(--crit); }
.cuve .k { font: 600 13px var(--font-mono); }
.cuve .v { font: 500 18px var(--font-mono); }
.cuve small { color: var(--muted); display: block; font-size: 12px; }
.pastille { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: baseline; }
.alertes { list-style: none; margin: 0; padding: 0; }
.alertes li { padding: 8px 16px; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: baseline; }
.alertes li:last-child { border-bottom: 0; }
.alertes a { color: inherit; }
.onglets { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 14px; }
.onglets button { background: transparent; color: var(--muted); border-color: var(--line); }
.onglets button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.total td { font-weight: 600; background: var(--sunk); }
.histo { display: flex; align-items: flex-end; gap: 6px; height: 140px; padding: 14px 16px 0; }
.histo .col { flex: 1; display: flex; flex-direction: column-reverse; gap: 2px; min-width: 0; }
.histo .col i { display: block; border-radius: 2px 2px 0 0; }
.histo-lbl { display: flex; gap: 6px; padding: 4px 16px 12px; }
.histo-lbl span { flex: 1; text-align: center; font: 11px var(--font-mono); color: var(--muted); }
.saisie td input[type=number] { width: 120px; }
.grand { font: 500 26px var(--font-mono); }
@media print { .nav, .actions, button { display: none !important; } .shell { display: block; } }
.session { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid rgba(255,255,255,.12); display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.session small { opacity: .65; margin-bottom: 6px; }
.session a { padding: 4px 0; opacity: .75; }
@media (max-width: 820px) { .session { margin-top: 0; width: 100%; flex-direction: row; flex-wrap: wrap; gap: 10px; align-items: baseline; } }
.nav[hidden], .nav a[hidden] { display: none; }
.shell:has(.nav[hidden]) { grid-template-columns: minmax(0, 1fr); }

/* ───────────── Version arabe : de droite à gauche ───────────── */
html[dir=rtl] { --font-body: "IBM Plex Sans Arabic", "Noto Sans Arabic", "IBM Plex Sans", system-ui, sans-serif; --font-display: "IBM Plex Sans Arabic", "Archivo", sans-serif; }
html[dir=rtl] th, html[dir=rtl] td { text-align: right; }
html[dir=rtl] td.n, html[dir=rtl] th.n { text-align: left; }
html[dir=rtl] .kpi .k { letter-spacing: 0; text-transform: none; }
html[dir=rtl] th { letter-spacing: 0; text-transform: none; }
html[dir=rtl] .pastille { margin-right: 0; margin-left: 6px; }
html[dir=rtl] .toast { right: auto; left: 20px; }
/* Montants, index, codes : toujours lus de gauche à droite. */
html[dir=rtl] input[type=number], html[dir=rtl] input[type=date], html[dir=rtl] .mono { direction: ltr; unicode-bidi: isolate; }
html[dir=rtl] td.mono, html[dir=rtl] td .mono { text-align: right; }
.bascule-langue { font-weight: 700; min-width: 34px; background: transparent; border-color: rgba(255,255,255,.35); color: inherit; padding: 3px 8px; align-self: flex-start; margin: 4px 0; }
.session .ligne { display: flex; gap: 8px; align-items: center; }
.relire { font-size: 11.5px; color: var(--muted); }

/* ───────────── Messagerie ───────────── */
.nav a .badge { display: inline-block; min-width: 18px; padding: 0 5px; margin-inline-start: 6px; border-radius: 9px; background: var(--crit); color: #fff; font: 600 11px/18px var(--font-mono); text-align: center; }
.msg { display: grid; grid-template-columns: minmax(240px, 330px) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 900px) { .msg { grid-template-columns: minmax(0, 1fr); } }
.msg-fils { list-style: none; margin: 0; padding: 0; max-height: 70vh; overflow: auto; }
.msg-fils li { padding: 10px 14px; border-bottom: 1px solid var(--line); cursor: pointer; display: grid; gap: 2px; }
.msg-fils li:hover, .msg-fils li[aria-current="true"] { background: var(--accent-soft); }
.msg-fils .t { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
.msg-fils .a { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-fil { list-style: none; margin: 0; padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; max-height: 60vh; overflow: auto; }
.msg-fil li { max-width: 78%; background: var(--sunk); border-radius: 8px; padding: 8px 12px; }
.msg-fil li.moi { margin-inline-start: auto; background: var(--accent-soft); }
.msg-fil li .q { font-size: 12px; color: var(--muted); display: flex; gap: 8px; justify-content: space-between; }
.msg-fil li .x { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 2px; }
.msg-fil li.masque .x { color: var(--muted); font-style: italic; }
.msg-ecrire { border-top: 1px solid var(--line); padding: 12px 16px; display: grid; gap: 8px; }
.msg-ecrire textarea { font-family: var(--font-body); font-size: 13.5px; }
.regle { font-size: 12px; color: var(--muted); background: var(--sunk); border-radius: 4px; padding: 6px 10px; }
.voile { position: fixed; inset: 0; background: rgba(10, 14, 20, .55); display: grid; place-items: center; z-index: 30; padding: 16px; }
.voile .carte { width: min(680px, 100%); max-height: 88vh; display: flex; flex-direction: column; }
.voile .defile { overflow: auto; padding: 14px 16px; white-space: pre-wrap; font-size: 13.5px; }
.discuter { position: fixed; inset: 0 0 0 auto; width: min(440px, 100%); background: var(--surface); border-inline-start: 1px solid var(--line); box-shadow: -8px 0 24px rgba(0,0,0,.12); z-index: 25; display: flex; flex-direction: column; }
html[dir=rtl] .discuter { inset: 0 auto 0 0; box-shadow: 8px 0 24px rgba(0,0,0,.12); }
.discuter > header { padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.discuter .msg-fil { flex: 1; max-height: none; }

/* ───────────── Assistant IA : bulle flottante déplaçable, fenêtre de dialogue, grande vue (couleurs de la station) ───────────── */
.ia-bulle-flottante { position: fixed; z-index: 60; padding: 0; border: 0; background: none; border-radius: 50%; cursor: grab; touch-action: none; user-select: none;
  box-shadow: 0 8px 22px -6px rgba(11, 22, 38, .55); transition: transform .2s; animation: ia-apparait .5s cubic-bezier(.2,.9,.3,1.3); }
.ia-bulle-flottante:hover { transform: scale(1.08); }
.ia-bulle-flottante:active { cursor: grabbing; }
.ia-bulle-flottante[hidden] { display: none; }
.ia-pastille { position: absolute; top: 0; right: 0; width: 14px; height: 14px; border-radius: 50%; background: var(--crit); border: 2px solid #fff; }
.ia-visage { position: relative; display: inline-block; flex: none; }
.ia-visage svg { position: relative; display: block; }
.ia-repos svg { animation: ia-flotte 3.2s ease-in-out infinite; }
.ia-cligne { transform-box: fill-box; transform-origin: center; animation: ia-cligne 4.5s infinite; }
rect.ia-parle { transform-box: fill-box; transform-origin: center; animation: ia-bouche .35s ease-in-out infinite alternate; }
.ia-orbite { transform-origin: 32px 32px; animation: ia-tourne 1.4s linear infinite; }
.ia-onde { position: absolute; inset: 0; border-radius: 50%; background: var(--accent); animation: ia-onde 1.4s ease-out infinite; }
@keyframes ia-flotte { 50% { transform: translateY(-3px); } }
@keyframes ia-cligne { 0%, 92%, 100% { transform: scaleY(1); } 95% { transform: scaleY(.1); } }
@keyframes ia-bouche { from { transform: scaleY(.4); } to { transform: scaleY(1.1); } }
@keyframes ia-tourne { to { transform: rotate(360deg); } }
@keyframes ia-onde { from { transform: scale(1); opacity: .45; } to { transform: scale(1.7); opacity: 0; } }
@keyframes ia-apparait { from { transform: scale(.3); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .ia-visage *, .ia-bulle-flottante, .ia-fenetre { animation: none !important; transition: none !important; } }
.ia-fenetre { position: fixed; z-index: 59; display: flex; flex-direction: column; overflow: hidden; border-radius: 14px; border: 1px solid var(--line);
  background: var(--surface); box-shadow: 0 24px 60px -12px rgba(11, 22, 38, .45); visibility: hidden; opacity: 0; transform: scale(.92); pointer-events: none;
  transition: opacity .25s, transform .3s cubic-bezier(.2,.9,.3,1.2), visibility .3s; }
.ia-fenetre.ouvert { visibility: visible; opacity: 1; transform: none; pointer-events: auto; }
.ia-entete { display: flex; align-items: center; gap: 8px; padding: 8px 10px; color: #fff; cursor: grab; touch-action: none; user-select: none; background: linear-gradient(100deg, #0b1626, #1d4f91 75%, #2e9d5b); }
.ia-entete-titre { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.ia-entete-titre small { color: #dbe6f2; font-size: 11px; }
.ia-entete button, .ia-entete a { background: none; border: 0; color: #e7eef6; font-size: 12px; padding: 4px 8px; border-radius: 6px; cursor: pointer; text-decoration: none; }
.ia-entete button:hover, .ia-entete a:hover { background: rgba(255,255,255,.15); }
.ia-entete button[aria-label] { font-size: 20px; line-height: 1; }
.ia-dialogue { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.ia-dialogue.grand { min-height: 55vh; max-height: 72vh; }
.ia-fil { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.ia-accueil p { margin: 0 0 8px; }
.ia-sujets { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.ia-puce { display: inline-block; border: 1px solid var(--line); background: var(--sunk); color: var(--ink); border-radius: 999px; padding: 5px 11px; font-size: 13px; font-weight: 400; cursor: pointer; text-decoration: none; text-align: start; }
.ia-puce:hover { border-color: var(--accent); }
.ia-bulle { max-width: 92%; padding: 9px 12px; border-radius: 12px; font-size: 14px; line-height: 1.5; overflow-wrap: anywhere; }
.ia-bulle p { margin: 0 0 6px; } .ia-bulle p:last-child { margin-bottom: 0; }
.ia-bulle ul, .ia-bulle ol { margin: 4px 0 6px; padding-inline-start: 20px; }
.ia-moi { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-end-end-radius: 4px; white-space: pre-wrap; }
.ia-lui { align-self: flex-start; background: var(--sunk); border: 1px solid var(--line); border-end-start-radius: 4px; }
.ia-lui.erreur { background: var(--crit-soft); color: var(--crit); }
.ia-titre { font-weight: 700; }
.ia-tableau { overflow-x: auto; margin: 6px 0; }
.ia-carte { margin-top: 8px; padding: 10px; border: 1px dashed var(--warn); border-radius: 10px; background: var(--surface); display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.ia-carte ul { margin: 0; padding-inline-start: 18px; }
.ia-citation { white-space: pre-wrap; padding: 6px 10px; border-inline-start: 3px solid var(--warn); background: var(--sunk); border-radius: 6px; }
.ia-outils { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 6px; font-size: 12px; color: var(--muted); }
button.lien { background: none; border: 0; color: var(--accent); padding: 0; font-size: 12px; font-weight: 600; }
.ia-points { letter-spacing: 3px; animation: ia-clignote 1s infinite; } @keyframes ia-clignote { 50% { opacity: .3; } }
.ia-saisie { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); align-items: flex-end; }
.ia-saisie textarea { flex: 1; resize: none; min-height: 42px; font-family: var(--font-body); font-size: 13.5px; }
.ia-boutons { display: flex; flex-direction: column; gap: 6px; }
.ia-boutons button { min-width: 42px; padding: 8px; }
.ia-grand-entete { display: flex; align-items: center; gap: 14px; }
@media (max-width: 700px) { .ia-fenetre { inset: 8px 8px 82px 8px !important; width: auto !important; height: auto !important; } }
@media print { .ia-bulle-flottante, .ia-fenetre { display: none !important; } }
/* En arabe, les en-têtes de colonnes de chiffres gardent la police arabe (la police à chasse fixe n'a pas de lettres arabes liées). */
html[dir=rtl] th.n, html[dir=rtl] .kpi .k, html[dir=rtl] .cuve small { font-family: var(--font-body); }
