/* 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,
.matrix-title,
.result-title,
.seo-feature-title,
.faq-accordion-header {
  font-family: var(--font-heading);
}

code, pre, .mono, .matrix-cell-input, .math-matrix {
  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%;
}

/* Barra de pestañas principal */
.matrix-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);
}

/* Opciones globales */
.options-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  background: var(--bg-card);
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  margin-bottom: 1.5rem;
}

.options-group {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
}

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

.btn-toggle-group {
  display: inline-flex;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.btn-toggle {
  padding: 0.4rem 0.85rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-toggle.active {
  background: var(--primary-color);
  color: #ffffff;
}

.decimals-selector select,
.dim-controls select,
.system-dim-select select,
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.55rem center;
  background-size: 14px 14px;
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.35rem 1.8rem 0.35rem 0.6rem;
  font-size: 0.85rem;
  cursor: pointer;
  color-scheme: dark light;
}

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

.example-buttons-container {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.btn-example-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-example-chip:hover {
  background: var(--primary-light);
  color: var(--primary-color);
  border-color: var(--primary-color);
}

/* Tarjeta contenedora de matriz */
.matrix-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;
}

.tab-pane {
  display: none;
}

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

/* Rejilla de configuración de matrices A y B */
.matrices-setup-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.matrix-block {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
}

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

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

.dim-controls {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.btn-icon-subtle {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 0.35rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

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

/* Brackets de matriz visual */
.matrix-bracket-wrapper {
  position: relative;
  display: inline-flex;
  justify-content: center;
  margin: 0.5rem auto;
  padding: 0 0.85rem;
  max-width: 100%;
  overflow-x: auto;
}

.matrix-bracket-wrapper::before,
.matrix-bracket-wrapper::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 8px;
  border: 2px solid var(--border-focus);
}

.matrix-bracket-wrapper::before {
  left: 0;
  border-right: none;
  border-radius: 4px 0 0 4px;
}

.matrix-bracket-wrapper::after {
  right: 0;
  border-left: none;
  border-radius: 0 4px 4px 0;
}

.matrix-grid {
  display: grid;
  gap: 0.4rem;
  padding: 0.5rem 0.25rem;
}

.matrix-cell-input {
  width: 58px;
  height: 40px;
  text-align: center;
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 500;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

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

/* Panel de botones de operaciones */
.operations-bar-panel {
  background: var(--bg-card-header);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}

.operations-title {
  display: block;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.ops-buttons-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
}

.btn-op {
  padding: 0.65rem 1.1rem;
  background: var(--bg-input);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.15s ease;
}

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

.btn-op strong {
  color: var(--primary-color);
  font-size: 1rem;
}

.scalar-op-box {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.25rem 0.6rem;
}

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

.input-scalar {
  width: 50px;
  height: 32px;
  text-align: center;
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-family: var(--font-mono);
}

.btn-op-small {
  padding: 0.35rem 0.65rem;
  background: var(--primary-light);
  color: var(--primary-color);
  border: 1px solid var(--primary-color);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-op-small:hover {
  background: var(--primary-color);
  color: #ffffff;
}

.btn-op-swap {
  padding: 0.65rem 1rem;
  background: var(--bg-input);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-left: auto;
}

.btn-op-swap:hover {
  color: var(--text-main);
  border-color: var(--text-muted);
}

/* Botones principales de acción */
.btn-action-primary {
  background: var(--accent-orange);
  color: #000000;
  font-weight: 700;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.75rem 1.4rem;
  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;
}

.btn-action-secondary {
  background: var(--bg-input);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.65rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

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

/* 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); }
}

.result-title {
  margin: 0 0 1rem 0;
  font-size: 1.2rem;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.result-content {
  margin-bottom: 1rem;
  overflow-x: auto;
}

/* Matriz renderizada en salida */
.math-matrix-display {
  display: inline-flex;
  align-items: center;
  margin: 0.5rem 0;
  padding: 0 0.75rem;
  position: relative;
  font-family: var(--font-mono);
  font-size: 0.95rem;
}

.math-matrix-display::before,
.math-matrix-display::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 6px;
  border: 2px solid var(--text-muted);
}

.math-matrix-display::before {
  left: 0;
  border-right: none;
  border-radius: 4px 0 0 4px;
}

.math-matrix-display::after {
  right: 0;
  border-left: none;
  border-radius: 0 4px 4px 0;
}

.math-matrix-table {
  border-collapse: separate;
  border-spacing: 0.75rem 0.4rem;
}

.math-matrix-table td {
  text-align: center;
  padding: 0.2rem 0.4rem;
  min-width: 32px;
}

/* Acordeón de pasos */
.steps-accordion {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  margin-top: 1rem;
  overflow: hidden;
  background: var(--bg-card);
}

.accordion-trigger {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.85rem 1.25rem;
  background: var(--bg-input);
  border: none;
  color: var(--text-main);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}

.accordion-trigger:hover {
  background: var(--bg-hover);
}

.accordion-trigger .chevron-icon {
  transition: transform 0.2s ease;
}

.steps-accordion.open .accordion-trigger .chevron-icon {
  transform: rotate(180deg);
}

.accordion-body {
  display: none;
  padding: 1.25rem;
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.6;
  border-top: 1px solid var(--border-color);
}

.steps-accordion.open .accordion-body {
  display: block;
}

.step-item {
  margin-bottom: 1.25rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px dashed var(--border-color);
}

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

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

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

/* Análisis de matriz individual */
.single-matrix-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

@media (min-width: 860px) {
  .single-matrix-layout {
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }
}

.analysis-actions-panel {
  background: var(--bg-card-header);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
}

.analysis-btn-grid {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.kpi-analysis-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

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

.kpi-title {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 600;
  margin-bottom: 0.4rem;
}

.kpi-value {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--primary-color);
  font-family: var(--font-mono);
}

/* Sistemas de ecuaciones */
.system-header-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.system-dim-select {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
}

.system-equations-container {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  overflow-x: auto;
}

.equation-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  flex-wrap: nowrap;
}

.equation-row:last-child {
  margin-bottom: 0;
}

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

.eq-var {
  font-family: var(--font-heading);
  font-weight: 700;
  color: var(--text-main);
  font-size: 1rem;
}

.eq-sign {
  color: var(--text-muted);
  font-weight: 600;
}

.system-solve-bar {
  display: flex;
  justify-content: center;
  margin-bottom: 1rem;
}

.system-classification-badge {
  display: inline-block;
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 1rem;
}

.badge-scd {
  background: rgba(16, 185, 129, 0.2);
  color: var(--accent-green);
  border: 1px solid var(--accent-green);
}

.badge-sci {
  background: rgba(249, 115, 22, 0.2);
  color: var(--accent-orange);
  border: 1px solid var(--accent-orange);
}

.badge-si {
  background: rgba(239, 68, 68, 0.2);
  color: var(--accent-red);
  border: 1px solid var(--accent-red);
}

.system-solution-summary {
  font-size: 1.05rem;
  line-height: 1.6;
  margin-bottom: 1.5rem;
  padding: 1rem;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

/* Guía SEO 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 inline */
.matrix-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;
}

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

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

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

  .options-bar {
    flex-direction: column;
    align-items: flex-start;
  }

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

  .btn-op-swap {
    margin-left: 0;
    width: 100%;
    justify-content: center;
  }

  .matrix-cell-input {
    width: 50px;
    height: 38px;
    font-size: 0.88rem;
  }
}
