/* ============================================================
   PureAnalyt — pa-app.css
   Entorno de trabajo (UX). Requiere tokens.css + brand.css antes.
   Responsive real: desktop (2 columnas) y móvil (drawer + bottom sheet).
   ============================================================ */

/* ---------- Shell ---------- */
html, body { height: 100%; }
body { overflow-x: hidden; }
.app { min-height: 100vh; display: flex; flex-direction: column; }

/* ---------- Appbar ---------- */
.appbar {
  position: sticky; top: 0; z-index: 60;
  display: flex; align-items: center; gap: var(--space-4);
  padding: 11px clamp(14px, 3vw, 30px);
  background: color-mix(in oklab, var(--bg) 82%, transparent);
  backdrop-filter: saturate(140%) blur(16px); -webkit-backdrop-filter: saturate(140%) blur(16px);
  border-bottom: 1px solid var(--line);
}
.appbar .brandrow { display: inline-flex; align-items: center; gap: 9px; }
.appbar .wordmark { font-size: 1.12rem; }
.appbar .brand-tag { font-family: var(--font-mono); font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); border-left: 1px solid var(--line-strong); padding-left: 10px; margin-left: 4px; }
.appbar .spacer { flex: 1; }
.appbar .ab-chips { display: flex; gap: 6px; }
.appbar .ab-chip { font-family: var(--font-mono); font-size: 10.5px; color: var(--muted); border: 1px solid var(--line); border-radius: var(--radius-pill); padding: 4px 10px; white-space: nowrap; }
.appbar #clock { font-family: var(--font-mono); font-size: var(--text-sm); color: var(--ink-2); letter-spacing: .04em; }

/* Pastilla de estado del sistema (viva) */
.sys-pill { display: inline-flex; align-items: center; gap: 8px; padding: 6px 13px; border-radius: var(--radius-pill); border: 1px solid var(--line-strong); background: var(--panel); font-size: var(--text-sm); white-space: nowrap; transition: all var(--dur); }
.sys-pill .sys-led { width: 8px; height: 8px; border-radius: 50%; background: var(--muted-2); flex: none; transition: all var(--dur); }
.sys-pill.s-off { color: var(--muted); }
.sys-pill.s-off .sys-led { background: var(--muted-2); }
.sys-pill.s-start { color: var(--warn); border-color: color-mix(in oklab, var(--warn) 40%, transparent); }
.sys-pill.s-start .sys-led { background: var(--warn); animation: pulse-led 1s infinite; }
.sys-pill.s-on { color: var(--success); border-color: color-mix(in oklab, var(--success) 40%, transparent); background: var(--success-soft); }
.sys-pill.s-on .sys-led { background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }
.sys-pill.s-inject { color: var(--brand); border-color: color-mix(in oklab, var(--brand) 45%, transparent); background: var(--brand-soft); }
.sys-pill.s-inject .sys-led { background: var(--brand); animation: pulse-led .7s infinite; }
@keyframes pulse-led { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

.themebtn .dot { width: 15px; height: 15px; border-radius: 50%; background: var(--grad-brand); }

/* ---------- Workspace ---------- */
.workspace { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 354px); gap: clamp(14px, 2vw, 26px); padding: clamp(14px, 2.2vw, 26px) clamp(14px, 3vw, 30px) 0; align-items: start; }
.stage { min-width: 0; display: flex; flex-direction: column; gap: var(--space-4); padding-bottom: 130px; }

/* ---------- Tabs ---------- */
#appTabs { display: flex; gap: 4px; background: var(--panel); border: 1px solid var(--line); padding: 5px; border-radius: var(--radius-md); position: sticky; top: 64px; z-index: 30; overflow-x: auto; }
.apptab { display: inline-flex; align-items: center; gap: 8px; font-family: var(--font-sans); font-weight: 600; font-size: var(--text-sm); color: var(--muted); background: transparent; border: none; padding: 9px 15px; border-radius: var(--radius-sm); cursor: pointer; transition: all var(--dur); white-space: nowrap; position: relative; }
.apptab .apptab-ic { display: inline-flex; opacity: .8; }
.apptab .apptab-ic svg { width: 16px; height: 16px; }
.apptab:hover:not(.active) { color: var(--ink-2); background: var(--panel-2); }
.apptab.active { background: var(--panel-3); color: var(--ink); box-shadow: var(--shadow-sm); }
.apptab.is-gated { color: var(--muted-2); }
.apptab .apptab-lock { display: inline-flex; margin-left: 2px; opacity: .7; }
.apptab .apptab-lock svg { width: 13px; height: 13px; }

/* ---------- Paneles ---------- */
.panel { display: none; }
.panel.is-active { display: block; animation: panel-in var(--dur-slow) var(--ease); }
@keyframes panel-in { from { transform: translateY(7px); } to { transform: none; } }
.panel-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: clamp(16px, 2.4vw, 26px); }

.cfg-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: var(--space-5); }
.panel-h { font-family: var(--font-display); font-weight: 600; font-size: var(--text-xl); }
.panel-sub { color: var(--muted); font-size: var(--text-sm); margin-top: 4px; max-width: 56ch; }
.cfg-count { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: var(--radius-pill); padding: 5px 11px; white-space: nowrap; }

/* ---------- Config: tarjetas de módulo ---------- */
.cfg-list { display: flex; flex-direction: column; gap: 10px; }
.modcard { border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--panel-2); overflow: hidden; transition: border-color var(--dur), box-shadow var(--dur); }
.modcard.is-open { border-color: color-mix(in oklab, var(--brand) 45%, transparent); box-shadow: var(--glow); }
.modcard-h { width: 100%; display: flex; align-items: center; gap: 14px; padding: 14px 16px; background: transparent; border: none; cursor: pointer; text-align: left; }
.modcard-num { font-size: var(--text-sm); color: var(--brand); font-weight: 500; width: 22px; flex: none; }
.modcard-tt { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.modcard-name { font-family: var(--font-display); font-weight: 600; font-size: var(--text-md); color: var(--ink); }
.modcard-spec { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.modcard-chev { color: var(--muted); display: inline-flex; transition: transform var(--dur); }
.modcard-chev svg { width: 17px; height: 17px; }
.modcard.is-open .modcard-chev { transform: rotate(90deg); color: var(--brand); }
.modcard-body { display: none; padding: 4px 16px 18px; flex-direction: column; gap: 14px; }
.modcard.is-open .modcard-body { display: flex; }
.modcard-hint { font-size: var(--text-sm); color: var(--ink-2); }
.cf-val { font-family: var(--font-mono); color: var(--brand); font-weight: 500; }
.cf-note { font-family: var(--font-mono); font-size: 11px; color: var(--muted); }
/* Slider con valor editable: el número va a la derecha del label. */
.field > label { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.cf-valedit { display: inline-flex; align-items: center; gap: 5px; }
.cf-numin { width: 64px; padding: 3px 7px; text-align: right; font-size: 12px; font-weight: 500;
  background: var(--panel-2); border: 1px solid var(--line-strong); border-radius: var(--radius-xs);
  color: var(--brand); -moz-appearance: textfield; }
.cf-numin:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
.cf-unit { font-size: 11px; color: var(--muted); }
/* Panel de configuración del mapa de resolución (DoE) */
.doe-axis { margin-bottom: 14px; }
.doe-axis .lib-h { margin-bottom: 8px; color: var(--ink-2); }
.doe-grid { display: grid; grid-template-columns: 1.5fr 1fr 1fr 0.85fr; gap: 9px; align-items: end; }
.doe-grid .field > label { justify-content: flex-start; }
.doe-grid .input.mono { padding: 8px 10px; }
@media (max-width: 620px) { .doe-grid { grid-template-columns: 1fr 1fr; } }
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
button.chip { cursor: pointer; background: var(--panel); transition: border-color var(--dur), color var(--dur), background var(--dur); }
button.chip:hover { border-color: color-mix(in oklab, var(--brand) 50%, transparent); color: var(--ink-2); }
.field.is-locked { opacity: .85; }
.field.is-locked .range { opacity: .4; cursor: not-allowed; }
.chip { padding: 6px 11px; border: 1px solid var(--line); border-radius: 999px; font-size: 12px; color: var(--muted); font-family: var(--font-mono); }
.chip.is-brand { border-color: var(--brand); color: var(--brand); background: color-mix(in oklab, var(--brand) 12%, transparent); }
/* Estado de carga de la muestra */
.cf-loaded { display: flex; align-items: center; gap: 10px; margin-top: 4px; padding: 9px 12px; border: 1px solid var(--line); border-radius: var(--radius-2, 10px); background: var(--panel); }
.cf-loaded-k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.cf-loaded-n { font-size: 18px; font-weight: 700; color: var(--ink-2); }
.cf-loaded-n.is-ok { color: var(--brand); }
.cf-loaded-msg { font-size: 12px; color: var(--muted); margin-left: auto; }
/* Biblioteca local de analitos */
.lib { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; padding: 12px; border: 1px dashed var(--line); border-radius: var(--radius-2, 10px); }
.lib-h { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-2); }
.lib-results { display: flex; flex-direction: column; gap: 2px; max-height: 220px; overflow-y: auto; margin-bottom: 10px; }
.lib-results:empty { display: none; }
.lib-result { display: flex; align-items: center; justify-content: space-between; gap: 10px; text-align: left; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--ink); cursor: pointer; transition: border-color var(--dur), background var(--dur); }
.lib-result:hover { border-color: var(--brand); background: var(--panel-2); }
.lib-result.is-sel { border-color: var(--brand); background: color-mix(in oklab, var(--brand) 12%, transparent); }
.lib-result[disabled] { opacity: .55; cursor: default; }
.lib-result-nm { font-size: 13px; }
.lib-noresult { padding: 8px 2px; }
.lib-props-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.lib-prop { display: flex; flex-direction: column; gap: 2px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.lib-prop .k { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .02em; }
.lib-prop .v { font-size: 13px; color: var(--ink); font-weight: 500; }
.lib-chips { display: flex; flex-wrap: wrap; gap: 7px; }
.lib-chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 6px 5px 11px; border: 1px solid var(--brand); border-radius: 999px; font-size: 12px; color: var(--brand); background: color-mix(in oklab, var(--brand) 12%, transparent); }
.lib-chip button { display: inline-flex; align-items: center; justify-content: center; width: 17px; height: 17px; border: none; border-radius: 50%; background: color-mix(in oklab, var(--brand) 22%, transparent); color: var(--brand); cursor: pointer; font-size: 13px; line-height: 1; }
.lib-chip button:hover { background: var(--brand); color: var(--bg, #0b0e15); }
/* Checklist de analitos del preset */
.anlist { display: flex; flex-direction: column; gap: 9px; margin-top: 4px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius-2, 10px); background: var(--panel); }
.anlist-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.anlist-h .lib-h { color: var(--ink-2); }
.anlist-act { display: flex; gap: 6px; }
.an-allbtn { padding: 3px 9px; border: 1px solid var(--line); border-radius: 999px; background: transparent; color: var(--muted); font-family: var(--font-mono); font-size: 11px; cursor: pointer; }
.an-allbtn:hover { border-color: var(--brand); color: var(--brand); }
.anlist-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.an-pick { display: flex; align-items: center; gap: 9px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; text-align: left; transition: border-color .12s, color .12s; }
.an-pick:hover { border-color: color-mix(in oklab, var(--brand) 50%, var(--line)); }
.an-pick.is-on { border-color: var(--brand); color: var(--ink); }
.an-box { display: inline-flex; align-items: center; justify-content: center; width: 17px; height: 17px; flex: none; border: 1.5px solid var(--line); border-radius: 5px; color: var(--bg, #0b0e15); }
.an-pick.is-on .an-box { background: var(--brand); border-color: var(--brand); }
.an-box svg { width: 12px; height: 12px; }
.an-nm { font-size: 13px; }
/* Filas de analito con concentración editable (ppm) */
.anlist-rows { display: flex; flex-direction: column; gap: 5px; }
.an-row { display: flex; align-items: center; gap: 8px; }
.an-row .an-pick { flex: 1; min-width: 0; }
.an-conc-wrap { display: inline-flex; align-items: center; gap: 4px; flex: none; }
.an-conc { width: 60px; padding: 5px 7px; text-align: right; font-size: 12px; background: var(--panel-2); border: 1px solid var(--line-strong); border-radius: 6px; color: var(--ink); -moz-appearance: textfield; }
.an-conc:focus { outline: none; border-color: var(--brand); }
.lib-chip .an-conc { width: 50px; padding: 2px 5px; margin: 0 3px 0 6px; }
/* Equivalencia de columnas (HSM) */
.hsm-block { margin-top: var(--space-4); padding-top: var(--space-4); border-top: 1px dashed var(--line); }
.hsm-block .lib-h { margin-bottom: 6px; }
.hsm-block .cf-note { margin: 0 0 8px; line-height: 1.45; }
.hsm-top { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.hsm-chip { font-family: var(--font-mono); font-size: 11px; padding: 3px 8px; border: 1px solid var(--line-strong); border-radius: 999px; color: var(--ink-2); background: var(--panel-2); }
.hsm-res { font-family: var(--font-mono); font-size: 13px; font-weight: 600; margin-top: 8px; }
.scan-range { display: flex; align-items: center; gap: 8px; }
.scan-range .input { width: 100px; }
.field-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.field-row > label { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--ink-2); letter-spacing: .03em; text-transform: uppercase; }
.methods-bar { display: flex; align-items: center; gap: 8px; margin-bottom: var(--space-4); flex-wrap: wrap; }
.methods-bar #cf-mname { flex: 1 1 160px; min-width: 140px; }
.methods-bar #cf-mload { flex: 1 1 180px; min-width: 150px; }
.methods-bar .btn { flex: none; }
.cfg-warn { margin-top: var(--space-5); }
.cfg-warn + .cfg-warn { margin-top: 10px; }
.diag-list { margin: 4px 0 0; padding-left: 16px; }
.diag-list li { font-size: var(--text-sm); color: var(--ink-2); margin-top: 3px; line-height: 1.4; }
.diag-list li::marker { color: currentColor; }

/* ---------- Análisis ---------- */
.an-metrics { display: grid; grid-template-columns: repeat(5, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius-md); overflow: hidden; margin-bottom: var(--space-4); }
.an-metric { background: var(--panel); padding: 12px 14px; }
.an-metric .k { font-size: 10.5px; color: var(--muted); letter-spacing: .04em; }
.an-metric .v { font-size: var(--text-lg); color: var(--ink); margin-top: 3px; font-weight: 500; }
.an-metric .v .u { font-size: 11px; color: var(--muted); }

.chromo-card { border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--panel-2); padding: 14px 16px; }
.chromo-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.chromo-h .mono { font-size: 11px; color: var(--muted); }
.chromo-svg { display: block; }
.chromo-trace { stroke-dasharray: 2400; stroke-dashoffset: 2400; animation: trace-in 1.6s var(--ease-out) forwards; }
@keyframes trace-in { to { stroke-dashoffset: 0; } }
.chromo-empty { display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center; padding: 38px 20px; color: var(--muted); }
.chromo-empty svg { width: 40px; height: 40px; color: var(--brand); opacity: .8; }
.chromo-empty p { font-size: var(--text-sm); line-height: 1.5; }

.an-table-wrap { margin-top: var(--space-4); border: 1px solid var(--line); border-radius: var(--radius-md); overflow: hidden; }
.an-table { font-size: var(--text-sm); }
/* Filas seleccionables (modo MS) + espectro */
.an-table .peak-row { cursor: pointer; transition: background var(--dur); }
.an-table .peak-row:hover { background: var(--panel-2); }
.an-table .peak-row.is-active { background: color-mix(in oklab, var(--brand) 12%, transparent); }
.ms-haslib { color: var(--brand); font-size: 9px; vertical-align: middle; }
.ms-tablehint { margin-top: 6px; }
.ms-spec-panel { display: none; }
.ms-spec-panel.is-open { display: block; margin-top: var(--space-4); border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--panel-2); padding: 14px 16px; }
.ms-spec-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.ms-spec-title { font-family: var(--font-display); font-weight: 600; font-size: var(--text-md); }
.ms-spec-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.ms-spec-svg { display: block; width: 100%; height: auto; }
.ms-spec-foot { font-size: 10.5px; color: var(--muted); margin-top: 8px; line-height: 1.4; }
.ms-spec-foot a { color: var(--brand); text-decoration: none; border-bottom: 1px dotted currentColor; }
.an-actions { display: flex; gap: 10px; margin-top: var(--space-4); justify-content: flex-end; flex-wrap: wrap; }
.an-actions.center { justify-content: center; }
.methodchip { display: inline-flex; align-items: center; gap: 7px; font-size: 11.5px; color: var(--ink-2); background: var(--panel-2); border: 1px solid var(--line-strong); border-radius: var(--radius-pill); padding: 6px 12px; cursor: pointer; transition: border-color var(--dur), color var(--dur); white-space: nowrap; }
.methodchip:hover { border-color: var(--brand); color: var(--brand); }
.methodchip svg { width: 13px; height: 13px; }

/* Estado offline (gating) */
.offline { text-align: center; padding: clamp(30px, 6vw, 60px) 20px; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.offline-glyph { width: 68px; height: 68px; border-radius: var(--radius-lg); display: grid; place-items: center; background: var(--panel-2); border: 1px solid var(--line-strong); color: var(--brand); }
.offline-glyph svg { width: 32px; height: 32px; }
.offline-sub { color: var(--muted); font-size: var(--text-md); max-width: 48ch; }
.offline-steps { margin: 8px 0; }
.ministep { display: inline-flex; align-items: center; gap: 7px; font-family: var(--font-mono); font-size: 11px; color: var(--muted-2); }
.ministep i { width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; font-size: 10px; border: 1px solid var(--line-strong); color: var(--muted); font-style: normal; }
.ministep.done { color: var(--success); } .ministep.done i { background: var(--success-soft); border-color: transparent; color: var(--success); }
.ministep.now { color: var(--brand); } .ministep.now i { background: var(--brand); border-color: transparent; color: var(--brand-ink); }
.ministep-sep { display: inline-block; width: 22px; height: 1px; background: var(--line-strong); margin: 0 8px; vertical-align: middle; }

/* ---------- Mapa ---------- */
.mp-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: var(--space-4); }
.mp-stat { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 11px 13px; }
.mp-stat .k { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.mp-stat .v { font-size: var(--text-lg); color: var(--ink); margin-top: 4px; }
.mp-stat .v.is-ok { color: var(--success); }
.mp-card { border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--panel-2); padding: 14px 16px; }
/* Ejes del mapa: valores en X (abajo) y Y (izquierda) */
.mp-plot { display: flex; align-items: stretch; gap: 6px; }
.mp-plot .mp-grid { flex: 1; }
.mp-yaxis { display: flex; flex-direction: column; justify-content: space-between; width: 40px; flex: none; text-align: right; padding-right: 5px; }
.mp-tick { font-family: var(--font-mono); font-size: 10px; color: var(--muted); white-space: nowrap; }
.mp-xaxis { display: flex; justify-content: space-between; padding: 5px 0 0 46px; }
.mp-xaxis.is-cat { flex-wrap: wrap; gap: 2px 6px; }
.mp-xaxis.is-cat .mp-tick, .mp-yaxis.is-cat .mp-tick { font-size: 8.5px; }
.mp-grid { position: relative; display: grid; gap: 0; border-radius: var(--radius-sm); overflow: hidden; aspect-ratio: 18 / 9; }
.mp-cell { width: 100%; height: 100%; }
.mp-cell.is-space { box-shadow: inset 0 0 0 1.5px rgba(255,255,255,.85); }
.doe-check { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: var(--text-sm); color: var(--ink-2); cursor: pointer; }
.doe-check input { width: 15px; height: 15px; accent-color: var(--brand); }
.mp-marker { position: absolute; transform: translate(-50%, 50%); font-size: 17px; line-height: 1; text-shadow: 0 0 3px rgba(0,0,0,.5); }
.mp-marker.mp-opt { color: #f6c026; }
.mp-marker.mp-cur { color: #fff; }
.mp-legend { display: flex; align-items: center; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.mp-legend .mono { font-size: 10px; color: var(--muted); }
.mp-bar { flex: 1; min-width: 80px; height: 9px; border-radius: 5px; background: linear-gradient(90deg,#d73027,#f46d43,#fdae61,#fee08b,#a6d96a,#66bd63,#1a9850); }
.mp-leg-item { font-family: var(--font-mono); font-size: 11px; color: var(--ink-2); display: inline-flex; align-items: center; gap: 5px; }
.mp-leg-item b.mp-opt { color: #f6c026; } .mp-leg-item b.mp-cur { color: var(--ink); }

/* ============================================================
   INSTRUMENT RAIL (ancla de estado)  — siempre oscuro (modo instrumento)
   ============================================================ */
.instrument-rail { position: sticky; top: 76px; display: flex; flex-direction: column; gap: 12px; }
.rail-cta { width: 100%; }
.rail-cta-wrap { display: flex; flex-direction: column; gap: 6px; }
.rail-off { width: 100%; margin-top: 2px; color: var(--muted); }
.rail-off:hover { color: var(--danger); }
#railNote { font-family: var(--font-mono); font-size: 10.5px; color: var(--muted); text-align: center; }

.pai { background: #0b0e15; border: 1px solid rgba(226,231,247,.12); border-radius: var(--radius-lg); padding: 16px 16px 14px; position: relative; overflow: hidden; color: #aeb9d8; }
.pai::before { content: ""; position: absolute; inset: 0; background-image: repeating-linear-gradient(0deg, rgba(132,150,205,.05) 0 1px, transparent 1px 56px), repeating-linear-gradient(90deg, rgba(132,150,205,.05) 0 1px, transparent 1px 56px); pointer-events: none; }
.pai > * { position: relative; }
.pai-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.pai-ttl { font-family: var(--font-mono); font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: #8590a6; }
.pai-state { display: inline-flex; align-items: center; gap: 7px; font-family: var(--font-mono); font-size: 10px; letter-spacing: .06em; text-transform: uppercase; color: #8590a6; }
.pai-state .pai-pwr { width: 7px; height: 7px; border-radius: 50%; background: #5c6678; transition: all var(--dur); }
.pai-state.s-starting { color: #f0a93b; } .pai-state.s-starting .pai-pwr { background: #f0a93b; animation: pulse-led 1s infinite; }
.pai-state.s-on { color: #2fd296; } .pai-state.s-on .pai-pwr { background: #2fd296; box-shadow: 0 0 8px #2fd296; }
.pai-state.s-inject { color: #5479ff; } .pai-state.s-inject .pai-pwr { background: #5479ff; animation: pulse-led .7s infinite; }

/* Botellas */
.pai-bottles { display: flex; align-items: flex-end; justify-content: center; gap: 14px; height: 34px; margin-bottom: 6px; position: relative; }
.pai-bottle { width: 17px; height: 26px; border: 1.4px solid rgba(174,185,216,.55); border-radius: 3px 3px 5px 5px; position: relative; }
.pai-bottle::before { content: ""; position: absolute; top: -5px; left: 50%; transform: translateX(-50%); width: 6px; height: 5px; background: rgba(174,185,216,.55); border-radius: 2px 2px 0 0; }
.pai-bottle::after { content: ""; position: absolute; left: 1.5px; right: 1.5px; bottom: 1.5px; height: 45%; background: rgba(84,121,255,.22); border-radius: 1px; transition: background var(--dur); }
.pai.is-flowing .pai-bottle::after { background: rgba(84,121,255,.42); }
.pai-bottle.is-mid::after { height: 60%; }
.pai-bottles-lab { position: absolute; bottom: -2px; right: 4px; font-family: var(--font-mono); font-size: 8.5px; color: #5c6678; letter-spacing: .05em; }

/* Torre */
.pai-tower { position: relative; padding-left: 6px; }
.pai-conduit { position: absolute; left: 13px; top: -4px; bottom: 6px; width: 4px; z-index: 0; }
.pai-flowline { position: absolute; left: 1px; top: 0; bottom: 0; width: 2px; background: rgba(84,121,255,.28); border-radius: 2px; }
.pai.is-flowing .pai-flowline { background: linear-gradient(180deg, rgba(84,121,255,.15) 0%, rgba(84,121,255,.85) 50%, rgba(84,121,255,.15) 100%); background-size: 100% 60px; animation: flow-down 1.1s linear infinite; }
@keyframes flow-down { from { background-position: 0 -60px; } to { background-position: 0 60px; } }
.pai-pulse { position: absolute; left: -1px; width: 6px; height: 6px; border-radius: 50%; background: #5479ff; box-shadow: 0 0 7px #5479ff; opacity: 0; top: 0; }
.pai.is-flowing .pai-pulse { animation: pulse-travel 1.7s linear infinite; }
.pai.is-flowing .pai-pulse.p2 { animation-delay: .57s; }
.pai.is-flowing .pai-pulse.p3 { animation-delay: 1.14s; }
.pai.is-injecting .pai-pulse { animation-duration: .8s; }
@keyframes pulse-travel { 0% { top: 0; opacity: 0; } 8% { opacity: 1; } 92% { opacity: 1; } 100% { top: 100%; opacity: 0; } }

.pai-stack { display: flex; flex-direction: column; gap: 6px; position: relative; z-index: 1; }
.pai-bay { display: flex; align-items: center; gap: 11px; width: 100%; text-align: left; padding: 9px 11px 9px 26px; border: 1.2px solid rgba(174,185,216,.22); border-radius: 8px; background: rgba(84,121,255,.03); cursor: pointer; transition: all var(--dur); position: relative; }
.pai-bay .pai-port { position: absolute; left: 5px; top: 50%; transform: translateY(-50%); width: 9px; height: 9px; border-radius: 50%; border: 1.2px solid rgba(174,185,216,.4); background: #0b0e15; transition: all var(--dur); }
.pai-bay .pai-icon { color: rgba(174,185,216,.85); flex: none; transition: color var(--dur); }
.pai-bay .pai-icon svg { width: 38px; height: 28px; display: block; }
.pai-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.pai-num { font-family: var(--font-mono); font-size: 9px; color: #5479ff; letter-spacing: .1em; }
.pai-name { font-family: var(--font-display); font-weight: 600; font-size: 12.5px; color: #c7d0e8; line-height: 1.15; }
.pai-spec { font-family: var(--font-mono); font-size: 9.5px; color: #8590a6; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pai-led { width: 8px; height: 8px; border-radius: 50%; background: rgba(132,150,205,.22); flex: none; transition: all var(--dur); }
.pai-led.led-ready { background: #5479ff; box-shadow: 0 0 5px rgba(84,121,255,.6); }
.pai-led.led-on { background: #2fd296; box-shadow: 0 0 7px #2fd296; }
.pai-led.led-warn { background: #ff5e74; box-shadow: 0 0 7px #ff5e74; animation: pulse-led 1s infinite; }
.pai-bay:hover, .pai-bay.is-hover { border-color: rgba(174,185,216,.5); background: rgba(84,121,255,.07); }
.pai-bay.is-active { border-color: #5479ff; background: rgba(84,121,255,.12); box-shadow: 0 0 0 1px rgba(84,121,255,.3), 0 8px 24px rgba(84,121,255,.14); }
.pai-bay.is-active .pai-icon, .pai-bay.is-active .pai-name { color: #91a7ff; }
.pai-bay.is-active .pai-port { border-color: #5479ff; background: #5479ff; box-shadow: 0 0 7px #5479ff; }
.pai-bay.is-dim { opacity: .5; }

.pai-foot { display: flex; gap: 14px; margin-top: 12px; padding-top: 11px; border-top: 1px solid rgba(226,231,247,.09); }
.pai-legend { display: inline-flex; align-items: center; gap: 6px; font-family: var(--font-mono); font-size: 9px; color: #8590a6; letter-spacing: .04em; }
.pai-dot { width: 7px; height: 7px; border-radius: 50%; }
.pai-dot.d-on { background: #2fd296; } .pai-dot.d-flow { background: #5479ff; } .pai-dot.d-warn { background: #ff5e74; }

/* ============================================================
   COACH (asistente)
   ============================================================ */
#coach { position: fixed; left: clamp(14px, 3vw, 30px); bottom: 16px; width: min(640px, calc(100% - 388px - clamp(14px,3vw,30px) - 30px)); z-index: 55; background: color-mix(in oklab, var(--panel) 92%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border: 1px solid var(--line-strong); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); overflow: hidden; transition: border-color var(--dur); }
#coach.is-intercept { border-color: color-mix(in oklab, var(--warn) 55%, transparent); }
.coach-rail { display: flex; align-items: center; gap: 4px; padding: 9px 16px; background: var(--panel-2); border-bottom: 1px solid var(--line); overflow-x: auto; }
.coach-step { display: inline-flex; align-items: center; gap: 7px; font-size: 11px; color: var(--muted-2); white-space: nowrap; }
.coach-step:not(:last-child)::after { content: ""; width: 16px; height: 1px; background: var(--line-strong); margin-left: 4px; }
.coach-step i { width: 17px; height: 17px; border-radius: 50%; display: grid; place-items: center; font-size: 9.5px; font-family: var(--font-mono); border: 1px solid var(--line-strong); color: var(--muted); }
.coach-step i svg { width: 10px; height: 10px; }
.coach-step.done { color: var(--success); } .coach-step.done i { background: var(--success-soft); border-color: transparent; color: var(--success); }
.coach-step.now { color: var(--brand); font-weight: 600; } .coach-step.now i { background: var(--brand); border-color: transparent; color: var(--brand-ink); }
.coach-body { display: flex; align-items: center; gap: 13px; padding: 13px 16px; }
.coach-mark { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); flex: none; }
.coach-mark.warn { background: var(--warn-soft); color: var(--warn); }
.coach-mark svg { width: 20px; height: 20px; }
.coach-tx { flex: 1; min-width: 0; }
.coach-ttl { font-family: var(--font-display); font-weight: 600; font-size: var(--text-md); color: var(--ink); }
.coach-tx p { font-size: var(--text-sm); color: var(--ink-2); margin-top: 1px; }
.coach-warn { display: flex; align-items: flex-start; gap: 6px; font-size: 11px; color: var(--warn); margin-top: 6px; }
.coach-warn svg { width: 13px; height: 13px; flex: none; margin-top: 1px; }
.coach-cta { flex: none; }
/* Guía minimizable: pastilla compacta + botón de colapsar */
#coach.is-min { width: auto; right: auto; }
.coach-mini { display: inline-flex; align-items: center; gap: 11px; width: 100%; padding: 9px 13px; background: transparent; border: none; cursor: pointer; color: var(--ink); text-align: left; }
.coach-mini-mark { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); flex: none; }
.coach-mini-mark svg { width: 17px; height: 17px; }
.coach-mini-tx { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.coach-mini-tx b { font-size: 13px; }
.coach-mini-tx .mono { font-size: 10.5px; color: var(--muted); white-space: nowrap; }
.coach-mini > svg:last-child { width: 15px; height: 15px; color: var(--muted); margin-left: 8px; flex: none; }
.coach-collapse { position: absolute; top: 7px; right: 9px; z-index: 3; width: 24px; height: 24px; border-radius: 6px; border: none; background: transparent; color: var(--muted); cursor: pointer; display: grid; place-items: center; transition: background var(--dur), color var(--dur); }
.coach-collapse:hover { background: var(--panel-2); color: var(--ink); }
.coach-collapse svg { width: 16px; height: 16px; }
#coach:not(.is-min) .coach-rail { padding-right: 30px; }

/* FAB del instrumento (solo móvil) */
.rail-toggle { display: none; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 960px) {
  .workspace { grid-template-columns: 1fr; padding-bottom: 0; }
  .stage { padding-bottom: 200px; }
  #appTabs { top: 60px; }

  /* Instrument rail -> drawer derecho */
  .instrument-rail { position: fixed; top: 0; right: 0; height: 100dvh; width: min(340px, 88vw); padding: 64px 16px 16px; background: var(--bg); border-left: 1px solid var(--line-strong); box-shadow: var(--shadow-lg); transform: translateX(102%); transition: transform var(--dur-slow) var(--ease); z-index: 70; overflow-y: auto; }
  body.rail-open .instrument-rail { transform: none; }
  body.rail-open::after { content: ""; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 65; }
  .rail-toggle { display: inline-flex; align-items: center; gap: 7px; }

  /* Coach -> bottom sheet */
  #coach { left: 8px; right: 8px; width: auto; bottom: 8px; }
  .an-metrics { grid-template-columns: repeat(3, 1fr); }
  .an-metric:nth-child(4), .an-metric:nth-child(5) { border-top: 1px solid var(--line); }
  .mp-summary { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 540px) {
  .appbar .ab-chips { display: none; }
  .appbar #clock { display: none; }
  .an-metrics { grid-template-columns: repeat(2, 1fr); }
  .cfg-head { flex-direction: column; gap: 8px; }
  .coach-rail .coach-step b { display: none; }
  .coach-body { flex-wrap: wrap; }
  .coach-cta { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .pai.is-flowing .pai-flowline, .pai.is-flowing .pai-pulse, .chromo-trace { animation: none; }
  .chromo-trace { stroke-dashoffset: 0; }
}
