* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0b1220;
  font-family: system-ui, "Segoe UI", sans-serif; color: #e2e8f0; }
#c { position: fixed; inset: 0; display: block; z-index: 0; }

/* top bar */
#topbar { position: fixed; top: 0; left: 0; right: 0; height: 48px; z-index: 20;
  display: flex; align-items: center; gap: 16px; padding: 0 16px;
  background: linear-gradient(#0b1220ee, #0b1220aa); backdrop-filter: blur(6px);
  border-bottom: 1px solid #1e293b; pointer-events: auto; }
.brand { font-weight: 700; letter-spacing: .3px; }
.brand em { color: #94a3b8; font-weight: 400; font-style: normal; }
.brand .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%;
  background: #22c55e; box-shadow: 0 0 8px #22c55e; margin-right: 6px; }
.modes { margin-left: auto; display: flex; gap: 6px; }
.modes button, .layers button { background: #111a2e; color: #cbd5e1; border: 1px solid #263349;
  padding: 6px 12px; border-radius: 8px; cursor: pointer; font-size: 12px; font-weight: 600; }
.modes button.on { background: #2563eb; border-color: #3b82f6; color: #fff; }
.layers { display: flex; gap: 6px; flex: 0 0 auto; }
.layers button { pointer-events: auto; position: relative; z-index: 21; min-width: 148px; }
.layers button.on { background: #a16207; border-color: #c9a227; color: #fff; }
.layers button:not(.on) { background: #14532d; border-color: #22c55e; color: #dcfce7; }
.layer-toggle { display: block; width: 100%; margin: 4px 0 0; background: #a16207;
  color: #fff; border: 1px solid #c9a227; padding: 8px 10px; border-radius: 8px;
  cursor: pointer; font-size: 12px; font-weight: 700; }
.layer-toggle:not(.on) { background: #14532d; border-color: #22c55e; color: #dcfce7; }
.layer-hint { margin: 4px 2px 8px; font-size: 10px; color: #94a3b8; line-height: 1.3; }
.meta { color: #94a3b8; font-size: 12px; }
.meta b { color: #fbbf24; }

/* sidebar */
#side { position: fixed; top: 48px; left: 0; bottom: 0; width: 230px; z-index: 20;
  background: #0d1526cc; backdrop-filter: blur(6px); border-right: 1px solid #1e293b;
  overflow-y: auto; padding: 8px; }
.side-h { font-size: 11px; text-transform: uppercase; letter-spacing: 1px;
  color: #64748b; padding: 6px 8px; }
.grp { font-size: 10px; text-transform: uppercase; letter-spacing: .8px; color: #f59e0b;
  margin: 10px 8px 4px; }
.eq { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  background: transparent; color: #cbd5e1; border: 0; border-radius: 7px;
  padding: 7px 8px; cursor: pointer; font-size: 13px; }
.eq:hover { background: #16213a; }
.eq.sel { background: #1d4ed833; outline: 1px solid #3b82f6; }
.led { width: 9px; height: 9px; border-radius: 50%; background: #475569; flex: 0 0 auto;
  box-shadow: 0 0 6px currentColor; }
.legend { margin: 14px 8px; font-size: 11px; color: #94a3b8; line-height: 1.9; }
.legend .sw { display: inline-block; width: 11px; height: 11px; border-radius: 3px;
  vertical-align: middle; margin-right: 4px; }
.legend hr { border: 0; border-top: 1px solid #1e293b; margin: 8px 0; }

/* right panel */
#panel { position: fixed; top: 60px; right: 12px; width: 330px; z-index: 20;
  background: #0d1526e6; border: 1px solid #22304a; border-radius: 12px;
  padding: 14px; backdrop-filter: blur(6px); max-height: calc(100vh - 76px);
  overflow-y: auto; }
#emptyHint { color: #94a3b8; font-size: 13px; line-height: 1.5; }
.part-box { margin-top: 10px; padding: 10px; border: 1px solid #1e3a5f;
  border-radius: 10px; background: #0b1a33; }
.part-id { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 16px;
  font-weight: 700; color: #38bdf8; letter-spacing: .4px; }
#dPartName { font-size: 13px; margin-top: 2px; text-transform: capitalize; }
.part-actions { display: flex; gap: 6px; margin-top: 8px; }
.part-actions button { flex: 1; background: #111a2e; color: #cbd5e1; border: 1px solid #263349;
  padding: 6px 8px; border-radius: 8px; cursor: pointer; font-size: 11px; font-weight: 600; }
.part-actions button:hover { border-color: #38bdf8; color: #fff; }
#partSearch { width: 100%; margin-top: 10px; background: #0b1220; color: #e2e8f0;
  border: 1px solid #22304a; border-radius: 8px; padding: 6px 8px; font-size: 12px; }
.parts-list { max-height: 36vh; overflow-y: auto; margin-top: 8px; }
body.edit-mode .parts-list { max-height: 16vh; }
body.edit-mode #panel { width: 360px; }
body.edit-mode #dTags,
body.edit-mode .d-foot { display: none; }
body.edit-mode #editBox {
  position: sticky; top: 0; z-index: 3;
  margin-top: 0; margin-bottom: 10px;
}
.pfam { font-size: 10px; text-transform: uppercase; letter-spacing: .7px; color: #38bdf8;
  margin: 8px 2px 3px; cursor: pointer; user-select: none; }
.prow { display: flex; align-items: center; gap: 6px; width: 100%; text-align: left;
  background: transparent; color: #cbd5e1; border: 0; border-radius: 6px;
  padding: 4px 6px; cursor: pointer; font-size: 11px; }
.prow:hover { background: #16213a; }
.prow.sel { background: #42200666; outline: 1px solid #fbbf24; }
.prow.off { opacity: .38; }
.prow .pid { font-family: ui-monospace, Menlo, monospace; color: #7dd3fc; flex: 0 0 72px; }
.prow .pn { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  text-transform: capitalize; }
.prow .eye { flex: 0 0 18px; color: #94a3b8; font-size: 12px; }
#hoverTag { position: fixed; z-index: 8; pointer-events: none; background: #0d1526f2;
  border: 1px solid #38bdf8; color: #e2e8f0; padding: 4px 8px; border-radius: 6px;
  font-size: 12px; font-family: ui-monospace, Menlo, monospace; transform: translate(12px, 14px);
  box-shadow: 0 8px 24px #0008; }
#hoverTag b { color: #38bdf8; }
.d-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
#dName { font-size: 17px; font-weight: 700; }
.sub { color: #94a3b8; font-size: 11px; margin-top: 2px; }
.badge { font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 20px; letter-spacing: .5px; }
.badge.RUN { background: #052e16; color: #4ade80; border: 1px solid #16a34a; }
.badge.STOP { background: #1e293b; color: #94a3b8; border: 1px solid #475569; }
.badge.ALARM { background: #450a0a; color: #f87171; border: 1px solid #ef4444;
  animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .5; } }
#dTags { margin-top: 12px; }
.tag { display: flex; justify-content: space-between; padding: 6px 0;
  border-bottom: 1px solid #172136; font-size: 13px; }
.tag .tk { color: #94a3b8; }
.tag .tv { font-weight: 700; font-variant-numeric: tabular-nums; }
.tag .tv em { color: #64748b; font-style: normal; font-weight: 400; font-size: 11px; }
.d-foot { margin-top: 12px; font-size: 11px; color: #64748b; }
.prow.edited .pn { color: #fbbf24; }
.prow .ped { flex: 0 0 14px; color: #fbbf24; font-size: 11px; }
.modes button#modeEdit.on { background: #7c3aed; border-color: #a78bfa; color: #fff; }
body:not(.taller-open) #modeEdit,
body:not(.taller-open) #btnEditPart,
body:not(.taller-open) #btnDeletePart,
body:not(.taller-open) #btnDeleteEdit,
body:not(.taller-open) #workshopBox,
body:not(.taller-open) #btnLinks { display: none !important; }
.prim-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 8px; }
.prim-row button { flex: 1; min-width: 64px; background: #111a2e; color: #cbd5e1;
  border: 1px solid #263349; padding: 6px 8px; border-radius: 8px; cursor: pointer;
  font-size: 11px; font-weight: 600; }
.prim-row button:hover, .prim-row button.on { border-color: #a78bfa; color: #fff; background: #4c1d95; }
.edit-name { display: flex; flex-direction: column; gap: 3px; font-size: 10px; color: #94a3b8; margin: 4px 0 6px; }
.edit-name input { width: 100%; background: #0b1220; color: #e2e8f0; border: 1px solid #22304a;
  border-radius: 6px; padding: 5px 6px; font-size: 12px; }
#sketchHud { position: fixed; left: 240px; right: 380px; bottom: 12px; z-index: 18;
  pointer-events: none; }
body.sketching #sketchHud { pointer-events: auto; }
.sketch-bar { display: flex; flex-wrap: wrap; gap: 6px; align-items: flex-end;
  background: #1a1030f2; border: 1px solid #6d28d9; border-radius: 12px; padding: 10px 12px; }
.sketch-bar button, .sketch-bar label { font-size: 11px; color: #cbd5e1; }
.sketch-bar button { background: #111a2e; border: 1px solid #263349; border-radius: 8px;
  padding: 6px 10px; cursor: pointer; font-weight: 600; }
.sketch-bar button.on, #btnSketchBake { background: #6d28d9; border-color: #a78bfa; color: #fff; }
.sketch-bar label { display: flex; flex-direction: column; gap: 2px; color: #94a3b8; }
.sketch-bar input { width: 78px; background: #0b1220; color: #e2e8f0; border: 1px solid #22304a;
  border-radius: 6px; padding: 4px 6px; }
.sketch-title { font-size: 11px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase;
  color: #c4b5fd; margin-right: 6px; align-self: center; }
.sketch-help { margin: 6px 4px 0; font-size: 11px; color: #c4b5fd; text-align: center;
  pointer-events: none; }
body.sketching #c { cursor: crosshair; }
#tallerLock { position: fixed; inset: 0; z-index: 50; background: #020617cc;
  display: flex; align-items: center; justify-content: center; }
#tallerLock[hidden] { display: none !important; }
.taller-card { width: 320px; background: #1a1030; border: 1px solid #6d28d9; border-radius: 14px;
  padding: 18px; box-shadow: 0 20px 50px #000a; }
.taller-card p { font-size: 13px; color: #94a3b8; line-height: 1.45; margin: 8px 0 12px; }
#tallerPin { width: 100%; background: #0b1220; color: #e2e8f0; border: 1px solid #5b21b6;
  border-radius: 8px; padding: 8px 10px; font-size: 14px; margin-bottom: 10px; }
.taller-err { color: #f87171 !important; }
body.edit-mode #c { cursor: crosshair; }
.edit-box { margin-top: 10px; padding: 10px; border: 1px solid #5b21b6; border-radius: 10px;
  background: #1a1030; }
.edit-h { font-size: 11px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase;
  color: #c4b5fd; display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
#editPartLabel { font-size: 10px; font-weight: 600; letter-spacing: 0; text-transform: none;
  color: #fde68a; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 210px; }
.edit-hint { font-size: 11px; color: #94a3b8; line-height: 1.35; margin: 4px 0 6px; }
.edit-tools { display: flex; gap: 6px; margin-bottom: 8px; align-items: center; }
.edit-tools button { flex: 1; background: #111a2e; color: #cbd5e1; border: 1px solid #263349;
  padding: 6px 8px; border-radius: 8px; cursor: pointer; font-size: 11px; font-weight: 600; }
.edit-tools button.on { background: #6d28d9; border-color: #a78bfa; color: #fff; }
.edit-color-inline { display: flex; flex-direction: column; gap: 2px; font-size: 10px; color: #94a3b8;
  flex: 0 0 64px; }
.edit-color-inline input[type=color] { width: 100%; height: 28px; border: 1px solid #22304a;
  border-radius: 6px; background: #0b1220; padding: 2px; cursor: pointer; }
.edit-sec { font-size: 10px; text-transform: uppercase; letter-spacing: .6px; color: #a78bfa;
  margin: 6px 0 3px; }
.edit-grid, .edit-appear { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.edit-grid[hidden], .edit-sec[hidden] { display: none !important; }
.edit-grid label, .edit-appear label { display: flex; flex-direction: column; gap: 3px;
  font-size: 10px; color: #94a3b8; }
.edit-grid input, .edit-appear input[type=number] { width: 100%; background: #0b1220; color: #e2e8f0;
  border: 1px solid #22304a; border-radius: 6px; padding: 5px 6px; font-size: 12px;
  font-variant-numeric: tabular-nums; }
.edit-appear input[type=color] { width: 100%; height: 28px; border: 1px solid #22304a;
  border-radius: 6px; background: #0b1220; padding: 2px; cursor: pointer; }
.edit-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 10px; }
.edit-actions button { background: #111a2e; color: #cbd5e1; border: 1px solid #263349;
  padding: 6px 8px; border-radius: 8px; cursor: pointer; font-size: 11px; font-weight: 600; }
.edit-actions button:hover { border-color: #a78bfa; color: #fff; }
.edit-actions button.danger { border-color: #7f1d1d; color: #fecaca; background: #1c1014; grid-column: 1 / -1; }
.edit-actions button.danger:hover { border-color: #ef4444; color: #fff; background: #3f1219; }
.edit-dirty { margin-top: 8px; font-size: 11px; color: #c4b5fd; }
.tag.live .tk::after { content: " LIVE"; color: #4ade80; font-size: 9px; font-weight: 700;
  letter-spacing: .4px; margin-left: 6px; }

#linksPanel { position: fixed; left: 242px; right: 354px; top: 56px; bottom: 12px; z-index: 24;
  background: #0d1526f2; border: 1px solid #1d4ed8; border-radius: 12px; padding: 12px 14px;
  backdrop-filter: blur(8px); overflow: auto; box-shadow: 0 18px 50px #000a; }
#linksPanel[hidden] { display: none !important; }
.links-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.links-head .edit-h span { color: #93c5fd; font-weight: 600; text-transform: none; letter-spacing: 0; }
#linksClose { background: #111a2e; color: #cbd5e1; border: 1px solid #263349; border-radius: 8px;
  padding: 6px 10px; cursor: pointer; font-size: 11px; font-weight: 700; }
.links-gw { display: flex; gap: 8px; align-items: end; margin: 10px 0 8px; flex-wrap: wrap; }
.links-gw label { flex: 1; min-width: 220px; display: flex; flex-direction: column; gap: 3px;
  font-size: 10px; color: #94a3b8; }
.links-gw input { background: #0b1220; color: #e2e8f0; border: 1px solid #22304a; border-radius: 6px;
  padding: 6px 8px; font-size: 12px; }
.links-gw button { background: #111a2e; color: #cbd5e1; border: 1px solid #263349; border-radius: 8px;
  padding: 7px 10px; cursor: pointer; font-size: 11px; font-weight: 700; }
.links-tabs { display: flex; gap: 6px; margin: 8px 0; }
.links-tabs button { background: #111a2e; color: #cbd5e1; border: 1px solid #263349; border-radius: 8px;
  padding: 6px 10px; cursor: pointer; font-size: 11px; font-weight: 700; }
.links-tabs button.on { background: #1d4ed8; border-color: #60a5fa; color: #fff; }
.links-split { display: grid; grid-template-columns: 220px 1fr; gap: 12px; }
.links-list { display: flex; flex-direction: column; gap: 4px; }
.links-row { display: flex; gap: 8px; align-items: center; text-align: left; width: 100%;
  background: #111a2e; color: #cbd5e1; border: 1px solid #263349; border-radius: 8px;
  padding: 8px; cursor: pointer; }
.links-row.sel { outline: 1px solid #60a5fa; background: #1d4ed833; }
.links-row-t { display: flex; flex-direction: column; min-width: 0; }
.links-row-t b { font-size: 12px; }
.links-row-t i { font-style: normal; font-size: 10px; color: #94a3b8; }
.links-led { width: 9px; height: 9px; border-radius: 50%; background: #475569; flex: 0 0 auto; }
.links-led.ok { background: #22c55e; box-shadow: 0 0 8px #22c55e; }
.links-led.bad { background: #ef4444; box-shadow: 0 0 8px #ef4444; }
.links-led.off { background: #475569; }
.links-form .edit-grid label { min-width: 0; }
.links-check { justify-content: center; }
.links-check input { width: 18px; height: 18px; margin-top: 8px; }
.links-pill { display: inline-block; margin-top: 6px; font-size: 11px; color: #93c5fd; }
.links-table-wrap { overflow: auto; max-height: 46vh; border: 1px solid #1e293b; border-radius: 8px; }
.links-table { width: 100%; border-collapse: collapse; font-size: 11px; }
.links-table th { text-align: left; color: #64748b; padding: 6px; font-weight: 600; position: sticky; top: 0;
  background: #0d1526; }
.links-table td { padding: 4px; border-top: 1px solid #172136; }
.links-table input, .links-table select { width: 100%; min-width: 72px; background: #0b1220; color: #e2e8f0;
  border: 1px solid #22304a; border-radius: 6px; padding: 4px 5px; font-size: 11px; }
.links-table button { background: #111a2e; color: #f87171; border: 1px solid #263349; border-radius: 6px;
  cursor: pointer; width: 28px; height: 26px; }
.links-key { background: transparent; color: #7dd3fc; border: 0; cursor: pointer; font-family: ui-monospace, Menlo, monospace; }
.links-status { min-height: 18px; margin-top: 8px; font-size: 12px; color: #93c5fd; }
.links-status.err { color: #f87171; }
.links-status.ok { color: #4ade80; }
.links-help { font-size: 13px; color: #cbd5e1; line-height: 1.5; }
.links-help code { font-size: 11px; background: #0b1220; padding: 1px 5px; border-radius: 4px; color: #93c5fd; }
.links-help ol { padding-left: 18px; }
.links-catalog { display: flex; flex-direction: column; gap: 4px; max-height: 28vh; overflow: auto; margin-top: 6px; }
.links-cat { text-align: left; background: #111a2e; color: #cbd5e1; border: 1px solid #263349;
  border-radius: 8px; padding: 7px 9px; cursor: pointer; font-size: 11px; }
.links-cat:hover { border-color: #60a5fa; }
.links-cat b { color: #7dd3fc; font-family: ui-monospace, Menlo, monospace; }
.links-cat i { color: #94a3b8; font-style: normal; margin-left: 6px; }
.links-cat span { display: block; color: #64748b; font-size: 10px; margin-top: 2px; }
.links-logs { font-size: 11px; color: #94a3b8; font-family: ui-monospace, Menlo, monospace; }
.links-log.err, .links-log.warn { color: #fbbf24; }
.links-pill-row { display: flex; align-items: center; gap: 8px; font-size: 12px; margin: 4px 0; }
.modes button#btnLinksBar { background: #1e3a5f; border-color: #3b82f6; }
.meta b.live { color: #4ade80; }

@media (max-width: 1100px) {
  #linksPanel { left: 8px; right: 8px; }
  .links-split { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  #side { display: none; } #panel { width: 46vw; }
}

.clone-actions { grid-template-columns: 1fr 1fr; }
.clone-actions button { font-size: 12px; }
#fuseStatus { margin-top: 4px; color: #c4b5fd; }
.part-marked { outline: 1px solid #a78bfa; }


/* Modelado taller */
.model-actions button.on { border-color: #22d3ee; color: #fff; background: #155e75; }
#modelHud { position: fixed; left: 240px; right: 380px; bottom: 12px; z-index: 19; pointer-events: none; }
body.modeling #modelHud { pointer-events: auto; }
.model-bar { display: flex; flex-wrap: wrap; gap: 6px; align-items: flex-end;
  background: #0c1929f2; border: 1px solid #0891b2; border-radius: 12px; padding: 10px 12px; }
.model-bar button, .model-bar label { font-size: 11px; color: #cbd5e1; }
.model-bar button { background: #111a2e; border: 1px solid #263349; border-radius: 8px;
  padding: 6px 10px; cursor: pointer; color: #e2e8f0; }
.model-bar button.on, #btnModelApply { background: #0e7490; border-color: #22d3ee; color: #fff; }
.model-title { font-size: 11px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase;
  color: #67e8f9; margin-right: 6px; align-self: center; }
.model-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.model-row[hidden] { display: none !important; }
.model-label { font-size: 10px; color: #94a3b8; text-transform: uppercase; }
.model-check { display: inline-flex; align-items: center; gap: 4px; color: #94a3b8; font-size: 11px; }
.model-bar input[type="number"] { width: 78px; background: #0b1220; color: #e2e8f0; border: 1px solid #22304a;
  border-radius: 6px; padding: 4px 6px; }
.model-help { margin: 6px 4px 0; font-size: 11px; color: #a5f3fc; text-align: center; }
.model-status { font-size: 11px; color: #67e8f9; align-self: center; margin-left: 4px; }
body.modeling #c { cursor: crosshair; }
body.modeling.pulling #c { cursor: ns-resize; }
.model-pull-hint { font-size: 11px; color: #67e8f9; white-space: nowrap; }
.model-actions button[data-model-mode="erase"] {
  border-color: #fb7185; color: #fecdd3;
}
.model-actions button[data-model-mode="erase"].on {
  background: #9f1239; border-color: #fb7185; color: #fff;
}
body.modeling.erasing #c { cursor: cell; }
.model-erase-hint { font-size: 11px; color: #fda4af; }
.model-actions button[data-model-mode="pull"].on {
  background: #0f766e; border-color: #2dd4bf; color: #fff;
}
