/* Estilos extraídos del Portal de Enlaces para el Bot */
:root{
  --brand-green:#FF5900;
  --wa-header:#075E54;
  --wa-send:#128C7E;
  --bot-panel-bg:#fff;
  --bot-backdrop:rgba(0,0,0,.35);
  --bot-chat-bg:#ECE5DD;
  --bot-msg-bot:#fff;
  --bot-msg-user:#DCF8C6;
  --bot-border:rgba(0,0,0,.08);
  --vvh: 1vh;
  --peek: 70px;
}

/* Soporte para Tema Oscuro si el cuerpo tiene data-theme="dark" */
[data-theme="dark"]{
  --bot-panel-bg:#1d1d1d;
  --bot-border:rgba(255,255,255,.10);
  --bot-chat-bg:#141414;
  --bot-msg-bot:#242424;
  --bot-msg-user:#1f3b2b;
  --bot-backdrop:rgba(0,0,0,.55);
}

.bot-backdrop{
  position:fixed;
  inset:0;
  background:var(--bot-backdrop);
  opacity:0;
  pointer-events:none;
  transition:opacity .18s ease;
  z-index:9998;
}
.bot-backdrop.is-open{
  opacity:1;
  pointer-events:auto;
}

.bot-fab{
  position:fixed;
  right:20px;
  bottom:20px;
  width:62px;
  height:62px;
  border-radius:50%;
  border:none;
  background:var(--brand-green);
  color:#fff;
  display:grid;
  place-items:center;
  cursor:pointer;
  box-shadow:0 10px 25px rgba(0,0,0,.25);
  z-index:9999;
  transition:transform .12s ease;
}
.bot-fab:hover{ transform:translateY(-1px); }
.bot-fab:active{ transform:translateY(0) scale(.98); }

.fab-emoji{
  font-size:28px;
  line-height:1;
  transform:translateY(1px);
  user-select:none;
}

.bot-panel{
  position:fixed;
  right:20px;
  bottom:95px;
  width:360px;
  height: min(540px, calc(100vh - 140px));
  max-height: calc(100vh - 140px);
  background:var(--bot-panel-bg);
  border-radius:16px;
  box-shadow:0 16px 40px rgba(0,0,0,.28);
  border:1px solid var(--bot-border);
  display:flex;
  flex-direction:column;
  overflow:hidden;
  opacity:0;
  transform:translateY(14px) scale(.98);
  pointer-events:none;
  transition:opacity .18s ease, transform .18s ease;
  z-index:9999;
}
.bot-panel.is-open{
  opacity:1;
  transform:translateY(0) scale(1);
  pointer-events:auto;
}

.bot-header{
  background:var(--wa-header);
  color:#fff;
  padding:12px 12px;
  display:flex;
  align-items:center;
  justify-content:space-between;
}

.bot-title{
  display:flex;
  align-items:center;
  gap:10px;
}
.bot-avatar{
  width:34px;
  height:34px;
  border-radius:50%;
  background:rgba(255,255,255,.14);
  display:grid;
  place-items:center;
  font-size:18px;
}
.bot-title-text{
  display:flex;
  flex-direction:column;
  line-height:1.05;
}
.bot-name{ font-size:15px; font-weight:700; font-family: sans-serif; }
.bot-status{ font-size:12px; opacity:.85; font-family: sans-serif; }

.bot-actions{
  display:flex;
  align-items:center;
  gap:6px;
}

.bot-menu{
  position:relative;
}
.bot-menu-btn{
  border:none;
  background:transparent;
  color:#fff;
  cursor:pointer;
  font-size:26px;
  line-height:1;
  padding:4px 10px;
  border-radius:10px;
}
.bot-menu-btn:hover{
  background:rgba(255,255,255,.14);
}
.bot-menu-dropdown{
  position:absolute;
  right:0;
  top:42px;
  min-width:210px;
  background:var(--bot-panel-bg);
  border:1px solid var(--bot-border);
  border-radius:12px;
  box-shadow:0 14px 30px rgba(0,0,0,.22);
  padding:6px;
  display:none;
  z-index:10000;
}
.bot-menu-dropdown.is-open{
  display:block;
}
.bot-menu-item{
  width:100%;
  text-align:left;
  border:none;
  background:transparent;
  color: #333; /* Forzamos color para legibilidad */
  padding:10px 10px;
  border-radius:10px;
  cursor:pointer;
  font-size:14px;
}
[data-theme="dark"] .bot-menu-item { color: #f1f1f1; }
.bot-menu-item:hover{
  background:rgba(0,0,0,.06);
}

.bot-close{
  border:none;
  background:transparent;
  color:#fff;
  cursor:pointer;
  padding:6px 10px;
  font-size:20px;
  line-height:1;
  border-radius:10px;
}
.bot-close:hover{
  background:rgba(255,255,255,.14);
}

.bot-messages{
  flex:1;
  padding:12px;
  overflow-y:auto;
  display:flex;
  flex-direction:column;
  gap:10px;
  background:
    radial-gradient(circle at 20px 20px, rgba(0,0,0,.03) 0 2px, transparent 3px) 0 0/40px 40px,
    var(--bot-chat-bg);
  will-change: scroll-position;
}

.msg{
  max-width:82%;
  padding:10px 12px;
  border-radius:14px;
  font-size:14px;
  line-height:1.25;
  white-space:pre-wrap;
  word-wrap:break-word;
  box-shadow:0 1px 0 rgba(0,0,0,.08);
  border:1px solid var(--bot-border);
  font-family: sans-serif;
}
.msg.bot{
  align-self:flex-start;
  background:var(--bot-msg-bot);
  border-top-left-radius:6px;
  color: #333;
  /* Privilegiar respuesta corta eliminando espacios finales */
  display: flex;
  flex-direction: column;
}
.msg.user{
  align-self:flex-end;
  background:var(--bot-msg-user);
  border-top-right-radius:6px;
  color: #333;
}
[data-theme="dark"] .msg.bot, [data-theme="dark"] .msg.user { color: #f1f1f1; }

.msg.typing{
  max-width:160px;
  padding:12px 14px;
}
.typing-dots{
  display:inline-flex;
  gap:6px;
  align-items:center;
}
.typing-dots span{
  width:7px;
  height:7px;
  border-radius:50%;
  background:rgba(0,0,0,.45);
  animation:typingBounce 1.1s infinite ease-in-out;
}
@keyframes typingBounce{
  0%, 80%, 100% { transform:translateY(0); opacity:.55; }
  40% { transform:translateY(-5px); opacity:1; }
}

.bot-input{
  padding:10px;
  background:rgba(0,0,0,.03);
  border-top:1px solid var(--bot-border);
  display:flex;
  align-items:flex-end;
  gap:10px;
}

.bot-input textarea{
  flex:1;
  min-height:42px;
  max-height:120px;
  height:42px;
  resize:none;
  overflow-y:auto;
  padding:10px 12px;
  border-radius:18px;
  border:1px solid var(--bot-border);
  outline:none;
  font-size:14px;
  background:var(--bot-panel-bg);
  color: inherit;
}

.bot-input button{
  width:44px;
  height:44px;
  border-radius:50%;
  border:none;
  cursor:pointer;
  background:var(--wa-send);
  color:#fff;
  font-weight:800;
  display:grid;
  place-items:center;
}

@media (max-width:520px){
  .bot-panel{
    right:10px;
    left:10px;
    bottom:10px;
    width:auto;
    height: calc((var(--vvh) * 100) - 20px - var(--peek));
    border-radius:18px;
  }
  .bot-input textarea { font-size: 16px !important; }
}

.sources-wrapper {
  margin-top: 4px; 
  border-top: 1px dashed var(--bot-border);
  padding-top: 4px;
  width: 100%;
}

.sources-toggle {
  background: none;
  border: none;
  color: var(--wa-send);
  font-size: 11px;
  font-weight: bold;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px; /* Espacio para la flecha del CSS */
  padding: 2px 0;
  text-transform: uppercase;
  font-family: sans-serif;
}

/* Esta es la flecha animada del CSS */
.sources-toggle::after {
  content: '▶'; 
  font-size: 8px;
  display: inline-block;
  transition: transform 0.2s ease;
}

/* Cuando se abre, la flecha gira */
.sources-toggle.active::after {
  transform: rotate(90deg); 
}

.sources-content {
  display: none; 
  font-size: 11px;
  color: #666;
  font-family: 'Courier New', Courier, monospace;
  line-height: 1.3;
  margin-top: 4px;
  padding: 6px;
  background: rgba(0,0,0,0.02);
  border-radius: 4px;
  border-left: 2px solid var(--wa-send);
}

.sources-content.show {
  display: block; 
}

[data-theme="dark"] .sources-content {
  color: #aaa;
  background: rgba(255,255,255,0.03);
}

/* ════════════════════════════════════════════════════════════
   MENÚ COMPACTO - ESTILO TIPO "FUENTES"
   ════════════════════════════════════════════════════════════ */

.menu-wrapper {
  margin-top: 6px;
  border-top: 1px dashed var(--bot-border);
  padding-top: 6px;
  width: 100%;
}

.menu-title {
  font-weight: bold;
  font-size: 11px;
  color: #666;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Botón de departamento - igual que Fuentes */
.menu-dept {
  background: none;
  border: none;
  color: #555;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 0;
  font-family: sans-serif;
  margin: 2px 0;
  width: 100%;
  text-align: left;
}

.menu-dept:hover { opacity: 0.8; }

/* Flecha del departamento */
.menu-dept::after {
  content: '▶';
  font-size: 8px;
  display: inline-block;
  transition: transform 0.2s ease;
  color: #555;
}

.menu-dept.active::after {
  transform: rotate(90deg);
  color: #FF5900; /* Naranja cuando está expandido */
}

/* Contenedor de sub-opciones */
.menu-suboptions {
  display: none;
  font-size: 11px;
  color: #555;
  line-height: 1.5;
  margin: 2px 0 6px 0;
  padding-left: 4px;
}

.menu-suboptions.show {
  display: block;
}

/* Sub-opción clickeable */
.menu-subitem {
  cursor: pointer;
  padding: 2px 0 2px 8px;
  position: relative;
  color: #333;
  display: block;
  margin: 1px 0;
}

.menu-subitem::before {
  content: "└─";
  position: absolute;
  left: -8px;
  color: #555;
  font-weight: bold;
}

.menu-subitem:hover {
  color: #555;
  text-decoration: underline;
}

/* └─ naranja cuando el menú está expandido */
.menu-dept.active + .menu-suboptions .menu-subitem::before,
.menu-dept.active + .menu-suboptions .menu-input-label::before {
  color: #FF5900;
}

/* Campo de texto para análisis */
.menu-input-wrapper {
  margin: 2px 0 2px 8px;
  position: relative;
}

.menu-input-label {
  display: block;
  font-size: 10px;
  color: #666;
  margin-bottom: 3px;
  padding-left: 8px;
  position: relative;
}

.menu-input-label::before {
  content: "└─";
  position: absolute;
  left: -8px;
  color: #555;
  font-weight: bold;
}

.menu-text-input {
  width: 100%;
  padding: 5px 8px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 11px;
  font-family: sans-serif;
}

.menu-text-input:focus {
  outline: none;
  border-color: #555;
}

.menu-text-input::placeholder {
  color: #999;
  font-style: italic;
  font-size: 10px;
}

[data-theme="dark"] .menu-dept { color: #888; }
[data-theme="dark"] .menu-subitem { color: #f1f1f1; }
[data-theme="dark"] .menu-subitem:hover { color: #888; }
[data-theme="dark"] .menu-subitem::before,
[data-theme="dark"] .menu-input-label::before { color: #888; }
