:root {
  font-family: "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
  color: #101827;
  background: #eef2f7;
  --blue: #1677ff;
  --line: #d9e2ef;
  --muted: #64748b;
  --panel: #ffffff;
  --dark: #202124;
}

* {
  box-sizing: border-box;
}

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

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.home {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 440px 1fr;
}

.panel {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 30px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #0f172a;
  color: #fff;
  font-weight: 800;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
}

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

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

.field span {
  font-weight: 700;
}

.field input[type="text"] {
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
}

.dropzone {
  position: relative;
  min-height: 168px;
  border: 1px dashed #9fb2ca;
  border-radius: 8px;
  display: grid;
  place-items: center;
  text-align: center;
  background: #f8fafc;
}

.dropzone input {
  position: absolute;
  inset: 0;
  opacity: 0;
}

.dropzone strong {
  display: block;
  margin-bottom: 8px;
  font-size: 18px;
}

.primary {
  height: 44px;
  border-radius: 8px;
  background: var(--blue);
  color: #fff;
  font-weight: 800;
}

.primary:disabled {
  background: #94a3b8;
  cursor: not-allowed;
}

.result,
.project-list,
.notice {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
}

.notice {
  background: #f8fafc;
}

.share-row {
  display: grid;
  grid-template-columns: 1fr 70px;
  gap: 8px;
  margin-top: 10px;
}

.share-row input {
  min-width: 0;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 8px;
}

.share-row button {
  border-radius: 6px;
  color: #fff;
  background: var(--dark);
  font-weight: 700;
}

.qr {
  width: 150px;
  height: 150px;
  border: 1px solid var(--line);
  margin-top: 12px;
}

.project-list {
  display: grid;
  gap: 10px;
}

.project-list > strong {
  display: none;
}

.project-list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.project-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 4px;
  padding: 10px 0;
  color: inherit;
  border-top: 1px solid #eef2f7;
}

.project-link {
  display: grid;
  min-width: 0;
  gap: 4px;
  color: inherit;
  text-decoration: none;
}

.project-item:first-child {
  border-top: 0;
}

.project-item strong {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.ghost {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: #334155;
  font-weight: 700;
}

.ghost.danger {
  color: #b42318;
  border-color: #fecaca;
}

.stage {
  position: relative;
  min-width: 0;
  overflow: hidden;
  background: #bfc3c7;
}

.preview-text {
  position: absolute;
  left: 36px;
  bottom: 36px;
  max-width: 560px;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .35);
}

.cad-viewer {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: #bfc3c7;
}

.cad-viewer.dark-theme {
  background: #000;
}

#cadCanvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.viewer-badge {
  position: absolute;
  left: 16px;
  top: 62px;
  z-index: 3;
  display: grid;
  gap: 4px;
  max-width: min(480px, calc(100vw - 96px));
  padding: 8px 10px;
  border-radius: 4px;
  color: rgba(255, 255, 255, .9);
  background: rgba(32, 33, 36, .4);
  backdrop-filter: blur(6px);
}

.viewer-badge strong {
  font-size: 14px;
}

.viewer-badge span {
  font-size: 12px;
}

.viewer-quality-badge {
  justify-self: start;
  height: 24px;
  padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, .24);
  border-radius: 4px;
  background: rgba(255, 255, 255, .14);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.viewer-quality-pass {
  border-color: rgba(134, 239, 172, .7);
  background: rgba(22, 101, 52, .7);
}

.viewer-quality-risk {
  border-color: rgba(251, 191, 36, .85);
  background: rgba(146, 64, 14, .82);
}

.viewer-quality-pending {
  border-color: rgba(203, 213, 225, .65);
  background: rgba(51, 65, 85, .7);
}

.ref-top-toolbar {
  position: absolute;
  top: 12px;
  left: 16px;
  z-index: 8;
  display: flex;
  gap: 8px;
}

.ref-top-toolbar button {
  min-width: 60px;
  height: 40px;
  padding: 0 14px;
  border-radius: 4px;
  background: #2d2d2d;
  color: #fff;
  font-weight: 700;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .12) inset;
}

.ref-top-toolbar button:hover,
.ref-bottom-toolbar button:hover,
.ref-top-toolbar button.active,
.ref-bottom-toolbar button.active {
  background: #171717;
}

.ref-top-toolbar button.active,
.ref-bottom-toolbar button.active {
  background: #1684ff;
  color: #fff;
}

.ref-side-toolbar {
  position: absolute;
  top: 8px;
  right: 16px;
  z-index: 8;
  display: grid;
  gap: 8px;
}

.ref-side-toolbar button {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, .96);
  color: #1684ff;
  font-weight: 900;
  box-shadow: 0 6px 18px rgba(15, 23, 42, .12);
}

.ref-side-toolbar button:hover {
  transform: translateY(-1px);
}

.ref-bottom-toolbar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 8;
  height: 44px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: #2d2d2d;
}

.ref-bottom-toolbar button {
  color: #fff;
  background: transparent;
  font-weight: 700;
}

/* 底部柜名切换栏（view-fly 风格）：横向滚动，一次只看一个柜体 */
.cabinet-strip {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 44px;
  z-index: 8;
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  overflow-x: auto;
  background: rgba(20, 20, 20, .82);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.cabinet-strip button {
  flex: 0 0 auto;
  padding: 7px 14px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, .18);
  background: rgba(255, 255, 255, .08);
  color: #e9e9e9;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.cabinet-strip button.active {
  background: #2994ff;
  border-color: #2994ff;
  color: #fff;
}

.floating-menu {
  position: absolute;
  z-index: 11;
  min-width: 140px;
  padding: 6px;
  border-radius: 4px;
  background: rgba(32, 33, 36, .95);
  box-shadow: 0 16px 36px rgba(0, 0, 0, .2);
}

.floating-menu button {
  width: 100%;
  height: 34px;
  border-radius: 3px;
  color: #fff;
  background: transparent;
  text-align: left;
  padding: 0 10px;
}

.floating-menu button:hover,
.floating-menu button.active {
  background: rgba(255, 255, 255, .12);
}

.floating-menu button.active {
  color: #7cc2ff;
}

.floating-menu-label {
  height: 28px;
  display: flex;
  align-items: center;
  padding: 0 10px;
  color: rgba(255, 255, 255, .62);
  font-size: 12px;
  font-weight: 700;
}

.floating-menu-label.with-line {
  margin-top: 6px;
  border-top: 1px solid rgba(255, 255, 255, .16);
}

.ref-bottom-sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 44px;
  z-index: 9;
  max-height: 333px;
  min-height: 220px;
  display: grid;
  grid-template-rows: auto 1fr;
  background: rgba(245, 247, 249, .96);
  border-top: 1px solid rgba(0, 0, 0, .12);
  box-shadow: 0 -18px 50px rgba(15, 23, 42, .18);
}

.ref-bottom-sheet header {
  height: 48px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  border-bottom: 1px solid #dde5ee;
}

#sheetTitle {
  font-size: 16px;
  font-weight: 800;
}

.ref-bottom-sheet header button,
.sheet-actions button,
.note-form button {
  min-height: 28px;
  border-radius: 4px;
  padding: 0 12px;
  color: #fff;
  background: #2d2d2d;
  font-weight: 700;
}

#sheetBody {
  min-height: 0;
  overflow: auto;
  padding: 12px;
}

.sheet-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.room-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.room-tabs button {
  height: 30px;
  border-radius: 4px;
  padding: 0 14px;
  color: #fff;
  background: #2994ff;
  font-weight: 700;
}

.cabinet-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 10px;
}

.cabinet-card {
  min-height: 76px;
  display: grid;
  grid-template-columns: 24px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border: 1px solid #d4dde9;
  border-radius: 4px;
  background: #fff;
}

.cabinet-card span {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.cabinet-card strong {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.cabinet-card small {
  color: #52647a;
}

.cabinet-card button {
  height: 30px;
  border-radius: 4px;
  background: #111827;
  color: #fff;
  padding: 0 10px;
  font-weight: 700;
}

.material-table-wrap {
  overflow: auto;
  border: 1px solid #d4dde9;
  background: #fff;
}

.material-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.material-table th,
.material-table td {
  height: 34px;
  padding: 0 10px;
  border-bottom: 1px solid #e8eef5;
  text-align: left;
  white-space: nowrap;
}

.material-table th {
  position: sticky;
  top: 0;
  background: #f1f5f9;
  z-index: 1;
}

.material-table tbody tr[data-panel-key] {
  cursor: pointer;
}

.material-table tbody tr[data-panel-key]:hover,
.material-table tbody tr.active {
  background: #e9f4ff;
}

.material-table button {
  height: 24px;
  border-radius: 4px;
  padding: 0 8px;
  color: #fff;
  background: #111827;
  font-size: 12px;
}

.material-section-title {
  margin: 8px 0 10px;
  font-size: 14px;
}

.small-table {
  margin-bottom: 12px;
}

.small-table .material-table {
  font-size: 12px;
}

.sheet-hint {
  color: #64748b;
  padding: 10px 0;
}

.diagnostics-quality {
  display: grid;
  gap: 4px;
  margin-bottom: 12px;
  padding: 10px 12px;
  border: 1px solid #d4dde9;
  border-radius: 8px;
  background: #f8fafc;
  color: #334155;
}

.diagnostics-quality-ok {
  border-color: #86efac;
  background: #f0fdf4;
  color: #166534;
}

.diagnostics-quality-warn {
  border-color: #fbbf24;
  background: #fffbeb;
  color: #92400e;
}

.diagnostics-quality-danger {
  border-color: #fca5a5;
  background: #fef2f2;
  color: #991b1b;
}

.diagnostics-quality-high {
  background: #fef2f2;
  color: #991b1b;
}

.diagnostics-quality-medium {
  background: #fffbeb;
  color: #92400e;
}

.diagnostics-quality-pass {
  background: #f0fdf4;
  color: #166534;
}

.diagnostics-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(260px, 1fr));
  gap: 12px;
}

.diagnostics-table {
  max-height: 150px;
}

.diagnostic-json {
  max-height: 150px;
  overflow: auto;
  margin: 0;
  padding: 10px;
  border: 1px solid #d4dde9;
  border-radius: 4px;
  background: #0f172a;
  color: #dbeafe;
  font: 12px/1.5 Consolas, "Courier New", monospace;
  white-space: pre-wrap;
}

.note-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 80px;
  gap: 8px;
  margin-bottom: 12px;
}

.note-form.note-editor {
  grid-template-columns: 1fr;
}

.note-editor label {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
}

.note-editor textarea {
  min-height: 74px;
  resize: vertical;
  border: 1px solid #d4dde9;
  border-radius: 4px;
  padding: 8px 10px;
  font: inherit;
}

.note-form input {
  height: 36px;
  border: 1px solid #d4dde9;
  border-radius: 4px;
  padding: 0 10px;
}

.note-list {
  display: grid;
  gap: 8px;
}

.note-list article {
  padding: 10px;
  border: 1px solid #d4dde9;
  border-radius: 4px;
  background: #fff;
}

.note-list article strong {
  color: #475569;
  font-size: 12px;
}

.note-list article small,
.note-list article a {
  display: block;
  margin-top: 6px;
  color: #475569;
  font-size: 12px;
}

.qr-panel {
  position: absolute;
  right: 70px;
  top: 54px;
  z-index: 10;
  width: 360px;
  padding: 14px;
  border-radius: 4px;
  background: rgba(255, 255, 255, .96);
  box-shadow: 0 18px 44px rgba(15, 23, 42, .2);
}

.board-lookup-panel {
  position: absolute;
  right: 70px;
  top: 102px;
  z-index: 10;
  width: 360px;
  max-height: calc(100vh - 150px);
  overflow: auto;
  padding: 14px;
  border-radius: 4px;
  background: #fff;
  box-shadow: 0 18px 44px rgba(15, 23, 42, .22);
}

.qr-panel header,
.board-lookup-panel header,
.detail-dialog header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.qr-panel header button,
.board-lookup-panel header button,
.detail-dialog header button {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  color: #fff;
  background: #111827;
}

.board-lookup-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 72px;
  gap: 8px;
  margin-bottom: 10px;
}

.board-lookup-form input {
  min-width: 0;
  height: 36px;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  padding: 0 10px;
  font: inherit;
}

.board-lookup-form button,
.board-lookup-actions button {
  min-height: 36px;
  border-radius: 4px;
  padding: 0 12px;
  color: #fff;
  background: #111827;
  font-weight: 800;
}

.board-lookup-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.board-scan-preview {
  overflow: hidden;
  margin-bottom: 10px;
  border-radius: 4px;
  background: #0f172a;
}

.board-scan-preview video {
  display: block;
  width: 100%;
  max-height: 240px;
  object-fit: cover;
}

.board-lookup-panel [data-board-lookup-status] {
  margin: 0 0 10px;
  padding: 8px 10px;
  border-radius: 4px;
  color: #475569;
  background: #f1f5f9;
  font-size: 12px;
  line-height: 1.4;
}

.board-lookup-panel .board-lookup-ok {
  color: #166534;
  background: #dcfce7;
}

.board-lookup-panel .board-lookup-warn {
  color: #92400e;
  background: #fffbeb;
}

.board-lookup-results {
  display: grid;
  gap: 8px;
}

.board-lookup-results button {
  display: grid;
  gap: 4px;
  width: 100%;
  min-height: 58px;
  padding: 8px 10px;
  border: 1px solid #d4dde9;
  border-radius: 4px;
  color: #111827;
  background: #fff;
  text-align: left;
}

.board-lookup-results button.active,
.board-lookup-results button:hover {
  border-color: #1684ff;
  background: #e9f4ff;
}

.board-lookup-results strong,
.board-lookup-results span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.board-lookup-results span {
  color: #52647a;
  font-size: 12px;
}

.qr-panel img {
  display: block;
  width: 132px;
  height: 132px;
  margin: 6px auto;
  border: 1px solid #e2e8f0;
}

.qr-panel p {
  word-break: break-all;
  color: #475569;
  font-size: 12px;
}

.qr-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 10px 0;
}

.qr-grid figure {
  margin: 0;
  text-align: center;
  color: #475569;
  font-size: 12px;
}

.qr-fallback {
  display: grid;
  gap: 4px;
  margin: 10px 0;
  padding: 12px;
  border: 1px dashed #cbd5e1;
  border-radius: 4px;
  color: #475569;
  background: #f8fafc;
  text-align: center;
}

.qr-fallback strong {
  color: #0f172a;
}

.share-link {
  max-height: 48px;
  overflow: auto;
}

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

.share-actions button {
  min-height: 30px;
  border-radius: 4px;
  color: #fff;
  background: #2d2d2d;
  font-weight: 700;
  font-size: 12px;
}

.board-info-panel {
  position: absolute;
  left: 14px;
  top: 166px;
  z-index: 9;
  width: 280px;
  max-height: calc(100vh - 240px);
  overflow: auto;
  border-radius: 4px;
  background: #fff;
  box-shadow: 0 18px 44px rgba(15, 23, 42, .22);
  padding: 12px;
}

.board-info-panel.collapsed {
  width: 260px;
  max-height: none;
  overflow: visible;
  padding: 8px 10px;
}

.board-info-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.board-info-header strong {
  min-width: 0;
  overflow: hidden;
  color: #111827;
  font-size: 13px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.board-info-header button {
  flex: 0 0 auto;
  min-height: 28px;
  border-radius: 4px;
  padding: 0 9px;
  color: #fff;
  background: #1f2937;
  font-size: 12px;
  font-weight: 800;
}

.board-info-summary {
  margin: 0;
  color: #475569;
  font-size: 12px;
  line-height: 1.35;
  word-break: break-word;
}

.board-info-panel dl,
.detail-dialog dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 7px 10px;
  margin: 0;
  font-size: 13px;
}

.board-info-panel dt,
.detail-dialog dt {
  color: #64748b;
  white-space: nowrap;
}

.board-info-panel dd,
.detail-dialog dd {
  min-width: 0;
  margin: 0;
  word-break: break-word;
}

.detail-dialog {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: rgba(15, 23, 42, .34);
}

.detail-dialog article {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 80px);
  overflow: auto;
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 24px 80px rgba(15, 23, 42, .28);
  padding: 16px;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: 66px;
  z-index: 20;
  transform: translateX(-50%);
  min-width: 120px;
  padding: 10px 16px;
  border-radius: 4px;
  text-align: center;
  color: #fff;
  background: rgba(17, 24, 39, .88);
}

.empty-3d {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 30px;
}

.empty-card {
  max-width: 680px;
  padding: 24px;
  border-radius: 8px;
  background: rgba(255, 255, 255, .94);
  box-shadow: 0 20px 60px rgba(15, 23, 42, .18);
}

@media (max-width: 900px) {
  .home {
    grid-template-columns: 1fr;
  }

  .stage {
    min-height: 420px;
  }

  .viewer-badge {
    display: none;
  }

  .ref-top-toolbar {
    left: 8px;
    top: 8px;
    gap: 6px;
  }

  .ref-top-toolbar button {
    min-width: 52px;
    padding: 0 10px;
  }

  .ref-side-toolbar {
    right: 8px;
  }

  .ref-bottom-toolbar {
    grid-template-columns: repeat(4, 1fr);
    height: 44px;
  }

  .ref-bottom-sheet {
    bottom: 44px;
  }

  .cabinet-strip {
    bottom: 44px;
  }

  .qr-panel {
    right: 56px;
    width: min(320px, calc(100vw - 72px));
  }

  .board-lookup-panel {
    right: 56px;
    top: 56px;
    width: min(320px, calc(100vw - 72px));
    max-height: calc(100vh - 160px);
  }

  .board-info-panel {
    top: 56px;
    width: min(280px, calc(100vw - 82px));
    max-height: 260px;
  }

  .board-info-panel.collapsed {
    width: min(240px, calc(100vw - 104px));
  }
}
