/* ── Reset & Base ── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --text: #1a1a2e;
  --text-muted: #6b7280;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --success: #10b981;
  --error: #ef4444;
  --warning: #f59e0b;
  --border: #e5e7eb;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --surface: #1e293b;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #334155;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.3);
  }
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Layout ── */
.app {
  max-width: 640px;
  margin: 0 auto;
  padding: 24px 16px;
}

header {
  text-align: center;
  margin-bottom: 24px;
}

header h1 {
  font-size: 1.75rem;
  font-weight: 700;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-top: 4px;
}

/* ── Cards ── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

/* ── Drop Zone ── */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--primary);
  background: rgba(59, 130, 246, 0.05);
}

.upload-icon {
  width: 48px;
  height: 48px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.drop-zone p {
  color: var(--text);
  font-size: 1rem;
  font-weight: 500;
}

.drop-zone-hint {
  color: var(--text-muted) !important;
  font-size: 0.85rem !important;
  font-weight: 400 !important;
  margin-top: 4px;
}

/* ── Options ── */
.options {
  display: flex;
  gap: 16px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.option-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 140px;
}

.option-group label {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}

.option-group select,
.option-group input {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
}

/* ── File Info ── */
.file-info {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  padding: 12px;
  background: rgba(59, 130, 246, 0.08);
  border-radius: 8px;
  font-size: 0.9rem;
}

#file-name {
  font-weight: 600;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#file-size {
  color: var(--text-muted);
  white-space: nowrap;
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
}

.btn-icon:hover {
  color: var(--error);
  background: rgba(239, 68, 68, 0.1);
}

/* ── Buttons ── */
.btn-primary {
  display: block;
  width: 100%;
  padding: 14px 24px;
  margin-top: 16px;
  border: none;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
  text-align: center;
  text-decoration: none;
}

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

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-secondary {
  display: block;
  width: 100%;
  padding: 12px 24px;
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-secondary:hover {
  background: rgba(59, 130, 246, 0.05);
}

.btn-download {
  background: var(--success);
}

.btn-download:hover {
  background: #059669;
}

/* ── Pipeline Progress ── */
.pipeline {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 16px 0;
}

.pipeline-stage {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 8px;
  transition: background 0.2s;
}

.stage-indicator {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.3s, background 0.3s;
}

.pipeline-stage.pending .stage-indicator {
  border-color: var(--border);
}

.pipeline-stage.working .stage-indicator {
  border-color: var(--primary);
  background: rgba(59, 130, 246, 0.1);
  animation: pulse 1.5s ease-in-out infinite;
}

.pipeline-stage.done .stage-indicator {
  border-color: var(--success);
  background: var(--success);
}

.pipeline-stage.done .stage-indicator::after {
  content: '';
  width: 10px;
  height: 6px;
  border-left: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: rotate(-45deg) translateY(-1px);
}

.pipeline-stage.error .stage-indicator {
  border-color: var(--error);
  background: var(--error);
}

.pipeline-stage.error .stage-indicator::after {
  content: '\00d7';
  color: #fff;
  font-size: 1.2rem;
  font-weight: 700;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.4); }
  50% { box-shadow: 0 0 0 8px rgba(59, 130, 246, 0); }
}

.stage-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.stage-label {
  font-weight: 600;
  font-size: 0.95rem;
}

.stage-detail {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ── Log ── */
.log {
  margin-top: 16px;
  padding: 12px;
  background: var(--bg);
  border-radius: 8px;
  max-height: 200px;
  overflow-y: auto;
  font-family: 'SF Mono', 'Consolas', 'Monaco', monospace;
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.8;
}

.log-entry {
  padding: 1px 0;
}

.log-entry .log-time {
  color: var(--text-muted);
  opacity: 0.6;
  margin-right: 8px;
}

/* ── Complete ── */
.complete-content,
.error-content {
  text-align: center;
}

.complete-icon {
  width: 64px;
  height: 64px;
  color: var(--success);
  margin-bottom: 12px;
}

.error-icon {
  width: 64px;
  height: 64px;
  color: var(--error);
  margin-bottom: 12px;
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 16px 0;
  text-align: left;
}

.stat {
  padding: 8px 12px;
  background: var(--bg);
  border-radius: 8px;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-value {
  font-size: 1.1rem;
  font-weight: 600;
}

#error-message {
  color: var(--error);
  margin: 12px 0;
  font-size: 0.95rem;
}

/* ── Upload Progress Bar ── */
.upload-progress {
  margin-top: 16px;
}

.upload-progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.upload-progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 2px;
  transition: width 0.3s;
  width: 0%;
}

.upload-progress-text {
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 6px;
}

/* ── Responsive ── */
@media (max-width: 480px) {
  .app {
    padding: 16px 12px;
  }

  .card {
    padding: 16px;
  }

  .drop-zone {
    padding: 32px 16px;
  }

  .options {
    flex-direction: column;
  }

  .stats {
    grid-template-columns: 1fr;
  }
}
