:root {
  --bg: #0b0f1a;
  --bg2: #111726;
  --panel: #151c2e;
  --line: #243049;
  --txt: #e7ecf5;
  --muted: #8a97b3;
  --accent: #4ade80;
  --accent2: #38bdf8;
  --warn: #fbbf24;
  --danger: #f87171;
  --working: #4ade80;
  --idle: #5b6680;
  --attention: #fbbf24;
  --alert: #f87171;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--txt);
  font-family: "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
}

body {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    "top"
    "stage"
    "status";
  height: 100vh;
}
/* La sidebar (alertes/décisions) n'apparaît qu'à la demande (clic sur une carte). */
body.has-side {
  grid-template-columns: 1fr 360px;
  grid-template-areas:
    "top  top"
    "stage side"
    "status status";
}

/* ---- Top bar : une seule rangée, jamais d'empilement des cartes ---- */
#topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 16px;
  min-width: 0;
  padding: 8px 16px;
  background: linear-gradient(180deg, var(--bg2), var(--bg));
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; flex-direction: column; gap: 6px; flex-shrink: 0; }
.brand-row { display: flex; align-items: center; gap: 12px; }
.logo { display: block; width: 32px; height: 32px; flex-shrink: 0; }
.title { font-weight: 800; letter-spacing: 3px; font-size: 18px; }
.clock { color: var(--muted); font-variant-numeric: tabular-nums; margin-left: 6px; font-size: 14px; }

.metrics {
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  gap: 8px;
  flex-wrap: nowrap;
  overflow: hidden;
}
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 6px 8px;
  flex: 1 1 0;
  min-width: 0;
  overflow: hidden;
}
.card .label {
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card .value {
  font-size: clamp(13px, 1.35vw, 20px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card .value small { font-size: 12px; color: var(--muted); font-weight: 400; }
.card.good .value { color: var(--accent); }
.card.warn .value { color: var(--warn); }
.card.danger .value { color: var(--danger); }
.card.clickable { cursor: pointer; transition: border-color .15s, box-shadow .15s; }
.card.clickable:hover { border-color: var(--accent2); }
.card.clickable .label::after { content: " ▸"; color: var(--muted); }
.card.active { border-color: var(--accent2); box-shadow: inset 0 0 0 1px var(--accent2); }
.card.active .label::after { content: " ▾"; color: var(--accent2); }

/* ---- Stage / canvas ---- */
#stage { grid-area: stage; position: relative; overflow: hidden; }
#stage.grabbing #farm { cursor: grabbing; }
#farm { display: block; width: 100%; height: 100%; cursor: grab; }

.cam-controls {
  position: absolute; right: 16px; bottom: 16px; z-index: 4;
  display: flex; flex-direction: column; gap: 6px;
}
.cam-controls button {
  width: 36px; height: 36px; border-radius: 10px;
  background: rgba(21, 28, 46, 0.92); color: var(--txt);
  border: 1px solid var(--line); font-size: 18px; font-weight: 700;
  cursor: pointer; line-height: 1;
}
.cam-controls button:hover { border-color: var(--accent2); color: var(--accent2); }

.tooltip {
  position: absolute;
  background: rgba(8, 12, 22, 0.96);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  pointer-events: none;
  max-width: 260px;
  line-height: 1.5;
  z-index: 5;
}
.tooltip .t-title { font-weight: 700; }
.tooltip .t-hint { color: var(--muted); font-size: 11px; margin-top: 2px; }
/* Utilitaire : doit primer sur les `display` plus spécifiques (#side, .chat, .panel)
   sinon l'élément ne se masque jamais (bug d'ordre/spécificité). */
.hidden { display: none !important; }

/* ---- Side panels ---- */
#side {
  grid-area: side;
  background: var(--bg2);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.panel { display: flex; flex-direction: column; flex: 1; min-height: 0; border-bottom: 1px solid var(--line); }
.panel h2 {
  font-size: 13px; text-transform: uppercase; letter-spacing: 1px;
  padding: 12px 16px; color: var(--muted); display: flex; align-items: center; gap: 8px;
}
.badge {
  background: var(--line); color: var(--txt); border-radius: 10px;
  padding: 1px 8px; font-size: 12px; margin-left: auto;
}
.panel-close {
  background: none; border: none; color: var(--muted); font-size: 18px;
  cursor: pointer; line-height: 1; padding: 0 2px 0 8px;
}
.panel-close:hover { color: var(--txt); }
.feed { overflow-y: auto; padding: 0 12px 12px; flex: 1; }
.item {
  background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--muted);
  border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; font-size: 12px;
}
.item.alert { border-left-color: var(--alert); }
.item.human { border-left-color: var(--attention); }
.item.manager { border-left-color: var(--accent2); }
.item .head { display: flex; justify-content: space-between; gap: 8px; }
.item .bot { font-weight: 700; }
.item .when { color: var(--muted); font-size: 11px; }
.item .desc { color: var(--muted); margin-top: 4px; line-height: 1.4; }
.empty { color: var(--muted); font-size: 12px; padding: 8px 4px; }
.resolve { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; align-items: center; }
.rbtn {
  background: var(--line); color: var(--txt); border: 1px solid var(--line);
  border-radius: 8px; padding: 4px 8px; font-size: 11px; cursor: pointer;
}
.rbtn:hover { border-color: var(--accent2); }
.rbtn.ok:hover { border-color: var(--accent); }
.rbtn.no:hover { border-color: var(--danger); }
.rbtn:disabled { opacity: .5; cursor: default; }
.rinput {
  flex: 1; min-width: 80px; background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 4px 8px; color: var(--txt); font-size: 11px; outline: none;
}
.rinput:focus { border-color: var(--accent2); }

/* ---- Status bar ---- */
#statusbar {
  grid-area: status;
  display: flex; align-items: center; gap: 24px;
  padding: 8px 20px; background: var(--bg2); border-top: 1px solid var(--line);
  font-size: 12px;
}
.budget { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.bar { width: 220px; height: 8px; background: var(--line); border-radius: 6px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); transition: width .5s, background .5s; }
.conn { margin-left: auto; color: var(--accent); }
.conn.down { color: var(--danger); }

/* ---- Chat manager (drawer flottant) ---- */
.chat-toggle {
  position: fixed; left: 24px; bottom: 56px; z-index: 20;
  width: 54px; height: 54px; border-radius: 50%;
  background: var(--accent2); color: #04121d; border: none;
  font-size: 24px; cursor: pointer; box-shadow: 0 6px 18px rgba(0,0,0,.45);
}
.chat-toggle:hover { filter: brightness(1.08); }

/* Ancré en bas-GAUCHE (au-dessus de la scène) pour ne jamais masquer la sidebar
   des alertes/décisions, qui occupe les 360px de droite. */
.chat {
  position: fixed; left: 24px; bottom: 56px; z-index: 21;
  width: 380px; max-width: calc(100vw - 408px); height: 520px; max-height: calc(100vh - 100px);
  display: flex; flex-direction: column;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0,0,0,.55); overflow: hidden;
}
.chat-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; background: var(--panel); border-bottom: 1px solid var(--line);
  font-weight: 700; font-size: 14px;
}
.chat-actions { display: flex; align-items: center; gap: 6px; }
.chat-btn {
  background: none; border: 1px solid transparent; color: var(--muted);
  font-size: 20px; cursor: pointer; line-height: 1; border-radius: 8px; padding: 2px 6px;
}
.chat-btn:hover { color: var(--txt); border-color: var(--line); background: var(--bg); }
.chat-bu {
  background: var(--bg); color: var(--txt); border: 1px solid var(--line);
  border-radius: 8px; padding: 3px 6px; font-size: 12px; cursor: pointer; max-width: 160px;
}
.chat-bu:hover { border-color: var(--accent2); }
.budget-bu { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.bu-chip {
  border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px;
  font-size: 11px; color: var(--muted); background: var(--bg);
}
.bu-chip.over { color: var(--danger); border-color: var(--danger); }
.chat-log { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 85%; padding: 8px 12px; border-radius: 12px; font-size: 13px; line-height: 1.45; white-space: pre-wrap; word-break: break-word; }
.msg.user { align-self: flex-end; background: var(--accent2); color: #04121d; }
.msg.bot { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); }
.msg.bot.pending { color: var(--muted); font-style: italic; }
.msg a { text-decoration: underline; text-underline-offset: 2px; }
.msg.user a { color: #022c43; font-weight: 600; }
.msg.user a:hover { color: #000; }
.msg.bot a { color: var(--accent2); }
.msg.bot a:hover { color: #7dd3fc; }
/* Réponse manager en blocs : résumé clair + détails repliables (étapes). */
.msg-summary { white-space: pre-wrap; }
.msg-steps { margin-top: 8px; border-top: 1px solid var(--line); padding-top: 6px; }
.msg-steps > summary {
  cursor: pointer; font-size: 11.5px; color: var(--muted); list-style: none;
  user-select: none; padding: 2px 0;
}
.msg-steps > summary::-webkit-details-marker { display: none; }
.msg-steps > summary::before { content: "▸ "; }
.msg-steps[open] > summary::before { content: "▾ "; }
.step {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-size: 12px; padding: 4px 0; border-top: 1px dashed var(--line);
}
.step:first-of-type { border-top: none; }
.step-ic { flex: 0 0 auto; }
.step-who { font-weight: 600; color: var(--txt); }
.step-st { color: var(--muted); }
.step-cost { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.step-link { color: var(--accent2); }
/* Rapport d'auto-vérification post-encodage. */
.verify { margin: 2px 0 4px 22px; display: flex; flex-direction: column; gap: 2px; }
.vk { font-size: 11.5px; color: var(--muted); }
.vk-fail { color: var(--danger); }
.vk-warn { color: var(--warn); }
.vk-detail { opacity: 0.8; }
.chat-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); align-items: flex-end; }
.chat-input {
  flex: 1; background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 12px; color: var(--txt); font-size: 13px; outline: none;
  font-family: inherit; line-height: 1.4; resize: none; overflow-y: auto;
  min-height: 38px; max-height: 160px;
}
.chat-input:focus { border-color: var(--accent2); }
.chat-send {
  background: var(--accent2); color: #04121d; border: none; border-radius: 10px;
  width: 42px; height: 38px; flex: none; font-size: 16px; cursor: pointer;
}
.chat-send:disabled { opacity: .5; cursor: default; }

/* ---- Mode développeur : panneau smoke (admin) ---- */
.dev-toggle {
  position: fixed; left: 88px; bottom: 56px; z-index: 20;
  width: 54px; height: 54px; border-radius: 50%;
  background: var(--warn); color: #1a1405; border: none;
  font-size: 22px; cursor: pointer; box-shadow: 0 6px 18px rgba(0,0,0,.45);
}
.dev-toggle:hover { filter: brightness(1.08); }
.dev {
  position: fixed; left: 24px; bottom: 56px; z-index: 22;
  width: 520px; max-width: calc(100vw - 408px); height: 600px; max-height: calc(100vh - 90px);
  display: flex; flex-direction: column;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0,0,0,.55); overflow: hidden;
}
.dev-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; background: var(--panel); border-bottom: 1px solid var(--line);
  font-weight: 700; font-size: 14px;
}
.dev-actions { display: flex; align-items: center; gap: 6px; }
.dev-actions .chat-btn { font-size: 13px; padding: 4px 8px; }
.dev-sub { color: var(--muted); font-size: 11px; padding: 8px 14px 0; line-height: 1.4; }
.dev-sub code { background: var(--bg); padding: 1px 5px; border-radius: 5px; }
.dev-body { flex: 1; overflow-y: auto; padding: 10px 14px 14px; }
.dev-group { margin-top: 12px; }
.dev-group-head {
  color: var(--accent2); font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .5px; margin-bottom: 6px; display: flex; align-items: center; gap: 8px;
}
.dev-count { background: var(--line); color: var(--muted); border-radius: 10px; padding: 0 7px; font-size: 11px; }
.dev-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 10px; margin-bottom: 8px;
}
.dev-card-head { display: flex; align-items: center; gap: 10px; }
.dev-card-meta { flex: 1; min-width: 0; }
.dev-card-name { font-size: 13px; font-weight: 600; }
.dev-card-sub { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 3px; }
.dev-chip {
  border: 1px solid var(--line); border-radius: 999px; padding: 0 7px;
  font-size: 10px; color: var(--muted); background: var(--bg);
  text-transform: uppercase; letter-spacing: .3px;
}
.dev-kind { color: var(--accent2); border-color: var(--accent2); }
.dev-input {
  color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; max-width: 100%;
}
.dev-badge {
  flex: none; min-width: 46px; text-align: center; border-radius: 8px; padding: 3px 6px;
  font-size: 10px; font-weight: 700; letter-spacing: .5px; background: var(--line); color: var(--muted);
}
.dev-badge.running { background: var(--accent2); color: #04121d; }
.dev-badge.pass { background: var(--accent); color: #04210f; }
.dev-badge.fail { background: var(--danger); color: #2a0707; }
.dev-badge.review { background: var(--warn, #e0a534); color: #241802; }
.dev-vtag {
  display: inline-block; margin: 0 0 6px 6px; padding: 1px 7px; border-radius: 999px;
  font-size: 11px; background: var(--bg); border: 1px solid var(--line); color: var(--muted);
}
.dev-run {
  flex: none; background: var(--bg); border: 1px solid var(--line); color: var(--txt);
  border-radius: 8px; width: 30px; height: 28px; cursor: pointer; font-size: 12px;
}
.dev-run:hover { border-color: var(--accent); }
.dev-run:disabled { opacity: .4; cursor: default; }
.dev-result { margin-top: 8px; border-top: 1px dashed var(--line); padding-top: 8px; }
.dev-ms { float: right; color: var(--muted); font-size: 11px; }
.dev-checks { display: flex; flex-direction: column; gap: 3px; }
.dev-chk { font-size: 12px; line-height: 1.4; }
.dev-chk.ok { color: var(--accent); }
.dev-chk.fail { color: var(--danger); }
.dev-chk-det { color: var(--muted); }
.dev-chk-det code { background: var(--bg); padding: 0 4px; border-radius: 4px; color: var(--txt); }
.dev-trace-wrap { margin-top: 8px; }
.dev-trace-wrap > summary { cursor: pointer; color: var(--muted); font-size: 12px; }
.dev-trace-sum { font-size: 12px; line-height: 1.45; margin: 6px 0; white-space: pre-wrap; }
.dev-reply { color: var(--muted); }
.dev-trace-meta { color: var(--muted); font-size: 11px; margin: 4px 0; }
.dev-errs { color: var(--danger); font-size: 12px; margin: 4px 0; }
.dev-steps { display: flex; flex-direction: column; gap: 3px; margin: 6px 0; }
.dev-json { margin-top: 6px; }
.dev-json > summary { cursor: pointer; color: var(--accent2); font-size: 11px; }
.dev-json pre {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px; font-size: 11px; overflow-x: auto; max-height: 260px; margin: 4px 0 0;
}

/* ---- Navigation (Supervision / Bots / Outils) ---- */
.nav { display: flex; gap: 6px; }
.nav-btn {
  background: var(--panel); color: var(--muted); border: 1px solid var(--line);
  border-radius: 9px; padding: 7px 14px; font-size: 13px; font-weight: 600;
  cursor: pointer; font-family: inherit; transition: color .15s, border-color .15s, background .15s;
}
.nav-btn:hover { color: var(--txt); border-color: var(--accent2); }
.nav-btn.active { color: #04121d; background: var(--accent2); border-color: var(--accent2); }

/* ---- Bibliothèque (bots & outils) ---- */
#library { grid-area: stage; overflow-y: auto; padding: 22px 26px 40px; }
.lib-head { margin-bottom: 18px; }
.lib-head h2 { font-size: 22px; font-weight: 800; letter-spacing: 1px; }
.lib-sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
.lib-cat {
  color: var(--accent2); font-size: 12px; text-transform: uppercase; letter-spacing: 1.5px;
  font-weight: 700; margin: 22px 0 10px;
}
.lib-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.lib-grid-mini { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 12px; }
.lib-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 16px 18px; display: flex; flex-direction: column; gap: 8px;
  min-width: 0;
}
.lib-card:hover { border-color: var(--line); }
/* Carte compacte : portrait + nom, cliquable */
.lib-card-mini {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px 8px 10px; display: flex; flex-direction: column; align-items: center;
  gap: 7px; cursor: pointer; text-align: center;
  transition: border-color 0.15s, transform 0.12s, box-shadow 0.15s;
}
.lib-card-mini:hover {
  border-color: var(--accent); transform: translateY(-3px);
  box-shadow: 0 6px 18px rgba(0,0,0,0.35);
}
.lc-mini-portrait { line-height: 0; }
.lc-mini-portrait .lc-portrait { width: 64px; height: 64px; border-radius: 10px; }
.lc-mini-portrait .lc-emoji { font-size: 32px; display: block; line-height: 64px; }
.lc-mini-name { font-size: 12px; font-weight: 700; color: var(--txt); line-height: 1.3; word-break: break-word; }
.lc-mini-role { font-size: 10px; color: var(--muted); line-height: 1.3; }
/* Statut boutique : actif/inactif d'un bot dans le workspace sélectionné */
.lc-status {
  font-size: 10px; font-weight: 700; letter-spacing: 0.02em; line-height: 1;
  padding: 3px 8px; border-radius: 999px; border: 1px solid transparent;
}
.lc-status.on { color: #16331f; background: #4ade80; }
.lc-status.off { color: var(--muted); background: transparent; border-color: var(--line); }
.lib-card-mini.is-off { opacity: 0.5; filter: grayscale(0.6); }
.lib-card-mini.is-off:hover { opacity: 0.85; }
/* Spinner chargement */
@keyframes lib-spin { to { transform: rotate(360deg); } }
.lib-loading { display: flex; align-items: center; justify-content: center; padding: 60px 0; }
.lib-spinner {
  width: 30px; height: 30px;
  border: 3px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: lib-spin 0.75s linear infinite;
}
.lib-card .lc-head { display: flex; align-items: flex-start; gap: 10px; }
.lib-card-detail .lc-head-portrait { align-items: center; gap: 12px; }
.lc-head-text {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
}
.lc-portrait {
  width: 56px; height: 56px; flex-shrink: 0;
  border-radius: 12px; border: 1px solid var(--line);
  background-color: var(--bg); background-repeat: no-repeat;
  image-rendering: pixelated; image-rendering: crisp-edges;
}
.lib-card .lc-emoji { font-size: 22px; line-height: 1; }
.lib-card .lc-name { font-size: 16px; font-weight: 700; line-height: 1.25; }
.lib-card .lc-role {
  font-size: 11px; color: var(--accent); border: 1px solid var(--line);
  border-radius: 8px; padding: 2px 8px; max-width: 100%;
  line-height: 1.35; white-space: normal;
}
.lib-card .lc-summary { color: var(--muted); font-size: 13px; line-height: 1.5; }
.lib-card .lc-actions { display: flex; flex-direction: column; gap: 7px; margin-top: 4px; }
.lc-act { border-top: 1px solid var(--line); padding-top: 7px; }
.lc-act .lc-act-label { font-size: 13px; font-weight: 600; }
.lc-act .lc-act-desc { font-size: 12px; color: var(--muted); line-height: 1.45; }
.lib-card .lc-used { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }
.lc-chip {
  font-size: 11px; color: var(--muted); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 1px 8px;
}

/* Extras bot : modèle + mots-clés de routage */
.lc-extras { display: flex; flex-direction: column; gap: 4px; margin-top: 4px; }
.lc-extras .lib-cat { margin: 10px 0 6px; }
.lc-model { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px; }
.lc-model .lib-cat { margin: 10px 6px 6px 0; }
.lc-model-name {
  font-size: 12px; color: var(--accent); background: var(--bg);
  border: 1px solid var(--line); border-radius: 6px; padding: 1px 7px;
}
.lc-model-role { font-size: 11px; color: var(--muted); }
.lc-meta-block { display: flex; flex-direction: column; }
.lc-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.lc-meta-nf .lc-chip { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, var(--line)); }

/* Panneau agent (bibliothèque + live) */
.agent-detail { padding: 12px 14px 20px; }
.lib-card-detail { margin: 0; }
.live-block { margin-top: 6px; }
.live-block .lib-cat { margin: 12px 0 8px; }
.live-grid { display: flex; flex-direction: column; gap: 6px; }
.live-stat {
  display: flex; justify-content: space-between; gap: 10px; font-size: 12px;
  padding: 6px 8px; background: var(--bg2); border-radius: 8px; border: 1px solid var(--line);
}
.live-stat .live-lbl { color: var(--muted); }
.live-stat .live-val { font-weight: 600; text-align: right; }
.live-stat.good .live-val { color: var(--accent); }
.live-stat.warn .live-val { color: var(--warn); }
.live-stat.danger .live-val { color: var(--danger); }
.lib-link-btn {
  margin-top: 12px; align-self: flex-start;
  background: transparent; color: var(--accent2); border: 1px solid var(--line);
  border-radius: 9px; padding: 7px 12px; font-size: 12px; font-weight: 600;
  cursor: pointer; font-family: inherit;
}
.lib-link-btn:hover { border-color: var(--accent2); background: rgba(56, 189, 248, 0.08); }

/* ---- Vue Carte (graph force-dirigé) ---- */
#map-view {
  grid-area: stage;
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
  background: var(--bg);
  min-height: 0;
}
.map-head { padding: 12px 24px 6px; }
.map-head h2 { font-size: 20px; font-weight: 800; letter-spacing: 1px; }
#map-canvas {
  width: 100%;
  height: 100%;
  min-height: 0;
  display: block;
  cursor: crosshair;
  background: #080e1c;
}
.map-tooltip {
  position: fixed;
  background: #1a2540;
  color: var(--txt);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
  pointer-events: none;
  white-space: nowrap;
  z-index: 200;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}

/* ---- Workspace (Business Unit) dans le header ---- */
.workspace {
  display: flex; align-items: center; gap: 8px;
  flex-shrink: 0;
  padding: 4px 8px;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 10px;
}
.workspace.hidden { display: none; }
.workspace .ws-icon { font-size: 14px; }
.ws-switch, .ws-label {
  background: transparent; color: var(--txt); border: none;
  font-family: inherit; font-size: 13px; font-weight: 700; cursor: pointer;
  max-width: 220px;
}
.ws-switch:focus { outline: none; }
.ws-switch option { background: var(--panel); color: var(--txt); }
.ws-logout {
  background: transparent; color: var(--muted); border: 1px solid var(--line);
  border-radius: 8px; padding: 2px 8px; font-size: 13px; cursor: pointer; font-family: inherit;
}
.ws-logout:hover { color: var(--danger); border-color: var(--danger); }

/* ---- Écran de connexion (clé API) ---- */
.login-overlay {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 30%, #0e1424 0%, #070a12 100%);
}
.login-overlay.hidden { display: none; }
.login-card {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  width: min(360px, 90vw); padding: 32px 28px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
.login-logo { margin-bottom: 4px; }
.login-card h1 { font-size: 22px; font-weight: 800; letter-spacing: 1px; }
.login-sub { color: var(--muted); font-size: 13px; text-align: center; line-height: 1.4; }
.login-input {
  width: 100%; padding: 11px 13px; margin-top: 6px;
  background: var(--bg2); color: var(--txt);
  border: 1px solid var(--line); border-radius: 10px;
  font-family: inherit; font-size: 14px;
}
.login-input:focus { outline: none; border-color: var(--accent2); }
.login-btn {
  width: 100%; padding: 11px; margin-top: 4px;
  background: var(--accent2); color: #04101c; border: none; border-radius: 10px;
  font-family: inherit; font-size: 14px; font-weight: 800; cursor: pointer;
}
.login-btn:hover { filter: brightness(1.08); }
.login-btn:disabled { opacity: 0.6; cursor: default; }
.login-error { color: var(--danger); font-size: 12.5px; text-align: center; margin-top: 2px; }

/* --- Onglet Améliorations (réunion / HITL) --- */
#improve-view { grid-area: stage; overflow-y: auto; padding: 22px 26px 48px; background: var(--bg); }
.imp-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.imp-head h2 { font-size: 20px; font-weight: 800; letter-spacing: 1px; }
.imp-head-txt .lib-sub { max-width: 640px; line-height: 1.45; }
.imp-controls { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.imp-select, .imp-btn {
  background: var(--panel); border: 1px solid var(--line); color: var(--text, #d6e2ff);
  border-radius: 8px; padding: 7px 11px; font-family: inherit; font-size: 13px; cursor: pointer;
}
.imp-btn:hover, .imp-select:hover { border-color: var(--accent2); }
.imp-status { margin: 14px 0 0; padding: 9px 12px; border-radius: 8px; font-size: 13px;
  border: 1px solid var(--line); background: var(--panel); }
.imp-status.ok { border-color: var(--accent); color: var(--accent); }
.imp-status.err { border-color: var(--danger); color: var(--danger); }
.imp-list { margin-top: 16px; display: grid; gap: 14px; max-width: 900px; }
.imp-empty { color: var(--muted); padding: 40px 0; text-align: center; }
.imp-item {
  background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--accent2);
  border-radius: 12px; padding: 15px 17px;
}
.imp-item.imp-lim { border-left-color: var(--warn); }
.imp-item.imp-applied { border-left-color: var(--accent); opacity: 0.92; }
.imp-item.imp-rejected, .imp-item.imp-reverted,
.imp-item.imp-resolved, .imp-item.imp-dismissed { border-left-color: var(--muted); opacity: 0.62; }
.imp-item-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.imp-badge { font-size: 10.5px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.6px;
  padding: 2px 8px; border-radius: 20px; }
.imp-badge-prop { background: rgba(56,189,248,0.16); color: var(--accent2); }
.imp-badge-lim { background: rgba(251,191,36,0.16); color: var(--warn); }
.imp-badge-st { background: var(--bg2); color: var(--muted); border: 1px solid var(--line); }
.imp-badge-low { background: rgba(251,191,36,0.14); color: var(--warn); }
.imp-badge-recur { background: rgba(248,113,113,0.16); color: var(--danger); }
.imp-st-applied, .imp-st-resolved { color: var(--accent); }
.imp-st-rejected, .imp-st-reverted, .imp-st-dismissed { color: var(--muted); }
.imp-meta { color: var(--muted); font-size: 11.5px; margin-left: auto; }
.imp-title { font-size: 15.5px; font-weight: 700; margin: 9px 0 6px; }
.imp-why, .imp-need, .imp-sum { line-height: 1.5; margin: 4px 0; font-size: 13.5px; }
.imp-target { font-size: 12.5px; color: var(--muted); margin: 6px 0; }
.imp-target code, .imp-evid code { color: var(--accent2); }
.imp-warn { color: var(--warn); font-weight: 700; }
.imp-review { font-size: 12.5px; color: var(--muted); font-style: italic; margin: 6px 0; }
.imp-err { color: var(--danger); font-size: 12.5px; }
.imp-diff, .imp-evid { margin: 8px 0; }
.imp-diff summary, .imp-evid summary { cursor: pointer; color: var(--accent2); font-size: 12.5px; }
.imp-pre { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px;
  margin-top: 8px; font-size: 12px; line-height: 1.5; overflow-x: auto; white-space: pre-wrap; }
.imp-pre .d-del { color: var(--danger); display: block; }
.imp-pre .d-add { color: var(--accent); display: block; }
.imp-evid ul { margin: 8px 0 0; padding-left: 16px; font-size: 12px; line-height: 1.7; color: var(--muted); }
.imp-ev-meta { color: var(--muted); }
.imp-actions { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.imp-actions button {
  border-radius: 8px; padding: 7px 15px; font-family: inherit; font-size: 13px; font-weight: 700;
  cursor: pointer; border: 1px solid var(--line); background: var(--bg2); color: var(--text, #d6e2ff);
}
.imp-approve { border-color: var(--accent); color: var(--accent); }
.imp-approve:hover { background: rgba(74,222,128,0.12); }
.imp-resolve:hover { border-color: var(--accent); color: var(--accent); }
.imp-reject:hover, .imp-revert:hover { border-color: var(--danger); color: var(--danger); }
.imp-impact:hover, .imp-reopen:hover { border-color: var(--accent2); color: var(--accent2); }
.imp-actions button:disabled { opacity: 0.5; cursor: default; }
.imp-result { font-size: 12.5px; color: var(--muted); }
.imp-result.ok { color: var(--accent); }
.imp-result.err { color: var(--danger); }
