:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #cbd5e1;
  --text: #0f172a;
  --muted: #475569;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --accent: #059669;
  --accent-hover: #047857;
  --warn-bg: #fffbeb;
  --warn-border: #f59e0b;
  --warn-text: #92400e;
  --err-bg: #fef2f2;
  --err-border: #ef4444;
  --err-text: #991b1b;
  --info-bg: #eff6ff;
  --info-border: #60a5fa;
  --info-text: #1e40af;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  background: #0f172a;
  color: #f8fafc;
  padding: 10px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  border-bottom: 1px solid #1e293b;
  flex-shrink: 0;
}

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

.brand h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.brand .subtitle {
  margin: 2px 0 0;
  font-size: 12px;
  color: #94a3b8;
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.divider {
  width: 1px;
  height: 24px;
  background: #334155;
}

.btn-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.btn {
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 7px 12px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
  font-family: inherit;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-ghost {
  background: #1e293b;
  color: #cbd5e1;
  border-color: #334155;
}

.btn-ghost:hover {
  background: #334155;
  color: #ffffff;
}

.btn-ghost.active {
  background: #3b82f6;
  color: #ffffff;
  border-color: #60a5fa;
}

.btn-tab {
  background: #1e293b;
  color: #cbd5e1;
  border-color: #334155;
}

.btn-tab.active {
  background: #f8fafc;
  color: #0f172a;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-accent {
  background: var(--accent);
  color: #ffffff;
}

.btn-accent:hover {
  background: var(--accent-hover);
}

.topbar .btn-outline {
  background: transparent;
  color: #e2e8f0;
  border-color: #475569;
}

.topbar .btn-outline:hover {
  background: #1e293b;
}

.btn-outline {
  background: #ffffff;
  color: var(--text);
  border-color: var(--border);
}

.btn-outline:hover {
  background: #f1f5f9;
}

.workspace {
  flex: 1;
  min-height: 0;
  display: flex;
}

.sidebar {
  width: 344px;
  flex-shrink: 0;
  overflow-y: auto;
  padding: 12px;
  background: var(--bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.panel-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.panel-title {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text);
  padding-bottom: 6px;
  border-bottom: 1px solid #e2e8f0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field label {
  font-size: 12.5px;
  font-weight: 600;
  color: #334155;
}

.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

input[type="number"], input[type="text"], select {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 12.5px;
  color: var(--text);
  background: #ffffff;
  font-family: inherit;
}

.field-row input[type="number"] {
  width: 78px;
  text-align: right;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
  cursor: pointer;
}

.metrics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.metric-box {
  background: var(--surface-alt);
  border: 1px solid #e2e8f0;
  border-radius: 7px;
  padding: 7px 9px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.metric-label {
  font-size: 11px;
  color: var(--muted);
}

.metric-value {
  font-size: 14px;
  color: var(--primary);
}

.hint {
  margin: 0;
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.4;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: #1e293b;
  cursor: pointer;
}

.checkbox-row input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--primary);
}

.sub-field {
  margin-left: 16px;
  padding-left: 10px;
  border-left: 2px solid #e2e8f0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.size-preset-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.size-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 4px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-alt);
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}

.size-btn:hover {
  background: #eff6ff;
  border-color: #93c5fd;
}

.size-btn.active {
  background: #eff6ff;
  border-color: var(--primary);
  color: var(--primary);
}

.size-btn-name {
  font-size: 12.5px;
  font-weight: 700;
}

.size-btn-dim {
  font-size: 10.5px;
  color: var(--muted);
}

.size-btn.active .size-btn-dim {
  color: var(--primary);
}

.stage {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #e2e8f0;
}

.alerts-bar {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 12px 0;
}

.alert {
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid transparent;
  line-height: 1.4;
}

.alert-info {
  background: var(--info-bg);
  border-color: var(--info-border);
  color: var(--info-text);
}

.alert-warn {
  background: var(--warn-bg);
  border-color: var(--warn-border);
  color: var(--warn-text);
}

.alert-error {
  background: var(--err-bg);
  border-color: var(--err-border);
  color: var(--err-text);
  font-weight: 600;
}

.canvas-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
}

.legend {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 12px;
  color: #334155;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.dot-blue { background: #2563EB; }
.dot-red { background: #DC2626; }
.dot-black { background: #1E293B; }

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.canvas-wrap {
  flex: 1;
  min-height: 0;
  margin: 0 12px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  position: relative;
}

#previewSvg {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  user-select: none;
}

#previewSvg:active {
  cursor: grabbing;
}

.viewer3d-canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  touch-action: none;
}

.viewer3d-canvas:active {
  cursor: grabbing;
}

.hint-3d {
  font-size: 12px;
  color: #475569;
  font-weight: 500;
}

.viewer3d-bar {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.08);
}

.v3d-group {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.v3d-explode {
  gap: 6px;
}

.v3d-explode label {
  font-size: 11.5px;
  font-weight: 600;
  color: #334155;
  white-space: nowrap;
}

.v3d-explode input[type="range"] {
  width: 92px;
}

.btn-xs {
  padding: 4px 8px;
  font-size: 11.5px;
  border-radius: 6px;
}

.btn-xs.active {
  background: #eff6ff;
  border-color: var(--primary);
  color: var(--primary);
}

.fit-test-panel {
  position: absolute;
  top: 12px;
  left: 12px;
  width: 318px;
  max-width: calc(100% - 24px);
  background: rgba(255, 255, 255, 0.93);
  backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.08);
  font-size: 11.5px;
  z-index: 4;
  overflow: hidden;
}

.fit-test-panel.collapsed .fit-test-body {
  display: none;
}

.fit-test-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  background: rgba(248, 250, 252, 0.85);
}

.fit-head-btns {
  flex-wrap: nowrap;
  flex-shrink: 0;
}

.fit-test-panel.collapsed .fit-test-head {
  border-bottom: none;
}

.fit-badge {
  font-weight: 700;
  font-size: 11.5px;
  padding: 2px 7px;
  border-radius: 999px;
  white-space: nowrap;
}

.fit-badge-pass { background: #dcfce7; color: #166534; }
.fit-badge-warn { background: #fef3c7; color: #92400e; }
.fit-badge-fail { background: #fee2e2; color: #991b1b; }

.fit-test-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 10px;
  max-height: 290px;
  overflow-y: auto;
}

.fit-row {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  line-height: 1.35;
}

.fit-icon {
  flex: 0 0 16px;
  height: 16px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  margin-top: 1px;
}

.fit-icon-pass { background: #dcfce7; color: #15803d; }
.fit-icon-warn { background: #fef3c7; color: #b45309; }
.fit-icon-fail { background: #fee2e2; color: #b91c1c; }

.fit-row-text {
  min-width: 0;
  flex: 1;
}

.fit-row-title {
  font-weight: 600;
  color: #1e293b;
}

.fit-row-detail {
  color: #475569;
  font-size: 11px;
}

[hidden] {
  display: none !important;
}

.statusbar {
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  font-size: 12px;
  color: #334155;
  background: var(--surface);
  border-top: 1px solid var(--border);
  margin-top: 8px;
}

.status-ok { color: #059669; }
.status-err { color: #dc2626; }

@media (max-width: 960px) {
  body { overflow: auto; height: auto; }
  .workspace { flex-direction: column; }
  .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
  .canvas-wrap { min-height: 480px; }
}
