:root {
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --success: #10b981;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --warning: #f59e0b;
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  padding: 24px;
  max-width: 1200px;
  margin: 0 auto;
}

header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}

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

/* Badge */
.badge {
  font-size: .75rem;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.badge.idle { background: var(--border); color: var(--text-muted); }
.badge.running { background: #dbeafe; color: var(--primary); animation: pulse 2s infinite; }
.badge.done { background: #d1fae5; color: #065f46; }
.badge.error { background: #fee2e2; color: var(--danger); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .6; }
}

/* Layout */
main {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-bottom: 24px;
}

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

.card h2 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Form */
label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin: 12px 0 4px;
  text-transform: uppercase;
  letter-spacing: .3px;
}

input[type="text"],
input[type="number"] {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .9rem;
  outline: none;
  transition: border-color .15s;
}
input:focus { border-color: var(--primary); }

.row { display: flex; gap: 12px; }
.field { flex: 1; }
.field.small { flex: 0 0 160px; }
.single-select { position: relative; padding: 0; border: none; min-height: auto; }
.single-select input[type="text"] { width: 100%; }

.hint { font-weight: 400; color: var(--text-muted); text-transform: none; }

/* Dual range slider */
.range-slider {
  position: relative;
  height: 36px;
  display: flex;
  align-items: center;
}
.range-slider input[type="range"] {
  position: absolute;
  width: 100%;
  pointer-events: none;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  margin: 0;
  height: 36px;
}
.range-slider input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  background: transparent;
  border-radius: 3px;
}
.range-slider input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  height: 20px;
  width: 20px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
  cursor: pointer;
  pointer-events: auto;
  margin-top: -7px;
  position: relative;
  z-index: 2;
}
.range-slider input[type="range"]::-moz-range-thumb {
  height: 20px;
  width: 20px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
  cursor: pointer;
  pointer-events: auto;
}
.range-slider input[type="range"]::-moz-range-track {
  height: 6px;
  background: transparent;
}
.range-track {
  position: absolute;
  height: 6px;
  border-radius: 3px;
  background: var(--border);
  width: 100%;
  top: 50%;
  transform: translateY(-50%);
}
.range-track::after {
  content: "";
  position: absolute;
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  left: var(--left, 0%);
  right: var(--right, 100%);
}
.range-slider.disabled input[type="range"]::-webkit-slider-thumb {
  background: var(--border);
  cursor: default;
}
.range-slider.disabled .range-track::after {
  background: var(--border);
}
.range-labels {
  display: flex;
  justify-content: space-between;
  font-size: .78rem;
  color: var(--text-muted);
  margin-top: 2px;
}
.range-labels span {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Tag input */
.tag-input {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  min-height: 38px;
  align-items: center;
  cursor: text;
}
.tag-input input {
  border: none;
  outline: none;
  flex: 1;
  min-width: 100px;
  padding: 2px 4px;
  font-size: .9rem;
}
.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #e0e7ff;
  color: #3730a3;
  font-size: .8rem;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 4px;
}
.tag .remove {
  cursor: pointer;
  font-weight: 700;
  opacity: .6;
}
.tag .remove:hover { opacity: 1; }

/* Searchable dropdown */
.tag-input { position: relative; }
.dropdown-list {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
  max-height: 220px;
  overflow-y: auto;
  z-index: 50;
  margin-top: 4px;
}
.dropdown-list.open { display: block; }
.dropdown-item {
  padding: 8px 12px;
  font-size: .85rem;
  cursor: pointer;
  color: var(--text);
}
.dropdown-item:hover,
.dropdown-item.active {
  background: #e0e7ff;
  color: #3730a3;
}
.dropdown-item strong { font-weight: 700; }

/* Checkbox group */
.checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
}
.checkbox-group label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: .85rem;
  font-weight: 400;
  color: var(--text);
  text-transform: none;
  margin: 0;
  cursor: pointer;
}

/* Toggles */
.toggle-group { margin-top: 16px; display: flex; flex-direction: column; gap: 8px; }
.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .85rem;
  font-weight: 500;
  color: var(--text);
  text-transform: none;
  margin: 0;
  cursor: pointer;
}

/* Buttons */
.btn-row { display: flex; gap: 8px; margin-top: 20px; }

.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 6px;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
}
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn.secondary { background: var(--border); color: var(--text); }
.btn.secondary:hover:not(:disabled) { background: #cbd5e1; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger:hover:not(:disabled) { background: var(--danger-hover); }

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

/* Metrics */
.metric-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.metric {
  background: var(--bg);
  border-radius: 8px;
  padding: 12px 16px;
}
.metric-label {
  display: block;
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .3px;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.metric-value {
  display: block;
  font-size: 1.25rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* Progress bar */
.progress-wrap {
  margin: 16px 0;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  width: 0%;
  transition: width .3s;
}

/* File list */
.file-list { max-height: 300px; overflow-y: auto; }
.file-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: .85rem;
  gap: 12px;
}
.file-item:last-child { border-bottom: none; }
.file-info {
  flex: 1;
  min-width: 0;
}
.file-item a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
  word-break: break-all;
}
.file-item a:hover { text-decoration: underline; }
.file-size { color: var(--text-muted); font-size: .75rem; white-space: nowrap; display: block; margin-top: 2px; }

.btn-open-folder {
  flex-shrink: 0;
  padding: 6px 14px;
  font-size: .78rem;
  background: var(--border);
  color: var(--text);
  white-space: nowrap;
}
.btn-open-folder:hover:not(:disabled) { background: #cbd5e1; }
.btn-split {
  flex-shrink: 0;
  padding: 6px 14px;
  font-size: .78rem;
  background: #e0e7ff;
  color: #3730a3;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
}
.btn-split:hover:not(:disabled) { background: #c7d2fe; }
.btn-split:disabled { opacity: .5; cursor: wait; }
.muted { color: var(--text-muted); font-size: .85rem; }

/* Log */
.log-panel h2 { margin-bottom: 8px; }
#log {
  background: #0f172a;
  color: #94a3b8;
  padding: 16px;
  border-radius: 8px;
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: .78rem;
  line-height: 1.6;
  max-height: 300px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}
#log .log-error { color: var(--danger); }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--card);
  border-radius: var(--radius);
  padding: 32px;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.modal h3 { margin-bottom: 12px; }
.modal p { margin-bottom: 8px; color: var(--text-muted); }
.modal .btn-row { margin-top: 24px; justify-content: flex-end; }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: .85rem;
  font-weight: 500;
  color: #fff;
  z-index: 200;
  animation: slideIn .3s ease;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

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

@media (max-width: 800px) {
  main { grid-template-columns: 1fr; }
}
