:root {
  --brand-bg: radial-gradient(circle at 15% 20%, #a7f3d0 0%, transparent 38%),
    radial-gradient(circle at 85% 10%, #bae6fd 0%, transparent 35%),
    radial-gradient(circle at 45% 85%, #fde68a 0%, transparent 32%),
    #f8fafc;
  --primary: #7c3aed;
  --primary-light: rgba(124, 58, 237, 0.08);
  --success: #22c55e;
  --success-light: rgba(34, 197, 94, 0.08);
  --warning: #f59e0b;
  --warning-light: rgba(245, 158, 11, 0.08);
  --error: #ef4444;
  --error-light: rgba(239, 68, 68, 0.08);
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --bg-card: rgba(255, 255, 255, 0.82);
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.08), 0 4px 10px rgba(0, 0, 0, 0.04);
}

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

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

.glass-panel {
  backdrop-filter: blur(8px);
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.75);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.fade-in {
  animation: fadeIn 220ms ease;
}

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

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

.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2.5px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.spinner-lg {
  width: 48px;
  height: 48px;
  border-width: 4px;
}

/* --- Header --- */
.app-header {
  padding: 1.25rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.app-header h1 { font-size: 1.5rem; font-weight: 800; }
.app-header .subtitle { font-size: 0.8rem; color: var(--text-muted); }

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 1.1rem;
  border: none;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #6d28d9; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: #16a34a; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover:not(:disabled) { background: #d97706; }
.btn-danger { background: var(--error); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #dc2626; }
.btn-outline {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text);
}
.btn-outline:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { background: rgba(0,0,0,0.04); color: var(--text); }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn-lg { padding: 0.75rem 1.5rem; font-size: 1rem; }
.btn-block { width: 100%; justify-content: center; }

/* --- Form controls --- */
.form-group { display: flex; flex-direction: column; gap: 0.35rem; }
.form-group label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.form-input, .form-select, .form-textarea {
  padding: 0.6rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  background: #fff;
  color: var(--text);
  transition: border-color 0.15s;
  outline: none;
  width: 100%;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.1);
}
.form-input::placeholder { color: #94a3b8; }
.form-textarea { resize: vertical; min-height: 80px; }
.input-row { display: flex; gap: 0.5rem; align-items: center; }
.input-row .form-input { flex: 1; }

/* --- Cards --- */
.card {
  background: var(--bg-card);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.75);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}
.card-hover:hover {
  box-shadow: var(--shadow-lg);
  border-color: rgba(124, 58, 237, 0.2);
  transform: translateY(-1px);
  transition: all 0.2s ease;
}

/* --- Badges --- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.6rem;
  border-radius: 99px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: #b45309; }
.badge-error { background: var(--error-light); color: var(--error); }
.badge-info { background: var(--primary-light); color: var(--primary); }
.badge-neutral { background: rgba(0,0,0,0.05); color: var(--text-muted); }

/* --- Stepper --- */
.stepper {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem 0;
}
.step {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  opacity: 0.5;
}
.step.active { color: var(--primary); opacity: 1; }
.step.done { color: var(--success); opacity: 0.8; }
.step-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 800;
  border: 2px solid currentColor;
  flex-shrink: 0;
}
.step.active .step-num { background: var(--primary); color: #fff; border-color: var(--primary); }
.step.done .step-num { background: var(--success); color: #fff; border-color: var(--success); }
.step-divider { flex: 1; height: 2px; background: var(--border); min-width: 20px; }

/* --- Progress bar --- */
.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #a78bfa);
  border-radius: 4px;
  transition: width 0.4s ease;
}

/* --- Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}
.modal-content {
  background: #fff;
  border-radius: 16px;
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.15);
  animation: modalIn 200ms ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.96) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1.1rem; font-weight: 700; }
.modal-body { padding: 1.5rem; }
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
}

/* --- Table --- */
.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.85rem;
}
.data-table th {
  text-align: left;
  padding: 0.6rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
}
.data-table td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: rgba(0, 0, 0, 0.015); }

/* --- Mapping table --- */
.mapping-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto auto;
  gap: 0.5rem;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}
.mapping-row:last-child { border-bottom: none; }
.mapping-row .folder-name {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.4rem 0.6rem;
  background: rgba(0, 0, 0, 0.03);
  border-radius: 6px;
}
.mapping-row .row-info {
  font-size: 0.8rem;
  color: var(--success);
  font-weight: 600;
  white-space: nowrap;
}

/* --- File list / result cards --- */
.file-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  gap: 0.75rem;
  transition: background 0.1s;
}
.file-card:hover { background: rgba(0, 0, 0, 0.02); }
.file-card .file-info { flex: 1; min-width: 0; }
.file-card .file-name { font-weight: 600; font-size: 0.875rem; }
.file-card .file-meta { font-size: 0.75rem; color: var(--text-muted); }
.file-card .file-amount { font-weight: 700; font-size: 0.95rem; white-space: nowrap; }

/* --- Collapsible section --- */
.collapsible-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.1s;
  user-select: none;
}
.collapsible-header:hover { background: rgba(0, 0, 0, 0.02); }
.collapsible-header .arrow {
  transition: transform 0.2s;
  color: var(--text-muted);
}
.collapsible-header .arrow.open { transform: rotate(90deg); }
.collapsible-body { padding: 0 1rem 0.75rem 2.25rem; }

/* --- Status indicators --- */
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.status-dot.connected { background: var(--success); }
.status-dot.disconnected { background: var(--border); }

/* --- Empty state --- */
.empty-state {
  text-align: center;
  padding: 3rem 2rem;
  color: var(--text-muted);
}
.empty-state .empty-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.3;
}
.empty-state p { margin-bottom: 1.5rem; }

/* --- Conflict modal with PDF preview --- */
.conflict-modal {
  background: #fff;
  border-radius: 16px;
  max-width: 640px;
  width: 100%;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.2);
  animation: modalIn 200ms ease;
}
.conflict-modal--with-pdf {
  max-width: calc(100vw - 2rem);
  width: 100%;
}
.conflict-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.conflict-modal__body {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}
.conflict-modal__pdf-panel {
  flex: 0 0 50%;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  overflow: hidden;
}
.conflict-modal__candidates-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}
.conflict-modal__footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.pdf-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  flex-shrink: 0;
}
.pdf-viewer {
  flex: 1;
  overflow: auto;
  background: #525252;
  min-height: 300px;
}
.pdf-viewer iframe {
  display: block;
}
@media (max-width: 900px) {
  .conflict-modal--with-pdf { max-width: 95vw; }
  .conflict-modal__body { flex-direction: column; }
  .conflict-modal__pdf-panel { flex: 0 0 40%; border-right: none; border-bottom: 1px solid var(--border); }
}

/* --- Candidate selection --- */
.candidate-option {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
}
.candidate-option:hover { border-color: rgba(124, 58, 237, 0.3); background: var(--primary-light); }
.candidate-option.selected { border-color: var(--primary); background: var(--primary-light); }
.candidate-option input[type="radio"] { margin-top: 0.15rem; accent-color: var(--primary); }
.candidate-context {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-family: 'SF Mono', 'Fira Code', monospace;
  word-break: break-word;
  line-height: 1.4;
  margin-top: 0.3rem;
  max-height: 3.5em;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --- Alert --- */
.alert {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.875rem;
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}
.alert-error { background: var(--error-light); color: var(--error); border: 1px solid rgba(239, 68, 68, 0.15); }
.alert-success { background: var(--success-light); color: #15803d; border: 1px solid rgba(34, 197, 94, 0.15); }
.alert-warning { background: var(--warning-light); color: #92400e; border: 1px solid rgba(245, 158, 11, 0.15); }
.alert-info { background: var(--primary-light); color: var(--primary); border: 1px solid rgba(124, 58, 237, 0.15); }

/* --- Summary box --- */
.summary-box {
  padding: 1.25rem;
  border: 2px solid var(--primary);
  border-radius: var(--radius);
  background: var(--primary-light);
}
.summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.4rem 0;
}
.summary-total {
  border-top: 2px solid var(--border);
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  font-size: 1.25rem;
  font-weight: 800;
}

/* --- Responsive grid --- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
@media (max-width: 768px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .app-header { padding: 1rem; }
  .mapping-row { grid-template-columns: 1fr; }
}

/* --- Section divider --- */
.section-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

/* --- Flex utilities --- */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
.gap-6 { gap: 1.5rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-4 { margin-top: 1rem; }
.mt-6 { margin-top: 1.5rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-4 { margin-bottom: 1rem; }
.w-full { width: 100%; }
.text-center { text-align: center; }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
.text-muted { color: var(--text-muted); }
.font-bold { font-weight: 700; }
.font-mono { font-family: 'SF Mono', 'Fira Code', monospace; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --- Shortcuts overlay --- */
.shortcuts-panel {
  background: #fff;
  border-radius: 16px;
  padding: 1.5rem;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.15);
  animation: modalIn 200ms ease;
}
.shortcut-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
}
.shortcut-row:last-child { border-bottom: none; }
.shortcut-row kbd {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.6rem;
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.8rem;
  font-weight: 600;
  min-width: 70px;
  justify-content: center;
}
.shortcut-row span {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* --- Last entry hint --- */
.last-entry-hint {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--primary-light);
  border: 1px dashed rgba(124, 58, 237, 0.25);
  border-radius: 6px;
  font-size: 0.8rem;
  margin-bottom: 0.5rem;
  cursor: pointer;
  transition: all 0.15s;
}
.last-entry-hint:hover { background: rgba(124, 58, 237, 0.12); border-color: var(--primary); }

/* --- Language selector --- */
.lang-select {
  appearance: none;
  -webkit-appearance: none;
  background: rgba(0, 0, 0, 0.04);
  border: 1.5px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0.6rem;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
  min-width: 42px;
}
.lang-select:hover { border-color: var(--primary); color: var(--primary); }
.lang-select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.1); }
