:root {
  color-scheme: light;
  --bg-start: #d6f0ec;
  --bg-mid: #e6e9ff;
  --bg-end: #ffe6d6;
  --ink: #13201f;
  --muted: #4d615f;
  --line: rgba(33, 62, 58, 0.18);
  --glass: rgba(255, 255, 255, 0.52);
  --glass-strong: rgba(255, 255, 255, 0.82);
  --glass-solid: #f8fbf8;
  --glass-edge: rgba(255, 255, 255, 0.65);
  --shadow: 0 20px 48px rgba(24, 42, 40, 0.16);
  --shadow-soft: 0 10px 26px rgba(24, 42, 40, 0.1);
  --blur: blur(26px) saturate(165%);
  --accent: #0b7a75;
  --accent-strong: #075f5b;
  --accent-alt: #4c5bd5;
  --data: #c026d3;
  --event: #8a4a0a;
  --danger: #b42318;
  --danger-bg: #fff0ec;
  --ok: #176c43;
  --ok-bg: #eef8f1;
  --warn: #8f6200;
  --warn-bg: #fff5cf;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: linear-gradient(135deg, var(--bg-start) 0%, var(--bg-mid) 48%, var(--bg-end) 100%);
  color: var(--ink);
}

/* Colourful blurred blobs behind the translucent panels so the backdrop-filter
   blur actually reads as liquid glass instead of flat white over flat white. */
body::before {
  content: "";
  position: fixed;
  inset: -12%;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(40% 36% at 16% 20%, rgba(11, 122, 117, 0.5), transparent 70%),
    radial-gradient(38% 38% at 84% 16%, rgba(76, 91, 213, 0.46), transparent 70%),
    radial-gradient(46% 44% at 78% 84%, rgba(176, 92, 24, 0.34), transparent 72%),
    radial-gradient(42% 40% at 22% 86%, rgba(23, 108, 67, 0.4), transparent 72%);
  filter: blur(8px);
}

button,
input,
select {
  font: inherit;
}

button,
input,
select {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--glass-strong);
  color: var(--ink);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.72);
}

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

button:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(76, 91, 213, 0.35);
  outline-offset: 2px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.glass-panel {
  border: 1px solid var(--glass-edge);
  background: linear-gradient(155deg, rgba(255, 255, 255, 0.58), rgba(255, 255, 255, 0.3));
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.85);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
}

/* Inner panels sit on top of the glass aside; keep them a touch more opaque so
   stacked glass stays legible. */
.side-panel > section {
  background: linear-gradient(155deg, rgba(255, 255, 255, 0.66), rgba(255, 255, 255, 0.42));
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto auto 1fr;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.34), rgba(255, 255, 255, 0)),
    linear-gradient(180deg, rgba(255, 255, 255, 0.42), rgba(255, 255, 255, 0.12));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 88px;
  margin: 14px 16px 0;
  padding: 18px 22px;
  border-radius: 8px;
}

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

h2 {
  margin: 0 0 10px;
  font-size: 14px;
  line-height: 1.2;
  letter-spacing: 0;
  color: var(--muted);
  text-transform: uppercase;
}

p {
  margin: 0;
}

#engine-banner {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.status-cluster {
  display: grid;
  justify-items: end;
  gap: 8px;
  min-width: min(420px, 100%);
}

.verdict {
  min-width: 220px;
  max-width: 420px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font-weight: 700;
  line-height: 1.25;
  overflow-wrap: anywhere;
  box-shadow: var(--shadow-soft);
}

.verdict.ok {
  background: color-mix(in srgb, var(--ok-bg) 88%, white);
  color: var(--ok);
}

.verdict.bad {
  background: color-mix(in srgb, var(--danger-bg) 88%, white);
  color: var(--danger);
}

.verdict.warn {
  background: color-mix(in srgb, var(--warn-bg) 88%, white);
  color: var(--warn);
}

.source-chip {
  width: fit-content;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 10px;
  background: rgba(255, 255, 255, 0.64);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.1;
  overflow-wrap: anywhere;
  text-transform: uppercase;
}

.source-chip.source-raft {
  border-color: color-mix(in srgb, var(--ok) 42%, white);
  background: color-mix(in srgb, var(--ok-bg) 84%, white);
  color: var(--ok);
}

.source-chip.source-sim-model {
  border-color: color-mix(in srgb, var(--accent-alt) 38%, white);
  background: color-mix(in srgb, var(--bg-mid) 76%, white);
  color: var(--accent-alt);
}

.controls {
  display: flex;
  align-items: end;
  gap: 10px;
  min-height: 68px;
  margin: 10px 16px 0;
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
}

.controls label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.controls input[type="text"],
.controls input:not([type]) {
  width: 120px;
}

#seed-input {
  width: 120px;
  padding: 0 10px;
}

#scenario-select {
  width: 240px;
  padding: 0 10px;
}

#mode-select {
  width: 132px;
  padding: 0 10px;
}

.copy-status {
  flex-basis: 100%;
  min-height: 1rem;
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  overflow-wrap: anywhere;
}

.toggle {
  grid-template-columns: auto auto;
  align-items: center;
  min-height: 36px;
  padding: 0 8px;
}

.range input {
  width: 160px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 372px;
  gap: 14px;
  min-height: 0;
  padding: 14px 16px 16px;
}

.graph-panel {
  min-height: 560px;
  padding: 14px;
  border-radius: 8px;
}

#cluster-graph {
  display: block;
  width: 100%;
  height: min(68vh, 680px);
  min-height: 460px;
  touch-action: none;
  cursor: grab;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.76), rgba(242, 249, 247, 0.72)),
    var(--glass-solid);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.graph-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.graph-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 20px;
}

.legend-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
}

.legend-dot.vote {
  background: var(--accent-alt);
}

.legend-dot.heartbeat {
  background: var(--accent);
}

.legend-dot.data {
  background: var(--data);
}

.legend-dot.event {
  background: var(--event);
}

.side-panel {
  display: grid;
  align-content: start;
  gap: 12px;
  max-height: calc(100vh - 206px);
  padding: 12px;
  border-radius: 8px;
  overflow: auto;
}

.side-panel > section {
  padding: 12px;
  border-radius: 8px;
}

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

/* Node rows: name + meta on the first line, the action buttons on their own
   full-width row so "Isolate"/"Disable" no longer overflow the panel. */
#nodes-panel .metric {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  gap: 6px 10px;
}

#nodes-panel .metric > strong {
  grid-column: 1;
}

#nodes-panel .metric > span {
  grid-column: 2;
  text-align: right;
  white-space: nowrap;
}

#nodes-panel .metric > .button-row {
  grid-column: 1 / -1;
  margin-top: 2px;
}

#nodes-panel .metric button {
  min-width: 0;
  padding: 0 8px;
  font-size: 13px;
}

/* Colour the node rows by role, matching the graph circles: a thick left bar
   plus a light role-tinted background so the state reads at a glance. */
.node-row {
  border-left-width: 6px;
  transition:
    border-left-color 260ms ease,
    background-color 260ms ease;
}

.node-row.role-leader {
  border-left-color: var(--accent-strong);
  background: color-mix(in srgb, var(--accent-strong) 16%, white);
}

.node-row.role-follower {
  border-left-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, white);
}

.node-row.role-candidate {
  border-left-color: var(--warn);
  background: color-mix(in srgb, var(--warn) 16%, white);
}

.node-row.role-joining,
.node-row.role-catching_up {
  border-left-color: var(--accent-alt);
  background: color-mix(in srgb, var(--accent-alt) 14%, white);
}

.node-row.role-unknown,
.node-row.role-disconnected {
  border-left-color: #8c9b98;
  background: color-mix(in srgb, #8c9b98 14%, white);
}

.node-row.role-disabled {
  border-left-color: #8c9b98;
  background: color-mix(in srgb, #8c9b98 12%, white);
}

.node-row.role-crashed {
  border-left-color: var(--danger);
  background: color-mix(in srgb, var(--danger) 12%, white);
}

/* Signals list keeps a stable height so new in-flight rows do not shove the
   panels below it up and down on every step. */
#signals-panel {
  height: 208px;
  overflow-y: auto;
}

/* Space the "Add node" button off the node list below it. */
#add-node-button {
  margin-bottom: 10px;
}

/* Separate the subscriber rows from the client rows above them. */
#subscribers-panel {
  margin-top: 8px;
}

/* Client/subscriber rows stack their label and detail so long ids like
   "client-a@profiles" no longer break mid-word against the detail text. */
#clients-panel .metric,
#subscribers-panel .metric {
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}

#clients-panel .metric strong,
#subscribers-panel .metric strong {
  overflow-wrap: normal;
}

#selected-link {
  min-height: 22px;
  margin-bottom: 10px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.hash {
  margin-top: 10px;
  color: var(--muted);
  font-family: ui-monospace, "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  overflow-wrap: anywhere;
}

dl {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  margin: 0;
}

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

dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.metric-list,
.key-list {
  display: grid;
  gap: 8px;
}

.metric,
.key-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  background: var(--glass-strong);
}

.manual-controls {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.manual-controls input {
  width: 100%;
  padding: 0 10px;
}

.metric strong,
.key-row strong {
  overflow-wrap: anywhere;
}

.vertex {
  cursor: grab;
}

.vertex:active {
  cursor: grabbing;
}

.entity.clickable {
  cursor: pointer;
}

.node {
  cursor: grab;
}

.node circle {
  fill: rgba(255, 255, 255, 0.9);
  stroke: var(--accent);
  stroke-width: 3;
  filter: drop-shadow(0 8px 10px rgba(7, 95, 91, 0.14));
  transition:
    fill 260ms ease,
    stroke 260ms ease,
    stroke-width 260ms ease;
}

/* Role-driven node colour so a node visibly changes as it joins, leads, or
   comes back after a crash/restart (engine reports vote_state). */
.node.role-leader circle {
  fill: #d7f1ec;
  stroke: var(--accent-strong);
  stroke-width: 5;
}

.node.role-follower circle {
  fill: rgba(255, 255, 255, 0.92);
  stroke: var(--accent);
}

.node.role-candidate circle {
  fill: var(--warn-bg);
  stroke: var(--warn);
  stroke-width: 4;
}

.node.role-joining circle,
.node.role-catching_up circle {
  fill: #eef0ff;
  stroke: var(--accent-alt);
  stroke-dasharray: 6 5;
}

.node.role-unknown circle,
.node.role-disconnected circle {
  fill: #eef1f3;
  stroke: #93a3a0;
}

.node.disabled circle {
  fill: #ededed;
  stroke: #9aa0a0;
  stroke-dasharray: 2 5;
}

.node.crashed circle {
  fill: var(--danger-bg);
  stroke: var(--danger);
  stroke-dasharray: none;
}

.node.joining {
  animation: node-join 620ms ease-out;
}

@keyframes node-join {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

.node text {
  fill: var(--ink);
  font-size: 14px;
  font-weight: 700;
  text-anchor: middle;
}

.node button {
  pointer-events: none;
}

.link {
  cursor: pointer;
  stroke: #6d7c78;
  stroke-width: 3;
}

.link.partitioned {
  stroke: var(--danger);
  stroke-dasharray: 9 7;
}

.link.delayed {
  stroke: var(--warn);
  stroke-dasharray: 3 6;
}

.link.selected {
  stroke: var(--accent-strong);
  stroke-width: 5;
}

.link-hit {
  cursor: pointer;
  stroke: transparent;
  stroke-width: 18;
}

.packet-layer {
  pointer-events: none;
}

.packet-trail {
  stroke: rgba(76, 91, 213, 0.4);
  stroke-width: 8;
  stroke-linecap: round;
  filter: drop-shadow(0 8px 10px rgba(76, 91, 213, 0.18));
  animation: packet-glow 1.8s ease-in-out infinite;
}

.packet {
  fill: var(--accent-alt);
  stroke: rgba(255, 255, 255, 0.92);
  stroke-width: 2;
  filter: drop-shadow(0 5px 8px rgba(76, 91, 213, 0.3));
  animation: packet-pulse 1.6s ease-in-out infinite;
}

.packet.heartbeat {
  fill: var(--accent);
}

.packet.data,
.packet.upserted {
  fill: var(--data);
}

.packet.event,
.packet.invalidated {
  fill: var(--event);
}

.packet.vote,
.packet.vote-request,
.packet.vote-response {
  fill: var(--accent-alt);
}

@keyframes packet-pulse {
  0%,
  100% {
    opacity: 0.78;
  }

  50% {
    opacity: 1;
  }
}

@keyframes packet-glow {
  0%,
  100% {
    opacity: 0.22;
  }

  50% {
    opacity: 0.54;
  }
}

/* Manual clients / subscribers drawn just outside the cluster ring, linked to the
   node they are routed to. The link "flows" while data is moving. */
.entity-links {
  pointer-events: none;
}

.entity-link {
  stroke: var(--accent-alt);
  stroke-width: 2;
  stroke-dasharray: 5 6;
  opacity: 0.4;
}

.entity-link.subscriber {
  stroke: var(--event);
}

.entity-link.active {
  opacity: 0.92;
  stroke-width: 3;
  animation: entity-flow 0.7s linear infinite;
}

@keyframes entity-flow {
  to {
    stroke-dashoffset: -22;
  }
}

/* Choreographed data-flow pulse fired on a client push (bigger/brighter than the
   ambient signal packets so the sent data reads clearly). */
.pulse {
  stroke: rgba(255, 255, 255, 0.95);
  stroke-width: 2;
}

.pulse.data {
  fill: var(--data);
  filter: drop-shadow(0 0 7px color-mix(in srgb, var(--data) 70%, transparent));
}

.pulse.event {
  fill: var(--event);
  filter: drop-shadow(0 0 7px color-mix(in srgb, var(--event) 70%, transparent));
}

html[data-reduced-motion="true"] .pulse-layer {
  display: none;
}

.entity circle {
  fill: rgba(255, 255, 255, 0.96);
  stroke: var(--accent-alt);
  stroke-width: 2.5;
  filter: drop-shadow(0 4px 6px rgba(76, 91, 213, 0.18));
}

.entity.subscriber circle {
  stroke: var(--event);
}

.entity.active circle {
  stroke-width: 3.5;
}

.entity .entity-id {
  fill: var(--ink);
  font-size: 10px;
  font-weight: 700;
  text-anchor: middle;
}

.entity .entity-sub {
  fill: var(--muted);
  font-size: 9px;
  font-weight: 600;
  text-anchor: middle;
}

.entity.clickable {
  cursor: pointer;
}

.entity.clickable:hover circle {
  fill: color-mix(in srgb, var(--accent-alt) 16%, white);
}

.entity.subscriber.clickable:hover circle {
  fill: color-mix(in srgb, var(--event) 16%, white);
}

html[data-reduced-motion="true"] .entity-link.active {
  animation: none;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto;
    transition-duration: 0.01ms;
    animation-duration: 0.01ms;
    animation-iteration-count: 1;
  }

  .packet,
  .packet-trail {
    animation: none;
  }
}

html[data-reduced-motion="true"] .packet,
html[data-reduced-motion="true"] .packet-trail,
html[data-reduced-motion="true"] .node.joining,
html[data-reduced-motion="true"] .node circle {
  animation: none;
  transition: none;
}

@media (prefers-reduced-transparency: reduce) {
  .glass-panel,
  .metric,
  .key-row,
  button,
  input,
  select {
    background: var(--glass-solid);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
}

html[data-reduced-transparency="true"] .glass-panel,
html[data-reduced-transparency="true"] .metric,
html[data-reduced-transparency="true"] .key-row,
html[data-reduced-transparency="true"] button,
html[data-reduced-transparency="true"] input,
html[data-reduced-transparency="true"] select {
  background: var(--glass-solid);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

@media (max-width: 900px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .verdict {
    max-width: none;
  }

  .status-cluster {
    justify-items: stretch;
    min-width: 0;
  }

  .source-chip {
    justify-self: start;
  }

  .controls {
    align-items: stretch;
    flex-wrap: wrap;
  }

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

  .side-panel {
    max-height: none;
  }

  #cluster-graph {
    height: 520px;
  }
}
