@import url('https://fonts.googleapis.com/css2?family=Open+Sans:wght@300;400;600;700;800&display=swap');

:root {
  --bg-color: #f8faff;
  --chat-bg: #ffffff;
  --primary-color: #1B396A;
  --secondary-color: #122a50;
  --accent-red: #dc3545;
  --text-main: #333333;
  --text-muted: #666666;
  --border-light: #eef2f7;
  --user-msg-bg: linear-gradient(135deg, #1B396A 0%, #122a50 100%);
  --ai-msg-bg: #f1f4f9;
  /* Glassmorphism (paleta detectada: azul TecNM, cyan #7bbfff y coral #ff6b7a) */
  --glass-bg: rgba(255, 255, 255, 0.72);
  --glass-bg-strong: rgba(255, 255, 255, 0.85);
  --glass-border: rgba(27, 57, 106, 0.10);
  --glass-blur: blur(14px);
  --glass-shadow: 0 8px 32px rgba(27, 57, 106, 0.08);
  --transition-ui: all 0.3s ease;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Open Sans', sans-serif; }

body {
  /* Tintes suaves con la paleta del hero (azul TecNM / cyan / coral) para que
     el efecto de vidrio tenga color que difuminar */
  background:
    radial-gradient(900px 520px at 88% -10%, rgba(123, 191, 255, 0.18), transparent 60%),
    radial-gradient(720px 460px at -12% 28%, rgba(27, 57, 106, 0.10), transparent 60%),
    radial-gradient(820px 520px at 72% 112%, rgba(255, 107, 122, 0.08), transparent 60%),
    var(--bg-color);
  background-attachment: fixed;
  color: var(--text-main);
  height: 100vh;
  display: flex;
  overflow: hidden;
}

/* Chat Layout */
#chat-layout {
  display: flex;
  width: 100%;
  height: 100%;
  flex-direction: column;
  background: transparent;
}

/* Header */
.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 30px;
  background: var(--glass-bg-strong);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--glass-border);
  box-shadow: 0 4px 12px rgba(27, 57, 106, 0.04);
  z-index: 10;
  flex-shrink: 0;
}

/* Brand — estructura idéntica al panel burbuja */
.chat-header .tia-panel-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-header .tia-brand-avatar {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, #1B396A, #24518F);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 16px;
  flex-shrink: 0;
}

.chat-header .tia-brand-name {
  font-size: 17px;
  font-weight: 800;
  background: linear-gradient(135deg, #1B396A 0%, #dc3545 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.chat-header .tia-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-header .tia-credits-pill {
  background: rgba(27, 57, 106, 0.08);
  color: #1B396A;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
  white-space: nowrap;
}

.chat-header .tia-icon-btn {
  background: transparent;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: background 0.2s, color 0.2s;
  font-size: 15px;
  text-decoration: none;
  flex-shrink: 0;
}

.chat-header .tia-icon-btn:hover {
  background: rgba(27, 57, 106, 0.08);
  color: #1B396A;
}

/* En móvil el blur intenso puede costar rendimiento: lo reducimos */
@media (max-width: 768px) {
  :root {
    --glass-blur: blur(8px);
  }
}

/* ── Catalog Drawer ──────────────────────────────────────────────────── */
.oa-catalog-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 1100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}
.oa-catalog-backdrop.visible {
  opacity: 1;
  pointer-events: all;
}

.oa-catalog-drawer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-radius: 20px 20px 0 0;
  z-index: 1101;
  max-height: 72vh;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 -4px 32px rgba(27, 57, 106, 0.14);
}
.oa-catalog-drawer.open { transform: translateY(0); }

.oa-catalog-handle {
  width: 40px;
  height: 4px;
  background: #e2e8f0;
  border-radius: 2px;
  margin: 12px auto 0;
  flex-shrink: 0;
}

.oa-catalog-inner {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex: 1;
}

.oa-catalog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px 12px;
  border-bottom: 1px solid #eef2f7;
  flex-shrink: 0;
}

.oa-catalog-head-title {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 16px;
  font-weight: 800;
  color: #1B396A;
}

.oa-catalog-close-btn {
  background: transparent;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  transition: all 0.3s ease;
}
.oa-catalog-close-btn:hover { background: #f1f5f9; color: #475569; }

.oa-catalog-list {
  overflow-y: auto;
  padding: 10px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.oa-catalog-list::-webkit-scrollbar { width: 4px; }
.oa-catalog-list::-webkit-scrollbar-track { background: transparent; }
.oa-catalog-list::-webkit-scrollbar-thumb { background: #dce4ed; border-radius: 10px; }

.oa-catalog-group-label {
  font-size: 11px;
  font-weight: 700;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding: 10px 4px 4px;
}

.oa-catalog-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border: 1.5px solid #e2eaf4;
  border-radius: 12px;
  background: #f8faff;
  cursor: pointer;
  transition: all 0.3s ease;
  text-align: left;
  width: 100%;
  font-family: 'Open Sans', sans-serif;
}
.oa-catalog-item:hover { background: #eff4ff; border-color: var(--primary-color); }

.oa-catalog-item-num {
  width: 32px;
  height: 32px;
  background: rgba(27, 57, 106, 0.09);
  color: var(--primary-color);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 800;
  flex-shrink: 0;
}

.oa-catalog-item-info {
  flex: 1;
  min-width: 0;
}
.oa-catalog-item-title {
  font-size: 14px;
  font-weight: 700;
  color: #1e293b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.oa-catalog-item-desc {
  font-size: 12px;
  color: #64748b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.oa-catalog-item-arrow {
  color: #94a3b8;
  font-size: 13px;
  flex-shrink: 0;
  transition: transform 0.3s ease, color 0.3s ease;
}
.oa-catalog-item:hover .oa-catalog-item-arrow { transform: translateX(2px); color: var(--primary-color); }

.oa-catalog-status {
  text-align: center;
  padding: 32px 16px;
  font-size: 14px;
  color: #94a3b8;
}
.oa-catalog-status.error { color: var(--accent-red); }

@media (max-width: 640px) {
  .modules-btn-label { display: none; }
  .modules-btn { padding: 6px 10px; }
}

.logout-btn {
  background: white;
  color: var(--primary-color);
  border: 1px solid var(--primary-color);
  border-radius: 10px;
  font-size: 13px; 
  font-weight: 700; 
  padding: 8px 16px; 
  cursor: pointer;
  transition: all 0.3s;
}

.logout-btn:hover { 
  background: var(--primary-color);
  color: white;
}

/* Container */
.chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
  position: relative;
}

/* Messages */
.message-row {
  width: 100%;
  display: flex;
  padding: 0 16px;
}

.message-row.user { justify-content: flex-end; }
.message-row.ai {
  justify-content: flex-start;
  flex-direction: column;
  align-items: flex-start;
}

.message-content {
  max-width: 800px;
  display: flex;
  gap: 9px;
}

.user .message-content { flex-direction: row-reverse; }

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-shrink: 0;
  font-size: 13px;
  margin-top: 2px;
}

.avatar.user { background: #1B396A; color: white; }
.avatar.ai { background: var(--user-msg-bg); color: white; }

.text-bubble {
  padding: 11px 14px;
  border-radius: 16px;
  font-size: 13.5px;
  line-height: 1.6;
  position: relative;
  box-shadow: var(--glass-shadow);
  transition: box-shadow 0.3s ease;
}

.user .text-bubble {
  background: var(--user-msg-bg);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-bottom-right-radius: 4px;
  box-shadow: 0 6px 18px rgba(27, 57, 106, 0.20);
}

.ai .text-bubble {
  background: rgba(241, 244, 249, 0.78);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  color: var(--text-main);
  border-bottom-left-radius: 4px;
  border: 1px solid rgba(27, 57, 106, 0.08);
}

/* Markdown Styles */
.text-bubble p { margin-bottom: 8px; font-size: inherit; }
.text-bubble p:last-child { margin-bottom: 0; }
.text-bubble ul, .text-bubble ol { margin-left: 16px; margin-bottom: 8px; }
.text-bubble code { background: rgba(0,0,0,0.06); padding: 2px 5px; border-radius: 4px; font-size: 12px; font-family: monospace; }
.ai .text-bubble code { background: #f0f0f0; }
.text-bubble strong { font-weight: 700; }
.text-bubble h1, .text-bubble h2, .text-bubble h3 { font-size: 14px; font-weight: 700; margin: 10px 0 5px; }
.text-bubble table { border-collapse: collapse; font-size: 12px; margin: 8px 0; }
.text-bubble th, .text-bubble td { padding: 5px 8px; border: 1px solid #e2e8f0; }
.text-bubble th { background: #f8fafc; font-weight: 700; }

/* Feedback Controls (Premium Pill Design) */
.feedback-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 6px;
  padding-left: 39px;
  opacity: 0.6;
  transition: all 0.3s ease;
}

.message-row.ai:hover .feedback-controls {
  opacity: 1;
}

.feedback-btn {
  background: #f1f5f9;
  border: none;
  width: 28px;
  height: 28px;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  color: #64748b;
  font-size: 12px;
  transition: all 0.3s ease;
  border-radius: 7px;
}

.feedback-btn:hover {
  background: #e2e8f0;
  color: var(--primary-color);
  transform: translateY(-1px);
}

.feedback-btn.up.active {
  color: #10b981;
  background: #ecfdf5;
}

.feedback-btn.down.active {
  color: #ef4444;
  background: #fef2f2;
}

.feedback-btn:disabled {
  cursor: default;
  transform: none !important;
}

/* Quick Actions (Chips) */
.quick-actions {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 2px 0 8px;
  transition: opacity 0.3s ease;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none;  /* IE and Edge */
}

.quick-actions::-webkit-scrollbar {
  display: none; /* Chrome, Safari, Opera */
}

.chip {
  background: rgba(255, 255, 255, 0.65);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(27, 57, 106, 0.10);
  padding: 6px 12px;
  border-radius: 16px;
  font-size: 12px;
  color: #475569;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.3s ease;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(0,0,0,0.03);
}

.chip:hover {
  background: rgba(255, 255, 255, 0.85);
  border-color: var(--primary-color);
  color: var(--primary-color);
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(27, 57, 106, 0.08);
}

.chip i {
  margin-right: 5px;
  color: var(--primary-color);
  font-size: 11px;
}

.chip--disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

/* Code Syntax Styling */
pre {
  background: #1e293b !important; /* Fondo oscuro tipo VS Code */
  padding: 15px !important;
  border-radius: 12px !important;
  margin: 15px 0 !important;
  overflow-x: auto;
  position: relative;
}

code {
  font-family: 'Fira Code', 'Consolas', monospace !important;
  font-size: 13px !important;
}

.hljs {
  background: transparent !important;
  padding: 0 !important;
}

/* Botón de Copiar para Bloques de Código (Minimalista) */
.code-copy-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  background: transparent;
  border: none;
  color: #94a3b8;
  width: 30px;
  height: 30px;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 6px;
  cursor: pointer;
  z-index: 10;
  transition: all 0.3s ease;
}

.code-copy-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

.code-copy-btn i {
  font-size: 14px;
}

.feedback-btn:disabled {
  cursor: not-allowed;
  opacity: 0.5;
  transform: none !important;
}

/* Input Area */
.input-area {
  padding: 10px 14px 14px;
  background: transparent;
  flex-shrink: 0;
}

.input-wrapper {
  max-width: 1000px;
  margin: 0 auto;
  background: rgba(248, 250, 255, 0.75);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1.5px solid rgba(27, 57, 106, 0.10);
  border-radius: 14px;
  display: flex;
  align-items: flex-end;
  padding: 8px 10px;
  transition: border-color 0.3s ease, background 0.3s ease;
  position: relative;
}

.input-wrapper:focus-within {
  border-color: var(--primary-color);
  background: rgba(255, 255, 255, 0.92);
}

textarea#chat-input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 13.5px;
  padding: 6px 5px;
  resize: none;
  outline: none;
  min-height: 36px;
  max-height: 120px;
  color: var(--text-main);
  line-height: 1.45;
  font-family: 'Open Sans', sans-serif;
}

textarea#chat-input::placeholder { color: #94a3b8; }

textarea#chat-input:disabled {
  color: #94a3b8;
  cursor: not-allowed;
}

.input-wrapper.exhausted {
  background: #f8fafc;
  border-color: #e2e8f0;
}

#send-btn {
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: 9px;
  width: 34px;
  height: 34px;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.3s;
}

#send-btn:hover { background: var(--secondary-color); transform: scale(1.05); }
#send-btn:disabled { opacity: 0.28; cursor: not-allowed; transform: none; }

#stop-btn {
  background: white; 
  color: var(--primary-color); 
  border: 1.5px solid var(--primary-color); 
  border-radius: 12px;
  width: 45px; 
  height: 45px; 
  display: none; 
  justify-content: center; 
  align-items: center;
  cursor: pointer; 
  margin-bottom: 2px;
  margin-left: 10px; 
  transition: all 0.3s;
}

#stop-btn:hover { 
  background: #f1f5f9;
  transform: scale(1.05); 
}

/* Typing Indicator */
.typing-dots { display: flex; gap: 4px; padding: 5px 0; }
.typing-dots span { width: 6px; height: 6px; background: #bbb; border-radius: 50%; animation: blink 1.4s infinite both; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0% { opacity: 0.2; } 20% { opacity: 1; } 100% { opacity: 0.2; } }

.input-footer {
  max-width: 1000px;
  margin: 4px auto 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 0 2px;
}

.chat-disclaimer--short { display: none; }

.chat-disclaimer {
  text-align: left;
  font-size: 10px;
  color: #94a3b8;
  line-height: 1.3;
  margin: 0;
  flex: 1;
}

.chat-disclaimer--full { text-align: center; }

#chat-char-counter {
  font-size: 10px;
  font-weight: 700;
  color: #94a3b8;
  white-space: nowrap;
  flex-shrink: 0;
  transition: color 0.2s;
}

#chat-char-counter.warning {
  color: #f59e0b;
  opacity: 1;
}

#chat-char-counter.limit {
  color: #dc3545;
  opacity: 1;
}

/* Floating Scroll Button (Centered) */
.scroll-btn {
  position: absolute;
  /* Usamos la variable dinámica calculada por JS, con un fallback de 130px */
  bottom: calc(var(--input-area-height, 130px) + 15px);
  left: 50%;
  transform: translateX(-50%);
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--glass-bg-strong);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--glass-border);
  box-shadow: 0 4px 20px rgba(27, 57, 106, 0.15);
  color: var(--primary-color);
  display: none;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  z-index: 1000;
  transition: bottom 0.3s cubic-bezier(0.4, 0, 0.2, 1), transform 0.2s, opacity 0.3s;
  animation: fadeIn 0.3s;
}

.scroll-btn:hover {
  transform: translateX(-50%) translateY(-3px);
  box-shadow: 0 6px 25px rgba(27, 57, 106, 0.2);
}

.scroll-btn i { 
  font-size: 18px; 
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Typing indicator inside button */
.typing-indicator-mini {
  display: flex;
  gap: 4px;
}

.typing-indicator-mini span {
  width: 5px;
  height: 5px;
  background: var(--primary-color);
  border-radius: 50%;
  animation: blink 1.4s infinite both;
}

.typing-indicator-mini span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator-mini span:nth-child(3) { animation-delay: 0.4s; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateX(-50%) scale(0.8); }
  to { opacity: 1; transform: translateX(-50%) scale(1); }
}

/* Scrollbar */
.chat-container::-webkit-scrollbar { width: 6px; }
.chat-container::-webkit-scrollbar-track { background: transparent; }
.chat-container::-webkit-scrollbar-thumb { background: #dce4ed; border-radius: 10px; }
.chat-container::-webkit-scrollbar-thumb:hover { background: #ccd6e0; }


@media (max-width: 768px) {
  body { height: 100dvh; }
  .chat-header { padding: 8px 12px; }

  .input-area { padding: 10px; }
  .input-footer { margin-top: 6px; padding: 0 5px; gap: 8px; }
  .chat-disclaimer { font-size: 10px; }
  .chat-disclaimer--full { display: none; }
  .chat-disclaimer--short { display: block; }
  #chat-char-counter { font-size: 10px; }
  #stop-btn { width: 34px; height: 34px; }

  .scroll-btn {
    width: 42px;
    height: 42px;
  }

  .feedback-controls {
    opacity: 1 !important;
  }
}

/* ── OA Panel (Split View) ─────────────────────────────────────────────────── */

#oa-panel {
  display: none;
  width: 50%;
  height: 100%;
  flex-direction: column;
  background: var(--glass-bg-strong);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-left: 1px solid var(--glass-border);
  overflow: hidden;
  flex-shrink: 0;
}

body.oa-panel-open #chat-layout {
  width: 50%;
}

body.oa-panel-open #oa-panel {
  display: flex;
}

/* Wrapper del área de contenido (debajo del header + progress bar) */
.oa-panel-body {
  position: relative;
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── OA Panel Sidebar (índice de pasos) ───────────────────────────────────── */
.oa-panel-sidebar {
  position: absolute;
  top: 0;
  left: 0;
  width: 260px;
  height: 100%;
  background: rgba(248, 250, 252, 0.97);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-right: 1px solid rgba(27, 57, 106, 0.10);
  display: flex;
  flex-direction: column;
  z-index: 300;
  transform: translateX(-100%);
  transition: transform 0.28s ease;
  box-shadow: 4px 0 24px rgba(0,0,0,0.10);
}
.oa-panel-sidebar.open {
  transform: translateX(0);
}
.oa-panel-sidebar-header {
  padding: 16px 18px;
  border-bottom: 1px solid rgba(27, 57, 106, 0.10);
  background: rgba(255,255,255,0.70);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.oa-panel-sidebar-header h2 {
  font-size: 11.5px;
  font-weight: 800;
  color: var(--primary-color);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin: 0;
}
.oa-panel-sidebar-close {
  background: #f1f5f9;
  border: none;
  border-radius: 7px;
  width: 28px;
  height: 28px;
  color: var(--primary-color);
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  flex-shrink: 0;
}
.oa-panel-sidebar-close:hover { background: rgba(27,57,106,0.12); }

.oa-panel-sidebar-nav {
  flex-grow: 1;
  overflow-y: auto;
  padding: 6px 0;
  -webkit-overflow-scrolling: touch;
}
.oa-panel-sidebar-nav::-webkit-scrollbar { width: 4px; }
.oa-panel-sidebar-nav::-webkit-scrollbar-thumb { background: #dce4ed; border-radius: 4px; }

.oa-panel-nav-item {
  padding: 13px 18px;
  font-size: 13px;
  color: #4a5568;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  border-left: 3px solid transparent;
  transition: background 0.2s, color 0.2s;
}
.oa-panel-nav-item:hover { background: rgba(27,57,106,0.05); color: var(--primary-color); }
.oa-panel-nav-item.active {
  background: white;
  color: var(--primary-color);
  font-weight: 700;
  border-left-color: var(--primary-color);
}
.oa-panel-nav-item.visited { color: var(--primary-color); }
.oa-panel-nav-item.visited::after {
  content: '\f00c';
  font-family: 'FontAwesome';
  font-size: 10px;
  color: #10b981;
  margin-left: auto;
}
.oa-panel-nav-item.nav-locked { opacity: 0.4; cursor: not-allowed; pointer-events: none; }

.oa-panel-sidebar-overlay {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.40);
  z-index: 299;
  backdrop-filter: blur(2px);
}
.oa-panel-sidebar-overlay.open { display: block; }

/* Botón hamburguesa siempre visible en el panel */
.oa-panel-hamburger {
  background: var(--primary-color);
  border: none;
  border-radius: 8px;
  width: 34px;
  height: 34px;
  color: white;
  cursor: pointer;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s;
  box-shadow: 0 2px 8px rgba(27,57,106,0.2);
}
.oa-panel-hamburger:hover { background: #24518f; }
.oa-panel-hamburger i {
  transition: opacity 0.15s ease, transform 0.2s ease;
}

/* OA Panel Header */
.oa-panel-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  background: rgba(255, 255, 255, 0.65);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--glass-border);
  box-shadow: 0 2px 8px rgba(27, 57, 106, 0.04);
  flex-shrink: 0;
}

.oa-panel-back-btn {
  display: none;
  background: transparent;
  border: none;
  color: var(--primary-color);
  font-size: 16px;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 8px;
  transition: background 0.3s ease;
  flex-shrink: 0;
}
.oa-panel-back-btn:hover { background: #f1f5f9; }

.oa-panel-title {
  flex: 1;
  font-weight: 700;
  font-size: 14px;
  color: var(--primary-color);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.oa-panel-step-count {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  font-weight: 600;
}

.oa-panel-close-btn {
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 18px;
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: all 0.3s ease;
  flex-shrink: 0;
}
.oa-panel-close-btn:hover { background: #fff1f2; color: var(--accent-red); }

/* Progress Track */
.oa-panel-progress-track {
  height: 4px;
  background: #f1f4f9;
  flex-shrink: 0;
}
.oa-panel-progress-fill {
  height: 100%;
  background: var(--primary-color);
  transition: width 0.4s ease;
  width: 0%;
}

/* Panel Content */
.oa-panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
  scroll-behavior: smooth;
}
.oa-panel-content::-webkit-scrollbar { width: 5px; }
.oa-panel-content::-webkit-scrollbar-track { background: transparent; }
.oa-panel-content::-webkit-scrollbar-thumb { background: #dce4ed; border-radius: 10px; }

/* Panel Footer */
.oa-panel-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  background: rgba(255, 255, 255, 0.65);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--glass-border);
  flex-shrink: 0;
}

.oa-panel-btn {
  padding: 9px 20px;
  border-radius: 10px;
  border: 1px solid var(--border-light);
  background: white;
  color: var(--primary-color);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.3s ease;
}
.oa-panel-btn:hover:not(:disabled) { background: #f1f5f9; }
.oa-panel-btn.primary { background: var(--primary-color); color: white; border-color: var(--primary-color); }
.oa-panel-btn.primary:hover:not(:disabled) { background: var(--secondary-color); }
.oa-panel-btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* Documentos de referencia (mismo diseño que el visor normal) */
.oa-recursos-section {
  margin-top: 40px;
  padding-top: 24px;
  border-top: 1px solid var(--border-light);
}

.oa-recursos-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.oa-recursos-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.oa-recurso-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: #f8faff;
  border: 1.5px solid #e2eaf4;
  border-radius: 12px;
  text-decoration: none;
  transition: all 0.3s ease;
  flex: 1 1 200px;
  max-width: 320px;
}

.oa-recurso-card:hover {
  background: #eff4ff;
  border-color: var(--primary-color);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(27, 57, 106, 0.10);
  text-decoration: none;
}

.oa-recurso-icon {
  width: 40px;
  height: 40px;
  background: rgba(220, 53, 69, 0.08);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #dc3545;
  font-size: 18px;
  flex-shrink: 0;
}

.oa-recurso-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.oa-recurso-nombre {
  font-size: 13px;
  font-weight: 700;
  color: #1e293b;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.oa-recurso-cta {
  font-size: 11px;
  color: var(--primary-color);
  font-weight: 600;
}

/* Step Content */
.oa-panel-step h3 {
  font-size: 17px;
  font-weight: 700;
  color: var(--primary-color);
  margin-bottom: 18px;
  line-height: 1.3;
}

/* Objectives */
.oa-objectives { display: flex; flex-direction: column; gap: 10px; }
.oa-obj-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: #f8faff;
  border-left: 3px solid var(--primary-color);
  padding: 10px 14px;
  border-radius: 0 8px 8px 0;
  font-size: 14px;
  line-height: 1.5;
}
.oa-obj-item i { color: var(--primary-color); margin-top: 2px; flex-shrink: 0; }

/* Theory / Example / Conclusion */
.oa-theory-body { font-size: 14px; line-height: 1.7; color: var(--text-main); }
.oa-theory-body p { margin-bottom: 12px; }
.oa-theory-body ul, .oa-theory-body ol { margin-left: 18px; margin-bottom: 12px; }
.oa-theory-body h1, .oa-theory-body h2, .oa-theory-body h3 { color: var(--primary-color); margin: 16px 0 8px; }
.oa-theory-body code { background: #f0f4f8; padding: 2px 6px; border-radius: 4px; font-size: 13px; font-family: monospace; }
.oa-theory-body pre { background: #1e293b; padding: 14px; border-radius: 10px; overflow-x: auto; margin: 14px 0; }
.oa-theory-body pre code { background: transparent; color: #e2e8f0; }
.oa-theory-body table { width: 100%; border-collapse: collapse; margin: 14px 0; font-size: 13px; }
.oa-theory-body th, .oa-theory-body td { padding: 8px 12px; border: 1px solid var(--border-light); }
.oa-theory-body th { background: #f1f5f9; font-weight: 700; }

/* Quiz */
.oa-quiz { display: flex; flex-direction: column; gap: 10px; }
.oa-quiz-question { font-weight: 600; font-size: 15px; margin-bottom: 6px; line-height: 1.4; }
.oa-quiz-opt {
  width: 100%;
  text-align: left;
  padding: 12px 16px;
  border: 1.5px solid var(--border-light);
  border-radius: 10px;
  background: white;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.3s ease;
  color: var(--text-main);
  line-height: 1.4;
}
.oa-quiz-opt:hover:not(:disabled) { border-color: var(--primary-color); background: #f0f4ff; }
.oa-quiz-opt.correct { border-color: #10b981; background: #ecfdf5; color: #065f46; font-weight: 600; }
.oa-quiz-opt.incorrect { border-color: var(--accent-red); background: #fef2f2; color: #991b1b; }
.oa-quiz-opt:disabled { cursor: default; }
.oa-quiz-feedback { border-radius: 10px; padding: 12px 16px; font-size: 14px; line-height: 1.5; margin-top: 4px; }
.oa-quiz-feedback.success { background: #ecfdf5; color: #065f46; border: 1px solid #6ee7b7; }
.oa-quiz-feedback.error { background: #fef2f2; color: #991b1b; border: 1px solid #fca5a5; }

/* Loading skeleton */
.oa-panel-loading { padding: 4px 0; display: flex; flex-direction: column; gap: 0; }
.oa-skeleton {
  display: block;
  background: linear-gradient(90deg, #f0f4f8 25%, #e2e8f0 50%, #f0f4f8 75%);
  background-size: 200% 100%;
  animation: oaShimmer 1.5s infinite;
  margin-bottom: 9px;
}
@keyframes oaShimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* Error state */
.oa-panel-error {
  padding: 20px 0;
  color: #ef4444;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* OA Open Button in chat messages */
.oa-refs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}
.oa-open-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: #f0f4ff;
  border: 1.5px solid rgba(27, 57, 106, 0.2);
  border-radius: 20px;
  color: var(--primary-color);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
}
.oa-open-btn:hover {
  background: var(--primary-color);
  color: white;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(27, 57, 106, 0.2);
}
.oa-open-btn i { font-size: 13px; }

/* Mobile OA panel */
@media (max-width: 768px) {
  body.oa-panel-open #chat-layout { display: none; }

  #oa-panel {
    width: 100%;
    border-left: none;
  }

  /* Panel ocupa pantalla completa con posición fija para evitar que iOS recorte la altura */
  body.oa-panel-open #oa-panel {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    z-index: 999;
    flex-direction: column;
  }

  .oa-panel-back-btn { display: flex; }
  .oa-panel-close-btn { display: none; }

  .oa-panel-content {
    padding: 18px 16px;
    -webkit-overflow-scrolling: touch;
  }

  /* Espacio seguro en footer para notch de iOS */
  .oa-panel-footer {
    padding: 10px 14px;
    padding-bottom: max(14px, env(safe-area-inset-bottom, 14px));
  }

  .oa-panel-btn { padding: 8px 14px; font-size: 12px; }

  /* Contenido del panel: fuente y quiz más legibles en pantalla pequeña */
  .oa-panel-step h3 { font-size: 15px; }
  .oa-quiz-question { font-size: 14px; }
  .oa-quiz-opt { padding: 10px 14px; font-size: 13px; }
  .oa-theory-body { font-size: 13px; }
  .oa-theory-body pre { padding: 10px; font-size: 12px; }
}

/* ── Read-hint anti-trampa (OA Panel) ─────────────────────────────────────── */
.read-hint {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 8px;
  font-size: 11.5px;
  font-weight: 500;
  color: #1e40af;
  text-align: center;
  min-width: 0;
  transition: opacity 0.35s ease;
}
.read-hint-icon { font-size: 13px; flex-shrink: 0; color: #1B396A; }
.read-hint-done { opacity: 0; pointer-events: none; }
.fa-arrow-down.read-hint-icon { animation: bounce-down 1.2s ease-in-out infinite; }
@keyframes bounce-down {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(4px); }
}
@keyframes next-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(27, 57, 106, 0.5); }
  70%  { box-shadow: 0 0 0 10px rgba(27, 57, 106, 0); }
  100% { box-shadow: 0 0 0 0 rgba(27, 57, 106, 0); }
}
.btn-next-pulse { animation: next-pulse 0.8s ease-out; }
