* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --bg: #f8fafc;
  --card-bg: #ffffff;
  --text: #1e293b;
  --text-secondary: #64748b;
  --border: #e2e8f0;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

.app {
  max-width: 640px;
  margin: 0 auto;
  padding: 20px 16px;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 0;
}

.header h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--primary);
}

.header .subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* Upload Area */
.upload-area {
  background: var(--card-bg);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}

.upload-area:hover, .upload-area.dragover {
  border-color: var(--primary);
  background: #eff6ff;
}

.upload-icon {
  color: var(--primary);
  margin-bottom: 12px;
}

.upload-text {
  font-size: 16px;
  font-weight: 500;
  margin-bottom: 4px;
}

.upload-hint {
  font-size: 12px;
  color: var(--text-secondary);
}

/* Progress */
.progress-bar {
  margin-top: 16px;
  background: var(--border);
  border-radius: 8px;
  height: 32px;
  position: relative;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #60a5fa);
  border-radius: 8px;
  transition: width 0.3s;
  width: 0%;
}

.progress-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

/* Model List */
.model-list {
  margin-top: 32px;
}

.model-list h2 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 12px;
}

.empty {
  text-align: center;
  color: var(--text-secondary);
  padding: 40px 0;
}

.model-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  transition: transform 0.15s;
}

.model-card:active {
  transform: scale(0.98);
}

.model-icon {
  width: 48px;
  height: 48px;
  background: #eff6ff;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  flex-shrink: 0;
}

.model-info {
  flex: 1;
  min-width: 0;
}

.model-info h3 {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.model-info p {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.status {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  margin-top: 4px;
}

.status-ready { background: #dcfce7; color: #166534; }
.status-converting { background: #fef3c7; color: #92400e; }
.status-error { background: #fee2e2; color: #991b1b; }

.model-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

.btn-view, .btn-delete {
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-view {
  background: var(--primary);
  color: white;
}

.btn-view:hover { background: var(--primary-dark); }

.btn-delete {
  background: #fee2e2;
  color: var(--danger);
}

.btn-delete:hover { background: #fecaca; }

/* Model checkbox for merge selection */
.model-checkbox {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.model-checkbox input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--primary);
  cursor: pointer;
}

/* Merge bar */
.merge-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--primary);
  color: white;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 100;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.15);
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.merge-bar.show {
  transform: translateY(0);
}

.merge-bar span {
  font-size: 14px;
  font-weight: 500;
}

.btn-merge {
  background: white;
  color: var(--primary);
  border: none;
  border-radius: 8px;
  padding: 8px 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-merge:hover {
  background: #f0f0f0;
}

.btn-cancel-merge {
  background: rgba(255,255,255,0.2);
  color: white;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-cancel-merge:hover {
  background: rgba(255,255,255,0.3);
}

/* User bar */
.user-bar {
  display: flex;
  align-items: center;
  gap: 10px;
}
.user-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
}
.btn-logout {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}
.btn-logout:hover {
  border-color: var(--danger);
  color: var(--danger);
}

/* Share button */
.btn-share {
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  background: #e0f2fe;
  color: #0369a1;
}
.btn-share:hover { background: #bae6fd; }

/* Shared tag */
.tag-shared {
  display: inline-block;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 4px;
  background: #e0f2fe;
  color: #0369a1;
  font-weight: 400;
  margin-left: 4px;
  vertical-align: middle;
}

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.modal-card {
  background: #fff;
  border-radius: 16px;
  width: 90%;
  max-width: 400px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; }
.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text-secondary);
  cursor: pointer;
  line-height: 1;
}
.modal-body {
  padding: 16px 20px 20px;
}
.modal-body .form-group {
  margin-bottom: 16px;
}
.modal-body .form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #555;
  margin-bottom: 6px;
}
.modal-body .form-group input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
}
.modal-body .form-group input:focus {
  border-color: var(--primary);
}
.search-results {
  margin-top: 4px;
}
.search-item {
  padding: 8px 12px;
  cursor: pointer;
  border-radius: 6px;
  font-size: 14px;
  transition: background 0.1s;
}
.search-item:hover { background: #f1f5f9; }
.search-item.disabled { color: var(--text-secondary); cursor: default; }
.search-item small { color: var(--text-secondary); margin-left: 4px; }
.share-list h4 {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}
.share-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.share-empty {
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
  padding: 12px 0;
}
.btn-unshare {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 12px;
  cursor: pointer;
}

/* Version Button */
.btn-version {
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  background: #f0fdf4;
  color: #15803d;
}
.btn-version:hover { background: #dcfce7; }

/* Version Modal */
.version-modal-card {
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}
.version-modal-card .modal-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Version Timeline */
.version-timeline {
  margin-bottom: 20px;
  padding-left: 8px;
}
.version-item {
  display: flex;
  gap: 12px;
  position: relative;
  padding-bottom: 16px;
}
.version-item:not(:last-child)::before {
  content: '';
  position: absolute;
  left: 5px;
  top: 14px;
  bottom: 0;
  width: 2px;
  background: var(--border);
}
.version-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--border);
  border: 2px solid #fff;
  box-shadow: 0 0 0 2px var(--border);
  flex-shrink: 0;
  margin-top: 3px;
  z-index: 1;
}
.version-item.current .version-dot {
  background: var(--primary);
  box-shadow: 0 0 0 2px var(--primary);
}
.version-info {
  flex: 1;
  min-width: 0;
}
.version-top {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 2px;
}
.version-label-tag {
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
  background: #eff6ff;
  padding: 1px 8px;
  border-radius: 4px;
}
.version-current-tag {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 4px;
  background: #dcfce7;
  color: #166534;
  font-weight: 600;
}
.version-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.version-meta {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
}
.version-btns {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}
.btn-compare {
  border: none;
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  background: #fef3c7;
  color: #92400e;
  transition: background 0.15s;
}
.btn-compare:hover { background: #fde68a; }
.btn-view-sm {
  border: none;
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  background: #eff6ff;
  color: var(--primary);
  transition: background 0.15s;
}
.btn-view-sm:hover { background: #dbeafe; }

/* Version Actions */
.version-actions {
  border-top: 1px solid var(--border);
  padding-top: 16px;
}
.version-set-parent label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}
.version-hint {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 10px;
}
.version-set-parent select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  background: #fff;
  margin-bottom: 10px;
  appearance: auto;
}
.version-set-parent select:focus {
  border-color: var(--primary);
}
.version-label-row {
  display: flex;
  gap: 8px;
}
.version-label-row input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
}
.version-label-row input:focus {
  border-color: var(--primary);
}
.btn-set-version {
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  background: var(--primary);
  color: white;
  transition: background 0.15s;
  white-space: nowrap;
}
.btn-set-version:hover { background: var(--primary-dark); }
