.nbd-page { max-width: 1100px; margin: 0 auto; padding: 1rem 1.5rem 2rem; height: calc(100vh - 60px); display: flex; flex-direction: column; }

.nbd-toolbar {
  display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1rem;
  .btn-back {
    display: inline-flex; align-items: center; gap: 0.35rem; flex-shrink: 0;
    padding: 0.4rem 0.7rem; border-radius: 6px;
    border: 1px solid rgba(255,255,255,0.12); background: rgba(255,255,255,0.04);
    color: inherit; cursor: pointer; font-size: 0.85rem;
    &:hover { background: rgba(255,255,255,0.09); }
  }
  .nbd-title {
    flex: 1; padding: 0.4rem 0.6rem; border-radius: 6px; font-size: 1.15rem; font-weight: 600;
    border: 1px solid transparent; background: transparent; color: inherit;
    &:hover, &:focus { border-color: rgba(255,255,255,0.14); background: rgba(255,255,255,0.04); outline: none; }
  }
}

.nbd-grid {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: 280px 1fr; gap: 1rem;
}

/* Sources */
.nbd-sources {
  display: flex; flex-direction: column; gap: 0.5rem; overflow-y: auto;
  border: 1px solid rgba(255,255,255,0.08); border-radius: 10px; padding: 0.75rem;
}
.nbd-sources-head {
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
  h3 { display: flex; align-items: center; gap: 0.4rem; margin: 0; font-size: 0.95rem; }
}
.btn-upload {
  display: inline-flex; align-items: center; gap: 0.3rem; cursor: pointer;
  padding: 0.3rem 0.55rem; border-radius: 6px; font-size: 0.78rem;
  border: 1px solid rgba(102,126,234,0.4); color: #8ea2ff; background: rgba(102,126,234,0.1);
  &:hover { background: rgba(102,126,234,0.2); }
  &.disabled { opacity: 0.6; cursor: default; }
}
.nbd-upload-error { color: #e88; font-size: 0.8rem; margin: 0.2rem 0; }

// Compteur de sources actives — ambre quand une partie est décochée, pour
// rappeler que le chat ne voit pas tout.
.nbd-sources-hint {
  font-size: 0.72rem;
  color: var(--color-text-muted, #9aa0aa);
  margin: 0.1rem 0 0.2rem;

  &.partial { color: #fbbf24; }
}

.nbd-source {
  display: flex; align-items: flex-start; gap: 0.5rem; padding: 0.5rem;
  border-radius: 7px; background: rgba(255,255,255,0.03);
  lucide-icon.ok { color: #6bd08a; }
  lucide-icon.fail { color: #e88; }
  lucide-icon.busy { color: #e0c074; }

  // Case « source utilisée par le chat » (sources prêtes uniquement).
  .nbd-source-check {
    margin: 2px 0 0;
    accent-color: #6bd08a;
    cursor: pointer;
    flex-shrink: 0;
  }

  // Source décochée : grisée = hors du périmètre du chat et de l'analyse.
  &.nbd-source--off {
    opacity: 0.5;
  }

  .nbd-source-info { flex: 1; min-width: 0; }
  .nbd-source-name { font-size: 0.85rem; font-weight: 500; word-break: break-word; }
  .nbd-source-meta { font-size: 0.72rem; color: var(--color-text-muted, #9aa0aa); }
  .nbd-source-del {
    border: none; background: none; color: #e88; cursor: pointer; padding: 0.15rem;
    border-radius: 4px; &:hover { background: rgba(224,90,90,0.15); }
  }
}

/* Chat */
.nbd-chat {
  display: flex; flex-direction: column; min-height: 0;
  // min-width: 0 indispensable : enfant de grille (colonne 1fr), sinon sa largeur
  // MINIMALE devient celle de la plus longue ligne insécable d'un message
  // (tableau markdown, longue URL…) et le chat pousse toute la page hors écran.
  min-width: 0;
  border: 1px solid rgba(255,255,255,0.08); border-radius: 10px;
}

// Barre d'actions du chat : archives + vider (ou bandeau « archive en lecture seule »).
.nbd-chat-head {
  display: flex; align-items: center; gap: 0.4rem;
  padding: 0.45rem 0.6rem; border-bottom: 1px solid rgba(255,255,255,0.08);

  .nbd-chat-head-spacer { flex: 1; }

  .nbd-archive-banner {
    flex: 1;
    display: inline-flex; align-items: center; gap: 0.35rem;
    font-size: 0.8rem; color: #e0c074; font-style: italic;
  }

  // Badge « N archive(s) en référence » : rappelle que le contexte du chat
  // inclut d'anciennes conversations, même panneau fermé.
  .nbd-ref-badge {
    display: inline-flex; align-items: center; gap: 0.3rem;
    padding: 0.2rem 0.5rem; border-radius: 999px; font-size: 0.74rem;
    background: rgba(168,130,255,0.12); border: 1px solid rgba(168,130,255,0.4);
    color: #c4a8ff;
  }

  .nbd-chat-btn {
    display: inline-flex; align-items: center; gap: 0.3rem;
    padding: 0.28rem 0.55rem; border-radius: 6px; font-size: 0.78rem;
    border: 1px solid rgba(255,255,255,0.12); background: rgba(255,255,255,0.04);
    color: inherit; cursor: pointer;
    &:hover:not(:disabled) { background: rgba(255,255,255,0.09); }
    &.active { border-color: #667eea; }
    &:disabled { opacity: 0.45; cursor: default; }

    &--danger {
      color: #e88; border-color: rgba(224,90,90,0.35);
      &:hover:not(:disabled) { background: rgba(224,90,90,0.12); }
    }
  }
}

// Panneau des conversations archivées.
.nbd-archives {
  display: flex; flex-direction: column; gap: 0.3rem;
  padding: 0.5rem 0.6rem; border-bottom: 1px solid rgba(255,255,255,0.08);

  .nbd-archives-help {
    margin: 0 0 0.2rem;
    font-size: 0.74rem;
    color: var(--color-text-muted, #9aa0aa);
  }

  .nbd-archive-row {
    display: flex; align-items: center; gap: 0.45rem;

    // Archive cochée en référence : léger liseré violet pour la repérer.
    &.referenced .nbd-archive-item { border-color: rgba(168,130,255,0.5); }
  }

  .nbd-archive-check {
    accent-color: #c4a8ff;
    cursor: pointer;
    flex-shrink: 0;
  }

  .nbd-archive-item {
    flex: 1;
    display: inline-flex; align-items: center; gap: 0.4rem;
    padding: 0.35rem 0.55rem; border-radius: 6px; font-size: 0.82rem;
    border: 1px solid rgba(255,255,255,0.08); background: rgba(255,255,255,0.03);
    color: inherit; cursor: pointer; text-align: left;
    &:hover { background: rgba(255,255,255,0.08); }
  }
}
.nbd-messages { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: 0.85rem; }
.nbd-empty { color: var(--color-text-muted, #9aa0aa); font-style: italic; }

.nbd-msg {
  max-width: 88%;
  .nbd-msg-role {
    display: flex; align-items: center; gap: 0.3rem;
    font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.04em;
    color: var(--color-text-muted, #9aa0aa); margin-bottom: 0.2rem;
  }
  // overflow-wrap: anywhere : autorise la coupure DANS une séquence insécable
  // (ligne de tableau markdown, URL) plutôt que de déborder du conteneur.
  .nbd-msg-content { white-space: pre-wrap; line-height: 1.5; overflow-wrap: anywhere; }

  // Rendu markdown des messages assistant (même esthétique que ai-chat-drawer).
  // white-space normal : marked génère des <p>/<li>/<br>, pre-wrap doublerait
  // les espacements entre blocs.
  .nbd-msg-content.md {
    white-space: normal;

    > :first-child { margin-top: 0; }
    > :last-child  { margin-bottom: 0; }

    p { margin: 0 0 0.5em; }
    p:last-child { margin-bottom: 0; }

    h1, h2, h3, h4, h5, h6 {
      margin: 0.75em 0 0.35em;
      font-weight: 600;
      color: #f3f4f6;
      line-height: 1.25;
    }
    h1 { font-size: 1.05rem; }
    h2 { font-size: 1rem; }
    h3 { font-size: 0.95rem; }
    h4, h5, h6 { font-size: 0.9rem; }

    strong { color: #f3f4f6; font-weight: 600; }
    em     { color: #d1d5db; font-style: italic; }

    ul, ol { margin: 0.35em 0 0.5em; padding-left: 1.4em; }
    li     { margin: 0.15em 0; }
    ul ul, ul ol, ol ul, ol ol { margin: 0.15em 0; }

    code {
      background: #0b0b15;
      border: 1px solid #2a2a3d;
      border-radius: 3px;
      padding: 0 0.25em;
      font-family: 'SFMono-Regular', Consolas, monospace;
      font-size: 0.82em;
    }
    pre {
      background: #0b0b15;
      border: 1px solid #2a2a3d;
      border-radius: 6px;
      padding: 0.6em 0.75em;
      margin: 0.5em 0;
      overflow-x: auto;
      font-size: 0.82em;

      code { background: transparent; border: 0; padding: 0; font-size: inherit; }
    }

    blockquote {
      margin: 0.4em 0;
      padding: 0.2em 0.8em;
      border-left: 3px solid #3a3a5a;
      color: #9ca3af;
      font-style: italic;
    }

    a {
      color: #a5b4fc;
      text-decoration: underline;
      &:hover { color: #c7d2fe; }
    }

    hr { border: 0; border-top: 1px solid #2a2a3d; margin: 0.6em 0; }

    // Les tableaux (inventaires de boutique…) peuvent être plus larges que la
    // bulle : on les laisse défiler horizontalement DANS le message.
    table {
      display: block;
      max-width: 100%;
      overflow-x: auto;
      border-collapse: collapse;
      margin: 0.4em 0;
      font-size: 0.85em;

      th, td { border: 1px solid #2a2a3d; padding: 0.3em 0.5em; white-space: nowrap; }
      th { background: #14142a; font-weight: 600; }
    }
  }
  &.user { align-self: flex-end; text-align: right;
    .nbd-msg-content { background: rgba(102,126,234,0.16); padding: 0.5rem 0.75rem; border-radius: 10px; display: inline-block; text-align: left; }
  }
  &.assistant { align-self: flex-start;
    .nbd-msg-content { background: rgba(255,255,255,0.04); padding: 0.5rem 0.75rem; border-radius: 10px; }
  }
}
.cursor { opacity: 0.6; }

.nbd-input {
  display: flex; gap: 0.5rem; padding: 0.6rem; border-top: 1px solid rgba(255,255,255,0.08);
  textarea {
    flex: 1; resize: none; padding: 0.55rem 0.7rem; border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.14); background: rgba(255,255,255,0.04); color: inherit; font: inherit;
  }
  .btn-send {
    display: inline-flex; align-items: center; justify-content: center; width: 44px;
    border: none; border-radius: 8px; background: #667eea; color: #fff; cursor: pointer;
    &:hover:not(:disabled) { background: #5568d3; }
    &:disabled { opacity: 0.5; cursor: default; }
  }
  .btn-deep {
    display: inline-flex; align-items: center; justify-content: center; width: 44px;
    border: 1px solid rgba(168,130,255,0.4); border-radius: 8px;
    background: rgba(168,130,255,0.12); color: #c4a8ff; cursor: pointer;
    &:hover:not(:disabled) { background: rgba(168,130,255,0.22); }
    &:disabled { opacity: 0.5; cursor: default; }
  }
}

.nbd-deep-progress {
  display: inline-flex; align-items: center; gap: 0.35rem;
  font-size: 0.82rem; color: #c4a8ff; font-style: italic;
}

// Pages de la source utilisées par le RAG (transparence de la réponse)
.nbd-msg-sources {
  margin-top: 0.35rem;
  font-size: 0.75rem;
  opacity: 0.65;
}
