:root {
  font-family: Inter, system-ui, sans-serif;
  color: #182b3b;
  background: #f2f5f9
}

* {
  box-sizing: border-box
}

body {
  margin: 0
}

header {
  background: #102c3a;
  color: white;
  padding: 22px 5%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 30
}

header a {
  color: #abdfdf
}

h1 {
  font-size: 23px;
  margin: 0
}

small {
  color: #557080
}

header small {
  color: #aec7d0
}

nav {
  display: flex;
  gap: 18px;
  align-items: center
}

main {
  max-width: 1060px;
  margin: 32px auto;
  padding: 0 20px;
  flex: 1;
  min-width: 0;
  transition: background-color .15s
}

main.drag-over {
  background-color: #e7f1f4;
  outline: 2px dashed #087d83;
  outline-offset: -6px;
  border-radius: 14px
}

.card {
  background: white;
  padding: 26px;
  border: 1px solid #dce5ea;
  border-radius: 14px;
  margin-bottom: 20px
}

input,
textarea {
  font: inherit;
  padding: 13px;
  border: 1px solid #b9cbd5;
  border-radius: 8px;
  width: 100%;
  margin: 8px 0 16px
}

button {
  background: #087d83;
  color: white;
  border: 0;
  padding: 12px 20px;
  border-radius: 8px;
  cursor: pointer;
  font: inherit
}

button:disabled {
  opacity: .5
}

label {
  display: block
}

a {
  color: #086b78
}

.error {
  color: #ae2633
}

.answer {
  line-height: 1.6
}

.answer p { margin: 0 0 10px }
.answer p:last-child { margin-bottom: 0 }
.answer ul, .answer ol { margin: 0 0 10px; padding-left: 22px }
.answer li { margin: 2px 0 }
.answer h4, .answer h5, .answer h6 {
  margin: 14px 0 6px;
  line-height: 1.3
}
.answer h4:first-child, .answer h5:first-child, .answer h6:first-child { margin-top: 0 }
.answer code {
  background: rgba(9, 47, 56, .08);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: .92em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace
}
.answer pre {
  background: #0d2531;
  color: #e4f1f4;
  border-radius: 10px;
  padding: 12px 14px;
  margin: 0 0 10px;
  overflow-x: auto
}
.answer pre code {
  background: transparent;
  padding: 0;
  color: inherit
}

.question {
  font-weight: 650
}

.sources {
  font-size: 13px;
  color: #516c79
}

table {
  width: 100%;
  border-collapse: collapse
}

td,
th {
  text-align: left;
  padding: 12px;
  border-bottom: 1px solid #e1e9ed;
  overflow-wrap: anywhere
}

#status {
  font-size: 13px;
  color: #526b7b;
  margin-bottom: 18px
}

.login {
  max-width: 460px;
  margin: 65px auto
}

footer {
  font-size: 12px;
  color: #557080;
  margin-top: 25px
}

form {
  margin: 0
}

.app-shell {
  display: flex;
  align-items: flex-start
}

#sidebar {
  width: 270px;
  flex: 0 0 270px;
  background: #0d2531;
  color: #c8dbe2;
  padding: 18px 14px;
  align-self: flex-start;
  position: sticky;
  top: var(--header-h, 84px);
  height: calc(100vh - var(--header-h, 84px));
  overflow-y: auto
}

#sidebar h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #7fa0ac;
  margin: 18px 0 8px
}

#sidebar .sidebar-btn {
  width: 100%;
  background: #164351;
  color: #d8ecef;
  border: 1px solid #1f5866;
  padding: 10px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 6px;
  cursor: pointer
}

#sidebar .sidebar-btn:hover {
  background: #1c5261
}

#chat-search {
  width: 100%;
  margin: 4px 0 10px;
  padding: 9px 11px;
  font-size: 13px;
  border: 1px solid #1f5866;
  border-radius: 8px;
  background: #0d2531;
  color: #e4f1f4
}

#chat-search::placeholder { color: #6f8f9a }
#chat-search:focus { outline: 2px solid #3a8fa0; outline-offset: 1px }

#chat-search-results {
  margin: -4px 0 12px;
  border: 1px solid #1f5866;
  border-radius: 10px;
  background: #0f2c38;
  max-height: 280px;
  overflow-y: auto
}

.search-result {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 11px;
  background: transparent;
  border: 0;
  border-bottom: 1px solid #163b47;
  color: #e4f1f4;
  cursor: pointer
}

.search-result:last-child { border-bottom: 0 }
.search-result:hover, .search-result:focus-visible { background: #164351 }
.search-result strong {
  display: block;
  font-size: 12.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap
}
.search-result span {
  display: block;
  margin-top: 3px;
  font-size: 12px;
  color: #9fbac2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap
}
.search-result mark {
  background: #3a8fa0;
  color: #fff;
  border-radius: 3px;
  padding: 0 2px
}
.search-empty { padding: 10px 11px; font-size: 12.5px; color: #7fa0ac }

.folder-group {
  margin-bottom: 10px;
  border: 1px solid #163b47;
  border-radius: 10px;
  padding: 6px;
  background: #0f2c38
}

.folder-name {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px 6px;
  font-size: 13px;
  font-weight: 700;
  color: #bcdde3;
  cursor: grab;
  user-select: none
}

.folder-name span:nth-child(2) {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap
}

.folder-name .icon-btn {
  opacity: .6
}

.drag-handle {
  flex: 0 0 auto;
  color: #5c7a85;
  font-size: 14px;
  line-height: 1;
  cursor: grab
}

.chat-row.dragging,
.folder-group.dragging {
  opacity: .35
}

.chat-row {
  cursor: grab
}

#unfiled-chats {
  margin-top: 4px
}

.chat-list {
  list-style: none;
  margin: 0;
  padding: 0
}

.folder-group .chat-list {
  margin-left: 8px;
  padding-left: 10px;
  min-height: 14px;
  border-left: 2px solid #1c4552
}

.chat-row {
  display: flex;
  align-items: center;
  gap: 6px;
  border-radius: 8px;
  padding: 2px
}

.chat-row:hover {
  background: #123542
}

.chat-row.active {
  background: #0f4657
}

.chat-row a {
  flex: 1;
  min-width: 0;
  color: #e4f1f4;
  text-decoration: none;
  padding: 8px 6px;
  font-size: 13.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block
}

.icon-btn {
  background: transparent;
  border: 0;
  color: #8fb0ba;
  padding: 4px 6px;
  font-size: 13px;
  border-radius: 6px;
  cursor: pointer
}

.icon-btn:hover {
  background: #1c5261;
  color: #fff
}

.chat-row select {
  width: auto;
  margin: 0;
  padding: 2px 4px;
  font-size: 11px;
  border-radius: 6px;
  border: 1px solid #1f5866;
  background: #0d2531;
  color: #c8dbe2
}

.artifacts-card a.download-link {
  display: block;
  margin: 4px 0
}

@media(max-width:820px) {
  .app-shell {
    flex-direction: column
  }

  #sidebar {
    width: 100%;
    flex: none;
    position: static;
    height: auto;
    max-height: 260px
  }
}

@media(max-width:600px) {
  main {
    padding: 0 12px
  }

  .card {
    padding: 16px
  }

  header {
    padding: 18px
  }

  table {
    font-size: 12px
  }
}

.brand-accent {
  color: #74d9d4;
}
.document-filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.document-filters select {
  width: 100%;
  margin-top: 8px;
  padding: 13px;
  border: 1px solid #b9cbd5;
  border-radius: 8px;
  background: white;
  font: inherit;
}

.document-filter-actions {
  display: flex;
  align-items: center;
  gap: 16px;
  grid-column: 1 / -1;
}

.document-table {
  overflow-x: auto;
}

/* El mensaje y sus adjuntos comparten un único cuadro de composición. */
.chat-composer {
  padding: 10px 12px;
  margin: 24px 0;
  border: 1px solid #363636;
  border-radius: 28px;
  background: #222;
  color: #f4f4f4;
}

.composer-controls {
  display: flex;
  align-items: flex-end;
  gap: 12px;
}

.chat-composer #question {
  flex: 1;
  min-width: 0;
  min-height: 46px;
  max-height: 220px;
  padding: 12px 0;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
  resize: vertical;
  line-height: 1.5;
}

.chat-composer #question::placeholder { color: #b8b8b8; }
.chat-composer #question:focus { outline: none; }
.chat-composer:focus-within { border-color: #777; }
.chat-composer.drag-over { border-color: #3271d1; background: #262f3d; }

.chat-composer #attach-button,
.chat-composer #send {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  margin-bottom: 4px;
  padding: 0;
  border-radius: 50%;
  font-size: 27px;
  line-height: 1;
}

.chat-composer #attach-button { background: transparent; color: #eee; }
.chat-composer #attach-button:hover { background: #3b3b3b; }
.chat-composer #send { background: #3271d1; color: white; }
.chat-composer button:focus-visible, .chat-composer a:focus-visible {
  outline: 2px solid #9ac0ff;
  outline-offset: 3px;
}

#attachment-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

#attachment-list:not(:empty) { margin-bottom: 12px; }

.attachment-chip {
  display: flex;
  align-items: center;
  max-width: 100%;
  width: 320px;
  border: 1px solid #494949;
  border-radius: 18px;
  overflow: hidden;
}

.attachment-info {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
  padding: 12px;
  color: #eee;
}

.attachment-icon { font-size: 25px; flex-shrink: 0; }
.attachment-details { min-width: 0; }
.attachment-details strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}
.attachment-details small { display: block; margin-top: 4px; color: #bbb; }
.attachment-chip a { color: #ddd; padding: 12px; text-decoration: none; }
.attachment-remove {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  margin-right: 6px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: transparent;
  color: #aaa;
  font-size: 13px;
}
.attachment-remove:hover { background: #3b3b3b; color: #fff; }
.chat-composer .composer-status, .chat-composer .error {
  margin: 8px 12px;
  font-size: 13px;
}
.chat-composer .error { color: #ffb4b4; }
.chat-composer p:empty { display: none; }

/* Mensajes como una conversación real: usuario a la derecha, asistente a la izquierda. */
.message-row {
  flex-direction: column;
  display: flex;
  margin: 14px 0;
}

.message-row.user { align-items: flex-end; }
.message-row.assistant { align-items: flex-start; }

.bubble {
  max-width: 78%;
  padding: 14px 18px;
  border-radius: 18px;
  overflow-wrap: anywhere;
}

.message-row.user .bubble {
  background: #087d83;
  color: white;
  border-bottom-right-radius: 4px;
}

.message-row.assistant .bubble {
  background: white;
  color: #182b3b;
  border: 1px solid #dce5ea;
  border-bottom-left-radius: 4px;
}

.message-row .question { font-weight: 500; }
.message-row.assistant .sources {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid #e1e9ed;
  font-size: 12.5px;
}

@media(max-width:600px) {
  .bubble { max-width: 90%; }
}

/* Indicador de "escribiendo" mientras se espera la respuesta. */
.typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 2px;
}

.typing-indicator span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9fb3bd;
  animation: typing-bounce 1.2s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) { animation-delay: .15s; }
.typing-indicator span:nth-child(3) { animation-delay: .3s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* Archivos del chat: una franja compacta, no una tarjeta de mensaje más. */
.chat-files {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 10px;
  margin: 0 0 16px;
  padding: 10px 14px;
  background: #eef3f6;
  border: 1px solid #dce5ea;
  border-radius: 10px;
  font-size: 13px;
  color: #45606d;
}

.chat-files strong { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: #6f8a96; }
.chat-files .download-link {
  background: white;
  border: 1px solid #d3dee3;
  border-radius: 999px;
  padding: 4px 12px;
  margin: 0;
  text-decoration: none;
  font-size: 12.5px;
}
.chat-files .download-link:hover { background: #e4ecf0; }

/* Bajo el cuadro de mensaje, donde está el usuario en una conversación larga. */
.chat-tools {
  display: flex;
  justify-content: flex-end;
  margin: -12px 0 8px;
}
#export-chat {
  width: auto;
  margin: 0;
  font-size: 13px;
  padding: 4px 8px;
}

/* Barra bajo cada burbuja: hora y acciones, visible al pasar el ratón. */
.msg-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
  min-height: 24px;
  font-size: 12px;
  color: #6f8a96;
  opacity: 0;
  transition: opacity .12s;
}
.message-row:hover .msg-actions,
.message-row:focus-within .msg-actions { opacity: 1; }
@media (hover: none) { .msg-actions { opacity: 1; } }
.msg-time { margin-right: 6px; }
.msg-action {
  background: transparent;
  color: inherit;
  border: 0;
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 12px;
  cursor: pointer;
}
.msg-action:hover { background: #e4ecf0; color: #182b3b; }
.msg-action[data-action="regenerate"] { display: none; }
.message-row.is-last .msg-action[data-action="regenerate"] { display: inline-block; }

.edit-question {
  width: 100%;
  min-width: min(420px, 70vw);
  font: inherit;
  color: #182b3b;
  border: 0;
  border-radius: 8px;
  padding: 8px 10px;
  resize: vertical;
}
.edit-controls { display: flex; gap: 8px; margin-top: 8px; }
.edit-controls button { padding: 6px 12px; font-size: 13px; }
.edit-controls .secondary { background: transparent; color: white; border: 1px solid rgba(255,255,255,.6); }

/* El botón de enviar se convierte en detener mientras se genera la respuesta. */
.chat-composer #send.is-stop { background: #d14b4b; font-size: 18px; }

#jump-bottom {
  position: fixed;
  right: 24px;
  bottom: 120px;
  z-index: 40;
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .25);
}
#jump-bottom[hidden] { display: none; }

/* Barra lateral plegable. */
.header-btn {
  background: transparent;
  color: #c8dbe2;
  border: 1px solid #2f5566;
  padding: 6px 12px;
  font-size: 13px;
}
.header-btn:hover { background: #163b47; }
body.sidebar-collapsed #sidebar { display: none; }

/* ---- Tema claro/oscuro. Cabecera y barra lateral son oscuras en ambos; el resto sigue el
   tema del sistema salvo que se elija uno con el botón de la cabecera. ---- */
:root {
  color-scheme: light;
  --bg: #f2f5f9;
  --text: #182b3b;
  --surface: #ffffff;
  --surface-2: #eef3f6;
  --border: #dce5ea;
  --border-strong: #b9cbd5;
  --muted: #516c79;
  --muted-2: #6f8a96;
  --hover: #e4ecf0;
  --link: #086b78;
  --inline-code: rgba(9, 47, 56, .08);
  --drop-bg: #e7f1f4;
  --field-bg: #ffffff;
  --danger: #ae2633;
  --comp-bg: #ffffff;
  --comp-border: #c9d6dd;
  --comp-border-focus: #8fa9b5;
  --comp-text: #182b3b;
  --comp-placeholder: #7c93a0;
  --comp-hover: #e4ecf0;
  --comp-drop-bg: #e7f1f4;
  --comp-chip-muted: #6f8a96;
  --chart-1: #2a78d6;
  --chart-2: #eb6834;
  --chart-3: #1baf7a;
  --chart-4: #e34948;
  --chart-5: #4a3aa7;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0e1a22;
    --text: #e2edf1;
    --surface: #15252f;
    --surface-2: #122029;
    --border: #274150;
    --border-strong: #35586a;
    --muted: #9db7c1;
    --muted-2: #86a3af;
    --hover: #1f3542;
    --link: #74d9d4;
    --inline-code: rgba(255, 255, 255, .12);
    --drop-bg: #12303a;
    --field-bg: #101d25;
    --danger: #ff9b9b;
    --comp-bg: #15252f;
    --comp-border: #35586a;
    --comp-border-focus: #5f8799;
    --comp-text: #e2edf1;
    --comp-placeholder: #86a3af;
    --comp-hover: #23404f;
    --comp-drop-bg: #16303b;
    --comp-chip-muted: #9db7c1;
    --chart-1: #3987e5;
    --chart-2: #d95926;
    --chart-3: #199e70;
    --chart-4: #e66767;
    --chart-5: #9085e9;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1a22;
  --text: #e2edf1;
  --surface: #15252f;
  --surface-2: #122029;
  --border: #274150;
  --border-strong: #35586a;
  --muted: #9db7c1;
  --muted-2: #86a3af;
  --hover: #1f3542;
  --link: #74d9d4;
  --inline-code: rgba(255, 255, 255, .12);
  --drop-bg: #12303a;
  --field-bg: #101d25;
  --danger: #ff9b9b;
  --comp-bg: #15252f;
  --comp-border: #35586a;
  --comp-border-focus: #5f8799;
  --comp-text: #e2edf1;
  --comp-placeholder: #86a3af;
  --comp-hover: #23404f;
  --comp-drop-bg: #16303b;
  --comp-chip-muted: #9db7c1;
  --chart-1: #3987e5;
  --chart-2: #d95926;
  --chart-3: #199e70;
  --chart-4: #e66767;
  --chart-5: #9085e9;
}

:root { color: var(--text); background: var(--bg); }
body { background: var(--bg); color: var(--text); }
a { color: var(--link); }
small, #status, footer, .sources { color: var(--muted); }
.error { color: var(--danger); }
td, th { border-bottom-color: var(--border); }
main.drag-over { background-color: var(--drop-bg); }
.card { background: var(--surface); border-color: var(--border); }
input, textarea, select { background: var(--field-bg); color: var(--text); border-color: var(--border-strong); }
.document-filters select { background: var(--field-bg); border-color: var(--border-strong); }
.answer code { background: var(--inline-code); }
.message-row.assistant .bubble { background: var(--surface); color: var(--text); border-color: var(--border); }
.message-row.assistant .sources { border-top-color: var(--border); }
.msg-actions { color: var(--muted-2); }
.msg-action:hover { background: var(--hover); color: var(--text); }
.edit-question { background: #fff; color: #182b3b; }
.chat-files { background: var(--surface-2); border-color: var(--border); color: var(--muted); }
.chat-files strong { color: var(--muted-2); }
.chat-files .download-link { background: var(--surface); border-color: var(--border); }
.chat-files .download-link:hover { background: var(--hover); }

/* Cuadro de mensaje: sigue el tema en vez de ser siempre oscuro. */
.chat-composer { background: var(--comp-bg); border-color: var(--comp-border); color: var(--comp-text); }
.chat-composer #question { background: transparent; border: 0; color: inherit; }
.chat-composer #question::placeholder { color: var(--comp-placeholder); }
.chat-composer:focus-within { border-color: var(--comp-border-focus); }
.chat-composer.drag-over { border-color: #3271d1; background: var(--comp-drop-bg); }
.chat-composer #attach-button { color: var(--comp-text); }
.chat-composer #attach-button:hover { background: var(--comp-hover); }
.attachment-chip { border-color: var(--comp-border); }
.attachment-info { color: var(--comp-text); }
.attachment-details small { color: var(--comp-chip-muted); }
.attachment-chip a { color: var(--comp-text); }
.attachment-remove { color: var(--comp-chip-muted); }
.attachment-remove:hover { background: var(--comp-hover); color: var(--comp-text); }
.chat-composer .error { color: var(--danger); }

.chat-files[hidden] { display: none; }

/* Comandos rápidos. */
.shortcut-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.shortcut-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  text-align: left;
  padding: 16px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 14px;
}
.shortcut-card:hover { border-color: #087d83; background: var(--hover); }
.shortcut-card small { color: var(--muted); line-height: 1.4; }
.shortcut-icon { font-size: 26px; line-height: 1; }
#shortcut-form label { margin-bottom: 4px; font-size: 14px; color: var(--muted); }
#shortcut-form input, #shortcut-form select, #shortcut-form textarea { margin-bottom: 14px; }
.shortcut-actions { display: flex; flex-wrap: wrap; gap: 10px; }
button.secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border-strong);
}
button.secondary:hover { background: var(--hover); }

/* Favoritos y uso de los comandos rápidos. */
.shortcut-heading { margin: 22px 0 10px; font-size: 15px; color: var(--muted); }
#shortcut-sections .shortcut-grid { margin-bottom: 8px; }
.shortcut-card-wrap { position: relative; display: flex; }
.shortcut-card-wrap .shortcut-card { flex: 1; padding-right: 48px; }
.shortcut-star {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 4px 8px;
  background: transparent;
  color: var(--muted-2);
  font-size: 20px;
  line-height: 1;
  border-radius: 8px;
}
.shortcut-star:hover { background: var(--hover); color: #e0a800; }
.shortcut-star[data-favorite="true"] { color: #e0a800; }
.shortcut-meta { font-size: 12px; color: #087d83; font-weight: 600; margin-top: 2px; }

/* Administración de usuarios. */
.notice {
  padding: 12px 14px;
  border: 1px solid #087d83;
  border-radius: 10px;
  background: var(--drop-bg);
  margin: 12px 0;
}
.notice code { font-size: 1.05em; user-select: all; padding: 2px 8px; }
.table-scroll { overflow-x: auto; }
.admin-table th { white-space: nowrap; }
.admin-table select { width: auto; margin: 0; }
.admin-table tr.is-inactive td { opacity: .6; }
.chip-list { display: flex; flex-wrap: wrap; gap: 6px 10px; }
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; }
.chip input { width: auto; margin: 0; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.row-actions button { padding: 6px 10px; font-size: 12.5px; }
.badge { padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.ok { background: #d9f2e4; color: #14653a; }
.badge.off { background: #f3dcdc; color: #8a2020; }
.plain-list { margin: 8px 0 14px; padding-left: 20px; }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.inline-form input, .inline-form select { width: auto; flex: 1 1 200px; margin: 0; }
fieldset { border: 1px solid var(--border); border-radius: 10px; margin: 0 0 14px; padding: 10px 14px; }

/* La pantalla de usuarios necesita más ancho que el resto de páginas. */
main:has(.admin-table) { max-width: min(1600px, 96vw); }
.admin-table td, .admin-table th { overflow-wrap: normal; vertical-align: middle; }
.admin-table td:first-child strong { white-space: nowrap; }
.admin-table .badge { white-space: nowrap; display: inline-block; }
.admin-table .row-actions { flex-wrap: nowrap; }
.admin-table .row-actions button { white-space: nowrap; }
.admin-table .chip { white-space: nowrap; }

/* Valoración de respuestas. */
.msg-rate { filter: grayscale(1); opacity: .7; }
.msg-rate:hover { opacity: 1; }
.msg-rate[aria-pressed="true"] { filter: none; opacity: 1; background: var(--hover); }

/* Menú «⋯» de cada chat y secciones secundarias de la barra lateral. */
.chat-row { position: relative; }
.chat-menu {
  position: absolute;
  right: 4px;
  top: 100%;
  z-index: 25;
  min-width: 190px;
  padding: 6px;
  background: #0f2c38;
  border: 1px solid #1f5866;
  border-radius: 10px;
  box-shadow: 0 8px 22px rgba(0, 0, 0, .4);
}
.chat-menu[hidden] { display: none; }
.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 7px 10px;
  background: transparent;
  color: #e4f1f4;
  font-size: 13px;
  border-radius: 6px;
}
.menu-item:hover { background: #164351; }
.menu-item.delete-chat { color: #ffb4b4; }
.menu-move { display: flex; align-items: center; gap: 8px; padding: 5px 10px; font-size: 13px; color: #c8dbe2; }
.menu-move select { width: auto; flex: 1; margin: 0; }
.sidebar-extra { margin-top: 12px; color: #c8dbe2; }
.sidebar-extra summary { cursor: pointer; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: #7fa0ac; padding: 6px 0; }
.sidebar-extra .chat-list { margin-top: 4px; }
.shared-owner { color: #7fa0ac; font-size: 11px; white-space: nowrap; padding-right: 6px; }
.pinned-list .chat-row { cursor: default; }

/* Diálogo de compartir. */
.share-dialog {
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  padding: 22px;
  max-width: 460px;
  width: 92vw;
}
.share-dialog::backdrop { background: rgba(0, 0, 0, .5); }
.share-person { display: flex; align-items: center; gap: 6px; padding: 5px 0; }
.share-person input { width: auto; margin: 0; }

.odoo-warn { color: #b45a00; font-weight: 600; }

/* Lienzo visual de flujos de trabajo (admin). */
.builder-tabs {
  display: flex;
  gap: 4px;
  margin: 16px 0 12px;
  border-bottom: 1px solid var(--border);
}
.builder-tab {
  background: transparent;
  color: var(--muted);
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 8px 14px;
}
.builder-tab:hover { background: var(--hover); color: var(--text); }
.builder-tab[aria-selected="true"] { color: var(--text); border-bottom-color: #087d83; font-weight: 600; }

.canvas-toolbox { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.toolbox-block {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  font-size: 13px;
  padding: 8px 12px;
}
.toolbox-block:hover { background: var(--hover); }

.drawflow-canvas {
  width: 100%;
  height: 480px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  position: relative;
}
.wf-node { padding: 4px 6px; text-align: center; min-width: 110px; }
.wf-node-icon { font-size: 18px; }
.wf-node-name { font-size: 12px; margin-top: 2px; word-break: break-word; }
.drawflow .drawflow-node {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: 8px;
  box-shadow: none;
}
.drawflow .drawflow-node.selected { border-color: #087d83; }
.drawflow .connection .main-path { stroke: var(--muted-2); stroke-width: 3px; }
.drawflow .drawflow-node .input, .drawflow .drawflow-node .output { background: #087d83; }

#node-panel { margin-top: 12px; }
#node-config { display: grid; gap: 8px; margin: 10px 0; }
#node-config label { font-size: 13px; color: var(--muted); }

/* Constructor de flujos de trabajo (admin). */
.workflow-step {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 10px;
}
.workflow-step-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.workflow-step-head input[type="text"] { flex: 1; min-width: 160px; margin: 0; }
.workflow-step-level { display: flex; align-items: center; gap: 4px; font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.workflow-step-level input[type="number"] { width: 52px; margin: 0; }
.workflow-step-config { margin-top: 8px; display: grid; gap: 8px; }
.workflow-step-config label { font-size: 13px; color: var(--muted); }

/* Recuerdos automáticos (memoria entre conversaciones). */
.hint { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
#memory-list { list-style: none; padding: 0; margin: 0; }
#memory-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
#memory-list li:last-child { border-bottom: none; }
.forget-memory {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border-strong);
  padding: 5px 12px;
  font-size: 12.5px;
  flex-shrink: 0;
}
.forget-memory:hover { background: var(--hover); color: var(--text); }
#memory-empty { color: var(--muted); font-size: 13px; }

/* Pestañas del panel de administración. */
.admin-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border);
}
.admin-tab {
  background: transparent;
  color: var(--muted);
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 10px 16px;
}
.admin-tab:hover { background: var(--hover); color: var(--text); }
.admin-tab[aria-selected="true"] { color: var(--text); border-bottom-color: #087d83; font-weight: 600; }

/* Panel de uso y consumo (admin). */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}
.kpi-tile {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}
.kpi-tile .kpi-label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.kpi-tile .kpi-value { font-size: 22px; font-weight: 600; }
.kpi-tile .kpi-sub { display: block; font-size: 11.5px; color: var(--muted-2); margin-top: 2px; }

.usage-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 8px;
}
.usage-grid.full { grid-template-columns: 1fr; }
.chart-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  background: var(--surface);
}
.chart-card h4 { margin: 0 0 2px; font-size: 14px; }
.chart-card .chart-empty { color: var(--muted); font-size: 13px; padding: 20px 0; text-align: center; }
.chart-legend { display: flex; gap: 14px; flex-wrap: wrap; margin: 4px 0 8px; font-size: 12px; color: var(--muted); }
.chart-legend .swatch { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; }

.chart-svg { width: 100%; height: auto; overflow: visible; }
.chart-svg text { fill: var(--muted); font-size: 10.5px; }
.chart-svg .chart-value { fill: var(--text); }
.chart-svg .chart-grid { stroke: var(--border); stroke-width: 1; }
.chart-svg .chart-mark { cursor: default; }

.chart-tooltip {
  position: fixed;
  pointer-events: none;
  background: var(--text);
  color: var(--bg);
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 6px;
  z-index: 50;
  white-space: nowrap;
  opacity: 0;
  transition: opacity .1s;
}
.chart-tooltip.visible { opacity: 1; }

@media (max-width: 720px) {
  .usage-grid { grid-template-columns: 1fr; }
}
