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

:root {
  --bg-primary: #0a0f1a;
  --bg-secondary: #111827;
  --bg-tertiary: #1f2937;
  --bg-card: #162032;
  --text-primary: #f0f4f8;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent-primary: #06b6d4;
  --accent-secondary: #0891b2;
  --accent-glow: rgba(6, 182, 212, 0.3);
  --math-gold: #fbbf24;
  --math-gold-light: #fcd34d;
  --success-color: #10b981;
  --success-light: #34d399;
  --warning-color: #f59e0b;
  --danger-color: #ef4444;
  --danger-light: #f87171;
  --border-color: #334155;
  --border-glow: rgba(6, 182, 212, 0.2);
  --gradient-math: linear-gradient(135deg, #06b6d4 0%, #3b82f6 50%, #8b5cf6 100%);
}

body {
  font-family: 'Space Grotesk', sans-serif;
  background: var(--bg-primary);
  background-image:
    radial-gradient(ellipse at 20% 20%, rgba(6, 182, 212, 0.08) 0%, transparent 50%), radial-gradient(ellipse at 80% 80%, rgba(139, 92, 246, 0.06) 0%, transparent 50%),
    repeating-linear-gradient(0deg, transparent, transparent 100px, rgba(6, 182, 212, 0.02) 100px, rgba(6, 182, 212, 0.02) 101px),
    repeating-linear-gradient(90deg, transparent, transparent 100px, rgba(6, 182, 212, 0.02) 100px, rgba(6, 182, 212, 0.02) 101px);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

mjx-container {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
}
mjx-container[jax="CHTML"][display="true"] {
  margin: 0.5rem 0 !important;
}

.header {
  padding: 1.5rem 2rem;
  background: var(--bg-secondary);
  border-bottom: 2px solid var(--border-color);
  position: relative;
  overflow: hidden;
}

.header::before {
  content: '∑ ∫ π √ ∞ Δ θ λ';
  position: absolute;
  top: 50%;
  right: 2rem;
  transform: translateY(-50%);
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.5rem;
  color: rgba(6, 182, 212, 0.15);
  letter-spacing: 0.5rem;
  pointer-events: none;
}

.header-content {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
  z-index: 1;
  flex-wrap: wrap;
  gap: 1rem;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.logo-icon {
  width: 60px;
  height: 60px;
  background: var(--gradient-math);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  box-shadow: 0 4px 20px var(--accent-glow);
}

.header-text h1 {
  font-size: 1.6rem;
  font-weight: 700;
  background: var(--gradient-math);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-text p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-family: 'JetBrains Mono', monospace;
}

.header-buttons {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.help-btn {
  padding: 0.7rem 1.25rem;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  font-family: 'Space Grotesk', sans-serif;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.help-btn:hover {
  border-color: var(--accent-primary);
  box-shadow: 0 0 20px var(--accent-glow);
}

.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(4px);
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  background: var(--bg-secondary);
  margin: 3% auto;
  padding: 2rem;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  width: 90%;
  max-width: 700px;
  max-height: 85vh;
  overflow-y: auto;
  color: var(--text-primary);
  position: relative;
}

.modal-content h2 {
  background: var(--gradient-math);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 1.5rem;
  font-size: 1.5rem;
}

.close-modal {
  color: var(--text-secondary);
  float: right;
  font-size: 1.75rem;
  font-weight: bold;
  cursor: pointer;
  line-height: 1;
}

.close-modal:hover {
  color: var(--accent-primary);
}

.help-section {
  margin-bottom: 1.25rem;
  padding: 1rem;
  background: var(--bg-tertiary);
  border-left: 4px solid var(--accent-primary);
  border-radius: 6px;
}

.help-section h3 {
  color: var(--accent-primary);
  margin-bottom: 0.5rem;
  font-size: 1.05rem;
}

.help-section p {
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.7;
}

.help-section a {
  color: var(--math-gold);
}

.help-section.math-highlight {
  border-left-color: var(--math-gold);
  background: rgba(251, 191, 36, 0.08);
}

.help-section.math-highlight h3 {
  color: var(--math-gold);
}

/* --- Estilos API Key BYOP (Groq) --- */
.api-key-container {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  padding: 1.25rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.api-key-container label {
  font-weight: 600;
  color: var(--accent-primary);
  flex-basis: 100%;
  font-size: 0.95rem;
}

.api-key-container input {
  flex-grow: 1;
  padding: 0.7rem 1rem;
  font-size: 0.95rem;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-family: 'Space Grotesk', sans-serif;
  outline: none;
  min-width: 200px;
  transition: all 0.3s ease;
}

.api-key-container input:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.api-key-container button {
  padding: 0.7rem 1.25rem;
  font-size: 0.9rem;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--accent-primary);
  border-radius: 8px;
  cursor: pointer;
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 500;
  transition: all 0.3s ease;
  white-space: nowrap;
}

.api-key-container button:hover {
  background: var(--accent-primary);
  color: white;
  box-shadow: 0 0 20px var(--accent-glow);
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 2rem;
  flex: 1;
  width: 100%;
}

.config-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.config-title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 1.25rem;
  color: var(--accent-primary);
}

.config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.control-group label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.control-group select,
.control-group input[type='number'],
.control-group input[type='text'] {
  padding: 0.7rem 0.9rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.95rem;
  transition: all 0.3s ease;
}

.control-group select:focus,
.control-group input:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.checkbox-group {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.75rem 1rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  user-select: none;
}

.checkbox-group:hover {
  border-color: var(--accent-primary);
}

.checkbox-group input[type='checkbox'] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--accent-primary);
}

.checkbox-group span {
  font-size: 0.9rem;
}

.pdf-upload-area {
  margin-top: 1rem;
  padding: 1.25rem;
  background: var(--bg-tertiary);
  border: 2px dashed var(--border-color);
  border-radius: 10px;
  text-align: center;
  transition: all 0.3s ease;
}

.pdf-upload-area.drag-over {
  border-color: var(--accent-primary);
  background: rgba(6, 182, 212, 0.05);
}

.pdf-upload-btn {
  padding: 0.7rem 1.25rem;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  cursor: pointer;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.9rem;
  transition: all 0.3s ease;
}

.pdf-upload-btn:hover {
  border-color: var(--accent-primary);
}

.pdf-info {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 0.5rem;
}

.pdf-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
  justify-content: center;
}

.pdf-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.8rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  font-size: 0.85rem;
}

.pdf-remove {
  background: none;
  border: none;
  color: var(--danger-color);
  cursor: pointer;
  padding: 0;
  font-size: 1rem;
  line-height: 1;
}

.main-grid {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 1.5rem;
}

.chat-container {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  height: 600px;
}

.chat-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.chat-header h2 {
  font-size: 1.15rem;
  background: var(--gradient-math);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.message {
  display: flex;
  gap: 0.75rem;
  max-width: 100%;
}

.message-avatar {
  width: 36px;
  height: 36px;
  background: var(--bg-tertiary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.user-message .message-avatar {
  background: var(--gradient-math);
}

.message-content {
  background: var(--bg-tertiary);
  padding: 0.9rem 1.1rem;
  border-radius: 12px;
  flex: 1;
  font-size: 0.95rem;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.user-message .message-content {
  background: rgba(6, 182, 212, 0.1);
  border: 1px solid var(--border-glow);
}

.copy-btn {
  margin-top: 0.6rem;
  padding: 0.3rem 0.7rem;
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.78rem;
  font-family: 'Space Grotesk', sans-serif;
}

.copy-btn:hover {
  color: var(--accent-primary);
  border-color: var(--accent-primary);
}

.chat-input {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border-color);
}

.input-container {
  display: flex;
  gap: 0.75rem;
}

.input-container textarea {
  flex: 1;
  padding: 0.9rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  color: var(--text-primary);
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.95rem;
  resize: none;
  min-height: 56px;
  transition: all 0.3s ease;
}

.input-container textarea:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.send-btn {
  padding: 0.9rem 1.5rem;
  background: var(--gradient-math);
  color: white;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  font-family: 'Space Grotesk', sans-serif;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
}

.send-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 4px 20px var(--accent-glow);
}
.send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.action-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1.25rem;
}

.action-btn {
  width: 100%;
  padding: 0.9rem;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.92rem;
  font-family: 'Space Grotesk', sans-serif;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.download-btn {
  background: linear-gradient(135deg, var(--math-gold), #f59e0b);
  color: var(--bg-primary);
  margin-bottom: 0.75rem;
}

.download-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(251, 191, 36, 0.3);
}
.download-btn:disabled {
  background: var(--bg-tertiary);
  color: var(--text-muted);
  cursor: not-allowed;
}

.preview-btn {
  background: linear-gradient(135deg, var(--success-color), #059669);
  color: white;
  margin-bottom: 0.75rem;
}
.preview-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(16, 185, 129, 0.3);
}
.preview-btn:disabled {
  background: var(--bg-tertiary);
  color: var(--text-muted);
  cursor: not-allowed;
}

.clear-btn {
  background: transparent;
  color: var(--danger-color);
  border: 1px solid var(--danger-color);
}
.clear-btn:hover:not(:disabled) {
  background: var(--danger-color);
  color: white;
}
.clear-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.counter-card {
  text-align: center;
  padding: 1.75rem 1.25rem;
}

.counter-number {
  font-size: 3rem;
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
  background: var(--gradient-math);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1;
  margin-bottom: 0.4rem;
}

.counter-label {
  color: var(--text-secondary);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.stats-card {
  padding: 1rem 1.25rem;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0;
  border-bottom: 1px solid rgba(51, 65, 85, 0.5);
}

.stat-row:last-child {
  border-bottom: none;
}
.stat-label {
  color: var(--text-muted);
  font-size: 0.82rem;
}
.stat-value {
  color: var(--text-primary);
  font-weight: 600;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.9rem;
}

footer {
  text-align: center;
  padding: 1.75rem;
  color: var(--text-muted);
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  font-size: 0.88rem;
}
footer p {
  line-height: 1.8;
}

@media (max-width: 1024px) {
  .main-grid {
    grid-template-columns: 1fr;
  }
  .sidebar {
    flex-direction: row;
    flex-wrap: wrap;
  }
  .sidebar > * {
    flex: 1;
    min-width: 200px;
  }
}

@media (max-width: 768px) {
  .container {
    padding: 1rem;
  }
  .header-content {
    flex-direction: column;
    gap: 1rem;
    text-align: center;
  }
  .header::before {
    display: none;
  }
  .config-grid {
    grid-template-columns: 1fr;
  }
  .chat-container {
    height: 480px;
  }
  .header-left {
    flex-direction: column;
  }
}
