/* The LED layout editor: a dark studio around the room's real picture. Panels are solid
   rail surfaces with hairline dividers; violet marks what is selected or active, cyan
   what is connected and live. The stage itself only gets colours, never geometry. */

body.editing { overflow: hidden; }
body.editing .top, body.editing .hero, body.editing main, body.editing footer, body.editing .cinema-bar { display: none; }

body.editing .room {
  z-index: 0;
  inset: 0;
  width: 100vw;
  height: 100vh;
  transition: none;
}

.led-editor {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: grid;
  grid-template-columns: 276px minmax(0, 1fr) 332px;
  grid-template-rows: 58px minmax(0, 1fr);
  color: var(--text);
  pointer-events: none;
}

.led-editor button:disabled { opacity: 0.38; cursor: default; }

.ed-top, .ed-left, .ed-right {
  background: var(--sidebar);
  pointer-events: auto;
}

/* The top bar */
.ed-top {
  display: flex;
  grid-column: 1 / -1;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  box-shadow: var(--sheen);
}

.ed-title { display: grid; flex: none; max-width: 230px; margin-inline: 4px; line-height: 1.2; }
.ed-title h1 { margin: 0; overflow: hidden; font: 640 0.95rem var(--display); letter-spacing: -0.005em; white-space: nowrap; text-overflow: ellipsis; }
.ed-dirty { display: inline-flex; align-items: center; gap: 6px; color: var(--warn); font-size: 0.72rem; }
.ed-dirty:not(:empty)::before { content: ""; width: 6px; height: 6px; background: currentColor; border-radius: 50%; }
.ed-spacer { flex: 1; }

.ed-group {
  display: flex;
  flex: none;
  align-items: center;
  gap: 2px;
  padding: 2px;
  background: var(--well);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
}

.ed-zoom { min-width: 48px; color: var(--muted); font-size: 0.78rem; text-align: center; font-variant-numeric: tabular-nums; }
.ed-top .primary, .ed-top .ghost { display: inline-flex; flex: none; align-items: center; gap: 6px; }
.ed-top .primary .ed-icon, .ed-top .ghost .ed-icon { width: 16px; height: 16px; }

.ed-icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.ed-icon-button {
  display: grid;
  flex: none;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: var(--r-xs);
  transition: color var(--fast) var(--ease), background-color var(--fast) var(--ease);
}

.ed-icon-button:hover:not(:disabled) { color: var(--text); background: var(--surface-hover); }
.ed-icon-button:active:not(:disabled) { background: var(--surface-press); }
.ed-icon-button[aria-pressed="true"], .ed-icon-button.active { color: var(--violet-ink); background: color-mix(in srgb, var(--violet) 20%, transparent); }
.ed-icon-button[aria-pressed="true"]:hover:not(:disabled), .ed-icon-button.active:hover:not(:disabled) { color: var(--text); background: color-mix(in srgb, var(--violet) 30%, transparent); }

.led-editor :is(.ed-icon-button, .ed-tool, .ed-rail-handle, .ed-row-main):focus-visible {
  outline: 2px solid var(--violet-ink);
  outline-offset: 2px;
}

/* The sidebars */
.ed-left, .ed-right { min-height: 0; overflow-y: auto; scrollbar-width: thin; }
.ed-left { border-right: 1px solid var(--line); }
.ed-right { border-left: 1px solid var(--line); }
.ed-panel-body { padding: 10px 14px 28px; }
.ed-left h3 { margin: 20px 0 6px; color: var(--muted); font: 600 0.8rem var(--display); }

.ed-list { display: grid; gap: 2px; margin: 0; padding: 0; list-style: none; }
.ed-row { border-radius: var(--r-xs); transition: background-color var(--fast) var(--ease); }
.ed-row.on { background: color-mix(in srgb, var(--violet) 16%, transparent); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--violet) 34%, transparent); }
.ed-row-line { display: flex; align-items: center; gap: 0; padding-left: 2px; }

.ed-row-main {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 9px;
  min-width: 0;
  width: 100%;
  min-height: 40px;
  padding: 5px 8px;
  color: inherit;
  text-align: left;
  background: none;
  border: 0;
  border-radius: var(--r-xs);
}

.ed-row-main:hover { background: var(--surface-hover); }
.ed-row.on .ed-row-main:hover { background: color-mix(in srgb, var(--violet) 8%, transparent); }
.ed-row-text { display: grid; min-width: 0; line-height: 1.3; }
.ed-row-text b { overflow: hidden; font-size: 0.84rem; font-weight: 600; white-space: nowrap; text-overflow: ellipsis; }
.ed-row-text small { overflow: hidden; color: var(--muted); font-size: 0.72rem; white-space: nowrap; text-overflow: ellipsis; }
.ed-row.unassigned .ed-row-text small, .ed-row.offline .ed-row-text small { color: var(--warn); }
.ed-row.invalid .ed-row-text small { color: var(--bad-ink); }
.ed-row.online .ed-row-text small { color: var(--cyan); }
.ed-row-more { display: grid; gap: 4px; padding: 2px 10px 10px; font-size: 0.78rem; }
.ed-row-more .row.wrap { margin-block: 4px 0; }
.ed-row-more .toggle { font-size: 0.8rem; }

.ed-dot { flex: none; width: 8px; height: 8px; background: var(--faint); border-radius: 50%; }
.ed-dot.online { background: var(--cyan); box-shadow: 0 0 0 3px color-mix(in srgb, var(--cyan) 18%, transparent); }
.ed-dot.connecting { background: transparent; border: 1.5px solid var(--warn); }
.ed-dot.offline { background: var(--bad); }
.ed-swatch { flex: none; width: 14px; height: 14px; background: var(--raised); border: 1px solid var(--edge-strong); border-radius: 4px; }

/* The selected strip */
.ed-strip-head { padding-top: 6px; }
.ed-strip-head h2 { margin: 0 0 10px; overflow: hidden; font: 640 1.02rem var(--display); white-space: nowrap; text-overflow: ellipsis; }
.ed-strip-tools { display: flex; flex-wrap: wrap; gap: 6px; }
.ed-strip-tools .mini, .ed-right .row .mini { display: inline-flex; align-items: center; gap: 5px; min-height: 32px; }
.ed-strip-tools .ed-icon, .ed-right .mini .ed-icon { width: 14px; height: 14px; }
.ed-section { margin-top: 14px; border-top: 1px solid var(--line); }
.ed-section[open] { padding-bottom: 6px; }

.ed-section summary {
  display: flex;
  align-items: center;
  min-height: 40px;
  padding: 4px 0 0;
  color: var(--text);
  font: 600 0.82rem var(--display);
  cursor: pointer;
}

.ed-section summary:hover { color: var(--violet-ink); }
.ed-section .fields { gap: 10px; }
.ed-fact { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 8px; margin-top: 8px; font-size: 0.8rem; line-height: 1.35; }
.ed-fact > :first-child { color: var(--muted); }
.ed-fact [data-status="online"] { color: var(--cyan); }
.ed-fact [data-status="offline"] { color: var(--bad-ink); }
.ed-fact [data-status="connecting"] { color: var(--warn); }
.ed-right .toggle { margin-top: 4px; font-size: 0.84rem; }
.ed-quality[data-kind="exact"] { color: var(--ok); }
.ed-quality[data-kind="stretched"], .ed-quality[data-kind="single"] { color: var(--warn); }
.ed-empty { padding-top: 10px; }
.ed-empty h2 { margin: 6px 0; font: 640 1rem var(--display); }

.ed-notice {
  margin: 10px 0 0;
  padding: 9px 12px;
  color: var(--warn);
  font-size: 0.78rem;
  line-height: 1.4;
  background: color-mix(in srgb, var(--warn) 9%, transparent);
  border: 1px solid color-mix(in srgb, var(--warn) 26%, transparent);
  border-radius: var(--r-sm);
}

.ed-notice[data-kind="info"] { color: var(--muted); background: var(--surface); border-color: var(--line); }

/* The middle */
.ed-stage { position: relative; min-width: 0; min-height: 0; pointer-events: auto; }
.ed-canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; touch-action: none; user-select: none; cursor: default; }
.ed-canvas[data-tool="pan"] { cursor: grab; }
.ed-canvas[data-tool="strip"], .ed-canvas[data-tool="freehand"], .ed-canvas[data-tool="line"], .ed-canvas[data-tool="polyline"],
.ed-canvas[data-tool="curve"], .ed-canvas[data-tool="rect"], .ed-canvas[data-tool="ellipse"], .ed-canvas[data-tool="bulb"] { cursor: crosshair; }
.ed-canvas[data-tool="delete"] .ed-hit { cursor: not-allowed; }

.ed-rail {
  z-index: 10;
  position: absolute;
  top: 12px;
  left: 12px;
  display: grid;
  gap: 2px;
  padding: 4px;
  max-height: calc(100% - 24px);
  overflow-y: auto;
  scrollbar-width: thin;
  background: var(--glass-strong);
  border: 1px solid var(--edge);
  border-radius: var(--r-md);
  box-shadow: var(--sheen), var(--lift);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
}

.ed-rail-handle {
  width: 100%;
  height: 18px;
  padding: 0;
  color: var(--faint);
  background: transparent;
  border: 0;
  border-radius: var(--r-xs);
  cursor: grab;
  touch-action: none;
  user-select: none;
  line-height: 1;
}

.ed-rail-handle:hover { color: var(--text); background: var(--surface-hover); }
.ed-rail-header { display: flex; align-items: center; grid-column: 1 / -1; }
.ed-rail-header .ed-rail-handle { flex: 1; width: auto; min-width: 16px; height: 28px; }
.ed-label-toggle { display: grid; place-items: center; flex: none; width: 28px; height: 28px; padding: 0; color: var(--text); background: none; border: 0; border-radius: var(--r-xs); }
.ed-label-toggle:hover { background: var(--surface-hover); }
.ed-label-toggle:focus-visible { outline: 2px solid var(--violet-ink); outline-offset: 2px; }
.ed-label-toggle .ed-icon { width: 14px; height: 14px; }
.ed-rail-compact .ed-rail-header { flex-direction: column; }
.ed-rail-compact .ed-rail-header .ed-rail-handle { width: 100%; }
.ed-rail.dragging .ed-rail-handle { color: var(--violet-ink); cursor: grabbing; }

.ed-tool {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 154px;
  min-height: 36px;
  padding: 6px 9px;
  text-align: left;
  font-size: 0.78rem;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: var(--r-xs);
  transition: color var(--fast) var(--ease), background-color var(--fast) var(--ease);
}

.ed-tool .ed-icon { flex: none; }
.ed-tool kbd { margin-left: auto; color: inherit; opacity: 0.7; font: inherit; font-size: 0.68rem; }
.ed-rail-compact .ed-tool { width: 36px; justify-content: center; padding-inline: 0; }
.ed-rail-compact .ed-tool :is(span, kbd) { display: none; }
.ed-connect { margin-top: 5px; border-top: 1px solid var(--line); border-radius: 0 0 var(--r-xs) var(--r-xs); }

.ed-tool:hover { color: var(--text); background: var(--surface-hover); }
.ed-tool:active { background: var(--surface-press); }
.ed-tool[aria-pressed="true"] { color: #fff; background: var(--violet); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18); }

.ed-hint {
  position: absolute;
  right: 12px;
  bottom: 10px;
  left: 12px;
  width: fit-content;
  max-width: calc(100% - 24px);
  margin: 0 auto;
  padding: 7px 14px;
  color: var(--text);
  font-size: 0.8rem;
  line-height: 1.4;
  background: var(--glass-strong);
  border: 1px solid var(--edge);
  border-radius: var(--r-sm);
  box-shadow: var(--sheen), var(--lift);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
  pointer-events: none;
}

.ed-overflow, .ed-photo-note { position: absolute; top: 12px; right: 12px; left: 66px; width: fit-content; margin: 0 auto; }
.ed-overflow { background: color-mix(in srgb, var(--warn) 12%, var(--glass-solid)); }
.ed-photo-note { top: auto; bottom: 52px; background: color-mix(in srgb, var(--warn) 12%, var(--glass-solid)); }

/* What's drawn over the photo. Marks carry a dark halo so they read on any light. */
.ed-hit { fill: none; stroke: transparent; stroke-width: 18; pointer-events: stroke; cursor: move; }
circle.ed-hit { fill: transparent; stroke: none; pointer-events: all; }
.ed-strip.locked .ed-hit { cursor: default; }
.ed-line { fill: none; stroke: rgba(245, 247, 255, 0.85); stroke-width: 1.5; stroke-dasharray: 6 4; pointer-events: none; filter: drop-shadow(0 0 1px rgba(9, 11, 18, 0.9)); }
circle.ed-line { fill: rgba(245, 247, 255, 0.16); }
.ed-strip.online .ed-line { stroke: var(--cyan); }
.ed-strip.offline .ed-line, .ed-strip.unassigned .ed-line { stroke: var(--warn); }
.ed-strip.invalid .ed-line { stroke: var(--bad); }
.ed-strip.locked .ed-line { stroke-opacity: 0.6; }
.ed-strip.selected .ed-line { stroke: #fff; stroke-width: 2; stroke-dasharray: none; stroke-opacity: 1; filter: drop-shadow(0 0 1.5px var(--violet)) drop-shadow(0 0 1px rgba(9, 11, 18, 0.9)); }
.ed-arrow { fill: none; stroke: #fff; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; filter: drop-shadow(0 0 1px rgba(9, 11, 18, 0.9)); }
.ed-first circle { fill: #fff; stroke: var(--violet); stroke-width: 1.5; }
.ed-first text { fill: var(--ink); font-size: 10px; font-weight: 700; }
.ed-first { pointer-events: none; }

.ed-label {
  fill: var(--text);
  font-size: 12px;
  font-weight: 600;
  paint-order: stroke;
  stroke: rgba(9, 11, 18, 0.82);
  stroke-width: 3px;
  stroke-linejoin: round;
  pointer-events: none;
}

.ed-strip.selected .ed-label { fill: #fff; }

.ed-box { fill: none; stroke: var(--violet-ink); stroke-width: 1; stroke-dasharray: 4 3; pointer-events: none; }
.ed-handle { fill: #fff; stroke: var(--violet); stroke-width: 1.5; }
.ed-handle:hover { fill: var(--violet-ink); }
.ed-handle.nw, .ed-handle.se { cursor: nwse-resize; }
.ed-handle.ne, .ed-handle.sw { cursor: nesw-resize; }
.ed-handle.n, .ed-handle.s { cursor: ns-resize; }
.ed-handle.e, .ed-handle.w { cursor: ew-resize; }
.ed-rotate { fill: var(--violet); stroke: #fff; stroke-width: 1.5; cursor: grab; }
.ed-point { fill: #fff; stroke: var(--violet); stroke-width: 2; cursor: crosshair; }
.ed-point:hover { fill: var(--violet-ink); }
.ed-point.on { fill: var(--violet); stroke: #fff; }
.ed-sketch { fill: color-mix(in srgb, var(--violet) 10%, transparent); stroke: var(--violet-ink); stroke-width: 2; pointer-events: none; filter: drop-shadow(0 0 1px rgba(9, 11, 18, 0.9)); }
polyline.ed-sketch { fill: none; }
.ed-sketch-point { fill: #fff; stroke: var(--violet); stroke-width: 1.5; pointer-events: none; }
.ed-grid line { stroke: rgba(245, 247, 255, 0.12); stroke-width: 1; pointer-events: none; }
.ed-guides line { stroke: var(--violet-ink); stroke-width: 1; stroke-dasharray: 4 3; pointer-events: none; }

/* Preview: only the room */
.ed-preview-bar {
  position: absolute;
  right: 0;
  bottom: 20px;
  left: 0;
  display: none;
  gap: 6px;
  justify-content: center;
  width: fit-content;
  max-width: calc(100% - 24px);
  margin-inline: auto;
  padding: 6px;
  background: var(--glass-strong);
  border: 1px solid var(--edge);
  border-radius: var(--r-md);
  box-shadow: var(--sheen), var(--lift);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
  pointer-events: auto;
}

body.ed-previewing .led-editor { grid-template-columns: 0 minmax(0, 1fr) 0; grid-template-rows: 0 minmax(0, 1fr); }
body.ed-previewing .ed-top, body.ed-previewing .ed-left, body.ed-previewing .ed-right, body.ed-previewing .ed-rail, body.ed-previewing .ed-hint { display: none; }
body.ed-previewing .ed-preview-bar { display: flex; }
body.ed-previewing .ed-stage { grid-column: 2; grid-row: 2; }

@media (max-width: 1240px) {
  .led-editor { grid-template-columns: 236px minmax(0, 1fr) 290px; }
  .ed-top { gap: 6px; padding: 0 8px; }
  .ed-title { max-width: 150px; }
}

/* On a narrow screen the sidebars sit below the photo and scroll with their own content */
@media (max-width: 900px) {
  .led-editor { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) 36vh; }
  .ed-top { overflow-x: auto; padding-block: 6px; scrollbar-width: none; }
  .ed-top::-webkit-scrollbar { display: none; }
  .ed-stage { grid-column: 1 / -1; grid-row: 2; }
  .ed-left { grid-row: 3; border-top: 1px solid var(--line); }
  .ed-right { grid-row: 3; border-top: 1px solid var(--line); }
  .ed-panel-body { padding-inline: 12px; }
  body.ed-previewing .led-editor { grid-template-columns: 0 minmax(0, 1fr) 0; grid-template-rows: 0 minmax(0, 1fr) 0; }

  .ed-icon-button { width: 40px; height: 40px; }
  .ed-row-main { min-height: 44px; }
  .ed-strip-tools .mini, .ed-right .row .mini { min-height: 40px; }
  .ed-section summary { min-height: 44px; }

  /* Two columns of tools so the rail fits the shorter stage */
  .ed-rail { grid-template-columns: repeat(2, minmax(0, 1fr)); width: min(296px, calc(100% - 16px)); top: 8px; left: 8px; }
  .ed-rail-handle { grid-column: 1 / -1; height: 22px; }
  .ed-tool { width: 100%; min-height: 40px; }
  .ed-tool kbd { display: none; }
  .ed-rail-compact { width: auto; grid-template-columns: repeat(2, 40px); }
  .ed-rail-compact .ed-tool { width: 40px; }
}

@media (prefers-reduced-transparency: reduce) {
  .ed-rail, .ed-hint, .ed-preview-bar { background: var(--glass-solid); -webkit-backdrop-filter: none; backdrop-filter: none; }
}

@media (prefers-reduced-motion: reduce) {
  .ed-icon-button, .ed-tool, .ed-row { transition: none; }
}
