:root {
  --bg: #e8edf3;
  --panel: #ffffff;
  --panel-soft: #f7f9fc;
  --ink: #17202a;
  --muted: #657184;
  --line: #d7dee8;
  --line-strong: #b8c2d0;
  --accent: #0f766e;
  --accent-dark: #0b5f59;
  --accent-2: #1d4ed8;
  --danger: #b91c1c;
  --camera: #dc2626;
  --nvr: #475569;
  --switch: #2563eb;
  --cabinet: #0f172a;
  --pole: #92400e;
  --door: #0f766e;
  --barrier: #d97706;
  --ap: #7c3aed;
  --panel-ap: #9333ea;
  --tp: #0891b2;
  --dark: #111827;
  --shadow: 0 10px 30px rgba(15, 23, 42, .08);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  font-family: "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
  background: var(--bg);
}

button,
input,
select {
  font: inherit;
}

button,
.file-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 7px;
  padding: 8px 10px;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease, color .15s ease, transform .15s ease;
}

button:hover,
.file-button:hover {
  border-color: #9aa7b9;
  background: #f8fafc;
}

button:active,
.file-button:active {
  transform: translateY(1px);
}

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

button:disabled:hover {
  border-color: var(--line);
  background: #fff;
}

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-columns: 310px minmax(620px, 1fr) 300px;
}

.left-rail,
.right-rail {
  overflow: auto;
  padding: 16px;
  border-right: 1px solid var(--line);
  background: #eef3f8;
}

.right-rail {
  border-right: 0;
  border-left: 1px solid var(--line);
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 4px 2px 14px;
}

.brand-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .5px;
  background: linear-gradient(135deg, #0f766e, #1d4ed8);
  box-shadow: var(--shadow);
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
}

.brand p {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px;
  margin-bottom: 12px;
  box-shadow: 0 2px 10px rgba(15, 23, 42, .035);
}

.import-card {
  border-color: rgba(15, 118, 110, .28);
  background: linear-gradient(180deg, #ffffff 0%, #f1fbf9 100%);
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  color: #273447;
  font-size: 13px;
  font-weight: 800;
}

.panel-title::before {
  content: "";
  width: 4px;
  height: 15px;
  border-radius: 999px;
  background: var(--accent);
}

.panel-note {
  margin: -2px 0 12px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

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

.tool {
  position: relative;
  min-height: 38px;
  padding-left: 12px;
  text-align: left;
  color: #243244;
  background: var(--panel-soft);
}

.tool::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 7px;
  border-radius: 50%;
  background: #94a3b8;
}

.tool.device.camera::before {
  background: var(--camera);
}

.tool.device.nvr::before {
  background: var(--nvr);
}

.tool.device.switch::before {
  background: var(--switch);
}

.tool.device.cabinet::before {
  background: var(--cabinet);
}

.tool.device.pole::before {
  background: var(--pole);
}

.tool.device.door::before {
  background: var(--door);
}

.tool.device.barrier::before {
  background: var(--barrier);
}

.tool.device.ap::before {
  background: var(--ap);
}

.tool.device.panel-ap::before {
  background: var(--panel-ap);
}

.tool.device.tp::before {
  background: var(--tp);
}

.tool.accent-line::before {
  width: 18px;
  height: 3px;
  border-radius: 3px;
  vertical-align: middle;
  background: var(--accent-2);
}

.tool.active {
  color: #fff;
  border-color: var(--accent);
  background: var(--accent);
  box-shadow: 0 8px 18px rgba(15, 118, 110, .22);
}

.tool.active::before {
  background: #fff;
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 12px;
}

.field.compact {
  margin-top: 12px;
}

.field input,
.field select,
#projectName {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 9px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

.field input:focus,
.field select:focus,
#projectName:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, .12);
}

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

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  font-size: 13px;
  color: #334155;
}

.toggle input {
  accent-color: var(--accent);
}

.workspace {
  min-width: 0;
  display: grid;
  grid-template-rows: 68px 1fr 62px 28px;
  background:
    linear-gradient(rgba(17, 24, 39, .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(17, 24, 39, .035) 1px, transparent 1px),
    #dfe6ef;
  background-size: 24px 24px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .96);
}

.project-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 280px;
}

.eyebrow {
  display: block;
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 11px;
}

#projectName {
  max-width: 320px;
  padding: 0;
  border: 0;
  border-radius: 0;
  font-size: 18px;
  font-weight: 800;
  background: transparent;
}

#projectName:focus {
  box-shadow: none;
}

#statusText {
  padding: 5px 9px;
  border: 1px solid #dbe4ee;
  border-radius: 999px;
  color: var(--accent-dark);
  background: #ecfdf5;
  font-size: 12px;
  white-space: nowrap;
}

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

.actions button,
.actions .file-button,
.actions .download-link,
.actions .help-link {
  min-height: 34px;
  padding: 7px 10px;
  font-size: 13px;
}

.download-link,
.help-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  text-decoration: none;
}

.download-link {
  color: #fff;
  border-color: var(--accent);
  background: var(--accent);
}

.download-link:hover {
  color: #fff;
  border-color: var(--accent-dark);
  background: var(--accent-dark);
}

.help-link {
  color: var(--accent-dark);
  background: #ecfdf5;
}

.help-link:hover {
  border-color: var(--accent);
  background: #dff8f2;
}

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

.primary:hover,
.primary-action:hover {
  color: #fff;
  border-color: var(--accent-dark);
  background: var(--accent-dark);
}

.file-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.file-button.wide,
.wide-button {
  width: 100%;
}

.wide-button {
  margin-top: 6px;
}

.panel-action {
  margin-top: 12px;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.canvas-wrap {
  position: relative;
  min-height: 0;
  margin: 14px;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fbfcfe;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .85), var(--shadow);
}

.canvas-header {
  position: absolute;
  z-index: 2;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  pointer-events: none;
}

.canvas-header strong {
  display: block;
  margin-bottom: 3px;
  color: #111827;
  font-size: 14px;
}

.canvas-header span {
  color: #64748b;
  font-size: 12px;
}

.canvas-badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.canvas-badges span {
  padding: 5px 8px;
  border: 1px solid rgba(15, 23, 42, .1);
  border-radius: 999px;
  color: #334155;
  background: rgba(255, 255, 255, .92);
}

#cadCanvas {
  width: 100%;
  height: 100%;
  display: block;
  background:
    linear-gradient(rgba(37, 99, 235, .055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(37, 99, 235, .055) 1px, transparent 1px),
    #fbfcfe;
  background-size: 20px 20px;
  cursor: crosshair;
}

.canvas-text-editor {
  position: absolute;
  z-index: 4;
  min-width: 180px;
  max-width: 420px;
  height: 34px;
  padding: 6px 9px;
  border: 2px solid var(--accent);
  border-radius: 6px;
  color: #111827;
  background: #fff;
  box-shadow: 0 10px 28px rgba(15, 23, 42, .18);
  outline: none;
}

.hintbar {
  position: absolute;
  z-index: 3;
  left: 16px;
  bottom: 16px;
  max-width: min(760px, calc(100% - 32px));
  padding: 8px 10px;
  border: 1px solid rgba(15, 23, 42, .12);
  border-radius: 7px;
  color: #475569;
  background: rgba(255, 255, 255, .94);
  font-size: 12px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .08);
}

.summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  border-top: 1px solid var(--line);
  background: var(--line);
}

.summary div {
  display: grid;
  place-items: center;
  align-content: center;
  background: rgba(255, 255, 255, .96);
}

.summary strong {
  font-size: 19px;
  color: #111827;
}

.summary span {
  font-size: 12px;
  color: var(--muted);
}

.copyright {
  display: grid;
  place-items: center;
  border-top: 1px solid var(--line);
  color: #475569;
  background: #fff;
  font-size: 12px;
}

.object-panel .empty,
.empty {
  padding: 12px;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 7px;
  background: #fafcff;
  font-size: 13px;
}

.object-card {
  display: grid;
  gap: 7px;
  font-size: 13px;
}

.object-card b {
  color: #0f172a;
}

.object-editors {
  display: none;
  gap: 8px;
  margin-top: 10px;
}

.object-editors.visible {
  display: grid;
}

.object-editors .field {
  margin-bottom: 0;
}

.object-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

#deleteBtn {
  color: var(--danger);
}

.bom-list {
  display: grid;
  gap: 8px;
  font-size: 13px;
}

.bom-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid #eef2f7;
}

.bom-row:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.workflow {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 22px;
  color: #334155;
  font-size: 13px;
  line-height: 1.45;
}

.workflow li::marker {
  color: var(--accent);
  font-weight: 800;
}

.legend {
  display: grid;
  gap: 9px;
  font-size: 13px;
}

.legend span {
  display: flex;
  align-items: center;
  gap: 8px;
  line-height: 1.35;
}

.sample {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  display: inline-block;
  border: 2px solid #111827;
  background: #fff;
}

.sample.camera {
  border-radius: 50%;
  border-color: var(--camera);
}

.sample.nvr {
  border-color: var(--nvr);
  background: #e2e8f0;
}

.sample.switch {
  border-color: var(--switch);
}

.sample.cabinet {
  border-color: var(--cabinet);
  background: #f1f5f9;
}

.sample.pole {
  width: 8px;
  border-width: 0 0 0 3px;
  border-color: var(--pole);
  background: transparent;
}

.sample.door {
  border-color: var(--door);
}

.sample.barrier {
  border-color: var(--barrier);
}

.sample.ap {
  border-radius: 50%;
  border-color: var(--ap);
}

.sample.panel-ap {
  border-color: var(--panel-ap);
  border-radius: 4px;
}

.sample.tp {
  border-color: var(--tp);
  border-radius: 4px;
  background: linear-gradient(#fff 0 30%, #e0f2fe 30% 70%, #fff 70%);
}

@media (max-width: 1220px) {
  .app-shell {
    grid-template-columns: 280px minmax(480px, 1fr);
  }

  .right-rail {
    display: none;
  }
}

@media (max-width: 900px) {
  body {
    overflow: auto;
  }

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

  .left-rail,
  .right-rail {
    display: block;
    border: 0;
  }

  .workspace {
    height: 76vh;
    min-height: 560px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
    height: auto;
  }

  .project-meta,
  .canvas-header {
    flex-direction: column;
  }

  .canvas-badges {
    justify-content: flex-start;
  }
}
