:root {
  --bg: #eef1f5; --panel: #ffffff; --ink: #1c2430; --muted: #66707e; --line: #d5dbe3;
  --accent: #1f6feb; --accent-ink: #fff; --sim: #1a7f37; --warn: #b42318; --hover: #e8eef7;
  --brand: #1B5CB5; --cafe: #8a5a2b;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14181f; --panel: #1d232c; --ink: #e4e8ee; --muted: #9aa4b2; --line: #313a46;
    --accent: #4d8eff; --accent-ink: #fff; --sim: #2ea043; --warn: #ff6b5b; --hover: #26303c;
    --brand: #6aa2f0; --cafe: #d9a46c;
  }
}
:root[data-theme="dark"] {
  --bg: #14181f; --panel: #1d232c; --ink: #e4e8ee; --muted: #9aa4b2; --line: #313a46;
  --accent: #4d8eff; --accent-ink: #fff; --sim: #2ea043; --warn: #ff6b5b; --hover: #26303c;
  --brand: #6aa2f0; --cafe: #d9a46c;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 13px/1.35 "Segoe UI", system-ui, sans-serif; display: flex; flex-direction: column; overflow: hidden; }

#bar { display: flex; align-items: center; gap: 14px; padding: 6px 10px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
[hidden] { display: none !important; }
.brand { display: flex; align-items: center; gap: 8px; margin-right: 6px; background: none; border: none; padding: 2px 4px; text-align: left; }
.brand:hover { background: var(--hover); }
.brand .iso svg { width: 28px; height: 28px; display: block; }
.brand .bt { line-height: 1.1; font-size: 15px; color: var(--muted); }
.brand .bt b { color: var(--brand); font-weight: 700; letter-spacing: -.3px; }
.brand small { display: block; font-size: 10px; color: var(--muted); }
button.menu { font-weight: 700; letter-spacing: 1px; }

/* Cartel de cortocircuito sobre el esquema */
#banner { position: fixed; top: 60px; left: 50%; transform: translateX(-50%); z-index: 15; max-width: min(640px, calc(100% - 32px));
  background: #b42318; color: #fff; border-radius: 8px; padding: 10px 40px 10px 14px; box-shadow: 0 8px 24px rgba(0,0,0,.3); font-weight: 600; }
#banner small { display: block; font-weight: 400; opacity: .9; margin-top: 2px; }
#banner button { position: absolute; top: 6px; right: 6px; background: none; border: none; color: #fff; font-size: 18px; padding: 2px 8px; }

/* Pantalla de inicio / acerca de */
#about { position: fixed; inset: 0; z-index: 20; background: rgba(10, 16, 28, .55); display: grid; place-items: center; padding: 16px; }
.ab-card { width: min(980px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; background: var(--panel); color: var(--ink);
  border-radius: 14px; padding: 26px 28px 20px; box-shadow: 0 20px 60px rgba(0,0,0,.35); font-size: 14px; line-height: 1.5; }
.ab-card p { margin: 0 0 12px; }
.ab-marca { display: flex; align-items: center; justify-content: center; gap: 10px; }
.ab-marca svg { width: 44px; height: 44px; }
.ab-marca b { font-size: 32px; color: var(--brand); letter-spacing: -.5px; }
.ab-marca span { font-size: 32px; color: var(--muted); }
.ab-sub { text-align: center; color: var(--muted); font-size: 15px; margin-bottom: 16px !important; }
.ab-acc { margin: 0 0 18px; }
.ab-acc button { font: inherit; text-align: left; }
.ab-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ab-btns button { padding: 11px 10px; text-align: center; font-weight: 600; font-size: 15px; }
.ab-btns .ab-pri { background: var(--brand); color: #fff; border-color: var(--brand); }
.ab-btns .ab-pri:hover { background: var(--brand); filter: brightness(1.1); }
.ab-recup { display: flex; gap: 6px; margin-top: 8px; }
.ab-recup button[data-a="recover"] { flex: 1; display: flex; flex-direction: column; padding: 8px 12px;
  background: color-mix(in srgb, #e6a700 16%, var(--panel)); border-color: color-mix(in srgb, #e6a700 50%, var(--line)); }
.ab-recup button[data-a="recover"] span { font-size: 12px; color: var(--muted); }
.ab-recup .ab-desc { font-size: 12px; color: var(--muted); }
.ab-ex { width: 100%; margin-top: 8px; font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--ink); }
.ab-h { margin: 14px 0 6px !important; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.ab-lista { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.ab-lista button { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; padding: 7px 12px; background: var(--bg); }
.ab-lista button:hover { background: var(--hover); }
.ab-lista span { color: var(--muted); font-size: 12px; white-space: nowrap; }
@media (max-width: 520px) { .ab-btns { grid-template-columns: 1fr; } .ab-lista button { flex-direction: column; } }
.ab-sellos { display: flex; flex-wrap: wrap; gap: 6px 16px; font-weight: 600; margin-bottom: 12px; }
.ab-sellos span::before { content: "✓ "; color: var(--brand); }
.ab-aviso { background: var(--bg); border-radius: 8px; padding: 10px 12px; font-size: 13px; color: var(--muted); }
.ab-cafe { display: flex; gap: 14px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-bottom: 12px; }
.ab-cafe p { margin: 0 !important; flex: 1 1 260px; font-size: 13px; color: var(--muted); }
.cafecito { display: inline-flex; align-items: center; gap: 8px; padding: 9px 16px; border-radius: 999px; white-space: nowrap;
  border: 1px solid var(--cafe); color: var(--cafe); text-decoration: none; font-weight: 600; }
.cafecito:hover { background: var(--cafe); color: var(--panel); }
.ab-links { font-size: 13px; text-align: center; }
.ab-links a { color: var(--brand); }
.ab-pie { display: flex; align-items: center; justify-content: space-between; gap: 12px; border-top: 1px solid var(--line); padding-top: 14px; margin-top: 4px; }
.ab-pie span { color: var(--muted); font-size: 12px; }
.ab-ok { background: var(--brand); color: #fff; border-color: var(--brand); font-weight: 600; padding: 8px 22px; }
.ab-ok:hover { background: var(--brand); filter: brightness(1.1); }
.grp { display: flex; gap: 4px; }
button { font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 5px 10px; cursor: pointer; }
button:hover { background: var(--hover); }
button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.sim { font-weight: 600; }
body.simulating button.sim { background: var(--sim); color: #fff; border-color: var(--sim); }
body.simulating .edit-only { opacity: .35; pointer-events: none; }

#body { flex: 1; display: flex; min-height: 0; }
#palette { width: 210px; overflow-y: auto; background: var(--panel); border-right: 1px solid var(--line); padding: 6px; }
#palette h4 { margin: 10px 4px 4px; font-size: 11px; text-transform: uppercase; color: var(--muted); letter-spacing: .5px; }
.pitem { display: flex; align-items: center; gap: 6px; padding: 3px 5px; border-radius: 5px; cursor: pointer; }
.pitem:hover { background: var(--hover); }
.pitem.on { background: var(--accent); color: var(--accent-ink); }
.pitem svg { width: 34px; height: 30px; flex: none; background: #fff; border-radius: 4px; }
body.simulating #palette { opacity: .35; pointer-events: none; }

#panes { flex: 1; display: flex; min-width: 0; min-height: 0; position: relative; }
#panes.rows { flex-direction: column; }
.pane { flex: 1 1 0; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
#panes.single #p1, #panes.single .divider { display: none; }
#panes.single #p0 { flex: 1 1 0 !important; }
.divider { flex: 0 0 6px; background: var(--line); cursor: col-resize; }
#panes.rows .divider { cursor: row-resize; }
.divider:hover { background: var(--accent); }
.stage { flex: 1; position: relative; overflow: hidden; background: #9aa3ad; min-height: 0; }
.svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; user-select: none; }
.tabs { display: flex; gap: 2px; padding: 4px 6px; background: var(--panel); border-top: 2px solid var(--line); overflow-x: auto; }
#panes:not(.single) .pane.active .tabs { border-top-color: var(--accent); }
.tabs button { border-radius: 6px 6px 0 0; padding: 3px 12px; white-space: nowrap; }
#psearch { width: 100%; font: inherit; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--ink); position: sticky; top: 0; z-index: 1; }
.pitem[hidden], #plist h4[hidden] { display: none; }
#side textarea { width: 100%; font: inherit; padding: 4px 6px; border: 1px solid var(--line); border-radius: 5px; background: var(--bg); color: var(--ink); resize: vertical; }
#side label.chk { display: flex; gap: 6px; align-items: center; color: var(--ink); font-size: 12px; }
#side label.chk input { width: auto; }

#side { width: 250px; overflow-y: auto; background: var(--panel); border-left: 1px solid var(--line); padding: 10px; }
#side h3 { margin: 0 0 8px; font-size: 13px; }
#side label { display: block; margin: 7px 0 2px; color: var(--muted); font-size: 11px; }
#side input, #side select { width: 100%; font: inherit; padding: 4px 6px; border: 1px solid var(--line); border-radius: 5px; background: var(--bg); color: var(--ink); }
#side .hint { color: var(--muted); font-size: 12px; }
#side .row { display: flex; gap: 6px; }
#side .row button { flex: 1; }
#side button.danger { width: 100%; margin-top: 6px; color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, var(--line)); }
#side button:disabled { opacity: .45; cursor: default; }
#side hr { border: none; border-top: 1px solid var(--line); margin: 14px 0 10px; }
.alarm { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); border-radius: 6px; padding: 6px 8px; margin: 6px 0; font-weight: 600; }
.tmr { margin: 4px 0 8px; font-size: 12px; }
.tmr span { color: var(--muted); font-size: 11px; }
.tmr .bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin: 3px 0 1px; }
.tmr .bar i { display: block; height: 100%; }
.tmr small { color: var(--muted); }
.log { font-size: 11px; color: var(--muted); margin: 2px 0; }
.legend { display: grid; grid-template-columns: 1fr 1fr; gap: 3px 8px; font-size: 11px; margin-top: 6px; }
.legend i { display: inline-block; width: 18px; height: 4px; vertical-align: middle; margin-right: 4px; }

#ctx { position: fixed; z-index: 10; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 6px 20px rgba(0,0,0,.25); padding: 4px; min-width: 220px; }
#ctx div { padding: 5px 9px; border-radius: 4px; cursor: pointer; }
#ctx div:hover { background: var(--hover); }
#ctx .t { font-weight: 600; cursor: default; color: var(--muted); }
#ctx .t:hover { background: none; }
#ctx .g { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); cursor: default; padding-top: 8px; }
#ctx .g:hover { background: none; }
#ctx { max-height: calc(100vh - 16px); overflow-y: auto; }

/* Hoja (siempre papel blanco). El informe usa una copia de estas reglas (SHEET_CSS en js/report.js) */
.paper { fill: #fff; }
.frm { fill: none; stroke: #888; stroke-width: 1; }
.colnum { font: 10px sans-serif; fill: #666; text-anchor: middle; }
.rot1 { font: bold 13px sans-serif; fill: #222; }
.rot2 { font: 11px sans-serif; fill: #444; }
.rotl { font: 6.5px sans-serif; fill: #777; letter-spacing: .3px; }
.rotv { font: bold 13px sans-serif; fill: #222; }
.gridpt { fill: #c9ced6; }
.el { color: #111; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; }
.el text { stroke: none; fill: #111; }
.el .tn { font: 9px sans-serif; fill: #555; }
.el .tag { font: bold 12px sans-serif; fill: #0b3d91; }
.el .tag.orphan { fill: #d00; }
.el .xref { stroke: #777; stroke-width: .8; cursor: move; }
.el .xref .xhit { fill: rgba(255,255,255,.9); stroke: none; }
.el .xref text { font: 8px sans-serif; fill: #333; stroke: none; }
.el .xref .xh { font-weight: bold; text-anchor: middle; }
.el .xref .xr { fill: #0b3d91; }
.el .xref .pol { fill: #777; }
.el .xref .xh2 { font-weight: bold; }
.el.sel .xref { stroke: #1f6feb; }
.warnbox { background: color-mix(in srgb, #e6a700 18%, transparent); border-radius: 6px; padding: 6px 8px; margin: 6px 0; font-size: 12px; }
.el .act { font: bold 10px sans-serif; text-anchor: middle; }
.el .mt { font: bold 15px sans-serif; text-anchor: middle; }
.el .mt2 { font: 11px sans-serif; text-anchor: middle; }
.el .cdat { font: 10px sans-serif; fill: #444; }
.el .free { font-family: sans-serif; fill: #111; }
.el .note { font: italic 11px sans-serif; fill: #333; cursor: move; }
.el.sel .note { fill: #1f6feb; }
.el .tstate { font: bold 10px sans-serif; fill: #555; }
.el .tstate.run { fill: #1f6feb; }
.el .tstate.bad { fill: #c92a2a; }
.el .mstate { font: bold 11px sans-serif; fill: #c45a00; }
.el .hit { fill: transparent; stroke: none; }
.el.sel { color: var(--accent); }
.el.sel .hit { fill: rgba(31,111,235,.08); stroke: #1f6feb; stroke-width: 1; stroke-dasharray: 3 3; }
.el.fault { color: #c2185b; }
.el.ghost { opacity: .5; pointer-events: none; }
.wire { fill: none; stroke: #111; stroke-width: 2; stroke-linejoin: round; }
.wire.dead { stroke: #b9bec6; }
.wire.live { stroke-width: 3.5; }
.wire.short { stroke: #e000a0; stroke-width: 5; animation: blink .4s infinite alternate; }
.wire.sel { stroke: #1f6feb; stroke-width: 3; }
.wire.draft { stroke: #1f6feb; stroke-dasharray: 5 4; }
.whit { fill: none; stroke: transparent; stroke-width: 10; }
.dot { fill: #111; }
.cursor { fill: none; stroke: #1f6feb; stroke-width: 1.5; }
.rot-cw, .rot-ccw { transform-box: fill-box; transform-origin: center; animation: spin 1.2s linear infinite; }
.rot-ccw { animation-direction: reverse; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes blink { to { opacity: .3; } }
body.simulating .el { cursor: pointer; }

@media (max-width: 800px) {
  #palette { width: 150px; }
  #side { display: none; }
}

/* ---------- Ayuda ---------- */
button.help { font-weight: 700; min-width: 30px; }
button.fallas { background: #fdecef; color: #b0173f; border-color: #e7a3b3; font-weight: 600; }
button.fallas[hidden] { display: none; }
button.help.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
body.helpmode .stage, body.helpmode .stage *, body.helpmode #palette .pitem, body.helpmode #palette .pitem * { cursor: help !important; }
body.helpmode .stage { outline: 2px dashed var(--accent); outline-offset: -3px; }
#side .qhelp { display: inline-block; margin: -4px 0 4px; font-size: 12px; color: var(--accent); }
#help { width: 360px; flex: none; display: flex; flex-direction: column; background: var(--panel); border-left: 1px solid var(--line); min-height: 0; }
#help .htop { display: flex; gap: 6px; align-items: center; padding: 8px; border-bottom: 1px solid var(--line); }
#help .htop .hq { flex: 1; min-width: 0; font: inherit; padding: 4px 8px; border: 1px solid var(--line); border-radius: 5px; background: var(--bg); color: var(--ink); }
#help .htop button { padding: 3px 8px; }
#help .htop button:disabled { opacity: .35; }
#help .hbody { flex: 1; overflow-y: auto; padding: 4px 14px 24px; font-size: 13.5px; line-height: 1.5; }
#help .hhead { display: flex; gap: 12px; align-items: center; margin: 12px 0 4px; }
#help .hsym { width: 56px; height: 56px; flex: none; background: #fff; border: 1px solid var(--line); border-radius: 6px; }
#help h2 { margin: 0; font-size: 18px; }
#help .hhead span { color: var(--muted); font-size: 12px; }
#help h3 { margin: 16px 0 4px; font-size: 13.5px; color: var(--brand); }
#help p { margin: 4px 0; }
#help ul, #help ol { margin: 4px 0; padding-left: 20px; }
#help li { margin: 3px 0; }
#help code { font-family: Consolas, monospace; font-size: 12.5px; background: var(--bg); padding: 0 3px; border-radius: 3px; }
#help a { color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
#help .nota { background: var(--bg); border-left: 3px solid var(--warn); padding: 6px 10px; margin: 8px 0; }
#help .hint { color: var(--muted); font-size: 12.5px; }
#help ul.hidx { list-style: none; padding-left: 0; }
#help ul.hidx ul { list-style: none; padding-left: 12px; margin: 2px 0 6px; }
#help li.sub { color: var(--muted); font-size: 12px; margin-top: 6px; }
#help li.sub li { font-size: 13.5px; color: var(--ink); }
#help li.prox { color: var(--muted) !important; }
@media (max-width: 1200px) { #help { width: 300px; } }

/* Cartel propio (cambios sin guardar) */
#vencida { position: fixed; inset: 0; z-index: 50; background: rgba(10, 16, 28, .85); display: grid; place-items: center; padding: 16px; }
#vencida .dlg-btns { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
#dlg { position: fixed; inset: 0; z-index: 30; background: rgba(10, 16, 28, .45); display: grid; place-items: center; padding: 16px; }
.dlg-card { width: min(440px, 100%); background: var(--panel); color: var(--ink); border-radius: 12px; padding: 20px 22px 16px; box-shadow: 0 20px 60px rgba(0,0,0,.35); font-size: 14px; line-height: 1.5; }
.dlg-card p { margin: 0 0 16px; }
.dxf-lista { display: grid; gap: 4px; margin-top: 12px; max-height: 50vh; overflow: auto; }
.dxf-lista label { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.dlg-btns { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.dlg-btns button { padding: 6px 14px; }
.dlg-btns button.pri { background: var(--brand); color: #fff; border-color: var(--brand); }
.el .mstate.bad { fill: #c92a2a; }
.el .fstate { font: bold 11px sans-serif; fill: #c2185b; paint-order: stroke; stroke: #fff; stroke-width: 3px; }
/* Bobina que oscila y sus contactos (circuito inestable) */
.el .oscbox { fill: rgba(217, 72, 15, .12); stroke: #d9480f; stroke-width: 2; stroke-dasharray: 5 3; animation: oscblink .7s steps(2) infinite; }
@keyframes oscblink { 50% { opacity: .2; } }
/* Pantalla de inicio en dos columnas: entra completa sin desplazarse */
.ab-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; align-items: start; }
.ab-izq .ab-acc { margin-bottom: 0; }
.ab-der { font-size: 13.5px; }
.ab-der .ab-links { text-align: left; margin-bottom: 0 !important; }
.ab-der .ab-cafe { margin-bottom: 10px; }
.ab-card { padding: 22px 28px 16px; }
.ab-sub { margin-bottom: 14px !important; }
.ab-pie { margin-top: 14px; }
@media (max-width: 860px) { .ab-cols { grid-template-columns: 1fr; gap: 14px; } }
/* Indicaciones de la herramienta Cable, sobre el borde inferior del área de dibujo */
#wireHint { position: absolute; left: 50%; bottom: 44px; transform: translateX(-50%); z-index: 5; max-width: calc(100% - 24px);
  background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px;
  font-size: 12.5px; box-shadow: 0 4px 14px rgba(0,0,0,.15); pointer-events: none; text-align: center; }
#wireHint b { color: var(--brand); }
/* Rectángulo de selección: de izquierda a derecha (azul, lo que queda adentro) / de derecha a izquierda (verde, lo que toca) */
.selbox { fill: rgba(31, 111, 235, .08); stroke: #1f6feb; stroke-width: 1; vector-effect: non-scaling-stroke; }
.selbox.toca { fill: rgba(42, 157, 58, .08); stroke: #2a9d3a; stroke-dasharray: 6 4; }
body.copiando, body.copiando * { cursor: copy !important; }
body.panning .stage, body.panning .stage * { cursor: grab !important; }
/* Pie de la pantalla de inicio: logo chico de la gama Verifica */
.ab-gama { display: inline-flex; align-items: center; gap: 8px; }
.ab-gama svg { width: 20px; height: 20px; flex: none; }
.ab-gama b { color: var(--brand); }
