* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: #f0f2f5;
  color: #1a1a1a;
  min-height: 100vh;
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1rem 4rem;
}

/* Header */
header {
  text-align: center;
  margin-bottom: 2rem;
}
header h1 { font-size: 2rem; font-weight: 700; margin-bottom: 0.4rem; }
header p  { color: #666; font-size: 1rem; }
header a  { color: #6366f1; text-decoration: none; }

/* Config */
.config {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.5rem;
  background: #fff;
  padding: 1.25rem;
  border-radius: 12px;
  border: 1px solid #e0e0e0;
}
@media (max-width: 600px) { .config { grid-template-columns: 1fr; } }

.field label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: #555;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.field input[type="password"],
.field input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 0.9rem;
  background: #fafafa;
  transition: border-color 0.2s;
}
.field input:focus {
  outline: none; border-color: #6366f1; background: #fff;
}
.field small {
  display: block;
  font-size: 0.75rem;
  color: #999;
  margin-top: 5px;
}
.field small a { color: #6366f1; }

.slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.slider-row input[type="range"] {
  flex: 1;
  accent-color: #6366f1;
}
.slider-val {
  font-size: 0.9rem;
  font-weight: 600;
  color: #6366f1;
  min-width: 28px;
  text-align: right;
}

/* Upload Zone */
.upload-zone {
  border: 2px dashed #ccc;
  border-radius: 12px;
  padding: 2.5rem;
  text-align: center;
  cursor: pointer;
  background: #fff;
  position: relative;
  transition: border-color 0.2s, background 0.2s;
  margin-bottom: 1rem;
}
.upload-zone:hover, .upload-zone.drag-over {
  border-color: #6366f1; background: #f0f0ff;
}
.upload-zone input {
  position: absolute; inset: 0; opacity: 0;
  cursor: pointer; width: 100%; height: 100%;
}
.upload-zone .icon { font-size: 2.5rem; display: block; margin-bottom: 0.75rem; }
.upload-zone p { font-size: 1rem; color: #444; margin-bottom: 0.25rem; }
.upload-zone small { font-size: 0.8rem; color: #999; }

/* Preview */
.preview-wrap {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: flex-start;
  gap: 1rem;
}
.preview-wrap img {
  max-height: 160px;
  max-width: 280px;
  border-radius: 8px;
  object-fit: contain;
  border: 1px solid #eee;
}
.preview-info {
  font-size: 0.85rem;
  color: #555;
  line-height: 1.7;
}
.preview-info strong { color: #1a1a1a; }

/* Actions */
.actions {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.actions button {
  padding: 12px 20px;
  border-radius: 10px;
  border: none;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
}
.actions button:active { transform: scale(0.98); }

#runBtn {
  flex: 1;
  background: #6366f1;
  color: #fff;
}
#runBtn:disabled { background: #c7c7ef; cursor: not-allowed; }

#downloadAllBtn {
  background: #059669;
  color: #fff;
  white-space: nowrap;
}
#downloadAllBtn:disabled { background: #a7d7c5; cursor: not-allowed; }

#resetBtn {
  background: #fff;
  color: #444;
  border: 1px solid #ddd !important;
  border: none;
}
#resetBtn:hover { background: #f5f5f5; }

/* Progress */
.progress-wrap {
  background: #e5e7eb;
  border-radius: 99px;
  height: 6px;
  margin-bottom: 1rem;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #6366f1, #8b5cf6);
  border-radius: 99px;
  width: 0%;
  transition: width 0.4s ease;
}

/* Log */
.log-box {
  background: #1a1a2e;
  color: #a0f0a0;
  border-radius: 10px;
  padding: 1rem 1.25rem;
  font-family: 'Courier New', monospace;
  font-size: 0.82rem;
  min-height: 60px;
  max-height: 220px;
  overflow-y: auto;
  margin-bottom: 1.5rem;
}
.log-box .line { padding: 2px 0; line-height: 1.5; }
.log-box .line.ok   { color: #6ee46e; }
.log-box .line.err  { color: #f87171; }
.log-box .line.info { color: #93c5fd; }
.log-box .line.warn { color: #fbbf24; }

/* Results */
.results-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid #e0e0e0;
}
.section-title {
  font-size: 1.1rem;
  font-weight: 700;
}
.layer-count {
  font-size: 0.8rem;
  background: #ede9fe;
  color: #6d28d9;
  padding: 3px 10px;
  border-radius: 20px;
  font-weight: 600;
}

.layers-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.25rem;
}
@media (max-width: 600px) { .layers-grid { grid-template-columns: 1fr; } }

/* Layer Card */
.layer-card {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  transition: box-shadow 0.2s;
}
.layer-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.1); }

.layer-card .card-header {
  padding: 12px 16px;
  border-bottom: 1px solid #eee;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.layer-card .card-header .name {
  font-weight: 600;
  font-size: 0.9rem;
  flex: 1;
}
.layer-card .card-header .badge {
  font-size: 0.7rem;
  padding: 3px 8px;
  border-radius: 20px;
  font-weight: 600;
}

/* Checkerboard background for transparency */
.canvas-wrap {
  background-image:
    linear-gradient(45deg, #bbb 25%, transparent 25%),
    linear-gradient(-45deg, #bbb 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #bbb 75%),
    linear-gradient(-45deg, transparent 75%, #bbb 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
  background-color: #ddd;
  min-height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  position: relative;
}

.canvas-wrap img {
  max-width: 100%;
  max-height: 240px;
  display: block;
  border-radius: 4px;
}

.canvas-wrap .loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.8rem;
  color: #666;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid #e0e0e0;
  border-top-color: #6366f1;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.card-footer {
  padding: 10px 16px;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  border-top: 1px solid #eee;
}

.btn-dl {
  padding: 7px 14px;
  border-radius: 8px;
  background: #22c55e;
  color: #fff;
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
  display: inline-block;
  transition: background 0.2s;
  border: none;
  cursor: pointer;
}
.btn-dl:hover { background: #16a34a; }

.btn-copy {
  padding: 7px 14px;
  border-radius: 8px;
  background: #f1f5f9;
  color: #334155;
  font-size: 0.82rem;
  font-weight: 600;
  border: 1px solid #ddd;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-copy:hover { background: #e2e8f0; }

/* Cost badge */
.cost-note {
  font-size: 0.75rem;
  color: #888;
  text-align: right;
  margin-top: 0.5rem;
  margin-bottom: 1rem;
}

/* Error state */
.error-card {
  background: #fef2f2;
  border: 1px solid #fca5a5;
  border-radius: 12px;
  padding: 1.25rem;
  color: #b91c1c;
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

/* Qwen AI Analysis Card */
.qwen-analysis-card {
  background: linear-gradient(135deg, #f5f3ff 0%, #edd8ff 100%);
  border: 1px solid #c084fc;
  border-radius: 12px;
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 4px 15px rgba(168, 85, 247, 0.1);
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: fadeIn 0.5s ease-out;
}

.qwen-analysis-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  color: #6b21a8;
  font-size: 1rem;
}

.qwen-analysis-body {
  font-size: 0.9rem;
  color: #581c87;
  line-height: 1.6;
  background: rgba(255, 255, 255, 0.6);
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid rgba(192, 132, 252, 0.2);
}

.qwen-analysis-params {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.qwen-param-badge {
  background: #7c3aed;
  color: #fff;
  padding: 4px 10px;
  border-radius: 99px;
  font-size: 0.8rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Disabled sliders when auto-detect is active */
.slider-disabled {
  opacity: 0.5;
  pointer-events: none;
  filter: grayscale(0.5);
  transition: opacity 0.3s ease, filter 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

