* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; font-family: "Microsoft YaHei", system-ui, sans-serif; color: #1f2937; }
body { background: #f3f4f6; overflow: hidden; }
button, select, input { font: inherit; }
button, .importBtn {
  border: 1px solid #cbd5e1; background: #fff; border-radius: 6px; padding: 6px 10px;
  cursor: pointer; color: #111827;
}
button:hover, .importBtn:hover { background: #f8fafc; border-color: #94a3b8; }
button:disabled, input:disabled { cursor: not-allowed; opacity: .6; }

.loginPage { display: grid; place-items: center; min-height: 100%; overflow: auto; padding: 24px; }
.loginCard { width: min(400px, 100%); background: #fff; border: 1px solid #d7dde6; border-radius: 12px; padding: 28px; box-shadow: 0 18px 45px rgba(15, 23, 42, .12); }
.loginCard h1 { margin: 0 0 8px; font-size: 24px; }
.loginCard > p { margin: 0 0 22px; color: #64748b; }
.loginForm { display: grid; gap: 9px; }
.loginForm label { font-size: 13px; color: #334155; }
.loginForm input { width: 100%; border: 1px solid #cbd5e1; border-radius: 6px; padding: 10px; }
.loginForm button { margin-top: 6px; padding: 10px; background: #2563eb; border-color: #2563eb; color: #fff; }
.loginError { min-height: 20px; color: #b91c1c; font-size: 13px; }

.app { height: 100%; display: grid; grid-template-columns: 360px 1fr; transition: grid-template-columns .2s ease; }
.sidebar { min-width: 0; background: #fff; border-right: 1px solid #d7dde6; padding: 14px; overflow: hidden; display: flex; flex-direction: column; gap: 10px; transition: transform .2s ease; }
body.sidebar-collapsed .app { grid-template-columns: 0 1fr; }
body.sidebar-collapsed .sidebar { transform: translateX(-100%); }
.title { font-size: 20px; font-weight: 700; }
.sub { font-size: 12px; color: #64748b; line-height: 1.5; }
.authBar { display: flex; align-items: center; gap: 6px; font-size: 12px; color: #475569; }
.authBar span { flex: 1; }
.authBar button { padding: 3px 6px; font-size: 11px; }
.toolbar { display: flex; gap: 8px; }
.toolbar button, .toolbar .importBtn { flex: 1; text-align: center; }
.search { width: 100%; border: 1px solid #cbd5e1; border-radius: 6px; padding: 8px 10px; }
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.filters select { min-width: 0; border: 1px solid #cbd5e1; border-radius: 6px; padding: 7px; background: #fff; }
.checkline { font-size: 13px; color: #334155; }
.legend { display: flex; flex-wrap: wrap; gap: 8px; font-size: 12px; color: #475569; }
.layerControls {
  border-top: 1px solid #e5e7eb;
  padding-top: 8px;
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: #334155;
}
.layerTitle {
  font-weight: 700;
  color: #111827;
}
.layerControls label {
  display: flex;
  align-items: center;
  gap: 6px;
}
.layerImportBtn {
  text-align: center;
}
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 999px; margin-right: 4px; vertical-align: -1px; }
.green { background: #22c55e; }
.red { background: #ef4444; }
.gray { background: #9ca3af; }
.hint { border: 1px solid #f59e0b; background: #fffbeb; color: #92400e; padding: 8px; border-radius: 6px; font-size: 13px; line-height: 1.5; }
.hidden { display: none !important; }

.deviceList { overflow: auto; border-top: 1px solid #e5e7eb; padding-top: 6px; }
.deviceItem { border-bottom: 1px solid #eef2f7; padding: 8px 0; display: grid; grid-template-columns: 18px 1fr auto; gap: 8px; align-items: start; }
.deviceState { width: 14px; height: 10px; border-radius: 2px; margin-top: 4px; border: 1px solid rgba(0,0,0,.15); }
.deviceName { font-size: 13px; font-weight: 600; line-height: 1.4; }
.deviceMeta { font-size: 12px; color: #64748b; line-height: 1.45; word-break: break-all; }
.deviceActions { display: flex; flex-direction: column; gap: 4px; }
.deviceActions button { padding: 3px 6px; font-size: 12px; white-space: nowrap; }
.unplaced { color: #b45309; }

.mapPane { min-width: 0; display: grid; grid-template-rows: 42px 1fr; }
.topbar { background: #fff; border-bottom: 1px solid #d7dde6; display: flex; align-items: center; gap: 10px; padding: 0 12px; }
#modeText { flex: 1; color: #475569; font-size: 13px; }
.saveState { border-radius: 999px; padding: 3px 8px; background: #dcfce7; color: #166534; font-size: 12px; white-space: nowrap; }
.saveState.dirty { background: #fef3c7; color: #92400e; }
.saveState.conflict { background: #fee2e2; color: #991b1b; }
.topUpdateInfo {
  flex: 0 1 auto;
  max-width: 620px;
  color: #334155;
  font-size: 12px;
  line-height: 1.35;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mapViewport { position: relative; overflow: hidden; background: #111827; cursor: grab; }
.mapViewport.dragging { cursor: grabbing; }
.mapViewport.placing {
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='25' height='25' viewBox='0 0 25 25'%3E%3Cline x1='12' y1='0' x2='12' y2='25' stroke='%23ef4444' stroke-width='1'/%3E%3Cline x1='0' y1='12' x2='25' y2='12' stroke='%23ef4444' stroke-width='1'/%3E%3Ccircle cx='12' cy='12' r='2.5' fill='%23ef4444'/%3E%3C/svg%3E") 12 12, crosshair;
}
.stage { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
#mapImage { position: absolute; left: 0; top: 0; user-select: none; pointer-events: none; }
.mapLayer {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.psdTextPreview {
  position: absolute;
  color: #111827;
  background: rgba(255, 255, 255, .55);
  border: 1px dashed rgba(37, 99, 235, .45);
  padding: 1px 3px;
  line-height: 1.1;
  white-space: nowrap;
  pointer-events: auto;
  cursor: pointer;
}
.psdShapePreview {
  position: absolute;
  border: 2px solid rgba(100, 116, 139, .8);
  background: rgba(100, 116, 139, .18);
  pointer-events: auto;
  cursor: pointer;
}
.psdShapePreview.lineCandidate {
  border-color: rgba(239, 68, 68, .9);
  background: rgba(239, 68, 68, .18);
}
.psdShapePreview.smallMarkerCandidate {
  border-color: rgba(234, 179, 8, .9);
  background: rgba(234, 179, 8, .22);
}
.psdShapePreview.areaCandidate {
  border-color: rgba(168, 85, 247, .9);
  background: rgba(168, 85, 247, .18);
}
.psdShapePreview.otherShape {
  border-color: rgba(100, 116, 139, .9);
  background: rgba(100, 116, 139, .18);
}
.formalText {
  position: absolute;
  color: #111827;
  line-height: 1.15;
  white-space: pre;
  pointer-events: auto;
  cursor: move;
  text-shadow: 0 1px 2px rgba(255,255,255,.75);
}
.formalText.selected {
  outline: 2px solid #38bdf8;
  background: rgba(255,255,255,.45);
}
.lineSvg {
  position: absolute;
  left: 0;
  top: 0;
  overflow: visible;
  pointer-events: none;
}
.formalLine {
  fill: none;
  cursor: pointer;
  pointer-events: stroke;
}
.formalLine.selected { filter: drop-shadow(0 0 5px #38bdf8); }
.linePoint {
  fill: #fff;
  stroke: #0f172a;
  stroke-width: 2;
  cursor: move;
  pointer-events: auto;
}
.layerEditor {
  position: absolute;
  z-index: 25;
  width: 280px;
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  box-shadow: 0 12px 28px rgba(15, 23, 42, .22);
  padding: 10px;
  display: grid;
  gap: 8px;
  pointer-events: auto;
}
.layerEditor label {
  display: grid;
  gap: 3px;
  font-size: 12px;
  color: #475569;
}
.layerEditor input,
.layerEditor select,
.layerEditor textarea {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 5px;
  padding: 5px 6px;
}
.markerLayer { position: absolute; left: 0; top: 0; pointer-events: none; }
.doorMarker {
  position: absolute; width: 20px; height: 11px; border-radius: 2px; border: 1px solid rgba(0,0,0,.45);
  box-shadow: 0 1px 3px rgba(0,0,0,.35); cursor: pointer; pointer-events: auto;
}
.doorMarker.green { background: #22c55e; }
.doorMarker.red { background: #ef4444; }
.doorMarker.gray { background: #9ca3af; }
.doorMarker.important { outline: 2px solid #facc15; }
.doorMarker.selected { outline: 2px solid #38bdf8; }
.doorMarker:hover { filter: brightness(1.12); }

.popup {
  position: absolute; width: 360px; max-width: calc(100% - 24px); background: #fff; border: 1px solid #cbd5e1;
  border-radius: 10px; box-shadow: 0 12px 30px rgba(0,0,0,.28); z-index: 20; overflow: hidden;
}
.popupHead { display: flex; justify-content: space-between; gap: 8px; padding: 10px 12px; border-bottom: 1px solid #e5e7eb; background: #f8fafc; }
.popupTitle { font-weight: 700; line-height: 1.4; }
.popupSub { font-size: 12px; color: #64748b; }
.popupClose { padding: 2px 8px; height: 28px; }
.popupBody { padding: 10px 12px; min-height: 170px; max-height: 230px; overflow: hidden; font-size: 13px; }
.field { display: grid; grid-template-columns: 92px 1fr; gap: 8px; padding: 5px 0; border-bottom: 1px dashed #e5e7eb; }
.fieldLabel { color: #64748b; }
.fieldValue { word-break: break-all; }
.popupFoot { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-top: 1px solid #e5e7eb; background: #f8fafc; }
.popupFoot button { font-size: 12px; padding: 4px 7px; }
#pageInfo { flex: 1; text-align: center; font-size: 12px; color: #64748b; }

.conflictPanel { position: absolute; z-index: 30; left: 50%; top: 18px; transform: translateX(-50%); width: min(560px, calc(100% - 32px)); background: #fff7ed; color: #9a3412; border: 1px solid #fdba74; border-radius: 8px; padding: 10px; box-shadow: 0 10px 24px rgba(15, 23, 42, .22); display: grid; gap: 7px; font-size: 13px; }

@media (max-width: 1000px) {
  .app { grid-template-columns: 300px 1fr; }
}

@media (max-width: 720px) {
  .app,
  body.sidebar-collapsed .app {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    grid-template-columns: minmax(0, 1fr);
  }
  .mapPane,
  .mapViewport {
    width: 100%;
    min-width: 0;
    max-width: 100%;
  }
  .mapPane { grid-template-columns: minmax(0, 1fr); }
  .topbar {
    min-width: 0;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
  }
  .sidebar {
    position: absolute;
    z-index: 40;
    inset: 0 auto 0 0;
    width: min(360px, 92vw);
    transform: translateX(0);
    box-shadow: 8px 0 24px rgba(15, 23, 42, .2);
  }
  #sidebarToggle {
    position: fixed;
    top: 6px;
    right: 8px;
    z-index: 50;
  }
  body.sidebar-collapsed .sidebar { transform: translateX(-100%); }
}
