/* ========== CSS Variables ========== */
:root {
  --bg-primary: #0f0f14;
  --bg-secondary: #1a1a24;
  --bg-tertiary: #252536;
  --bg-card: #1e1e2e;
  --border-color: #2d2d42;
  --text-primary: #e8e8f0;
  --text-secondary: #8888a0;
  --text-muted: #5c5c78;
  --accent: #6c5ce7;
  --accent-hover: #7d6ff0;
  --accent-glow: rgba(108, 92, 231, 0.3);
  --success: #00d68f;
  --warning: #ffa940;
  --danger: #ff4d6a;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.6);
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ========== Reset & Base ========== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { cursor: pointer; border: none; outline: none; font-family: inherit; }
select { outline: none; font-family: inherit; }
input { outline: none; font-family: inherit; }

/* ========== App Container ========== */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 1440px;
  margin: 0 auto;
}

/* ========== Header ========== */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  height: 60px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  z-index: 100;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.5px;
}

.logo svg {
  color: var(--accent);
  filter: drop-shadow(0 0 8px var(--accent-glow));
}

.nav {
  display: flex;
  gap: 4px;
  background: var(--bg-tertiary);
  padding: 4px;
  border-radius: var(--radius-md);
}

.nav a {
  padding: 6px 18px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.nav a:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
}

.nav a.active {
  color: #fff;
  background: var(--accent);
  box-shadow: 0 2px 8px var(--accent-glow);
}

/* API Status Badge */
.api-status {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 20px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  cursor: pointer;
  transition: var(--transition);
  margin-left: 12px;
}

.api-status:hover {
  border-color: var(--accent);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: var(--transition);
}

.api-status.configured .status-dot {
  background: var(--success);
  box-shadow: 0 0 6px var(--success);
}

.status-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
}

/* ========== Main Content ========== */
.main-content {
  display: flex;
  flex: 1;
  min-height: 0;
  gap: 1px;
  background: var(--border-color);
}

/* ========== Upload Section ========== */
.upload-section {
  width: 380px;
  min-width: 380px;
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 24px;
  gap: 20px;
}

.section-title h2 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.section-title p {
  font-size: 12px;
  color: var(--text-muted);
}

/* Upload Area */
.upload-area {
  position: relative;
  border: 2px dashed var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: var(--transition);
  cursor: pointer;
  background: var(--bg-tertiary);
  min-height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.upload-area:hover {
  border-color: var(--accent);
  background: rgba(108, 92, 231, 0.05);
}

.upload-area.drag-over {
  border-color: var(--accent);
  background: rgba(108, 92, 231, 0.12);
  border-style: solid;
  transform: scale(1.01);
}

.upload-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
  padding: 32px;
  text-align: center;
}

.upload-placeholder svg {
  color: var(--text-muted);
  transition: var(--transition);
}

.upload-area:hover .upload-placeholder svg {
  color: var(--accent);
  transform: translateY(-2px);
}

.upload-placeholder p {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-secondary);
}

.upload-placeholder span {
  font-size: 12px;
  color: var(--text-muted);
}

/* Image Preview */
.image-preview {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 220px;
}

.image-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: var(--radius-lg);
  background: var(--bg-tertiary);
}

.remove-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  backdrop-filter: blur(8px);
}

.remove-btn:hover {
  background: var(--danger);
  transform: scale(1.1);
}

/* Config Status */
.config-status {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
}

.status-info {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-secondary);
}

.status-icon { font-size: 16px; }

/* Settings Panel */
.settings-panel {
  background: var(--bg-tertiary);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  border: 1px solid var(--border-color);
}

.settings-panel h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.setting-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.setting-item > label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Quality Buttons */
.quality-options {
  display: flex;
  gap: 6px;
}

.quality-btn {
  flex: 1;
  padding: 8px 4px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.quality-btn:hover {
  border-color: var(--accent);
  color: var(--text-primary);
}

.quality-btn.active {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 2px 8px var(--accent-glow);
}

.quality-badge {
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border-radius: var(--radius-sm);
  box-shadow: 0 2px 8px var(--accent-glow);
  display: inline-block;
  align-self: flex-start;
}

/* Format Select */
.setting-item select {
  padding: 10px 14px;
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' stroke='%238888a0' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

.setting-item select:hover {
  border-color: var(--accent);
}

.setting-item select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* Range Slider */
input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  background: var(--bg-secondary);
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 2px 8px var(--accent-glow);
  transition: var(--transition);
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

.setting-item:has(input[type="range"]) {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
}

.setting-item:has(input[type="range"]) > label {
  width: 100%;
}

.setting-item:has(input[type="range"]) input[type="range"] {
  flex: 1;
  margin-right: 10px;
}

.range-value {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  min-width: 36px;
  text-align: right;
}

/* Checkbox */
.setting-checkbox {
  padding: 4px 0;
}

.checkbox-label {
  display: flex !important;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  text-transform: none !important;
  letter-spacing: 0 !important;
  font-size: 13px !important;
  color: var(--text-secondary) !important;
}

.checkbox-label input[type="checkbox"] {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  min-width: 18px;
  border: 2px solid var(--border-color);
  border-radius: 4px;
  background: var(--bg-secondary);
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  flex-shrink: 0;
}

.checkbox-label input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.checkbox-label input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 3px;
  top: 1px;
  width: 5px;
  height: 9px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* Convert Hint */
.convert-hint {
  font-size: 12px;
  color: var(--warning);
  text-align: center;
  line-height: 1.5;
}

.convert-hint.ready {
  color: var(--text-muted);
}

/* Convert Button */
.convert-btn {
  width: 100%;
  padding: 14px;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border-radius: var(--radius-md);
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 4px 16px var(--accent-glow);
}

.convert-btn:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 6px 24px var(--accent-glow);
}

.convert-btn:active:not(:disabled) {
  transform: translateY(0);
}

.convert-btn:disabled {
  background: var(--bg-tertiary);
  color: var(--text-muted);
  cursor: not-allowed;
  box-shadow: none;
  border: 1px solid var(--border-color);
}

/* Spinner */
.spinner {
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ========== Preview Section ========== */
.preview-section {
  flex: 1;
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.preview-section .section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.preview-actions {
  display: flex;
  gap: 6px;
}

.preview-actions button {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  transition: var(--transition);
  border: 1px solid var(--border-color);
}

.preview-actions button:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(108, 92, 231, 0.1);
}

/* Canvas Container */
.canvas-container {
  flex: 1;
  position: relative;
  background: var(--bg-primary);
  overflow: hidden;
}

.canvas-container canvas {
  display: block;
}

/* Empty State */
.empty-state {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  color: var(--text-muted);
  pointer-events: none;
  text-align: center;
}

.empty-state p {
  font-size: 14px;
  color: var(--text-muted);
}

/* Model Info */
.model-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 24px;
  background: var(--bg-tertiary);
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
}

.info-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 14px;
  border-right: 1px solid var(--border-color);
}

.info-item:first-child { padding-left: 0; }
.info-item:last-of-type { border-right: none; }

.info-item span {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.info-item strong {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.download-btn {
  margin-left: auto;
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: var(--success);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 6px;
  transition: var(--transition);
}

.download-btn:hover {
  filter: brightness(1.15);
  transform: translateY(-1px);
}

.upload-btn {
  margin-left: 6px;
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 6px;
  transition: var(--transition);
  box-shadow: 0 2px 8px var(--accent-glow);
}

.upload-btn:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px var(--accent-glow);
}

/* ========== Scrollbar ========== */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ========== Progress Overlay (on canvas) ========== */
.progress-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(15, 15, 20, 0.85);
  z-index: 10;
  backdrop-filter: blur(4px);
}

.progress-overlay[hidden] {
  display: none;
}

.progress-bar {
  width: 240px;
  height: 4px;
  background: var(--bg-tertiary);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s ease;
  box-shadow: 0 0 12px var(--accent-glow);
}

.progress-text {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
}

.progress-icon {
  font-size: 32px;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(1.1); }
}

/* Preview action active state */
.preview-actions button.active {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(108, 92, 231, 0.2);
}

/* ========== Tooltip ========== */
[title] {
  position: relative;
}

/* ========== Modal ========== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(8px);
  animation: fadeIn 0.2s ease;
}

.modal-overlay[hidden] {
  display: none;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  width: 440px;
  max-width: 90vw;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.25s ease;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
  font-size: 17px;
  font-weight: 600;
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.modal-close:hover {
  background: var(--danger);
  color: #fff;
}

.modal-body {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.modal-desc {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.6;
}

.modal-link {
  color: var(--accent);
  text-decoration: underline;
  transition: var(--transition);
}

.modal-link:hover {
  color: var(--accent-hover);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group > label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-group input[type="text"],
.form-group input[type="password"] {
  padding: 10px 14px;
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.form-group input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.btn-primary {
  flex: 1;
  padding: 11px 20px;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  transition: var(--transition);
  box-shadow: 0 2px 8px var(--accent-glow);
}

.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  padding: 11px 18px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.btn-secondary:hover {
  color: var(--text-primary);
  border-color: var(--accent);
}

.modal-status {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  text-align: center;
}

.modal-status.success {
  background: rgba(0, 214, 143, 0.1);
  color: var(--success);
  border: 1px solid rgba(0, 214, 143, 0.2);
}

.modal-status.error {
  background: rgba(255, 77, 106, 0.1);
  color: var(--danger);
  border: 1px solid rgba(255, 77, 106, 0.2);
}

/* ========== Responsive ========== */
@media (max-width: 768px) {
  .main-content {
    flex-direction: column;
  }

  .upload-section {
    width: 100%;
    min-width: 100%;
    max-height: 50vh;
  }

  .preview-section {
    min-height: 400px;
  }

  .header {
    padding: 0 16px;
  }

  .nav a {
    padding: 6px 12px;
    font-size: 13px;
  }
}
