/* ==========================================================================
   Calculadora de margen real, landed cost y GMROI - Hoja de estilos
   fijate.com - Estándares canónicos corporativos
   ========================================================================== */

:root {
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-heading: 'Outfit', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Tema oscuro por defecto */
  --bg-page: #0b0f17;
  --bg-card: #111827;
  --bg-card-subtle: #162032;
  --bg-card-hover: #1c293e;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-focus: rgba(56, 189, 248, 0.4);

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

  --accent-primary: #38bdf8;
  --accent-primary-hover: #0ea5e9;
  --accent-success: #34d399;
  --accent-warning: #f59e0b;
  --accent-danger: #ef4444;
  --accent-purple: #a855f7;

  --badge-bg-success: rgba(52, 211, 153, 0.12);
  --badge-text-success: #34d399;
  --badge-bg-warning: rgba(245, 158, 11, 0.12);
  --badge-text-warning: #f59e0b;
  --badge-bg-danger: rgba(239, 68, 68, 0.12);
  --badge-text-danger: #f87171;

  --input-bg: #0d131f;
  --input-border: #1e293b;
  --input-color: #f1f5f9;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.25);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -2px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.35), 0 4px 6px -4px rgba(0, 0, 0, 0.25);
}

[data-theme="light"] {
  --bg-page: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-subtle: #f1f5f9;
  --bg-card-hover: #e2e8f0;
  --border-color: rgba(0, 0, 0, 0.08);
  --border-focus: rgba(2, 132, 199, 0.4);

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

  --accent-primary: #0284c7;
  --accent-primary-hover: #0369a1;
  --accent-success: #059669;
  --accent-warning: #d97706;
  --accent-danger: #dc2626;
  --accent-purple: #9333ea;

  --badge-bg-success: rgba(5, 150, 105, 0.1);
  --badge-text-success: #059669;
  --badge-bg-warning: rgba(217, 119, 6, 0.1);
  --badge-text-warning: #b45309;
  --badge-bg-danger: rgba(220, 38, 38, 0.1);
  --badge-text-danger: #b91c1c;

  --input-bg: #ffffff;
  --input-border: #cbd5e1;
  --input-color: #0f172a;

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

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

body {
  font-family: var(--font-sans);
  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;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  font-weight: 700;
  color: var(--text-main);
}

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

.tool-layout {
  max-width: 1320px;
  margin: 1.5rem auto 3rem;
  padding: 0 1rem;
  width: 100%;
  flex: 1;
}

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

.tool-main-content {
  flex: 1 1 0%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Barra superior de presets */
.tool-top-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 0.875rem 1.25rem;
}

.presets-group {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.presets-label {
  font-size: 0.8125rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-right: 0.25rem;
}

.btn-preset {
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.btn-preset:hover {
  background: var(--bg-card-hover);
  color: var(--text-main);
  border-color: var(--border-focus);
}

.btn-preset.active {
  background: var(--accent-primary);
  color: #0b0f17;
  border-color: var(--accent-primary);
  font-weight: 600;
}

.top-bar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.btn-action-sm {
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 36px;
}

.btn-action-sm:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-focus);
}

/* Tarjetas y secciones */
.card-section {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

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

.section-title-wrap {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.section-step-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent-primary);
  color: #0b0f17;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 0.8125rem;
}

.section-title {
  font-size: 1.0625rem;
  color: var(--text-main);
  font-weight: 600;
}

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

/* Grids de formulario */
.form-grid-4 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

.form-grid-3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

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

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

.form-label small {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-dim);
}

.input-control,
.select-control {
  width: 100%;
  height: 40px;
  min-height: 40px;
  padding: 0 0.75rem;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  background-color: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 6px;
  color: var(--input-color);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.select-control {
  max-width: 100%;
  min-width: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  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='%2394a3b8' 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.75rem center;
  padding-right: 2.25rem;
}

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

.input-control:focus,
.select-control:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px var(--border-focus);
}

.input-with-unit {
  display: flex;
  align-items: center;
  border: 1px solid var(--input-border);
  border-radius: 6px;
  background-color: var(--input-bg);
  height: 40px;
  min-height: 40px;
  overflow: hidden;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input-with-unit:focus-within {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px var(--border-focus);
}

.input-with-unit input {
  flex: 1 1 0%;
  width: 0;
  min-width: 0;
  height: 100%;
  border: none;
  background: transparent;
  padding: 0 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  color: var(--input-color);
  outline: none;
}

.input-unit-badge {
  padding: 0 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg-card-subtle);
  border-left: 1px solid var(--border-color);
  height: 100%;
  display: flex;
  align-items: center;
  user-select: none;
  white-space: nowrap;
}

/* Tarjetas de KPIs */
.kpis-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.875rem;
}

.kpi-card {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.875rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  position: relative;
  overflow: hidden;
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 3px;
  height: 100%;
  background: var(--accent-primary);
}

.kpi-card.kpi-warning::before {
  background: var(--accent-warning);
}

.kpi-card.kpi-danger::before {
  background: var(--accent-danger);
}

.kpi-card.kpi-success::before {
  background: var(--accent-success);
}

.kpi-card.kpi-purple::before {
  background: var(--accent-purple);
}

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

.kpi-value {
  font-family: var(--font-mono);
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.2;
}

.kpi-subtext {
  font-size: 0.6875rem;
  color: var(--text-dim);
}

/* Tabs de canal */
.channel-tabs {
  display: flex;
  gap: 0.5rem;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.35rem;
  overflow-x: auto;
}

.channel-tab-btn {
  flex: 1;
  min-height: 38px;
  padding: 0.4rem 0.875rem;
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  font-weight: 600;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

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

.channel-tab-btn.active {
  background: var(--accent-primary);
  color: #0b0f17;
}

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

.chart-card {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.chart-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-main);
}

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

.chart-canvas-wrapper canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
  cursor: crosshair;
}

/* Tabla comparativa multicanal */
.table-responsive-container {
  border: 1px solid var(--border-color);
  border-radius: 8px;
  overflow-x: auto;
  background: var(--bg-card-subtle);
}

.channel-comparison-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
  text-align: right;
}

.channel-comparison-table th {
  background: var(--bg-card);
  color: var(--text-muted);
  font-weight: 600;
  padding: 0.625rem 0.875rem;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.channel-comparison-table th:first-child,
.channel-comparison-table td:first-child {
  text-align: left;
}

.channel-comparison-table td {
  padding: 0.625rem 0.875rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-main);
  font-family: var(--font-mono);
  white-space: nowrap;
}

.channel-comparison-table tr:hover td {
  background: var(--bg-card-hover);
}

.channel-comparison-table .highlight-row td {
  font-weight: 700;
  background: var(--bg-card-hover);
}

/* Simulador de descuentos */
.discount-simulator-card {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.discount-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.discount-pill-btn {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 0.4rem 0.875rem;
  border-radius: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
}

.discount-pill-btn:hover {
  color: var(--text-main);
  border-color: var(--border-focus);
}

.discount-pill-btn.active {
  background: var(--accent-danger);
  color: #fff;
  border-color: var(--accent-danger);
}

.discount-results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 0.875rem;
}

.discount-result-item {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.discount-result-label {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.discount-result-val {
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
}

.fatal-discount-alert {
  background: var(--badge-bg-danger);
  border: 1px solid var(--accent-danger);
  border-radius: 8px;
  padding: 0.875rem 1rem;
  color: var(--badge-text-danger);
  font-size: 0.8125rem;
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

/* Botones principales */
.btn-primary {
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.625rem 1.25rem;
  border-radius: 6px;
  background: var(--accent-primary);
  color: #0b0f17;
  border: none;
  cursor: pointer;
  min-height: 40px;
  transition: background 0.2s;
}

.btn-primary:hover {
  background: var(--accent-primary-hover);
}

.btn-secondary {
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.625rem 1.25rem;
  border-radius: 6px;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  cursor: pointer;
  min-height: 40px;
  transition: all 0.2s;
}

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

.actions-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem 0 0;
}

.footer-btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

/* Modales */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  transform: scale(0.95);
  transition: transform 0.2s ease;
}

.modal-overlay.active .modal-card {
  transform: scale(1);
}

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

.modal-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-main);
}

.btn-close-modal {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.35rem;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.modal-body {
  padding: 1.25rem;
  overflow-y: auto;
  font-size: 0.875rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.modal-body h4 {
  font-size: 0.9375rem;
  color: var(--text-main);
  margin-top: 0.5rem;
}

.formula-box {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--accent-primary);
  margin: 0.25rem 0;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border-color);
}

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

  .tool-top-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .presets-group {
    overflow-x: auto;
    padding-bottom: 0.25rem;
  }

  .form-grid-4,
  .form-grid-3 {
    grid-template-columns: 1fr;
  }

  .kpis-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .actions-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .footer-btn-group {
    flex-direction: column;
    width: 100%;
  }

  .btn-primary,
  .btn-secondary {
    width: 100%;
  }
}

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

/* Impresión */
@media print {
  body {
    background: #fff !important;
    color: #000 !important;
  }
  .app-header,
  .tool-top-bar,
  .tool-ad-sidebar,
  .tools-ad-banner-section,
  .fijate-footer,
  .actions-footer,
  .modal-overlay {
    display: none !important;
  }
  .tool-layout {
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  .card-section {
    border: 1px solid #ccc !important;
    box-shadow: none !important;
    break-inside: avoid;
  }
}
