/* Tokens — charte graphique « style Hugo Buisson » (docs/charte-graphique-hugo.md) */
:root {
  --bg: #F6F5F1;
  --card: #FFFFFF;
  --zone-grise: #EFEEE9;
  --border: #E4E2DC;
  --text: #1F2937;
  --text-secondary: #6B7280;
  --success: #16A34A;
  --success-hover: #15803D;
  --danger: #DC2626;
  --warning: #D97706;
  --accent: #6366F1;
  --radius: 14px;
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.06);
  --sidebar-w: 210px;
  --sidebar-w-collapsed: 72px;
}

* { box-sizing: border-box; }

html, body {
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #D8D6CF; border-radius: 4px; }

/* --- Layout 3 panneaux (Phase 5, façon Hugo) --- */
.app-shell { display: flex; min-height: 100vh; }

/* Panneau 1 : navigation globale — icônes + libellés TOUJOURS visibles (demande Franck) */
.nav-global {
  width: 200px;
  flex-shrink: 0;
  background: var(--bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: 20px 12px 16px;
  gap: 8px;
}

.nav-global-logo {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--success);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 700;
  margin: 0 0 14px 6px;
  flex-shrink: 0;
}

.nav-agents {
  display: flex; flex-direction: column; align-items: stretch;
  gap: 2px;
  width: 100%;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  max-height: 260px;
  overflow-y: auto;
}

.nav-agent-avatar {
  position: relative;
  min-height: 34px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: flex-start;
  gap: 8px;
  font-size: 15px;
  padding: 5px 10px;
  text-decoration: none;
  flex-shrink: 0;
  transition: background .12s ease;
}
.nav-agent-avatar:hover { background: var(--zone-grise); }

.nav-items { display: flex; flex-direction: column; gap: 2px; width: 100%; align-items: stretch; }

.nav-item {
  position: relative;
  width: 100%; min-height: 40px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: flex-start;
  gap: 10px;
  font-size: 16px;
  padding: 8px 10px;
  color: var(--text);
  text-decoration: none;
  background: transparent;
  border: none;
  cursor: pointer;
}
.nav-item:hover { background: var(--zone-grise); }
.nav-item.active { background: #DCFCE7; }

/* Libellés TOUJOURS visibles à côté des icônes (plus de tooltips cachés) */
.nav-item .tooltip, .nav-agent-avatar .tooltip {
  display: inline;
  position: static;
  left: auto; top: auto;
  transform: none;
  background: none;
  color: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 0;
  border-radius: 0;
  white-space: nowrap;
  z-index: auto;
}
.nav-item:hover .tooltip, .nav-agent-avatar:hover .tooltip { display: inline; }

.nav-global-bottom { margin-top: auto; display: flex; flex-direction: column; align-items: stretch; gap: 2px; }
#panel-list-toggle { display: none; }

/* Panneau 2 : liste contextuelle (~240px) — Profils/Agents uniquement */
.panel-list {
  width: 240px;
  flex-shrink: 0;
  background: var(--bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.panel-list-search { padding: 18px 14px 12px; }
.panel-list-search .input { width: 100%; border-radius: 999px; }
.panel-list-items { flex: 1; overflow-y: auto; padding: 8px 12px 16px; display: flex; flex-direction: column; gap: 8px; }
.panel-list-item {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  border-radius: 10px;
  border-left: 3px solid transparent;
  text-decoration: none;
  color: var(--text);
}
.panel-list-item:hover { background: var(--zone-grise); }
.panel-list-item.selected { background: #FCE7F3; border-left-color: #EC4899; }
.plist-name { font-size: 13px; font-weight: 600; }
.plist-role { font-size: 11px; color: var(--text-secondary); }

.main-area { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.workspace-header {
  padding: 22px 32px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  background: var(--bg);
}
.breadcrumb { font-size: 13px; color: var(--text-secondary); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.breadcrumb a { color: var(--text-secondary); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; color: var(--text); }
.breadcrumb-current { color: var(--text); font-weight: 600; }
.breadcrumb-sep { color: var(--border); }

.header-icon-btn {
  width: 32px; height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  cursor: pointer;
  color: var(--text-secondary);
}
.header-icon-btn:hover { background: var(--zone-grise); }

/* Barre d'alerte (workspace, sous le header, seulement si anomalies) */
.alert-bar {
  display: none;
  align-items: center; justify-content: space-between;
  gap: 12px;
  background: #FEE2E2;
  color: #991B1B;
  padding: 10px 24px;
  font-size: 13px; font-weight: 600;
  border-bottom: 1px solid #FCA5A5;
}
.alert-bar.visible { display: flex; }
.alert-bar-btn {
  background: #fff; color: #991B1B; border: 1px solid #FCA5A5;
  border-radius: 8px; padding: 4px 12px; font-size: 12px;
  text-decoration: none; font-weight: 600; flex-shrink: 0;
}
.alert-bar-btn:hover { background: #FEF2F2; }

/* Raisonnement de l'agent visible (chain of thought), Phase 5 */
.reasoning-block {
  align-self: flex-start;
  max-width: 75%;
  background: #F3F2ED;
  border-radius: 10px;
  padding: 10px 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--text-secondary);
  display: flex; flex-direction: column; gap: 3px;
}
.reasoning-step { white-space: pre-wrap; line-height: 1.4; }

.page-content { padding: 36px 44px; flex: 1; overflow-y: auto; }

/* Sous 900px : panneau 2 replié en drawer, déclenché par le bouton ☰ de la nav globale */
@media (max-width: 900px) {
  .nav-global { width: 64px; padding: 14px 0 10px; align-items: center; }
  .nav-global-logo { margin: 0 0 14px; }
  .nav-agents { align-items: center; }
  .nav-agent-avatar { padding: 0; width: 34px; height: 34px; border-radius: 50%; justify-content: center; }
  .nav-items { align-items: center; }
  .nav-item { width: 40px; min-height: 40px; padding: 0; justify-content: center; }
  .nav-item .tooltip, .nav-agent-avatar .tooltip {
    display: none; position: absolute; left: 48px; top: 50%; transform: translateY(-50%);
    background: var(--text); color: #fff; font-size: 12px; padding: 4px 8px;
    border-radius: 6px; white-space: nowrap; z-index: 50;
  }
  .nav-item:hover .tooltip, .nav-agent-avatar:hover .tooltip { display: block; }
  .nav-global-bottom { align-items: center; }
  #panel-list-toggle { display: flex; }
  .panel-list {
    display: none;
    position: fixed;
    left: 64px; top: 0; bottom: 0;
    z-index: 45;
    box-shadow: 4px 0 16px rgba(0,0,0,0.15);
  }
  .panel-list.open { display: flex; }
}

/* --- Cards --- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 26px;
}
.card-title { font-size: 15px; font-weight: 600; color: var(--text); }
.card-hover { transition: box-shadow .15s ease, transform .15s ease; }
.card-hover:hover { box-shadow: 0 4px 14px rgba(0,0,0,0.08); transform: translateY(-1px); }

/* --- Buttons --- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 14px; font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
  text-decoration: none;
}
.btn-primary { background: var(--success); color: #fff; }
.btn-primary:hover { background: var(--success-hover); }
.btn-secondary { background: #fff; border-color: var(--border); color: #374151; }
.btn-secondary:hover { background: var(--zone-grise); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: #4f46e5; }
.btn-danger { background: #fff; border-color: #FCA5A5; color: var(--danger); }
.btn-danger:hover { background: #FEF2F2; }

/* --- Inputs --- */
.input {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 14px;
  color: var(--text);
}
.input:focus { outline: none; border-color: var(--accent); }

/* --- Pastilles de statut --- */
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.dot-green { background: var(--success); }
.dot-amber { background: var(--warning); }
.dot-red { background: var(--danger); }
.dot-grey { background: #D1D5DB; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
}
.badge-green { background: #DCFCE7; color: #15803D; }
.badge-amber { background: #FEF3C7; color: #B45309; }
.badge-red { background: #FEE2E2; color: #B91C1C; }
.badge-grey { background: var(--zone-grise); color: var(--text-secondary); }
.badge-accent { background: #E0E7FF; color: #4338CA; }

/* --- Avatars --- */
.avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.avatar-sm { width: 32px; height: 32px; font-size: 15px; }
.avatar-lg { width: 56px; height: 56px; font-size: 26px; }

/* Palette pastel pour fonds d'avatar, choisie par hash du nom côté template */
.pastel-1 { background: #DBEAFE; }
.pastel-2 { background: #FCE7F3; }
.pastel-3 { background: #FEF3C7; }
.pastel-4 { background: #D1FAE5; }
.pastel-5 { background: #EDE9FE; }
.pastel-6 { background: #FFE4E6; }

/* --- Listes --- */
.list-row {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--zone-grise);
  text-decoration: none;
  color: var(--text);
  transition: background .12s ease;
}
.list-row:last-child { border-bottom: none; }
.list-row:hover { background: #FAF9F6; }

/* --- Chat --- */
.chat-window {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 28px;
}
.bubble {
  max-width: 75%;
  padding: 14px 20px;
  border-radius: 16px;
  font-size: 14px;
  white-space: pre-wrap;
  line-height: 1.65;
}
.bubble-user { align-self: flex-end; background: #DCFCE7; border-bottom-right-radius: 4px; color: #14532D; }
.bubble-agent { align-self: flex-start; background: #F3F2ED; border-bottom-left-radius: 4px; color: var(--text); }

/* --- Pièces jointes --- */
.attachment-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.bubble .attachment-chip { display: flex; margin-bottom: 6px; }
.attachment-thumb {
  max-width: 220px;
  max-height: 160px;
  border-radius: 10px;
  object-fit: cover;
  display: block;
}
.attachment-file {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 13px;
  color: var(--text);
  text-decoration: none;
  max-width: 220px;
}
.attachment-file:hover { background: var(--zone-grise); }
.attachment-file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-file-size { color: var(--text-secondary); font-size: 11px; flex-shrink: 0; }
.attachment-remove {
  position: absolute;
  top: -6px; right: -6px;
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.attachment-remove:hover { background: #FEE2E2; color: var(--danger); }

.attachment-pending-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 8px;
}
.attachment-pending-row:empty { margin-top: 0; }

.chat-input-zone {
  position: relative;
  border-radius: var(--radius);
  transition: background .1s ease;
}
.chat-input-zone.dropzone-active {
  background: #E0E7FF;
  outline: 2px dashed var(--accent);
  outline-offset: 4px;
}
.attach-btn {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 16px;
  cursor: pointer;
}
.attach-btn:hover { background: var(--zone-grise); }

/* --- Organigramme (legacy, arbre statique) --- */
.org-node {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 14px 18px;
  text-decoration: none;
  color: var(--text);
  display: inline-flex;
  flex-direction: column;
  gap: 2px;
  min-width: 160px;
  transition: box-shadow .15s ease, transform .15s ease;
}
.org-node:hover { box-shadow: 0 4px 14px rgba(0,0,0,0.08); transform: translateY(-1px); }
.org-line { background: var(--border); }

/* --- Organigramme canvas (Phase 4, façon n8n) --- */
.org-canvas-viewport {
  position: relative;
  overflow: hidden;
  background-color: #EFEEE9;
  background-image: radial-gradient(circle, #DEDCD4 1px, transparent 1px);
  background-size: 22px 22px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  cursor: grab;
  touch-action: none;
  user-select: none;
}
.org-canvas-viewport.panning { cursor: grabbing; }
.org-canvas-world {
  position: absolute;
  top: 0; left: 0;
  transform-origin: 0 0;
  width: 1px; height: 1px;
}
.org-canvas-world svg { position: absolute; top: 0; left: 0; overflow: visible; pointer-events: none; }
.org-edge-hit { fill: none; stroke: transparent; stroke-width: 16; pointer-events: stroke; cursor: pointer; }
.org-edge-line { fill: none; stroke: var(--border); stroke-width: 2; pointer-events: none; }
.org-edge-group:hover .org-edge-line { stroke: var(--accent); }
.org-edge-remove { opacity: 0; transition: opacity .1s ease; pointer-events: all; cursor: pointer; }
.org-edge-group:hover .org-edge-remove { opacity: 1; }

.org-canvas-node {
  position: absolute;
  width: 172px;
  background: var(--card);
  border-radius: 12px;
  box-shadow: var(--shadow-card);
  border: 1px solid var(--border);
  padding: 10px 12px 12px;
  cursor: pointer;
  user-select: none;
}
.org-canvas-node:hover { box-shadow: 0 4px 14px rgba(0,0,0,0.1); border-color: var(--accent); }
.org-canvas-node.dragging { box-shadow: 0 8px 20px rgba(0,0,0,0.16); z-index: 20; cursor: grabbing; }
.org-node-head { display: flex; align-items: center; justify-content: space-between; }
.org-node-emoji { font-size: 20px; }
.org-node-name { font-weight: 600; font-size: 13px; margin-top: 4px; color: var(--text); }
.org-node-role { font-size: 11px; color: var(--text-secondary); }
.org-node-model { font-size: 10px; color: var(--text-secondary); margin-top: 2px; }
.org-node-chat {
  position: absolute; top: 8px; right: 8px;
  width: 22px; height: 22px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; background: var(--zone-grise); border: none; cursor: pointer;
}
.org-node-chat:hover { background: #E8E7E2; }
.org-port {
  position: absolute; left: 50%; transform: translateX(-50%);
  width: 14px; height: 14px; border-radius: 50%;
  background: #fff; border: 2px solid var(--accent);
  cursor: crosshair; z-index: 5;
}
.org-port:hover { background: var(--accent); }
.org-port-in { top: -8px; }
.org-port-out { bottom: -8px; }

/* Utilitaires texte */
.text-secondary { color: var(--text-secondary); }
.text-danger { color: var(--danger); }

/* --- Panneau de sélection de modèle (mode sombre, Phase 6 §A3) --- */
.mp-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(15, 23, 42, 0.72);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.mp-overlay.hidden { display: none; }
.mp-modal {
  width: 100%; max-width: 640px; max-height: 82vh;
  background: #0F172A;
  border-radius: 16px;
  overflow: hidden;
  display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.mp-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #1E293B;
}
.mp-title { color: #F8FAFC; font-weight: 700; font-size: 16px; }
.mp-close { background: transparent; border: none; color: #94A3B8; font-size: 16px; cursor: pointer; }
.mp-close:hover { color: #F8FAFC; }
.mp-body { padding: 16px 20px; overflow-y: auto; }
.mp-body.hidden { display: none; }
.mp-search { width: 100%; margin-bottom: 12px; }
.mp-providers { display: flex; flex-direction: column; gap: 10px; }
.mp-provider {
  background: #111827;
  border: 1px solid #1E293B;
  border-radius: 12px;
  padding: 10px 12px;
}
.mp-provider-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.mp-provider-name { color: #F8FAFC; font-weight: 600; font-size: 13px; }
.mp-auth-flag { font-size: 11px; font-weight: 600; }
.mp-auth-yes { color: #4ADE80; }
.mp-auth-no { color: #64748B; }
.mp-model-list { display: flex; flex-direction: column; gap: 2px; }
.mp-model-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: transparent; border: none; text-align: left;
  padding: 7px 8px; border-radius: 8px; cursor: pointer;
  color: #E2E8F0; font-size: 12px;
}
.mp-model-row:hover { background: #1E293B; }
.mp-model-name { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.mp-model-meta { color: #94A3B8; font-size: 11px; white-space: nowrap; }
.mp-price-na { color: #64748B; }
.mp-empty { color: #64748B; font-size: 12px; padding: 4px; }

.mp-confirm-card {
  background: #fff;
  border-radius: 12px;
  padding: 18px;
  color: var(--text);
}
.mp-back { background: none; border: none; color: var(--accent); font-size: 12px; cursor: pointer; padding: 0 0 12px; }
.mp-confirm-row { display: flex; align-items: center; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--zone-grise); font-size: 13px; }
.mp-confirm-label { color: var(--text-secondary); }
.mp-confirm-value { font-weight: 600; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.mp-confirm-value-new { color: var(--accent); }
.mp-field { margin-top: 14px; }
.mp-field-label { display: block; font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 4px; }
.mp-radio-row { display: flex; align-items: center; gap: 6px; font-size: 13px; margin-bottom: 4px; }
.mp-radio-row.mp-disabled { color: var(--text-secondary); opacity: .5; }
.mp-apply-btn { width: 100%; justify-content: center; margin-top: 16px; }

.mp-toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(10px);
  background: #111827; color: #F8FAFC;
  padding: 10px 18px; border-radius: 10px; font-size: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  opacity: 0; transition: opacity .2s ease, transform .2s ease;
  z-index: 200;
}
.mp-toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }
.mp-toast-error { background: #7F1D1D; }

/* Header stats page Modèles (style OpenRouter, fond sombre) */
.mp-stats-header {
  background: #0F172A;
  border-radius: var(--radius);
  padding: 20px 24px;
  color: #F8FAFC;
}
.mp-stats-title { font-size: 13px; color: #94A3B8; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 10px; }
.mp-stats-row { display: flex; gap: 32px; flex-wrap: wrap; }
.mp-stat { display: flex; flex-direction: column; }
.mp-stat-value { font-size: 26px; font-weight: 700; }
.mp-stat-label { font-size: 12px; color: #94A3B8; }
.models-model-row { padding: 4px 0; border-bottom: 1px solid var(--zone-grise); }
.models-model-row:last-child { border-bottom: none; }

/* Badge modèle cliquable (fiche agent) */
.model-badge-btn {
  display: inline-flex; align-items: center; gap: 4px;
  background: #E0E7FF; color: #4338CA;
  border: none; border-radius: 999px;
  padding: 3px 10px; font-size: 12px; font-weight: 600;
  cursor: pointer;
}
.model-badge-btn:hover { background: #C7D2FE; }

/* --- Dashboard (Phase 6 §B) --- */
.dash-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; flex-wrap: wrap; gap: 10px; }
.dash-greeting { font-size: 22px; font-weight: 700; }
.dash-sub { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }
.dash-pole-card {
  display: flex; align-items: center; gap: 14px;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow-card);
  padding: 16px 18px; text-decoration: none; color: var(--text);
}
.dash-pole-card:hover { box-shadow: 0 4px 14px rgba(0,0,0,0.08); }
.dash-pole-info { flex: 1; min-width: 0; }
.dash-pole-name { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.dash-pole-meta { font-size: 12px; color: var(--text-secondary); margin-top: 3px; }
.dash-pole-stats { display: flex; gap: 16px; text-align: right; flex-shrink: 0; }
.dash-pole-stat-value { font-weight: 700; font-size: 15px; }
.dash-pole-stat-label { font-size: 10px; color: var(--text-secondary); }
.dash-section-title { font-size: 15px; font-weight: 700; margin: 24px 0 10px; }
.dash-anomaly-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: #FEF2F2; border: 1px solid #FCA5A5; border-radius: 10px;
  padding: 10px 14px; font-size: 13px; color: #991B1B; margin-bottom: 8px;
}
.dash-bilan-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border-radius: 10px; box-shadow: var(--shadow-card);
  padding: 10px 14px; text-decoration: none; color: var(--text); margin-bottom: 8px;
}
.dash-bilan-text { flex: 1; min-width: 0; font-size: 13px; color: var(--text-secondary); }
.dash-shortcuts { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
