:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --secondary: #0f172a;
  --success: #059669;
  --success-soft: #ecfdf5;
  --warning: #d97706;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 6px 20px rgba(15, 23, 42, 0.04);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.88em;
  background: #f1f5f9;
  padding: 1px 5px;
  border-radius: 5px;
  color: #334155;
}

.app-shell {
  max-width: 1120px;
  margin: 0 auto;
  padding: 28px 20px 60px;
}

.topbar {
  margin-bottom: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-icon {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.25);
}

h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.94rem;
}

.main-grid {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  box-shadow: var(--shadow);
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.card-header h2 {
  margin: 0;
  font-size: 1.12rem;
  font-weight: 650;
}

.hint {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.hidden {
  display: none !important;
}

/* Drop Zone */
.drop-zone {
  border: 2px dashed #cbd5e1;
  border-radius: 12px;
  padding: 32px 20px;
  text-align: center;
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.1s ease;
}

.drop-zone:hover,
.drop-zone:focus-visible,
.drop-zone.dragover {
  border-color: var(--primary);
  background: var(--primary-soft);
  outline: none;
}

.drop-icon {
  color: var(--primary);
  margin-bottom: 8px;
}

.drop-title {
  font-weight: 600;
  font-size: 0.98rem;
}

.drop-title span {
  color: var(--primary);
  text-decoration: underline;
}

.drop-sub {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 4px;
}

/* File list */
.file-list-wrap {
  margin-top: 18px;
}

.file-list-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 0.9rem;
}

.file-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 10px;
}

.file-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
}

.file-meta {
  min-width: 0;
  flex: 1;
}

.file-orig {
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}

.file-label-input {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  padding: 5px 8px;
  font-size: 0.88rem;
  font-weight: 500;
  background: #fff;
  color: var(--text);
}

.file-label-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.file-remove {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px 7px;
  border-radius: 6px;
}

.file-remove:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

/* Options */
.options-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
}

.option-item {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  background: var(--surface-2);
  transition: border-color 0.15s ease, background 0.15s ease;
}

.option-item:hover {
  border-color: #cbd5e1;
}

.option-highlight {
  background: var(--primary-soft);
  border-color: #bfdbfe;
  grid-column: 1 / -1;
}

.option-item input[type="checkbox"] {
  margin-top: 3px;
  width: 17px;
  height: 17px;
  accent-color: var(--primary);
  flex-shrink: 0;
  cursor: pointer;
}

.option-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.option-title {
  font-weight: 600;
  font-size: 0.93rem;
}

.option-desc {
  font-size: 0.83rem;
  color: var(--muted);
}

/* Buttons & Action Bar */
.action-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 18px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 10px 18px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s ease, opacity 0.15s ease, border-color 0.15s ease;
}

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

.btn-primary {
  background: var(--primary);
  color: #fff;
}

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

.btn-secondary {
  background: var(--secondary);
  color: #fff;
}

.btn-secondary:hover:not(:disabled) {
  background: #1e293b;
}

.btn-ghost {
  background: #fff;
  border-color: var(--border);
  color: var(--text);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.83rem;
}

.progress-wrap {
  flex: 1;
  min-width: 240px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.progress-track {
  height: 8px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--primary);
  transition: width 0.2s ease;
}

.progress-text {
  font-size: 0.83rem;
  color: var(--muted);
}

.alert {
  margin-top: 14px;
  padding: 11px 14px;
  border-radius: 9px;
  font-size: 0.9rem;
}

.alert-error {
  background: var(--danger-soft);
  color: #991b1b;
  border: 1px solid #fecaca;
}

/* Results */
.results-header {
  flex-wrap: wrap;
  align-items: center;
}

.download-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.kpi-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}

.kpi-label {
  font-size: 0.82rem;
  color: var(--muted);
}

.kpi-value {
  font-size: 1.45rem;
  font-weight: 700;
  margin-top: 2px;
}

.kpi-card.kpi-accent {
  background: var(--success-soft);
  border-color: #a7f3d0;
}

.kpi-card.kpi-accent .kpi-value {
  color: var(--success);
}

.table-wrap {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow-x: auto;
}

.stats-table-wrap {
  margin-bottom: 22px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.data-table th,
.data-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.data-table th {
  background: var(--surface-2);
  font-weight: 600;
  color: #334155;
  white-space: nowrap;
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.data-table tbody tr:hover {
  background: #f8fafc;
}

.data-table th.num,
.data-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.actions-col {
  text-align: right !important;
  white-space: nowrap;
}

/* Preview */
.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 12px;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tab-btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.tab-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.search-box input {
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 0.88rem;
  min-width: 260px;
}

.search-box input:focus {
  outline: none;
  border-color: var(--primary);
}

.preview-table-wrap {
  max-height: 440px;
  overflow-y: auto;
}

.preview-table-wrap thead th {
  position: sticky;
  top: 0;
  z-index: 1;
}

.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  gap: 10px;
  flex-wrap: wrap;
}

.pagination-btns {
  display: flex;
  align-items: center;
  gap: 8px;
}

.page-indicator {
  font-size: 0.86rem;
  color: var(--muted);
  min-width: 56px;
  text-align: center;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  background: #e2e8f0;
  color: #334155;
}

@media (max-width: 640px) {
  .card {
    padding: 16px;
  }
  .search-box,
  .search-box input {
    width: 100%;
  }
}
