:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --ink: #172033;
  --muted: #5f697a;
  --line: #d8deea;
  --panel: #ffffff;
  --panel-2: #eef3f8;
  --private: #635bff;
  --lan: #16846f;
  --restricted: #c0522b;
  --node: #22324f;
  --accent: #0f766e;
  --warn: #b45309;
  --danger: #b42318;
  --shadow: 0 18px 45px rgba(23, 32, 51, 0.1);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

html,
body {
  height: 100%;
}

.intro-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(16, 24, 39, 0.72);
  cursor: pointer;
}

.intro-panel {
  width: min(520px, 100%);
  padding: 24px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.24);
  cursor: pointer;
}

.intro-panel h2 {
  font-size: 22px;
  line-height: 1.15;
}

.intro-panel p {
  margin-top: 12px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
select {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  min-height: 34px;
  border-radius: 6px;
}

button {
  padding: 0 12px;
  cursor: pointer;
}

button:hover,
select:hover {
  border-color: #a9b5c8;
}

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) minmax(128px, 21vh) 150px;
  gap: 12px;
  padding: 14px;
  overflow: hidden;
}

.topbar,
.inventory,
.editor,
.detail-pane,
.console-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 16px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.15;
  letter-spacing: 0;
}

h2 {
  font-size: 14px;
  line-height: 1.2;
}

.topbar p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.topbar-actions,
.panel-heading {
  display: flex;
  align-items: center;
  gap: 8px;
}

.editor-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.danger-button {
  color: var(--danger);
  border-color: #f0b5ad;
  background: #fff7f5;
}

.danger-text-button {
  color: var(--danger);
  border-color: #f0b5ad;
  background: #fff;
  font-weight: 800;
}

.confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(16, 24, 39, 0.62);
}

.confirm-panel {
  width: min(390px, 100%);
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.24);
}

.confirm-panel h2 {
  font-size: 18px;
  line-height: 1.2;
}

.confirm-panel p {
  margin-top: 10px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.workspace {
  display: grid;
  grid-template-columns: 250px minmax(420px, 1fr) 310px;
  gap: 12px;
  min-height: 0;
}

.inventory,
.editor {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.panel-heading {
  justify-content: space-between;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.tabs {
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-2);
}

.tab {
  min-height: 28px;
  padding: 0 10px;
  border: 0;
  background: transparent;
  border-radius: 5px;
  font-size: 12px;
}

.tab.active {
  background: #fff;
  box-shadow: 0 1px 5px rgba(23, 32, 51, 0.12);
}

.node-list,
.link-list {
  padding: 8px;
  display: grid;
  align-content: start;
  gap: 8px;
  overflow: auto;
  min-height: 0;
}

.node-card,
.link-card {
  border: 1px solid var(--line);
  border-left: 4px solid var(--node);
  border-radius: 7px;
  padding: 9px;
  background: #fff;
  text-align: left;
  min-height: 72px;
}

.cluster-card {
  border-left-color: var(--accent);
  background: #f8fbfc;
  min-height: 78px;
}

.nested-card {
  margin-left: 16px;
  min-height: 62px;
  border-left-width: 2px;
}

.node-card.active,
.link-card.active {
  border-color: #7280f7;
  border-left-color: var(--private);
  background: #f7f8ff;
}

.node-card.multi-selected,
.link-card.multi-selected {
  border-color: var(--accent);
  background: #f3fbf8;
}

.node-card strong,
.node-card span {
  display: block;
}

.node-card-top {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
}

.node-card-top strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.node-card-icon {
  color: var(--node);
}

.node-card-meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.link-card strong,
.link-card span {
  display: block;
}

.link-card span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.badges {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  border-radius: 999px;
  padding: 0 7px;
  font-size: 11px;
  color: #fff;
  background: var(--node);
}

.badge.private {
  background: var(--private);
}

.badge.lan {
  background: var(--lan);
}

.badge.restricted {
  background: var(--restricted);
}

.badge.container {
  background: #6d5b38;
}

.badge.group {
  background: #466383;
}

.graph-stage {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(rgba(34, 50, 79, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(34, 50, 79, 0.06) 1px, transparent 1px),
    #fbfcff;
  background-size: 34px 34px;
  min-height: 0;
}

#graph {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}

#graph:active {
  cursor: grabbing;
}

#graph.select-mode {
  cursor: crosshair;
}

#graph.pan-mode {
  cursor: grab;
}

#graph.pan-mode:active {
  cursor: grabbing;
}

#graph.is-panning {
  cursor: grabbing;
}

.edge {
  fill: none;
  stroke-width: 4;
  stroke-linecap: round;
  opacity: 0.74;
  cursor: pointer;
}

.edge-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 24;
  stroke-linecap: round;
  cursor: pointer;
  pointer-events: stroke;
}

.group-hull {
  fill: rgba(22, 132, 111, 0.07);
  stroke: rgba(22, 132, 111, 0.38);
  stroke-width: 2;
  stroke-dasharray: 7 6;
  cursor: grab;
  pointer-events: visiblePainted;
}

.container-hull {
  fill: rgba(109, 91, 56, 0.055);
  stroke: rgba(109, 91, 56, 0.42);
  stroke-width: 2;
  cursor: grab;
  pointer-events: visiblePainted;
}

.container-hull:active {
  cursor: grabbing;
}

.container-label {
  fill: #6d5b38;
  font-size: 13px;
  font-weight: 800;
  cursor: text;
  pointer-events: all;
}

.group-hull:active {
  cursor: grabbing;
}

.group-label {
  fill: var(--accent);
  font-size: 12px;
  font-weight: 700;
  cursor: text;
  pointer-events: all;
}

.edge.dimmed {
  opacity: 0.12;
}

.edge.active {
  stroke-width: 6;
  opacity: 1;
}

.draft-edge {
  fill: none;
  stroke: var(--accent);
  stroke-width: 4;
  stroke-dasharray: 8 7;
  stroke-linecap: round;
  pointer-events: none;
}

.selection-box {
  fill: rgba(15, 118, 110, 0.12);
  stroke: var(--accent);
  stroke-width: 2;
  stroke-dasharray: 7 5;
  pointer-events: none;
}

.edge-label {
  font-size: 12px;
  fill: var(--ink);
  paint-order: stroke;
  stroke: #fff;
  stroke-width: 5px;
  pointer-events: none;
}

.graph-node {
  cursor: grab;
}

.graph-node:active {
  cursor: grabbing;
}

.graph-node circle {
  fill: #fff;
  stroke: var(--node);
  stroke-width: 4;
  filter: url(#nodeShadow);
}

.graph-node.active circle {
  stroke: var(--private);
  stroke-width: 6;
}

.graph-node.multi-selected circle {
  stroke: var(--accent);
  stroke-width: 6;
}

.graph-node.restricted circle {
  stroke: var(--restricted);
}

.graph-node .connection-handle {
  fill: #fff;
  stroke: var(--accent);
  stroke-width: 3;
  filter: none;
  cursor: crosshair;
}

.graph-node .connection-handle:hover {
  fill: #dff8f1;
}

.graph-node text {
  text-anchor: middle;
  fill: var(--ink);
  pointer-events: none;
}

.node-icon {
  color: var(--node);
  pointer-events: none;
}

.node-name {
  font-weight: 700;
  font-size: 13px;
}

.node-ip {
  font-size: 11px;
  fill: var(--muted);
}

.tooltip {
  position: absolute;
  z-index: 5;
  max-width: 280px;
  pointer-events: none;
  padding: 10px;
  border-radius: 7px;
  color: #fff;
  background: rgba(20, 28, 44, 0.94);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.18);
  font-size: 12px;
  line-height: 1.35;
}

.tooltip strong {
  display: block;
  margin-bottom: 4px;
}

.context-menu {
  position: absolute;
  z-index: 8;
  min-width: 190px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  box-shadow: 0 18px 42px rgba(23, 32, 51, 0.18);
}

.context-menu button {
  display: block;
  width: 100%;
  min-height: 32px;
  padding: 0 9px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  text-align: left;
}

.context-menu button:hover {
  background: var(--panel-2);
}

.tooltip-service-common,
.tooltip-service-diff {
  display: inline-block;
  margin: 4px 6px 0 0;
  padding: 2px 6px;
  border-radius: 5px;
  background: #fff;
}

.tooltip-service-common {
  color: #000;
}

.tooltip-service-diff {
  color: #a33b12;
  background: #fff4ed;
}

.tooltip-connection-list {
  display: grid;
  gap: 5px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.22);
}

.tooltip-connection-row {
  color: rgba(255, 255, 255, 0.84);
}

.tooltip-connection-row strong {
  margin: 0;
  color: #fff;
  font-size: 11px;
}

.mode-control,
.view-control,
.tile-control,
.legend-control {
  position: absolute;
  z-index: 4;
  display: grid;
  justify-items: end;
  gap: 6px;
}

.mode-control {
  left: 12px;
  top: 12px;
  grid-auto-flow: column;
  justify-items: start;
}

.view-control {
  right: 12px;
  top: 12px;
}

.legend-control {
  right: 12px;
  bottom: 12px;
}

.tile-control {
  left: 12px;
  bottom: 12px;
  justify-items: start;
}

.zoom-buttons {
  display: flex;
  gap: 6px;
}

.zoom-buttons button {
  width: 32px;
  padding-inline: 0;
  font-weight: 800;
}

.mode-control button,
.view-control button,
.tile-control button,
.legend-control button {
  min-height: 30px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 6px 18px rgba(23, 32, 51, 0.14);
}

.mode-control button.active {
  border-color: var(--accent);
  color: #fff;
  background: var(--accent);
}

.legend-panel {
  display: grid;
  gap: 8px;
  width: 180px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 12px 30px rgba(23, 32, 51, 0.16);
  font-size: 12px;
}

.legend-panel div {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
}

.legend-line,
.legend-dash,
.legend-box {
  display: block;
  width: 34px;
  height: 0;
  border-top: 4px solid var(--node);
  border-radius: 999px;
}

.legend-line.private {
  border-color: var(--private);
}

.legend-line.lan {
  border-color: var(--lan);
}

.legend-dash {
  border-top: 2px dashed rgba(22, 132, 111, 0.65);
}

.legend-box {
  height: 18px;
  border: 2px solid rgba(109, 91, 56, 0.65);
  border-radius: 4px;
  background: rgba(109, 91, 56, 0.08);
}

.legend-node {
  width: 18px;
  height: 18px;
  border: 4px solid var(--node);
  border-radius: 50%;
  justify-self: center;
  background: #fff;
}

.legend-node.restricted {
  border-color: var(--restricted);
}

.legend-node.selected {
  border-color: var(--private);
}

.edit-form {
  display: grid;
  align-content: start;
  gap: 10px;
  padding: 12px;
  overflow: auto;
  min-height: 0;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  color: var(--ink);
  background: #fff;
}

textarea {
  min-height: 70px;
  resize: vertical;
}

.field-grid {
  display: grid;
  gap: 9px;
}

.advanced-options {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-2);
  padding: 8px;
}

.advanced-options summary {
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
}

.advanced-options label {
  margin-top: 10px;
}

.option-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 10px;
}

.detail-strip {
  display: grid;
  grid-template-columns: 250px 1fr 1fr;
  gap: 12px;
  min-height: 0;
  overflow: hidden;
}

.detail-pane {
  min-width: 0;
  padding: 12px;
  overflow: auto;
}

.detail-pane h2 {
  margin-bottom: 10px;
}

dl {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 7px 10px;
  margin: 0;
  font-size: 13px;
}

dt {
  color: var(--muted);
}

dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.service-pane {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 8px;
}

.service-card {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 9px;
  background: var(--panel-2);
}

.service-card strong,
.service-card span {
  display: block;
}

.service-card span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

pre {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.console-wrap {
  display: grid;
  grid-template-rows: 1fr auto;
  min-height: 0;
  overflow: hidden;
  background: #101827;
  color: #e6edf7;
  border-color: #253248;
}

.console-log {
  padding: 10px 12px;
  overflow: auto;
  font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.console-line {
  min-height: 18px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.console-line.command {
  color: #9ee2d1;
}

.console-line.error {
  color: #ffb4a8;
}

.console-form {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
  border-top: 1px solid #253248;
  padding: 8px;
}

.console-form input {
  background: #172238;
  color: #f8fbff;
  border-color: #2d3a52;
}

.console-form button {
  background: #eef3f8;
}

@media (max-width: 1060px) {
  .app-shell {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .workspace {
    grid-template-columns: 220px minmax(360px, 1fr);
  }

  .editor {
    grid-column: 1 / -1;
  }

  .detail-strip {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 8px;
    grid-template-rows: auto auto auto 180px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    flex-wrap: wrap;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .graph-stage {
    min-height: 390px;
  }
}
