/* =============================================================================
   UniControl Lab - Páginas de herramienta con navegación del sitio
   (Simulador PID, Calculadora 4-20 mA, Manual de FSM Designer)

   Se carga DESPUÉS de site.css y reutiliza sus tokens (:root), nav, footer,
   botones (.btn) y badges (.badge-clean). Solo agrega lo propio de herramienta:
   encabezado, paneles de parámetros, campos, consola oscura de resultados y
   tipografía de documentación técnica.
   ============================================================================= */

:root {
  --brand-blue-ring: rgba(0, 82, 204, 0.18);
  --amber-text: #b45309;
  --amber-soft: #fef3c7;
  --danger: #b91c1c;
}

/* Sin ligaduras en datos técnicos: ">=" y "==" se leen tal cual */
body { font-variant-ligatures: none; }

/* -----------------------------------------------------------------------------
   Encabezado de herramienta
   ----------------------------------------------------------------------------- */
.tool-page { padding: 3.5rem 0 4.5rem; }

.tool-head { max-width: 760px; margin-bottom: 2.5rem; }

.tool-head h1 {
  margin: 1rem 0 0.75rem;
  font-size: clamp(2rem, 3.4vw, 2.8rem);
  font-weight: 800;
  letter-spacing: -0.025em;
  line-height: 1.15;
  color: var(--text-title);
}

.tool-head p { margin: 0; font-size: 1.08rem; line-height: 1.7; color: var(--text-body); }

.tool-head-actions { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-top: 1.5rem; }

/* -----------------------------------------------------------------------------
   Paneles de parámetros
   ----------------------------------------------------------------------------- */
.tool-grid {
  display: grid;
  grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
  gap: 1.5rem;
  align-items: start;
}

.tool-stack { display: flex; flex-direction: column; gap: 1rem; }

.tool-panel {
  background: var(--bg-white);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 1.1rem 1.2rem 1.2rem;
  box-shadow: var(--shadow-sm);
}

.tool-panel-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0 0 0.9rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-title);
}

.tool-panel-title svg { color: var(--brand-blue); }
.tool-panel-title .step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--brand-blue-soft);
  color: var(--brand-blue);
  font-size: 0.66rem;
}

.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; }
.field-grid.cols-1 { grid-template-columns: 1fr; }
.field-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field-grid .span-all { grid-column: 1 / -1; }

.field { display: flex; flex-direction: column; gap: 0.35rem; min-width: 0; }

.field > label, .field-label {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.field input[type="number"],
.field input[type="text"],
.field select {
  width: 100%;
  height: 38px;
  padding: 0 0.7rem;
  border: 1px solid var(--border-card);
  border-radius: var(--radius-sm);
  background: var(--bg-white);
  color: var(--text-title);
  font-family: var(--font-mono);
  font-size: 0.88rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.field select { font-family: var(--font-sans); }

.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--brand-blue);
  box-shadow: 0 0 0 3px var(--brand-blue-ring);
}

.field-hint { font-size: 0.74rem; color: var(--text-muted); line-height: 1.45; }

/* Selector de opciones tipo "tarjeta" (modelos de simulación) */
.choice-list { display: grid; gap: 0.45rem; }

.choice {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
}

.choice:hover { border-color: var(--brand-blue); background: var(--brand-blue-soft); }
.choice:has(input:checked) { border-color: var(--brand-blue); background: var(--brand-blue-soft); box-shadow: inset 3px 0 0 var(--brand-blue); }
.choice input { margin-top: 0.2rem; accent-color: var(--brand-blue); }
.choice strong { display: block; font-size: 0.86rem; color: var(--text-title); }
.choice small { display: block; font-family: var(--font-mono); font-size: 0.7rem; color: var(--text-muted); margin-top: 0.1rem; }

input[type="checkbox"], input[type="radio"] { accent-color: var(--brand-blue); }

/* -----------------------------------------------------------------------------
   Consola oscura de resultados (identidad SCADA del sitio)
   ----------------------------------------------------------------------------- */
.tool-console {
  background: var(--scada-bg);
  border: 1px solid var(--scada-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-scada);
  color: var(--text-light);
  overflow: hidden;
}

.tool-console-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.85rem 1.1rem;
  border-bottom: 1px solid var(--scada-border);
  background: rgba(15, 23, 42, 0.6);
}

.tool-console-title {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-white);
}

.led {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-light);
  flex-shrink: 0;
  transition: var(--transition);
}

.led.run { background: var(--led-run); box-shadow: var(--led-run-glow); }

.console-status {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--scada-border);
  color: var(--text-light);
}

.console-status.run { color: var(--led-run); border-color: rgba(16, 185, 129, 0.35); background: var(--led-run-soft); }

.tool-console-body { padding: 1.1rem; }

.console-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* Botones sobre la consola oscura */
.cbtn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  height: 34px;
  padding: 0 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--scada-border);
  background: var(--scada-surface);
  color: var(--text-white);
  font-family: var(--font-sans);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.cbtn svg { width: 15px; height: 15px; }
.cbtn:hover:not(:disabled) { background: var(--scada-surface-elevated); border-color: var(--scada-border-active); }
.cbtn:disabled { opacity: 0.4; cursor: not-allowed; }
.cbtn.run { background: var(--led-run); border-color: var(--led-run); color: #fff; }
.cbtn.run:hover:not(:disabled) { background: #059669; border-color: #059669; }

.console-tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.6rem; margin-bottom: 1rem; }

.console-tile {
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--scada-border);
  border-radius: var(--radius-sm);
  background: rgba(15, 23, 42, 0.55);
}

.console-tile .lbl {
  font-family: var(--font-mono);
  font-size: 0.64rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-light);
}

.console-tile .val {
  margin-top: 0.15rem;
  font-family: var(--font-mono);
  font-size: 1.35rem;
  font-weight: 500;
  color: var(--brand-cyan);
  font-variant-numeric: tabular-nums;
}

.console-tile .val small { font-size: 0.7rem; color: var(--text-light); margin-left: 0.25rem; }

.console-chart {
  position: relative;
  height: 380px;
  padding: 0.5rem;
  border: 1px solid var(--scada-border);
  border-radius: var(--radius-md);
  background: rgba(15, 23, 42, 0.45);
}

.console-chart canvas { width: 100% !important; height: 100% !important; }

.console-section-title {
  margin: 1.1rem 0 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.66rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-light);
}

/* Filas de sliders en vivo */
.live-row {
  display: grid;
  grid-template-columns: 44px minmax(120px, 170px) minmax(0, 1fr) 72px;
  align-items: center;
  gap: 0.6rem;
  padding: 0.3rem 0;
}

.live-row label { font-family: var(--font-mono); font-size: 0.8rem; font-weight: 600; color: var(--text-white); }
.live-row small { font-family: var(--font-mono); font-size: 0.68rem; color: var(--text-light); }
.live-row span { font-family: var(--font-mono); font-size: 0.82rem; text-align: right; color: var(--brand-cyan); font-variant-numeric: tabular-nums; }

.live-row input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 9999px;
  background: var(--scada-surface-elevated);
  cursor: pointer;
}

.live-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--brand-cyan);
  border: 2px solid var(--scada-bg);
  box-shadow: 0 0 0 1px var(--brand-cyan);
}

.live-row input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--brand-cyan);
  border: 2px solid var(--scada-bg);
}

.live-row input[type="range"]:disabled { cursor: default; }
.live-row input[type="range"]:disabled::-webkit-slider-thumb { background: var(--text-light); box-shadow: 0 0 0 1px var(--text-light); }

.console-check {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0.4rem 0 0.2rem;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--text-white);
  cursor: pointer;
}

.console-check input { accent-color: var(--brand-cyan); }

.console-divider { border: 0; border-top: 1px solid var(--scada-border); margin: 0.8rem 0; }

.console-note { margin: 0.5rem 0 0; font-size: 0.8rem; color: var(--text-light); }

/* -----------------------------------------------------------------------------
   Documentación técnica (guías, teoría, manuales)
   ----------------------------------------------------------------------------- */
.doc-section { padding: 4rem 0; border-top: 1px solid var(--border-light); }
.doc-section.alt { background: var(--bg-white); }

.doc-card {
  max-width: 900px;
  margin: 0 auto;
}

.doc-head { margin-bottom: 2rem; }

.doc-head h2 {
  margin: 0.9rem 0 0.5rem;
  font-size: clamp(1.7rem, 2.6vw, 2.2rem);
  font-weight: 800;
  letter-spacing: -0.025em;
  line-height: 1.2;
  color: var(--text-title);
}

.doc-head p { margin: 0; font-size: 1.05rem; color: var(--text-body); line-height: 1.7; }

.prose { font-size: 1rem; line-height: 1.75; color: var(--text-body); }
.prose > *:first-child { margin-top: 0; }
.prose p { margin: 0 0 1rem; }
.prose strong { color: var(--text-title); }

.prose h3 {
  margin: 2.5rem 0 0.8rem;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.015em;
  color: var(--text-title);
}

.prose h4 {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 2rem 0 0.7rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border-light);
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-title);
}

.prose h4:first-child, .prose h3 + h4 { border-top: none; padding-top: 0; }
.prose h5 { margin: 1.4rem 0 0.5rem; font-size: 0.95rem; font-weight: 700; color: var(--text-title); }

.prose ul, .prose ol { margin: 0 0 1.1rem; padding-left: 1.3rem; }
.prose li { margin: 0.35rem 0; }
.prose li::marker { color: var(--brand-blue); }
.prose li ul { margin: 0.4rem 0 0.2rem; }

.prose code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  background: var(--bg-subtle);
  color: var(--brand-blue-hover);
}

.prose pre {
  margin: 0 0 1.2rem;
  padding: 1rem 1.1rem;
  overflow-x: auto;
  border-radius: var(--radius-md);
  background: var(--scada-bg);
  color: #e2e8f0;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  line-height: 1.6;
}

.prose pre code { background: none; padding: 0; color: var(--brand-cyan); }

.prose table {
  width: 100%;
  margin: 0 0 1.25rem;
  border-collapse: separate;
  border-spacing: 0;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  overflow: hidden;
  font-size: 0.9rem;
}

.prose th {
  background: var(--bg-subtle);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  text-align: left;
  padding: 0.55rem 0.75rem;
}

.prose td { padding: 0.55rem 0.75rem; border-top: 1px solid var(--border-light); vertical-align: top; }

.prose mjx-container[display="true"] {
  margin: 1rem 0 1.25rem !important;
  padding: 0.9rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--bg-titanium);
  border: 1px solid var(--border-light);
  overflow-x: auto;
}

.callout {
  margin: 0 0 1.25rem;
  padding: 0.9rem 1.1rem;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(0, 82, 204, 0.2);
  background: var(--brand-blue-soft);
  font-size: 0.95rem;
}

.callout.warn { border-color: #fcd34d; background: #fffbeb; color: #92400e; }

/* Índice lateral de documentación */
.doc-layout { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 3rem; align-items: start; }

.doc-toc {
  position: sticky;
  top: 96px;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  padding-right: 0.5rem;
}

.doc-toc .field-label { display: block; margin-bottom: 0.7rem; }
.doc-toc a {
  display: block;
  padding: 0.3rem 0 0.3rem 0.75rem;
  border-left: 2px solid var(--border-light);
  font-size: 0.86rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: var(--transition);
}

.doc-toc a:hover, .doc-toc a.active { color: var(--brand-blue); border-left-color: var(--brand-blue); }

/* -----------------------------------------------------------------------------
   Responsive
   ----------------------------------------------------------------------------- */
@media (max-width: 1024px) {
  .tool-grid { grid-template-columns: 1fr; }
  .doc-layout { grid-template-columns: 1fr; }
  .doc-toc { position: static; max-height: none; }
  .console-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .tool-page { padding: 2.25rem 0 3rem; }
  .field-grid, .field-grid.cols-3 { grid-template-columns: 1fr; }
  .live-row { grid-template-columns: 38px minmax(0, 1fr) 64px; }
  .live-row small { display: none; }
  .console-chart { height: 300px; }
}
