:root {
  color-scheme: dark;
  --surface-0: #0d0f10;
  --surface-1: #151819;
  --surface-2: #1c2021;
  --surface-3: #24292a;
  --line: #343a3b;
  --line-strong: #485052;
  --text: #f1f4f3;
  --text-soft: #c2c9c7;
  --muted: #87908e;
  --accent: #29c7a1;
  --accent-strong: #19ad89;
  --accent-soft: rgba(41, 199, 161, .12);
  --warning: #e7b84b;
  --danger: #ff6b6b;
}

* { box-sizing: border-box; }
html, body { width: 100%; min-height: 100%; margin: 0; background: var(--surface-0); color: var(--text); font-family: "Segoe UI", "Microsoft YaHei", Arial, sans-serif; letter-spacing: 0; }
body { overflow: hidden; }
button, input { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

/* 文件入口 */
.upload-page { position: fixed; inset: 0; overflow: auto; background: #101313; }
.upload-header { display: flex; align-items: center; justify-content: space-between; width: min(1120px, calc(100% - 40px)); height: 72px; margin: 0 auto; border-bottom: 1px solid var(--line); }
.upload-header-tag { padding: 5px 8px; border: 1px solid var(--line); border-radius: 4px; color: var(--muted); font-size: 11px; }
.upload-main { display: grid; min-height: calc(100vh - 72px); place-items: center; padding: 44px 20px 64px; }
.upload-workspace { width: min(620px, 100%); }
.upload-heading { margin-bottom: 28px; }
.upload-kicker { margin: 0 0 8px; color: var(--accent); font-size: 12px; font-weight: 700; }
.upload-heading h1 { margin: 0; font-size: 30px; font-weight: 650; line-height: 1.2; }
.upload-heading > p:last-child { margin: 10px 0 0; color: var(--muted); font-size: 14px; }
.upload-form { padding: 20px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface-1); }
.upload-dropzone { display: grid; min-height: 230px; place-items: center; align-content: center; gap: 8px; padding: 28px; border: 1px dashed #56605e; border-radius: 6px; background: #111414; text-align: center; cursor: pointer; transition: border-color .15s ease, background .15s ease; }
.upload-dropzone:hover, .upload-dropzone.is-dragging { border-color: var(--accent); background: var(--accent-soft); }
.upload-dropzone.has-file { min-height: 150px; border-color: #3b6258; }
.upload-file-symbol { display: grid; width: 54px; height: 62px; place-items: center; border: 1px solid #51605c; border-radius: 5px; color: var(--accent); font-size: 12px; font-weight: 750; }
.upload-dropzone strong { margin-top: 4px; font-size: 16px; }
.upload-dropzone > span:not(.upload-file-symbol) { color: var(--text-soft); font-size: 13px; }
.upload-dropzone small { color: var(--muted); font-size: 11px; }
.upload-file-summary { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 12px; min-height: 58px; margin-top: 12px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 5px; background: var(--surface-2); }
.file-type-badge { min-width: 40px; padding: 5px 6px; border-radius: 4px; background: var(--accent-soft); color: var(--accent); text-align: center; font-size: 10px; font-weight: 750; }
.file-summary-copy { min-width: 0; }
.file-summary-copy strong, .file-summary-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-summary-copy strong { font-size: 13px; }
.file-summary-copy small { margin-top: 3px; color: var(--muted); font-size: 11px; }
.plain-button { padding: 3px 4px; border: 0; background: transparent; color: var(--text-soft); font-size: 11px; cursor: pointer; }
.plain-button:hover { color: var(--accent); }
.upload-submit { width: 100%; min-height: 42px; margin-top: 14px; border: 1px solid var(--accent-strong); border-radius: 5px; background: var(--accent-strong); color: #07120f; font-weight: 700; cursor: pointer; }
.upload-submit:hover:not(:disabled) { background: var(--accent); }
.upload-submit:disabled { border-color: #363c3b; background: #2b302f; color: #727a78; cursor: not-allowed; }
.upload-progress { height: 2px; margin-top: 12px; overflow: hidden; background: var(--surface-3); }
.upload-progress span { display: block; width: 35%; height: 100%; background: var(--accent); animation: upload-progress 1.1s ease-in-out infinite; }
.upload-status { min-height: 18px; margin: 10px 0 0; color: var(--muted); text-align: center; font-size: 12px; }
.upload-status.is-error { color: var(--danger); }
.format-matrix { display: grid; grid-template-columns: repeat(3, 1fr); margin: 18px 0 0; border-top: 1px solid var(--line); }
.format-matrix > div { min-width: 0; padding: 14px 12px; border-right: 1px solid var(--line); }
.format-matrix > div:last-child { border-right: 0; }
.format-matrix dt { color: var(--text-soft); font-size: 11px; font-weight: 700; }
.format-matrix dd { margin: 4px 0 0; color: var(--muted); font-size: 10px; line-height: 1.5; }
@keyframes upload-progress { from { transform: translateX(-110%); } to { transform: translateX(390%); } }

/* 专业预览工作区 */
.viewer-shell { display: grid; grid-template-rows: 48px minmax(0, 1fr) 24px; width: 100vw; height: 100vh; height: 100dvh; overflow: hidden; overscroll-behavior: none; background: var(--surface-0); }
.viewer-commandbar { display: grid; grid-template-columns: minmax(40px, 1fr) auto minmax(40px, 1fr); align-items: center; min-width: 0; padding: 0 10px; border-bottom: 1px solid var(--line); background: #171a1b; }
.viewer-nav { display: flex; min-width: 0; align-items: center; }
.viewer-toolbar { display: flex; align-items: center; justify-content: center; gap: 4px; }
.viewer-actions { display: flex; min-width: 0; align-items: center; justify-content: flex-end; }
.mobile-only { display: none !important; }
.icon-command, .text-command { display: inline-grid; height: 30px; place-items: center; border: 1px solid transparent; border-radius: 4px; background: transparent; color: var(--text-soft); text-decoration: none; cursor: pointer; }
.icon-command { width: 30px; padding: 0; font-size: 18px; }
.text-command { padding: 0 10px; font-size: 11px; }
.icon-command:hover, .text-command:hover { border-color: var(--line-strong); background: var(--surface-3); color: var(--text); }
.icon-command.subtle { color: var(--muted); }
.zoom-value { width: 50px; color: var(--text-soft); text-align: center; font-variant-numeric: tabular-nums; font-size: 11px; }
.command-divider { width: 1px; height: 18px; margin: 0 4px; background: var(--line); }
.viewer-workspace { position: relative; display: grid; grid-template-columns: 230px minmax(0, 1fr); min-height: 0; }
.viewer-workspace.properties-open { grid-template-columns: 230px minmax(0, 1fr) 250px; }
.viewer-workspace.layers-collapsed { grid-template-columns: minmax(0, 1fr); }
.viewer-workspace.layers-collapsed.properties-open { grid-template-columns: minmax(0, 1fr) 250px; }
.viewer-workspace.layers-collapsed .layer-panel { display: none; }
.viewer-panel { min-width: 0; overflow: hidden; background: var(--surface-1); }
.layer-panel { display: grid; grid-template-rows: auto auto auto minmax(0, 1fr); border-right: 1px solid var(--line); }
.property-panel { min-height: 0; overflow-y: auto; border-left: 1px solid var(--line); }
.icon-command.is-active { border-color: var(--accent-strong); background: var(--surface-3); color: var(--accent); }
.panel-heading { display: flex; min-height: 50px; align-items: center; justify-content: space-between; padding: 9px 12px; border-bottom: 1px solid var(--line); }
.panel-heading strong, .panel-heading small { display: block; }
.panel-heading strong { font-size: 12px; }
.panel-heading small { margin-top: 2px; color: var(--muted); font-size: 10px; }
.panel-heading-actions { display: flex; align-items: center; gap: 2px; }
.layer-actions { display: flex; gap: 12px; padding: 8px 10px 4px; }
.layer-search { display: block; padding: 6px 10px 8px; }
.layer-search input { width: 100%; height: 30px; padding: 0 9px; border: 1px solid var(--line); border-radius: 4px; outline: none; background: #0f1212; color: var(--text); font-size: 11px; }
.layer-search input:focus { border-color: var(--accent-strong); }
.cad-layers { min-height: 0; overflow-y: auto; padding: 2px 6px 10px; }
.cad-layer-row { display: grid; grid-template-columns: 18px 10px minmax(0, 1fr); align-items: center; min-height: 29px; padding: 0 5px; border-radius: 3px; color: var(--text-soft); font-size: 11px; cursor: pointer; }
.cad-layer-row:hover { background: var(--surface-3); }
.cad-layer-row input { margin: 0; accent-color: var(--accent); }
.cad-layer-row > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cad-layer-swatch { width: 8px; height: 8px; border: 1px solid rgba(255,255,255,.38); }
.empty-state, .property-empty { padding: 16px 12px; color: var(--muted); font-size: 11px; }
.property-grid { margin: 0; }
.property-grid > div { display: grid; grid-template-columns: 74px minmax(0, 1fr); gap: 8px; padding: 8px 12px; border-bottom: 1px solid #252a2b; }
.property-grid dt { color: var(--muted); font-size: 10px; font-weight: 400; }
.property-grid dd { min-width: 0; margin: 0; overflow-wrap: anywhere; color: var(--text-soft); font-size: 11px; font-variant-numeric: tabular-nums; }
.cad-main { display: flex; min-width: 0; min-height: 0; background: #000; }
.cad-canvas-wrap { position: relative; flex: 1; min-width: 0; min-height: 0; overflow: hidden; overscroll-behavior: none; touch-action: none; }
#cad-canvas { display: block; width: 100%; height: 100%; cursor: crosshair; touch-action: none; -webkit-user-select: none; user-select: none; transform-origin: 0 0; will-change: transform; }
#cad-canvas.is-dragging { cursor: grabbing; }
.cad-empty, .cad-loading { position: absolute; pointer-events: none; }
.cad-empty { inset: 0; display: grid; place-content: center; justify-items: center; gap: 8px; background: #080909; color: var(--muted); text-align: center; }
.cad-empty strong { color: var(--text); font-size: 16px; }
.cad-empty p { margin: 0; font-size: 12px; }
.cad-empty a { pointer-events: auto; color: var(--accent); font-size: 12px; }
.cad-loading { top: 12px; right: 12px; display: flex; align-items: center; gap: 7px; padding: 6px 9px; border: 1px solid var(--line); border-radius: 4px; background: rgba(21, 24, 25, .92); color: var(--text-soft); font-size: 10px; }
.cad-loading span { width: 7px; height: 7px; border-radius: 50%; background: var(--warning); animation: loading-pulse 1s ease-in-out infinite; }
@keyframes loading-pulse { 50% { opacity: .25; } }
.viewer-statusbar { display: flex; align-items: center; gap: 18px; min-width: 0; padding: 0 10px; border-top: 1px solid var(--line); background: #171a1b; color: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.statusbar-spacer { flex: 1; }

@media (max-width: 980px) {
  .viewer-workspace { grid-template-columns: 210px minmax(0, 1fr); }
  .viewer-workspace.layers-collapsed { grid-template-columns: minmax(0, 1fr); }
  .viewer-workspace.layers-collapsed.properties-open { grid-template-columns: minmax(0, 1fr); }
  .viewer-workspace.properties-open { grid-template-columns: 210px minmax(0, 1fr); }
  .viewer-workspace.properties-open .property-panel { position: absolute; z-index: 5; top: 0; right: 0; bottom: 0; display: block; width: min(280px, calc(100vw - 32px)); box-shadow: -12px 0 24px rgba(0,0,0,.28); }
  .viewer-commandbar { grid-template-columns: minmax(40px, 1fr) auto minmax(40px, 1fr); }
  .viewer-toolbar { justify-content: center; }
}

@media (max-width: 700px), (max-height: 500px) and (pointer: coarse) {
  .upload-header { width: calc(100% - 28px); }
  .upload-main { place-items: start center; padding-top: 30px; }
  .upload-heading h1 { font-size: 25px; }
  .upload-form { padding: 12px; }
  .upload-dropzone { min-height: 190px; }
  .format-matrix { grid-template-columns: 1fr; }
  .format-matrix > div { border-right: 0; border-bottom: 1px solid var(--line); }
  .format-matrix > div:last-child { border-bottom: 0; }
  .viewer-shell { grid-template-rows: 48px minmax(0, 1fr) 24px; }
  .viewer-commandbar { grid-template-columns: minmax(40px, 1fr) auto minmax(40px, 1fr); padding: 0 max(6px, env(safe-area-inset-right)) 0 max(6px, env(safe-area-inset-left)); }
  .viewer-commandbar .icon-command { width: 36px; height: 36px; }
  .viewer-toolbar .mobile-only, .panel-heading .mobile-only { display: inline-grid !important; }
  .viewer-toolbar .zoom-value, .viewer-toolbar .command-divider, .viewer-toolbar .text-command { display: none; }
  .viewer-workspace { grid-template-columns: minmax(0, 1fr); }
  .viewer-workspace.properties-open { grid-template-columns: minmax(0, 1fr); }
  .layer-panel { display: none; }
  .viewer-workspace.layers-open .layer-panel { position: absolute; z-index: 6; top: 0; bottom: 0; left: 0; display: grid; width: min(280px, calc(100vw - 32px)); box-shadow: 12px 0 24px rgba(0,0,0,.32); }
  .viewer-statusbar { gap: 10px; padding-right: max(10px, env(safe-area-inset-right)); padding-left: max(10px, env(safe-area-inset-left)); }
  #cad-coordinates { display: none; }
}
