:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel-border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --green: #3fb950;
  --red: #f85149;
  --grey: #6e7681;
  --accent: #58a6ff;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  padding: 16px;
  min-height: 100vh;
}

/* header */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 4px 16px;
  border-bottom: 1px solid var(--panel-border);
  margin-bottom: 16px;
}
header h1 { font-size: 22px; font-weight: 600; }
header .sub { color: var(--muted); font-size: 13px; }
.header-right { display: flex; align-items: center; gap: 14px; }
.clock { text-align: right; }
.clock #clock-time { font-size: 20px; font-variant-numeric: tabular-nums; }
.clock #clock-date { color: var(--muted); font-size: 12px; }

/* edit / save toggle */
.edit-btn {
  background: var(--panel);
  color: var(--accent);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s, border-color .2s, color .2s;
  white-space: nowrap;
}
.edit-btn:hover { border-color: var(--accent); }
.edit-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* schematic / photo stage */
.schematic {
  background: #fff;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 16px;
}
.photo-stage {
  position: relative;
  line-height: 0;
}
.photo-stage img {
  display: block;
  width: 100%;
  height: auto;
}
.marker {
  position: absolute;
  border: 2px solid var(--grey);
  border-radius: 6px;
  background: rgba(13, 17, 23, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 2px 4px;
  box-sizing: border-box;
  pointer-events: none;
  transition: border-color .3s, box-shadow .3s;
  line-height: 1.1;
}
.marker .led { width: 8px; height: 8px; flex: none; }
.marker-name {
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  text-shadow: 0 1px 2px rgba(0,0,0,.9);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.marker.m-running { border-color: var(--green); box-shadow: 0 0 10px rgba(63,185,80,.55); }
.marker.m-off     { border-color: var(--red);   box-shadow: 0 0 10px rgba(248,81,73,.5); }
.marker.m-unknown { border-color: var(--grey);  border-style: dashed; }

/* edit mode — rectangles become grabable and draggable */
.photo-stage.editing { cursor: move; touch-action: none; user-select: none; -webkit-user-select: none; }
.marker.editing {
  pointer-events: auto;
  cursor: grab;
  border-style: solid;
  border-color: var(--accent);
  border-width: 2px;
  background: rgba(88, 166, 255, 0.12);
  box-shadow: 0 0 0 1px var(--accent), 0 0 12px rgba(88,166,255,.35);
  z-index: 10;
}
.marker.editing:hover { box-shadow: 0 0 0 2px var(--accent), 0 0 14px rgba(88,166,255,.5); }
.marker.editing.dragging { cursor: grabbing; box-shadow: 0 0 0 2px var(--accent), 0 0 18px rgba(88,166,255,.7); }
.marker.editing .marker-name { cursor: grab; }
.marker.editing.dragging .marker-name { cursor: grabbing; }

/* resize corner handles — only visible while editing */
.marker .handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: #fff;
  border: 2px solid var(--accent);
  border-radius: 3px;
  box-sizing: border-box;
  z-index: 20;
  display: none;
  pointer-events: auto;
}
.marker.editing .handle { display: block; }
.handle[data-dir="nw"] { left: -7px; top: -7px; cursor: nwse-resize; }
.handle[data-dir="ne"] { right: -7px; top: -7px; cursor: nesw-resize; }
.handle[data-dir="sw"] { left: -7px; bottom: -7px; cursor: nesw-resize; }
.handle[data-dir="se"] { right: -7px; bottom: -7px; cursor: nwse-resize; }
.marker.editing.resizing { background: rgba(88, 166, 255, 0.2); box-shadow: 0 0 0 2px var(--accent), 0 0 18px rgba(88,166,255,.7); }

/* device blocks */
.blocks {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
.block {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-left: 4px solid var(--grey);
  border-radius: 8px;
  padding: 12px 14px;
  transition: border-color .3s;
}
.block[data-led-running] { border-left-color: var(--green); }
.block[data-led-off]     { border-left-color: var(--red); }
.block-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.block-name { font-size: 14px; font-weight: 600; }
.block-value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.block-detail { color: var(--muted); font-size: 12px; min-height: 16px; }
.block-meta { color: var(--muted); font-size: 11px; margin-top: 6px; }

/* LED */
.led {
  width: 12px; height: 12px;
  border-radius: 50%;
  display: inline-block;
  flex: none;
  box-shadow: 0 0 6px rgba(0,0,0,.4);
}
.led-green { background: var(--green); box-shadow: 0 0 8px var(--green); }
.led-red   { background: var(--red);   box-shadow: 0 0 8px var(--red); }
.led-grey  { background: var(--grey); }

footer { color: var(--muted); font-size: 11px; margin-top: 16px; text-align: center; }
