:host {
  // Le drawer lui-même gère son positionnement fixed. Rien à prévoir côté host.
  display: contents;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  // La largeur est appliquee en inline-style par le composant (effectiveWidth).
  height: 100vh;
  background: #0f0f1a;
  border-left: 1px solid #1e1e3a;
  display: flex;
  flex-direction: row;
  transform: translateX(100%);
  transition: transform 0.25s ease, width 0.25s ease;
  z-index: 1000;
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.4);
}

// Pendant un drag, on veut que la largeur suive la souris sans interpolation.
.drawer.is-resizing {
  transition: transform 0.25s ease;
}

.resize-handle {
  position: absolute;
  top: 0;
  left: -3px;
  width: 6px;
  height: 100%;
  cursor: ew-resize;
  z-index: 1;
  background: transparent;
  transition: background 0.15s;

  &:hover,
  .drawer.is-resizing & {
    background: rgba(108, 99, 255, 0.35);
  }
}

.conv-sidebar {
  width: 220px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: #0b0b15;
  border-right: 1px solid #1e1e3a;
}

.conv-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0.9rem;
  border-bottom: 1px solid #1e1e3a;

  .conv-sidebar-title {
    font-size: 0.78rem;
    font-weight: 600;
    color: #9ca3af;
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }
  .conv-new-btn {
    background: transparent;
    border: none;
    color: #9ca3af;
    cursor: pointer;
    padding: 0.3rem;
    border-radius: 4px;
    display: flex;

    &:hover:not(:disabled) {
      background: #1e1e3a;
      color: white;
    }
    &:disabled { opacity: 0.4; cursor: not-allowed; }
  }
}

.conv-list {
  list-style: none;
  margin: 0;
  padding: 0.4rem 0;
  overflow-y: auto;
  flex: 1;
}

.conv-empty {
  padding: 1rem 0.9rem;
  font-size: 0.78rem;
  color: #6b7280;
  font-style: italic;
}

.conv-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.9rem;
  cursor: pointer;
  font-size: 0.82rem;
  color: #d1d5db;
  border-left: 2px solid transparent;

  &:hover {
    background: #14142a;
  }
  &.active {
    background: #1a1a2e;
    border-left-color: #6c63ff;
    color: white;
  }
  .conv-item-title {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .conv-item-del {
    background: transparent;
    border: none;
    color: #6b7280;
    cursor: pointer;
    padding: 0.2rem;
    border-radius: 3px;
    display: flex;
    opacity: 0;
    transition: opacity 0.15s;

    &:hover:not(:disabled) { color: #f87171; background: #1f0f0f; }
  }
  &:hover .conv-item-del { opacity: 1; }
  &.active .conv-item-del { opacity: 1; }
}

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

.sidebar-toggle {
  background: transparent;
  border: none;
  color: #9ca3af;
  cursor: pointer;
  padding: 0.3rem;
  border-radius: 4px;
  display: flex;

  &:hover { background: #1e1e3a; color: white; }
}

.header-title-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 0.35rem;

  .header-title {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
    color: white;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
  }
  .rename-btn {
    background: transparent;
    border: none;
    color: #6b7280;
    cursor: pointer;
    padding: 0.2rem;
    border-radius: 3px;
    display: flex;

    &:hover { color: white; background: #1e1e3a; }
  }
  .rename-input {
    flex: 1;
    background: #1a1a2e;
    border: 1px solid #6c63ff;
    color: white;
    padding: 0.3rem 0.5rem;
    border-radius: 4px;
    font-size: 0.9rem;
    font-family: inherit;
    outline: none;
  }
}

.drawer-open {
  transform: translateX(0);
}

// --- Header --------------------------------------------------------------

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid #1e1e3a;
  flex-shrink: 0;

  h2 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: white;
  }

  .close-btn,
  .wide-toggle-btn {
    background: transparent;
    border: none;
    color: #9ca3af;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 4px;
    display: flex;

    &:hover {
      color: white;
      background: #1e1e3a;
    }
  }
}

// --- Zone messages -------------------------------------------------------

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.msg {
  max-width: 85%;
  padding: 0.6rem 0.85rem;
  border-radius: 10px;
  font-size: 0.88rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.msg-assistant {
  align-self: flex-start;
  background: #1a1a2e;
  color: #e5e7eb;
  border: 1px solid #2a2a3d;
}

// Rendu markdown dans les messages assistant. On override le white-space
// puisque marked genere des <p>/<li>/<br> et on veut les espacements naturels.
.msg.md {
  white-space: normal;

  // Marges propres : pas d'espace avant le premier / apres le dernier bloc.
  > :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;
  }

  table {
    border-collapse: collapse;
    margin: 0.4em 0;
    font-size: 0.85em;

    th, td { border: 1px solid #2a2a3d; padding: 0.3em 0.5em; }
    th { background: #14142a; font-weight: 600; }
  }
}

.msg-user {
  align-self: flex-end;
  background: #6c63ff;
  color: white;
}

.msg-streaming {
  // Le caret clignotant à la fin donne la sensation de "l'IA est en train d'écrire"
  .caret {
    display: inline-block;
    width: 6px;
    height: 1em;
    background: #a5b4fc;
    margin-left: 2px;
    vertical-align: text-bottom;
    animation: blink 1s step-end infinite;
  }
}

.msg-error {
  align-self: stretch;
  background: #3f1f1f;
  color: #fca5a5;
  border: 1px solid #7f1d1d;
  font-size: 0.85rem;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0; }
}

// --- Indicateur "typing" -------------------------------------------------

.typing-indicator {
  display: flex;
  gap: 0.3rem;
  padding: 0.6rem 0.85rem;
  align-self: flex-start;

  span {
    width: 6px;
    height: 6px;
    background: #6c63ff;
    border-radius: 50%;
    animation: bounce 1.2s infinite ease-in-out both;
  }
  span:nth-child(2) { animation-delay: 0.15s; }
  span:nth-child(3) { animation-delay: 0.3s; }
}

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40%           { transform: scale(1);   opacity: 1; }
}

// --- Action primaire -----------------------------------------------------

.primary-action {
  padding: 0.75rem 1.25rem 0;
  flex-shrink: 0;

  .primary-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    width: 100%;
    padding: 0.65rem 0.9rem;
    background: #6c63ff;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.88rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;

    &:hover:not(:disabled) { background: #5a52e0; }
    &:disabled {
      opacity: 0.5;
      cursor: not-allowed;
    }
  }
}

// --- Suggestions rapides -------------------------------------------------

.quick-suggestions {
  padding: 0.75rem 1.25rem 0;
  border-top: 1px solid #1e1e3a;
  flex-shrink: 0;

  .quick-label {
    font-size: 0.75rem;
    color: #9ca3af;
    margin: 0 0 0.5rem;
  }

  .quick-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
  }

  .quick-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.35rem 0.6rem;
    background: #1a1a2e;
    border: 1px solid #2a2a3d;
    border-radius: 4px;
    color: #d1d5db;
    font-size: 0.78rem;
    cursor: pointer;
    transition: background 0.15s;

    &:hover:not(:disabled) {
      background: #2a2a3d;
      color: white;
    }
    &:disabled {
      opacity: 0.5;
      cursor: not-allowed;
    }
  }
}

// --- Zone de saisie ------------------------------------------------------

.input-row {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem 1rem;
  flex-shrink: 0;

  input {
    flex: 1;
    background: #1a1a2e;
    border: 1px solid #2a2a3d;
    color: white;
    padding: 0.55rem 0.75rem;
    border-radius: 6px;
    font-size: 0.88rem;
    font-family: inherit;

    &:focus {
      outline: none;
      border-color: #6c63ff;
    }
    &:disabled {
      opacity: 0.5;
    }
  }

  .send-btn {
    background: #6c63ff;
    color: white;
    border: none;
    border-radius: 6px;
    width: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;

    &:hover:not(:disabled) { background: #5a52e0; }
    &:disabled {
      opacity: 0.5;
      cursor: not-allowed;
    }
  }
}


/* --- Jauge de contexte ------------------------------------------------- */
.context-gauge {
  padding: 0.5rem 1rem 0.75rem;
  border-bottom: 1px solid #1e1e3a;
  background: #141428;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.context-gauge .gauge-bar {
  height: 6px;
  border-radius: 3px;
  background: #2a2a45;
  overflow: hidden;
}

.context-gauge .gauge-fill {
  height: 100%;
  transition: width 0.3s ease, background-color 0.3s ease;
  border-radius: 3px;
}

.context-gauge[data-level="low"] .gauge-fill  { background: #10b981; }
.context-gauge[data-level="mid"] .gauge-fill  { background: #f59e0b; }
.context-gauge[data-level="high"] .gauge-fill { background: #ef4444; }

.context-gauge .gauge-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: #9ca3af;
  font-variant-numeric: tabular-nums;
}

.context-gauge[data-level="high"] .gauge-percent {
  color: #f87171;
  font-weight: 600;
}
