:root {
  --bg: #0b0f17;
  --bg-alt: #10161f;
  --panel: #131a25;
  --border: #223047;
  --text: #dbe4f0;
  --text-dim: #7c8aa3;
  --accent: #4fd1c5;
  --accent-glow: rgba(79, 209, 197, 0.35);
  --tcp: #4f8dfd;
  --udp: #4fd17d;
  --icmp: #f5a623;
  --http: #c084fc;
  --danger: #ff5d6c;
  --node-fill: #16202f;
  --node-stroke: #2c3d57;
  --link: #24344c;
  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);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: linear-gradient(180deg, var(--bg-alt), var(--bg));
  border-bottom: 1px solid var(--border);
}

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

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent-glow);
  animation: pulse 1.8s ease-in-out infinite;
}

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

.brand h1 {
  font-size: 17px;
  font-weight: 600;
  margin: 0;
  letter-spacing: 0.2px;
}

.stats {
  display: flex;
  gap: 22px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat span:last-child {
  font-size: 16px;
  font-weight: 600;
}

.layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 16px;
  padding: 16px;
  height: calc(100vh - 62px);
}

.network-pane {
  position: relative;
  background: radial-gradient(circle at 30% 20%, #101a28 0%, var(--bg) 70%);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  min-height: 300px;
}

.legend-overlay {
  position: absolute;
  left: 14px;
  bottom: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  max-width: min(560px, calc(100% - 28px));
  padding: 10px 14px;
  background: rgba(11, 15, 23, 0.82);
  border: 1px solid var(--border);
  border-radius: 10px;
  backdrop-filter: blur(4px);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--node-fill);
  border: 2px solid currentColor;
  flex-shrink: 0;
}

#networkSvg {
  width: 100%;
  height: 100%;
  display: block;
}

.control-pane {
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  padding-right: 2px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-dim);
}

.row {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.btn {
  flex: 1;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #182333;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s, transform 0.1s;
}

.btn:hover { background: #1e2c40; }
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--accent);
  color: #05201d;
  border-color: var(--accent);
}
.btn-primary:hover { background: #63e0d4; }

.btn-ghost {
  width: 100%;
  background: transparent;
}

.btn-toggle {
  width: 100%;
  background: rgba(79, 209, 197, 0.12);
  border-color: rgba(79, 209, 197, 0.4);
  color: var(--accent);
}

.btn-toggle[aria-pressed="false"] {
  background: transparent;
  border-color: var(--border);
  color: var(--text-dim);
}

.btn-toggle[aria-pressed="false"]::before {
  content: "○ ";
}

.btn-toggle[aria-pressed="true"]::before {
  content: "● ";
}

.field.disabled {
  opacity: 0.45;
  pointer-events: none;
}

.field {
  display: block;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--text-dim);
}

.field span { display: block; margin-bottom: 6px; }
.field b { color: var(--text); }

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.select {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #182333;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}

.select:focus {
  outline: 1px solid var(--accent);
}

.checks {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  color: var(--text);
  font-size: 13px;
}

.checks label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.swatch {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  display: inline-block;
}
.swatch.tcp { background: var(--tcp); }
.swatch.udp { background: var(--udp); }
.swatch.icmp { background: var(--icmp); }
.swatch.http { background: var(--http); }

.log-panel {
  flex: none;
  display: flex;
  flex-direction: column;
}

.event-log {
  max-height: 260px;
  overflow-y: auto;
  font-family: 'Cascadia Code', Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--text-dim);
}

.event-log .entry {
  padding: 3px 0;
  border-bottom: 1px solid rgba(255,255,255,0.03);
  animation: fadein 0.25s ease;
}

@keyframes fadein {
  from { opacity: 0; transform: translateY(-2px); }
  to { opacity: 1; transform: translateY(0); }
}

.entry .t { color: #4a5a76; margin-right: 6px; }
.entry.ok .p { color: var(--text); }
.entry.drop { color: var(--danger); }
.entry.drop .p { color: var(--danger); }

/* SVG elements */
.node-label {
  fill: var(--text);
  font-size: 12px;
  font-weight: 600;
  text-anchor: middle;
  font-family: 'Segoe UI', sans-serif;
}

.node-sub {
  fill: var(--text-dim);
  font-size: 9.5px;
  text-anchor: middle;
}

.link-line {
  stroke: var(--link);
  stroke-width: 2;
  fill: none;
}

.node-circle {
  fill: var(--node-fill);
  stroke: var(--node-stroke);
  stroke-width: 1.5;
}

.node-icon {
  pointer-events: none;
}
.node-icon path,
.node-icon rect,
.node-icon line,
.node-icon circle,
.node-icon ellipse {
  fill: none;
  stroke: var(--text);
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.node-icon .icon-fill {
  fill: var(--text);
  stroke: none;
}

.node-ring {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.5;
  opacity: 0;
}

.node-ring.active {
  animation: ripple 0.6s ease-out;
}

@keyframes ripple {
  from { r: 26; opacity: 0.8; stroke-width: 3; }
  to { r: 42; opacity: 0; stroke-width: 0.5; }
}

.packet {
  filter: drop-shadow(0 0 4px currentColor);
}

.packet.drop-flash {
  fill: var(--danger) !important;
  filter: drop-shadow(0 0 8px var(--danger));
}

/* ---------- Account / topology / history panels ---------- */

.text-input {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #101823;
  color: var(--text);
  font-size: 13px;
}

.text-input:focus {
  outline: 1px solid var(--accent);
}

.json-input {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0c1219;
  color: var(--text);
  font-family: 'Cascadia Code', Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.5;
  resize: vertical;
}

.json-input:focus {
  outline: 1px solid var(--accent);
}

.full-width {
  width: 100%;
  margin-bottom: 10px;
}

.account-line {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--text-dim);
}

.status-text {
  min-height: 16px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-dim);
}

.status-text:not(:empty) {
  color: var(--accent);
}

.list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
  max-height: 220px;
  overflow-y: auto;
}

.empty-hint {
  font-size: 12px;
  color: var(--text-dim);
  font-style: italic;
  padding: 4px 0;
}

.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  background: #101823;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12.5px;
}

.list-row .btn-sm {
  flex-shrink: 0;
}

.history-row {
  align-items: flex-start;
}

.history-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.history-info span {
  color: var(--text-dim);
  font-size: 11px;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 11.5px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #182333;
  color: var(--text);
  cursor: pointer;
}

.btn-sm:hover {
  background: #1e2c40;
}

.topology-editor {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 4px;
}

.topology-editor summary {
  cursor: pointer;
  font-size: 12.5px;
  color: var(--text-dim);
}

.topology-editor[open] summary {
  margin-bottom: 10px;
  color: var(--text);
}

.panel.requires-auth.disabled {
  opacity: 0.55;
  pointer-events: none;
}

/* ---------- Rotate-device prompt (mobile portrait only) ---------- */

.rotate-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(11, 15, 23, 0.97);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  text-align: center;
  padding: 24px;
}

@media (max-width: 700px) and (orientation: portrait) {
  .rotate-overlay:not(.dismissed) {
    display: flex;
  }
}

.rotate-overlay .phone-icon {
  width: 64px;
  height: 64px;
  color: var(--accent);
}

.rotate-overlay .phone-shape {
  animation: rotate-phone 1.8s ease-in-out infinite;
  transform-origin: 24px 24px;
}

@keyframes rotate-phone {
  0%, 15% { transform: rotate(0deg); }
  50%, 65% { transform: rotate(90deg); }
  100% { transform: rotate(0deg); }
}

.rotate-overlay .rotate-arrow {
  opacity: 0.7;
}

.rotate-overlay p {
  max-width: 260px;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  margin: 0;
}
