:root {
  --bg-main: #0b0f19;
  --bg-panel: #111827;
  --bg-card: #1e293b;
  --bg-hover: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --gold: #fbbf24;
  --gold-hover: #f59e0b;
  --gold-alpha: rgba(251, 191, 36, 0.18);
  --border-color: rgba(255, 255, 255, 0.15);
  --burgundy: #9f1239;
  --burgundy-hover: #881337;
}

body {
  background: var(--bg-main);
  color: var(--text-main);
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
  margin: 0;
  padding-top: 65px;
  -webkit-font-smoothing: antialiased;
}

.font-gold { 
  color: var(--gold) !important; 
}

/* ==========================================
   ESTRUCTURA PRINCIPAL Y CONTENEDORES
   ========================================== */
.social-wrapper {
  margin-left: 230px;
  padding: 20px 15px;
  min-height: calc(100vh - 65px);
  display: flex;
  justify-content: center;
}

@media (max-width: 768px) {
  .social-wrapper { 
    margin-left: 0; 
    padding: 10px 6px; 
  }
}

.social-card-main {
  width: 100%;
  max-width: 820px;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.45);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* TOPBAR Y NAVEGACIÓN */
.social-topbar {
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  background: #070a12;
}

.social-brand { 
  display: flex; 
  align-items: center; 
  gap: 10px; 
}

.social-brand i { 
  font-size: 1.7rem; 
}

.social-brand h2 { 
  font-size: 1.25rem; 
  font-weight: 800; 
  margin: 0; 
  color: #fff; 
}

.sub-brand { 
  font-size: 0.65rem; 
  font-weight: 800; 
  letter-spacing: 0.12em; 
  color: var(--gold); 
}

.social-subnav {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: rgba(0, 0, 0, 0.35);
  border-bottom: 1px solid var(--border-color);
  padding: 6px 10px;
  gap: 6px;
}

.social-tab-btn {
  background: transparent;
  border: 1px solid transparent;
  padding: 9px 4px;
  border-radius: 12px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  transition: all 0.2s;
}

.social-tab-btn.active {
  background: var(--gold-alpha);
  color: var(--gold);
  font-weight: 800;
  border-color: rgba(251, 191, 36, 0.5);
}

.social-tab-btn span { 
  font-size: 0.8rem; 
}

.badge-prox { 
  background: #38bdf8; 
  color: #000; 
  font-size: 8px; 
  font-weight: 800; 
  padding: 1px 6px; 
  border-radius: 8px; 
  text-transform: uppercase; 
}

.social-tab-contents { 
  padding: 20px; 
  flex: 1; 
}

.tab-pane { 
  display: none; 
}

.tab-pane.active { 
  display: block; 
}

/* ==========================================
   PERFIL ACADÉMICO PROFESIONAL MEJORADO
   ========================================== */
.social-profile-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.4);
  margin-top: 5px;
  display: flex;
  flex-direction: column;
}

.profile-header-banner {
  height: 140px;
  background: linear-gradient(135deg, #1e293b, #f59e0b);
  position: relative;
  background-size: cover;
  background-position: center;
}

.profile-avatar-wrapper {
  margin-top: -55px;
  text-align: center;
  position: relative;
  z-index: 3;
}

.profile-avatar-wrapper img {
  width: 106px;
  height: 106px;
  border-radius: 50%;
  border: 4px solid var(--bg-card);
  object-fit: cover;
  background: var(--bg-main);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.6);
}

.profile-details {
  text-align: center;
  padding: 8px 20px 16px;
}

.profile-details h3 {
  margin: 6px 0 4px;
  font-size: 1.4rem;
  color: var(--text-main);
  font-weight: 800;
  letter-spacing: -0.01em;
}

.role-badge {
  display: inline-block;
  padding: 3px 12px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 800;
  background: rgba(245, 158, 11, 0.15);
  color: var(--gold);
  border: 1px solid rgba(245, 158, 11, 0.35);
  text-transform: uppercase;
  margin-bottom: 4px;
}

.profile-followers-inline {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.88rem;
  color: var(--text-muted);
  margin: 4px 0 8px;
}

.profile-followers-inline strong {
  color: var(--gold);
}

.user-email-text {
  color: var(--text-muted);
  font-size: 0.86rem;
  margin: 2px 0 12px;
}

.btn-edit-profile-mini {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 7px 16px;
  border-radius: 10px;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0 auto;
}

.btn-edit-profile-mini:hover {
  background: var(--gold-alpha);
  color: var(--gold);
  border-color: var(--gold);
  transform: translateY(-1px);
}

.profile-optional-info {
  padding: 14px 24px;
  display: grid;
  gap: 10px;
  font-size: 0.88rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);
  background: rgba(0, 0, 0, 0.1);
}

.info-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.info-row strong { 
  color: var(--text-main); 
}

/* ESTADÍSTICAS EN 3 COLUMNAS HORIZONTALES FIJAS */
.profile-stats-grid {
  display: grid !important;
  grid-template-columns: repeat(3, 1fr) !important;
  gap: 12px;
  padding: 18px;
  background: rgba(0, 0, 0, 0.25);
}

.stat-box {
  text-align: center;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  padding: 14px 8px;
  border-radius: 14px;
  transition: all 0.2s ease;
}

.stat-box:hover {
  border-color: rgba(251, 191, 36, 0.4);
  background: rgba(251, 191, 36, 0.04);
}

.stat-box i {
  font-size: 1.2rem;
  margin-bottom: 6px;
  display: block;
}

.stat-box h4 {
  font-size: 1.35rem;
  margin: 0 0 2px;
  color: var(--text-main);
  font-weight: 800;
}

.stat-box span {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* ==========================================
   FORMULARIO Y EDITOR DE TEXTO ENRIQUECIDO
   ========================================== */
.questions-header-text h2 { 
  font-size: 1.5rem; 
  font-weight: 800; 
  margin: 0 0 4px; 
  color: #fff; 
}

.questions-header-text p { 
  color: var(--text-muted); 
  font-size: 0.88rem; 
  margin: 0 0 16px; 
}

.search-bar-box {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 10px 14px;
  margin-bottom: 18px;
}

.search-bar-box i { 
  color: var(--gold); 
}

.search-bar-box input { 
  width: 100%; 
  background: transparent; 
  border: none; 
  color: #fff; 
  font-size: 0.9rem; 
  outline: none; 
}

.btn-primary-publish {
  width: 100%;
  background: var(--burgundy);
  color: #fff;
  border: none;
  padding: 14px;
  border-radius: 12px;
  font-size: 1.02rem;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: all 0.2s;
  margin-bottom: 20px;
  box-shadow: 0 4px 15px rgba(159, 18, 57, 0.4);
}

.btn-primary-publish:hover { 
  background: var(--burgundy-hover); 
  transform: translateY(-1px); 
}

.ask-form-accordion {
  background: var(--bg-card);
  border: 1.5px solid var(--gold);
  border-radius: 14px;
  padding: 18px;
  margin-bottom: 20px;
}

.ask-form-title { 
  margin: 0 0 12px; 
  font-size: 1.05rem; 
  color: var(--gold); 
  font-weight: 800; 
}

.ask-form-inner { 
  display: flex; 
  flex-direction: column; 
  gap: 12px; 
}

.form-row { 
  display: grid; 
  grid-template-columns: 180px 1fr; 
  gap: 10px; 
}

@media (max-width: 600px) { 
  .form-row { 
    grid-template-columns: 1fr; 
  } 
}

.social-input {
  width: 100%;
  background: var(--bg-main);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 10px 12px;
  color: #fff;
  font-size: 0.9rem;
  outline: none;
  box-sizing: border-box;
}

.social-input:focus { 
  border-color: var(--gold); 
}

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  background: #0f172a;
  border: 1px solid var(--border-color);
  border-bottom: none;
  border-radius: 10px 10px 0 0;
  padding: 6px 10px;
  flex-wrap: wrap;
}

.tool-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.88rem;
  transition: all 0.15s ease;
}

.tool-btn:hover { 
  background: rgba(255, 255, 255, 0.1); 
  color: var(--gold); 
}

.tool-separator { 
  width: 1px; 
  height: 20px; 
  background: var(--border-color); 
  margin: 0 4px; 
}

.btn-open-calc, 
.btn-open-formula { 
  width: auto !important; 
  padding: 0 12px !important; 
  gap: 6px; 
  font-weight: 700; 
  color: var(--gold) !important; 
  background: rgba(251, 191, 36, 0.12) !important; 
  border: 1px solid var(--gold) !important; 
}

.btn-open-calc:hover,
.btn-open-formula:hover {
  background: var(--gold) !important;
  color: #000 !important;
}

.rich-editor-box {
  min-height: 110px;
  max-height: 320px;
  background: var(--bg-main);
  border: 1px solid var(--border-color);
  border-radius: 0 0 10px 10px;
  padding: 12px;
  color: var(--text-main);
  font-size: 0.95rem;
  outline: none;
  line-height: 1.6;
  overflow-y: auto;
  word-break: break-word;
}

.rich-editor-box:focus { 
  border-color: var(--gold); 
}

/* ==========================================
   MATHJAX RENDERIZADO
   ========================================== */
mjx-container {
  color: inherit !important;
  outline: none !important;
  vertical-align: middle !important;
  margin: 0 3px !important;
  display: inline-block !important;
}

mjx-container[jax="CHTML"][display="true"],
mjx-container[jax="SVG"][display="true"] {
  display: block !important;
  margin: 10px auto !important;
  text-align: center;
}

/* ==========================================
   FEED DE PREGUNTAS Y TARJETAS
   ========================================== */
.feed-section-header h3 { 
  font-size: 1.1rem; 
  margin: 0 0 10px; 
  color: #fff; 
}

.materia-filters { 
  display: flex; 
  gap: 8px; 
  overflow-x: auto; 
  margin-bottom: 16px; 
  padding-bottom: 4px;
}

.filter-chip {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 6px 14px;
  border-radius: 18px;
  font-size: 0.82rem;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.filter-chip.active { 
  background: var(--gold) !important; 
  color: #000 !important; 
  font-weight: 800; 
}

.questions-feed { 
  display: flex; 
  flex-direction: column; 
  gap: 16px; 
}

.question-card { 
  background: var(--bg-card); 
  border: 1px solid var(--border-color); 
  border-radius: 14px; 
  padding: 18px; 
}

.q-top-info { 
  display: flex; 
  justify-content: space-between; 
  align-items: center; 
  margin-bottom: 10px; 
}

.q-tag-subject { 
  background: var(--gold-alpha); 
  color: var(--gold); 
  padding: 3px 10px; 
  border-radius: 6px; 
  font-size: 0.78rem; 
  font-weight: 800; 
}

.q-reward-pill { 
  background: rgba(34, 197, 94, 0.15); 
  color: #22c55e; 
  padding: 2px 8px; 
  border-radius: 6px; 
  font-size: 0.75rem; 
  font-weight: 800; 
}

.q-title { 
  font-size: 1.1rem; 
  font-weight: 800; 
  margin: 0 0 8px; 
  color: #fff; 
}

.q-content { 
  font-size: 0.94rem; 
  color: #cbd5e1; 
  margin-bottom: 14px; 
  line-height: 1.6; 
}

.q-author-line {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.84rem;
  color: var(--text-muted);
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.clickable-user-link { 
  color: var(--gold); 
  text-decoration: underline; 
  cursor: pointer; 
  font-weight: 700; 
}

.btn-follow-mini {
  background: rgba(251, 191, 36, 0.15);
  border: 1px solid var(--gold);
  color: var(--gold);
  padding: 3px 10px;
  border-radius: 8px;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-follow-mini:hover, 
.btn-follow-mini.following { 
  background: var(--gold); 
  color: #000; 
}

.q-actions-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid var(--border-color);
  padding-top: 12px;
}

.q-action-left { 
  display: flex; 
  gap: 12px; 
  align-items: center; 
}

.btn-action-icon {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.88rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 8px;
}

.btn-action-icon:hover { 
  background: rgba(255, 255, 255, 0.08); 
  color: #fff; 
}

.btn-action-icon.liked { 
  color: #ef4444; 
}

.answers-container {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed var(--border-color);
}

.answer-box-single {
  background: rgba(0, 0, 0, 0.25);
  border-left: 3px solid var(--gold);
  padding: 12px 14px;
  border-radius: 8px;
  margin-bottom: 10px;
}

.answer-box-single.verified { 
  border-left-color: #22c55e; 
  background: rgba(34, 197, 94, 0.06); 
}

.ans-author { 
  font-size: 0.82rem; 
  font-weight: 800; 
  margin-bottom: 6px; 
  color: #fff; 
  display: flex; 
  justify-content: space-between; 
}

.ans-text { 
  font-size: 0.9rem; 
  color: #cbd5e1; 
  line-height: 1.5; 
}

.answer-editor-wrapper { 
  margin-top: 12px; 
  display: flex; 
  flex-direction: column; 
  gap: 8px; 
}

/* ==========================================
   MODAL DE EDITOR DE ECUACIONES
   ========================================== */
.social-modal-profile {
  width: min(640px, 95vw);
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  color: var(--text-main);
  padding: 20px;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.8);
}

.social-modal-profile::backdrop {
  background: rgba(2, 6, 23, 0.85);
  backdrop-filter: blur(4px);
}

.modal-profile-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 10px;
}

.modal-profile-header h3 {
  margin: 0;
  color: var(--gold);
  font-size: 1.15rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.equation-toolbar-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  background: rgba(0, 0, 0, 0.35);
  padding: 6px;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  margin-bottom: 12px;
}

.eq-tab-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.eq-tab-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.05);
}

.eq-tab-btn.active {
  background: var(--gold-alpha);
  color: var(--gold);
  border-color: rgba(251, 191, 36, 0.4);
  font-weight: 700;
}

.eq-pane {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 180px;
  overflow-y: auto;
  padding: 4px;
  margin-bottom: 12px;
}

.formula-preset-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 65px;
  font-size: 0.85rem;
  transition: all 0.2s ease;
}

.formula-preset-btn:hover {
  border-color: var(--gold);
  background: var(--bg-hover);
  color: var(--gold);
  transform: translateY(-2px);
}

#formulaPreviewDisplay {
  background: rgba(0, 0, 0, 0.3);
  border: 1px dashed var(--gold);
  border-radius: 12px;
  padding: 16px;
  text-align: center;
  min-height: 65px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px;
  overflow-x: auto;
}

/* ==========================================
   MODO CLARO (body.light)/* ==========================================
   MODO CLARO (body.light) - CORREGIDO Y PULIDO
   ========================================== */
body.light {
  background: #f1f5f9;
  color: #0f172a;
}

body.light .social-topbar {
  background: #ffffff;
  border-bottom-color: #cbd5e1;
}

body.light .social-brand h2,
body.light .questions-header-text h2,
body.light .q-title,
body.light .feed-section-header h3,
body.light .ask-form-title,
body.light .ans-author,
body.light .profile-details h3,
body.light .info-row strong {
  color: #0f172a !important;
}

body.light .social-subnav {
  background: #e2e8f0;
  border-bottom-color: #cbd5e1;
}

body.light .social-tab-btn {
  color: #475569;
}

body.light .social-tab-btn.active {
  background: rgba(245, 158, 11, 0.2);
  color: #b45309;
  border-color: #f59e0b;
}

body.light .social-card-main,
body.light .social-profile-card,
body.light .question-card,
body.light .social-modal-profile,
body.light .ask-form-accordion {
  background: #ffffff;
  border-color: #cbd5e1;
  color: #0f172a;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.06);
}

body.light .search-bar-box,
body.light .social-input,
body.light .rich-editor-box {
  background: #f8fafc;
  color: #0f172a;
  border-color: #cbd5e1;
}

body.light .editor-toolbar {
  background: #e2e8f0;
  border-color: #cbd5e1;
}

body.light .tool-btn {
  color: #475569;
}

body.light .tool-btn:hover {
  background: #cbd5e1;
  color: #0f172a;
}

/* CORRECCIÓN DE CONTRASTE EN EL PERFIL (MODO CLARO) */
body.light .profile-optional-info {
  background: #f8fafc;
  color: #334155 !important;
  border-color: #cbd5e1;
}

body.light .profile-followers-inline {
  color: #475569 !important;
}

body.light .profile-followers-inline strong {
  color: #b45309 !important;
}

body.light .user-email-text {
  color: #475569 !important;
}

body.light .role-badge {
  background: rgba(245, 158, 11, 0.15);
  color: #b45309 !important;
  border-color: rgba(245, 158, 11, 0.4);
}

body.light .profile-stats-grid {
  background: #f8fafc !important;
  border-top: 1px solid #cbd5e1;
}

body.light .stat-box {
  background: #ffffff !important;
  border-color: #cbd5e1 !important;
}

body.light .stat-box h4 {
  color: #0f172a !important;
}

body.light .stat-box span {
  color: #475569 !important;
}

body.light .stat-box i {
  color: #b45309 !important;
}

body.light .equation-toolbar-tabs {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

body.light .formula-preset-btn {
  background: #f8fafc;
  border-color: #cbd5e1;
  color: #0f172a;
}

body.light #formulaPreviewDisplay {
  background: #f8fafc;
  border-color: #f59e0b;
}

body.light mjx-container {
  color: #0f172a !important;
}

/* ==========================================
   MEJORAS VISUALES: MODAL DE ECUACIONES (EDITOR)
   ========================================== */

#formulaModal {
  border: none !important;
  background: var(--bg-panel) !important;
  color: var(--text-main) !important;
  padding: 24px !important;
  border-radius: 24px !important;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.7) !important;
  max-width: 680px !important;
  width: 95vw !important;
}

#formulaModal::backdrop {
  background: rgba(3, 7, 18, 0.8) !important;
  backdrop-filter: blur(5px);
}

/* Pestañas superiores del editor */
#formulaModal .equation-toolbar-tabs {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border-color);
  padding: 6px;
  border-radius: 14px;
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
}

#formulaModal .eq-tab-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 8px 16px;
  border-radius: 10px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  flex: 1;
  text-align: center;
}

#formulaModal .eq-tab-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.05);
}

#formulaModal .eq-tab-btn.active {
  background: var(--gold-alpha);
  color: var(--gold);
  border: 1px solid rgba(251, 191, 36, 0.3);
}

/* Paneles de símbolos y estructuras */
#formulaModal .eq-pane {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 8px;
  max-height: 200px;
  overflow-y: auto;
  padding: 4px;
  margin-bottom: 14px;
}

/* Botones individuales de fórmulas (Presets) */
#formulaModal .formula-preset-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 10px 8px;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 0.8rem;
  font-weight: 600;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  min-height: 48px;
}

#formulaModal .formula-preset-btn:hover {
  border-color: var(--gold);
  background: var(--bg-hover);
  color: var(--gold);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(251, 191, 36, 0.15);
}

/* Ocultar texto LaTeX largo o feo dentro del botón si se ve saturado, manteniendo el título limpio */
#formulaModal .formula-preset-btn span {
  font-size: 0.75rem;
  opacity: 0.8;
}

/* Input de código LaTeX editable */
#formulaInput {
  background: var(--bg-main) !important;
  border: 1px solid var(--border-color) !important;
  color: var(--gold) !important;
  font-family: 'Fira Code', Consolas, monospace !important;
  font-size: 1.05rem !important;
  padding: 12px 16px !important;
  border-radius: 12px !important;
  outline: none !important;
  transition: border-color 0.2s;
}

#formulaInput:focus {
  border-color: var(--gold) !important;
  box-shadow: 0 0 0 3px rgba(251, 191, 36, 0.15);
}

/* Cuadro de previsualización en vivo */
#formulaPreviewDisplay {
  background: rgba(0, 0, 0, 0.35) !important;
  border: 1.5px dashed rgba(251, 191, 36, 0.4) !important;
  border-radius: 14px !important;
  padding: 18px !important;
  min-height: 70px !important;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  font-size: 1.4rem;
  color: #fff;
}

/* Botón de inserción final */
#formulaModal #insertFormulaBtn {
  background: var(--burgundy) !important;
  color: #fff !important;
  border: none !important;
  padding: 14px !important;
  border-radius: 12px !important;
  font-weight: 800 !important;
  font-size: 1rem !important;
  cursor: pointer !important;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 4px 15px rgba(159, 18, 57, 0.4);
  transition: all 0.2s ease;
}

#formulaModal #insertFormulaBtn:hover {
  background: var(--burgundy-hover) !important;
  transform: translateY(-1px);
}


/* ==========================================
   EDITOR DE ECUACIONES - DISEÑO PROFESIONAL
   ========================================== */
#formulaModal {
  border: none !important;
  background: var(--bg-panel) !important;
  color: var(--text-main) !important;
  padding: 24px !important;
  border-radius: 20px !important;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.6) !important;
  max-width: 700px !important;
  width: 95vw !important;
}

#formulaModal::backdrop {
  background: rgba(3, 7, 18, 0.75) !important;
  backdrop-filter: blur(4px);
}

/* Pestañas del modal */
#formulaModal .equation-toolbar-tabs {
  display: flex;
  gap: 6px;
  background: rgba(0, 0, 0, 0.2);
  padding: 6px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  margin-bottom: 14px;
}

#formulaModal .eq-tab-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  flex: 1;
  text-align: center;
  transition: all 0.2s ease;
}

#formulaModal .eq-tab-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.05);
}

#formulaModal .eq-tab-btn.active {
  background: var(--gold-alpha);
  color: var(--gold);
  border: 1px solid rgba(251, 191, 36, 0.3);
}

/* Cuadrícula limpia para los botones de fórmulas */
#formulaModal .eq-pane {
  display: grid !important;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)) !important;
  gap: 8px !important;
  max-height: 210px !important;
  overflow-y: auto !important;
  padding: 4px !important;
  margin-bottom: 16px !important;
}

#formulaModal .formula-preset-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 10px 8px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 0.82rem;
  font-weight: 600;
  transition: all 0.2s ease;
  min-height: 52px;
}

#formulaModal .formula-preset-btn:hover {
  border-color: var(--gold);
  background: var(--bg-hover);
  color: var(--gold);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(251, 191, 36, 0.15);
}

/* Input y previsualización en el modal */
#formulaModal #formulaInput {
  background: var(--bg-main) !important;
  border: 1px solid var(--border-color) !important;
  color: var(--gold) !important;
  font-family: 'Fira Code', Consolas, monospace !important;
  font-size: 1rem !important;
  padding: 12px !important;
  border-radius: 10px !important;
  outline: none !important;
  width: 100% !important;
  box-sizing: border-box;
}

#formulaModal #formulaInput:focus {
  border-color: var(--gold) !important;
  box-shadow: 0 0 0 3px rgba(251, 191, 36, 0.15);
}

#formulaModal #formulaPreviewDisplay {
  background: rgba(0, 0, 0, 0.3) !important;
  border: 1.5px dashed rgba(251, 191, 36, 0.4) !important;
  border-radius: 12px !important;
  padding: 16px !important;
  min-height: 65px !important;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  font-size: 1.3rem;
  color: #fff;
  overflow-x: auto;
}

/* MODO CLARO ESPECÍFICO PARA EL MODAL */
body.light #formulaModal {
  background: #ffffff !important;
  color: #0f172a !important;
  border: 1px solid #cbd5e1 !important;
}

body.light #formulaModal .equation-toolbar-tabs {
  background: #f1f5f9 !important;
  border-color: #cbd5e1 !important;
}

body.light #formulaModal .eq-tab-btn {
  color: #475569 !important;
}

body.light #formulaModal .eq-tab-btn.active {
  background: rgba(245, 158, 11, 0.15) !important;
  color: #b45309 !important;
  border-color: #f59e0b !important;
}

body.light #formulaModal .formula-preset-btn {
  background: #f8fafc !important;
  border-color: #cbd5e1 !important;
  color: #0f172a !important;
}

body.light #formulaModal .formula-preset-btn:hover {
  background: #f1f5f9 !important;
  border-color: #f59e0b !important;
  color: #b45309 !important;
}

body.light #formulaModal #formulaInput {
  background: #f8fafc !important;
  color: #b45309 !important;
  border-color: #cbd5e1 !important;
}

body.light #formulaModal #formulaPreviewDisplay {
  background: #f8fafc !important;
  border-color: #f59e0b !important;
  color: #0f172a !important;
}
#formulaModal .eq-pane {
  display: none !important;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)) !important;
  gap: 8px !important;
  max-height: 220px !important;
  overflow-y: auto !important;
  padding: 4px !important;
  margin-bottom: 16px !important;
}

#formulaModal .eq-pane.active {
  display: grid !important;
}