:root {
  --bg: #0f1115;
  --panel: #171a21;
  --border: #2a2e37;
  --text: #e8eaed;
  --muted: #9aa0aa;
  --accent: #4f8cff;
  --user-bubble: #2a3548;
  --assistant-bubble: #1c2028;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f6f8;
    --panel: #ffffff;
    --border: #e1e3e8;
    --text: #1b1e24;
    --muted: #666c78;
    --accent: #2f6fed;
    --user-bubble: #e6edff;
    --assistant-bubble: #f0f1f4;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app {
  height: 100vh;
  display: flex;
  flex-direction: row;
}

.sidebar {
  width: 260px;
  flex-shrink: 0;
  min-height: 0;
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
}

.history-empty {
  font-size: 12px;
  color: var(--muted);
  padding: 8px 10px;
}

.new-chat-btn {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.sidebar-section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-top: 6px;
  padding: 0 4px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  overflow-y: auto;
}

.history-item {
  padding: 9px 12px;
  border-radius: 8px;
  cursor: pointer;
  position: relative;
  border-left: 3px solid transparent;
}

.history-item:hover {
  background: var(--assistant-bubble);
}

.history-item.active {
  background: var(--user-bubble);
  border-left-color: var(--accent);
}

.history-item .h-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-right: 22px;
}

.history-item .h-meta {
  font-size: 10.5px;
  color: var(--muted);
  margin-top: 3px;
}

.history-item .h-delete {
  display: none;
  position: absolute;
  top: 7px;
  right: 6px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  padding: 3px 5px;
  border-radius: 5px;
}

.history-item .h-delete:hover {
  background: rgba(214, 69, 69, 0.15);
  color: #d64545;
}

.history-item:hover .h-delete {
  display: block;
}

.main-panel {
  flex: 1;
  min-width: 0;
  min-height: 0;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

.topbar {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
}

.topbar h1 {
  font-size: 16px;
  margin: 0;
  font-weight: 600;
  color: var(--text);
}

.user-badge {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-muted, #666);
}

.user-badge a {
  color: inherit;
  text-decoration: underline;
}

/* Menus deroulants (dossier(s) / moteur), regroupes pres du composer -- voir .composer-controls */
.picker-wrap {
  position: relative;
}

.picker-btn {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
}

.picker-btn:hover {
  background: var(--assistant-bubble);
}

.picker-panel {
  position: absolute;
  bottom: 100%;
  left: 0;
  margin-bottom: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  min-width: 240px;
  max-height: 280px;
  overflow-y: auto;
  z-index: 20;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.picker-search {
  position: sticky;
  top: -8px;
  z-index: 1;
  width: 100%;
  box-sizing: border-box;
  margin: -8px -8px 6px;
  padding: 8px 10px;
  width: calc(100% + 16px);
  border: none;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
  border-radius: 10px 10px 0 0;
}

.picker-search:focus {
  outline: none;
  background: var(--assistant-bubble);
}

.picker-no-results {
  padding: 8px 4px;
  font-size: 12px;
  color: var(--text-muted, #888);
}

.picker-checkboxes {
  display: flex;
  flex-direction: column;
}

.picker-checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  border-radius: 4px;
}

.picker-checkbox-row:hover {
  background: var(--assistant-bubble);
}

.picker-checkbox-row input {
  cursor: pointer;
}

.picker-option-row {
  padding: 7px 8px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  border-radius: 4px;
}

.picker-option-row:hover {
  background: var(--assistant-bubble);
}

.picker-actions {
  border-top: 1px solid var(--border);
  margin-top: 6px;
  padding-top: 6px;
}

.picker-clear {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 12px;
  cursor: pointer;
  padding: 4px;
}

.thread {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.msg {
  max-width: 80%;
  padding: 10px 14px 12px;
  border-radius: 12px;
  line-height: 1.55;
  font-size: 14px;
}

.msg-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  margin-bottom: 4px;
}

.msg-body {
  white-space: pre-wrap;
}

.msg.user {
  align-self: flex-end;
  background: var(--user-bubble);
}

.msg.user .msg-body {
  white-space: pre-wrap;
}

.msg.assistant {
  align-self: flex-start;
  background: var(--assistant-bubble);
  border: 1px solid var(--border);
  width: 100%;
}

.msg.assistant .msg-body {
  white-space: normal;
}

.msg.pending {
  color: var(--muted);
}

.msg.pending .msg-body {
  font-style: italic;
}

.msg.error {
  border-color: #d64545;
}

.msg.error .msg-body {
  color: #d64545;
}

/* markdown renderizado dentro de la respuesta del asistente */
.msg-body p {
  margin: 0 0 10px;
}
.msg-body p:last-child {
  margin-bottom: 0;
}
.msg-body h3, .msg-body h4 {
  margin: 12px 0 6px;
  font-size: 14px;
  font-weight: 700;
}
.msg-body ul, .msg-body ol {
  margin: 0 0 10px;
  padding-left: 20px;
}
.msg-body li {
  margin: 2px 0;
}
.msg-body strong {
  font-weight: 700;
}
.msg-body code {
  background: rgba(127, 127, 127, 0.18);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 12.5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.msg-body pre {
  background: rgba(127, 127, 127, 0.14);
  border-radius: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  margin: 0 0 10px;
}
.msg-body pre code {
  background: none;
  padding: 0;
}
.msg-body a.cite {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}
.msg-body a.cite:hover {
  text-decoration: underline;
}

.sources {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}

.sources-title {
  font-weight: 600;
  text-transform: uppercase;
  font-size: 10.5px;
  letter-spacing: 0.03em;
  margin-bottom: 4px;
  cursor: pointer;
  user-select: none;
}

.sources ul {
  margin: 6px 0 0;
  padding-left: 0;
  list-style: none;
}

.sources li {
  padding: 4px 0;
}

.sources .src-path {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: var(--muted);
  opacity: 0.8;
  white-space: pre-wrap;
  word-break: break-all;
  margin: 2px 0 0 16px;
}

.sources .src-n {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  margin-right: 2px;
}

.sources a {
  color: var(--accent);
  text-decoration: none;
}

.sources a:hover {
  text-decoration: underline;
}

.sources .src-loc {
  color: var(--muted);
}

.correction-control {
  margin-top: 8px;
}

.correction-toggle {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
  padding: 2px 0;
}

.correction-toggle:hover {
  color: var(--accent);
}

.correction-toggle:disabled {
  cursor: default;
  color: var(--muted);
  opacity: 0.7;
}

.correction-form {
  margin-top: 6px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
}

.correction-form .correction-text {
  width: 100%;
  resize: vertical;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 12.5px;
  font-family: inherit;
}

.correction-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}

.correction-actions button {
  font-size: 11.5px;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
}

.correction-actions .correction-submit {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.correction-status {
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
}

.attachment-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  padding: 6px 10px;
  background: var(--assistant-bubble);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  color: var(--muted);
  width: fit-content;
  max-width: calc(100% - 40px);
}

.attachment-chip.pending {
  font-style: italic;
}

.attachment-chip.error {
  border-color: #d64545;
  color: #d64545;
}

.attachment-chip .chip-remove {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 0 2px;
}

.composer-wrap {
  padding: 12px 20px 20px;
  border-top: 1px solid var(--border);
}

/* Carte unique regroupant le champ de saisie et, en dessous, les controles (piece jointe,
   dossier(s), moteur, envoyer) -- comme la zone de saisie de ce chat-ci (icones integrees sous
   le texte plutot qu'une barre de controles separee en haut de la page). */
.composer-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 12px;
}

.composer-card textarea {
  width: 100%;
  resize: none;
  background: transparent;
  color: var(--text);
  border: none;
  padding: 4px 4px 8px;
  font-size: 14px;
  font-family: inherit;
}

.composer-card textarea:focus {
  outline: none;
}

.composer-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.composer-controls-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.pill-btn {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 12.5px;
  cursor: pointer;
  white-space: nowrap;
}

.pill-btn:hover {
  background: var(--assistant-bubble);
}

.pill-btn.icon-only {
  padding: 7px 10px;
  font-size: 14px;
}

.pill-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.pill-btn:disabled,
.pill-btn.disabled {
  opacity: 0.45;
  cursor: default;
  pointer-events: none;
}

.send-btn {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 999px;
  padding: 9px 22px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
}

.send-btn:disabled {
  opacity: 0.5;
  cursor: default;
}
