/* Editor: paleta lógica + fórmulas KaTeX */

.logic-math-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.65rem 0.75rem;
  background: #f8f7f5;
  border: 1px solid #dddcd8;
  border-bottom: none;
  margin-bottom: 0;
}

.logic-symbols-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  flex: 1;
  min-width: 0;
}

.logic-group {
  position: relative;
}

.logic-group summary {
  list-style: none;
  cursor: pointer;
  font-family: 'Jost', sans-serif;
  font-size: 0.58rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 0.35rem 0.65rem;
  background: #fff;
  border: 1px solid #dddcd8;
  user-select: none;
}

.logic-group summary::-webkit-details-marker { display: none; }

.logic-symbol-grid {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 2px;
  padding: 0.5rem;
  background: #fff;
  border: 1px solid #dddcd8;
  box-shadow: 0 8px 24px rgba(0,0,0,0.08);
  min-width: 220px;
}

.logic-sym-btn {
  font-family: 'STIX Two Math', 'Cambria Math', serif;
  font-size: 1rem;
  line-height: 1;
  padding: 0.45rem 0.35rem;
  border: 1px solid #eee;
  background: #fafafa;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.logic-sym-btn:hover {
  background: #111;
  color: #fff;
  border-color: #111;
}

.logic-formula-btn {
  font-family: 'Jost', sans-serif;
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 0.45rem 0.85rem;
  background: #111;
  color: #fff;
  border: none;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

.logic-formula-btn:hover { background: #333; }

.logic-bar-hint {
  flex: 1 1 100%;
  font-family: 'Jost', sans-serif;
  font-size: 0.68rem;
  color: #999;
  line-height: 1.4;
}

@media (min-width: 700px) {
  .logic-bar-hint {
    flex: 1 1 auto;
    text-align: right;
    align-self: center;
  }
}

/* Quill: fórmulas en el editor */
.ql-editor .math-inline {
  display: inline-block;
  vertical-align: middle;
  margin: 0 0.12em;
  padding: 0 0.15em;
  background: rgba(0,0,0,0.04);
  border-radius: 2px;
  cursor: default;
}

.ql-editor .math-display {
  display: block;
  text-align: center;
  margin: 1rem 0;
  padding: 0.85rem 1rem;
  background: rgba(0,0,0,0.03);
  border-left: none;
}

/* Modal fórmula */
.formula-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(0,0,0,0.45);
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.formula-modal.open { display: flex; }

.formula-modal-box {
  width: 100%;
  max-width: 520px;
  background: #fff;
  padding: 1.5rem;
  max-height: 90vh;
  overflow-y: auto;
}

.formula-modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.formula-modal-head h3 {
  font-family: 'Jost', sans-serif;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.formula-modal-close {
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  color: #888;
}

.formula-modal-hint {
  font-size: 0.78rem;
  color: #666;
  line-height: 1.5;
  margin-bottom: 1rem;
}

.formula-modal-hint code {
  font-size: 0.72rem;
  background: #f0efed;
  padding: 0.1em 0.35em;
}

.formula-mode {
  display: flex;
  gap: 1.25rem;
  margin-bottom: 1rem;
  font-size: 0.82rem;
}

.formula-mode label { cursor: pointer; }

.formula-label {
  display: block;
  font-size: 0.58rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #999;
  margin-bottom: 0.35rem;
}

.formula-select,
.formula-input {
  width: 100%;
  font-family: 'Jost', ui-monospace, monospace;
  font-size: 0.85rem;
  padding: 0.5rem 0.65rem;
  border: 1px solid #dddcd8;
  margin-bottom: 0.85rem;
}

.formula-input { resize: vertical; line-height: 1.5; }

.formula-preview {
  min-height: 3rem;
  padding: 1rem;
  background: #fafaf8;
  border: 1px solid #e8e7e3;
  margin-bottom: 1rem;
  overflow-x: auto;
}

.formula-preview-display {
  text-align: center;
}

.formula-preview-empty {
  font-size: 0.78rem;
  color: #aaa;
}

.formula-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.formula-btn-cancel,
.formula-btn-insert {
  font-family: 'Jost', sans-serif;
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 0.55rem 1rem;
  cursor: pointer;
  border: 1px solid #dddcd8;
  background: #fff;
}

.formula-btn-insert {
  background: #111;
  color: #fff;
  border-color: #111;
}

/* Publicación — estilo paper académico */
.article-body .math-inline {
  font-family: 'STIX Two Math', 'Latin Modern Math', 'Cambria Math', serif;
  white-space: nowrap;
}

.article-body .math-display {
  display: block;
  text-align: center;
  margin: 1.75rem auto;
  padding: 1rem 0.5rem;
  overflow-x: auto;
  position: relative;
  max-width: 100%;
}

.article-body .math-display[data-eq]::after {
  content: '(' attr(data-eq) ')';
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  font-family: 'Jost', sans-serif;
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--gray, #777);
}

.article-body .katex {
  font-size: 1.05em;
}

.article-body .math-display .katex {
  font-size: 1.15em;
}

.article-body .katex-display {
  margin: 0;
}

@media (max-width: 600px) {
  .logic-symbol-grid { grid-template-columns: repeat(4, 1fr); min-width: 160px; }
  .logic-math-bar { flex-direction: column; }
}

@media print {
  .article-body .math-display {
    page-break-inside: avoid;
  }
  .article-body .math-display[data-eq]::after {
    color: #555;
  }
}
