/* ==========================================================================
   Calculadora de Fermentación de Masas Madre (Acidez TTA y DDT)
   Fijate Tools - Estilos corporativos con diseño artesanal panadero
   ========================================================================== */

:root {
  --font-main: 'Inter', system-ui, -apple-system, sans-serif;
  --font-heading: 'Outfit', 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Paleta cromática artesanal (Dark por defecto con switch a Light) */
  --bg-primary: #0b0f17;
  --bg-secondary: #121824;
  --bg-tertiary: #1a2233;
  --bg-card: #141c2c;
  --bg-card-hover: #1a253a;
  --bg-input: #0f1624;

  --border-subtle: #233047;
  --border-focus: #f59e0b;

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

  /* Acentos de fermentación: ámbar miel, trigo tostado, verde activo y alerta proteolítica */
  --accent-amber: #f59e0b;
  --accent-amber-light: #fbbf24;
  --accent-amber-glow: rgba(245, 158, 11, 0.15);
  
  --accent-rye: #b45309;
  --accent-wheat: #eab308;
  
  --color-success: #10b981;
  --color-success-bg: rgba(16, 185, 129, 0.12);
  --color-warning: #f59e0b;
  --color-warning-bg: rgba(245, 158, 11, 0.14);
  --color-danger: #ef4444;
  --color-danger-bg: rgba(239, 68, 68, 0.14);
  --color-info: #0ea5e9;
  --color-info-bg: rgba(14, 165, 233, 0.12);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.45);
  --shadow-glow: 0 0 20px rgba(245, 158, 11, 0.2);
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
}

/* Modo claro nativo unificado con theme.js */
[data-theme="light"],
body.light-theme {
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f1f5f9;
  --bg-card: #ffffff;
  --bg-card-hover: #f8fafc;
  --bg-input: #ffffff;

  --border-subtle: #e2e8f0;
  --border-focus: #d97706;

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

  --accent-amber: #d97706;
  --accent-amber-light: #f59e0b;
  --accent-amber-glow: rgba(217, 119, 6, 0.12);

  --color-success-bg: rgba(16, 185, 129, 0.1);
  --color-warning-bg: rgba(245, 158, 11, 0.12);
  --color-danger-bg: rgba(239, 68, 68, 0.1);
  --color-info-bg: rgba(14, 165, 233, 0.1);

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.07);
  --shadow-glow: 0 0 20px rgba(217, 119, 6, 0.15);
}

/* Base obligatoria canónica */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

h1, h2, h3, h4, h5, h6,
.brand-title,
.section-title,
.panel-title,
.hero-title,
.faq-section-title {
  font-family: var(--font-heading);
  letter-spacing: -0.015em;
  font-weight: 700;
  color: var(--text-main);
}

.mono,
.kpi-value,
.code-box,
code {
  font-family: var(--font-mono);
}

/* Layout canónico */
.tool-layout {
  max-width: 1240px;
  margin: 1.5rem auto 3rem;
  padding: 0 1rem;
  width: 100%;
  flex: 1 0 auto;
}

.tool-with-sidebar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
  align-items: start;
}

@media (min-width: 1536px) {
  .tool-with-sidebar {
    grid-template-columns: minmax(0, 1fr) 300px;
  }
}

.tool-main-content {
  min-width: 0;
  width: 100%;
}

/* Hero introductorio */
.hero-card {
  background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  margin-bottom: 1.75rem;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

.hero-card::after {
  content: '';
  position: absolute;
  top: -60px;
  right: -60px;
  width: 180px;
  height: 180px;
  background: radial-gradient(circle, var(--accent-amber-glow) 0%, transparent 70%);
  pointer-events: none;
  border-radius: 50%;
}

.hero-header {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.hero-icon-box {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  background: var(--accent-amber-glow);
  color: var(--accent-amber);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.hero-title {
  font-size: 1.6rem;
  line-height: 1.25;
}

.hero-lead {
  color: var(--text-muted);
  font-size: 0.98rem;
  max-width: 900px;
}

/* Selector de presets rápidos */
.presets-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border-subtle);
}

.preset-chip {
  appearance: none;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  padding: 0.5rem 1rem;
  color: var(--text-main);
  font-size: 0.86rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 38px;
}

.preset-chip:hover {
  border-color: var(--accent-amber);
  background: var(--accent-amber-glow);
  color: var(--accent-amber);
  transform: translateY(-1px);
}

.preset-chip.active {
  background: var(--accent-amber);
  border-color: var(--accent-amber);
  color: #0b0f17;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(245, 158, 11, 0.35);
}

/* Cuadrícula de paneles principales */
.panels-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
  margin-bottom: 2rem;
}

@media (min-width: 960px) {
  .panels-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .panel-full-width {
    grid-column: 1 / -1;
  }
}

.tool-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  transition: border-color var(--transition-normal);
}

.tool-panel:hover {
  border-color: rgba(245, 158, 11, 0.35);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
}

.panel-title-group {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.panel-badge {
  font-size: 0.72rem;
  font-family: var(--font-mono);
  font-weight: 700;
  text-transform: uppercase;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-full);
  background: var(--bg-tertiary);
  color: var(--accent-amber);
  border: 1px solid var(--border-subtle);
}

.panel-title {
  font-size: 1.15rem;
  font-weight: 700;
}

/* Formularios y controles */
.form-group {
  margin-bottom: 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

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

.form-hint {
  font-size: 0.78rem;
  color: var(--text-dim);
  font-weight: normal;
}

.form-control,
.form-select {
  width: 100%;
  min-height: 42px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 0.95rem;
  padding: 0.55rem 0.85rem;
  transition: all var(--transition-fast);
}

.form-select {
  max-width: 100%;
  min-width: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  padding-right: 42px;
  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='%23f59e0b' 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;
  background-size: 14px;
  cursor: pointer;
}

.form-control:focus,
.form-select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-amber-glow);
}

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

/* Input wrappers con sufijo */
.input-with-suffix {
  display: flex;
  align-items: stretch;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: border-color var(--transition-fast);
}

.input-with-suffix:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-amber-glow);
}

.input-with-suffix .form-control {
  flex: 1 1 0%;
  width: 0;
  min-width: 0;
  border: none;
  border-radius: 0;
  box-shadow: none;
  font-family: var(--font-mono);
  font-weight: 600;
}

.input-suffix {
  display: flex;
  align-items: center;
  padding: 0 0.85rem;
  background: var(--bg-tertiary);
  color: var(--text-muted);
  font-size: 0.85rem;
  font-family: var(--font-mono);
  border-left: 1px solid var(--border-subtle);
  user-select: none;
}

/* Rango y slider con visualización reactiva */
.range-container {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.form-range {
  flex: 1;
  accent-color: var(--accent-amber);
  height: 6px;
  border-radius: 3px;
  cursor: pointer;
}

.range-val-badge {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--accent-amber);
  background: var(--accent-amber-glow);
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius-md);
  min-width: 60px;
  text-align: center;
}

/* Tarjetas KPI y resultados visuales */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem;
  margin-top: 1rem;
}

@media (min-width: 640px) {
  .kpi-row-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .kpi-row-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

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

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--accent-amber);
  opacity: 0.7;
}

.kpi-card.kpi-success::before { background: var(--color-success); }
.kpi-card.kpi-danger::before { background: var(--color-danger); }
.kpi-card.kpi-info::before { background: var(--color-info); }

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

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

.kpi-subtext {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 0.35rem;
}

/* Alerta de hielo / calor DDT */
.thermal-alert-box {
  margin-top: 1rem;
  padding: 1rem;
  border-radius: var(--radius-md);
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  border: 1px solid;
}

.thermal-alert-box.alert-ice {
  background: var(--color-info-bg);
  border-color: rgba(14, 165, 233, 0.4);
  color: #38bdf8;
}

.thermal-alert-box.alert-warm {
  background: var(--accent-amber-glow);
  border-color: rgba(245, 158, 11, 0.4);
  color: var(--accent-amber-light);
}

.thermal-alert-box.alert-ok {
  background: var(--color-success-bg);
  border-color: rgba(16, 185, 129, 0.4);
  color: #34d399;
}

.thermal-alert-icon {
  flex-shrink: 0;
  margin-top: 2px;
}

.thermal-alert-content {
  font-size: 0.88rem;
  line-height: 1.45;
  color: var(--text-main);
}

.thermal-alert-content strong {
  color: inherit;
  font-weight: 700;
}

/* Gráfico de simulación en Canvas */
.canvas-wrapper {
  position: relative;
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.75rem;
  margin-top: 1rem;
  touch-action: pan-y;
}

#fermentationChart {
  width: 100%;
  height: 290px;
  display: block;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  margin-top: 0.85rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border-subtle);
  font-size: 0.82rem;
  color: var(--text-muted);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.legend-color {
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

.legend-color.color-ph { background: #38bdf8; }
.legend-color.color-tta { background: #f59e0b; }
.legend-color.color-vol { background: #10b981; }
.legend-color.color-zone-optimal { background: rgba(16, 185, 129, 0.25); border: 1px solid #10b981; }
.legend-color.color-zone-danger { background: rgba(239, 68, 68, 0.25); border: 1px solid #ef4444; }

/* Tooltip dinámico sobre canvas */
.chart-tooltip {
  position: absolute;
  top: 15px;
  right: 15px;
  background: rgba(18, 24, 36, 0.94);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.65rem 0.85rem;
  font-size: 0.82rem;
  pointer-events: none;
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(4px);
  z-index: 10;
  display: none;
}

[data-theme="light"] .chart-tooltip,
body.light-theme .chart-tooltip {
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.chart-tooltip-title {
  font-family: var(--font-heading);
  font-weight: 700;
  color: var(--accent-amber);
  margin-bottom: 0.25rem;
}

/* Indicador semafórico de proteólisis */
.proteolysis-status-card {
  border-radius: var(--radius-md);
  padding: 1.15rem;
  margin-top: 1.25rem;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  border: 1px solid var(--border-subtle);
  background: var(--bg-secondary);
}

.proteolysis-indicator-gauge {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-weight: 800;
  font-size: 1.15rem;
}

.status-optimal {
  background: var(--color-success-bg);
  border-color: rgba(16, 185, 129, 0.4);
}
.status-optimal .proteolysis-indicator-gauge {
  background: var(--color-success);
  color: #0b0f17;
}

.status-warning {
  background: var(--color-warning-bg);
  border-color: rgba(245, 158, 11, 0.4);
}
.status-warning .proteolysis-indicator-gauge {
  background: var(--color-warning);
  color: #0b0f17;
}

.status-danger {
  background: var(--color-danger-bg);
  border-color: rgba(239, 68, 68, 0.4);
}
.status-danger .proteolysis-indicator-gauge {
  background: var(--color-danger);
  color: #ffffff;
}

.proteolysis-info h4 {
  font-size: 1rem;
  margin-bottom: 0.2rem;
}

.proteolysis-info p {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Laboratorio de titulación manual de TTA */
.titration-box {
  background: var(--bg-tertiary);
  border: 1px dashed var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  margin-top: 1rem;
}

.titration-inputs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.titration-result-display {
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.tta-big-val {
  font-size: 2rem;
  font-weight: 800;
  color: var(--accent-amber);
  line-height: 1;
}

/* Botones principales de acción */
.btn-action-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  width: 100%;
  min-height: 44px;
  background: var(--accent-amber);
  color: #0b0f17;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-heading);
  font-size: 0.96rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition-fast);
  padding: 0.65rem 1.25rem;
  margin-top: 1rem;
}

.btn-action-primary:hover {
  background: var(--accent-amber-light);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.35);
}

.btn-action-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  width: 100%;
  min-height: 42px;
  background: transparent;
  color: var(--text-main);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  font-family: var(--font-main);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  padding: 0.5rem 1rem;
  margin-top: 0.75rem;
}

.btn-action-secondary:hover {
  background: var(--bg-tertiary);
  border-color: var(--accent-amber);
  color: var(--accent-amber);
}

/* Bloque FAQ y Acordeón técnico */
.faq-accordion-section {
  margin-top: 2.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
}

.faq-title {
  font-size: 1.35rem;
  margin-bottom: 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.accordion-item {
  border-bottom: 1px solid var(--border-subtle);
}

.accordion-item:last-child {
  border-bottom: none;
}

.accordion-trigger {
  width: 100%;
  min-height: 48px;
  background: none;
  border: none;
  color: var(--text-main);
  font-family: var(--font-heading);
  font-size: 1.02rem;
  font-weight: 600;
  text-align: left;
  padding: 0.85rem 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  gap: 1rem;
}

.accordion-trigger:hover {
  color: var(--accent-amber);
}

.accordion-icon {
  transition: transform var(--transition-normal);
  flex-shrink: 0;
}

.accordion-item.open .accordion-icon {
  transform: rotate(180deg);
}

.accordion-content {
  display: none;
  padding-bottom: 1rem;
  font-size: 0.92rem;
  line-height: 1.6;
  color: var(--text-muted);
}

.accordion-item.open .accordion-content {
  display: block;
}

/* Tabla de valores canónicos */
.reference-table-wrapper {
  overflow-x: auto;
  margin-top: 0.85rem;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

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

.reference-table th {
  background: var(--bg-tertiary);
  color: var(--text-main);
  padding: 0.65rem 0.85rem;
  font-family: var(--font-heading);
  border-bottom: 1px solid var(--border-subtle);
}

.reference-table td {
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-muted);
}

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

/* Modal accesible de confirmación / informe (cero alert) */
.custom-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 9999;
}

.custom-modal-backdrop.active {
  display: flex;
}

.custom-modal-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  max-width: 560px;
  width: 100%;
  box-shadow: var(--shadow-md);
  padding: 1.5rem;
  position: relative;
  max-height: 90vh;
  overflow-y: auto;
}

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

.modal-title {
  font-size: 1.2rem;
}

.modal-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.25rem;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.modal-body {
  font-size: 0.92rem;
  line-height: 1.6;
  color: var(--text-muted);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

/* Estilos de impresión técnica para obrador */
@media print {
  .app-header,
  .tools-ad-banner-section,
  .tool-ad-sidebar,
  .fijate-footer,
  .presets-bar,
  .btn-action-primary,
  .btn-action-secondary {
    display: none !important;
  }

  body {
    background: #ffffff !important;
    color: #000000 !important;
  }

  .tool-panel,
  .hero-card,
  .faq-accordion-section {
    border: 1px solid #cccccc !important;
    background: #ffffff !important;
    box-shadow: none !important;
  }

  .kpi-card {
    border: 1px solid #999999 !important;
    background: #f8fafc !important;
  }
}
