/* Variables y tokens corporativos */
:root,
[data-theme="dark"] {
  --font-main: 'Inter', system-ui, -apple-system, sans-serif;
  --font-heading: 'Outfit', 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Tema oscuro por defecto */
  --bg-page: #0b0f17;
  --bg-card: #131b26;
  --bg-card-header: #1a2433;
  --bg-input: #0c131d;
  --bg-hover: #1f2c3f;
  --border-color: #243247;
  --border-focus: #3b82f6;

  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  --primary-color: #3b82f6;
  --primary-hover: #2563eb;
  --primary-light: rgba(59, 130, 246, 0.15);

  --accent-orange: #f97316;
  --accent-orange-hover: #ea580c;
  --accent-green: #10b981;
  --accent-red: #ef4444;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-card: 0 4px 20px rgba(0, 0, 0, 0.35);
}

[data-theme="light"] {
  --bg-page: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-header: #f1f5f9;
  --bg-input: #ffffff;
  --bg-hover: #e2e8f0;
  --border-color: #cbd5e1;
  --border-focus: #2563eb;

  --text-main: #0f172a;
  --text-muted: #475569;
  --text-dim: #64748b;

  --primary-color: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: rgba(37, 99, 235, 0.1);

  --accent-orange: #ea580c;
  --accent-orange-hover: #c2410c;
  --accent-green: #059669;
  --accent-red: #dc2626;

  --shadow-card: 0 4px 20px rgba(0, 0, 0, 0.08);
}

/* Reset y layout base */
*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-page);
  color: var(--text-main);
  font-family: var(--font-main);
  line-height: 1.5;
  overflow-x: clip;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3, h4, h5, h6,
.brand-title,
.card-section-title,
.subsection-title,
.seo-feature-title,
.faq-accordion-header {
  font-family: var(--font-heading);
}

code, pre, .mono, .highlight-val, .vert-num, .vert-prime {
  font-family: var(--font-mono);
}

/* Contenedor principal */
.tool-layout {
  max-width: 1200px;
  margin: 1.5rem auto 3rem;
  padding: 0 1rem;
  box-sizing: border-box;
  flex: 1 0 auto;
  width: 100%;
}

.tool-with-sidebar {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
  width: 100%;
}

.tool-main-content {
  flex: 1 1 0%;
  min-width: 0;
  width: 100%;
}

/* Pestañas */
.mcm-tabs-nav {
  display: flex;
  gap: 0.5rem;
  border-bottom: 2px solid var(--border-color);
  margin-bottom: 1.5rem;
  overflow-x: auto;
  padding-bottom: 2px;
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.tab-btn:hover {
  color: var(--text-main);
  background: var(--bg-hover);
}

.tab-btn.active {
  color: var(--primary-color);
  border-bottom-color: var(--primary-color);
  background: var(--primary-light);
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
}

/* Tarjeta principal */
.mcm-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-card);
  margin-bottom: 2rem;
}

.card-header-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.25rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--border-color);
}

.card-section-title {
  margin: 0 0 0.25rem 0;
  font-size: 1.2rem;
  color: var(--text-main);
}

.card-section-subtitle {
  margin: 0;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.select-count,
select {
  appearance: none;
  -webkit-appearance: none;
  background-color: var(--bg-input);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.65rem center;
  background-size: 14px 14px;
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.45rem 1.8rem 0.45rem 0.8rem;
  font-size: 0.9rem;
  cursor: pointer;
  color-scheme: dark light;
}

select option,
select optgroup {
  background-color: var(--bg-card);
  color: var(--text-main);
}

/* Entradas de números */
.numbers-inputs-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1rem;
}

.num-input-box {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.num-input-box label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.input-mcm-num {
  width: 110px;
  height: 42px;
  background: var(--bg-input);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.75rem;
  font-family: var(--font-mono);
  font-size: 1.05rem;
  text-align: center;
}

.input-mcm-num:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px var(--primary-light);
}

/* Presets */
.presets-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.presets-label {
  font-size: 0.82rem;
  color: var(--text-dim);
  font-weight: 600;
}

.btn-preset-chip {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 0.8rem;
  padding: 0.35rem 0.65rem;
  border-radius: 9999px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-preset-chip:hover {
  background: var(--primary-light);
  color: var(--primary-color);
  border-color: var(--primary-color);
}

.btn-icon-subtle {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  cursor: pointer;
  margin-left: auto;
  transition: all 0.15s ease;
}

.btn-icon-subtle:hover {
  color: var(--accent-red);
  border-color: var(--accent-red);
}

/* Botón principal */
.action-bar-center {
  display: flex;
  justify-content: center;
  margin: 1.5rem 0;
}

.btn-action-primary {
  background: var(--accent-orange);
  color: #000000;
  font-weight: 700;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.8rem 1.6rem;
  font-size: 0.95rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: background-color 0.15s ease, transform 0.1s ease;
}

.btn-action-primary:hover {
  background: var(--accent-orange-hover);
  color: #000000;
}

.btn-action-primary svg {
  stroke: #000000;
}

/* Sección de resultados */
.result-section {
  background: var(--bg-card-header);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  margin-top: 1.5rem;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Tarjetas destacadas MCM / MCD */
.mcm-kpi-highlight-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

@media (min-width: 600px) {
  .mcm-kpi-highlight-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.mcm-highlight-card {
  border-radius: var(--radius-md);
  padding: 1.25rem;
  text-align: center;
}

.card-mcm {
  background: rgba(59, 130, 246, 0.15);
  border: 2px solid var(--primary-color);
}

.card-mcd {
  background: rgba(16, 185, 129, 0.15);
  border: 2px solid var(--accent-green);
}

.highlight-label {
  font-size: 0.95rem;
  font-weight: 700;
  text-transform: uppercase;
  margin-bottom: 0.4rem;
}

.card-mcm .highlight-label { color: var(--primary-color); }
.card-mcd .highlight-label { color: var(--accent-green); }

.highlight-val {
  font-size: 2.4rem;
  font-weight: 800;
  line-height: 1.2;
  margin-bottom: 0.35rem;
  word-break: break-all;
}

.card-mcm .highlight-val { color: var(--primary-color); }
.card-mcd .highlight-val { color: var(--accent-green); }

.highlight-desc {
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* Potencias de primos */
.powers-summary-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  line-height: 1.8;
  font-size: 1.05rem;
}

.power-line {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}

.power-num {
  font-family: var(--font-heading);
  font-weight: 700;
  color: var(--primary-color);
}

.power-factors {
  font-family: var(--font-mono);
  color: var(--text-main);
}

/* Tablas verticales escolares */
.vertical-tables-container {
  margin-bottom: 1.5rem;
}

.subsection-title {
  font-size: 1.1rem;
  color: var(--text-main);
  margin: 0 0 1rem 0;
}

.vertical-tables-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
}

.vertical-factor-box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
}

.vert-table-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.vert-table {
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 1.1rem;
}

.vert-table td {
  padding: 0.25rem 0.65rem;
}

.vert-table td.vert-num {
  text-align: right;
  border-right: 2px solid var(--primary-color);
  font-weight: 600;
  color: var(--text-main);
}

.vert-table td.vert-prime {
  text-align: left;
  font-weight: 700;
  color: var(--accent-orange);
}

/* Algoritmo de Euclides */
.euclid-container {
  margin-bottom: 1.5rem;
}

.euclid-table-wrapper {
  overflow-x: auto;
}

.euclid-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
  text-align: center;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
}

.euclid-table th,
.euclid-table td {
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border-color);
}

.euclid-table th {
  background: var(--bg-input);
  color: var(--text-main);
  font-family: var(--font-heading);
}

/* Divisores */
.divisors-container {
  margin-bottom: 1rem;
}

.divisors-chips-grid {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.divisors-row {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
  font-size: 0.9rem;
}

.divisors-title {
  font-weight: 700;
  color: var(--primary-color);
  margin-bottom: 0.35rem;
}

/* ==========================================
   PESTAÑA FRACCIONES: ESTILOS
   ========================================== */
.fraction-expression-box {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  margin-bottom: 1.25rem;
  overflow-x: auto;
}

.fraction-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.frac-mixed-input {
  width: 44px;
  height: 38px;
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  text-align: center;
  font-family: var(--font-mono);
  font-size: 0.95rem;
}

.fraction-stacked {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.frac-input {
  width: 54px;
  height: 34px;
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  text-align: center;
  font-family: var(--font-mono);
  font-size: 0.95rem;
}

.fraction-bar {
  width: 100%;
  height: 2px;
  background: var(--text-muted);
}

.operator-select {
  background: var(--bg-card);
  color: var(--primary-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 1.2rem;
  font-weight: 800;
  height: 38px;
  padding: 0 0.5rem;
  cursor: pointer;
}

/* Tarjeta resultado de fracciones */
.frac-final-card {
  background: var(--bg-card);
  border: 2px solid var(--primary-color);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  text-align: center;
  margin-bottom: 1.5rem;
}

.frac-final-label {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 0.6rem;
}

.frac-final-display {
  display: inline-flex;
  align-items: center;
  font-size: 2rem;
  font-weight: 800;
  color: var(--primary-color);
  gap: 0.5rem;
}

.frac-v-view {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: middle;
  line-height: 1.1;
}

.frac-v-num, .frac-v-den {
  font-family: var(--font-mono);
  font-size: 1.7rem;
}

.frac-v-line {
  width: 100%;
  height: 2px;
  background: currentColor;
  margin: 3px 0;
}

.frac-final-decimal {
  font-size: 1rem;
  color: var(--text-dim);
  font-family: var(--font-mono);
  margin-top: 0.5rem;
}

/* Pasos detallados */
.frac-steps-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
}

.frac-step-row {
  margin-bottom: 1.25rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px dashed var(--border-color);
  line-height: 1.6;
}

.frac-step-row:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.frac-step-title {
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 0.35rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.step-badge {
  background: var(--primary-light);
  color: var(--primary-color);
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.8rem;
}

/* Guía didáctica y FAQ */
.seo-guide-section {
  margin-top: 2.5rem;
  margin-bottom: 2.5rem;
}

.seo-feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.25rem;
  margin-bottom: 2rem;
}

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

.seo-feature-title {
  margin: 0 0 0.5rem 0;
  font-size: 1.05rem;
  color: var(--text-main);
}

.seo-feature-text {
  margin: 0;
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.faq-accordion-block {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
}

.faq-accordion-header {
  margin: 0 0 1.25rem 0;
  font-size: 1.2rem;
  color: var(--text-main);
}

.faq-item {
  border-bottom: 1px solid var(--border-color);
  padding: 0.85rem 0;
}

.faq-item:last-child {
  border-bottom: none;
}

.faq-question {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-main);
  list-style: none;
}

.faq-question::-webkit-details-marker {
  display: none;
}

.faq-chevron {
  transition: transform 0.2s ease;
  color: var(--text-muted);
  flex-shrink: 0;
}

.faq-item[open] .faq-chevron {
  transform: rotate(180deg);
}

.faq-answer {
  padding-top: 0.65rem;
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.55;
}

.faq-answer p {
  margin: 0;
}

/* Alertas */
.mcm-alert {
  padding: 0.85rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.mcm-alert-error {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid var(--accent-red);
  color: #fca5a5;
}

[data-theme="light"] .mcm-alert-error {
  background: #fee2e2;
  border-color: #ef4444;
  color: #991b1b;
}

/* Responsive */
@media (max-width: 768px) {
  .tool-layout {
    padding: 0 0.75rem;
    margin: 1rem auto 2rem;
  }

  .btn-action-primary {
    width: 100%;
    min-height: 44px;
  }

  .fraction-expression-box {
    padding: 1rem;
  }
}
