:root {
  --paper: #eef2f6;
  --surface: #ffffff;
  --ink: #12213a;
  --muted: #5a6b84;
  --line: #d5dce6;
  --accent: #7b3706;
  --accent-strong: #1f3cb0;
  --on-accent: #ffffff;
  --tool-bg: #fff1cc;
  --tool-ink: #6b4700;
  --error-bg: #fde8e8;
  --error-ink: #8a1c1c;
  --ok: #1f9d63;

  --font-display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --font-body: "Instrument Sans", "Segoe UI", system-ui, sans-serif;

  /* Estilos Personalizados para el Chat */
  --primary-color: #3a1a05; /* Indigo moderno */
  --primary-light: #e0e7ff;
  --bg-color: #00000000;
  --sidebar-bg: #ffffff;
  --chat-bg: #ffffff;
  --text-main: #1f2937;
  --text-secondary: #6b7280;
  --border-color: #e5e7eb;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);

  /*VARIABLES DE COLOR PARA LAS CATEGORIAS*/
  --dgala-oro: #b8923a;
  --dgala-oro-claro: #A16C08; /*#D1B22E;*/
  --dgala-texto: #2b2b2b;
  --dgala-fondo: #ffffff;
  --dgala-borde: #e6e0d2;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  height: 100vh;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

button, textarea { font: inherit; color: inherit; }

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Estructura general ---------- */
.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 760px;
  margin: 0 auto;
  padding: 0 16px;
}

/* ---------- Cabecera ---------- */
.top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 0 14px;
  border-bottom: 2px solid var(--ink);
}

.brand h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2rem, 7vw, 2.9rem);
  line-height: 0.95;
  letter-spacing: -0.03em;
}

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--ok);
}
.dot.off { background: #c28a00; }

.ghost {
  flex-shrink: 0;
  padding: 8px 12px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.9rem;
  cursor: pointer;
}
.ghost:hover { border-color: var(--ink); color: var(--ink); }

/* ---------- Mensajes ---------- */
.log {
  flex: 1;
  overflow-y: auto;
  padding: 20px 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.msg {
  display: flex;
  flex-direction: column;
  max-width: 85%;
}
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.bot  { align-self: flex-start; align-items: flex-start; }

.bubble {
  padding: 10px 14px;
  border-radius: 14px;
  overflow-wrap: anywhere;
}
.bubble p { margin: 0; }
.bubble p + p, .bubble p + ul, .bubble ul + p { margin-top: 8px; }
.bubble ul { margin: 0; padding-left: 20px; }
.bubble li + li { margin-top: 2px; }

.msg.bot .bubble {
  background: var(--surface);
  border: 1px solid var(--line);
  border-top-left-radius: 4px;
  line-height: 1.55;
}
.msg.user .bubble {
  background: var(--accent);
  color: var(--on-accent);
  border-top-right-radius: 4px;
}
.msg.error .bubble {
  background: var(--error-bg);
  border-color: transparent;
  color: var(--error-ink);
}

.tools {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}
.tool-badge {
  padding: 2px 8px;
  background: var(--tool-bg);
  color: var(--tool-ink);
  border-radius: 6px;
  font-size: 0.8rem;
}

/* ---------- Indicador de escritura ---------- */
.typing .bubble {
  display: flex;
  gap: 5px;
  padding: 14px 16px;
}
.typing span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: pulse 1.1s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes pulse {
  0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

/* ---------- Preguntas rápidas ---------- */
.chips {
  display: flex;
  gap: 8px;
  padding: 4px 0 12px;
  overflow-x: auto;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex-shrink: 0;
  padding: 8px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.92rem;
  cursor: pointer;
}
.chip:hover { border-color: var(--accent); color: var(--accent-strong); }
.chip:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Campo de texto ---------- */
.composer {
  display: flex;
  gap: 8px;
  padding: 0 0 max(16px, env(safe-area-inset-bottom));
}

.composer textarea {
  flex: 1;
  resize: none;
  max-height: 140px;
  padding: 11px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  line-height: 1.4;
}
.composer textarea:focus-visible { border-color: var(--accent); outline-offset: 0; }

.composer button {
  padding: 0 20px;
  background: var(--accent);
  border: 0;
  border-radius: 12px;
  color: var(--on-accent);
  font-weight: 600;
  cursor: pointer;
}
.composer button:hover { background: var(--accent-strong); }
.composer button:disabled { opacity: 0.5; cursor: not-allowed; }

@media (prefers-reduced-motion: reduce) {
  .log { scroll-behavior: auto; }
  .typing span { animation: none; opacity: 0.6; }
}

/* ------------------------------------------------- */
/* Contenedor Principal */
.main-container {
    width: 100%;
    max-width: 1200px;
    height: 100vh;
    background-color: var(--chat-bg);
    border-radius: 20px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    display: flex;
    overflow: hidden;
}
/* Área de Chat */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: #fff;
}

.chat-header {
    padding: 15px 25px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.user-details {
    display: flex;
    align-items: center;
}

.user-details img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    margin-right: 12px;
}

.user-details h3 {
    font-size: 1rem;
    color: var(--text-main);
}

.status {
    font-size: 0.8rem;
    color: #10b981; /* Verde éxito */
    display: block;
}

.header-actions i {
    color: var(--text-secondary);
    margin-left: 20px;
    cursor: pointer;
    font-size: 1.1rem;
    transition: color 0.2s;
}

.header-actions i:hover {
    color: var(--primary-color);
}

/* Mensajes */
.messages-container {
    flex: 1;
    padding: 25px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
    /*background-color: #e7e7e7;*/
    background-image: url('https://img.freepik.com/vector-premium/joyas-patrones-fisuras-textura-fondo-fondos-pantalla-ornamento-fin-impresion-repetitiva_684413-215.jpg');
    background-repeat: no-repeat;
    background-size: cover;
}

.message {
    display: flex;
    align-items: flex-end;
    max-width: 70%;
}

.message img {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    margin-right: 10px;
    margin-bottom: 5px;
}

.message-content {
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.4;
    position: relative;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.message.received {
    align-self: flex-start;
}

.message.received .message-content {
    background-color: #ffffff;
    color: var(--text-main);
    border-bottom-left-radius: 4px;
}

.message.sent {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message.sent img {
    display: none; /* Ocultar avatar en enviados */
}

.message.sent .message-content {
    background-color: var(--primary-color);
    color: white;
    border-bottom-right-radius: 4px;
}

.time {
    display: block;
    font-size: 0.7rem;
    margin-top: 5px;
    opacity: 0.7;
    text-align: right;
}

/* Input Area */
.chat-input-area {
    padding: 20px 25px;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 15px;
}

.attach-btn, .send-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
    color: var(--text-secondary);
    transition: color 0.2s;
}

.attach-btn:hover, .send-btn:hover {
    color: var(--primary-color);
}

#messageInput {
    flex: 1;
    padding: 12px 15px;
    border-radius: 25px;
    border: 1px solid var(--border-color);
    background-color: #f9fafb;
    outline: none;
    transition: 0.3s;
}

#messageInput:focus {
    border-color: var(--primary-color);
    background-color: #fff;
}

.send-btn {
    background-color: var(--primary-color);
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 6px rgba(99, 102, 241, 0.3);
}

.send-btn:hover {
    background-color: #4f46e5;
    color: white;
    transform: scale(1.05);
}

/*ESTILOS PARA LAS CATEGORIAS*/
.categorias {
  max-width: 720px;
  /*margin: 2rem auto;
  padding: 1.5rem;*/
  background: var(--dgala-fondo);
  /*border: 1px solid var(--dgala-borde);
  border-radius: 16px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);*/
}
.categorias__titulo {
  margin: 0 0 1.25rem;
  padding-bottom: 0.75rem;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.0rem;
  letter-spacing: 0.04em;
  color: var(--dgala-oro);
  border-bottom: 2px solid var(--dgala-oro);
}
.categorias__lista {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.75rem;
  margin: 0;
  padding: 0;
  list-style: none;
}
.categorias__item {
  display: block;
  padding: 0.4rem 0.1rem;
  text-align: center;
  text-decoration: none;
  font-family: system-ui, sans-serif;
  font-weight: 500;
  color: var(--dgala-texto);
  background: var(--dgala-oro-claro);
  border: 1px solid transparent;
  border-radius: 999px;
  transition: background 0.2s, color 0.2s, transform 0.2s, border-color 0.2s;
}
.categorias__item:hover {
  background: var(--dgala-oro);
  color: #fff;
  transform: translateY(-2px);
}
.categorias__item:focus-visible {
  outline: 3px solid var(--dgala-oro);
  outline-offset: 2px;
}
@media (max-width: 480px) {
  .categorias__lista {
    grid-template-columns: repeat(2, 1fr);
  }
}

/*PROCESAMIENTO DE LISTA DE CATEGORIAS*/
ol {
  counter-reset: li; /* Initiate a counter */
  list-style: none; /* Remove default numbering */
  *list-style: decimal; /* Keep using default numbering for IE6/7 */
  font: 14px 'trebuchet MS', 'lucida sans';
  padding: 0;
  margin-bottom: 1em;
  text-shadow: 0 1px 0 rgba(255,255,255,.5);
}

ol ol {
  margin: 0 0 0 2em; /* Add some left margin for inner lists */
}

.rounded-list a{
  position: relative;
  display: block;
  padding: .8em .4em .8em 3em;
  *padding: .4em;
  margin: .7em 0;
  background: #A16C08;
  color: #ffffff;
  text-decoration: none;
  border-radius: .3em;
  transition: all .3s ease-out;
}
.rounded-list a:hover{
  background: #2b2b2b;
}
.rounded-list a:hover:before{
  transform: rotate(360deg);
}
.rounded-list a:before{
  content: "";
  /*counter-increment: li;*/
  position: absolute;
  left: 0.5em;
  top: 50%;
  margin-top: -1em;
  background: #2b2b2b;
  height: 2em;
  width: 2em;
  line-height: 2em;
  border: .3em solid #FAC12D;
  text-align: center;
  font-weight: bold;
  border-radius: 2em;
  transition: all .3s ease-out;
}