/**
 * Estilos visuales del comparador de márgenes: Amazon FBA vs Tienda propia
 * Compatible con temas claro y oscuro, responsive y adaptado a normas canónicas
 */

:root {
  --font-main: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-heading: 'Outfit', 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --font-sans: var(--font-main);
  --font-title: var(--font-heading);

  /* Tema claro por defecto */
  --bg-page: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-alt: #f1f5f9;
  --bg-input: #ffffff;
  --border-color: #e2e8f0;
  --border-focus: #3b82f6;

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

  /* Colores temáticos de canal */
  --color-fba: #d97706;
  --color-fba-bg: #fffbeb;
  --color-fba-border: #fde68a;

  --color-own: #2563eb;
  --color-own-bg: #eff6ff;
  --color-own-border: #bfdbfe;

  --color-success: #10b981;
  --color-success-bg: #ecfdf5;
  --color-danger: #ef4444;
  --color-danger-bg: #fef2f2;
  --color-warning: #f59e0b;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
}

[data-theme="dark"] {
  --bg-page: #0b0f17;
  --bg-card: #131b26;
  --bg-card-alt: #1a2434;
  --bg-input: #101722;
  --border-color: #243044;
  --border-focus: #60a5fa;

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-sub: #cbd5e1;

  --color-fba: #f59e0b;
  --color-fba-bg: rgba(245, 158, 11, 0.12);
  --color-fba-border: rgba(245, 158, 11, 0.35);

  --color-own: #3b82f6;
  --color-own-bg: rgba(59, 130, 246, 0.12);
  --color-own-border: rgba(59, 130, 246, 0.35);

  --color-success: #34d399;
  --color-success-bg: rgba(52, 211, 153, 0.12);
  --color-danger: #f87171;
  --color-danger-bg: rgba(248, 113, 113, 0.12);
}

*, *::before, *::after {
  box-sizing: border-box;
}

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

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  margin-top: 0;
  color: var(--text-main);
  letter-spacing: -0.015em;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: 0.9375rem;
}

.text-mono {
  font-family: var(--font-mono);
}

.font-bold {
  font-weight: 700;
}

.text-right {
  text-align: right;
}

.text-center {
  text-align: center;
}

.text-success {
  color: var(--color-success) !important;
}

.text-danger {
  color: var(--color-danger) !important;
}

/* Layout canónico */
.main-wrapper.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 superior de herramientas y presets */
.toolbar-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.preset-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1 1 300px;
}

.preset-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-sub);
  white-space: nowrap;
}

.toolbar-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* Botones estándar */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.55rem 1rem;
  min-height: 40px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid transparent;
  text-decoration: none;
}

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

.btn-primary:hover {
  background: #1d4ed8;
}

.btn-secondary {
  background: var(--bg-card-alt);
  color: var(--text-main);
  border-color: var(--border-color);
}

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

.btn-sm {
  padding: 0.35rem 0.65rem;
  min-height: 32px;
  font-size: 0.8125rem;
}

.btn-icon {
  padding: 0.5rem;
  min-height: 40px;
  min-width: 40px;
}

/* Banner de veredicto ganador */
.verdict-card {
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
  border: 1px solid transparent;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.verdict-card.verdict-own {
  background: var(--color-own-bg);
  border-color: var(--color-own-border);
}

.verdict-card.verdict-own .verdict-title {
  color: var(--color-own);
}

.verdict-card.verdict-fba {
  background: var(--color-fba-bg);
  border-color: var(--color-fba-border);
}

.verdict-card.verdict-fba .verdict-title {
  color: var(--color-fba);
}

.verdict-card.verdict-tie {
  background: var(--bg-card-alt);
  border-color: var(--border-color);
}

.verdict-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.verdict-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0;
}

.verdict-desc {
  font-size: 0.9375rem;
  color: var(--text-sub);
  margin: 0;
  line-height: 1.5;
}

.verdict-metrics-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-color);
}

.verdict-metric-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
  color: var(--text-sub);
}

.verdict-metric-val {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--text-main);
}

/* Tarjetas duales de KPI comparativo */
.dual-kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.5rem;
  margin-bottom: 2rem;
}

@media (max-width: 768px) {
  .dual-kpi-grid {
    grid-template-columns: 1fr;
  }
}

.channel-kpi-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  position: relative;
  overflow: hidden;
}

.channel-kpi-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
}

.channel-kpi-card.card-fba::before {
  background: var(--color-fba);
}

.channel-kpi-card.card-own::before {
  background: var(--color-own);
}

.channel-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.channel-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
  font-weight: 700;
  padding: 0.25rem 0.65rem;
  border-radius: 9999px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.badge-fba {
  background: var(--color-fba-bg);
  color: var(--color-fba);
  border: 1px solid var(--color-fba-border);
}

.badge-own {
  background: var(--color-own-bg);
  color: var(--color-own);
  border: 1px solid var(--color-own-border);
}

.channel-main-metric {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

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

.kpi-value {
  font-family: var(--font-mono);
  font-size: 2rem;
  font-weight: 800;
  line-height: 1.1;
  color: var(--text-main);
}

.kpi-subvalue {
  font-family: var(--font-mono);
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-muted);
}

.channel-secondary-metrics {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-color);
}

.metric-item {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.metric-item .metric-title {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.metric-item .metric-data {
  font-family: var(--font-mono);
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text-main);
}

/* Formulario principal dividido en paneles */
.card-section {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 2rem;
  box-shadow: var(--shadow-sm);
}

.section-header {
  margin-bottom: 1.25rem;
}

.section-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0 0 0.35rem 0;
}

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

/* Grilla de formulario responsiva */
.form-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.25rem;
}

.form-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.25rem;
}

.form-grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}

@media (max-width: 900px) {
  .form-grid-3, .form-grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 600px) {
  .form-grid-2, .form-grid-3, .form-grid-4 {
    grid-template-columns: 1fr;
  }
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.form-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-main);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.form-help {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.input-control,
.select-control {
  width: 100%;
  min-height: 40px;
  padding: 0.55rem 0.85rem;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  box-sizing: border-box;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input-control:focus,
.select-control:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.select-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2.5rem;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

[data-theme="dark"] .select-control {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}

/* Control con sufijo / prefijo */
.input-with-affix {
  display: flex;
  align-items: center;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.input-with-affix:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.input-with-affix .input-control {
  border: none;
  box-shadow: none;
  flex: 1 1 0%;
  width: 0;
  min-width: 0;
}

.input-affix {
  padding: 0 0.75rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-card-alt);
  min-height: 40px;
  display: flex;
  align-items: center;
  user-select: none;
  border-left: 1px solid var(--border-color);
}

.input-affix.affix-prefix {
  border-left: none;
  border-right: 1px solid var(--border-color);
}

/* Checkbox estilizado */
.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  cursor: pointer;
  color: var(--text-main);
  user-select: none;
}

.checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--color-own);
}

/* Slider de volumen mensual */
.volume-slider-box {
  background: var(--bg-card-alt);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  margin-top: 1rem;
}

.slider-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.slider-val-box {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.range-slider {
  width: 100%;
  height: 8px;
  border-radius: 4px;
  background: var(--border-color);
  outline: none;
  accent-color: var(--color-own);
  cursor: pointer;
}

/* Paneles de parámetros paralelos Amazon vs Tienda Propia */
.channels-config-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.5rem;
}

@media (max-width: 768px) {
  .channels-config-grid {
    grid-template-columns: 1fr;
  }
}

.channel-config-panel {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.channel-config-panel.panel-fba {
  border-top: 3px solid var(--color-fba);
}

.channel-config-panel.panel-own {
  border-top: 3px solid var(--color-own);
}

.panel-title {
  font-size: 1.0625rem;
  font-weight: 700;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Contenedores de gráficos */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.5rem;
  margin-bottom: 2rem;
}

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

.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.25rem 1rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
}

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

.chart-title {
  font-size: 1.0625rem;
  font-weight: 700;
  margin: 0 0 0.25rem 0;
}

.chart-desc {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin: 0;
}

.chart-canvas-wrapper {
  position: relative;
  width: 100%;
  height: 280px;
}

.chart-canvas-wrapper canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Tablas analíticas */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}

.analytics-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  text-align: left;
}

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

.analytics-table th {
  background: var(--bg-card-alt);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.8125rem;
  white-space: nowrap;
}

.analytics-table tbody tr:last-child td {
  border-bottom: none;
}

.table-concept-title {
  font-weight: 600;
  color: var(--text-main);
}

.table-concept-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.row-subtotal td {
  background: var(--bg-card-alt);
  font-weight: 700;
}

.row-result td {
  background: rgba(16, 185, 129, 0.08);
  font-weight: 700;
  border-top: 2px solid var(--color-success);
}

.row-highlight td {
  background: rgba(59, 130, 246, 0.08);
  font-weight: 800;
  border-top: 1px solid var(--border-color);
}

.row-selected-volume td {
  background: rgba(59, 130, 246, 0.12);
}

.badge-winner {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 700;
}

.badge-winner-own {
  background: var(--color-own-bg);
  color: var(--color-own);
  border: 1px solid var(--color-own-border);
}

.badge-winner-fba {
  background: var(--color-fba-bg);
  color: var(--color-fba);
  border: 1px solid var(--color-fba-border);
}

/* Modales accesibles */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 1rem;
}

.modal-overlay.is-active {
  display: flex;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 1.125rem;
  font-weight: 700;
  margin: 0;
}

.btn-close-modal {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
  padding: 0.25rem;
}

.btn-close-modal:hover {
  color: var(--text-main);
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  font-size: 0.9375rem;
  line-height: 1.6;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-color);
  background: var(--bg-card-alt);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* Fórmulas matemáticas en modales o guías */
.formula-box {
  background: var(--bg-card-alt);
  border: 1px solid var(--border-color);
  border-left: 3px solid var(--color-own);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  margin: 0.75rem 0;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  color: var(--text-main);
  overflow-x: auto;
}

/* Lista de SKUs guardados */
.saved-sku-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.85rem;
  background: var(--bg-card-alt);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  margin-bottom: 0.5rem;
}

.saved-sku-info {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.saved-sku-info span {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.saved-sku-actions {
  display: flex;
  gap: 0.35rem;
}

.empty-skus-msg {
  padding: 1.5rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* Guía SEO y acordeón didáctico */
.seo-guide-section {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2rem;
  margin-top: 2.5rem;
  box-shadow: var(--shadow-sm);
}

.seo-guide-section h2 {
  font-size: 1.5rem;
  margin-bottom: 1rem;
}

.seo-guide-section h3 {
  font-size: 1.2rem;
  margin-top: 1.5rem;
  margin-bottom: 0.75rem;
}

.seo-guide-section p {
  color: var(--text-sub);
  line-height: 1.65;
  margin-bottom: 1rem;
}

.faq-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

.faq-item {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-card-alt);
}

.faq-question {
  width: 100%;
  text-align: left;
  padding: 1rem 1.25rem;
  background: transparent;
  border: none;
  font-weight: 700;
  font-size: 0.9375rem;
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.faq-answer {
  padding: 0 1.25rem 1.25rem;
  color: var(--text-sub);
  font-size: 0.875rem;
  line-height: 1.6;
}

/* Adaptación para impresión limpia A4 (Informe ejecutivo) */
@media print {
  body {
    background: #ffffff !important;
    color: #000000 !important;
  }
  .app-header,
  .tool-ad-sidebar,
  .tools-ad-banner-section,
  .toolbar-presets,
  .fijate-footer,
  .btn,
  .modal-overlay {
    display: none !important;
  }
  .main-wrapper.tool-layout {
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  .tool-with-sidebar {
    display: block !important;
  }
  .card-section,
  .channel-kpi-card,
  .chart-card,
  .verdict-card {
    border: 1px solid #cccccc !important;
    box-shadow: none !important;
    break-inside: avoid;
  }
}
