* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: #f6f7f4;
  color: #171a16;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 26px 30px 20px;
  border-bottom: 1px solid #dfe4dc;
}

h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.1;
  font-weight: 720;
}

p {
  margin: 6px 0 0;
  color: #697064;
  font-size: 13px;
}

.identity {
  display: grid;
  gap: 6px;
  min-width: 240px;
}

.identity label,
.section-title,
.field span {
  color: #697064;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.identity input,
.field input {
  width: 100%;
  height: 36px;
  border: 1px solid #cbd3c8;
  border-radius: 8px;
  padding: 0 11px;
  background: #fff;
  color: #171a16;
  outline: none;
}

.identity input:focus,
.field input:focus {
  border-color: #176e5c;
  box-shadow: 0 0 0 3px rgba(23, 110, 92, .14);
}

.workspace {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  min-height: 0;
}

.sidebar {
  padding: 20px 18px;
  border-right: 1px solid #dfe4dc;
  min-width: 0;
  overflow: auto;
}

.peer-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.connection-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  margin-top: 12px;
  padding: 8px 10px;
  border: 1px solid #d7ddd4;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}

.connection-toggle:hover {
  border-color: #9eb0a5;
}

.connection-toggle:focus-within {
  border-color: #176e5c;
  box-shadow: 0 0 0 3px rgba(23, 110, 92, .12);
}

.connection-toggle input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: #176e5c;
}

.connection-toggle span {
  display: grid;
  gap: 2px;
}

.connection-toggle strong {
  font-size: 13px;
}

.connection-toggle small {
  color: #697064;
  font-size: 11px;
}

.peer {
  width: 100%;
  min-height: 96px;
  padding: 12px;
  border: 1px solid #d7ddd4;
  border-radius: 8px;
  background: #fff;
  color: inherit;
  text-align: left;
  cursor: default;
}

.peer:hover {
  border-color: #9eb0a5;
}

.peer.selectable {
  cursor: pointer;
}

.peer.selected {
  border-color: #176e5c;
  box-shadow: 0 0 0 3px rgba(23, 110, 92, .12);
}

.peer-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  min-width: 0;
}

.peer-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 700;
}

.badge {
  flex: 0 0 auto;
  max-width: 48%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border-radius: 999px;
  padding: 3px 7px;
  color: #4c564c;
  background: #eef1eb;
  font-size: 11px;
  font-weight: 650;
}

.badge.connected {
  color: #0f5f50;
  background: #dcefe9;
}

.badge.warning {
  color: #744e00;
  background: #fff0c7;
}

.peer-meta {
  margin-top: 8px;
  color: #697064;
  font-size: 12px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.peer-path {
  margin-top: 5px;
  overflow: visible;
  color: #31584f;
  font-size: 12px;
  font-weight: 650;
  line-height: 1.35;
  overflow-wrap: anywhere;
  white-space: normal;
}

.pairing-code {
  margin-top: 12px;
  color: #124f43;
  font-size: 28px;
  font-weight: 760;
  letter-spacing: .12em;
  text-align: center;
}

.pairing-code.hidden {
  display: none;
}

.peer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 11px;
}

.peer-actions:empty {
  display: none;
}

.small-button.primary {
  border-color: #176e5c;
  background: #176e5c;
  color: #fff;
}

.small-button.primary:hover {
  border-color: #0f5b4c;
  background: #0f5b4c;
}

.small-button.quiet {
  border-color: transparent;
  background: transparent;
  color: #697064;
}

.empty {
  color: #697064;
  line-height: 1.45;
  font-size: 13px;
}

.empty.paused {
  padding: 12px;
  border-radius: 8px;
  background: #eef1eb;
  color: #4c564c;
}

.settings-panel {
  display: grid;
  gap: 10px;
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px solid #dfe4dc;
}

.permission-panel {
  display: grid;
  gap: 10px;
  margin-top: 14px;
  padding: 12px;
  border: 1px solid #d8b669;
  border-radius: 8px;
  background: #fff8e5;
  color: #5a4310;
  font-size: 12px;
  font-weight: 700;
}

.permission-panel.hidden {
  display: none;
}

.field {
  display: grid;
  gap: 6px;
}

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

.small-button {
  width: fit-content;
  min-width: 72px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid #cbd3c8;
  border-radius: 8px;
  background: #fff;
  color: #171a16;
  cursor: pointer;
}

.small-button:hover {
  border-color: #9eb0a5;
}

.small-button:disabled {
  color: #9aa29a;
  background: #f1f3ef;
  cursor: default;
}

.layout {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 14px;
  min-height: 430px;
  padding: 24px 28px 28px;
}

.map-toolbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 18px;
  min-height: 24px;
}

#setupTitle {
  font-size: 16px;
  font-weight: 760;
}

#setupMeta {
  color: #697064;
  font-size: 12px;
  text-align: right;
}

.display-tile {
  position: absolute;
  z-index: 2;
  display: grid;
  place-content: center;
  gap: 5px;
  min-width: 48px;
  min-height: 34px;
  padding: 8px;
  border: 1px solid #8d998f;
  border-radius: 6px;
  background: #f5f7f3;
  color: #171a16;
  text-align: center;
  box-sizing: border-box;
}

.display-map {
  position: relative;
  min-height: 440px;
  border: 1px solid #cbd3c8;
  border-radius: 8px;
  background: #fcfdfb;
  overflow: hidden;
}

.display-machine-group {
  position: absolute;
  z-index: 1;
  border: 2px solid rgba(23, 110, 92, .45);
  border-radius: 10px;
  background: rgba(23, 110, 92, .035);
  pointer-events: none;
}

.display-machine-group.local {
  border-color: rgba(23, 26, 22, .38);
  background: rgba(255, 255, 255, .35);
}

.display-machine-group.dragging {
  z-index: 9;
  border-color: #176e5c;
  box-shadow: 0 12px 30px rgba(23, 51, 42, .16);
}

.display-machine-group.drop-target {
  border-color: #176e5c;
  box-shadow: 0 0 0 4px rgba(23, 110, 92, .14);
}

.machine-label {
  position: absolute;
  top: -27px;
  left: 0;
  max-width: 100%;
  overflow: hidden;
  border-radius: 999px;
  padding: 4px 9px;
  background: #e5f0ec;
  color: #125e50;
  font-size: 11px;
  font-weight: 760;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.display-machine-group.local .machine-label {
  background: #e9ece7;
  color: #30362f;
}

.display-tile.local {
  border-color: #171a16;
  background: #ffffff;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.display-map.ready .display-tile.local {
  border-color: #176e5c;
}

.display-tile.remote {
  border-style: dashed;
  border-color: #176e5c;
  background: rgba(23, 110, 92, .08);
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.display-tile.remote.unplaced {
  border-color: #8d998f;
  background: #f1f3ef;
}

.display-tile.dragging {
  z-index: 10;
  border-style: solid;
  border-color: #176e5c;
  box-shadow: 0 10px 28px rgba(23, 51, 42, .2);
  cursor: grabbing;
}

.display-map.dragging {
  cursor: grabbing;
  user-select: none;
}

.display-tile.local.drop-target {
  border-color: #176e5c;
  box-shadow: 0 0 0 4px rgba(23, 110, 92, .14);
}

.display-tile.drop-target::after {
  position: absolute;
  z-index: 5;
  content: "";
  border-radius: 3px;
  background: #176e5c;
  box-shadow: 0 0 0 3px rgba(23, 110, 92, .16);
  pointer-events: none;
}

.display-tile.drop-target[data-drop-edge="left"]::after,
.display-tile.drop-target[data-drop-edge="right"]::after {
  top: 8px;
  bottom: 8px;
  width: 4px;
}

.display-tile.drop-target[data-drop-edge="top"]::after,
.display-tile.drop-target[data-drop-edge="bottom"]::after {
  right: 8px;
  left: 8px;
  height: 4px;
}

.display-tile.drop-target[data-drop-edge="left"]::after {
  left: -2px;
}

.display-tile.drop-target[data-drop-edge="right"]::after {
  right: -2px;
}

.display-tile.drop-target[data-drop-edge="top"]::after {
  top: -2px;
}

.display-tile.drop-target[data-drop-edge="bottom"]::after {
  bottom: -2px;
}

.display-tile.selected {
  outline: 2px solid #176e5c;
  outline-offset: 2px;
}

.display-name {
  font-size: 12px;
  font-weight: 760;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.display-meta {
  color: #697064;
  font-size: 10px;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.edge-handle {
  position: absolute;
  z-index: 4;
  border: 0;
  border-radius: 4px;
  background: #176e5c;
  opacity: .28;
  cursor: pointer;
  transition: opacity .14s ease, transform .14s ease;
}

.edge-handle:hover,
.edge-handle:focus,
.edge-handle.drop-target {
  opacity: .92;
  outline: none;
}

.edge-handle.drop-target {
  transform: scale(1.18);
}

.edge-handle.left,
.edge-handle.right {
  top: 10px;
  bottom: 10px;
  width: 11px;
}

.edge-handle.top,
.edge-handle.bottom {
  left: 10px;
  right: 10px;
  height: 11px;
}

.edge-handle.left {
  left: -6px;
  cursor: w-resize;
}

.edge-handle.right {
  right: -6px;
  cursor: e-resize;
}

.edge-handle.top {
  top: -6px;
  cursor: n-resize;
}

.edge-handle.bottom {
  bottom: -6px;
  cursor: s-resize;
}

.footer {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 18px;
  padding: 14px 30px 18px;
  border-top: 1px solid #dfe4dc;
  color: #697064;
  font-size: 12px;
}

@media (max-width: 800px) {
  .topbar,
  .footer {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid #dfe4dc;
  }

  .layout {
    min-height: 460px;
    padding: 20px;
  }

  .map-toolbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  #setupMeta {
    text-align: left;
  }
}
