:root {
  color-scheme: light;
  -webkit-tap-highlight-color: transparent;
  --bg: #e9eef1;
  --panel: #ffffff;
  --panel-up: #f7fafb;
  --stroke: #c9d6db;
  --line: #dce5e9;
  --text: #162c35;
  --sub: #344e5d;
  --muted: #586f7c;
  --mint: #08745e;
  --mint-soft: rgba(8, 116, 94, 0.12);
  --violet: #704ba4;
  --blue: #275faa;
  --amber: #c26d0a;
  --rose: #b84264;
  --danger: #c63848;
  --header: #ffffff;
  --border-strong: #9aaeb9;
  --surface-tint: #edf3f5;
  --hover: #e5eff0;
  --selected: #dce9ea;
  --canvas: #f2f5f7;
  --canvas-dot: rgba(20, 48, 60, 0.14);
  --glow: #dbece7;
  --label-bg: rgba(255, 255, 255, 0.94);
  --shadow: 0 2px 10px rgba(22, 44, 53, 0.06);
  --shadow-lg: 0 12px 32px rgba(22, 44, 53, 0.11);
  --map-card: #ffffff;
  --map-card-edge: #cfdbe0;
  --map-card-rule: #e4ecef;
  --bar-empty: #dce5e9;
  --bar-ok: #10a37f;
  --bar-warn: #e0912a;
  --bar-down: #d94858;
  --bar-standby: #94a7b3;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #0b1015;
  --panel: #10171e;
  --panel-up: #151d25;
  --stroke: #27313c;
  --line: #222d37;
  --text: #e9eff3;
  --sub: #b7c2cd;
  --muted: #8a99a8;
  --mint: #5dd8b4;
  --mint-soft: rgba(93, 216, 180, 0.14);
  --violet: #b4a0ef;
  --blue: #7fb2f8;
  --amber: #f2b56b;
  --rose: #ed93ac;
  --danger: #f06e7d;
  --header: #0d1319;
  --border-strong: #3c4d5b;
  --surface-tint: #19232c;
  --hover: #1b2830;
  --selected: #23313b;
  --canvas: #0d141b;
  --canvas-dot: rgba(255, 255, 255, 0.09);
  --glow: #142629;
  --label-bg: rgba(16, 23, 30, 0.92);
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.28);
  --shadow-lg: 0 14px 36px rgba(0, 0, 0, 0.45);
  --map-card: #18222c;
  --map-card-edge: #31414f;
  --map-card-rule: #253340;
  --bar-empty: #26333f;
  --bar-ok: #34d399;
  --bar-warn: #f59e0b;
  --bar-down: #f87171;
  --bar-standby: #64748b;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  color: var(--text);
  background: radial-gradient(ellipse at 25% -20%, var(--glow) 0%, transparent 55%), var(--bg);
  min-height: 100vh;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }

.workspace {
  max-width: 1460px;
  margin: 0 auto;
  padding: 16px 20px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.topology-panel {
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.topology-panel.is-expanded {
  position: fixed;
  inset: 12px;
  z-index: 60;
  max-width: none;
}

/* Header */
.board-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  background: var(--header);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.head-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.02em;
}

.brand-sub {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--mint-soft);
  color: var(--mint);
  font-weight: 600;
  font-size: 11.5px;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 2.2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.85); }
}

/* Telemetry summary */
.telemetry {
  display: flex;
  align-items: center;
  gap: 20px;
  margin: 0;
  padding: 6px 14px;
  background: var(--panel-up);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.telemetry-item {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.telemetry-item dt {
  font-size: 11px;
  color: var(--muted);
}

.telemetry-item dd {
  margin: 0;
  font-family: var(--mono);
  font-size: 13.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Actions */
.board-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.board-clock {
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--sub);
  padding: 6px 10px;
  border-radius: 10px;
  background: var(--panel-up);
  border: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}

.board-clock small {
  color: var(--muted);
  margin-left: 4px;
  font-size: 10.5px;
}

.control-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-up);
  color: var(--sub);
  font-size: 12.5px;
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.control-btn:hover {
  background: var(--hover);
  border-color: var(--border-strong);
  color: var(--text);
}

.control-btn.active {
  background: var(--mint-soft);
  border-color: rgba(8, 116, 94, 0.32);
  color: var(--mint);
}

.icon-btn {
  width: 34px;
  height: 34px;
  padding: 0;
  justify-content: center;
}

/* Route filter strip */
.route-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: var(--panel-up);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}
.route-strip::-webkit-scrollbar { display: none; }

.route-chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--sub);
  font-size: 12.5px;
  font-weight: 500;
  transition: all 0.15s ease;
}

.route-chip:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.route-chip.active {
  background: var(--text);
  color: var(--panel);
  border-color: var(--text);
}

.route-chip .chip-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

.route-chip .chip-ms {
  font-family: var(--mono);
  font-size: 11.5px;
  opacity: 0.78;
}

/* Canvas Area */
.canvas-scroll {
  position: relative;
  overflow: auto;
  background-color: var(--canvas);
  background-image: radial-gradient(var(--canvas-dot) 1.25px, transparent 1.25px);
  background-size: 20px 20px;
  min-height: 540px;
  flex: 1;
}

.topology-stage {
  position: relative;
  margin: 0 auto;
  min-height: 540px;
}

.edges-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}

.edge-group {
  pointer-events: visibleStroke;
  cursor: pointer;
  transition: opacity 0.2s ease;
}

.edge-group.dimmed { opacity: 0.16; }

.edge-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 18;
}

.edge-path {
  fill: none;
  stroke-width: 2.2;
  stroke-linecap: round;
  transition: stroke-width 0.18s ease, opacity 0.18s ease;
}

.edge-group:hover .edge-path,
.edge-group.selected .edge-path {
  stroke-width: 3.4;
}

.edge-path.dashed {
  stroke-dasharray: 5 5;
  opacity: 0.65;
}

.edge-pill {
  pointer-events: auto;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.2s ease;
}

.edge-pill.dimmed { opacity: 0.18; }

.edge-pill-rect {
  fill: var(--label-bg);
  stroke: var(--map-card-edge);
  stroke-width: 1.1;
  filter: drop-shadow(0 1px 3px rgba(20, 40, 50, 0.08));
}

.edge-pill.selected .edge-pill-rect,
.edge-pill:hover .edge-pill-rect {
  stroke: var(--mint);
  stroke-width: 1.6;
}

.edge-pill-text {
  font-family: var(--mono);
  font-size: 11.5px;
  font-weight: 600;
  fill: var(--text);
  text-anchor: middle;
  dominant-baseline: central;
  font-variant-numeric: tabular-nums;
}

/* Node Cards (Linkscope signature style) */
.nodes-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.node-card {
  position: absolute;
  width: 236px;
  background: var(--map-card);
  border: 1px solid var(--map-card-edge);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 12px 14px 11px;
  pointer-events: auto;
  cursor: pointer;
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease, opacity 0.2s ease;
  user-select: none;
}

.node-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-lg);
}

.node-card.selected {
  border-color: var(--mint);
  box-shadow: 0 0 0 3px var(--mint-soft), var(--shadow-lg);
}

.node-card.dimmed { opacity: 0.24; }

.node-top {
  display: flex;
  align-items: center;
  gap: 10px;
}

.flag-badge {
  width: 30px;
  height: 22px;
  border-radius: 5px;
  overflow: hidden;
  flex: 0 0 auto;
  border: 1px solid rgba(0, 0, 0, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-tint);
}

.flag-badge svg { width: 100%; height: 100%; display: block; }

.node-title-wrap {
  min-width: 0;
  flex: 1;
}

.node-name {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.01em;
}

.node-meta {
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.node-divider {
  height: 1px;
  background: var(--map-card-rule);
  margin: 10px 0 8px;
}

.node-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* 20-bar mini health strip */
.health-bars {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: 12px;
}

.health-bar {
  width: 3.5px;
  height: 10px;
  border-radius: 2px;
  background: var(--bar-empty);
}
.health-bar.ok { background: var(--bar-ok); }
.health-bar.degraded { background: var(--bar-warn); }
.health-bar.down { background: var(--bar-down); }
.health-bar.standby { background: var(--bar-standby); opacity: 0.55; }

.node-stat {
  font-family: var(--mono);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--sub);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.node-stat.down { color: var(--danger); }
.node-stat.standby { color: var(--muted); font-weight: 500; }

/* Tone colors */
.tone-mint { color: var(--mint); stroke: var(--mint); }
.tone-blue { color: var(--blue); stroke: var(--blue); }
.tone-violet { color: var(--violet); stroke: var(--violet); }
.tone-rose { color: var(--rose); stroke: var(--rose); }
.tone-amber { color: var(--amber); stroke: var(--amber); }

/* Detail Drawer */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(16, 28, 36, 0.22);
  backdrop-filter: blur(2px);
  z-index: 80;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }

.detail-drawer {
  position: fixed;
  top: 14px;
  right: 14px;
  bottom: 14px;
  width: min(410px, calc(100vw - 28px));
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  z-index: 90;
  display: flex;
  flex-direction: column;
  transform: translateX(calc(100% + 24px));
  transition: transform 0.24s cubic-bezier(0.2, 0.8, 0.2, 1);
  overflow: hidden;
}

.detail-drawer.open { transform: translateX(0); }

.drawer-head {
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.drawer-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.drawer-sub {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.drawer-body {
  padding: 16px 18px 22px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.kv-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.kv-card {
  background: var(--panel-up);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}

.kv-card .k {
  font-size: 11px;
  color: var(--muted);
}

.kv-card .v {
  margin-top: 4px;
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.chart-box {
  background: var(--panel-up);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
}

.chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.chart-head span {
  font-size: 12.5px;
  font-weight: 600;
}

.range-tabs {
  display: inline-flex;
  gap: 4px;
}

.range-tabs button {
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 3px 8px;
  border-radius: 7px;
  font-size: 11px;
  color: var(--muted);
}

.range-tabs button.active {
  background: var(--mint-soft);
  border-color: rgba(8, 116, 94, 0.35);
  color: var(--mint);
  font-weight: 600;
}

.chart-svg {
  width: 100%;
  height: 150px;
  display: block;
}

.drawer-note {
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--sub);
  background: var(--panel-up);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}

/* Footer note */
.board-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: var(--header);
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
  flex-wrap: wrap;
  gap: 8px;
}

.legend {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.legend i {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 2px;
}

/* Admin styles */
.admin-wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card-box {
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: 16px;
  padding: 18px 20px;
  box-shadow: var(--shadow);
}

.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: min(380px, 100%);
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: 18px;
  padding: 26px 24px;
  box-shadow: var(--shadow-lg);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 12px;
}

.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--sub);
}

.field input, .field select, .field textarea {
  padding: 8px 11px;
  border-radius: 10px;
  border: 1px solid var(--stroke);
  background: var(--panel-up);
  outline: none;
}

.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--mint);
  box-shadow: 0 0 0 3px var(--mint-soft);
}

.btn-primary {
  background: var(--mint);
  color: #fff;
  border: none;
  padding: 9px 16px;
  border-radius: 10px;
  font-weight: 600;
}

.btn-primary:hover { filter: brightness(1.06); }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(198, 56, 72, 0.3);
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 12px;
}

.btn-ghost {
  background: var(--panel-up);
  color: var(--sub);
  border: 1px solid var(--line);
  padding: 6px 12px;
  border-radius: 9px;
  font-size: 12.5px;
}

.table-scroll { overflow-x: auto; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th, .data-table td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.data-table th {
  font-size: 11.5px;
  color: var(--muted);
  font-weight: 600;
}

.code-block {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--panel-up);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.55;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 10px;
}

.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: var(--panel);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: all 0.2s ease;
  z-index: 200;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 780px) {
  .workspace { padding: 10px 10px 20px; }
  .board-head { padding: 12px 14px; }
  .telemetry { width: 100%; justify-content: space-between; gap: 10px; }
  .board-clock { display: none; }
}
