/* ==========================================================================
   Calculadora de Diluciones y Mezclas Químicas - Fijate Tools
   Estilos visuales canónicos, temas claro/oscuro y visualizador dinámico
   ========================================================================== */

: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;

  /* Paleta cromática corporativa (Modo claro) */
  --bg-page: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-subtle: #f1f5f9;
  --bg-input: #ffffff;
  --border-color: #e2e8f0;
  --border-focus: #3b82f6;

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

  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-subtle: #eff6ff;
  --primary-border: #bfdbfe;

  --color-success: #10b981;
  --color-success-bg: #ecfdf5;
  --color-success-border: #a7f3d0;
  --color-success-text: #065f46;

  --color-warning: #f59e0b;
  --color-warning-bg: #fffbeb;
  --color-warning-border: #fde68a;
  --color-warning-text: #92400e;

  --color-danger: #ef4444;
  --color-danger-bg: #fef2f2;
  --color-danger-border: #fecaca;
  --color-danger-text: #991b1b;

  --color-cyan: #06b6d4;
  --color-water: #38bdf8;
  --color-water-bg: rgba(56, 189, 248, 0.25);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --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 -2px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
}

/* Modo oscuro universal corporativo */
[data-theme="dark"] {
  --bg-page: #0b0f17;
  --bg-card: #131b26;
  --bg-card-subtle: #1a2433;
  --bg-input: #172231;
  --border-color: #243247;
  --border-focus: #60a5fa;

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

  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --primary-subtle: #172554;
  --primary-border: #1e3a8a;

  --color-success: #34d399;
  --color-success-bg: rgba(16, 185, 129, 0.15);
  --color-success-border: #065f46;
  --color-success-text: #6ee7b7;

  --color-warning: #fbbf24;
  --color-warning-bg: rgba(245, 158, 11, 0.15);
  --color-warning-border: #78350f;
  --color-warning-text: #fde68a;

  --color-danger: #f87171;
  --color-danger-bg: rgba(239, 68, 68, 0.15);
  --color-danger-border: #7f1d1d;
  --color-danger-text: #fca5a5;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.6);
}

*, *::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;
}

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

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

/* Layout Canónico */
.tool-layout {
  max-width: 1200px;
  margin: 1.5rem auto 3rem;
  padding: 0 1rem;
  box-sizing: border-box;
  flex: 1 0 auto;
}

.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%;
}

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

/* Cabecera de la herramienta dentro de card-main */
.tool-intro-header {
  margin-bottom: 1.75rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 1.25rem;
}

.tool-headline {
  font-size: 1.6rem;
  line-height: 1.3;
  margin-bottom: 0.5rem;
}

.tool-lead {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin: 0;
}

/* Sección de Presets preconfigurados */
.preset-section {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  margin-bottom: 1.75rem;
}

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

.preset-title {
  font-size: 0.95rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.preset-badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 9999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  background: var(--primary-subtle);
  color: var(--primary);
  border: 1px solid var(--primary-border);
}

.preset-select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: 44px;
  min-height: 44px;
  padding: 0 40px 0 0.85rem;
  background-color: var(--bg-input);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  outline: none;
  font-weight: 500;
  cursor: pointer;
  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%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}

.preset-select option {
  background-color: var(--bg-card);
  color: var(--text-main);
  padding: 0.5rem;
}

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

.preset-description {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.6rem;
  margin-bottom: 0;
}

.preset-warning-box {
  margin-top: 0.85rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--color-warning-bg);
  border: 1px solid var(--color-warning-border);
  color: var(--color-warning-text);
  font-size: 0.82rem;
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  line-height: 1.45;
}

.preset-warning-box[hidden] {
  display: none !important;
}

/* Selector segmentado de modo */
.mode-tabs-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 0.4rem;
  background: var(--bg-card-subtle);
  padding: 0.35rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  margin-bottom: 1.5rem;
}

.mode-tab-btn {
  background: transparent;
  border: none;
  padding: 0.65rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.mode-tab-btn:hover {
  color: var(--text-main);
  background: rgba(0, 0, 0, 0.04);
}

[data-theme="dark"] .mode-tab-btn:hover {
  background: rgba(255, 255, 255, 0.05);
}

.mode-tab-btn.active {
  background: var(--bg-card);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

/* Paneles de modo */
.mode-panel {
  display: none;
}

.mode-panel.active {
  display: block;
}

/* Grilla de controles y visualizador */
.calculator-grid {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 2rem;
  margin-bottom: 2rem;
}

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

/* Controles de formulario */
.form-group {
  margin-bottom: 1.25rem;
}

.form-label {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 0.45rem;
}

.form-help {
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-top: 0.35rem;
  display: block;
}

.form-input {
  width: 100%;
  height: 44px;
  min-height: 44px;
  padding: 0 0.85rem;
  background-color: var(--bg-input);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  outline: none;
  font-family: var(--font-mono);
  font-size: 0.95rem;
  transition: border-color 0.15s ease;
}

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

.form-select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: 44px;
  min-height: 44px;
  padding: 0 40px 0 0.85rem;
  background-color: var(--bg-input);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  outline: none;
  cursor: pointer;
  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%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}

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

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

/* Chips rápidos de volumen */
.volume-chips-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.6rem;
}

.volume-chip-btn {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--text-muted);
  cursor: pointer;
  min-height: 38px;
  transition: all 0.15s ease;
}

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

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

/* Panel visualizador SVG de la botella */
.visualizer-card {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 360px;
}

.visualizer-title {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.bottle-svg-wrapper {
  width: 100%;
  max-width: 240px;
  height: 280px;
  position: relative;
}

.bottle-svg-wrapper svg {
  width: 100%;
  height: 100%;
  display: block;
}

.svg-tick-line {
  stroke: var(--text-dim);
  stroke-width: 1.5;
  stroke-dasharray: 2, 2;
  opacity: 0.6;
}

.svg-tick-text {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  fill: var(--text-main);
}

.svg-bottle-contour {
  fill: none;
  stroke: var(--border-color);
  stroke-width: 3;
}

[data-theme="dark"] .svg-bottle-contour {
  stroke: #475569;
}

.svg-bottle-cap {
  fill: #64748b;
}

.svg-liquid-water {
  fill: var(--color-water-bg);
  transition: all 0.3s ease;
}

.svg-liquid-product {
  transition: all 0.3s ease;
}

/* Tarjetas KPI de resultados */
.kpis-banner {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
  margin-bottom: 1.5rem;
}

.kpi-card {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  text-align: center;
}

.kpi-card.highlight {
  background: var(--primary-subtle);
  border-color: var(--primary-border);
}

.kpi-label {
  font-size: 0.78rem;
  color: var(--text-dim);
  font-weight: 600;
  margin-bottom: 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

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

.kpi-card.highlight .kpi-value {
  color: var(--primary);
}

/* Banner resumen de preparación */
.summary-action-banner {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 1rem 1.25rem;
  font-size: 0.95rem;
  color: var(--text-main);
  line-height: 1.5;
  margin-bottom: 1.5rem;
}

/* Botón de acción para generar etiqueta */
.btn-open-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background: var(--primary);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.65rem 1.25rem;
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  min-height: 42px;
  transition: background 0.15s ease;
}

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

/* Secciones complementarias (Ahorro, Incompatibilidades, Tabla de ratios) */
.tool-subsections-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-top: 2rem;
}

@media (max-width: 850px) {
  .tool-subsections-grid {
    grid-template-columns: 1fr;
  }
}

.tool-subsection-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.subsection-heading {
  font-size: 1.15rem;
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.subsection-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0;
  margin-bottom: 1.25rem;
}

/* Semáforo de incompatibilidades químicas */
.chemical-selectors {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

@media (max-width: 500px) {
  .chemical-selectors {
    grid-template-columns: 1fr;
  }
}

.chemical-result-card {
  border-radius: var(--radius-sm);
  padding: 1.15rem;
  margin-top: 1rem;
  border: 1px solid transparent;
  transition: all 0.2s ease;
}

.chemical-result-card.status-danger {
  background: var(--color-danger-bg);
  border-color: var(--color-danger-border);
  color: var(--color-danger-text);
}

.chemical-result-card.status-warning {
  background: var(--color-warning-bg);
  border-color: var(--color-warning-border);
  color: var(--color-warning-text);
}

.chemical-result-card.status-safe {
  background: var(--color-success-bg);
  border-color: var(--color-success-border);
  color: var(--color-success-text);
}

.chemical-result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}

.chemical-result-badge {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
}

.chemical-result-card.status-danger .chemical-result-badge {
  background: #dc2626;
  color: #ffffff;
}

.chemical-result-card.status-warning .chemical-result-badge {
  background: #d97706;
  color: #ffffff;
}

.chemical-result-card.status-safe .chemical-result-badge {
  background: #059669;
  color: #ffffff;
}

.chemical-result-title {
  font-size: 0.95rem;
  font-weight: 700;
  margin: 0;
}

.chemical-result-reaction {
  font-size: 0.85rem;
  margin: 0.4rem 0;
  line-height: 1.45;
}

.chemical-result-advice {
  font-size: 0.8rem;
  margin-top: 0.5rem;
  font-weight: 600;
  opacity: 0.95;
}

/* Tabla de matriz de ratios interactiva */
.ratio-matrix-section {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  margin-top: 2rem;
}

.table-responsive-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.ratio-matrix-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  text-align: left;
}

.ratio-matrix-table th {
  background: var(--bg-card-subtle);
  color: var(--text-dim);
  font-weight: 700;
  padding: 0.75rem 0.85rem;
  border-bottom: 2px solid var(--border-color);
  font-family: var(--font-heading);
}

.ratio-matrix-table td {
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border-color);
  font-family: var(--font-mono);
  color: var(--text-main);
}

.ratio-matrix-row {
  cursor: pointer;
  transition: background 0.15s ease;
}

.ratio-matrix-row:hover {
  background: var(--primary-subtle);
}

.ratio-badge-pill {
  display: inline-block;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  color: var(--primary);
}

/* Guía técnica y educativa SEO */
.seo-guide-section {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.75rem;
  margin-top: 2rem;
  line-height: 1.65;
}

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

.seo-guide-section h3 {
  font-size: 1.1rem;
  margin-top: 1.25rem;
  margin-bottom: 0.5rem;
}

.seo-guide-section p, .seo-guide-section li {
  color: var(--text-muted);
  font-size: 0.92rem;
}

.formula-box {
  background: var(--bg-card-subtle);
  border-left: 3px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1.15rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  margin: 1rem 0;
  color: var(--text-main);
}

/* Modal de etiqueta para imprimir */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.modal-overlay[hidden] {
  display: none !important;
}

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

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

.modal-title {
  font-size: 1.1rem;
  margin: 0;
}

.modal-close-btn {
  background: transparent;
  border: none;
  font-size: 1.35rem;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
}

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

.modal-body {
  padding: 1.5rem;
}

.printable-label {
  background: #ffffff;
  color: #0f172a;
  border: 2px dashed #94a3b8;
  border-radius: 8px;
  padding: 1.25rem;
  text-align: left;
  box-shadow: var(--shadow-sm);
}

.printable-label-header {
  border-bottom: 2px solid #0f172a;
  padding-bottom: 0.5rem;
  margin-bottom: 0.75rem;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.printable-label-title {
  font-family: var(--font-heading);
  font-size: 1.2rem;
  font-weight: 800;
  margin: 0;
  color: #0f172a;
}

.printable-label-ratio {
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-weight: 800;
  color: #2563eb;
}

.printable-label-row {
  font-size: 0.85rem;
  margin-bottom: 0.4rem;
  line-height: 1.4;
  color: #1e293b;
}

.printable-label-warning {
  margin-top: 0.75rem;
  padding-top: 0.5rem;
  border-top: 1px solid #cbd5e1;
  font-size: 0.75rem;
  color: #b91c1c;
  font-weight: 600;
}

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

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 0.55rem 1rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
  min-height: 40px;
}

.btn-primary {
  background: var(--primary);
  border: none;
  color: #ffffff;
  padding: 0.55rem 1.25rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
  min-height: 40px;
}

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

/* Reglas de impresión (@media print) */
@media print {
  body * {
    visibility: hidden;
  }
  .printable-label, .printable-label * {
    visibility: visible;
  }
  .modal-overlay {
    position: static;
    background: transparent;
    padding: 0;
  }
  .printable-label {
    position: absolute;
    left: 20mm;
    top: 20mm;
    width: 90mm;
    border: 2px solid #000000;
    page-break-inside: avoid;
  }
}
