*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #f0f2f5;
  --panel: #fff;
  --border: #d9dee8;
  --text: #1a2332;
  --muted: #6b7a90;
  --primary: #1a73e8;
  --primary-hover: #1557b0;
  --highlight: #e8f0fe;
  --danger: #d93025;
  --shadow: 0 8px 28px rgba(26, 35, 50, 0.12);
  --radius: 8px;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: var(--bg);
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.config-selector {
  display: flex;
  align-items: center;
  gap: 10px;
}

.config-selector label {
  font-size: 14px;
  color: var(--muted);
}

.config-selector select {
  min-width: 220px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
}

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

.layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: calc(100vh - 57px);
  gap: 0;
}

.panel {
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.panel-viewer {
  border-right: none;
}

.panel-title {
  margin: 0;
  padding: 14px 16px;
  font-size: 15px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}

.mesh-tree {
  flex: 1;
  overflow: auto;
  padding: 8px 0;
  font-size: 13px;
}

.tree-node {
  user-select: none;
}

.tree-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px 6px 8px;
  cursor: pointer;
  border-radius: 4px;
  margin: 0 6px;
}

.tree-row:hover {
  background: #f5f7fa;
}

.tree-row.selected {
  background: var(--highlight);
  color: var(--primary);
  font-weight: 500;
}

.tree-toggle {
  width: 18px;
  height: 18px;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--muted);
  font-size: 10px;
  flex-shrink: 0;
  padding: 0;
}

.tree-toggle.empty {
  visibility: hidden;
}

.tree-icon {
  width: 16px;
  color: var(--muted);
  font-size: 11px;
}

.tree-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-badge {
  font-size: 11px;
  color: var(--muted);
  background: #eef1f6;
  padding: 1px 6px;
  border-radius: 10px;
}

.tree-children {
  display: none;
}

.tree-children.expanded {
  display: block;
}

.viewer-canvas {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  touch-action: none;
}

.viewer-canvas canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
}

.viewer-toolbar {
  padding: 8px 16px;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  text-align: center;
}

.btn {
  border: none;
  border-radius: var(--radius);
  padding: 8px 16px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

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

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

.btn-outline {
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-outline:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-outline-primary {
  background: #fff;
  border: 1px solid var(--primary);
  color: var(--primary);
}

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

.btn-text {
  background: transparent;
  color: var(--muted);
  padding: 6px 10px;
}

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

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal[hidden] {
  display: none;
}

.modal-dialog {
  background: var(--panel);
  border-radius: 12px;
  box-shadow: var(--shadow);
  width: min(920px, 94vw);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-dialog-sm {
  width: min(420px, 92vw);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.modal-close {
  border: none;
  background: transparent;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  padding: 0 4px;
}

.modal-body {
  display: grid;
  grid-template-columns: 200px 1fr;
  min-height: 380px;
  overflow: hidden;
}

.modal-sidebar {
  padding: 16px;
  border-right: 1px solid var(--border);
  background: #fafbfc;
  min-width: 0;
  overflow: hidden;
}

.modal-sidebar h3 {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.mesh-info-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.mesh-info-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--highlight);
  border: 1px solid #c2d7f7;
  overflow: hidden;
}

.mesh-info-name {
  font-weight: 600;
  font-size: 14px;
  word-break: break-all;
}

.mesh-info-tag {
  font-size: 10px;
  color: var(--muted);
  word-break: break-all;
  line-height: 1.4;
  max-width: 100%;
}

.modal-main {
  padding: 16px 20px;
  overflow-y: auto;
}

.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.tab {
  border: none;
  background: transparent;
  padding: 10px 16px;
  font-size: 14px;
  cursor: pointer;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-head h4,
.upload-section h4,
.color-section h4 {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 600;
}

.image-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 24px;
  min-height: 100px;
}

.image-card {
  width: 88px;
  min-width: 0;
  text-align: center;
  cursor: pointer;
}

.image-card input {
  display: none;
}

.image-thumb {
  width: 88px;
  height: 88px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: #f5f5f5;
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-card.selected .image-thumb {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--highlight);
}

.image-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.image-card .image-caption {
  display: block;
  margin-top: 6px;
  padding: 0 2px;
  font-size: 12px;
  line-height: 1.3;
  color: var(--muted);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.drop-zone {
  width: 88px;
  height: 88px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  padding: 0;
  background: transparent;
  font: inherit;
}

.drop-zone:hover,
.drop-zone.dragover {
  border-color: var(--primary);
  background: var(--highlight);
}

.drop-zone .plus {
  font-size: 32px;
  color: var(--muted);
  line-height: 1;
}

.upload-hint {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.color-row {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
}

.color-row input[type="color"] {
  width: 56px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  padding: 2px;
}

.color-row input[type="text"] {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: monospace;
}

.color-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.color-swatch {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--border);
  cursor: pointer;
}

.color-swatch:hover {
  transform: scale(1.08);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.save-body {
  display: block;
  padding: 20px;
}

.save-body label {
  display: block;
  margin-bottom: 8px;
  font-size: 14px;
}

.save-body input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #323232;
  color: #fff;
  padding: 12px 24px;
  border-radius: var(--radius);
  font-size: 14px;
  z-index: 2000;
  box-shadow: var(--shadow);
}

.toast[hidden] {
  display: none;
}

/* Blender 级 UV 编辑器布局 */
.modal-dialog-xl {
  width: min(1280px, 98vw);
  max-height: 92vh;
}

.modal-body-blender {
  display: grid;
  grid-template-columns: 220px minmax(320px, 1fr) 260px;
  min-height: 520px;
}

.modal-body-blender .modal-sidebar {
  overflow-y: auto;
  max-height: 70vh;
}

.section-label {
  margin: 16px 0 8px;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.transform-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field-row {
  display: grid;
  grid-template-columns: 88px 1fr;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

.field-row input,
.field-row select {
  width: 100%;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 12px;
}

.field-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  margin-top: 4px;
}

.btn-block {
  width: 100%;
  margin-top: 8px;
}

.uv-editor-panel {
  display: flex;
  flex-direction: column;
  background: #1e1e1e;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  min-height: 0;
}

.uv-editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 12px;
  background: #2d2d2d;
  border-bottom: 1px solid #444;
}

.uv-editor-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.uv-editor-actions .btn-outline {
  background: #3a3a3a;
  border-color: #666;
  color: #e0e0e0;
  font-size: 11px;
  padding: 4px 8px;
}

.uv-editor-actions .btn-outline:hover {
  border-color: #4fc3f7;
  color: #4fc3f7;
}

.uv-editor-head h3 {
  margin: 0;
  font-size: 12px;
  color: #ccc;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.uv-canvas {
  flex: 1;
  width: 100%;
  min-height: 360px;
  display: block;
  cursor: grab;
}

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

.modal-body-blender .modal-main {
  overflow-y: auto;
  max-height: 70vh;
}

@media (max-width: 1100px) {
  .modal-body-blender {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
  }

  .uv-editor-panel {
    border: none;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
  }
}
