:root {
  --bg:           #f0f2f5;
  --panel:        #ffffff;
  --border:       #dde1e7;
  --accent:       #0066cc;
  --accent-hover: #0052a3;
  --text:         #1a1a2e;
  --text-muted:   #6b7280;
  --success-bg:   #d1fae5;
  --success-fg:   #065f46;
  --error-bg:     #fee2e2;
  --error-fg:     #991b1b;
  --changed-bg:   #eff6ff;
  --dupe-fg:      #b45309;
  --radius:       8px;
  --radius-sm:    4px;
  --shadow:       0 1px 3px rgba(0,0,0,0.08);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── Header ──────────────────────────────────────────────── */
.app-header {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 14px 20px;
  flex-shrink: 0;
}

.app-header h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.tagline {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── Layout ──────────────────────────────────────────────── */
.app-layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ── Controls pane ───────────────────────────────────────── */
.controls-pane {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.mode-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: #f8f9fa;
  flex-shrink: 0;
}

.tab {
  flex: 1;
  padding: 11px 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color 0.15s;
}

.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-panel {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  gap: 6px;
}

.tab-panel.active { display: flex; flex-direction: column; }

/* ── Rule cards ──────────────────────────────────────────── */
.rule-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  flex-shrink: 0;
}

.rule-card.enabled {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.rule-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  background: #f8f9fa;
}

.rule-check {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 500;
  font-size: 13px;
  user-select: none;
}

.rule-check input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
}

.rule-num {
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  background: var(--text-muted);
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.rule-card.enabled .rule-num { background: var(--accent); }

.rule-body {
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.rule-card:not(.enabled) .rule-body {
  opacity: 0.45;
  pointer-events: none;
}

/* ── Form fields ─────────────────────────────────────────── */
.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field.vcenter {
  justify-content: flex-end;
}

.field > label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.field > label small {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  opacity: 0.85;
}

.field input[type="text"],
.field input[type="number"],
.field select,
textarea {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: white;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  width: 100%;
}

.field input:focus,
.field select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(0,102,204,0.15);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  align-items: start;
}

.field-row--wide-left {
  grid-template-columns: 3fr 2fr;
}

.check-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.check-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}

.check-label input[type="checkbox"] {
  accent-color: var(--accent);
}

.short-input { width: 60px !important; }

/* Find row with pill toggles */
.find-row {
  display: flex;
  gap: 5px;
  align-items: center;
}

.find-row .flex-input { flex: 1; min-width: 0; }

.help {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 1px solid currentColor;
  font-size: 9px;
  font-weight: 700;
  opacity: 0.45;
  cursor: help;
  vertical-align: middle;
  margin-left: 3px;
  user-select: none;
  flex-shrink: 0;
}
.help:hover { opacity: 0.8; }

.pill { display: flex; align-items: center; }
.pill input { display: none; }

.pill span {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}

.pill input:checked + span {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

/* ── CSV tab ─────────────────────────────────────────────── */
.csv-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 4px;
}

.csv-desc code {
  background: var(--bg);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: 'Consolas', 'Menlo', monospace;
  font-size: 11px;
}

.drop-zone.small {
  padding: 16px;
  margin-bottom: 0;
}

.drop-zone.small .drop-icon { font-size: 22px; }
.drop-zone.small p { font-size: 13px; }

.or-divider {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 11px;
  margin: 8px 0;
}

.or-divider::before,
.or-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

#csv-text {
  font-family: 'Consolas', 'Menlo', monospace;
  font-size: 12px;
  resize: vertical;
  min-height: 90px;
}

.btn-secondary {
  margin-top: 8px;
  width: 100%;
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text);
  transition: background 0.12s;
}

.btn-secondary:hover { background: var(--bg); }

.csv-status {
  margin-top: 8px;
  font-size: 12px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  display: none;
}

.csv-status.success { display: block; background: var(--success-bg); color: var(--success-fg); }
.csv-status.error   { display: block; background: var(--error-bg);   color: var(--error-fg);   }

.file-status         { font-size: 13px; padding: 8px 12px; border-radius: var(--radius-sm); flex-shrink: 0; }
.file-status.hidden  { display: none; }
.file-status.error   { display: block; background: var(--error-bg);  color: var(--error-fg); }
.file-status.warning { display: block; background: #fef3c7;          color: #92400e; }

.drop-meta {
  display: flex;
  justify-content: flex-end;
  margin-top: -6px;
}

.info-btn {
  background: none;
  border: none;
  font-size: 11px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  font-family: inherit;
  transition: color 0.12s;
}
.info-btn:hover { color: var(--accent); }

.limit-info {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 12px;
  flex-shrink: 0;
}
.limit-info.hidden { display: none; }
.limit-info strong { font-size: 12px; font-weight: 600; display: block; margin-bottom: 6px; }
.limit-info ul { margin: 0; padding-left: 16px; }
.limit-info li { color: var(--text-muted); line-height: 1.5; margin-top: 4px; }
.limit-info li strong { display: inline; font-size: inherit; margin-bottom: 0; }

/* ── Main pane ───────────────────────────────────────────── */
.main-pane {
  display: flex;
  flex-direction: column;
  padding: 14px;
  gap: 12px;
  overflow: hidden;
  min-height: 0;
}

/* ── Drop zone ───────────────────────────────────────────── */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 28px 20px;
  text-align: center;
  cursor: pointer;
  background: var(--panel);
  transition: border-color 0.15s, background 0.15s;
  flex-shrink: 0;
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--accent);
  background: rgba(0,102,204,0.04);
}

.drop-icon { font-size: 28px; display: block; margin-bottom: 6px; }
.drop-text { font-size: 14px; font-weight: 500; }
.drop-hint { font-size: 12px; color: var(--text-muted); margin-top: 3px; }

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: inherit;
  text-decoration: underline;
  padding: 0;
  font-family: inherit;
}

/* ── Preview pane ────────────────────────────────────────── */
.preview-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.preview-title {
  font-size: 14px;
  font-weight: 600;
}

.badge {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2px 10px;
  font-size: 11px;
  color: var(--text-muted);
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.dupe-warn {
  font-size: 11px;
  font-weight: 600;
  color: var(--dupe-fg);
  background: #fef3c7;
  padding: 3px 8px;
  border-radius: 20px;
}

.dupe-warn.hidden { display: none; }

.btn-ghost {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text-muted);
  transition: background 0.1s;
}

.btn-ghost:hover { background: var(--bg); }

/* ── Preview table ───────────────────────────────────────── */
.table-wrap {
  flex: 1;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  min-height: 0;
}

.preview-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  font-family: 'Consolas', 'Menlo', monospace;
  table-layout: fixed;
}

.preview-table th {
  position: sticky;
  top: 0;
  background: #f8f9fa;
  border-bottom: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  z-index: 1;
}

.preview-table td {
  padding: 6px 12px;
  border-bottom: 1px solid #f0f2f5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.preview-table tr:last-child td { border-bottom: none; }
.preview-table tr.changed       { background: var(--changed-bg); }
.preview-table tr.dupe td:nth-child(3) { color: var(--dupe-fg); font-weight: 600; }

.preview-table th:last-child,
.preview-table td:last-child { width: 28px; padding: 0 4px; text-align: center; }

.del-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 0;
  opacity: 0;
  transition: opacity 0.1s, color 0.1s;
}
.preview-table tr:hover .del-btn { opacity: 1; }
.del-btn:hover { color: var(--error-fg); }

.new-name { color: var(--accent); }

.empty-row td {
  text-align: center;
  color: var(--text-muted);
  padding: 40px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-style: italic;
  font-size: 13px;
}

/* ── Action bar ──────────────────────────────────────────── */
.action-bar {
  display: flex;
  justify-content: flex-end;
  flex-shrink: 0;
}

.btn-primary {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  padding: 10px 22px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  font-family: inherit;
}

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

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

/* ── Search + sort toolbar ───────────────────────────────── */
.preview-toolbar-search {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-shrink: 0;
}

.search-input {
  flex: 1;
  min-width: 0;
  height: 28px;
  padding: 0 8px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}
.search-input:focus { border-color: var(--accent); }

.sort-select {
  height: 28px;
  padding: 0 6px;
  font-size: 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
  flex-shrink: 0;
  outline: none;
}
.sort-select:focus { border-color: var(--accent); }

/* ── Selection action bar ────────────────────────────────── */
.selection-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--changed-bg);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  font-size: 12px;
  flex-shrink: 0;
  flex-wrap: wrap;
}
.selection-bar.hidden { display: none; }
.selection-count { color: var(--text-muted); margin-right: auto; font-size: 11px; }

.folder-input-wrap {
  display: flex;
  gap: 4px;
  align-items: center;
}
.folder-input-wrap.hidden { display: none; }

.folder-input {
  height: 26px;
  padding: 0 7px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--text);
  font-family: inherit;
  width: 130px;
  outline: none;
}
.folder-input:focus { border-color: var(--accent); }

.sel-action-btn,
.folder-btn {
  margin-top: 0;
  width: auto;
  padding: 4px 10px;
  font-size: 11px;
}
.sel-action-btn.hidden { display: none; }

/* ── Checkbox column ─────────────────────────────────────── */
.preview-table th.col-check,
.preview-table td.col-check {
  width: 32px;
  padding: 0 4px;
  text-align: center;
  overflow: visible;
  vertical-align: middle;
}
.preview-table .col-check input[type="checkbox"] {
  display: block;
  margin: 0 auto;
  cursor: pointer;
  accent-color: var(--accent);
}

/* ── Folder prefix in renamed column ─────────────────────── */
.folder-prefix { color: var(--text-muted); }
