*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #0f172a;
  color: #e2e8f0;
  height: 100vh;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ── Toolbar ─────────────────────────────────────────────── */
#toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  background: #1e293b;
  border-bottom: 1px solid #334155;
  padding: 6px 10px;
  flex-shrink: 0;
  flex-wrap: wrap;
  min-height: 64px;
  overflow-x: auto;
}

.toolbar-brand {
  font-size: 15px;
  font-weight: 700;
  color: #38bdf8;
  white-space: nowrap;
  margin-right: 8px;
  letter-spacing: 0.5px;
}

.toolbar-divider {
  width: 1px;
  height: 40px;
  background: #334155;
  margin: 0 6px;
  flex-shrink: 0;
}

.toolbar-section {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: nowrap;
}

.toolbar-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: #64748b;
  margin-right: 4px;
  white-space: nowrap;
}

/* Device add buttons */
.device-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 8px;
  color: #94a3b8;
  cursor: pointer;
  padding: 6px 8px;
  transition: all 0.15s;
  min-width: 52px;
}
.device-btn span { font-size: 10px; }
.device-btn:hover {
  background: #1e3a5f;
  border-color: #38bdf8;
  color: #e2e8f0;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(56,189,248,0.2);
}
.device-btn:active { transform: translateY(0); }

/* Tool buttons */
.tool-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 8px;
  color: #94a3b8;
  cursor: pointer;
  padding: 6px 10px;
  transition: all 0.15s;
  min-width: 56px;
}
.tool-btn span { font-size: 10px; }
.tool-btn:hover {
  background: #1e293b;
  border-color: #475569;
  color: #e2e8f0;
}
.tool-btn.active {
  background: #0369a1;
  border-color: #38bdf8;
  color: #ffffff;
  box-shadow: 0 0 0 1px #38bdf850;
}

/* File buttons */
.file-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 8px;
  color: #94a3b8;
  cursor: pointer;
  padding: 6px 8px;
  transition: all 0.15s;
  min-width: 48px;
}
.file-btn span { font-size: 10px; }
.file-btn:hover {
  background: #1e293b;
  border-color: #475569;
  color: #e2e8f0;
}

/* ── Canvas ──────────────────────────────────────────────── */
#canvas-container {
  flex: 1;
  overflow: hidden;
  position: relative;
  background: #0f172a;
  background-image:
    radial-gradient(circle, #1e293b 1px, transparent 1px);
  background-size: 28px 28px;
}

#canvas {
  display: block;
  cursor: default;
}

/* ── Status bar ──────────────────────────────────────────── */
#statusbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #1e293b;
  border-top: 1px solid #334155;
  padding: 4px 14px;
  font-size: 11px;
  color: #64748b;
  flex-shrink: 0;
}

/* ── Popups ──────────────────────────────────────────────── */
.popup {
  position: fixed;
  background: #1e293b;
  border: 1px solid #475569;
  border-radius: 10px;
  padding: 16px;
  z-index: 1000;
  min-width: 220px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
  display: flex;
  flex-direction: column;
  gap: 8px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
.popup.hidden { display: none; }

.popup label {
  font-size: 12px;
  color: #94a3b8;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.popup input, .popup select {
  background: #0f172a;
  border: 1px solid #475569;
  border-radius: 6px;
  color: #e2e8f0;
  font-size: 13px;
  padding: 7px 10px;
  outline: none;
  transition: border-color 0.15s;
}
.popup input:focus, .popup select:focus {
  border-color: #38bdf8;
}

.popup-btns {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.popup-btns button {
  flex: 1;
  padding: 7px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all 0.15s;
}
.popup-btns button:first-child {
  background: #0369a1;
  color: white;
}
.popup-btns button:first-child:hover { background: #0284c7; }
.popup-btns button:last-child {
  background: #334155;
  color: #94a3b8;
}
.popup-btns button:last-child:hover { background: #475569; }

/* ── Context Menu ────────────────────────────────────────── */
#ctx-menu {
  position: fixed;
  background: #1e293b;
  border: 1px solid #475569;
  border-radius: 8px;
  padding: 6px 0;
  z-index: 2000;
  min-width: 160px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}
#ctx-menu.hidden { display: none; }
.ctx-item {
  padding: 8px 16px;
  font-size: 13px;
  color: #cbd5e1;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}
.ctx-item:hover { background: #334155; color: #fff; }
.ctx-item.danger { color: #f87171; }
.ctx-item.danger:hover { background: #450a0a; }
.ctx-divider { height: 1px; background: #334155; margin: 4px 0; }

/* Tooltip */
[title]:hover::after {
  content: attr(title);
  position: absolute;
  background: #334155;
  color: #e2e8f0;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 4px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 9999;
  top: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
}

/* ── Path Find Panel ─────────────────────────────────────── */
#path-panel {
  position: fixed;
  bottom: 40px;       /* just above the status bar */
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  border: 1px solid #38bdf8;
  border-radius: 10px;
  padding: 0;
  z-index: 1100;
  min-width: 320px;
  max-width: 600px;
  box-shadow: 0 8px 32px rgba(56,189,248,0.25), 0 2px 8px rgba(0,0,0,0.5);
  overflow: hidden;
  animation: pathPanelIn 0.2s ease;
}
#path-panel.hidden { display: none; }

@keyframes pathPanelIn {
  from { opacity: 0; transform: translateX(-50%) translateY(12px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

#path-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #0f172a;
  padding: 8px 14px;
  border-bottom: 1px solid #334155;
}

#path-panel-title {
  font-size: 12px;
  font-weight: 700;
  color: #38bdf8;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

#path-panel-close {
  background: none;
  border: none;
  color: #64748b;
  cursor: pointer;
  font-size: 14px;
  padding: 2px 4px;
  border-radius: 4px;
  line-height: 1;
  transition: color 0.15s;
}
#path-panel-close:hover { color: #e2e8f0; }

#path-panel-body {
  padding: 12px 14px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
}

.path-node {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  color: #e2e8f0;
  font-weight: 600;
}
.path-node.path-source {
  border-color: #38bdf8;
  color: #38bdf8;
  background: rgba(56,189,248,0.1);
}
.path-node.path-dest {
  border-color: #f59e0b;
  color: #f59e0b;
  background: rgba(245,158,11,0.1);
}
.path-node.path-mid {
  border-color: #22d3ee;
  color: #cffafe;
}

.path-arrow {
  color: #64748b;
  font-size: 14px;
  user-select: none;
}

.path-no-path {
  color: #f87171;
  font-size: 13px;
}

/* Path-find button active state (matches tool-btn.active) */
.tool-btn.path-active {
  background: #065f46;
  border-color: #10b981;
  color: #6ee7b7;
  box-shadow: 0 0 0 1px #10b98150;
}

/* Device pick-highlight ring drawn in canvas — just CSS cursor hint */
.canvas-pathpick { cursor: crosshair !important; }
