:root {
  --bg-0: #f5f7fb;
  --bg-1: #ebf1f8;
  --bg-2: #dce8f4;
  --panel: #fbfdff;
  --panel-strong: #ffffff;
  --canvas: #f4f8fd;
  --ink: #0f1728;
  --ink-muted: #4a607c;
  --ink-subtle: #7388a3;
  --line: #c8d5e4;
  --line-strong: #9db1c9;
  --accent: #1565d8;
  --accent-strong: #0f4dab;
  --accent-soft: #e6f0ff;
  --ok: #0f7a49;
  --warn: #9b6200;
  --err: #ac2f24;
  --power: #d6691f;
  --ground: #60748d;
  --clock: #d35c2f;
  --signal: #2f72e7;
  --analog: #0d978e;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-1: 0 1px 2px rgba(16, 24, 40, 0.08);
  --shadow-2: 0 10px 24px rgba(16, 24, 40, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "IBM Plex Sans", "Manrope", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 0% 0%, #fff4de 0 20%, transparent 30%),
    radial-gradient(circle at 96% 5%, #dbf2ff 0 18%, transparent 28%),
    linear-gradient(180deg, var(--bg-1), var(--bg-0));
}

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

button,
input,
select,
textarea,
.list li,
details > summary {
  transition: background-color 120ms ease, border-color 120ms ease, box-shadow 120ms ease, color 120ms ease;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.list li:focus-visible,
details > summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-strong);
  color: var(--ink);
  padding: 6px 11px;
  cursor: pointer;
  box-shadow: var(--shadow-1);
}

button:hover {
  border-color: var(--line-strong);
  background: #f3f8ff;
}

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

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

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

button.chip {
  padding: 4px 9px;
  font-size: 0.76rem;
}

button.activeChip {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-strong);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #f9fcff, #f2f8ff);
  backdrop-filter: blur(2px);
  position: sticky;
  top: 0;
  z-index: 40;
}

.brand h1 {
  margin: 0;
  font-size: 1.6rem;
  letter-spacing: 0.08em;
  line-height: 1;
}

.brand p {
  margin: 2px 0 0;
  font-size: 0.84rem;
  color: var(--ink-muted);
  font-weight: 600;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 7px;
}

.inlineSelect,
.inlineCheck,
.inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.inlineSelect select {
  min-width: 138px;
}

.workspace {
  height: calc(100vh - 77px);
  display: grid;
  gap: 10px;
  grid-template-columns: 270px minmax(520px, 1fr) 392px;
  padding: 10px;
}

.pane {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, var(--panel), #f6faff);
  box-shadow: var(--shadow-1);
}

.pane.left,
.pane.right {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px;
  overflow: auto;
}

.pane.center {
  overflow: hidden;
  background: linear-gradient(180deg, #fcfeff, #f6faff);
}

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

.sectionHead h2 {
  margin: 0;
  font-size: 0.92rem;
  color: var(--ink);
}

h2 {
  margin: 0;
  font-size: 0.94rem;
}

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

input::placeholder,
textarea::placeholder {
  color: var(--ink-subtle);
}

textarea {
  min-height: 250px;
  font-family: "JetBrains Mono", "IBM Plex Mono", monospace;
  font-size: 12px;
  line-height: 1.42;
}

.list {
  margin: 8px 0 0;
  list-style: none;
  padding: 0;
  max-height: 250px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.72);
}

.list li {
  padding: 8px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  color: var(--ink);
}

.list li:hover {
  background: #f2f7ff;
}

.list li:last-child {
  border-bottom: none;
}

.list li.active {
  background: var(--accent-soft);
  color: #0b3a84;
  font-weight: 600;
}

.list li.listSpacer {
  padding: 0;
  border: none;
  cursor: default;
  background: transparent;
}

.quickCreate {
  margin-top: 8px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

.quickCreate button {
  justify-self: start;
}

.legendSection {
  margin-top: 2px;
}

.netLegend {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fbfdff;
  padding: 8px;
  display: grid;
  gap: 6px;
}

.legendRow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--ink-muted);
}

.legendSwatch {
  display: inline-block;
  width: 20px;
  height: 0;
  border-top: 3px solid var(--line-strong);
}

.legendPower {
  border-top-color: var(--power);
}

.legendGround {
  border-top-color: var(--ground);
}

.legendClock {
  border-top-color: var(--clock);
}

.legendSignal {
  border-top-color: var(--signal);
}

.legendAnalog {
  border-top-color: var(--analog);
}

.card {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fbfdff;
  padding: 8px;
  color: var(--ink-muted);
  font-size: 0.85rem;
  white-space: pre-wrap;
}

.editorCard {
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px;
  background: #f8fbff;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.editorSection {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  margin-top: 8px;
  background: #ffffffcc;
  overflow: hidden;
}

.editorSection > summary {
  cursor: pointer;
  list-style: none;
  padding: 8px 10px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink);
}

.editorSection > summary:hover {
  background: #f3f8ff;
}

.editorSection[open] > summary {
  border-bottom: 1px solid var(--line);
  background: #eef4ff;
}

.editorSection > summary::-webkit-details-marker {
  display: none;
}

.editorGrid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.editorActions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.hintText {
  font-size: 0.8rem;
  color: var(--ink-muted);
}

.miniList {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  max-height: 180px;
  overflow: auto;
}

.miniRow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
  font-size: 0.8rem;
}

.miniRow:last-child {
  border-bottom: none;
}

.symbolPinRow {
  display: grid;
  align-items: center;
  grid-template-columns: 1fr 0.9fr 0.9fr 0.8fr 1fr auto auto auto;
}

.pinCol {
  min-width: 0;
  padding: 5px 6px;
  font-size: 0.76rem;
}

.symbolPinRow.invalidRow {
  background: #fff3f1;
}

.symbolValidationError {
  color: var(--err);
  font-size: 0.76rem;
}

.migrationPreview {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px;
  margin: 6px 0;
  line-height: 1.35;
  background: #f5f9ff;
}

.canvasTools {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #f8fbff, #f2f7ff);
}

#compileStatus {
  margin-left: auto;
  color: var(--ink-muted);
  font-size: 0.84rem;
  font-weight: 600;
}

.status-ok {
  color: var(--ok);
}

.canvasViewport {
  height: calc(100% - 52px);
  position: relative;
  overflow: hidden;
  cursor: grab;
  background:
    linear-gradient(0deg, #d9e4f0 1px, transparent 1px),
    linear-gradient(90deg, #d9e4f0 1px, transparent 1px),
    linear-gradient(180deg, var(--canvas), #edf4fc);
  background-size: 20px 20px, 20px 20px, auto;
}

.canvasViewport.dragging {
  cursor: grabbing;
}

.canvasInner {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
}

.canvasInner svg {
  display: block;
}

.selectionBox {
  position: absolute;
  z-index: 15;
  pointer-events: none;
  border: 1px solid var(--accent);
  background: rgba(21, 101, 216, 0.12);
}

.pinTooltip {
  position: absolute;
  z-index: 20;
  pointer-events: none;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.95);
  box-shadow: var(--shadow-2);
  font-size: 0.74rem;
}

.hidden {
  display: none;
}

.jsonActions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.jsonActions button {
  font-size: 0.77rem;
  padding: 4px 8px;
}

.jsonFeedback {
  min-height: 18px;
  margin-bottom: 6px;
  color: var(--ink-muted);
  font-size: 0.78rem;
}

.issueRow {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px;
  margin-bottom: 6px;
  cursor: pointer;
  background: #fff;
}

.issueRow:hover {
  background: #f4f8ff;
}

.issueErr {
  border-color: #f3bab5;
  background: #fff5f4;
}

.issueWarn {
  border-color: #f0d28b;
  background: #fffaf0;
}

.issueTitle {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink);
}

.issueMeta {
  font-size: 0.72rem;
  color: var(--ink-muted);
}

.issueActions {
  margin-top: 6px;
}

.issueActions button {
  font-size: 0.74rem;
  padding: 3px 8px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(14, 22, 36, 0.54);
}

.modal.hidden {
  display: none;
}

.modalCard {
  width: min(1120px, 100%);
  height: min(88vh, 900px);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: #fff;
  box-shadow: 0 24px 60px rgba(16, 24, 40, 0.24);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.compactModal {
  width: min(760px, 100%);
  height: auto;
  max-height: min(86vh, 760px);
}

.modalHead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.modalHead h3 {
  margin: 0;
  font-size: 0.96rem;
}

.modalHint {
  margin: 0;
  color: var(--ink-muted);
  font-size: 0.8rem;
}

#schemaViewer {
  height: 100%;
  min-height: 0;
}

.shortcutGrid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  overflow: auto;
  padding-right: 4px;
}

.shortcutGrid > div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 0.86rem;
  color: var(--ink-muted);
  background: #f8fbff;
}

kbd {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 6px;
  background: #fff;
  padding: 2px 6px;
  color: var(--ink);
  font-size: 0.74rem;
  font-family: "JetBrains Mono", monospace;
}

.commandList {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: auto;
  max-height: 46vh;
  background: #fff;
}

.commandRow {
  width: 100%;
  border: none;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: #fff;
  text-align: left;
  box-shadow: none;
  padding: 8px 10px;
  color: var(--ink);
  font-size: 0.84rem;
}

.commandRow:last-child {
  border-bottom: none;
}

.commandRow:hover,
.commandRow.active {
  background: #edf4ff;
}

.flash {
  animation: flashPulse 0.7s ease-in-out 0s 2;
}

@keyframes flashPulse {
  0% {
    opacity: 0.2;
  }
  100% {
    opacity: 1;
  }
}

@media (max-width: 1460px) {
  .workspace {
    grid-template-columns: 248px minmax(420px, 1fr) 360px;
  }
}

@media (max-width: 1300px) {
  .workspace {
    height: auto;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
  }

  .pane.center {
    min-height: 600px;
  }
}

@media (max-width: 820px) {
  .topbar {
    position: static;
  }

  .brand h1 {
    font-size: 1.3rem;
  }

  .actions {
    justify-content: flex-start;
  }

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