/* ==========================================================================
   OpenCode Manager — feuille de style unique
   --------------------------------------------------------------------------
   Thème sombre par défaut : le tableau de bord est un outil de
   supervision, souvent ouvert longtemps, et le sombre fatigue moins
   dans cette usage. Un thème clair est prévu via prefers-color-scheme.

   Aucune dépendance externe, aucune police distante : le site doit
   fonctionner hors ligne et sans appel réseau supplémentaire.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Attribut `hidden`
   --------------------------------------------------------------------------
   Le navigateur masque un élément `hidden` par une règle de sa feuille
   par défaut. TOUTE règle d'auteur qui déclare `display` l'emporte sur
   cette règle, quelle que soit sa spécificité : un `.modal-root` stylé
   `display: flex` reste donc visible malgré l'attribut.

   Conséquence observée : le calque de modale, vide mais présent,
   recouvrait la page entière — l'écran paraissait grisé et plus rien
   n'était cliquable. Aucun message d'erreur, aucune entrée en console.

   Cette règle rend `hidden` contraignant, quel que soit le `display`
   déclaré ensuite. Elle est en tête de feuille pour cette raison.
   -------------------------------------------------------------------------- */
[hidden] { display: none !important; }

:root {
  /* Fonds, du plus profond au plus clair */
  --bg:            #0b0d12;
  --bg-raised:     #12151d;
  --bg-card:       #161a24;
  --bg-hover:      #1c2130;
  --bg-input:      #0e1118;

  /* Textes */
  --text:          #e6e8ef;
  --text-dim:      #98a0b3;
  --text-faint:    #626b80;

  /* Traits */
  --border:        #232837;
  --border-strong: #333c50;

  /* Accent */
  --accent:        #6ea8fe;
  --accent-dim:    #3a6fc4;
  --accent-bg:     #16233c;

  /* États de session — une couleur par état, utilisée partout */
  --st-active:     #3ddc97;
  --st-idle:       #8b95ad;
  --st-waiting:    #f0b429;
  --st-permission: #f0883e;
  --st-question:   #b98cf5;
  --st-error:      #f2545b;
  --st-done:       #4ec9a8;
  --st-unknown:    #5a6377;

  /* Sémantique */
  --ok:            #3ddc97;
  --warn:          #f0b429;
  --danger:        #f2545b;
  --info:          #6ea8fe;

  /* Formes */
  --radius:        8px;
  --radius-sm:     5px;
  --radius-lg:     12px;

  /* Ombres */
  --shadow:        0 1px 2px rgba(0, 0, 0, .4);
  --shadow-lg:     0 8px 28px rgba(0, 0, 0, .55);

  --topbar-h:      54px;

  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg:            #f6f7fa;
    --bg-raised:     #ffffff;
    --bg-card:       #ffffff;
    --bg-hover:      #eef1f7;
    --bg-input:      #ffffff;
    --text:          #171b26;
    --text-dim:      #5a6377;
    --text-faint:    #8a93a6;
    --border:        #dfe3ec;
    --border-strong: #c3cad9;
    --accent:        #2b6cd4;
    --accent-dim:    #1e4fa0;
    --accent-bg:     #e4edfc;
    --st-active:     #17976a;
    --st-idle:       #6b7488;
    --st-waiting:    #b7791f;
    --st-permission: #c2611f;
    --st-question:   #7c4dd0;
    --st-error:      #d13a42;
    --st-done:       #1d8f76;
    --st-unknown:    #97a0b3;
    --shadow:        0 1px 2px rgba(20, 25, 40, .08);
    --shadow-lg:     0 8px 28px rgba(20, 25, 40, .14);
    color-scheme: light;
  }
}

/* --------------------------------------------------------------------------
   Réinitialisation minimale
   -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

h1, h2, h3, h4 { margin: 0; font-weight: 650; line-height: 1.25; }

code, pre, .mono {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: .92em;
}

button, input, select, textarea { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* --------------------------------------------------------------------------
   En-tête
   -------------------------------------------------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--bg-raised) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: 16px;
  height: var(--topbar-h);
  padding: 0 16px;
  max-width: 1600px;
  margin: 0 auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-weight: 650;
  white-space: nowrap;
}
.brand:hover { text-decoration: none; }

.brand-mark {
  width: 18px;
  height: 18px;
  border: 2.5px solid var(--accent);
  border-radius: 50%;
  position: relative;
  flex: none;
}
.brand-mark::after {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  background: var(--accent);
  opacity: .35;
}

.nav {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
  flex: 1;
  min-width: 0;
}
.nav::-webkit-scrollbar { display: none; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 13px;
  white-space: nowrap;
  transition: background .12s, color .12s;
}
.nav-link:hover { background: var(--bg-hover); color: var(--text); text-decoration: none; }
.nav-link.is-active { background: var(--accent-bg); color: var(--accent); }

.topbar-right { display: flex; align-items: center; gap: 8px; flex: none; }

.api-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 550;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-dim);
  white-space: nowrap;
}
.api-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}
.api-live .api-dot { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 22%, transparent); }
.api-live { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 35%, var(--border)); }
.api-stale .api-dot { background: var(--warn); }
.api-stale { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, var(--border)); }
.api-offline .api-dot { background: var(--danger); }
.api-offline { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }
.api-unknown .api-dot { background: var(--text-faint); }
.api-unknown { color: var(--text-faint); }
.api-syncing .api-dot { animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }

/* --------------------------------------------------------------------------
   Machine active — pastille du bandeau
   --------------------------------------------------------------------------
   Elle repond a la question la plus fondamentale de l'interface, et doit
   rester lisible quand le bandeau se serre : le nom de la machine passe
   donc avant tout le reste, et le mot « Machine » s'efface sur petit
   ecran plutot que de tronquer le nom — c'est l'information utile.
   -------------------------------------------------------------------------- */
.machine-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 11px 4px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  border: 1px solid color-mix(in srgb, var(--accent) 32%, var(--border));
  background: var(--accent-bg);
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  transition: border-color .15s, background .15s;
}
.machine-pill:hover { background: color-mix(in srgb, var(--accent) 16%, var(--bg-card)); }
.machine-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent);
  flex: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}
.machine-text { display: inline-flex; align-items: baseline; gap: 5px; min-width: 0; }
.machine-kicker {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: color-mix(in srgb, var(--accent) 72%, var(--text-dim));
}
.machine-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 22ch;
}
@media (max-width: 900px) { .machine-kicker { display: none; } }

/* --------------------------------------------------------------------------
   Page Machines
   -------------------------------------------------------------------------- */
.card-current-machine {
  border-color: color-mix(in srgb, var(--accent) 30%, var(--border));
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 7%, var(--bg-card)), var(--bg-card));
}
.current-machine {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
}
.current-machine-kicker {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.current-machine-name {
  font-size: 21px;
  font-weight: 680;
  line-height: 1.25;
  margin-top: 2px;
}
.current-machine-host {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  margin-top: 2px;
}
.current-machine-url { margin-top: 4px; word-break: break-all; }
.current-machine-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(74px, auto));
  gap: 10px;
}
@media (max-width: 760px) { .current-machine-stats { grid-template-columns: repeat(2, 1fr); width: 100%; } }

.machine-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 12px;
}
.machine-card {
  display: flex;
  flex-direction: column;
  gap: 11px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius, 10px);
  background: var(--bg-raised);
}
.machine-card.is-active { border-color: color-mix(in srgb, var(--ok) 40%, var(--border)); }
.machine-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.machine-title { display: flex; align-items: center; gap: 7px; min-width: 0; }
.machine-title-name { font-size: 14.5px; font-weight: 640; }
.machine-badges { display: flex; gap: 5px; flex: none; flex-wrap: wrap; justify-content: flex-end; }
.machine-endpoint {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11.5px;
  color: var(--text-faint);
  word-break: break-all;
}
.machine-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 9px 10px;
  border-radius: 8px;
  background: var(--bg-card);
}
.machine-stat-label {
  font-size: 10px;
  font-weight: 650;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.machine-stat-value { font-size: 16px; font-weight: 640; margin-top: 1px; }
.machine-facts {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 3px 10px;
  margin: 0;
  font-size: 12px;
}
.machine-facts dt { color: var(--text-faint); }
.machine-facts dd {
  margin: 0;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
}
.machine-error {
  font-size: 11.5px;
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 10%, transparent);
  padding: 6px 9px;
  border-radius: 6px;
  word-break: break-word;
}
.machine-actions { margin-top: auto; padding-top: 3px; }
.is-earlier { opacity: .62; }

/* Etats de joignabilite. Deux couleurs suffisent : joignable ou non.
   Le detail du motif est dans la pastille du bandeau et dans le texte
   d'erreur, pas dans une troisieme nuance de couleur. */
.badge-ok   { color: var(--ok);     border-color: color-mix(in srgb, var(--ok) 34%, var(--border)); }
.badge-off  { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 34%, var(--border)); }
.badge-subtle { color: var(--text-faint); font-weight: 550; }

@media (max-width: 640px) {
  .machine-stats { grid-template-columns: repeat(2, 1fr); }
}

/* Barre de connexion SSE */
.sse-bar {
  padding: 5px 16px;
  font-size: 12px;
  text-align: center;
  background: color-mix(in srgb, var(--warn) 14%, var(--bg-raised));
  color: var(--warn);
  border-bottom: 1px solid var(--border);
}

/* --------------------------------------------------------------------------
   Icônes (dessinées en CSS : aucune police d'icônes, donc aucun
   téléchargement externe et aucun FOUC)
   -------------------------------------------------------------------------- */
[data-icon] {
  display: inline-block;
  width: 14px; height: 14px;
  background: currentColor;
  opacity: .85;
  -webkit-mask: var(--icon) center / contain no-repeat;
  mask: var(--icon) center / contain no-repeat;
  flex: none;
  vertical-align: -2px;
}
[data-icon="server"]   { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%23000' stroke-width='2' d='M3 4h18v6H3zM3 14h18v6H3z'/%3E%3Cpath fill='%23000' d='M6.5 7h.01M6.5 17h.01'/%3E%3C/svg%3E"); }
[data-icon="swap"]     { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' d='M7 4 3 8l4 4M3 8h13a4 4 0 0 1 4 4M17 20l4-4-4-4M21 16H8a4 4 0 0 1-4-4'/%3E%3C/svg%3E"); }
[data-icon="activity"] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' d='M2 12h4l3-8 4 16 3-8h6'/%3E%3C/svg%3E"); }
[data-icon="grid"]    { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%23000' stroke-width='2' d='M3 3h7v7H3zM14 3h7v7h-7zM14 14h7v7h-7zM3 14h7v7H3z'/%3E%3C/svg%3E"); }
[data-icon="clock"]   { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%23000' stroke-width='2' d='M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18zM12 7v5l3 2'/%3E%3C/svg%3E"); }
[data-icon="send"]    { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%23000' stroke-width='2' d='M22 2 11 13M22 2l-7 20-4-9-9-4z'/%3E%3C/svg%3E"); }
[data-icon="bolt"]    { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%23000' stroke-width='2' d='M13 2 4 14h7l-1 8 9-12h-7z'/%3E%3C/svg%3E"); }
[data-icon="chart"]   { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%23000' stroke-width='2' d='M4 20V10M10 20V4M16 20v-7M22 20H2'/%3E%3C/svg%3E"); }
[data-icon="cog"]     { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%23000' stroke-width='2' d='M12 15a3 3 0 1 0 0-6 3 3 0 0 0 0 6zM19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-2.8 1.17V21a2 2 0 1 1-4 0v-.09A1.65 1.65 0 0 0 7 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 3 15a2 2 0 1 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.6h.09A2 2 0 0 1 11 3V3a2 2 0 1 1 4 0v.09A1.65 1.65 0 0 0 16 4.6a1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 20.4 9v.09a2 2 0 1 1 0 4h-.09a1.65 1.65 0 0 0-1.91 1.91z'/%3E%3C/svg%3E"); }
[data-icon="logout"]  { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%23000' stroke-width='2' d='M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4M16 17l5-5-5-5M21 12H9'/%3E%3C/svg%3E"); }
[data-icon="play"]    { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%23000' stroke-width='2' d='M6 4l14 8-14 8z'/%3E%3C/svg%3E"); }
[data-icon="stop"]    { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%23000' stroke-width='2' d='M6 6h12v12H6z'/%3E%3C/svg%3E"); }
[data-icon="refresh"] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%23000' stroke-width='2' d='M23 4v6h-6M1 20v-6h6M3.5 9a9 9 0 0 1 14.9-3.4L23 10M1 14l4.6 4.4A9 9 0 0 0 20.5 15'/%3E%3C/svg%3E"); }
[data-icon="search"]  { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%23000' stroke-width='2' d='M11 19a8 8 0 1 0 0-16 8 8 0 0 0 0 16zM21 21l-4.35-4.35'/%3E%3C/svg%3E"); }
[data-icon="alert"]   { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%23000' stroke-width='2' d='M10.3 3.9 1.8 18a2 2 0 0 0 1.7 3h17a2 2 0 0 0 1.7-3L13.7 3.9a2 2 0 0 0-3.4 0zM12 9v4M12 17h.01'/%3E%3C/svg%3E"); }
[data-icon="check"]   { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%23000' stroke-width='2' d='M20 6 9 17l-5-5'/%3E%3C/svg%3E"); }
[data-icon="plus"]    { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%23000' stroke-width='2' d='M12 5v14M5 12h14'/%3E%3C/svg%3E"); }
[data-icon="close"]   { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%23000' stroke-width='2' d='M18 6 6 18M6 6l12 12'/%3E%3C/svg%3E"); }
[data-icon="edit"]    { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%23000' stroke-width='2' d='M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7M18.5 2.5a2.1 2.1 0 0 1 3 3L12 15l-4 1 1-4z'/%3E%3C/svg%3E"); }
[data-icon="trash"]   { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%23000' stroke-width='2' d='M3 6h18M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6M10 11v6M14 11v6'/%3E%3C/svg%3E"); }
[data-icon="filter"]  { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%23000' stroke-width='2' d='M22 3H2l8 9.5V19l4 2v-8.5z'/%3E%3C/svg%3E"); }
[data-icon="list"]    { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%23000' stroke-width='2' d='M8 6h13M8 12h13M8 18h13M3 6h.01M3 12h.01M3 18h.01'/%3E%3C/svg%3E"); }
[data-icon="git"]     { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='18' r='3' fill='%23000'/%3E%3Ccircle cx='6' cy='6' r='3' fill='%23000'/%3E%3Ccircle cx='18' cy='6' r='3' fill='%23000'/%3E%3Cpath fill='none' stroke='%23000' stroke-width='2' d='M6 9v3a6 6 0 0 0 6 6h3M18 9v3a6 6 0 0 1-3 5.2'/%3E%3C/svg%3E"); }
[data-icon="test"]    { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%23000' stroke-width='2' d='M9 3v6L4 19a2 2 0 0 0 1.7 3h12.6A2 2 0 0 0 20 19L15 9V3M8 3h8M7 15h10'/%3E%3C/svg%3E"); }
[data-icon="bug"]     { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Crect x='8' y='6' width='8' height='14' rx='4' fill='none' stroke='%23000' stroke-width='2'/%3E%3Cpath fill='none' stroke='%23000' stroke-width='2' d='M8 12H3M21 12h-5M8 8L4 5M16 8l4-3M8 16l-4 3M16 16l4 3'/%3E%3C/svg%3E"); }
[data-icon="info"]    { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='12' r='10' fill='none' stroke='%23000' stroke-width='2'/%3E%3Cpath fill='none' stroke='%23000' stroke-width='2' d='M12 16v-4M12 8h.01'/%3E%3C/svg%3E"); }
[data-icon="forward"] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%23000' stroke-width='2' d='M5 12h14M13 6l6 6-6 6'/%3E%3C/svg%3E"); }
[data-icon="branch"]  { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='6' cy='6' r='3' fill='none' stroke='%23000' stroke-width='2'/%3E%3Ccircle cx='6' cy='18' r='3' fill='none' stroke='%23000' stroke-width='2'/%3E%3Ccircle cx='18' cy='8' r='3' fill='none' stroke='%23000' stroke-width='2'/%3E%3Cpath fill='none' stroke='%23000' stroke-width='2' d='M6 9v6M18 11c0 3-3 4-6 4'/%3E%3C/svg%3E"); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px; height: 30px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-dim);
  cursor: pointer;
  transition: background .12s, color .12s;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); text-decoration: none; }
.icon-btn [data-icon] { width: 15px; height: 15px; }

/* --------------------------------------------------------------------------
   Structure de page
   -------------------------------------------------------------------------- */
.main {
  max-width: 1600px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.page-title { font-size: 20px; }
.page-subtitle { margin: 4px 0 0; color: var(--text-dim); font-size: 13px; }
.page-head-right { display: flex; align-items: center; gap: 8px; }

.version-tag {
  font-size: 11px;
  color: var(--text-faint);
  padding: 2px 7px;
  border: 1px solid var(--border);
  border-radius: 999px;
}

.footer {
  max-width: 1600px;
  margin: 0 auto;
  padding: 18px 16px 30px;
  border-top: 1px solid var(--border);
  color: var(--text-faint);
  font-size: 12px;
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
}
.footer-sep { opacity: .5; }

/* --------------------------------------------------------------------------
   Cartes et compteurs
   -------------------------------------------------------------------------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-raised);
  flex-wrap: wrap;
}
.card-title { font-size: 14px; font-weight: 620; }
.card-subtitle { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.card-body { padding: 14px; }
.card-body.tight { padding: 0; }

.grid { display: grid; gap: 12px; }
.grid-stats { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }

.stat {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  position: relative;
  overflow: hidden;
}
.stat::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--stat-accent, var(--border-strong));
}
.stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-faint);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 5px;
}
.stat-value {
  font-size: 24px;
  font-weight: 680;
  line-height: 1.15;
  margin-top: 5px;
  font-variant-numeric: tabular-nums;
}
.stat-hint { font-size: 11.5px; color: var(--text-faint); margin-top: 3px; }
.stat.is-clickable { cursor: pointer; transition: background .12s, border-color .12s; }
.stat.is-clickable:hover { background: var(--bg-hover); border-color: var(--border-strong); }
.stat.is-active-filter { border-color: var(--accent); background: var(--accent-bg); }

/* --------------------------------------------------------------------------
   Badges d'état
   -------------------------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 580;
  border: 1px solid;
  white-space: nowrap;
}
.badge::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}
.badge-no-dot::before { display: none; }

.badge-active     { color: var(--st-active);     border-color: color-mix(in srgb, var(--st-active) 40%, transparent);     background: color-mix(in srgb, var(--st-active) 12%, transparent); }
.badge-idle       { color: var(--st-idle);       border-color: color-mix(in srgb, var(--st-idle) 40%, transparent);       background: color-mix(in srgb, var(--st-idle) 10%, transparent); }
.badge-waiting    { color: var(--st-waiting);    border-color: color-mix(in srgb, var(--st-waiting) 40%, transparent);    background: color-mix(in srgb, var(--st-waiting) 12%, transparent); }
.badge-permission { color: var(--st-permission); border-color: color-mix(in srgb, var(--st-permission) 40%, transparent); background: color-mix(in srgb, var(--st-permission) 14%, transparent); }
.badge-question   { color: var(--st-question);   border-color: color-mix(in srgb, var(--st-question) 40%, transparent);   background: color-mix(in srgb, var(--st-question) 12%, transparent); }
.badge-error      { color: var(--st-error);      border-color: color-mix(in srgb, var(--st-error) 40%, transparent);      background: color-mix(in srgb, var(--st-error) 12%, transparent); }
.badge-completed  { color: var(--st-done);       border-color: color-mix(in srgb, var(--st-done) 40%, transparent);       background: color-mix(in srgb, var(--st-done) 12%, transparent); }
.badge-unknown    { color: var(--st-unknown);    border-color: color-mix(in srgb, var(--st-unknown) 40%, transparent);    background: color-mix(in srgb, var(--st-unknown) 10%, transparent); }
.badge-stale      { color: var(--warn);          border-color: color-mix(in srgb, var(--warn) 40%, transparent);          background: color-mix(in srgb, var(--warn) 10%, transparent); }

.badge-active .badge-dot, .badge.is-pulsing::before { animation: pulse 1.4s ease-in-out infinite; }

/* --------------------------------------------------------------------------
   Boutons
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text);
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s, opacity .12s;
  text-decoration: none;
}
.btn:hover { background: var(--bg-hover); text-decoration: none; }
.btn:disabled, .btn.is-loading { opacity: .55; cursor: not-allowed; }
.btn [data-icon] { width: 13px; height: 13px; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #06090f;
}
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 85%, white); }
@media (prefers-color-scheme: light) { .btn-primary { color: #fff; } }

.btn-ok    { color: var(--ok);     border-color: color-mix(in srgb, var(--ok) 45%, transparent);     background: color-mix(in srgb, var(--ok) 10%, transparent); }
.btn-ok:hover { background: color-mix(in srgb, var(--ok) 20%, transparent); }
.btn-warn  { color: var(--warn);   border-color: color-mix(in srgb, var(--warn) 45%, transparent);   background: color-mix(in srgb, var(--warn) 10%, transparent); }
.btn-warn:hover { background: color-mix(in srgb, var(--warn) 20%, transparent); }
.btn-danger{ color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); background: color-mix(in srgb, var(--danger) 10%, transparent); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 20%, transparent); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text-dim); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }
.btn-sm { padding: 3px 8px; font-size: 12px; }
.btn-lg { padding: 9px 16px; font-size: 14px; }

.btn-row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

/* --------------------------------------------------------------------------
   Formulaires
   -------------------------------------------------------------------------- */
.field { margin-bottom: 12px; }
.field:last-child { margin-bottom: 0; }
.field-label {
  display: block;
  font-size: 12px;
  font-weight: 580;
  color: var(--text-dim);
  margin-bottom: 4px;
}
.field-hint { font-size: 11.5px; color: var(--text-faint); margin-top: 4px; }
.field-error { font-size: 12px; color: var(--danger); margin-top: 4px; }

.input, .select, .textarea {
  width: 100%;
  padding: 7px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  transition: border-color .12s, box-shadow .12s;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
.textarea { resize: vertical; min-height: 90px; line-height: 1.5; }
.textarea.mono { font-size: 12.5px; }
.select { cursor: pointer; }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  cursor: pointer;
  font-size: 13px;
}
.checkbox-row input[type="checkbox"] {
  width: 15px; height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
  flex: none;
}

.input-group { display: flex; gap: 6px; align-items: center; }
.input-group .input { flex: 1; min-width: 0; }

/* --------------------------------------------------------------------------
   Barre de filtres
   -------------------------------------------------------------------------- */
.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.toolbar .input { max-width: 260px; }
.toolbar-spacer { flex: 1; }

.chips { display: flex; gap: 5px; flex-wrap: wrap; }
.chip {
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-card);
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, color .12s, border-color .12s;
}
.chip:hover { background: var(--bg-hover); color: var(--text); }
.chip.is-active { background: var(--accent-bg); border-color: var(--accent); color: var(--accent); }
.chip-count { opacity: .65; margin-left: 4px; font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------------------
   Liste des sessions
   -------------------------------------------------------------------------- */
.session-list { display: flex; flex-direction: column; }

.session-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: start;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}
.session-row:last-child { border-bottom: none; }
.session-row:hover { background: var(--bg-hover); }
.session-row.is-highlight { background: var(--accent-bg); }

.session-marker {
  width: 3px;
  align-self: stretch;
  border-radius: 2px;
  background: var(--st-idle);
  min-height: 34px;
}
.session-marker.active     { background: var(--st-active); }
.session-marker.idle       { background: var(--st-idle); }
.session-marker.waiting    { background: var(--st-waiting); }
.session-marker.permission { background: var(--st-permission); }
.session-marker.question   { background: var(--st-question); }
.session-marker.error      { background: var(--st-error); }
.session-marker.completed  { background: var(--st-done); }
.session-marker.unknown    { background: var(--st-unknown); }

.session-main { min-width: 0; }
.session-title-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 3px; }
.session-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.session-title:hover { color: var(--accent); text-decoration: none; }

.session-meta {
  display: flex;
  gap: 5px 12px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 5px;
}
.session-meta-item { display: inline-flex; align-items: center; gap: 4px; }
.session-meta-item [data-icon] { width: 11px; height: 11px; opacity: .6; }
.session-path {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  color: var(--text-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.session-last {
  font-size: 12.5px;
  color: var(--text-dim);
  margin-top: 5px;
  padding-left: 9px;
  border-left: 2px solid var(--border);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.session-last.is-error { color: var(--st-error); border-left-color: var(--st-error); }

.session-summary {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 6px;
  padding: 7px 10px;
  background: var(--bg-raised);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  white-space: pre-wrap;
}
.session-summary b { color: var(--text); font-weight: 600; }

.session-actions {
  display: flex;
  gap: 5px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: 340px;
}

.session-blocker {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 7px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  border: 1px solid;
}
.session-blocker-permission {
  background: color-mix(in srgb, var(--st-permission) 10%, transparent);
  border-color: color-mix(in srgb, var(--st-permission) 35%, transparent);
  color: var(--st-permission);
}
.session-blocker-question {
  background: color-mix(in srgb, var(--st-question) 10%, transparent);
  border-color: color-mix(in srgb, var(--st-question) 35%, transparent);
  color: var(--st-question);
}
.session-blocker [data-icon] { margin-top: 2px; }
.session-blocker-body { flex: 1; min-width: 0; }
.session-blocker-actions { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 6px; }
.session-blocker code { font-size: 11px; opacity: .9; word-break: break-all; }

/* --------------------------------------------------------------------------
   Actions rapides
   -------------------------------------------------------------------------- */
.quick-bar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
  padding: 10px 14px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.quick-bar-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-faint);
  font-weight: 600;
  margin-right: 4px;
}
.quick-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text);
  font-size: 12.5px;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
.quick-btn:hover { background: var(--bg-hover); border-color: var(--accent); }
.quick-btn:disabled { opacity: .5; cursor: not-allowed; }
.quick-btn [data-icon] { width: 12px; height: 12px; }
.quick-btn.is-primary { background: var(--accent-bg); border-color: var(--accent-dim); color: var(--accent); }

/* --------------------------------------------------------------------------
   Timeline des messages
   -------------------------------------------------------------------------- */
.timeline { display: flex; flex-direction: column; gap: 2px; padding: 14px; }

.msg {
  display: grid;
  grid-template-columns: 84px 1fr;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 55%, transparent);
}
.msg:last-child { border-bottom: none; }
.msg:hover { background: color-mix(in srgb, var(--bg-hover) 45%, transparent); }

.msg-side { text-align: right; }
.msg-role {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.msg-time { font-size: 10.5px; color: var(--text-faint); font-variant-numeric: tabular-nums; }
.msg-cost { font-size: 10px; color: var(--text-faint); }

.msg-body { min-width: 0; }
.msg-text {
  font-size: 13.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg-text:empty::after { content: "(vide)"; color: var(--text-faint); font-style: italic; }

.msg-user      { border-left: 3px solid var(--accent); padding-left: 10px; }
.msg-assistant { }
.msg-system    { opacity: .82; }
.msg-event     { opacity: .6; font-size: 12px; font-style: italic; }
.msg-tool      { border-left: 3px solid var(--st-waiting); padding-left: 10px; }
.msg-error     { border-left: 3px solid var(--st-error); padding-left: 10px; }
.msg-summary   { border-left: 3px solid var(--st-question); padding-left: 10px; background: color-mix(in srgb, var(--st-question) 6%, transparent); }

.msg-role-user      { color: var(--accent); }
.msg-role-assistant { color: var(--st-done); }
.msg-role-tool      { color: var(--st-waiting); }
.msg-role-system    { color: var(--st-question); }
.msg-role-event     { color: var(--text-faint); }

.msg-tools { margin-top: 6px; display: flex; gap: 5px; flex-wrap: wrap; }
.tool-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 11px;
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text-dim);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.tool-chip.is-error { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.tool-chip.is-running { color: var(--warn); }
.tool-chip.is-completed { color: var(--ok); }

.msg-error-box {
  margin-top: 6px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--st-error) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--st-error) 30%, transparent);
  color: var(--st-error);
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-copy {
  opacity: 0;
  margin-left: 6px;
  cursor: pointer;
  color: var(--text-faint);
  background: none;
  border: none;
  padding: 0;
  font-size: 11px;
}
.msg:hover .msg-copy { opacity: 1; }
.msg-copy:hover { color: var(--accent); }

/* --------------------------------------------------------------------------
   Résumé structuré
   -------------------------------------------------------------------------- */
.summary-grid { display: grid; gap: 10px; }
.summary-row {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 12px;
  padding: 7px 0;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 50%, transparent);
}
.summary-row:last-child { border-bottom: none; }
.summary-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding-top: 2px;
}
.summary-value { font-size: 13px; line-height: 1.55; white-space: pre-wrap; }
.summary-list { margin: 0; padding-left: 18px; }
.summary-list li { margin: 2px 0; }

@media (max-width: 640px) {
  .summary-row { grid-template-columns: 1fr; gap: 2px; }
}

/* --------------------------------------------------------------------------
   Tableaux
   -------------------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left;
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-faint);
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
}
.table td { padding: 8px 12px; border-bottom: 1px solid color-mix(in srgb, var(--border) 55%, transparent); vertical-align: top; }
.table tbody tr:hover { background: var(--bg-hover); }
.table tbody tr:last-child td { border-bottom: none; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .nowrap { white-space: nowrap; }
.table-compact td, .table-compact th { padding: 5px 9px; }

/* --------------------------------------------------------------------------
   Graphiques (barres CSS, sans bibliothèque)
   -------------------------------------------------------------------------- */
.bars { display: flex; align-items: flex-end; gap: 3px; height: 110px; }
.bars-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; }
.bars-bar {
  width: 100%;
  background: var(--accent);
  border-radius: 3px 3px 0 0;
  min-height: 2px;
  transition: opacity .12s;
}
.bars-col:hover .bars-bar { opacity: .75; }
.bars-label { font-size: 10px; color: var(--text-faint); white-space: nowrap; }
.bars-value { font-size: 10px; color: var(--text-dim); font-variant-numeric: tabular-nums; }

.hbar-list { display: flex; flex-direction: column; gap: 6px; }
.hbar {
  display: grid;
  grid-template-columns: minmax(90px, 150px) 1fr auto;
  gap: 10px;
  align-items: center;
  font-size: 12.5px;
}
.hbar-name { color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { background: var(--bg-input); border-radius: 3px; height: 16px; overflow: hidden; }
.hbar-fill { height: 100%; background: var(--accent); border-radius: 3px; min-width: 2px; }
.hbar-fill.is-error { background: var(--danger); }
.hbar-fill.is-ok { background: var(--ok); }
.hbar-value { font-variant-numeric: tabular-nums; color: var(--text); min-width: 3.5em; text-align: right; }

.heatmap { display: grid; grid-template-columns: repeat(24, 1fr); gap: 2px; }
.heat-cell {
  aspect-ratio: 1;
  border-radius: 2px;
  background: var(--bg-input);
  border: 1px solid transparent;
}
.heat-cell[data-level="1"] { background: color-mix(in srgb, var(--accent) 25%, var(--bg-input)); }
.heat-cell[data-level="2"] { background: color-mix(in srgb, var(--accent) 50%, var(--bg-input)); }
.heat-cell[data-level="3"] { background: color-mix(in srgb, var(--accent) 75%, var(--bg-input)); }
.heat-cell[data-level="4"] { background: var(--accent); }
.heat-legend { display: flex; gap: 4px; align-items: center; font-size: 11px; color: var(--text-faint); margin-top: 6px; }
.heat-legend .heat-cell { width: 10px; aspect-ratio: 1; }

/* --------------------------------------------------------------------------
   Modale
   -------------------------------------------------------------------------- */
/* Fermé par défaut, ouvert uniquement quand le JavaScript retire
   l'attribut `hidden`. Même sans la règle globale ci-dessus, ce patron
   rend l'intention explicite. */
.modal-root {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(3, 5, 9, .68);
  backdrop-filter: blur(3px);
  animation: fade .12s ease-out;
}
.modal-root:not([hidden]) { display: flex; }
@keyframes fade { from { opacity: 0; } }

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: min(620px, 100%);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  animation: rise .14s ease-out;
}
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }

.modal-lg { width: min(880px, 100%); }
.modal-sm { width: min(440px, 100%); }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex: none;
}
.modal-title { font-size: 15px; }
.modal-body { padding: 16px; overflow-y: auto; flex: 1; }
.modal-foot {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-raised);
  flex: none;
  flex-wrap: wrap;
}

/* --------------------------------------------------------------------------
   Notifications
   -------------------------------------------------------------------------- */
/* Pas d'attribut `hidden` ici : la pile est toujours presente et
   reste vide quand elle n'a rien a afficher. `pointer-events: none`
   fait qu'elle ne bloque jamais les clics. */
.toast-stack {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(420px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 10px 13px;
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  animation: slide-in .16s ease-out;
  display: flex;
  gap: 9px;
  align-items: flex-start;
}
@keyframes slide-in { from { transform: translateX(16px); opacity: 0; } }
.toast.is-leaving { animation: slide-out .14s ease-in forwards; }
@keyframes slide-out { to { transform: translateX(16px); opacity: 0; } }
.toast-ok     { border-left-color: var(--ok); }
.toast-warn   { border-left-color: var(--warn); }
.toast-error  { border-left-color: var(--danger); }
.toast-info   { border-left-color: var(--info); }
.toast-body { flex: 1; min-width: 0; }
.toast-title { font-weight: 600; margin-bottom: 2px; }
.toast-text { color: var(--text-dim); font-size: 12.5px; white-space: pre-wrap; word-break: break-word; }

/* --------------------------------------------------------------------------
   Page de connexion
   -------------------------------------------------------------------------- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background:
    radial-gradient(1000px 500px at 50% -10%, color-mix(in srgb, var(--accent) 10%, transparent), transparent),
    var(--bg);
}
.login-card {
  width: min(400px, 100%);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow-lg);
}
.login-brand { display: flex; align-items: center; gap: 9px; margin-bottom: 6px; }
.login-brand .brand-mark { width: 22px; height: 22px; }
.login-title { font-size: 17px; font-weight: 650; }
.login-sub { color: var(--text-dim); font-size: 13px; margin: 0 0 20px; }
.login-error {
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  color: var(--danger);
  font-size: 12.5px;
  margin-bottom: 14px;
}
.login-foot { margin-top: 18px; text-align: center; font-size: 11.5px; color: var(--text-faint); }

/* --------------------------------------------------------------------------
   Divers
   -------------------------------------------------------------------------- */
.empty {
  padding: 44px 20px;
  text-align: center;
  color: var(--text-faint);
}
.empty-title { font-size: 14px; color: var(--text-dim); margin-bottom: 5px; font-weight: 550; }
.empty-hint { font-size: 12.5px; max-width: 380px; margin: 0 auto; }
.empty [data-icon] { width: 26px; height: 26px; margin-bottom: 10px; opacity: .35; }

.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.small { font-size: 12px; }
.tiny  { font-size: 11px; }
.strong { font-weight: 620; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; } .mb-3 { margin-bottom: 24px; }
.flex { display: flex; } .between { justify-content: space-between; } .center-y { align-items: center; }
.gap-1 { gap: 6px; } .gap-2 { gap: 12px; } .wrap { flex-wrap: wrap; }

.notice {
  display: flex;
  gap: 9px;
  padding: 10px 13px;
  border-radius: var(--radius);
  font-size: 12.5px;
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text-dim);
  margin-bottom: 14px;
  align-items: flex-start;
}
.notice [data-icon] { margin-top: 1px; flex: none; }
.notice-warn   { color: var(--warn);   border-color: color-mix(in srgb, var(--warn) 35%, transparent);   background: color-mix(in srgb, var(--warn) 8%, transparent); }
.notice-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); background: color-mix(in srgb, var(--danger) 8%, transparent); }
.notice-info   { color: var(--info);   border-color: color-mix(in srgb, var(--info) 30%, transparent);   background: color-mix(in srgb, var(--info) 8%, transparent); }
.notice-ok     { color: var(--ok);     border-color: color-mix(in srgb, var(--ok) 30%, transparent);     background: color-mix(in srgb, var(--ok) 8%, transparent); }
.notice strong { color: inherit; }

.kv { display: grid; grid-template-columns: 128px 1fr; gap: 4px 12px; font-size: 12.5px; }
.kv dt { color: var(--text-faint); }
.kv dd { margin: 0; word-break: break-word; }
@media (max-width: 520px) { .kv { grid-template-columns: 1fr; } .kv dt { margin-top: 6px; } }

.pagination { display: flex; gap: 6px; align-items: center; justify-content: center; padding: 12px; }

.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.segmented button {
  padding: 5px 11px;
  border: none;
  background: var(--bg-card);
  color: var(--text-dim);
  font-size: 12.5px;
  cursor: pointer;
  border-right: 1px solid var(--border);
}
.segmented button:last-child { border-right: none; }
.segmented button:hover { background: var(--bg-hover); color: var(--text); }
.segmented button.is-active { background: var(--accent-bg); color: var(--accent); font-weight: 600; }

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 900px) {
  .session-row { grid-template-columns: auto 1fr; }
  .session-actions { grid-column: 2; max-width: none; justify-content: flex-start; }
  .msg { grid-template-columns: 68px 1fr; gap: 9px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

@media (max-width: 700px) {
  .nav-label { display: none; }
  .nav-link { padding: 6px 8px; }
  .topbar-inner { gap: 10px; padding: 0 10px; }
  .main { padding: 14px 10px 30px; }
  .api-pill .api-text { display: none; }
  .api-pill { padding: 4px 7px; }
  .toast-stack { right: 10px; left: 10px; bottom: 10px; max-width: none; }
  .page-title { font-size: 17px; }
}

@media (max-width: 460px) {
  .brand-text { display: none; }
  .stat-value { font-size: 20px; }
  .msg { grid-template-columns: 1fr; }
  .msg-side { text-align: left; display: flex; gap: 8px; align-items: baseline; }
}

/* Respect des préférences de mouvement réduit */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* --------------------------------------------------------------------------
   Impression : le tableau de bord n'a aucun sens sur papier, mais on
   évite au moins les couleurs d’encre inversées
   -------------------------------------------------------------------------- */
@media print {
  .topbar, .footer, .toast-stack, .session-actions, .toolbar, .quick-bar { display: none !important; }
  body { background: #fff; color: #000; }
  .card { border-color: #ccc; break-inside: avoid; }
}

/* --------------------------------------------------------------------------
   Messagerie — choisir projet, session, message
   -------------------------------------------------------------------------- */
.msg-layout { align-items: start; }

.session-picker {
  max-height: 420px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-raised);
}
.session-picker .empty { padding: 28px 16px; }

.picker-group {
  padding: 7px 12px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--text-faint);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  border-top: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1;
}
.picker-group:first-child { border-top: 0; }

/* Chaque ligne est un <button> : le clavier doit fonctionner comme la
   souris, sans quoi la page n'est utilisable qu'à la souris. */
.picker-row {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 12px;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--border);
  color: inherit;
  font: inherit;
  cursor: pointer;
}
.picker-row:last-child { border-bottom: 0; }
.picker-row:hover { background: var(--bg-hover); }
.picker-row:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.picker-row.is-active {
  background: var(--accent-bg);
  box-shadow: inset 3px 0 0 var(--accent);
}

.picker-title {
  font-size: 13px;
  font-weight: 550;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.picker-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 3px;
  font-size: 11.5px;
  color: var(--text-dim);
}

.recent-row {
  display: flex;
  gap: 12px;
  padding: 7px 0;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 55%, transparent);
}
.recent-row:last-child { border-bottom: 0; }
.recent-when {
  flex: none;
  width: 86px;
  font-size: 11.5px;
  color: var(--text-faint);
}
.recent-what { min-width: 0; }

@media (max-width: 900px) {
  .recent-when { width: auto; }
}
