:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --sidebar-bg: #141a21;
  --sidebar-fg: #dfe5ec;
  --sidebar-muted: #8b98a8;
  --border: #e3e7ec;
  --text: #1b2229;
  --text-muted: #64717f;
  --accent: #1f6feb;
  --accent-soft: #eaf1fe;
  --danger: #b42318;
  --danger-soft: #fdf0ef;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
}

.app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 280px;
  flex: 0 0 280px;
  background: var(--sidebar-bg);
  color: var(--sidebar-fg);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  gap: 12px;
}

.sidebar__header { padding: 4px 6px 0; }

.brand { display: flex; align-items: center; gap: 10px; }

.brand__mark {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: .5px;
}

.brand__name { font-weight: 600; font-size: 16px; }

.btn-new {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 10px;
  background: rgba(255,255,255,.06);
  color: var(--sidebar-fg);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background .15s ease;
}
.btn-new:hover { background: rgba(255,255,255,.12); }

.sidebar__section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--sidebar-muted);
  padding: 8px 8px 0;
}

.conv-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }

.conv-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--sidebar-fg);
  background: none;
  border: none;
  font: inherit;
  text-align: left;
  width: 100%;
}
.conv-item:hover { background: rgba(255,255,255,.07); }
.conv-item--active { background: rgba(255,255,255,.14); }

.conv-item__title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.conv-item__delete {
  opacity: 0;
  background: none;
  border: none;
  color: var(--sidebar-muted);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 5px;
}
.conv-item:hover .conv-item__delete,
.conv-item__delete:focus-visible { opacity: 1; }
.conv-item__delete:hover { color: #fff; background: rgba(255,255,255,.12); }

.conv-empty { color: var(--sidebar-muted); font-size: 13px; padding: 8px 10px; }

.sidebar__footer {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--sidebar-muted);
  padding: 8px 8px 0;
  border-top: 1px solid rgba(255,255,255,.08);
}

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #d0a215;
  flex: 0 0 8px;
}
.status-dot--ok { background: #2fa36b; }

.sidebar-backdrop { display: none; }

/* ---------- Chat ---------- */
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }

.chat__header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.chat__title { margin: 0; font-size: 16px; font-weight: 600; }
.chat__subtitle { margin: 0; font-size: 13px; color: var(--text-muted); }

.icon-btn {
  display: none;
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 16px;
  color: var(--text);
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.msg { max-width: 760px; width: 100%; margin: 0 auto; display: flex; flex-direction: column; }
.msg__bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg--user { align-items: flex-end; }
.msg--user .msg__bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
  max-width: 80%;
}

.msg--assistant .msg__bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.msg--error .msg__bubble {
  background: var(--danger-soft);
  border: 1px solid #f3c9c5;
  color: var(--danger);
}

.msg__role {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

/* Acciones bajo la respuesta */
.msg__actions {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  padding-left: 2px;
  opacity: 0;
  transition: opacity .15s ease;
}
.msg:hover .msg__actions,
.msg__actions:focus-within { opacity: 1; }

.msg__action {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: none;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 4px 8px;
  font: inherit;
  font-size: 12.5px;
  color: var(--text-muted);
  cursor: pointer;
}
.msg__action:hover { background: var(--surface); border-color: var(--border); color: var(--text); }
.msg__action--done { color: #2fa36b; }

.msg__action-icon { font-size: 13px; line-height: 1; }

/* En pantallas táctiles no hay hover: mantener las acciones visibles */
@media (hover: none) {
  .msg__actions { opacity: 1; }
}

/* Fuentes y fragmentos */
.evidence { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }

.evidence__block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.evidence__toggle {
  width: 100%;
  background: none;
  border: none;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 10px 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: left;
}
.evidence__toggle:hover { background: var(--accent-soft); color: var(--accent); }
.evidence__caret { transition: transform .15s ease; display: inline-block; }
.evidence__block[open] .evidence__caret { transform: rotate(90deg); }

.evidence__body { padding: 0 14px 12px; display: flex; flex-direction: column; gap: 10px; }

.source {
  border-left: 3px solid var(--accent);
  padding-left: 10px;
  font-size: 13.5px;
}
.source__doc { font-weight: 600; }
.source__meta { color: var(--text-muted); font-size: 13px; }

.chunk {
  border-left: 3px solid var(--border);
  padding: 2px 0 2px 10px;
  font-size: 13.5px;
  color: var(--text-muted);
  font-style: italic;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* Estado de carga */
.typing { display: inline-flex; align-items: center; gap: 8px; color: var(--text-muted); }
.typing__dots { display: inline-flex; gap: 3px; }
.typing__dots span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-muted);
  animation: blink 1.2s infinite ease-in-out;
}
.typing__dots span:nth-child(2) { animation-delay: .2s; }
.typing__dots span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.empty-state {
  margin: auto;
  max-width: 460px;
  text-align: center;
  color: var(--text-muted);
}
.empty-state h2 { color: var(--text); font-size: 18px; margin: 0 0 6px; }
.empty-state p { margin: 0; font-size: 14px; }

/* ---------- Composer ---------- */
.composer { padding: 12px 24px 18px; background: var(--bg); }

.composer__box {
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px 8px 8px 14px;
}
.composer__box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.composer__input {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font: inherit;
  color: var(--text);
  background: transparent;
  max-height: 180px;
  padding: 6px 0;
}

.btn-send {
  flex: 0 0 auto;
  width: 36px; height: 36px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.btn-send:disabled { background: #c3cbd6; cursor: not-allowed; }

.composer__hint {
  max-width: 760px;
  margin: 8px auto 0;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    transform: translateX(-100%);
    transition: transform .2s ease;
  }
  .sidebar--open { transform: translateX(0); }
  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 15;
  }
  .sidebar-backdrop[hidden] { display: none; }
  .icon-btn { display: block; }
  .messages { padding: 20px 14px; }
  .composer { padding: 10px 14px 14px; }
}

/* Ocultar el marcador nativo de <details> en los bloques de evidencia */
.evidence__toggle { list-style: none; }
.evidence__toggle::-webkit-details-marker { display: none; }
