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

code, pre, .mono, .stat-val, .comb-big-num {
  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 */
.stats-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 */
.stats-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);
}

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

.btn-toggle {
  padding: 0.45rem 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;
}

/* Paneles de entrada */
.data-input-panel {
  margin-bottom: 1.25rem;
}

.input-label {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.textarea-data {
  width: 100%;
  background: var(--bg-input);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.95rem;
  line-height: 1.5;
  resize: vertical;
  min-height: 100px;
}

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

.presets-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.6rem;
}

.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 centrado */
.action-bar-center {
  display: flex;
  justify-content: center;
  margin: 1.25rem 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); }
}

.result-title {
  margin: 0 0 1.25rem 0;
  font-size: 1.2rem;
  color: var(--text-main);
}

/* Rejilla de KPIs de estadística */
.stats-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

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

.stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.stat-val {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--primary-color);
  line-height: 1.2;
}

.stat-sub {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-top: 0.3rem;
}

/* Gráficos Canvas */
.charts-wrapper-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

@media (min-width: 900px) {
  .charts-wrapper-grid {
    grid-template-columns: 1fr 1fr;
  }
}

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

.chart-header {
  margin-bottom: 0.75rem;
}

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

.canvas-container {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.canvas-container canvas {
  width: 100%;
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  background: var(--bg-input);
}

/* Tabla de frecuencias */
.table-container-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  margin-top: 1rem;
}

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

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

.custom-data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  text-align: right;
}

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

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

.custom-data-table tbody tr:hover {
  background: var(--bg-hover);
}

/* Pestaña Distribuciones */
.dist-selector-box select,
.select-comb,
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 2rem 0.45rem 0.8rem;
  font-size: 0.95rem;
  cursor: pointer;
  color-scheme: dark light;
}

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

.dist-params-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
}

.param-input-item {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

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

.input-num {
  width: 130px;
  height: 40px;
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.3rem 0.65rem;
  font-family: var(--font-mono);
  font-size: 0.95rem;
}

.prob-calc-type-box {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
}

.prob-type-title {
  display: block;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.prob-radio-group {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 1.5rem;
}

.radio-label {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  cursor: pointer;
  color: var(--text-main);
}

.prob-inputs-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  margin-bottom: 1.25rem;
}

.prob-input-item {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

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

.dist-kpi-banner {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--primary-color);
  border-radius: var(--radius-sm);
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
  font-size: 1.15rem;
}

.dist-chart-box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
}

/* Pestaña Combinatoria */
.comb-types-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

@media (min-width: 768px) {
  .comb-types-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.comb-inputs-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

.comb-input-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

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

.comb-help-text {
  font-size: 0.78rem;
  color: var(--text-dim);
}

.comb-big-result {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  margin-bottom: 1rem;
  text-align: center;
}

.comb-big-label {
  font-size: 0.9rem;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.comb-big-num {
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--primary-color);
  word-break: break-all;
  line-height: 1.2;
}

.comb-explanation-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  line-height: 1.6;
}

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

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

[data-theme="light"] .stats-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;
  }

  .input-num {
    width: 100%;
  }

  .comb-big-num {
    font-size: 1.6rem;
  }
}
