/* === CHAT AREA === */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-primary);
}

/* === EMPTY STATE === */
.chat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  text-align: center;
  padding: 40px;
  color: var(--text-secondary);
}

.brand-icon-lg {
  color: var(--accent);
  margin-bottom: 12px;
  opacity: 0.7;
}

.chat-empty h2 {
  font-size: 22px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.chat-empty p {
  max-width: 480px;
  line-height: 1.6;
  font-size: 14px;
}

.chat-empty-detail {
  margin-top: 8px;
  font-size: 13px;
  color: var(--text-muted);
  max-width: 520px;
}

/* === MESSAGES CONTAINER === */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 0;
}

/* === MESSAGE === */
.message {
  display: flex;
  flex-direction: column;
  padding: 4px 32px;
  animation: fadeIn 0.3s ease;
  width: 100%;
}

.message + .message {
  margin-top: 4px;
}

/* User message: bulle accent, alignée à droite */
.message-user {
  align-items: flex-end;
}

.message-user .message-content {
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-lg) var(--radius-lg) 4px var(--radius-lg);
  padding: 10px 16px;
  max-width: 80%;
}

.message-user .message-text {
  color: #fff;
}

.message-user .message-text a {
  color: #fff;
  text-decoration: underline;
}

.message-user .message-text code {
  background: rgba(255,255,255,0.15);
  color: #fff;
}

.message-user .message-text pre {
  background: rgba(255,255,255,0.1);
  border-color: rgba(255,255,255,0.2);
}

.message-user .message-text blockquote {
  border-left-color: rgba(255,255,255,0.5);
  color: rgba(255,255,255,0.85);
}

/* Assistant message: texte neutre, aligné à gauche */
.message-assistant {
  align-items: flex-start;
}

.message-assistant .message-content {
  max-width: 90%;
}

/* Avatar masqué en mode bulle (gardé dans le DOM pour JS) */
.message-avatar {
  display: none;
}

.message-content {
  min-width: 0;
}

.message-text {
  font-size: 14px;
  line-height: 1.7;
  word-wrap: break-word;
}

/* Markdown styles inside messages */
.message-text h1, .message-text h2, .message-text h3 {
  margin-top: 16px;
  margin-bottom: 8px;
  font-weight: 600;
}

.message-text h1 { font-size: 18px; }
.message-text h2 { font-size: 16px; }
.message-text h3 { font-size: 15px; }

.message-text p { margin-bottom: 8px; }
.message-text p:last-child { margin-bottom: 0; }

.message-text ul, .message-text ol {
  margin: 8px 0;
  padding-left: 24px;
}

.message-text li { margin-bottom: 4px; }

.message-text code {
  background: var(--bg-secondary);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 13px;
}

.message-text pre {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  overflow-x: auto;
  margin: 8px 0;
}

.message-text pre code {
  background: none;
  padding: 0;
}

.message-text blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  margin: 8px 0;
  color: var(--text-secondary);
}

.message-text strong { font-weight: 600; }
.message-text em { font-style: italic; }

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

/* === STREAMING CURSOR (hidden — clean end of stream) === */
.streaming-cursor::after {
  display: none;
}

/* === MESSAGE ACTION BAR (sources + actions) === */
.message-action-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 6px;
  gap: 4px 8px;
}

.message-actions {
  display: flex;
  gap: 2px;
  margin-left: auto;
}

/* === SOURCES (FidesIA style) === */
.message-sources {
  margin-top: 8px;
}

.sources-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 6px 10px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
}

.sources-toggle:hover {
  background: var(--bg-secondary);
  color: var(--text-secondary);
}

.sources-toggle .chevron {
  font-size: 10px;
  transition: transform 0.2s;
}

.sources-toggle.expanded .chevron {
  transform: rotate(90deg);
}

.sources-list {
  margin-top: 6px;
  display: none;
  flex-direction: column;
  gap: 4px;
}

.sources-list.visible { display: flex; }

.source-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  font-size: 13px;
  transition: background 0.15s;
}

.source-item:hover { background: var(--accent-light); }

.source-name {
  flex: 1;
  color: var(--text-secondary);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.source-name:hover {
  color: var(--accent);
  text-decoration: underline;
}

.source-score {
  width: 50px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  flex-shrink: 0;
}

.source-score-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
}

.source-percent {
  color: var(--text-muted);
  font-size: 11px;
  flex-shrink: 0;
  min-width: 30px;
  text-align: right;
}

/* === RATING (FidesIA gold style) === */
.message-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.rating-container {
  display: flex;
  align-items: center;
  gap: 0;
}

.rating-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-right: 4px;
  white-space: nowrap;
}

.rating-stars {
  display: flex;
  gap: 0;
}

.rating-star {
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  padding: 4px 2px;
  line-height: 1;
  min-width: 28px;
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--border);
  transition: color 0.15s;
}

.rating-star:hover,
.rating-star.filled { color: #d4a830; }
.rating-star.readonly { cursor: default; }

.response-time {
  font-size: 12px;
}

/* === INPUT BAR === */
.chat-input-bar {
  padding: 12px 32px 16px;
  background: var(--bg-primary);
  flex-shrink: 0;
}

.chat-input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin: 0 auto;
  background: var(--bg-input);
  border: 1.5px solid var(--accent);
  border-radius: var(--radius-lg);
  padding: 8px 12px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.chat-input-wrapper:focus-within {
  box-shadow: 0 0 0 2px var(--accent-light);
}

#chat-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 14px;
  font-family: var(--font-family);
  line-height: 1.5;
  resize: none;
  max-height: 150px;
  min-height: 24px;
}

#chat-input::placeholder { color: var(--text-muted); }

.btn-send {
  background: var(--accent);
  border: none;
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s, opacity 0.2s;
}

.btn-send:hover { background: var(--accent-hover); }
.btn-send:disabled { opacity: 0.4; cursor: not-allowed; }

/* === SEARCHING INDICATOR === */
.searching-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  color: var(--text-muted);
  font-size: 13px;
}

.searching-indicator .spinner {
  width: 14px;
  height: 14px;
}

/* === FILTER TREE === */
.filter-tree {
  min-height: 200px;
}

.tree-node {
  padding: 2px 0;
}

.tree-node-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
}

.tree-node-row:hover { background: var(--bg-secondary); }

.tree-node-checkbox {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

.tree-node-chevron {
  width: 16px;
  font-size: 10px;
  color: var(--text-muted);
  cursor: pointer;
  text-align: center;
  transition: transform 0.2s;
  user-select: none;
}

.tree-node-chevron.expanded {
  transform: rotate(90deg);
}

.tree-node-icon {
  font-size: 14px;
}

.tree-node-name {
  font-size: 13px;
  flex: 1;
}

.tree-node-meta {
  font-size: 11px;
  color: var(--text-muted);
}

.tree-children {
  padding-left: 24px;
}
