/* ─── Reset y variables ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --rojo:         #c8102e;
  --rojo-oscuro:  #6c0b12;
  --negro:        #000000;
  --gris:         #1d1d1b;   /* texto principal */
  --gris-dim:     #6b6b6b;   /* texto secundario */
  --gris-suave:   #9c9b9b;   /* usuario */
  --gris-medio:   #c3c3c3;   /* bordes, wave idle */
  --gris-claro:   #f5f5f5;   /* fondos secundarios */
  --blanco:       #ffffff;
  --borde:        #eeeeee;
  --radius:       6px;
  --radius-sm:    4px;
}

html, body {
  height: 100%;
  font-family: 'Montserrat', sans-serif;
  background: var(--blanco);
  color: var(--gris);
  overflow: hidden;
}

/* ─── Estructura principal ──────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ─── Header ────────────────────────────────────────────────────── */
#header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 100px;
  height: 64px;
  background: var(--blanco);
  border-bottom: 1px solid var(--borde);
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}

.header-logo {
  display: flex;
  align-items: center;
  text-decoration: none;
  flex-shrink: 0;
  position: absolute;
    top: 0;
    left: 0;
}

.header-logo img {
  display: block;
      width: 100%;
    height: 100%;
}

.logo-fallback {
  font-family: 'Playfair Display', serif;
  font-size: 18px;
  font-weight: 500;
  color: var(--rojo);
  letter-spacing: 0.04em;
}

.header-divider {
  display: block;
  width: 1px;
  height: 28px;
  background: var(--borde);
  flex-shrink: 0;
}

.header-subtitle {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gris-dim);
}

#btn-clear {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  background: none;
  border: 1px solid var(--gris-medio);
  color: var(--gris-dim);
  padding: 6px 14px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 11px;
  font-family: 'Montserrat', sans-serif;
  font-weight: 500;
  letter-spacing: 0.04em;
  transition: border-color 0.2s, color 0.2s;
}

#btn-clear:hover {
  border-color: var(--rojo);
  color: var(--rojo);
}

#btn-clear i {
  width: 13px;
  height: 13px;
}

/* ─── Main layout (conversation + panel) ───────────────────────── */
#main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ─── Conversation column ───────────────────────────────────────── */
#conversation {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

/* ─── Entidad animada (canvas wave, full-width) ─────────────────── */
#entity {
  width: 100%;
  padding: 20px 0 8px;
  flex-shrink: 0;
  overflow: hidden;   /* recorta el glow que pueda sobresalir */
  display: none;;
}

#entity-canvas {
  display: block;
  width: 100%;        /* tamaño real gestionado por JS (DPR-aware) */
}

/* ─── Mensajes ──────────────────────────────────────────────────── */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 49px 250px 24px;
  display: flex;
  flex-direction: column;
  gap: 0;
  scroll-behavior: smooth;
}

#messages::-webkit-scrollbar { width: 4px; }
#messages::-webkit-scrollbar-track { background: transparent; }
#messages::-webkit-scrollbar-thumb { background: var(--gris-medio); border-radius: 2px; }

.msg {
  display: flex;
  flex-direction: column;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg.teatro {
  align-self: flex-start;
  max-width: 80%;
  margin-bottom: 28px;
}

.msg.user {
  align-self: flex-end;
  max-width: 70%;
  margin-bottom: 20px;
}

/* Avatar labels */
.msg .avatar {
  display: flex;
  align-items: center;
  margin-bottom: 6px;
}

.msg.teatro .avatar {
  justify-content: flex-start;
}

.msg.user .avatar {
  justify-content: flex-end;
}

.msg .avatar .label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.msg.teatro .avatar .label {
  color: var(--rojo);
}

.msg.user .avatar .label {
  color: var(--gris-suave);
}

/* Bubbles — transparent, no border */
.bubble {
  background: none;
  border: none;
  padding: 0;
  word-break: break-word;
}

/* Teatro: base Montserrat para párrafos, Playfair para encabezados */
.msg.teatro .bubble {
  font-family: 'Montserrat', sans-serif;
  font-size: 14px;
  line-height: 1.8;
  color: var(--gris);
}

/* Markdown: encabezados en Playfair */
.msg.teatro .bubble h1,
.msg.teatro .bubble h2,
.msg.teatro .bubble h3,
.msg.teatro .bubble h4,
.msg.teatro .bubble h5,
.msg.teatro .bubble h6 {
  font-family: 'Playfair Display', serif;
  font-weight: 500;
  color: var(--gris);
  margin-top: 20px;
  margin-bottom: 8px;
  line-height: 1.3;
}

.msg.teatro .bubble h2 { font-size: 20px; }
.msg.teatro .bubble h3 { font-size: 17px; }
.msg.teatro .bubble h4 { font-size: 15px; }

/* Primer párrafo: ligera serif para entrada elegante */
.msg.teatro .bubble > p:first-child {
  font-family: 'Playfair Display', serif;
  font-size: 16px;
  line-height: 1.85;
}

.msg.teatro .bubble p {
  margin-bottom: 10px;
}

.msg.teatro .bubble p:last-child {
  margin-bottom: 0;
}

.msg.teatro .bubble ul,
.msg.teatro .bubble ol {
  margin: 8px 0 10px 20px;
}

.msg.teatro .bubble li {
  margin-bottom: 4px;
  line-height: 1.7;
}

.msg.teatro .bubble strong {
  font-weight: 600;
  color: var(--gris);
}

.msg.teatro .bubble em {
  font-style: italic;
}

.msg.teatro .bubble blockquote {
  border-left: 2px solid var(--rojo);
  margin: 12px 0;
  padding: 6px 16px;
  color: var(--gris-dim);
  font-style: italic;
}

.msg.teatro .bubble code {
  font-family: 'Courier New', monospace;
  font-size: 12px;
  background: var(--gris-claro);
  padding: 2px 6px;
  border-radius: 3px;
}

.msg.teatro .bubble pre {
  background: var(--gris-claro);
  padding: 12px;
  border-radius: var(--radius);
  overflow-x: auto;
  margin: 10px 0;
}

.msg.teatro .bubble pre code {
  background: none;
  padding: 0;
}

.msg.teatro .bubble hr {
  border: none;
  border-top: 1px solid var(--borde);
  margin: 16px 0;
}

/* User: Montserrat small gray, right-aligned */
.msg.user .bubble {
  font-family: 'Montserrat', sans-serif;
  font-size: 13px;
  line-height: 1.6;
  color: var(--gris-suave);
  text-align: right;
}

/* Thinking state */
.bubble.thinking {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0;
}

.bubble.thinking .dots {
  display: none; /* replaced by entity wave animation */
}

.bubble.thinking .thinking-label {
  font-family: 'Playfair Display', serif;
  font-style: italic;
  font-size: 15px;
  color: var(--gris-dim);
}

/* Tool badge */
.tool-badge {
  font-family: 'Montserrat', sans-serif;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.06em;
  color: var(--rojo);
  opacity: 0.6;
  margin-top: 6px;
  display: block;
}

/* ─── Cursor de streaming ───────────────────────────────────────── */
.cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--rojo);
  margin-left: 2px;
  animation: blink-cur 0.8s step-end infinite;
  vertical-align: text-bottom;
  opacity: 0.7;
}

@keyframes blink-cur { 50% { opacity: 0; } }

/* ─── Galería de archivos (en bubble — solo móvil) ──────────────── */
.archivos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.archivo-card {
  border: 1px solid var(--borde);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
  font-family: 'Montserrat', sans-serif;
  background: var(--blanco);
}

.archivo-card:hover {
  border-color: var(--gris-medio);
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
}

.archivo-card .thumb {
  width: 100%;
  height: 100px;
  object-fit: cover;
  display: block;
  background: var(--gris-claro);
}

.archivo-card .thumb-placeholder {
  width: 100%;
  height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gris-claro);
}

.file-ext {
  font-family: 'Montserrat', sans-serif;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--rojo);
}

.archivo-card .card-body {
  padding: 8px 10px;
}

.archivo-card .card-tipo {
  font-size: 9px;
  font-weight: 600;
  color: var(--gris-dim);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 3px;
}

.archivo-card .card-pie {
  font-size: 11px;
  color: var(--gris);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-height: 1.4;
}

/* ─── Resize handle ─────────────────────────────────────────────── */
#resize-handle {
  width: 5px;
  flex-shrink: 0;
  cursor: col-resize;
  background: var(--borde);
  transition: background 0.2s;
  position: relative;
}

#resize-handle::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 1px;
  height: 40px;
  background: var(--gris-medio);
  border-radius: 1px;
  opacity: 0;
  transition: opacity 0.2s;
}

#resize-handle:hover,
#resize-handle.resizing {
  background: rgba(200, 16, 46, 0.12);
}

#resize-handle:hover::after,
#resize-handle.resizing::after {
  opacity: 1;
  background: var(--rojo);
}

/* ─── Panel lateral ─────────────────────────────────────────────── */
#panel-archivos {
  width: 280px;
  flex-shrink: 0;
  border-left: 1px solid var(--borde);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#panel-header {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--rojo);
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--borde);
  flex-shrink: 0;
}

#panel-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px 20px;
  text-align: center;
}

#panel-placeholder p {
  font-size: 12px;
  color: var(--gris-medio);
  line-height: 1.6;
  font-family: 'Montserrat', sans-serif;
}

#panel-items {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

#panel-items::-webkit-scrollbar { width: 3px; }
#panel-items::-webkit-scrollbar-thumb { background: var(--gris-medio); border-radius: 2px; }

/* Panel cards: 2-column narrow grid */
#panel-items .archivos-grid {
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 0;
}

#panel-items .archivo-card .thumb,
#panel-items .archivo-card .thumb-placeholder {
  height: 78px;
}

/* ─── Suggestions ───────────────────────────────────────────────── */
#suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 250px 16px;
  flex-shrink: 0;
}

.suggestion-btn {
  background: none;
  border: 1px solid var(--borde);
  border-radius: 20px;
  padding: 7px 16px;
  color: var(--gris-dim);
  font-size: 12px;
  font-family: 'Montserrat', sans-serif;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
  letter-spacing: 0.01em;
}

.suggestion-btn:hover {
  border-color: var(--rojo);
  color: var(--rojo);
}

/* ─── Input bar ─────────────────────────────────────────────────── */
#input-bar {
  padding: 12px 250px 16px;
  background: var(--blanco);
  /*border-top: 1px solid var(--borde);*/
  flex-shrink: 0;
}

#input-bar .wrapper-input-bar {
    border: 1px solid var(--borde);
    border-radius: 10px;
    padding: 0 10px 10px;
    box-shadow: 0px 0px 7px 0px #0000001a;
}

#input-form {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

#input-field {
  flex: 1;
  background: none;
  border: none;
  border-bottom: 1px solid var(--gris-medio);
  padding: 10px 0;
  color: var(--gris);
  font-size: 14px;
  font-family: 'Montserrat', sans-serif;
  font-weight: 400;
  resize: none;
  min-height: 45px;
  max-height: 200px;
  line-height: 1.5;
  outline: none;
  transition: border-color 0.2s;
  border-radius: 0;
      overflow: hidden;
}

#input-field:focus {
  border-bottom-color: var(--rojo);
}

#input-field::placeholder {
  color: var(--gris-medio);
  font-weight: 300;
}

#btn-send {
  background: none;
  border: none;
  padding: 6px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--rojo);
  transition: background 0.18s, opacity 0.18s;
  margin-bottom: 1px;
}

#btn-send:hover:not(:disabled) {
  background: rgba(200, 16, 46, 0.08);
}

#btn-send:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

#btn-send svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  display: block;
}

#btn-send.is-streaming #icon-loading {
  animation: spin-loading 0.9s linear infinite;
}

@keyframes spin-loading {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

#hint {
  font-size: 10px;
  color: var(--gris-medio);
  font-family: 'Montserrat', sans-serif;
  margin-top: 8px;
  letter-spacing: 0.02em;
}

/* ─── Lightbox ──────────────────────────────────────────────────── */
#lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  z-index: 1000;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

#lightbox.open { display: flex; }

#lb-content {
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: min(90vw, 1000px);
  max-height: 80vh;
}

#lightbox img {
  max-width: 100%;
  max-height: 80vh;
  border-radius: var(--radius);
  object-fit: contain;
}

#lightbox iframe {
  width: min(90vw, 900px);
  height: 80vh;
  background: white;
  border-radius: var(--radius);
  border: none;
}

.lb-info {
  margin-top: 16px;
  text-align: center;
  color: rgba(255,255,255,0.6);
  font-size: 12px;
  font-family: 'Montserrat', sans-serif;
  max-width: 600px;
  letter-spacing: 0.03em;
}

.lb-close {
  position: absolute;
  top: 20px;
  right: 24px;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s;
  color: white;
}

.lb-close:hover {
  background: rgba(255,255,255,0.2);
}

.lb-close i {
  width: 18px;
  height: 18px;
  stroke: white;
}

/* ─── Responsive ────────────────────────────────────────────────── */
@media (max-width: 768px) {
  #panel-archivos,
  #resize-handle {
    display: none;
  }

  #messages {
    padding: 8px 20px 16px;
  }

  #suggestions {
    padding: 0 20px 12px;
  }

  #input-bar {
    padding: 10px 20px 14px;
  }

  .msg.teatro { max-width: 95%; }
  .msg.user   { max-width: 95%; }

  .archivos-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  }
}

@media (max-width: 480px) {
  #header {
    padding: 0 16px;
    gap: 10px;
  }
  .header-divider,
  .header-subtitle {
    display: none;
  }
}
