:root {
  --bg: #0f1722;
  --panel: #16202e;
  --panel-2: #1c2838;
  --line: #2a3a4f;
  --text: #e6edf6;
  --muted: #8aa0b8;
  --accent: #2f9e6e;
  --accent-2: #3b82f6;
  --danger: #e0533d;
  --source: #34c777;
  --load: #f0a93b;
  --closed: #34c777;
  --open: #e0533d;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  background: linear-gradient(180deg, #18222f, #131c27);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand .logo { font-size: 28px; filter: drop-shadow(0 0 8px rgba(59,130,246,.5)); }
.brand h1 { margin: 0; font-size: 18px; letter-spacing: .3px; }
.brand p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }

.actions { display: flex; align-items: center; gap: 8px; }
.actions .sep { width: 1px; height: 26px; background: var(--line); margin: 0 4px; }

.btn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: .15s;
}
.btn:hover { border-color: #46617f; transform: translateY(-1px); }
.btn.ghost { background: transparent; }
.btn.primary { background: var(--accent); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { background: #37b27e; }
.btn.danger:hover { border-color: var(--danger); color: #ffb6a8; }

/* ---------- layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 1fr 360px;
  height: calc(100vh - 60px);
}

/* ---------- canvas ---------- */
.canvas-wrap { position: relative; overflow: hidden; background:
    radial-gradient(circle at 20% 10%, #16263a 0%, #0f1722 60%); }
#canvas { width: 100%; height: 100%; display: block; cursor: default; }
#canvas.panning { cursor: grabbing; }
#canvas.grabbing, #canvas.grabbing * { cursor: grabbing !important; }

/* floating zoom controls (top-left of the canvas) */
.zoom-controls {
  position: absolute;
  left: 12px;
  top: 12px;
  display: flex;
  gap: 6px;
  z-index: 15;
}
.zbtn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 7px;
  font-size: 12.5px;
  cursor: pointer;
}
.zbtn:hover { border-color: var(--accent-2); }

/* canvas hint strip (top-right) */
.hint {
  position: absolute;
  right: 12px;
  top: 12px;
  max-width: 360px;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.5;
  background: rgba(15,23,34,.85);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  pointer-events: none;
  z-index: 14;
}
.hint b { color: var(--text); }

/* ---------- right-click context menu ---------- */
.ctx-menu {
  position: fixed;
  display: none;
  z-index: 50;
  list-style: none;
  margin: 0;
  padding: 5px;
  min-width: 190px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  box-shadow: var(--shadow);
}
.ctx-item {
  padding: 7px 10px;
  font-size: 12.5px;
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
}
.ctx-item:hover { background: #1d2c44; }
.ctx-item.danger { color: #ffb6a8; }
.ctx-item.danger:hover { background: rgba(224,83,61,.18); }
.ctx-sep { height: 1px; margin: 5px 4px; background: var(--line); }
.statusbar {
  position: absolute;
  left: 12px;
  bottom: 10px;
  font-size: 11.5px;
  color: var(--muted);
  background: rgba(15,23,34,.8);
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  pointer-events: none;
}

/* persistent colour legend */
.legend-overlay {
  position: absolute;
  right: 12px;
  bottom: 12px;
  background: rgba(15,23,34,.9);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 11px;
  font-size: 11px;
  color: var(--muted);
  pointer-events: none;
  backdrop-filter: blur(2px);
  max-width: 280px;
}
.legend-overlay .legend-title {
  font-size: 10px; text-transform: uppercase; letter-spacing: 1px;
  color: #93a7be; margin-bottom: 6px;
}
.legend-overlay .lg { display: flex; align-items: center; gap: 7px; line-height: 1.7; }
.legend-overlay .sw { display: inline-block; width: 14px; height: 6px; border-radius: 3px; flex: none; }
.legend-overlay .sw.flow { background: linear-gradient(90deg, #2fe48a, #c9ffe4); height: 5px; }
.legend-overlay .sw.energ { background: #3f9d70; }
.legend-overlay .sw.open { background: #e0533d; }
.legend-overlay .sw.dead { background: #586b84; }
.legend-overlay .sw.src { background: #34c777; border-radius: 50%; width: 10px; height: 10px; }
.legend-overlay .sw.ld { background: #f0a93b; border-radius: 50%; width: 10px; height: 10px; }

/* live status badge */
.live-badge {
  position: absolute;
  left: 50%;
  top: 12px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: .3px;
  padding: 6px 14px;
  border-radius: 20px;
  pointer-events: none;
  z-index: 15;
}
.live-badge .dot { width: 9px; height: 9px; border-radius: 50%; animation: pulse 1s infinite; }
.live-badge.fed { background: rgba(47,228,138,.16); border: 1px solid #2fe48a; color: #b6ffd9; }
.live-badge.fed .dot { background: #2fe48a; }
.live-badge.dead { background: rgba(224,83,61,.16); border: 1px solid #e0533d; color: #ffc3b8; }
.live-badge.dead .dot { background: #e0533d; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .25; } }

/* Play button active state */
.btn.playing { background: var(--accent-2); border-color: var(--accent-2); font-weight: 600; }

/* in-canvas name editor */
.inline-edit {
  position: absolute;
  transform: translate(-50%, -50%);
  z-index: 20;
  width: 120px;
  font: 600 13px "Segoe UI", sans-serif;
  text-align: center;
  color: var(--text);
  background: #0e1722;
  border: 1px solid var(--accent-2);
  border-radius: 6px;
  padding: 3px 6px;
  outline: none;
  box-shadow: 0 4px 16px rgba(0,0,0,.5);
}

/* svg element styles */
.grid line { stroke: #1b2a3c; }
.bus-bar { stroke-width: 7; stroke-linecap: round; cursor: grab; }
.bus-label { font: 600 12px "Segoe UI"; fill: var(--text); pointer-events: none; }
.dev-line { stroke: #7e93ab; stroke-width: 2; }
.flow-arrow { fill: #c9ffe4; }
.handle { cursor: ew-resize; }
.dev-sym { cursor: pointer; }
.dev-label { font: 600 11px "Segoe UI"; fill: #cdd9e6; pointer-events: none; }
.selected { filter: drop-shadow(0 0 6px rgba(59,130,246,.9)); }
.pickable { cursor: pointer; }

/* ---------- right panel ---------- */
.panel {
  background: var(--panel);
  border-left: 1px solid var(--line);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
}
.panel-card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
}
.panel-card.grow { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.panel-card h2 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }

.props-empty, .results-empty { color: var(--muted); font-size: 12.5px; line-height: 1.6; }
.field { margin-bottom: 10px; }
.field label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.field input[type=text] {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 7px 9px;
  border-radius: 7px;
  font-size: 13px;
}
.segmented { display: flex; gap: 6px; }
.segmented button {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 6px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 12px;
}
.segmented button.on { background: #1d2c44; border-color: var(--accent-2); }
.row { display: flex; gap: 8px; align-items: center; }
.meta { font-size: 11.5px; color: var(--muted); }
.btn-del {
  width: 100%; margin-top: 6px;
  background: transparent; border: 1px solid var(--line);
  color: #ffb6a8; padding: 7px; border-radius: 7px; cursor: pointer; font-size: 12.5px;
}
.btn-del:hover { border-color: var(--danger); }

/* results */
.results-head { display: flex; align-items: center; justify-content: space-between; }
.fmt { display: flex; gap: 10px; font-size: 11.5px; color: var(--muted); }
.fmt label { cursor: pointer; }
.warnings:empty { display: none; }
.warnings {
  background: rgba(240,169,59,.1);
  border: 1px solid rgba(240,169,59,.4);
  color: #ffd79a;
  font-size: 12px;
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 10px;
  line-height: 1.5;
}
.warnings ul { margin: 4px 0 0; padding-left: 18px; }
#results { overflow-y: auto; }
.path-item {
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 10px;
  margin-bottom: 9px;
  background: var(--bg);
  cursor: pointer;
  transition: .12s;
}
.path-item:hover { border-color: var(--accent-2); }
.path-item.active { border-color: var(--accent-2); box-shadow: inset 0 0 0 1px rgba(59,130,246,.4); }
.path-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.path-name { font-weight: 600; font-size: 12.5px; }
.path-tag { font-size: 10.5px; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.chip { font-size: 11px; background: #15324a; border: 1px solid #29597f; color: #bfe0ff; padding: 2px 7px; border-radius: 20px; }
.logic { font-family: "Cascadia Code", "Consolas", monospace; font-size: 11.5px; color: #cfe3ff; word-break: break-word; line-height: 1.5; }
.results-summary { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.breakdown { margin-top: 8px; border-top: 1px solid var(--line); padding-top: 7px; display: flex; flex-direction: column; gap: 4px; }
.bd { font-size: 11.5px; color: #cdd9e6; line-height: 1.4; }
.bd b { color: #fff; }
.copybtn { font-size: 10.5px; background: transparent; border: 1px solid var(--line); color: var(--muted); border-radius: 6px; padding: 2px 7px; cursor: pointer; }
.copybtn:hover { color: var(--text); border-color: var(--accent-2); }
