:root {
  --primary: #6A2C91;
  --primary-hover: #58247a;
  --primary-light: #f3e8ff;
  --primary-focus: rgba(106, 44, 145, 0.25);
  
  --success: #238844;
  --success-hover: #1b6d36;
  --success-light: #ecfdf5;
  --success-glow: rgba(35, 136, 68, 0.3);

  --danger: #dc2626;
  --danger-light: #fef2f2;

  --bg-main: #f8fafc;
  --card-bg: #ffffff;
  --border-color: #e2e8f0;
  --border-focus: #a855f7;

  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-subtle: #94a3b8;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
  --shadow-glow: 0 0 20px rgba(106, 44, 145, 0.15);
}

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

body {
  font-family: 'Assistant', 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  position: relative;
  display: flex;
  flex-direction: column;
}

/* Background Ambient Glow */
.app-background {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 380px;
  background: radial-gradient(circle at 50% -20%, rgba(106, 44, 145, 0.15), transparent 70%);
  pointer-events: none;
  z-index: 0;
}

.container {
  max-width: 680px;
  width: 100%;
  margin: 0 auto;
  padding: 2.5rem 1.25rem 3rem;
  position: relative;
  z-index: 1;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border-color);
}

.brand {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.brand-logo {
  width: 48px;
  height: 48px;
  object-fit: contain;
  border-radius: var(--radius-sm);
}

.brand-title {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--primary);
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.brand-subtitle {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.header-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: white;
  border: 1px solid var(--border-color);
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-full);
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
  box-shadow: var(--shadow-sm);
}

.badge-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--success);
  box-shadow: 0 0 0 2px var(--success-light);
}

/* Main Card */
.card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-lg), var(--shadow-glow);
  padding: 2rem;
  backdrop-filter: blur(10px);
}

.section {
  margin-bottom: 1.75rem;
}

.section-header {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 0.875rem;
}

.step-number {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background-color: var(--primary-light);
  color: var(--primary);
  font-size: 0.8125rem;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 2px;
}

.section-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.3;
}

.section-description {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* Template Selector */
.template-selector-container {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.select-wrapper {
  position: relative;
  flex: 1;
}

.select-icon {
  position: absolute;
  left: 0.875rem;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--text-muted);
  pointer-events: none;
}

.form-select {
  width: 100%;
  padding: 0.75rem 2.5rem 0.75rem 2.75rem;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-main);
  background-color: white;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2364748b' stroke-width='2'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.875rem center;
  background-size: 16px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.form-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-focus);
}

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: white;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-icon:hover {
  color: var(--primary);
  border-color: var(--primary);
  background-color: var(--primary-light);
}

.btn-icon svg {
  width: 18px;
  height: 18px;
}

.helper-text {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.4rem;
  padding-left: 0.25rem;
}

/* File Dropzone */
.dropzone {
  border: 2px dashed var(--border-color);
  border-radius: var(--radius-md);
  background-color: #fafbfd;
  padding: 2rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.25s ease;
  outline: none;
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--primary);
  background-color: var(--primary-light);
}

.dropzone.dragover {
  transform: scale(1.01);
}

.upload-icon-wrapper {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background-color: white;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  margin-bottom: 0.875rem;
}

.upload-icon {
  width: 24px;
  height: 24px;
  color: var(--primary);
}

.dropzone-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-main);
  margin-bottom: 0.25rem;
}

.dropzone-hint {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* File Selected Card */
.file-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: white;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.875rem 1rem;
  box-shadow: var(--shadow-sm);
  text-align: left;
}

.file-card-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  overflow: hidden;
}

.file-icon-box {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  background-color: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.file-icon-box svg {
  width: 20px;
  height: 20px;
}

.file-details {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.file-name {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 280px;
}

.file-size {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.file-card-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-subtle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: transparent;
  border: 1px solid var(--border-color);
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
}

.btn-subtle svg {
  width: 14px;
  height: 14px;
}

.btn-subtle:hover {
  background-color: var(--bg-main);
  color: var(--text-main);
  border-color: #cbd5e1;
}

.btn-subtle.danger:hover {
  background-color: var(--danger-light);
  color: var(--danger);
  border-color: #fca5a5;
}

/* Document Title Field */
.title-field-group {
  margin-top: 1.25rem;
  text-align: left;
}

.field-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 0.45rem;
}

.badge-subtle {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-muted);
  background-color: #f1f5f9;
  border: 1px solid var(--border-color);
  padding: 0.1rem 0.45rem;
  border-radius: var(--radius-sm);
  letter-spacing: 0.02em;
}

.badge-subtle.auto {
  color: var(--primary);
  background-color: var(--primary-light);
  border-color: #e9d5ff;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.input-icon {
  position: absolute;
  left: 0.875rem;
  width: 18px;
  height: 18px;
  color: var(--text-muted);
  pointer-events: none;
}

.form-input {
  width: 100%;
  padding: 0.75rem 1rem 0.75rem 2.75rem;
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--text-main);
  background-color: white;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  box-sizing: border-box;
  transition: all 0.2s ease;
}

.form-input::placeholder {
  color: var(--text-subtle);
  font-weight: 400;
}

.form-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-focus);
}

.field-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.4rem;
  padding-left: 0.25rem;
}

/* Preview Panel */
.preview-panel {
  margin-top: 0.875rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background-color: #1e1e2e;
  color: #e2e8f0;
  overflow: hidden;
}

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.875rem;
  background-color: #181825;
  border-bottom: 1px solid #313244;
  font-size: 0.75rem;
  font-weight: 600;
  color: #a6adc8;
}

.close-btn {
  background: none;
  border: none;
  color: #a6adc8;
  font-size: 1.1rem;
  cursor: pointer;
  line-height: 1;
}

.close-btn:hover {
  color: white;
}

.preview-content {
  padding: 0.875rem;
  font-family: 'JetBrains Mono', Consolas, monospace;
  font-size: 0.8125rem;
  line-height: 1.5;
  max-height: 200px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Action Section & The Main Button */
.action-section {
  margin-top: 2rem;
  margin-bottom: 0;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  width: 100%;
  padding: 0.95rem 1.75rem;
  font-size: 1.05rem;
  font-weight: 700;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  text-decoration: none;
}

.btn-icon-wrapper svg {
  width: 20px;
  height: 20px;
  vertical-align: middle;
}

/* Primary Process State */
.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, #7e22ce 100%);
  color: white;
  box-shadow: 0 4px 12px rgba(106, 44, 145, 0.35);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--primary-hover) 0%, #6b21a8 100%);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(106, 44, 145, 0.45);
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

/* Transformed Download State */
.btn-download {
  background: linear-gradient(135deg, var(--success) 0%, #15803d 100%) !important;
  color: white !important;
  box-shadow: 0 4px 14px var(--success-glow) !important;
  animation: pulse-download 1.8s infinite;
}

.btn-download:hover {
  background: linear-gradient(135deg, var(--success-hover) 0%, #166534 100%) !important;
  transform: translateY(-2px) !important;
  box-shadow: 0 8px 20px var(--success-glow) !important;
}

@keyframes pulse-download {
  0% {
    box-shadow: 0 0 0 0 rgba(35, 136, 68, 0.5);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(35, 136, 68, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(35, 136, 68, 0);
  }
}

/* Secondary Button */
.btn-secondary {
  background-color: white;
  border: 1.5px solid var(--border-color);
  color: var(--text-main);
  font-size: 0.9rem;
  padding: 0.75rem 1.25rem;
}

.btn-secondary:hover {
  background-color: var(--bg-main);
  border-color: #cbd5e1;
}

.btn-secondary svg {
  width: 16px;
  height: 16px;
}

/* Status Box */
.status-box {
  background-color: #fafbfd;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  animation: fadeIn 0.3s ease-out;
}

.status-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: var(--primary);
  animation: pulse-dot 1.2s infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}

.status-label {
  font-weight: 700;
  font-size: 0.875rem;
  color: var(--primary);
}

.status-timer {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* Progress bar */
.progress-bar-container {
  height: 6px;
  background-color: #e2e8f0;
  border-radius: var(--radius-full);
  overflow: hidden;
  margin-bottom: 0.875rem;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary) 0%, #a855f7 100%);
  border-radius: var(--radius-full);
  width: 100%;
}

.progress-bar.indeterminate {
  width: 40%;
  animation: shimmer 1.6s infinite ease-in-out;
}

@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(350%); }
}

.status-detail {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

/* Workflow steps */
.workflow-steps {
  display: flex;
  gap: 0.75rem;
  border-top: 1px solid var(--border-color);
  padding-top: 0.875rem;
}

.wf-step {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  color: var(--text-subtle);
  flex: 1;
}

.wf-step.active {
  color: var(--primary);
  font-weight: 600;
}

.wf-step.done {
  color: var(--success);
  font-weight: 600;
}

.wf-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: currentColor;
}

.wf-check {
  font-size: 0.8rem;
  font-weight: bold;
}

/* Success Actions */
.success-actions {
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
  animation: fadeIn 0.3s ease-out;
}

.success-banner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background-color: var(--success-light);
  border: 1px solid #bbf7d0;
  border-radius: var(--radius-md);
  padding: 0.875rem 1rem;
  color: var(--success-hover);
  font-size: 0.875rem;
  font-weight: 600;
}

.success-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: var(--success);
}

.secondary-btn-group {
  display: flex;
  gap: 0.75rem;
}

.secondary-btn-group .btn {
  flex: 1;
}

/* Error Box */
.error-box {
  background-color: var(--danger-light);
  border: 1px solid #fecaca;
  border-radius: var(--radius-md);
  padding: 1rem;
  color: #991b1b;
  animation: fadeIn 0.3s ease-out;
}

.error-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  margin-bottom: 0.25rem;
}

.error-icon {
  width: 18px;
  height: 18px;
  color: var(--danger);
  flex-shrink: 0;
}

.error-message {
  font-size: 0.8125rem;
  line-height: 1.4;
  word-break: break-word;
}

/* Footer */
.footer {
  text-align: center;
  margin-top: 2rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.footer strong {
  color: var(--text-main);
}

/* Animation utilities */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.spin {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* Responsive tweaks */
@media (max-width: 600px) {
  .container {
    padding: 1.5rem 1rem;
  }

  .card {
    padding: 1.25rem;
  }

  .header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .header-badge {
    align-self: flex-start;
  }

  .secondary-btn-group {
    flex-direction: column;
  }

  .workflow-steps {
    flex-direction: column;
    gap: 0.4rem;
  }
}
