/* ═══════════════════════════════════════════════════════════════════════════
   TOKENS — MODO OSCURO (por defecto)
   ═══════════════════════════════════════════════════════════════════════════ */
:root {
  --bg-main:    #44687E;
  --bg-alt:     #496D83;
  --bg-dark:    #2E4A5D;
  --white:      #FDFEFE;
  --text:       rgba(253,254,254,.92);
  --muted:      rgba(253,254,254,.58);
  --border:     rgba(253,254,254,.13);
  --card:       rgba(253,254,254,.08);
  --accent:     #6EC6FF;
  --err:        #FF7676;
  --send-bg:    rgba(110,198,255,.18);
  --send-hover: rgba(110,198,255,.30);
  --stop-bg:    rgba(255,118,118,.14);
  --stop-hover: rgba(255,118,118,.26);
}

/* ═══════════════════════════════════════════════════════════════════════════
   TOKENS — MODO CLARO
   Colores derivados de la paleta de marca (#44687E, #2E4A5D)
   ═══════════════════════════════════════════════════════════════════════════ */
:root[data-theme="light"] {
  --bg-main:    #E8F0F5;
  --bg-alt:     #DCE8F0;
  --bg-dark:    #C6DAE5;
  --white:      #1B3346;
  --text:       rgba(27,51,70,.92);
  --muted:      rgba(27,51,70,.55);
  --border:     rgba(27,51,70,.13);
  --card:       rgba(27,51,70,.07);
  --accent:     #1F6E9C;
  --err:        #C0392B;
  --send-bg:    rgba(31,110,156,.16);
  --send-hover: rgba(31,110,156,.28);
  --stop-bg:    rgba(192,57,43,.12);
  --stop-hover: rgba(192,57,43,.22);
}

/* ═══════════════════════════════════════════════════════════════════════════
   BASE
   ═══════════════════════════════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }

body {
  font-family: Inter, system-ui, sans-serif;
  background: linear-gradient(180deg, var(--bg-alt), var(--bg-main));
  color: var(--text);
  font-size: 14px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   LAYOUT
   ═══════════════════════════════════════════════════════════════════════════ */
.app { display: flex; height: 100%; }

/* ═══════════════════════════════════════════════════════════════════════════
   SIDEBAR
   ═══════════════════════════════════════════════════════════════════════════ */
.sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--bg-dark);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  transition: width .25s ease, min-width .25s ease, opacity .2s ease, border-color .25s ease;
}

.sidebar.collapsed {
  width: 52px;
  min-width: 52px;
  opacity: 1;
}

/* ── Mini sidebar (modo colapsado) ── */
.sidebar-mini {
  display: none;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  width: 52px;
  height: 100%;
  padding: 10px 0;
}
.sidebar.collapsed .sidebar-mini { display: flex; }
.sidebar.collapsed .sidebar-top,
.sidebar.collapsed .sidebar-bottom { display: none; }

.sidebar-mini-top {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 100%;
  padding: 0 6px;
}

.sidebar-mini-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, color .15s;
  flex-shrink: 0;
  position: relative;
}
.sidebar-mini-btn:hover {
  background: var(--card);
  color: var(--text);
}
.sidebar-mini-btn:first-child {
  margin-bottom: 6px;
  color: var(--text);
}

/* Tooltip al hover */
.sidebar-mini-btn::after {
  content: attr(title);
  position: absolute;
  left: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--bg-dark);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s, transform .15s;
  transform: translateY(-50%) translateX(-4px);
  z-index: 999;
  box-shadow: 0 4px 12px rgba(0,0,0,.3);
}
.sidebar-mini-btn:hover::after {
  opacity: 1;
  transform: translateY(-50%) translateX(0);
}

.sidebar-mini-bottom {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 0 6px 4px;
}

.sidebar-mini-status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
}

.sidebar-mini-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: opacity .15s;
  position: relative;
}
.sidebar-mini-avatar:hover { opacity: .8; }
.sidebar-mini-avatar::after {
  content: "Chutrau";
  position: absolute;
  left: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%) translateX(-4px);
  background: var(--bg-dark);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s, transform .15s;
  z-index: 999;
  box-shadow: 0 4px 12px rgba(0,0,0,.3);
}
.sidebar-mini-avatar:hover::after {
  opacity: 1;
  transform: translateY(-50%) translateX(0);
}

/* ── Botón toggle de barra lateral ── */
.chat-header {
  display: flex;
  align-items: center;
  padding: 8px 10px;
  flex-shrink: 0;
}

/* Ocultar botón en header cuando sidebar visible — ahora siempre oculto en desktop */
.chat-header > .sidebar-toggle {
  display: none;
}
.sidebar.collapsed + .chat .chat-header > .sidebar-toggle {
  display: none;
}

.sidebar-toggle {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, color .15s;
  flex-shrink: 0;
}
.sidebar-toggle:hover {
  background: var(--send-hover);
  color: var(--accent);
}

.sidebar-top {
  padding: 14px 10px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow-y: auto;
  flex: 1;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* ── Acciones principales ── */
.sidebar-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}

/* ── Botones de accion ── */
.new-chat,
.new-folder-btn {
  width: 100%;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--white);
  font-family: inherit;
  font-weight: 500;
  font-size: 13px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 14px;
}
.new-chat:hover,
.new-folder-btn:hover {
  background: rgba(255,255,255,.11);
  border-color: rgba(255,255,255,.18);
}
:root[data-theme="light"] .new-chat,
:root[data-theme="light"] .new-folder-btn {
  color: var(--text);
}

/* ── Etiquetas de sección ── */
.sidebar-section-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  font-weight: 600;
  margin: 14px 0 5px 3px;
  opacity: .7;
}

/* ── Input nueva carpeta ── */
.folder-input-row {
  display: none;
  flex-direction: column;
  gap: 6px;
  margin: 6px 0 4px;
  padding: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 9px;
}
.folder-input-row.open { display: flex; }

.folder-input {
  width: 100%;
  padding: 7px 10px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: rgba(0,0,0,.15);
  color: var(--white);
  font-family: inherit;
  font-size: 13px;
  outline: none;
}
.folder-input:focus { border-color: rgba(110,198,255,.4); }
:root[data-theme="light"] .folder-input { background: rgba(255,255,255,.5); }

.folder-input-actions {
  display: flex;
  gap: 6px;
}

.folder-btn-ok,
.folder-btn-cancel {
  flex: 1;
  height: 30px;
  border-radius: 7px;
  border: 1px solid var(--border);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background .12s;
  color: var(--white);
}
.folder-btn-ok     { background: rgba(110,198,255,.2); }
.folder-btn-ok:hover { background: rgba(110,198,255,.35); }
.folder-btn-cancel { background: var(--card); }
.folder-btn-cancel:hover { background: rgba(255,255,255,.12); }

/* ── Brand ── */
.brand {
  margin: 0 0 16px 2px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand-info { display: flex; flex-direction: column; align-items: center; flex: 1; }
.brand-mark {
  font-weight: 800;
  font-size: 20px;
  letter-spacing: -1px;
  color: var(--white);
}
.brand-mark span:last-child { opacity: .72; }
.brand-logo { height: 72px; width: auto; object-fit: contain; display: block; }
.login-brand-logo { height: 96px; width: auto; object-fit: contain; display: block; margin: 0 auto 4px; }
.brand-name { font-size: 11px; color: var(--muted); margin-top: 2px; padding-left: 0; text-align: center; }

/* ── Titulo de secciones (legacy, mantenido por compatibilidad) ── */
.history-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin: 12px 0 5px 2px;
  font-weight: 600;
}

/* ── Icono de chat en historial ── */
.hi-icon {
  color: var(--muted);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  opacity: .6;
}
.history-item:hover .hi-icon,
.history-item.active .hi-icon { opacity: 1; }

/* ── Icono de carpeta ── */
.folder-icon {
  color: var(--muted);
  display: flex;
  align-items: center;
  flex-shrink: 0;
  opacity: .7;
}
.folder-header:hover .folder-icon { opacity: 1; }

/* ═══════════════════════════════════════════════════════════════════════════
   CARPETAS (punto 2)
   ═══════════════════════════════════════════════════════════════════════════ */
.folders-section { margin-bottom: 4px; }

.folder-item { margin-bottom: 2px; }

.folder-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border-radius: 9px;
  cursor: pointer;
  transition: background .12s;
  user-select: none;
}
.folder-header:hover { background: var(--card); }

.folder-arrow {
  color: var(--muted);
  display: flex;
  align-items: center;
  transition: transform .18s;
  flex-shrink: 0;
  opacity: .6;
}
.folder-arrow.open { transform: rotate(90deg); }

.folder-name {
  flex: 1;
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}

.folder-count {
  font-size: 10px;
  color: var(--muted);
  background: rgba(255,255,255,.08);
  padding: 1px 6px;
  border-radius: 10px;
  flex-shrink: 0;
}
:root[data-theme="light"] .folder-count { background: rgba(0,0,0,.07); }

.folder-delete {
  width: 20px;
  height: 20px;
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 15px;
  border-radius: 4px;
  display: none;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all .12s;
  padding: 0;
  line-height: 1;
}
.folder-header:hover .folder-delete { display: flex; }
.folder-delete:hover { background: rgba(255,118,118,.2); color: var(--err); }

.folder-chats { padding-left: 14px; }

.folder-empty {
  padding: 5px 10px;
  font-size: 11px;
  color: var(--muted);
  font-style: italic;
}

.show-more-folders {
  width: 100%;
  padding: 5px 8px;
  background: none;
  border: none;
  border-radius: 7px;
  color: var(--accent);
  font-size: 11.5px;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background .12s;
  margin-top: 2px;
}
.show-more-folders:hover { background: var(--card); }

/* ═══════════════════════════════════════════════════════════════════════════
   HISTORIAL DE CHATS (punto 1)
   ═══════════════════════════════════════════════════════════════════════════ */
.history-list { display: flex; flex-direction: column; gap: 2px; }

.history-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 9px;
  cursor: pointer;
  transition: background .12s;
  border-left: 2px solid transparent;
}
.history-item:hover  { background: var(--card); }
.history-item.active {
  background: rgba(110,198,255,.10);
  border-left-color: var(--accent);
}
:root[data-theme="light"] .history-item.active {
  background: rgba(31,110,156,.10);
}

.hi-body {
  flex: 1;
  min-width: 0;
}

.hi-title {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}

.hi-meta {
  font-size: 10px;
  color: var(--muted);
}

.hi-actions {
  display: none;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
}
.history-item:hover .hi-actions { display: flex; }

.hi-action {
  width: 22px;
  height: 22px;
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  transition: all .12s;
  padding: 0;
  position: relative;
}
.hi-action:hover { background: var(--card); color: var(--text); }

.history-empty {
  padding: 8px 4px;
  font-size: 11.5px;
  color: var(--muted);
  font-style: italic;
}

/* ── Menu mover a carpeta ── */
.move-menu {
  position: absolute;
  right: 0;
  top: 100%;
  z-index: 100;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  min-width: 140px;
  box-shadow: 0 6px 24px rgba(0,0,0,.35);
}
.move-option {
  display: block;
  width: 100%;
  padding: 6px 10px;
  background: none;
  border: none;
  border-radius: 6px;
  color: var(--text);
  font-size: 12.5px;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: background .1s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.move-option:hover { background: var(--card); }

/* ═══════════════════════════════════════════════════════════════════════════
   SIDEBAR BOTTOM
   ═══════════════════════════════════════════════════════════════════════════ */
.sidebar-bottom {
  padding: 10px 12px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ── Selector de tema (punto 5) ── */
.theme-toggle {
  display: flex;
  gap: 4px;
}

.theme-btn {
  flex: 1;
  height: 27px;
  border: 1px solid var(--border);
  background: none;
  color: var(--muted);
  font-family: inherit;
  font-size: 11px;
  font-weight: 500;
  border-radius: 7px;
  cursor: pointer;
  transition: all .15s;
}
.theme-btn:hover { background: var(--card); color: var(--text); }
.theme-btn.active {
  background: var(--card);
  color: var(--text);
  border-color: rgba(110,198,255,.38);
}
:root[data-theme="light"] .theme-btn.active {
  border-color: rgba(31,110,156,.38);
}

/* ── Fila usuario ── */
.bottom-user-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
  cursor: help;
  transition: background .3s;
}
.status-dot.online  { background: #4ade80; }
.status-dot.offline { background: var(--err); }

.user { display: flex; align-items: center; gap: 8px; flex: 1; }

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--card);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 12px;
  flex-shrink: 0;
  border: 1px solid var(--border);
}

.user-name { font-size: 13px; font-weight: 500; }
.user-plan { font-size: 10px; color: var(--muted); }

/* ═══════════════════════════════════════════════════════════════════════════
   CHAT AREA
   ═══════════════════════════════════════════════════════════════════════════ */
.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ═══════════════════════════════════════════════════════════════════════════
   MENSAJES (punto 8)
   ═══════════════════════════════════════════════════════════════════════════ */
.messages {
  flex: 1;
  padding: 24px 28px;
  overflow-y: auto;
  scroll-behavior: smooth;
  display: flex;
  flex-direction: column;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.message {
  margin-bottom: 20px;
}

/* Agente: izquierda */
.message.assistant {
  align-self: flex-start;
  max-width: 70%;
}

/* Usuario: derecha */
.message.user {
  align-self: flex-end;
  max-width: 65%;
}

.bubble {
  padding: 12px 16px;
  border-radius: 14px;
  line-height: 1.65;
  word-break: break-word;
}

/* Agente: superficie con contraste legible */
.message.assistant .bubble {
  background: rgba(0,0,0,.32);
  border: 1px solid rgba(255,255,255,.18);
}
:root[data-theme="light"] .message.assistant .bubble {
  background: rgba(27,51,70,.11);
  border: 1px solid rgba(27,51,70,.22);
}

/* Usuario: tono distintivo */
.message.user .bubble {
  background: rgba(110,198,255,.18);
  border: 1px solid rgba(110,198,255,.32);
  color: var(--white);
  border-radius: 14px;
}

:root[data-theme="light"] .message.user .bubble {
  background: rgba(31,110,156,.14);
  border-color: rgba(31,110,156,.28);
}

/* ── Bubble header: hora + botón colapsar ──────────────────────────────── */
.bubble-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  min-height: 16px;
}

.msg-time {
  font-size: 10px;
  font-weight: 400;
  color: var(--muted);
  opacity: 0.7;
  letter-spacing: 0.01em;
  user-select: none;
}

.collapse-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  background: none;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  color: var(--muted);
  opacity: 0;
  transition: opacity .15s, background .15s, color .15s;
  padding: 0;
  flex-shrink: 0;
}
.bubble:hover .collapse-btn,
.bubble.collapsed .collapse-btn { opacity: 1; }
.collapse-btn:hover { background: rgba(255,255,255,.12); color: var(--text); }
:root[data-theme="light"] .collapse-btn:hover { background: rgba(27,51,70,.12); }
.collapse-btn svg { transition: transform .22s ease; display: block; }
.bubble.collapsed .collapse-btn svg { transform: rotate(180deg); }

/* ── Preview (visible solo en modo colapsado) ───────────────────────────── */
.bubble-preview {
  display: none;
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-style: italic;
  opacity: .8;
}
.bubble.collapsed .bubble-preview { display: block; }
.bubble.collapsed .msg-content,
.bubble.collapsed .msg-actions,
.bubble.collapsed .tool-indicator { display: none !important; }

/* Contenedor del contenido (texto, markdown, tablas) */
.msg-content { }

/* Cursor de streaming — va al final del contenido, no del bubble */
.bubble.streaming .msg-content::after {
  content: '\25AE';
  animation: blink .9s step-end infinite;
  color: var(--accent);
  margin-left: 2px;
}
@keyframes blink {
  0%,100% { opacity: 1; }
  50%      { opacity: 0; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   INDICADOR DE HERRAMIENTA
   ═══════════════════════════════════════════════════════════════════════════ */
.tool-indicator {
  display: none;
  align-items: center;
  gap: 7px;
  margin-top: 10px;
  padding: 6px 10px;
  background: rgba(110,198,255,.08);
  border: 1px solid rgba(110,198,255,.18);
  border-radius: 8px;
  font-size: 12px;
  color: var(--accent);
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
  0%,100% { opacity: .65; }
  50%      { opacity: 1;   }
}

/* ═══════════════════════════════════════════════════════════════════════════
   MARKDOWN — TABLAS Y CONTENIDO ESTRUCTURADO (punto 9)
   ═══════════════════════════════════════════════════════════════════════════ */
.bubble p                        { margin: 6px 0; }
.msg-content p:first-child       { margin-top: 0; }
.msg-content p:last-child        { margin-bottom: 0; }

/* ── Bloques Pensamiento / Conclusión / Desglose ────────────────────────── */
.resp-thinking {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.55;
  margin-bottom: 10px;
  font-style: italic;
}
.resp-thinking p { margin: 3px 0; }

hr.resp-divider {
  border: none;
  border-top: 1px solid rgba(255,255,255,.25);
  margin: 12px 0;
}
:root[data-theme="light"] hr.resp-divider { border-top-color: rgba(27,51,70,.25); }

/* ── Gráficos inline en respuestas del agente ─────────────────────────────── */
.inline-chart-wrap {
  margin: 16px 0;
  padding: 14px 16px 12px;
  background: rgba(0,0,0,.22);
  border: 1px solid rgba(110,198,255,.12);
  border-radius: 12px;
  position: relative;
}
.inline-chart-title {
  font-size: 12px;
  font-weight: 600;
  color: rgba(220,230,255,.85);
  margin-bottom: 10px;
  letter-spacing: .02em;
}
.inline-chart-canvas-wrap {
  position: relative;
}
.inline-chart-wrap canvas {
  display: block;
  max-height: 340px;
}

.resp-conclusion {
  margin-bottom: 14px;
}
.resp-conclusion-header {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 8px;
}
.resp-conclusion-body p { margin: 0; line-height: 1.7; }

.resp-desglose {
  border-top: 1px solid rgba(255,255,255,.18);
  margin-top: 8px;
  padding-top: 12px;
}
:root[data-theme="light"] .resp-desglose { border-top-color: rgba(27,51,70,.20); }
.resp-desglose-header {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 8px;
}
.resp-desglose-body p:first-child { margin-top: 0; }
.resp-desglose-body p:last-child  { margin-bottom: 0; }
/* ─────────────────────────────────────────────────────────────────────── */

.bubble h1, .bubble h2, .bubble h3 {
  font-weight: 700;
  margin: 16px 0 8px;
  line-height: 1.3;
  color: var(--text);
}
.bubble h1 { font-size: 1.2em; border-bottom: 1px solid rgba(255,255,255,.15); padding-bottom: 6px; }
.bubble h2 { font-size: 1.1em; }
.bubble h3 { font-size: 1em; color: var(--accent); }
:root[data-theme="light"] .bubble h1 { border-bottom-color: rgba(27,51,70,.18); }
:root[data-theme="light"] .bubble h3 { color: var(--accent); }

.bubble ul, .bubble ol { margin: 6px 0; padding-left: 22px; }
.bubble li             { margin: 3px 0; }
.bubble strong         { font-weight: 700; }
.bubble em             { font-style: italic; }
.bubble hr             { border: none; border-top: 1px solid var(--border); margin: 12px 0; }

.bubble code {
  font-family: 'Courier New', monospace;
  font-size: 12.5px;
  background: rgba(0,0,0,.22);
  padding: 2px 6px;
  border-radius: 4px;
}
:root[data-theme="light"] .bubble code { background: rgba(0,0,0,.08); }

.bubble pre {
  background: rgba(0,0,0,.24);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  overflow-x: auto;
  margin: 10px 0;
}
:root[data-theme="light"] .bubble pre { background: rgba(0,0,0,.06); }
.bubble pre code { background: none; padding: 0; }

/* Tablas: ancho completo, limpias y alineadas */
.bubble table {
  border-collapse: collapse;
  width: 100%;
  margin: 12px 0;
  font-size: 13px;
  display: block;
  overflow-x: auto;
}
.bubble th, .bubble td {
  border: 1px solid rgba(255,255,255,.22);
  padding: 8px 14px;
  text-align: left;
  white-space: nowrap;
  line-height: 1.5;
}
:root[data-theme="light"] .bubble th,
:root[data-theme="light"] .bubble td { border-color: rgba(27,51,70,.22); }
.bubble th {
  background: rgba(110,198,255,.2);
  font-weight: 700;
  color: var(--text);
  letter-spacing: .03em;
  font-size: 12px;
  text-transform: uppercase;
}
:root[data-theme="light"] .bubble th { background: rgba(31,110,156,.18); }
.bubble tr:nth-child(even) td { background: rgba(255,255,255,.06); }
.bubble tr:hover td { background: rgba(255,255,255,.09); }
:root[data-theme="light"] .bubble tr:nth-child(even) td { background: rgba(27,51,70,.06); }
:root[data-theme="light"] .bubble tr:hover td { background: rgba(27,51,70,.09); }

.bubble blockquote {
  border-left: 3px solid var(--accent);
  margin: 8px 0;
  padding: 4px 12px;
  color: var(--muted);
}

/* Error */
.err { color: var(--err); }
.err code {
  background: rgba(255,118,118,.15);
  color: var(--err);
  font-size: 12px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   COMPOSER
   ═══════════════════════════════════════════════════════════════════════════ */
.composer {
  display: flex;
  padding: 12px 16px 14px;
  border-top: 1px solid var(--border);
  background: linear-gradient(to top, rgba(46,74,93,.75), transparent);
}
:root[data-theme="light"] .composer {
  background: linear-gradient(to top, rgba(198,218,229,.75), transparent);
}

/* Wrapper unificado: borde + fondo aqui, textarea y boton adentro */
.input-wrapper {
  flex: 1;
  position: relative;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--card);
  transition: border-color .15s;
}
.input-wrapper:focus-within {
  border-color: rgba(110,198,255,.4);
}
:root[data-theme="light"] .input-wrapper:focus-within {
  border-color: rgba(31,110,156,.4);
}

.input-wrapper textarea {
  display: block;
  width: 100%;
  min-height: 50px;
  max-height: 160px;
  border: none;
  background: transparent;
  color: var(--white);
  padding: 13px 52px 13px 16px;   /* padding-right deja espacio al boton */
  outline: none;
  resize: none;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  overflow-y: auto;
  border-radius: 14px;
}
.input-wrapper textarea::placeholder { color: rgba(253,254,254,.42); }
:root[data-theme="light"] .input-wrapper textarea::placeholder { color: rgba(27,51,70,.38); }
:root[data-theme="light"] .input-wrapper textarea { color: var(--white); }

/* Contenedor de botones — dentro del wrapper, abajo a la derecha */
.input-actions {
  position: absolute;
  right: 8px;
  bottom: 8px;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Boton enviar */
.send {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  border: none;
  background: var(--send-bg);
  color: var(--white);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background .15s, transform .1s, opacity .2s;
}
.send:hover:not(:disabled)  { background: var(--send-hover); }
.send:active:not(:disabled) { transform: scale(.93); }
.send:disabled              { opacity: .4; cursor: default; }

/* Boton detener — mismo tamaño, con transicion suave */
.stop-btn {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  border: none;
  background: var(--stop-bg);
  color: var(--err);
  cursor: pointer;
  display: grid;
  place-items: center;
  opacity: 0;
  pointer-events: none;
  transform: scale(.82);
  transition: opacity .2s, transform .2s, background .15s;
}
.stop-btn:hover  { background: var(--stop-hover); }
.stop-btn:active { transform: scale(.9) !important; }

/* Durante streaming: mostrar stop, ocultar send */
.composer.streaming .stop-btn {
  opacity: 1;
  pointer-events: auto;
  transform: scale(1);
}
.composer.streaming .send {
  opacity: 0;
  pointer-events: none;
}

/* ═══════════════════════════════════════════════════════════════════════════
   SETTINGS BUTTON
   ═══════════════════════════════════════════════════════════════════════════ */
.settings-btn {
  width: 100%;
  height: 34px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: background .15s, color .15s;
}
.settings-btn:hover {
  background: rgba(255,255,255,.10);
  color: var(--text);
}

/* ═══════════════════════════════════════════════════════════════════════════
   SETTINGS MODAL
   ═══════════════════════════════════════════════════════════════════════════ */
.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
}
.settings-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.settings-panel {
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 420px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 64px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
  transform: translateY(10px);
  transition: transform .2s ease;
}
.settings-overlay.open .settings-panel {
  transform: translateY(0);
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.settings-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--white);
}
.settings-close {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, color .15s;
}
.settings-close:hover {
  background: var(--stop-hover);
  color: var(--text);
}

.settings-body {
  overflow-y: auto;
  flex: 1;
  padding: 6px 0 10px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.settings-section {
  padding: 14px 18px 6px;
}
.settings-section + .settings-section {
  border-top: 1px solid var(--border);
}
.settings-section-title {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin-bottom: 12px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 34px;
  padding: 2px 0;
}
.settings-label {
  font-size: 13px;
  color: var(--text);
  flex-shrink: 0;
}
.settings-value {
  font-size: 12.5px;
  color: var(--muted);
  text-align: right;
}
.settings-badge {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
}

/* Tema toggle dentro del modal */
.settings-row .theme-toggle {
  flex-shrink: 0;
}

/* ── Selector de idioma ── */
.lang-selector {
  display: flex;
  gap: 4px;
}

.lang-btn {
  height: 27px;
  padding: 0 10px;
  border: 1px solid var(--border);
  background: none;
  color: var(--muted);
  font-family: inherit;
  font-size: 11px;
  font-weight: 500;
  border-radius: 7px;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.lang-btn:hover { background: var(--card); color: var(--text); }
.lang-btn.active {
  background: var(--card);
  color: var(--text);
  border-color: rgba(110,198,255,.38);
}
:root[data-theme="light"] .lang-btn.active {
  border-color: rgba(31,110,156,.38);
}

/* ═══════════════════════════════════════════════════════════════════════════
   AGENT SETTINGS CONTROLS
   ═══════════════════════════════════════════════════════════════════════════ */
.settings-row-col {
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  padding: 6px 0;
}

.agent-opt-group {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.agent-opt {
  height: 26px;
  padding: 0 9px;
  border: 1px solid var(--border);
  background: none;
  color: var(--muted);
  font-family: inherit;
  font-size: 11px;
  font-weight: 500;
  border-radius: 7px;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.agent-opt:hover  { background: var(--card); color: var(--text); }
.agent-opt.active { background: var(--card); color: var(--text); border-color: rgba(110,198,255,.38); }
:root[data-theme="light"] .agent-opt.active { border-color: rgba(31,110,156,.38); }

/* ═══════════════════════════════════════════════════════════════════════════
   RENAME INPUT (inline en sidebar)
   ═══════════════════════════════════════════════════════════════════════════ */
.rename-input {
  background: var(--bg-main);
  border: 1px solid var(--accent);
  border-radius: 5px;
  color: var(--text);
  font-family: inherit;
  font-size: 12.5px;
  padding: 2px 6px;
  width: 100%;
  outline: none;
}

/* Botón rename en folder-header */
.folder-rename {
  display: none;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 2px 3px;
  border-radius: 4px;
  transition: color .15s, background .15s;
  flex-shrink: 0;
}
.folder-header:hover .folder-rename { display: flex; align-items: center; }
.folder-rename:hover { color: var(--accent); background: var(--card); }

/* ═══════════════════════════════════════════════════════════════════════════
   TOAST NOTIFICATIONS
   ═══════════════════════════════════════════════════════════════════════════ */
.toast-container {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--bg-dark);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 18px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 4px 24px rgba(0,0,0,.35);
  opacity: 0;
  transition: opacity .2s ease, transform .2s ease;
  pointer-events: none;
  z-index: 3000;
  white-space: nowrap;
}
.toast-container.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ═══════════════════════════════════════════════════════════════════════════
   SIDEBAR BACKDROP (mobile overlay)
   ═══════════════════════════════════════════════════════════════════════════ */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 199;
  opacity: 0;
  transition: opacity .25s ease;
}

/* ═══════════════════════════════════════════════════════════════════════════
   RESPONSIVE — TABLET (≤ 900px)
   ═══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
  .sidebar { width: 220px; min-width: 220px; }
  .message.user .bubble      { max-width: 80%; }
  .message.assistant .bubble { max-width: 88%; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   RESPONSIVE — MOBILE (≤ 768px)
   ═══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  /* Sidebar becomes a full-height overlay */
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100%;
    z-index: 200;
    width: 280px !important;
    min-width: 280px !important;
    transform: translateX(0);
    opacity: 1 !important;
    border-right: 1px solid var(--border) !important;
    transition: transform .25s ease, opacity .2s ease;
  }
  .sidebar.collapsed {
    transform: translateX(-100%);
    opacity: 0 !important;
    pointer-events: none;
    width: 0 !important;
    min-width: 0 !important;
  }
  .sidebar-mini { display: none !important; }

  /* Backdrop visible on mobile when sidebar is open */
  .sidebar-backdrop {
    display: block;
    pointer-events: none;
  }
  .sidebar-backdrop.visible {
    opacity: 1;
    pointer-events: all;
  }

  /* Chat always occupies full width */
  .chat { width: 100%; }

  /* Open button always visible */
  .chat-header { display: flex !important; }

  /* Messages */
  .messages { padding: 12px 8px; }
  .message.user .bubble      { max-width: 92%; }
  .message.assistant .bubble { max-width: 96%; }

  /* Composer */
  .composer { padding: 8px 8px 14px; }

  /* Settings modal */
  .settings-panel {
    width: calc(100vw - 16px);
    border-radius: 12px;
  }
  .settings-row-col { flex-direction: column; }
  .agent-opt-group  { flex-wrap: wrap; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   RESPONSIVE — SMALL MOBILE (≤ 480px)
   ═══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  .settings-overlay  { align-items: flex-end; padding: 0; }
  .settings-panel    { width: 100vw; max-width: 100vw; border-radius: 14px 14px 0 0; }
  .brand-name        { display: none; }
  .composer textarea { font-size: 16px; } /* prevent iOS zoom */
}

/* ═══════════════════════════════════════════════════════════════════════════
   COPY BUTTON (on assistant messages)
   ═══════════════════════════════════════════════════════════════════════════ */
.msg-actions {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  opacity: 0;
  transition: opacity .15s;
}
.message.assistant:hover .msg-actions { opacity: 1; }

.msg-action-btn {
  height: 24px;
  padding: 0 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  font-family: inherit;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: background .12s, color .12s;
}
.msg-action-btn:hover {
  background: var(--send-hover);
  color: var(--text);
}
.msg-action-btn.copied {
  color: #4ade80;
  border-color: rgba(74,222,128,.3);
}

/* ═══════════════════════════════════════════════════════════════════════════
   SEARCH INPUT (sidebar)
   ═══════════════════════════════════════════════════════════════════════════ */
.search-input {
  width: 100%;
  padding: 8px 10px 8px 34px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.05);
  color: var(--white);
  font-family: inherit;
  font-size: 13px;
  outline: none;
  margin-bottom: 0;
  transition: border-color .15s, background .15s;
}
.search-input:focus {
  border-color: rgba(110,198,255,.4);
  background: rgba(255,255,255,.08);
}
.search-input::placeholder { color: var(--muted); }
:root[data-theme="light"] .search-input {
  background: rgba(0,0,0,.05);
  color: var(--text);
}
:root[data-theme="light"] .search-input:focus { background: rgba(0,0,0,.08); }

.search-wrapper {
  position: relative;
  margin-bottom: 4px;
}
.search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
  line-height: 1;
}

/* ═══════════════════════════════════════════════════════════════════════════
   EXPORT BUTTON (chat header)
   ═══════════════════════════════════════════════════════════════════════════ */
.chat-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
  padding-right: 8px;
}

.chat-action-btn {
  width: 32px;
  height: 32px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .12s, color .12s;
}
.chat-action-btn:hover {
  background: var(--send-hover);
  color: var(--text);
}

.alert-btn-wrap {
  position: relative;
  display: flex;
}
.alert-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background: var(--err);
  color: #fff;
  border-radius: 50%;
  min-width: 16px;
  height: 16px;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
  pointer-events: none;
  line-height: 1;
}
.alert-badge.hidden { display: none; }

/* ═══════════════════════════════════════════════════════════════════════════
   SQL HISTORY PANEL
   ═══════════════════════════════════════════════════════════════════════════ */
.sql-history-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: stretch;
  justify-content: flex-end;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
}
.sql-history-overlay.open {
  opacity: 1;
  pointer-events: all;
}
.sql-history-panel {
  background: var(--bg-dark);
  border-left: 1px solid var(--border);
  width: 440px;
  max-width: 100vw;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: -12px 0 40px rgba(0,0,0,.4);
  transform: translateX(30px);
  transition: transform .2s ease;
}
.sql-history-overlay.open .sql-history-panel {
  transform: translateX(0);
}
.sql-history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sql-history-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--white);
}
.sql-history-count {
  font-size: 11px;
  color: var(--muted);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2px 8px;
}
.sql-history-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.sql-history-empty {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  padding: 40px 16px;
}
.sql-query-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.sql-query-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.sql-query-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px 6px;
  border-bottom: 1px solid var(--border);
}
.sql-query-time {
  font-size: 11px;
  color: var(--muted);
  flex: 1;
}
.sql-query-rows {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 8px;
  background: rgba(110,198,255,.12);
  color: var(--accent);
  border: 1px solid rgba(110,198,255,.2);
}
.sql-query-rows.error {
  background: rgba(255,118,118,.12);
  color: var(--err);
  border-color: rgba(255,118,118,.2);
}
.sql-query-code {
  margin: 0;
  padding: 10px 12px;
  font-size: 12px;
  font-family: 'Menlo', 'Monaco', 'Consolas', monospace;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.6;
  background: rgba(0,0,0,.15);
  border-bottom: 1px solid var(--border);
}
.sql-query-actions {
  display: flex;
  justify-content: flex-end;
  padding: 6px 10px;
}
.sql-query-copy {
  font-size: 11px;
  font-family: inherit;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
  transition: color .15s, background .15s;
}
.sql-query-copy:hover { color: var(--white); background: rgba(255,255,255,.1); }
.sql-query-copy.copied { color: #34d399; border-color: rgba(52,211,153,.3); }


/* ═══════════════════════════════════════════════════════════════════════════
   UPLOAD MODAL
   ═══════════════════════════════════════════════════════════════════════════ */
.upload-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1001;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
}
.upload-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.upload-panel {
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 440px;
  max-width: calc(100vw - 32px);
  padding: 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
  transform: translateY(10px);
  transition: transform .2s ease;
}
.upload-overlay.open .upload-panel {
  transform: translateY(0);
}

.upload-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--white);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.upload-dropzone {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 32px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  margin-bottom: 12px;
}
.upload-dropzone:hover,
.upload-dropzone.dragover {
  border-color: var(--accent);
  background: rgba(110,198,255,.06);
}

.upload-dropzone-label {
  font-weight: 500;
  color: var(--text);
  margin-bottom: 4px;
}

.upload-status {
  font-size: 12px;
  color: var(--muted);
  min-height: 20px;
}
.upload-status.success { color: #4ade80; }
.upload-status.error   { color: var(--err); }

/* ═══════════════════════════════════════════════════════════════════════════
   LOGIN OVERLAY
   ═══════════════════════════════════════════════════════════════════════════ */
/* ═══════════════════════════════════════════════════════════════════════════
   LOGIN — LAYOUT HORIZONTAL
   ═══════════════════════════════════════════════════════════════════════════ */
.login-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, var(--bg-dark) 0%, var(--bg-main) 60%, var(--bg-alt) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5000;
  transition: opacity .35s ease;
}
.login-overlay.hidden { opacity: 0; pointer-events: none; }
#adminOverlay { align-items: center; justify-content: center; padding: 4vh 0; }

/* Contenedor dividido horizontalmente */
.login-split {
  display: flex;
  width: min(860px, 94vw);
  height: min(380px, 80vh);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 32px 90px rgba(0,0,0,.55);
  animation: loginEnter .45s cubic-bezier(.22,1,.36,1) both;
}
@keyframes loginEnter {
  from { opacity: 0; transform: translateY(18px) scale(.97); }
  to   { opacity: 1; transform: translateY(0)    scale(1);   }
}

/* ── Panel izquierdo: branding ─────────────────────────────────────────── */
.login-panel-left {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: linear-gradient(145deg, #dce8f0 0%, #c6dae5 55%, #b8d0de 100%);
  overflow: hidden;
}

/* Canvas de partículas */
.login-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* Brillo deslizante sobre el panel */
.login-panel-shine {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    115deg,
    transparent 0%,
    rgba(255,255,255,0) 38%,
    rgba(255,255,255,.28) 50%,
    rgba(255,255,255,0) 62%,
    transparent 100%
  );
  background-size: 200% 100%;
  animation: loginShine 5s ease-in-out infinite;
  pointer-events: none;
}
@keyframes loginShine {
  0%   { background-position: 200% 0; }
  50%  { background-position: -20% 0; }
  100% { background-position: 200% 0; }
}

/* Logo */
.login-brand-logo {
  position: relative;
  z-index: 1;
  width: 92%;
  max-width: 420px;
  height: auto;
  display: block;
  animation: loginFloat 7s ease-in-out infinite;
}
@keyframes loginFloat {
  0%,100% { transform: translateY(0px);  }
  50%      { transform: translateY(-5px); }
}

/* Subtítulo */
.login-panel-sub {
  position: absolute;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .24em;
  text-transform: uppercase;
  color: rgba(27,51,70,.72);
  white-space: nowrap;
}

/* ── Panel derecho: formulario ─────────────────────────────────────────── */
.login-panel-right {
  width: 300px;
  flex-shrink: 0;
  background: var(--bg-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 32px;
  border-left: 1px solid rgba(255,255,255,.07);
  animation: loginFormSlide .5s cubic-bezier(.22,1,.36,1) .1s both;
}
@keyframes loginFormSlide {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0);    }
}

.login-form-wrap {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.login-form-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 24px;
  letter-spacing: -.01em;
}

.login-field {
  width: 100%;
  padding: 10px 14px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: rgba(0,0,0,.18);
  color: var(--white);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  margin-bottom: 10px;
  transition: border-color .2s, background .2s;
  box-sizing: border-box;
}
.login-field:focus {
  border-color: rgba(110,198,255,.5);
  background: rgba(0,0,0,.25);
}
.login-field::placeholder { color: var(--muted); }
.login-pass-wrap { position: relative; margin-bottom: 10px; }
.login-pass-toggle {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; color: var(--muted);
  display: flex; align-items: center; padding: 2px; transition: color .2s;
}
.login-pass-toggle:hover { color: var(--text); }

.login-btn {
  width: 100%;
  height: 42px;
  border-radius: 9px;
  border: none;
  background: var(--send-bg);
  color: var(--white);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .18s, transform .1s;
  margin-top: 4px;
  letter-spacing: .02em;
}
.login-btn:hover   { background: var(--send-hover); transform: translateY(-1px); }
.login-btn:active  { transform: translateY(0); }
.login-btn:disabled { opacity: .5; cursor: default; transform: none; }

/* Responsive: pantallas chicas → vertical */
@media (max-width: 600px) {
  .login-split { flex-direction: column; height: auto; width: min(360px, 94vw); }
  .login-panel-left { padding: 36px 24px; min-height: 180px; }
  .login-panel-right { width: 100%; border-left: none; border-top: 1px solid rgba(255,255,255,.07); }
  .login-brand-logo { width: 55%; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   ADMIN PANEL
   ═══════════════════════════════════════════════════════════════════════════ */
.admin-tab {
  padding: 6px 14px;
  font-size: 13px;
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-muted);
  transition: all .15s;
}
.admin-tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.admin-tab:not(.active):hover { background: var(--hover); color: var(--text); }

/* ── Admin panel card (full-screen) ───────────────────────────────────────── */
.admin-panel-card {
  width: 96vw;
  max-width: 1440px;
  height: 92vh;
  background: var(--bg-main);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 24px 80px rgba(0,0,0,.55);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: loginEnter .3s cubic-bezier(.22,1,.36,1) both;
}

.admin-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.admin-panel-tabs {
  display: flex;
  gap: 8px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-secondary);
}

/* Each tab body fills remaining height and scrolls independently */
.admin-tab-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px 24px;
  min-height: 0;
}

/* ── Forecast tab layout ──────────────────────────────────────────────────── */
.admin-forecast-kpis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.admin-forecast-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}

.admin-forecast-col {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
  min-width: 0;
  overflow: hidden;
}

.admin-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  gap: 8px;
  flex-wrap: wrap;
}

.admin-section-title {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .5px;
}

.admin-btn-accent {
  font-size: 12px;
  padding: 4px 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity .15s;
}
.admin-btn-accent:hover { opacity: .85; }

/* Make admin panel single-column on narrow screens */
@media (max-width: 900px) {
  .admin-forecast-grid { grid-template-columns: 1fr; }
  .admin-forecast-kpis { grid-template-columns: repeat(2, 1fr); }
  .admin-panel-card { width: 100vw; height: 100vh; border-radius: 0; }
}

.admin-action-btn {
  padding: 3px 9px;
  font-size: 11px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: none;
  cursor: pointer;
  color: var(--text-muted);
  transition: all .15s;
  vertical-align: middle;
  line-height: 1.4;
}
.admin-action-btn:hover { background: var(--hover); color: var(--text); }
.admin-action-btn.danger:hover { background: #ef4444; color: #fff; border-color: #ef4444; }
.admin-action-btn.success { color: #22c55e; border-color: #22c55e; }

.admin-tag {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  background: var(--accent);
  color: #fff;
}
.admin-tag.inactive { background: var(--text-muted); }

/* ═══════════════════════════════════════════════════════════════════════════
   STOCK ALERTS PANEL
   ═══════════════════════════════════════════════════════════════════════════ */
.alerts-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  z-index: 1001;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
}
.alerts-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.alerts-panel {
  background: var(--bg-dark);
  border-left: 1px solid var(--border);
  width: min(920px, 100vw);
  max-width: 100vw;
  height: 100%;
  display: flex;
  flex-direction: column;
  box-shadow: -20px 0 60px rgba(0,0,0,.4);
  transform: translateX(40px);
  transition: transform .2s ease;
  overflow: hidden;
}
.alerts-overlay.open .alerts-panel {
  transform: translateX(0);
}

.alerts-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.alerts-title {
  font-weight: 600;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}
.alerts-legend {
  display: flex;
  align-items: center;
  padding: 10px 20px;
  font-size: 11px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 4px;
}
.alerts-legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.alerts-legend-dot.critico     { background: #ef4444; }
.alerts-legend-dot.advertencia { background: #f59e0b; }

.alerts-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.alerts-loading {
  color: var(--muted);
  font-size: 13px;
  padding: 20px 0;
  text-align: center;
}
.alerts-empty {
  color: var(--muted);
  font-size: 13px;
  padding: 32px 0;
  text-align: center;
}
.alerts-empty svg { opacity: .4; display: block; margin: 0 auto 10px; }

/* ── Feedback inline ────────────────────────────────────────────────────── */
.alert-fb-btn {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 5px;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.06);
  color: rgba(255,255,255,0.75);
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s;
}
.alert-fb-btn:hover { background: rgba(255,255,255,0.14); }

.alert-fb-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  border-radius: 4px;
  padding: 2px 6px;
  margin-right: 5px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.alert-fb-badge.reconocido  { background: rgba(34,197,94,.2);   color: #4ade80; }
.alert-fb-badge.desestimado { background: rgba(148,163,184,.15); color: #94a3b8; }
.alert-fb-badge.pospuesto   { background: rgba(251,146,60,.2);   color: #fb923c; }

.alert-fb-comment {
  font-size: 10px;
  color: rgba(255,255,255,0.4);
  margin-top: 3px;
  font-style: italic;
}
.alert-row-critico.has-feedback     { opacity: .6; }
.alert-row-advertencia.has-feedback { opacity: .6; }

/* ── Feedback Modal ──────────────────────────────────────────────────────── */
.fb-modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 1100;
}
.fb-modal-overlay.open { display: block; }

.fb-modal {
  display: none;
  flex-direction: column;
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: min(420px, 92vw);
  background: #1e2535;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  z-index: 1101;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.fb-modal.open { display: flex; }

.fb-modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  font-size: 13px; font-weight: 600;
}
.fb-modal-close {
  background: none; border: none;
  color: rgba(255,255,255,0.5); cursor: pointer; font-size: 14px;
  padding: 2px 4px; border-radius: 4px;
}
.fb-modal-close:hover { color: #fff; }

.fb-modal-product {
  font-size: 11px;
  color: rgba(255,255,255,0.4);
  padding: 8px 18px 0;
  word-break: break-word;
}

.fb-modal-body { padding: 14px 18px; display: flex; flex-direction: column; gap: 10px; }

.fb-label { font-size: 11px; font-weight: 600; color: rgba(255,255,255,0.5); text-transform: uppercase; letter-spacing: .05em; }

.fb-select, .fb-input, .fb-textarea {
  width: 100%; background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 7px; color: #fff;
  padding: 8px 10px; font-size: 13px;
  font-family: inherit; box-sizing: border-box;
}
.fb-select:focus, .fb-input:focus, .fb-textarea:focus {
  outline: none; border-color: rgba(99,102,241,0.6);
}
.fb-textarea { resize: vertical; min-height: 64px; }

.fb-dias-wrap { display: flex; flex-direction: column; gap: 6px; }
.fb-dias-row { display: flex; align-items: center; gap: 8px; }
.fb-input { width: 80px; }
.fb-dias-unit { font-size: 12px; color: rgba(255,255,255,0.5); }

.fb-modal-footer {
  padding: 12px 18px 16px;
  border-top: 1px solid rgba(255,255,255,0.08);
  display: flex; justify-content: flex-end;
}
.fb-submit-btn {
  background: #6366f1; color: #fff; border: none;
  border-radius: 8px; padding: 8px 20px;
  font-size: 13px; font-weight: 600; cursor: pointer;
  transition: background .15s;
}
.fb-submit-btn:hover:not(:disabled) { background: #4f46e5; }
.fb-submit-btn:disabled { opacity: .5; cursor: default; }

/* ── Historial de gestiones en el modal ─────────────────────────────────── */
.fb-historial {
  border-top: 1px solid rgba(255,255,255,0.08);
  padding: 12px 18px 4px;
}
.fb-historial-title {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.35);
  margin-bottom: 8px;
}
.fb-historial-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 180px;
  overflow-y: auto;
  padding-right: 4px;
}
.fb-hist-item {
  border-radius: 7px;
  padding: 8px 10px;
  font-size: 12px;
  border-left: 3px solid transparent;
}
.fb-hist-reconocido  { background: rgba(34,197,94,.1);   border-color: #4ade80; }
.fb-hist-desestimado { background: rgba(148,163,184,.1); border-color: #94a3b8; }
.fb-hist-pospuesto   { background: rgba(251,146,60,.1);  border-color: #fb923c; }
.fb-hist-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.fb-hist-badge { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.fb-hist-reconocido  .fb-hist-badge { color: #4ade80; }
.fb-hist-desestimado .fb-hist-badge { color: #94a3b8; }
.fb-hist-pospuesto   .fb-hist-badge { color: #fb923c; }
.fb-hist-pos {
  font-size: 10px; color: rgba(251,146,60,.8);
  background: rgba(251,146,60,.12); border-radius: 4px; padding: 1px 6px;
}
.fb-hist-meta { font-size: 10px; color: rgba(255,255,255,0.3); margin-left: auto; }
.fb-hist-comment {
  margin-top: 5px; font-size: 11px;
  color: rgba(255,255,255,0.6); font-style: italic; line-height: 1.4;
}
.fb-hist-delete {
  margin-left: auto;
  background: none;
  border: none;
  color: rgba(255,255,255,0.25);
  cursor: pointer;
  font-size: 11px;
  padding: 1px 4px;
  border-radius: 4px;
  line-height: 1;
  transition: color .15s, background .15s;
}
.fb-hist-delete:hover { color: #ef4444; background: rgba(239,68,68,.12); }
.fb-hist-delete:disabled { opacity: .4; cursor: default; }

.alerts-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  table-layout: fixed;
}
/* Anchos fijos por columna */
.alerts-table colgroup col:nth-child(1) { width: 22%; }  /* Producto */
.alerts-table colgroup col:nth-child(2) { width: 13%; }  /* Stock actual */
.alerts-table colgroup col:nth-child(3) { width: 12%; }  /* Buffer seg. */
.alerts-table colgroup col:nth-child(4) { width: 13%; }  /* Consumo/sem */
.alerts-table colgroup col:nth-child(5) { width: 18%; }  /* Días/Agotamiento */
.alerts-table colgroup col:nth-child(6) { width: 11%; }  /* Estado */
.alerts-table colgroup col:nth-child(7) { width: 11%; }  /* Gestión */

.alerts-table th {
  text-align: left;
  color: var(--muted);
  font-weight: 500;
  padding: 5px 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  font-size: 11px;
}
.alerts-table td {
  padding: 7px 8px;
  border-bottom: 1px solid rgba(255,255,255,.05);
  vertical-align: middle;
  overflow: hidden;
}

/* Producto: una línea con ellipsis */
.alerts-table td.td-producto {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 0; /* necesario para text-overflow con table-layout:fixed */
}
:root[data-theme="light"] .alerts-table td {
  border-bottom-color: rgba(0,0,0,.05);
}
.alerts-table tr:last-child td { border-bottom: none; }

.alert-row-critico td:first-child {
  border-left: 3px solid #ef4444;
}
.alert-row-advertencia td:first-child {
  border-left: 3px solid #f59e0b;
}

.alert-nivel-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 10.5px;
  font-weight: 600;
  white-space: nowrap;
}
.alert-nivel-badge.critico {
  background: rgba(239,68,68,.18);
  color: #f87171;
}
.alert-nivel-badge.advertencia {
  background: rgba(245,158,11,.18);
  color: #fbbf24;
}

.alerts-footer {
  padding: 10px 20px;
  font-size: 11px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  text-align: right;
}

/* ── Projection panel ── */
.proj-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  z-index: 1001;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
}
.proj-overlay.hidden { display: none; }
.proj-overlay.open {
  opacity: 1;
  pointer-events: all;
}
.proj-panel {
  background: var(--bg-dark);
  border-left: 1px solid var(--border);
  width: min(1060px, 100vw);
  max-width: 100vw;
  height: 100%;
  display: flex;
  flex-direction: column;
  box-shadow: -20px 0 60px rgba(0,0,0,.4);
  transform: translateX(40px);
  transition: transform .2s ease;
  overflow-y: auto;
}
.proj-overlay.open .proj-panel { transform: translateX(0); }
.proj-info {
  padding: 8px 20px 6px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.proj-body {
  padding: 16px 20px;
  flex: 1;
  overflow-x: auto;
}
.proj-detail-btn {
  background: rgba(96,165,250,.15);
  color: #60a5fa;
  border: 1px solid rgba(96,165,250,.3);
  border-radius: 4px;
  padding: 3px 10px;
  font-size: 11px;
  cursor: pointer;
  transition: background .15s;
}
.proj-detail-btn:hover { background: rgba(96,165,250,.28); }
.proj-chart-section {
  padding: 16px 20px 24px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.proj-chart-section.hidden { display: none; }
.proj-chart-title {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 12px;
  font-weight: 600;
}
.proj-chart-wrap { height: 240px; position: relative; }

.login-error {
  color: var(--err);
  font-size: 12px;
  text-align: center;
  margin-top: 8px;
  min-height: 18px;
}

.login-divider {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  margin: 10px 0;
}

/* Logout button inside settings */
.settings-logout-inline {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 14px;
  border-radius: 6px;
  background: rgba(239,68,68,.12);
  color: #ef4444;
  border: 1px solid rgba(239,68,68,.25);
  font-size: 13px;
  cursor: pointer;
  transition: background .15s;
}
.settings-logout-inline:hover { background: rgba(239,68,68,.22); }

/* ── Dashboard ─────────────────────────────────────────────────────────────── */
.dash-overlay {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(0,0,0,.6);
  display: flex; align-items: stretch;
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
}
.dash-overlay.open { opacity: 1; pointer-events: auto; }

.dash-panel {
  background: var(--bg-dark, #2E4A5D);
  width: 100%; max-width: 1100px;
  margin: auto;
  border-radius: 14px;
  display: flex; flex-direction: column;
  max-height: 92vh; overflow: hidden;
  box-shadow: 0 24px 80px rgba(0,0,0,.5);
  transform: translateY(16px);
  transition: transform .25s;
}
.dash-overlay.open .dash-panel { transform: translateY(0); }

.dash-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.dash-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 15px; font-weight: 600; color: var(--text);
}
.dash-updated { font-size: 11px; color: var(--muted); }

.dash-kpis {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px;
  padding: 16px 20px 8px; flex-shrink: 0;
}
.kpi-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px 16px;
}
.kpi-label { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.kpi-value { font-size: 22px; font-weight: 700; color: var(--text); line-height: 1.2; }
.kpi-sub { font-size: 11px; color: var(--muted); margin-top: 4px; }

.dash-charts {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 12px; padding: 8px 20px 20px;
  overflow-y: auto; flex: 1;
}
.dash-chart-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px;
}
.dash-chart-title { font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 10px; }
.dash-chart-wrap { height: 220px; position: relative; }

/* ── Slash commands ─────────────────────────────────────────────────────────── */
.slash-dropdown {
  position: absolute; bottom: 100%; left: 0; right: 0;
  margin-bottom: 6px;
  background: var(--bg-dark, #2E4A5D);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 -8px 32px rgba(0,0,0,.4);
  overflow: hidden; z-index: 50;
  max-height: 320px; overflow-y: auto;
}
.slash-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; cursor: pointer;
  transition: background .12s;
}
.slash-item:hover, .slash-item.active { background: rgba(110,198,255,.1); }
.slash-icon {
  width: 28px; height: 28px; border-radius: 7px;
  background: rgba(110,198,255,.15);
  color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700; flex-shrink: 0;
}
.slash-info { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.slash-cmd { font-size: 13px; font-weight: 600; color: var(--accent); flex-shrink: 0; }
.slash-label { font-size: 13px; color: var(--text); flex-shrink: 0; }
.slash-desc { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Presentation mode ──────────────────────────────────────────────────────── */
.present-bar {
  display: none;
  position: fixed; top: 20px; right: 24px; z-index: 9999;
  align-items: center; gap: 2px;
  background: rgba(10,10,20,.85); backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 10px; overflow: hidden;
  box-shadow: 0 4px 24px rgba(0,0,0,.5);
}
.present-bar-btn {
  display: flex; align-items: center; gap: 7px;
  padding: 9px 16px;
  color: var(--text); font-size: 13px; cursor: pointer;
  background: transparent; border: none;
  transition: background .15s; white-space: nowrap;
}
.present-bar-btn:hover { background: rgba(255,255,255,.08); }
.present-bar-exit { color: var(--muted); }
.present-bar-exit:hover { color: var(--text); }
.present-bar-divider { width: 1px; height: 20px; background: var(--border); flex-shrink: 0; }

body.presentation .present-bar { display: flex; }

/* Blur del chat cuando el dashboard está abierto en modo presentación */
body.presentation.dash-open .messages {
  filter: blur(8px);
  transition: filter .3s;
}
body.presentation .messages {
  transition: filter .3s;
}
body.presentation .sidebar { display: none !important; }
body.presentation .chat-header { display: none !important; }
body.presentation .composer  { display: none !important; }

body.presentation .chat {
  background: #0a0a14;
}

body.presentation .messages {
  padding: 48px 10vw;
  max-width: 100%;
}

body.presentation .message.user { display: none; }

body.presentation .message.assistant {
  max-width: 100%;
  align-self: stretch;
  margin-bottom: 48px;
}

body.presentation .message.assistant .bubble {
  font-size: 18px;
  line-height: 1.75;
  padding: 28px 36px;
  border-radius: 16px;
  background: rgba(255,255,255,.05);
  border: 1px solid rgba(255,255,255,.1);
  max-width: 100%;
}

body.presentation .message.assistant .bubble p  { margin-bottom: 1em; }
body.presentation .message.assistant .bubble h1,
body.presentation .message.assistant .bubble h2,
body.presentation .message.assistant .bubble h3 { font-size: 1.3em; margin: 1em 0 .5em; }
body.presentation .message.assistant .bubble table {
  font-size: 16px; width: 100%;
}
body.presentation .message.assistant .bubble th,
body.presentation .message.assistant .bubble td { padding: 10px 14px; }

body.presentation .message.assistant .bubble code {
  font-size: 15px;
}

body.presentation .msg-meta,
body.presentation .copy-btn { display: none !important; }

/* Branding overlay in presentation */
body.presentation .messages::before {
  content: 'WITHDATA — Agente Inteligente';
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .12em;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 32px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

/* ── Supply Chain Modules Panel ──────────────────────────────────────────── */
.sc-overlay {
  position: fixed; inset: 0;
  background: var(--bg-dark);
  display: flex; flex-direction: column;
  z-index: 1002;
  opacity: 0; pointer-events: none;
  transition: opacity .2s ease;
}
.sc-overlay.hidden { display: none; }
.sc-overlay.open { opacity: 1; pointer-events: all; }
.sc-panel {
  background: var(--bg-dark);
  width: 100%; height: 100%;
  display: flex; flex-direction: column;
  overflow: hidden;
}

/* Header */
.sc-panel .alerts-header {
  padding: 14px 28px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sc-tab-bar {
  display: flex; gap: 0;
  padding: 0 28px; border-bottom: 1px solid var(--border);
  flex-shrink: 0; background: var(--bg-dark);
}
.sc-tab {
  background: none; border: none; border-bottom: 3px solid transparent;
  color: var(--muted); font-size: 13px; font-weight: 500;
  padding: 12px 22px 11px; cursor: pointer; transition: color .15s, border-color .15s;
}
.sc-tab:hover { color: var(--text); }
.sc-tab.active { color: var(--text); border-bottom-color: var(--accent, #60a5fa); }

.sc-content {
  flex: 1; overflow-y: auto;
  padding: 28px 36px;
  max-width: 1400px; width: 100%; margin: 0 auto; box-sizing: border-box;
}
.sc-content.hidden { display: none; }

/* Wrap tables to allow horizontal scroll */
.sc-table-wrap { overflow-x: auto; border-radius: 8px; }

/* Urgency / Severity badges */
.sc-badge { display: inline-block; border-radius: 4px; padding: 2px 8px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.sc-badge-CRITICA  { background: rgba(239,68,68,.18);  color: #ef4444; border: 1px solid rgba(239,68,68,.3); }
.sc-badge-ALTA     { background: rgba(245,158,11,.18); color: #f59e0b; border: 1px solid rgba(245,158,11,.3); }
.sc-badge-MEDIA    { background: rgba(59,130,246,.18); color: #60a5fa; border: 1px solid rgba(59,130,246,.3); }
.sc-badge-BAJA     { background: rgba(34,197,94,.18);  color: #4ade80; border: 1px solid rgba(34,197,94,.3); }
.sc-badge-ml { display: inline-block; border-radius: 3px; padding: 1px 5px; font-size: 9px; font-weight: 700; white-space: nowrap; background: rgba(139,92,246,.2); color: #a78bfa; border: 1px solid rgba(139,92,246,.4); margin-left: 4px; vertical-align: middle; cursor: default; letter-spacing: .5px; }

/* OC action buttons */
.sc-btn {
  border: none; border-radius: 8px; padding: 7px 16px;
  font-size: 12px; cursor: pointer; font-weight: 600;
  transition: opacity .15s, transform .12s, box-shadow .12s;
  letter-spacing: .01em;
}
.sc-btn:hover  { opacity: .9; transform: translateY(-1px); box-shadow: 0 3px 10px rgba(0,0,0,.25); }
.sc-btn:active { transform: translateY(0); box-shadow: none; }
.sc-btn-approve { background: rgba(74,222,128,.18); color: #4ade80; border: 1px solid rgba(74,222,128,.35); }
.sc-btn-modify  { background: rgba(251,191,36,.18);  color: #fbbf24; border: 1px solid rgba(251,191,36,.35); }
.sc-btn-reject  { background: rgba(239,68,68,.18);   color: #ef4444; border: 1px solid rgba(239,68,68,.35); }
.sc-btn-export  { background: rgba(96,165,250,.18);  color: #60a5fa; border: 1px solid rgba(96,165,250,.35); }
.sc-btn-run     { background: rgba(167,139,250,.18); color: #a78bfa; border: 1px solid rgba(167,139,250,.35); }

/* OTIF coloring */
.sc-otif-ok   { color: #4ade80; font-weight: 600; }
.sc-otif-warn { color: #f59e0b; font-weight: 600; }
.sc-otif-fail { color: #ef4444; font-weight: 600; }

/* Alert cards */
.sc-alert-card { border-left: 3px solid; background: rgba(255,255,255,.03); border-radius: 6px; padding: 11px 14px; margin-bottom: 8px; }
.sc-alert-card-CRITICA  { border-left-color: #ef4444; }
.sc-alert-card-ALTA     { border-left-color: #f59e0b; }
.sc-alert-card-MEDIA    { border-left-color: #60a5fa; }
.sc-alert-card-BAJA     { border-left-color: #4ade80; }
.sc-alert-card-title    { font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 4px; display: flex; align-items: center; gap: 8px; }
.sc-alert-card-desc     { font-size: 11px; color: var(--muted); }
.sc-alert-card-actions  { display: flex; gap: 6px; margin-top: 8px; }

/* Summary KPI row */
.sc-kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 24px; }
.sc-kpi-card { background: rgba(255,255,255,.04); border: 1px solid var(--border); border-radius: 10px; padding: 18px 20px; }
.sc-kpi-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 6px; }
.sc-kpi-value { font-size: 28px; font-weight: 700; color: var(--text); }
.sc-kpi-sub   { font-size: 11px; color: var(--muted); margin-top: 4px; }

/* Filter row */
.sc-filter-row { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.sc-select {
  background: var(--bg-dark, #1e1e2e);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  outline: none;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
}
.sc-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb, 96,165,250), .15);
}
.sc-select option { background: var(--bg-dark, #1e1e2e); color: var(--text); }

/* ── Confirm Dialog ──────────────────────────────────────────────────────── */
.confirm-box {
  max-width: 360px !important;
  padding: 28px 28px 22px !important;
  text-align: center;
  animation: confirmIn .15s ease;
}
@keyframes confirmIn {
  from { opacity: 0; transform: scale(.94) translateY(-8px); }
  to   { opacity: 1; transform: scale(1)  translateY(0); }
}
.confirm-icon {
  font-size: 32px;
  margin-bottom: 12px;
  line-height: 1;
}
.confirm-btn {
  padding: 8px 22px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  min-width: 90px;
}
.confirm-btn:hover  { opacity: .88; }
.confirm-btn:active { transform: scale(.97); }
.confirm-btn-cancel {
  background: rgba(255,255,255,.08);
  color: var(--text);
  border: 1px solid var(--border);
}
.confirm-btn-cancel:hover { background: rgba(255,255,255,.13); }
.confirm-btn-danger  { background: #ef4444; color: #fff; }
.confirm-btn-warning { background: #f59e0b; color: #fff; }
.confirm-btn-primary { background: var(--accent); color: #fff; }

/* Mini modal for modify OC / add entrega */
.sc-modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 1100; }
.sc-modal.hidden { display: none; }
.sc-modal-box { background: var(--bg-dark); border: 1px solid var(--border); border-radius: 10px; padding: 20px 22px; min-width: 320px; max-width: 480px; width: 90vw; }
.sc-modal-title { font-size: 14px; font-weight: 600; margin-bottom: 14px; }
.sc-modal-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.sc-modal-label { font-size: 11px; color: var(--muted); }
.sc-modal-input {
  background: rgba(255,255,255,.1);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
  box-sizing: border-box;
}
.sc-modal-input::placeholder { color: rgba(255,255,255,.35); }
.sc-modal-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(96,165,250,.15);
  background: rgba(255,255,255,.13);
}
.sc-modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }

/* OTIF sub-tabs */
.sc-subtabs { display: flex; gap: 6px; margin-bottom: 14px; }
.sc-subtab { background: rgba(255,255,255,.05); border: 1px solid var(--border); color: var(--muted); border-radius: 6px; padding: 5px 14px; font-size: 12px; cursor: pointer; transition: all .15s; }
.sc-subtab.active { background: rgba(96,165,250,.15); color: #60a5fa; border-color: rgba(96,165,250,.4); }

/* Config section */
.sc-config-section { background: rgba(255,255,255,.02); border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px; margin-bottom: 14px; }
.sc-config-title { font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 10px; cursor: pointer; display: flex; align-items: center; gap: 6px; }
.sc-config-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.sc-config-item { display: flex; flex-direction: column; gap: 3px; }
.sc-config-label { font-size: 10px; color: var(--muted); }
.sc-config-input {
  background: rgba(255,255,255,.1);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 7px;
  padding: 7px 10px;
  font-size: 12px;
  width: 100%;
  outline: none;
  box-sizing: border-box;
  transition: border-color .15s, box-shadow .15s;
}
.sc-config-input::placeholder { color: rgba(255,255,255,.32); }
.sc-config-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(96,165,250,.15);
  background: rgba(255,255,255,.13);
}

.sc-empty { color: var(--muted); font-size: 13px; text-align: center; padding: 32px 0; }
.sc-section-title { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 16px 0 8px; }

/* Page header inside each tab */
.sc-page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 24px; gap: 16px; flex-wrap: wrap;
}
.sc-page-title { font-size: 20px; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.sc-page-sub   { font-size: 12px; color: var(--muted); }
