:root {
  --bg: #eef3fa;
  --panel: #ffffff;
  --panel-alt: #f6f9ff;
  --ink: #21364f;
  --muted: #6a7b92;
  --line: #d8e2f2;
  --accent: #1f5f9e;
  --accent-2: #2e78be;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
}

th,
td {
  border: 1px solid #dbe2ec;
  padding: 8px;
  text-align: left;
  font-size: 14px;
}

.table-photo-preview {
  width: 74px;
  height: 56px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid #ccd9ea;
  display: block;
}

.geo-map-panel {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(240px, 0.85fr);
  gap: 14px;
  margin-bottom: 18px;
}

.geo-map-module {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(280px, 0.8fr);
  gap: 16px;
  margin-top: 14px;
}

.geo-map {
  min-height: 360px;
  border: 1px solid #c6d5e9;
  border-radius: 10px;
  overflow: hidden;
  background: #eef4fb;
}

.geo-map-list {
  display: grid;
  gap: 10px;
  align-content: start;
}

.geo-map-card {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border: 1px solid #d2deed;
  border-radius: 10px;
  background: linear-gradient(180deg, #fbfdff 0%, #f1f6fd 100%);
}

.geo-map-module-canvas {
  min-height: 620px;
}

.geo-map-sidebar {
  display: grid;
  align-content: start;
}

.geo-popup-card {
  display: grid;
  gap: 6px;
  min-width: 220px;
}

.geo-popup-card h3 {
  margin: 0;
  font-size: 18px;
  color: #224264;
}

.geo-popup-card p {
  margin: 0;
  color: #35506d;
  font-size: 13px;
}

.geo-popup-kicker {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #6f88a4;
}

.content-panel {
  margin-top: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
}

.table-wrap {
  margin-top: 10px;
  overflow-x: auto;
}

.status-form {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0 12px;
}

.status-form select {
  border: 1px solid #c5d3e8;
  border-radius: 6px;
  padding: 7px 8px;
  background: #fff;
  min-width: 200px;
}

.status-pill {
  display: inline-flex;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: #e7f1ff;
  color: #255685;
  border: 1px solid #bad3f0;
}

.section-title {
  margin: 10px 0 0;
  font-size: 22px;
}

.meta-sep {
  margin: 0 8px;
  color: var(--muted);
}

/* Network editor */
.editor-body {
  min-height: 100vh;
  background: radial-gradient(circle at 20% 0%, #f7fbff 0%, #ebf2fb 42%, #e2ebf8 100%);
}

.editor-app {
  max-width: 1500px;
  margin: 16px auto;
  padding: 10px 12px 16px;
}

.editor-topbar {
  background: linear-gradient(90deg, #0c2f57 0%, #0f4cbf 52%, #1855c6 100%);
  color: #f2f8ff;
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  box-shadow: 0 14px 28px rgba(21, 53, 89, 0.18);
}

.editor-title-wrap {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
}

.brand-logo-image {
  width: 98px;
  height: 98px;
  object-fit: contain;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 8px 16px rgba(10, 20, 36, 0.32);
  padding: 4px;
}

.editor-kicker {
  margin: 0;
  opacity: 0.85;
  font-size: 12px;
}

.editor-title-wrap h1 {
  margin: 1px 0 0;
  font-size: 28px;
  font-weight: 700;
}

.editor-actions {
  display: flex;
  gap: 10px;
}

.primary-btn,
.ghost-btn {
  border: 1px solid rgba(255, 255, 255, 0.34);
  border-radius: 8px;
  padding: 10px 14px;
  text-decoration: none;
  cursor: pointer;
  font-weight: 600;
  transition: transform 0.15s ease, filter 0.15s ease;
}

.primary-btn {
  background: linear-gradient(180deg, #4b97d4 0%, #2472af 100%);
  color: #fff;
}

.ghost-btn {
  background: rgba(255, 255, 255, 0.1);
  color: #f6fbff;
}

.primary-btn:hover,
.ghost-btn:hover {
  filter: brightness(1.06);
  transform: translateY(-1px);
}

.editor-tabs {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  overflow: hidden;
  display: flex;
  background: var(--panel);
}

.tab {
  flex: 0 0 auto;
  border: 0;
  border-right: 1px solid var(--line);
  background: #fff;
  color: #3c4e67;
  font-size: 15px;
  font-weight: 600;
  padding: 10px 18px;
  cursor: default;
}

.tab-active {
  background: linear-gradient(180deg, #eef6ff 0%, #e2efff 100%);
}

.editor-layout {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 270px 1fr 320px;
  gap: 12px;
  min-height: 76vh;
}

.left-panel,
.right-panel,
.center-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.left-panel h2,
.right-panel h2 {
  margin: 0;
  padding: 14px;
  font-size: 28px;
  background: linear-gradient(180deg, #f7faff 0%, #edf4ff 100%);
  border-bottom: 1px solid var(--line);
}

.device-list {
  list-style: none;
  margin: 0;
  padding: 10px;
  display: grid;
  gap: 8px;
}

.device-list-item {
  display: grid;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px 11px;
  cursor: pointer;
}

.device-list-main {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 9px;
  align-items: center;
}

.device-list-text {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.device-thumb {
  width: 64px;
  height: 48px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid #c9d8eb;
  background: #f7fbff;
}

.device-thumb-empty {
  display: grid;
  place-items: center;
  font-size: 10px;
  color: #6f839b;
}

.device-list-item[draggable="true"] {
  cursor: grab;
}

.device-list-item.placed {
  border-color: #90b5d8;
  background: #f4f9ff;
}

.device-list-item strong {
  font-size: 17px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.device-list-item .device-model {
  font-size: 15px;
  color: var(--muted);
}

.device-status {
  display: inline-flex;
  width: fit-content;
  margin-top: 4px;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.device-status.status-placed {
  background: #e6f5ea;
  color: #24733d;
  border: 1px solid #b8dfc3;
}

.device-status.status-unplaced {
  background: #ffe7e7;
  color: #922e2e;
  border: 1px solid #e5b4b4;
}

.device-list-item.active {
  border-color: #3f82bd;
  background: linear-gradient(180deg, #e7f2ff 0%, #d6eaff 100%);
}

.device-list-item.empty {
  cursor: default;
  color: var(--muted);
}

.center-panel {
  display: flex;
  flex-direction: column;
}

.canvas-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-alt);
  font-size: 14px;
}

.tool-switch {
  display: flex;
  gap: 8px;
}

.tool-btn {
  border: 1px solid #a9bfd9;
  border-radius: 6px;
  background: #fff;
  color: #2b4768;
  font-weight: 600;
  font-size: 12px;
  padding: 6px 10px;
  cursor: pointer;
}

.tool-btn.active {
  border-color: #2f78b6;
  background: #dff0ff;
}

.hint {
  color: var(--muted);
}

#canvas {
  position: relative;
  flex: 1;
  min-height: 540px;
  background-color: #f7f9fc;
  background-image:
    linear-gradient(to right, rgba(93, 125, 162, 0.16) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(93, 125, 162, 0.16) 1px, transparent 1px);
  background-size: 30px 30px;
  overflow: hidden;
}

.drop-hint {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  border: 1px dashed #8ba9c8;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.8);
  color: #426489;
  padding: 10px 12px;
  font-size: 13px;
  z-index: 1;
  pointer-events: none;
}

.link-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}

.room-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}

.room-rect {
  fill: rgba(94, 138, 183, 0.14);
  stroke: rgba(57, 96, 134, 0.8);
  stroke-width: 1.5;
  stroke-dasharray: 5 4;
}

.room-label {
  fill: #2a4868;
  font-size: 12px;
  font-weight: 700;
}

.link-line {
  stroke: #1f5f9e;
  stroke-width: 2.2;
  stroke-linecap: round;
  opacity: 0.9;
}

.link-label {
  fill: #24486f;
  font-size: 12px;
  font-weight: 700;
  text-anchor: middle;
  paint-order: stroke;
  stroke: #f7f9fc;
  stroke-width: 3px;
}

.node {
  position: absolute;
  width: 98px;
  padding: 6px 6px 4px;
  border-radius: 9px;
  border: 1px solid #6d86a3;
  background: linear-gradient(180deg, #fdfefe 0%, #eff6ff 100%);
  box-shadow: 0 6px 16px rgba(36, 74, 112, 0.2);
  cursor: move;
  user-select: none;
  display: grid;
  gap: 4px;
  justify-items: center;
  z-index: 3;
}

.node-icon {
  width: 58px;
  height: 58px;
  object-fit: contain;
  display: block;
  pointer-events: none;
}

.node-caption {
  font-size: 10px;
  color: #2c405b;
  line-height: 1.2;
  max-width: 100%;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

.node-active {
  border-color: #0f71c4;
  box-shadow: 0 0 0 2px rgba(31, 117, 188, 0.24), 0 8px 16px rgba(36, 74, 112, 0.24);
}

.right-panel {
  display: flex;
  flex-direction: column;
}

.device-card {
  margin: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff 0%, #f5f9ff 100%);
}

.device-card h3 {
  margin: 0 0 10px;
  font-size: 32px;
}

.device-card p {
  margin: 7px 0;
  font-size: 15px;
  color: #2d4461;
}

.device-card .mini-inline {
  margin-top: 8px;
}

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

.link-editor {
  margin: 0 10px 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.room-help {
  margin-top: 0;
  margin-bottom: 8px;
}

.link-editor h3 {
  margin: 0 0 10px;
  font-size: 18px;
}

.device-photo-link {
  display: block;
  margin: 8px 0 10px;
}

.device-photo-preview {
  width: 100%;
  max-height: 190px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid #c6d5e9;
  display: block;
  cursor: zoom-in;
}

.image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 1300;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(8, 16, 28, 0.84);
}

.image-lightbox.open {
  display: flex;
}

.image-lightbox img {
  max-width: min(92vw, 1600px);
  max-height: 88vh;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 10px;
  border: 1px solid rgba(210, 224, 244, 0.32);
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.42);
  background: #0f1622;
}

.lightbox-close {
  position: absolute;
  top: 14px;
  right: 16px;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(220, 233, 255, 0.56);
  border-radius: 999px;
  background: rgba(14, 24, 38, 0.74);
  color: #fff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.device-info-modal {
  position: fixed;
  inset: 0;
  z-index: 1240;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(8, 16, 28, 0.76);
}

.device-info-modal.open {
  display: flex;
}

.device-info-modal-card {
  position: relative;
  width: min(540px, 96vw);
  max-height: 90vh;
  overflow: auto;
  background: #fff;
  border: 1px solid #c8d8ec;
  border-radius: 12px;
  box-shadow: 0 20px 46px rgba(0, 0, 0, 0.35);
  padding: 16px;
}

.device-info-modal-card h3 {
  margin: 0 44px 10px 0;
  font-size: 24px;
}

.device-info-modal-card p {
  margin: 6px 0;
  color: #2d4461;
}

.device-info-row {
  display: grid;
  grid-template-columns: 74px 1fr;
  gap: 10px;
  align-items: start;
}

.device-info-icon {
  width: 74px;
  height: 74px;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid #d4e2f2;
  background: #f8fbff;
  padding: 4px;
}

.link-form {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}

.link-form select {
  width: 100%;
  border: 1px solid #c5d3e8;
  border-radius: 6px;
  padding: 7px 8px;
  background: #fff;
}

.mini-btn {
  padding: 8px 10px;
  font-size: 13px;
}

.link-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.link-item {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  display: grid;
  gap: 6px;
  background: #f9fbff;
}

.link-item span {
  font-size: 13px;
  color: #2b4463;
}

.link-item select {
  border: 1px solid #c5d3e8;
  border-radius: 6px;
  padding: 5px 6px;
}

.link-item input {
  border: 1px solid #c5d3e8;
  border-radius: 6px;
  padding: 5px 6px;
}

.mini-inline {
  border: 1px solid #9eb6d1;
  background: #eef4fd;
  color: #294a6f;
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 12px;
  cursor: pointer;
}

.mini-inline.danger {
  border-color: #d7a4a4;
  background: #fff2f2;
  color: #8c2f2f;
}

.room-draft {
  position: absolute;
  border: 2px dashed #4c82b7;
  background: rgba(96, 145, 191, 0.12);
  z-index: 4;
  pointer-events: none;
}

.rack-box {
  position: absolute;
  border: none;
  border-radius: 4px;
  background: transparent;
  z-index: 2;
  min-width: 42px;
  min-height: 82px;
  cursor: context-menu;
  box-shadow: none;
  user-select: none;
  -webkit-user-select: none;
}

.rack-box > span {
  position: absolute;
  left: 50%;
  top: calc(50% + 34px);
  transform: translateX(-50%);
  font-size: 10px;
  font-weight: 700;
  color: #1f2f44;
  background: rgba(255, 255, 255, 0.9);
  padding: 1px 4px;
  border-radius: 4px;
  white-space: nowrap;
  pointer-events: none;
}

.rack-box.active {
  box-shadow: none;
}

.rack-box::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 64px;
  height: 64px;
  transform: translate(-50%, -50%);
  background: url("/static/icons/rack.png") center / contain no-repeat;
  pointer-events: none;
}

.context-menu {
  position: fixed;
  z-index: 999;
  background: #fff;
  border: 1px solid #c6d3e6;
  border-radius: 8px;
  box-shadow: 0 12px 28px rgba(31, 48, 69, 0.22);
  display: grid;
  min-width: 180px;
  overflow: hidden;
}

.context-menu button {
  border: 0;
  background: #fff;
  color: #25405f;
  text-align: left;
  padding: 9px 10px;
  cursor: pointer;
}

.context-menu button:hover {
  background: #edf4ff;
}

.hidden {
  display: none !important;
}

.rack-modal {
  position: fixed;
  inset: 0;
  background: rgba(18, 27, 39, 0.42);
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 18px;
}

.rack-modal-body {
  width: min(720px, 100%);
  max-height: 80vh;
  overflow: auto;
  background: #fff;
  border-radius: 10px;
  border: 1px solid #cfdbeb;
  box-shadow: 0 20px 44px rgba(16, 29, 45, 0.24);
  padding: 12px;
}

.rack-modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.rack-modal-head h3 {
  margin: 0;
  font-size: 22px;
}

.rack-mount-form {
  display: grid;
  grid-template-columns: 1fr 90px 90px auto;
  gap: 8px;
  margin-bottom: 10px;
}

.rack-editor-controls {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-bottom: 8px;
}

.rack-editor-controls input,
.rack-editor-controls select {
  border: 1px solid #c5d3e8;
  border-radius: 6px;
  padding: 7px 8px;
}

.rack-editor-modal {
  position: fixed;
  inset: 0;
  z-index: 1220;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(8, 16, 28, 0.72);
}

.rack-editor-modal.hidden {
  display: none !important;
}

.rack-editor-modal-card {
  position: relative;
  width: min(560px, 96vw);
  max-height: 90vh;
  overflow: auto;
  background: #fff;
  border: 1px solid #c8d8ec;
  border-radius: 12px;
  box-shadow: 0 20px 46px rgba(0, 0, 0, 0.35);
  padding: 14px;
}

.rack-editor-modal-card h3 {
  margin: 0 44px 10px 0;
  font-size: 22px;
}

.rack-grid {
  border: 1px solid #c6d4e8;
  border-radius: 6px;
  max-height: 280px;
  overflow: auto;
  margin-bottom: 8px;
}

.rack-slot {
  min-height: 28px;
  border-bottom: 1px solid #e0e8f3;
  padding: 3px 6px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
}

.rack-slot.occupied {
  background: #eef5ff;
}

.rack-slot-label {
  width: 34px;
  font-size: 11px;
  color: #6a7b92;
}

.rack-slot-device {
  font-size: 12px;
  color: #284565;
}

.rack-slot-delete {
  margin-left: auto;
  padding: 3px 7px;
  font-size: 11px;
}

.rack-links-viz {
  border: 1px solid #c6d4e8;
  border-radius: 8px;
  background: #f8fbff;
  min-height: 160px;
  max-height: 320px;
  overflow: auto;
  padding: 8px;
}

.rack-links-svg {
  width: 100%;
  display: block;
}

.rack-schema-body {
  fill: #f2f7ff;
  stroke: #98b3d1;
  stroke-width: 1.5;
}

.rack-schema-unit-line {
  stroke: #d4e0ef;
  stroke-width: 1;
}

.rack-schema-unit-label {
  fill: #627b98;
  font-size: 10px;
  font-weight: 700;
}

.rack-schema-device rect {
  fill: #ffffff;
  stroke: #7da0c6;
  stroke-width: 1;
}

.rack-schema-device text {
  fill: #26425f;
  font-size: 10px;
  font-weight: 700;
}

.rack-schema-link {
  fill: none;
  stroke-width: 2.3;
  stroke-linecap: round;
  opacity: 0.95;
}

.rack-links-legend {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.rack-links-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #2f4968;
}

.rack-links-legend-item i {
  width: 14px;
  height: 4px;
  border-radius: 2px;
  display: inline-block;
}

.rack-mount-form select,
.rack-mount-form input {
  border: 1px solid #c5d3e8;
  border-radius: 6px;
  padding: 7px 8px;
}

@media (max-width: 1320px) {
  .editor-layout {
    grid-template-columns: 250px 1fr 280px;
  }
}

@media (max-width: 1080px) {
  .geo-map-panel {
    grid-template-columns: 1fr;
  }
  .geo-map-module {
    grid-template-columns: 1fr;
  }
  .editor-title-wrap h1 {
    font-size: 20px;
  }
  .brand-logo-image {
    width: 84px;
    height: 84px;
  }
  .editor-layout {
    grid-template-columns: 1fr;
  }
  .left-panel,
  .right-panel {
    order: 1;
  }
  .center-panel {
    order: 0;
  }
  #canvas {
    min-height: 480px;
  }
}
