:root {
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  color: #1a1a1a;
  background: #f3f6f8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
}

#root {
  min-height: 100vh;
}

.app-shell {
  display: grid;
  grid-template-rows: auto auto 1fr;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  color: #f4f8ff;
  background: linear-gradient(90deg, #0b2a42 0%, #164863 100%);
}

.topbar__brand {
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.topbar__title {
  font-weight: 500;
}

.topbar__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  justify-content: center;
}

.topbar__actions button {
  padding: 0.35rem 0.6rem;
  border: 1px solid rgba(232, 242, 250, 0.65);
  border-radius: 6px;
  background: rgba(8, 24, 38, 0.24);
  color: #f2f8ff;
  font: inherit;
  cursor: pointer;
}

.topbar__actions button:hover:not(:disabled) {
  background: rgba(8, 24, 38, 0.38);
}

.topbar__actions button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.topbar__meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.1rem;
  font-size: 0.84rem;
  color: #d7e6f6;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #d7dde3;
  background: #ffffff;
}

.toolbar button {
  padding: 0.45rem 0.7rem;
  border-radius: 6px;
  border: 1px solid #164863;
  background: #ffffff;
  color: #164863;
  font: inherit;
  cursor: pointer;
}

.toolbar button:hover {
  background: #eaf2f8;
}

.toolbar__meta {
  margin-left: auto;
  color: #4a5b66;
  font-size: 0.9rem;
}

.workspace-grid {
  display: grid;
  grid-template-columns: 280px 1fr 320px;
  gap: 0.75rem;
  padding: 0.75rem;
  min-height: 0;
}

.panel,
.canvas {
  border: 1px solid #d7dde3;
  border-radius: 10px;
  background: #ffffff;
  min-height: 0;
}

.panel {
  padding: 0.9rem;
  overflow: auto;
}

.panel__title {
  margin: 0 0 0.5rem;
  font-size: 1rem;
}

.panel__body {
  margin: 0;
  color: #52626e;
}

.panel input[type="search"] {
  width: 100%;
  margin-bottom: 0.7rem;
  padding: 0.4rem 0.5rem;
  border: 1px solid #9bb0c0;
  border-radius: 6px;
  font: inherit;
}

.panel h3 {
  margin: 0.7rem 0 0.4rem;
  font-size: 0.9rem;
  color: #264258;
}

.panel ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.25rem;
}

.panel li button {
  width: 100%;
  text-align: left;
  border: 1px solid #d2dee8;
  border-radius: 6px;
  background: #fafcff;
  padding: 0.32rem 0.45rem;
  color: #173247;
  font: inherit;
  cursor: pointer;
}

.panel li button:hover {
  background: #eef6fd;
}

.panel pre {
  margin: 0.35rem 0 0.55rem;
  border: 1px solid #dbe5ee;
  border-radius: 8px;
  background: #f7fbff;
  color: #274054;
  padding: 0.45rem 0.55rem;
  max-height: 8rem;
  overflow: auto;
  font-size: 0.76rem;
}

.json-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}

.json-tools button {
  padding: 0.28rem 0.48rem;
  border: 1px solid #b9c9d6;
  border-radius: 6px;
  background: #f8fbff;
  color: #173247;
  font: inherit;
  cursor: pointer;
}

.json-tools button:hover {
  background: #eaf2f8;
}

.json-editor {
  width: 100%;
  min-height: 220px;
  border: 1px solid #c1d0dd;
  border-radius: 8px;
  padding: 0.5rem;
  background: #fbfdff;
  color: #173247;
  font-family: "IBM Plex Mono", "Fira Code", monospace;
  font-size: 0.78rem;
  line-height: 1.35;
  resize: vertical;
}

.json-status--ok {
  color: #12633c;
}

.json-status--error {
  color: #a31515;
}

.canvas {
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
  background: #f7fbff;
}

.canvas__toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
  border-bottom: 1px solid #dbe5ec;
  background: linear-gradient(180deg, #ffffff 0%, #f3f8fc 100%);
}

.canvas__toolbar button {
  padding: 0.35rem 0.6rem;
  border: 1px solid #8ca1b3;
  border-radius: 6px;
  background: #ffffff;
  color: #173247;
  font: inherit;
  cursor: pointer;
}

.canvas__toolbar button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.canvas__zoom-readout {
  min-width: 6rem;
  text-align: center;
  font-weight: 600;
  color: #21435a;
}

.canvas__placeholder-control {
  border-style: dashed;
}

.canvas__surface {
  position: relative;
  overflow: auto;
  background-color: #f7fbff;
  background-image:
    linear-gradient(to right, #e6edf3 1px, transparent 1px),
    linear-gradient(to bottom, #e6edf3 1px, transparent 1px);
  background-size: 28px 28px;
}

.canvas__surface:focus-visible {
  outline: 2px solid #0a79c2;
  outline-offset: -2px;
}

.canvas__selection-box {
  position: absolute;
  border: 1px solid #0a79c2;
  background: rgba(10, 121, 194, 0.14);
  pointer-events: none;
  z-index: 2;
}

.canvas__viewport {
  position: relative;
  width: 2200px;
  height: 1500px;
  transform-origin: 0 0;
}

.canvas-wires {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: auto;
}

.canvas-wire-segment {
  stroke: #5a6e7f;
  stroke-width: 2.2px;
  stroke-linecap: round;
  opacity: 0.9;
  pointer-events: stroke;
  cursor: pointer;
}

.canvas-wire-segment.is-highlight {
  stroke: #0b78bf;
  stroke-width: 3px;
  opacity: 1;
}

.canvas-wire-segment.is-dimmed {
  opacity: 0.2;
}

.canvas-wire-label {
  position: absolute;
  transform: translate(-50%, calc(-100% - 6px));
  padding: 0.1rem 0.3rem;
  border: 1px solid rgba(144, 158, 171, 0.8);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.95);
  color: #243f53;
  font-size: 0.66rem;
  line-height: 1.1;
  letter-spacing: 0.02em;
  white-space: nowrap;
  pointer-events: auto;
  cursor: pointer;
}

button.canvas-wire-label {
  font: inherit;
}

.canvas-wire-label.is-highlight {
  border-color: #0b78bf;
  color: #0d4f7b;
  font-weight: 600;
}

.canvas-wire-label.is-dimmed {
  opacity: 0.35;
}

.canvas-node {
  position: absolute;
  user-select: none;
  touch-action: none;
}

.canvas-node__chrome {
  width: 100%;
  min-height: inherit;
  border: 1px solid #406078;
  border-radius: 12px;
  background: linear-gradient(180deg, #ffffff 0%, #f6fbff 100%);
  box-shadow: 0 3px 10px rgba(38, 64, 89, 0.18);
}

.canvas-node__content {
  width: 100%;
  height: 100%;
  padding: 0.45rem 0.55rem 0.5rem;
  transform-origin: 50% 50%;
}

.canvas-node__ref {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #113148;
  text-transform: uppercase;
}

.canvas-node__value {
  margin-top: 0.15rem;
  margin-bottom: 0.35rem;
  font-size: 0.74rem;
  color: #405260;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.canvas-node__pins {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}

.canvas-node__pin-col {
  display: flex;
  flex-direction: column;
  gap: 0.14rem;
  min-width: 0;
  flex: 1;
}

.canvas-node__pin-col--right {
  text-align: right;
}

.canvas-node__pin {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: baseline;
  gap: 0.3rem;
  min-width: 0;
}

.canvas-node__pin-col--right .canvas-node__pin {
  grid-template-columns: 1fr auto;
}

.canvas-node__pin-number {
  font-size: 0.66rem;
  color: #6c8090;
  white-space: nowrap;
}

.canvas-node__pin-name {
  font-size: 0.68rem;
  color: #2d475a;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.canvas-node__lock {
  margin-top: 0.35rem;
  font-size: 0.64rem;
  color: #925d00;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.canvas-node.is-selected .canvas-node__chrome {
  border-color: #0a79c2;
  box-shadow: 0 0 0 2px rgba(10, 121, 194, 0.25), 0 4px 14px rgba(18, 53, 78, 0.25);
}

.canvas-node.is-dragging .canvas-node__chrome {
  cursor: grabbing;
  box-shadow: 0 0 0 2px rgba(10, 121, 194, 0.3), 0 8px 18px rgba(12, 42, 66, 0.26);
}

@media (max-width: 1100px) {
  .topbar {
    align-items: flex-start;
  }

  .topbar__meta {
    align-items: flex-start;
  }

  .workspace-grid {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(260px, 1fr) auto;
  }

  .toolbar__meta {
    width: 100%;
    margin-left: 0;
  }
}
