/* ─── TOKENS ─── */
:root {
  --primary:        #2563eb;
  --primary-hover:  #1d4ed8;
  --primary-light:  #eff6ff;
  --primary-border: #bfdbfe;

  --success:        #16a34a;
  --success-bg:     #f0fdf4;
  --success-border: #bbf7d0;
  --success-text:   #15803d;

  --warn:           #b45309;
  --warn-bg:        #fffbeb;
  --warn-border:    #fde68a;
  --warn-text:      #92400e;

  --error:          #dc2626;
  --error-bg:       #fef2f2;
  --error-border:   #fecaca;
  --error-text:     #b91c1c;

  --bg:             #f1f5f9;
  --card:           #ffffff;
  --border:         #e2e8f0;
  --border-focus:   #93c5fd;
  --text:           #0f172a;
  --text-muted:     #64748b;
  --text-subtle:    #94a3b8;

  --radius-sm:  6px;
  --radius:     12px;
  --radius-lg:  16px;

  --shadow-sm:  0 1px 2px rgba(0,0,0,.06);
  --shadow:     0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md:  0 4px 6px -1px rgba(0,0,0,.08), 0 2px 4px -1px rgba(0,0,0,.05);
}

/* ─── RESET ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
}
code {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12px;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--primary);
}

/* ─── HEADER ─── */
.header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}
.header-inner {
  max-width: 920px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.header-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}
.header-icon-wrap {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(37,99,235,.35);
}
.header-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.01em;
}
.header-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 1px;
}
.header-badge {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 5px 12px;
  border-radius: 20px;
}
.badge-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 2px rgba(22,163,74,.25);
  animation: pulse-dot 2s ease infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: .5; }
}

/* ─── MAIN ─── */
.main {
  max-width: 920px;
  margin: 0 auto;
  padding: 32px 24px 80px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

/* ─── RULES ─── */
.rules-card { padding: 0; overflow: hidden; }
.rules-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: none;
  border: none;
  cursor: pointer;
  padding: 16px 20px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-muted);
  transition: background .15s;
}
.rules-toggle:hover { background: #f8fafc; }
.rules-toggle-left {
  display: flex;
  align-items: center;
  gap: 9px;
}
.rules-optional {
  font-size: 11px;
  font-weight: 500;
  background: #f1f5f9;
  border: 1px solid var(--border);
  color: var(--text-subtle);
  padding: 1px 7px;
  border-radius: 10px;
  margin-left: 2px;
}
.chevron {
  color: var(--text-subtle);
  transition: transform .2s ease;
  flex-shrink: 0;
}
.rules-toggle[aria-expanded="true"] .chevron { transform: rotate(180deg); }
.rules-body {
  padding: 0 20px 20px;
  display: none;
  animation: slide-down .2s ease;
}
.rules-body.open { display: block; }
@keyframes slide-down {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  background: #fafafa;
  resize: vertical;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  line-height: 1.6;
}
.textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(147,197,253,.3);
  background: var(--card);
}

/* ─── STEPS ─── */
.step-card { display: flex; flex-direction: column; gap: 14px; }
.step-header { display: flex; align-items: flex-start; gap: 14px; }
.step-num {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  margin-top: 1px;
  box-shadow: 0 2px 6px rgba(37,99,235,.3);
}
.step-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}
.step-hint {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 3px;
}

/* ─── FOLDER PICKER ─── */
.folder-picker {
  display: flex;
  gap: 10px;
  align-items: center;
}
.folder-display {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 42px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 14px;
  background: #fafafa;
  color: var(--text-subtle);
  min-width: 0;
}
.folder-display svg { flex-shrink: 0; }
.folder-path-text {
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.folder-path-empty { color: var(--text-subtle); font-style: italic; }
.folder-path-set   { color: var(--text); font-style: normal; font-weight: 500; }
.btn-browse-folder {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 42px;
  padding: 0 16px;
  background: var(--card);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, color .15s, border-color .15s;
  flex-shrink: 0;
}
.btn-browse-folder:hover { background: var(--primary-light); color: var(--primary); border-color: var(--primary-border); }

/* ─── FOLDER MODAL ─── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.45);
  backdrop-filter: blur(3px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal-overlay.open {
  display: flex;
  animation: fade-in .15s ease;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
  width: 100%;
  max-width: 560px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  animation: slide-up .18s ease;
}
@keyframes slide-up {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
}
.modal-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}
.modal-close {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background .15s;
}
.modal-close:hover { background: var(--error-bg); color: var(--error); border-color: var(--error-border); }
.modal-breadcrumb {
  padding: 10px 20px;
  font-size: 12px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: #f8fafc;
}
.modal-dirs {
  flex: 1;
  overflow-y: auto;
  padding: 6px 8px;
  min-height: 160px;
}
.modal-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px;
  color: var(--text-muted);
  font-size: 13px;
}
.modal-empty {
  padding: 24px 20px;
  text-align: center;
  color: var(--text-subtle);
  font-size: 13px;
}
.dir-entry {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border: none;
  background: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: inherit;
  font-size: 13.5px;
  color: var(--text);
  text-align: left;
  transition: background .12s;
}
.dir-entry:hover { background: var(--primary-light); color: var(--primary); }
.dir-entry.dir-parent { color: var(--text-muted); font-size: 13px; }
.dir-entry svg.dir-icon { flex-shrink: 0; color: var(--text-subtle); }
.dir-entry:hover svg.dir-icon { color: var(--primary); }
.dir-entry span { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dir-entry svg.dir-arrow { flex-shrink: 0; color: var(--text-subtle); margin-left: auto; }
.modal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: #f8fafc;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.modal-selected-path {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--text-muted);
  min-width: 0;
  flex: 1;
}
.modal-selected-path span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.modal-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ─── INPUT ─── */
.input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.input-icon {
  position: absolute;
  left: 12px;
  color: var(--text-subtle);
  pointer-events: none;
}
.input {
  width: 100%;
  height: 42px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 14px 0 38px;
  font-family: inherit;
  font-size: 13.5px;
  color: var(--text);
  background: #fafafa;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(147,197,253,.3);
  background: var(--card);
}
.input.error { border-color: var(--error); }
.field-error {
  font-size: 12px;
  color: var(--error);
  min-height: 16px;
  display: none;
}
.field-error.visible { display: block; }

/* ─── DROPZONE ─── */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  background: #fafafa;
  cursor: pointer;
  transition: border-color .2s, background .2s;
  min-height: 110px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.dropzone:hover, .dropzone.drag-over {
  border-color: var(--primary);
  background: var(--primary-light);
}
.dropzone.has-file {
  border-style: solid;
  border-color: var(--success-border);
  background: var(--success-bg);
  cursor: default;
}
.dropzone-idle {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 24px;
  text-align: center;
}
.dropzone-icon-wrap {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: #f1f5f9;
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  color: var(--text-muted);
}
.dropzone-text {
  font-size: 13.5px;
  color: var(--text-muted);
}
.dropzone-hint {
  font-size: 11.5px;
  color: var(--text-subtle);
}
.dropzone-file {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  width: 100%;
}
.file-icon-wrap {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--success-bg);
  border: 1px solid var(--success-border);
  display: grid;
  place-items: center;
  color: var(--success);
  flex-shrink: 0;
}
.file-info { flex: 1; min-width: 0; }
.file-name {
  display: block;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-size {
  display: block;
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 1px;
}
.file-remove {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text-muted);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background .15s, color .15s;
  flex-shrink: 0;
}
.file-remove:hover { background: var(--error-bg); color: var(--error); border-color: var(--error-border); }
.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-weight: 500;
  cursor: pointer;
  font-size: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.link-btn:hover { color: var(--primary-hover); }

/* ─── LAUNCH BUTTON ─── */
.btn-launch {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  height: 50px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .1s, box-shadow .15s;
  box-shadow: 0 2px 8px rgba(37,99,235,.35);
  letter-spacing: -.01em;
}
.btn-launch:hover { background: var(--primary-hover); box-shadow: 0 4px 12px rgba(37,99,235,.4); }
.btn-launch:active { transform: translateY(1px); }
.btn-launch:disabled {
  background: #93c5fd;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}
.btn-launch.loading {
  background: var(--primary-hover);
  cursor: not-allowed;
}

/* ─── SCAN BANNER ─── */
.scan-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  background: var(--primary-light);
  border: 1px solid var(--primary-border);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  color: var(--primary);
  font-weight: 500;
}

/* ─── PROGRESS CARD ─── */
.progress-card { display: flex; flex-direction: column; gap: 14px; }
.progress-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.progress-status {
  font-size: 13.5px;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 70%;
}
.progress-pct {
  font-size: 14px;
  font-weight: 700;
  color: var(--primary);
  flex-shrink: 0;
}
.progress-track {
  height: 8px;
  background: #e2e8f0;
  border-radius: 99px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #60a5fa);
  border-radius: 99px;
  transition: width .4s ease;
  position: relative;
  overflow: hidden;
}
.progress-fill::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.35), transparent);
  animation: shimmer 1.5s infinite;
}
@keyframes shimmer {
  from { transform: translateX(-100%); }
  to   { transform: translateX(100%); }
}
.progress-stats {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.pstat {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12.5px;
  color: var(--text-muted);
  font-weight: 500;
}
.pstat-ok  { color: var(--success-text); }
.pstat-warn{ color: var(--warn-text); }
.pstat-err { color: var(--error-text); }

/* ─── TABLE ─── */
.table-card { padding: 0; overflow: hidden; }
.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 14px;
  border-bottom: 1px solid var(--border);
}
.table-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.table-live {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--success-text);
  font-weight: 500;
  background: var(--success-bg);
  border: 1px solid var(--success-border);
  padding: 3px 10px;
  border-radius: 99px;
}
.table-live.done {
  color: var(--text-muted);
  background: #f8fafc;
  border-color: var(--border);
}
.live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
  animation: live-blink 1s step-end infinite;
}
.table-live.done .live-dot {
  background: var(--text-subtle);
  animation: none;
}
@keyframes live-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}
.table-scroll {
  overflow-x: auto;
  max-height: 460px;
  overflow-y: auto;
}
.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.results-table thead th {
  position: sticky;
  top: 0;
  background: #f8fafc;
  color: var(--text-muted);
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 9px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.results-table thead th:first-child { width: 48px; text-align: center; }
.results-table thead th:last-child  { width: 100px; text-align: center; }
.results-table tbody tr {
  border-bottom: 1px solid #f1f5f9;
  animation: row-in .25s ease;
}
@keyframes row-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.results-table tbody tr:last-child { border-bottom: none; }
.results-table tbody tr.row-ok   { background: #fafffe; }
.results-table tbody tr.row-warn { background: #fffdf5; }
.results-table tbody tr.row-err  { background: #fff8f8; }
.results-table tbody td {
  padding: 10px 16px;
  color: var(--text);
  vertical-align: middle;
}
.results-table tbody td:first-child {
  text-align: center;
  color: var(--text-subtle);
  font-size: 12px;
  font-weight: 500;
}
.td-ref  { font-weight: 600; font-family: 'SF Mono','Fira Code',monospace; font-size: 12px; color: var(--primary); }
.td-file { font-size: 12px; color: var(--text-muted); white-space: nowrap; max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
.td-val  { font-weight: 500; }
.td-status { text-align: center; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 99px;
  white-space: nowrap;
}
.badge-ok   { background: var(--success-bg); color: var(--success-text); border: 1px solid var(--success-border); }
.badge-warn { background: var(--warn-bg);    color: var(--warn-text);    border: 1px solid var(--warn-border); }
.badge-err  { background: var(--error-bg);   color: var(--error-text);   border: 1px solid var(--error-border); }

/* ─── COMPLETE ─── */
.complete-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.complete-banner {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 24px;
  background: var(--success-bg);
  border: 1px solid var(--success-border);
  border-radius: var(--radius);
}
.complete-icon {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--success);
  color: #fff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(22,163,74,.3);
}
.complete-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--success-text);
}
.complete-sub {
  font-size: 13px;
  color: #4ade80;
  margin-top: 2px;
}
.complete-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.btn-download {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: 48px;
  padding: 0 24px;
  background: var(--primary);
  color: #fff;
  text-decoration: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  transition: background .15s, box-shadow .15s;
  box-shadow: 0 2px 8px rgba(37,99,235,.35);
}
.btn-download:hover { background: var(--primary-hover); box-shadow: 0 4px 12px rgba(37,99,235,.4); }

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 48px;
  padding: 0 20px;
  background: var(--card);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.btn-secondary:hover { background: #f8fafc; color: var(--text); }

/* ─── ERROR BANNER ─── */
.error-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  color: var(--error-text);
  font-weight: 500;
}
.error-banner svg { flex-shrink: 0; }
#errorText { flex: 1; }

/* ─── SPINNERS ─── */
.spinner-sm {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(37,99,235,.25);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── FORM SECTION + ANALYSIS SECTION ─── */
#formSection { display: flex; flex-direction: column; gap: 16px; }
#analysisSection { display: flex; flex-direction: column; gap: 16px; }

/* ─── RESPONSIVE ─── */
@media (max-width: 600px) {
  .header-inner { padding: 12px 16px; }
  .header-badge { display: none; }
  .main { padding: 20px 16px 60px; }
  .card { padding: 18px; }
  .progress-stats { gap: 10px; }
  .complete-actions { flex-direction: column; }
  .btn-download, .btn-secondary { width: 100%; justify-content: center; }
}
