:root {
  color-scheme: light dark;
  --bg: #f5f4f1;
  --surface: #ffffff;
  --surface-2: #eeece7;
  --border: #d9d6cf;
  --text: #17181a;
  --muted: #5b6068;
  --accent: #a65f00;
  --accent-ink: #ffffff;
  --accent-soft: #f6e7cf;
  --ok: #1d7f4e;
  --test: #8a6200;
  --plan: #2462b8;
  --danger: #b3261e;
  --warn: #8a4b00;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 4px 16px rgb(0 0 0 / .05);
  --radius: 14px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101113;
    --surface: #18191c;
    --surface-2: #212327;
    --border: #2e3136;
    --text: #eef0f2;
    --muted: #a0a6ae;
    --accent: #f3b04b;
    --accent-ink: #1a1204;
    --accent-soft: #3a2b12;
    --ok: #4fd18b;
    --test: #f2c94c;
    --plan: #6aaeff;
    --danger: #ff6b61;
    --warn: #ffb35c;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #101113; --surface: #18191c; --surface-2: #212327; --border: #2e3136; --text: #eef0f2; --muted: #a0a6ae;
  --accent: #f3b04b; --accent-ink: #1a1204; --accent-soft: #3a2b12; --ok: #4fd18b; --test: #f2c94c; --plan: #6aaeff;
  --danger: #ff6b61; --warn: #ffb35c; --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
code { font-family: var(--mono); font-size: .86em; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* Encabezado */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 24px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 0;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 1.1rem; letter-spacing: -.01em; }
.brand p { margin: 0; font-size: .78rem; color: var(--muted); }
.logo { width: 32px; height: 32px; }
.logo rect { fill: var(--accent); }
.logo circle { fill: var(--bg); }
.tabs { display: flex; gap: 2px; margin-left: auto; overflow-x: auto; scrollbar-width: none; }
.tabs button {
  border: 0; background: none; padding: 10px 12px 12px; cursor: pointer;
  color: var(--muted); font-weight: 600; font-size: .92rem; white-space: nowrap;
  border-bottom: 2px solid transparent;
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
@media (max-width: 560px) {
  .tabs { margin-left: 0; width: 100%; }
  .tabs button { flex: 1; padding-inline: 4px; }
}

main { max-width: 1100px; margin: 0 auto; padding: 16px; }
.view { display: grid; gap: 14px; }

/* Buscador */
.search input, .field input, .field select, .field textarea, .bank-head input, .bank-head select {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 44px;
}
.search input { font-size: 1rem; }

/* Bancos */
.bank-bar { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.bank-bar button {
  display: grid; justify-items: center; gap: 2px;
  padding: 8px 0 6px; min-height: 48px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
}
.bank-bar .num { font-weight: 700; font-size: 1.05rem; }
.bank-bar .dots { font-size: .5rem; letter-spacing: 1px; color: var(--muted); }
.bank-bar button[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.bank-bar button[aria-selected="true"] .dots { color: inherit; opacity: .75; }

.bank-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.bank-head h2 { font-size: 1.25rem; }
.bank-head input { flex: 1 1 180px; width: auto; min-height: 40px; background: transparent; }
.bank-head .ch { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: .9rem; }
.bank-head select { width: auto; min-height: 40px; padding: 6px 8px; }

/* Switches */
.pedal { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 900px) { .pedal { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 520px) {
  .pedal { gap: 8px; }
  .card { padding: 10px; min-height: 120px; }
  .card .name { font-size: 1rem; }
  .msgs .tr { font-size: .84rem; }
  .bank-head input { flex-basis: 120px; }
}
@media (max-width: 340px) { .pedal { grid-template-columns: 1fr; } }

.card {
  display: flex; flex-direction: column; align-items: stretch; gap: 6px;
  text-align: left; cursor: pointer; min-height: 150px;
  padding: 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  transition: border-color .15s, transform .15s;
}
.card:hover { border-color: var(--accent); }
.card:active { transform: scale(.99); }
.card.empty {
  align-items: center; justify-content: center; gap: 4px;
  background: transparent; border-style: dashed; box-shadow: none;
}
.card .plus { font-size: 1.3rem; font-weight: 700; color: var(--accent); }
.card-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.letter {
  display: inline-grid; place-items: center; min-width: 30px; height: 30px; padding: 0 6px;
  border-radius: 50%; background: var(--surface-2); font-weight: 800;
}
.card .name { font-size: 1.1rem; font-weight: 700; line-height: 1.25; }
.card .mode { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.status { font-size: .74rem; font-weight: 700; display: inline-flex; align-items: center; gap: 5px; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.status-ok { color: var(--ok); }
.status-test { color: var(--test); }
.status-plan { color: var(--plan); }

.msgs { display: grid; gap: 2px; padding-top: 6px; border-top: 1px solid var(--border); }
.msgs-label { font-size: .72rem; color: var(--muted); font-weight: 600; }
.msgs ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 3px; }
.msgs li { display: grid; }
.msgs .tr { font-size: .92rem; }
.msgs code { color: var(--muted); font-size: .76rem; }
.bad { color: var(--danger); }
.note { font-size: .85rem; color: var(--muted); font-style: italic; }
.warn { font-size: .8rem; color: var(--warn); font-weight: 600; margin: 0; }
.warn.soft { font-weight: 400; }
.warn-inline { color: var(--warn); font-size: .8rem; }

.results { display: grid; gap: 10px; }

/* Barra de conexión en vivo */
.live-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px;
  padding: 8px 12px; border-radius: 12px; border: 1px dashed var(--border); background: var(--surface);
}
.live-bar.connected { border-style: solid; border-color: var(--ok); }
.live-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--border); flex: none; }
.live-dot.on { background: var(--ok); animation: pulse 2s infinite; }
@keyframes pulse { 50% { opacity: .4; } }
.live-text { flex: 1 1 auto; }
.live-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.live-actions .btn { min-height: 38px; padding: 6px 12px; font-size: .9rem; }
.live-note { flex-basis: 100%; overflow-wrap: anywhere; }
.ble-tip { padding: 8px 10px; border-radius: 8px; background: var(--accent-soft); }
.ble-tip ol { margin: 4px 0 0; padding-left: 1.3em; }

/* Equipo: cadena del GP-150 + Chocolate */
.rig { display: grid; gap: 14px; }
.chain { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px 12px; }
.chain-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.chain-head > span:first-child { font-weight: 800; letter-spacing: .04em; }
.chain-vol { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; }
.chain-row { display: grid; grid-template-columns: repeat(14, minmax(0, 1fr)); gap: 5px; }
@media (max-width: 760px) { .chain-row { grid-template-columns: repeat(7, minmax(0, 1fr)); } }
.fx {
  position: relative; display: grid; place-items: center; align-content: center; gap: 1px;
  aspect-ratio: 1; min-height: 40px; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted);
  font-size: .72rem; font-weight: 800; transition: background .15s, color .15s, border-color .15s;
}
.fx-ctrl { border-style: dashed; }
.fx-used { border-color: var(--accent); color: var(--text); }
.fx-state { font-size: .62rem; font-weight: 700; min-height: .8em; }
.fx-on { background: var(--ok); border-color: var(--ok); color: #06140c; }
.fx-off { background: var(--surface-2); color: var(--muted); }
.fx-off .fx-name { text-decoration: line-through; text-decoration-thickness: 1px; }
.fx-who {
  position: absolute; top: -6px; right: -4px; min-width: 16px; height: 16px; padding: 0 3px;
  border-radius: 8px; background: var(--accent); color: var(--accent-ink); font-size: .6rem; line-height: 16px; text-align: center;
}

.board {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px;
  padding: 16px 14px 20px; border-radius: 18px;
  background: #1c1d20; border: 1px solid #2c2e33; color: #eef0f2;
}
@media (max-width: 520px) {
  .board { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 12px 10px 16px; gap: 14px 10px; order: -1; }
}
.fs {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  background: none; border: 0; padding: 0; color: inherit; cursor: pointer; text-align: left; min-width: 0;
}
.fs-screen {
  width: 100%; min-height: 84px; padding: 8px 10px; border-radius: 8px;
  background: #0f1512; border: 1px solid #2a3a31; display: flex; flex-direction: column; gap: 3px;
}
.fs:hover .fs-screen, .fs:focus-visible .fs-screen { border-color: var(--accent); }
.fs-top { display: flex; align-items: center; gap: 6px; }
.fs-letter { font-weight: 800; color: #9fb3a8; font-size: .8rem; }
.fs-dot { width: 8px; height: 8px; border-radius: 50%; margin-left: auto; background: currentColor; }
.fs-dot.status-ok { color: #4fd18b; } .fs-dot.status-test { color: #f2c94c; } .fs-dot.status-plan { color: #6aaeff; }
.fs-warn { width: 16px; height: 16px; border-radius: 50%; background: #ffb35c; color: #1a1204; font-size: .7rem; font-weight: 800; display: grid; place-items: center; }
.fs-name { font-weight: 700; font-size: .95rem; line-height: 1.2; overflow-wrap: anywhere; color: #eef0f2; }
.fs-sum { font-size: .78rem; color: #a9c2b5; line-height: 1.25; overflow-wrap: anywhere; }
.fs.empty .fs-screen { background: transparent; border-style: dashed; border-color: #3a3d42; }
.fs.empty .fs-name { color: #8b9097; font-weight: 600; }
.fs-led { width: 12px; height: 12px; border-radius: 50%; background: #3a3d42; border: 1px solid #4a4e55; transition: background .1s; }
.fs-led.on { background: #57e08f; border-color: #9ff0c0; box-shadow: 0 0 10px #57e08f; }
.fs-knob {
  width: 58px; height: 58px; border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #c9ccd1, #7c8087 60%, #5a5e65);
  border: 4px solid #2c2e33; transition: transform .08s;
}
.fs:active .fs-knob { transform: scale(.94); }
.fs.lit .fs-screen { border-color: #57e08f; }
@media (max-width: 520px) { .fs-knob { width: 48px; height: 48px; } .fs-screen { min-height: 76px; } }

.bank-detail ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.bank-detail li { display: flex; gap: 10px; padding: 10px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
.det-letter { font-weight: 800; width: 26px; height: 26px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; flex: none; }
.det-body { display: grid; gap: 3px; min-width: 0; }
.det-title { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.det-steps { display: flex; flex-wrap: wrap; gap: 2px 14px; font-size: .9rem; }

/* Editor por acciones */
.list-field { border: 1px solid var(--border); border-radius: 12px; padding: 10px; background: var(--surface); }
.list-field legend { padding: 0 6px; }
.acts { display: grid; gap: 8px; }
.act {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 6px; align-items: center;
  padding-bottom: 8px; border-bottom: 1px solid var(--border);
}
.act > select { grid-column: 1; min-height: 40px; }
.act-del { grid-column: 2; grid-row: 1; width: 40px; height: 40px; color: var(--muted); }
.act-ctl { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.act .warn-inline { grid-column: 1 / -1; }
.act select, .act input[type="text"], .act input[type="number"] {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; min-height: 40px;
}
.act input.mono { font-family: var(--mono); flex: 1 1 140px; min-width: 0; }
.value-ctl { display: flex; align-items: center; gap: 10px; flex: 1 1 200px; }
.value-ctl input[type="range"] { flex: 1; accent-color: var(--accent); min-height: 32px; padding: 0; border: 0; background: none; }
.value-ctl input[type="number"] { width: 5.2em; text-align: center; font-variant-numeric: tabular-nums; font-size: 1rem; }
.segmented.mini .seg span { min-height: 38px; font-size: .85rem; padding: 4px 12px; }
.rep { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); }
.rep input { width: 4em; text-align: center; }
.act-add { justify-self: start; min-height: 38px; padding-inline: 4px; color: var(--accent); }
.advanced summary { cursor: pointer; font-weight: 600; color: var(--muted); padding: 4px 0; }
.advanced[open] { display: grid; gap: 10px; }

/* Paneles */
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; display: grid; gap: 10px; box-shadow: var(--shadow);
}
.panel h2 { font-size: 1.05rem; }
.panel p { margin: 0; }
#view-file { grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); align-items: start; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.checks { display: grid; gap: 4px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 16px; border-radius: 10px; cursor: pointer; font-weight: 600;
  background: var(--surface-2); border: 1px solid var(--border);
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.danger:not(.ghost) { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.icon-btn { border: 0; background: none; width: 44px; height: 44px; border-radius: 50%; cursor: pointer; font-size: 1.1rem; }

.field { display: grid; gap: 6px; border: 0; margin: 0; padding: 0; min-width: 0; }
.field > span, .field legend { font-size: .85rem; font-weight: 600; color: var(--muted); padding: 0; }
.field.inline { grid-template-columns: 1fr auto; align-items: center; }
.field textarea { font-family: var(--mono); resize: vertical; }
.field textarea[name="note"] { font-family: inherit; }
.translation { margin: 0; font-size: 1.05rem; }

/* Tabla de referencia */
.table-wrap { display: grid; gap: 14px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
caption { text-align: left; font-weight: 700; padding: 0 0 6px; }
th, td { text-align: left; padding: 8px 12px; border-top: 1px solid var(--border); vertical-align: top; }
th { font-size: .78rem; color: var(--muted); background: var(--surface-2); border-top: 0; }
td.num { font-family: var(--mono); white-space: nowrap; font-weight: 700; }

/* Hoja de edición */
.sheet {
  width: min(640px, 100vw); max-height: min(92dvh, 900px);
  padding: 0; border: 1px solid var(--border); border-radius: 18px;
  background: var(--bg); color: var(--text);
}
.sheet::backdrop { background: rgb(0 0 0 / .55); }
.sheet form { display: flex; flex-direction: column; max-height: inherit; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 8px 10px 18px; border-bottom: 1px solid var(--border); }
.sheet-head h2 { font-size: 1.1rem; }
.sheet-body { overflow-y: auto; padding: 16px 18px; display: grid; gap: 14px; }
.sheet-foot { display: flex; align-items: center; gap: 8px; padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); flex-wrap: wrap; }
.danger-zone { margin-right: auto; display: flex; align-items: center; gap: 6px; }
@media (max-width: 640px) {
  .sheet { width: 100vw; max-width: 100vw; max-height: 100dvh; height: 100dvh; margin: 0; border-radius: 0; border: 0; }
  .sheet form { height: 100%; }
  .sheet-head { padding-top: calc(env(safe-area-inset-top) + 6px); }
}

.row { display: grid; grid-template-columns: 1fr 1.4fr; gap: 12px; }
@media (max-width: 520px) { .row { grid-template-columns: 1fr; } }
.segmented { display: flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface); }
.seg { flex: 1; position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; }
.seg span { display: grid; place-items: center; min-height: 42px; padding: 4px 6px; font-size: .82rem; font-weight: 600; text-align: center; cursor: pointer; color: var(--muted); }
.seg + .seg span { border-left: 1px solid var(--border); }
.seg input:checked + span { background: var(--surface-2); color: currentColor; box-shadow: inset 0 -3px 0 currentColor; }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }
.seg.status-ok input:checked + span { color: var(--ok); }
.seg.status-test input:checked + span { color: var(--test); }
.seg.status-plan input:checked + span { color: var(--plan); }

.bank-lists { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.bank-lists:has([data-list="b"][hidden]) { grid-template-columns: 1fr; }
@media (max-width: 520px) { .bank-lists { grid-template-columns: 1fr; } }
.live { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; font-size: .88rem; }
.live li::before { content: "→ "; color: var(--muted); }

/* Recetas */
.recipes { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0 14px; }
.recipes summary { cursor: pointer; padding: 14px 0; font-weight: 700; list-style-position: inside; }
.recipes summary .muted { font-weight: 400; font-size: .85rem; display: block; margin-left: 1.1em; }
.recipes[open] { padding-bottom: 14px; }
.recipe-groups { display: grid; gap: 10px; }
.recipe-group h3 { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--border); background: var(--surface-2); border-radius: 999px;
  padding: 8px 14px; min-height: 40px; cursor: pointer; font-weight: 600; font-size: .9rem;
}
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }
.recipe-params { display: grid; gap: 10px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.recipe-params input[type="range"] { padding: 0; min-height: 32px; accent-color: var(--accent); border: 0; background: none; }

/* Importar */
.diff { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.diff li { display: grid; gap: 2px; padding: 10px 12px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); }
.tag { font-size: .75rem; font-weight: 700; color: var(--muted); }
.diff-new .tag { color: var(--ok); }
.diff-diff .tag { color: var(--warn); }
.diff-missing .tag { color: var(--plan); }

.device { border-color: var(--accent); }
#device-status:not(.muted) { font-weight: 700; color: var(--ok); }
.progress { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.progress span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .15s; }
.diag { font-size: .85rem; color: var(--warn); }
.diag summary { cursor: pointer; font-weight: 600; }
.diag ul { padding-left: 1.2em; color: var(--text); overflow-wrap: anywhere; }
.small-btn { min-height: 36px; font-size: .85rem; justify-self: start; padding-inline: 0; }

.monitor-log { margin: 0; padding-left: 1.2em; display: grid; gap: 4px; font-size: .9rem; }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600;
  max-width: calc(100vw - 32px); z-index: 20; box-shadow: 0 6px 24px rgb(0 0 0 / .25);
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
