/* ---------- Theme tokens ---------- */
:root,
[data-theme="light"] {
  --bg:            #f6f7fa;
  --bg-elevated:   #ffffff;
  --card:          #ffffff;
  --text:          #151617;
  --text-subtle:   #293244;
  --muted:         #7d828b;
  --border:        #e3e8f1;
  --border-strong: #d0d8e8;
  --input-bg:      #ffffff;

  --primary:       #269a3c;
  --primary-hover: #1f8232;
  --primary-weak:  #d8f5e3;
  --accent:        #328fe6;

  --error:         #b91c1c;
  --error-bg:      #fff1f2;
  --warning-bg:    #fff7ed;
  --warning-border:#fdba74;
  --warning-text:  #92400e;
  --success:       #16a34a;

  --code-bg:       #eceff6;
  --shadow-sm:     0 1px 2px rgba(15, 17, 19, 0.04);
  --shadow-md:     0 4px 16px rgba(15, 17, 19, 0.06);
}

[data-theme="dark"] {
  --bg:            #0f1113;
  --bg-elevated:   #15181c;
  --card:          #1a1d21;
  --text:          #eceff6;
  --text-subtle:   #c8cde0;
  --muted:         #858fa3;
  --border:        #293244;
  --border-strong: #384056;
  --input-bg:      #14171b;

  --primary:       #43a047;
  --primary-hover: #52ae30;
  --primary-weak:  #143d1c;
  --accent:        #5eb0ff;

  --error:         #f87171;
  --error-bg:      #2a0f12;
  --warning-bg:    #2a1d0a;
  --warning-border:#7c5014;
  --warning-text:  #fbbf24;
  --success:       #4ade80;

  --code-bg:       #24282f;
  --shadow-sm:     0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md:     0 4px 16px rgba(0, 0, 0, 0.45);
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  transition: background 0.18s ease, color 0.18s ease;
}

/* ---------- Header ---------- */
header {
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}
header h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-weak);
}
nav { display: flex; gap: 10px; align-items: center; }

/* ---------- Layout ---------- */
main {
  max-width: 960px;
  margin: 32px auto;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.view { display: flex; flex-direction: column; gap: 24px; }
.view[hidden] { display: none; }
[hidden] { display: none !important; }

/* ---------- Cards / forms ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: var(--shadow-sm);
}
.card h2 { margin: 0; font-size: 20px; }
.card h3 { margin: 12px 0 8px; font-size: 16px; }

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
  color: var(--muted);
}

input[type="file"] {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 15px;
  color: var(--text);
  background: var(--input-bg);
}

/* ---------- Buttons ---------- */
button {
  background: var(--primary);
  color: #ffffff;
  border: none;
  padding: 10px 18px;
  border-radius: 6px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease;
}
button:hover:not(:disabled) { background: var(--primary-hover); }
button:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  padding: 6px 12px;
  font-size: 13px;
  border: 1px solid var(--border);
  font-weight: 500;
}
.btn-ghost:hover:not(:disabled) { background: var(--bg); color: var(--text); }

#btnTheme { display: inline-flex; align-items: center; gap: 6px; min-width: 40px; }
#btnTheme svg { width: 16px; height: 16px; }
html[data-theme="light"] #btnTheme .icon-sun { display: none; }
html[data-theme="dark"]  #btnTheme .icon-moon { display: none; }

/* ---------- Text bits ---------- */
.hint { font-size: 14px; color: var(--muted); margin: 0; }
.error { color: var(--error); font-size: 14px; margin: 0; }
.error:empty { display: none; }
code {
  background: var(--code-bg);
  color: var(--text-subtle);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.9em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

/* ---------- Progress bar ---------- */
.progress-determinate {
  width: 100%;
  height: 10px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
  margin-top: 4px;
}
.progress-determinate .progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary) 0%, var(--accent) 100%);
  border-radius: 999px;
  transition: width 200ms ease-out;
}
.progress-label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 6px;
  font-size: 0.85em;
  color: var(--muted);
}
.progress-stage {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.progress-pct {
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

/* ---------- Dropzone ---------- */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px 16px;
  border: 2px dashed var(--border-strong);
  border-radius: 10px;
  background: var(--bg-elevated);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.dropzone:hover,
.dropzone:focus-visible,
.dropzone.drag-over {
  border-color: var(--primary);
  background: var(--primary-weak);
  outline: none;
}
.dropzone-icon { width: 28px; height: 28px; color: var(--muted); }
.dropzone:hover .dropzone-icon,
.dropzone.drag-over .dropzone-icon { color: var(--primary); }
.dropzone-text strong { display: block; font-size: 14px; font-weight: 500; color: var(--text); }
.dropzone-text small { display: block; margin-top: 2px; font-size: 12px; color: var(--muted); }

/* ---------- File list ---------- */
.file-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.file-list:empty { margin: 0; }
.file-list li {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
  background: var(--bg-elevated);
  color: var(--text);
  max-width: 100%;
}
.file-list .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 260px;
}
.file-list .size { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.file-list .remove {
  appearance: none;
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 0 6px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  border-radius: 999px;
}
.file-list .remove:hover { color: var(--error); background: var(--error-bg); }

/* ---------- Progress block ---------- */
.progress-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  margin-top: 8px;
  font-size: 13px;
}
.progress-stats .stat {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
}
.progress-stats .stat-label {
  color: var(--muted);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.05em;
}
.progress-stats .stat-val {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

/* ---------- Per-file live list ---------- */
.files-live {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-height: 340px;
  overflow-y: auto;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  padding: 6px;
}
.fl-row {
  display: grid;
  grid-template-columns: 22px 1fr 1.2fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border-radius: 6px;
  background: var(--bg-elevated);
  border: 1px solid transparent;
}
.fl-row.fl-done { border-color: var(--primary-weak); }
.fl-row.fl-working { border-color: var(--accent); }
.fl-row.fl-queued { opacity: 0.65; }

.fl-icon {
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 14px;
}
.fl-icon.spin { animation: fl-spin 1.2s linear infinite; }
@keyframes fl-spin { to { transform: rotate(360deg); } }

.fl-name {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--text);
}
.fl-class {
  color: var(--primary); font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.fl-class.none { color: var(--muted); font-weight: normal; }
.fl-row.fl-working .fl-class,
.fl-row.fl-queued .fl-class { color: var(--muted); font-weight: normal; font-style: italic; }

.fl-conf {
  font-variant-numeric: tabular-nums;
  color: var(--muted); font-size: 12px;
  background: var(--primary-weak); color: var(--primary);
  padding: 1px 7px; border-radius: 999px; font-weight: 500;
}
.fl-flags { display: inline-flex; gap: 4px; }
.fl-flag {
  font-size: 10px; padding: 1px 6px; border-radius: 999px; font-weight: 500;
  letter-spacing: 0.03em;
}
.fl-flag.ocr    { background: var(--code-bg); color: var(--text-subtle); }
.fl-flag.review { background: var(--warning-bg); color: var(--warning-text); border: 1px solid var(--warning-border); }

/* ---------- Results: summary header ---------- */
.results-summary { margin-top: -4px; }
.rs-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}
.rs-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  display: flex; flex-direction: column; gap: 4px;
}
.rs-label {
  font-size: 11px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.05em;
}
.rs-val {
  font-size: 26px; font-weight: 600; color: var(--text);
  line-height: 1.1; font-variant-numeric: tabular-nums;
}
.rs-denom { color: var(--muted); font-weight: 400; font-size: 18px; }
.rs-sub { font-size: 12px; color: var(--muted); }
.rs-cov-bar {
  height: 6px; background: var(--border); border-radius: 999px; overflow: hidden;
  margin-top: 2px;
}
.rs-cov-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary) 0%, var(--accent) 100%);
  border-radius: 999px;
  transition: width 250ms ease-out;
}

/* ---------- Tabs inside results ---------- */
.results-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin: 6px 0 -4px;
}
.results-tab {
  background: transparent;
  border: none;
  padding: 8px 14px;
  cursor: pointer;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.results-tab:hover { color: var(--text-subtle); }
.results-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

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

/* ---------- By-class view ---------- */
.cls-row {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  overflow: hidden;
  background: var(--bg-elevated);
}
.cls-row.cls-missing { background: var(--error-bg); border-color: var(--warning-border); opacity: 0.9; }
.cls-row.cls-review { border-color: var(--warning-border); }
.cls-row.cls-unmatched { border-color: var(--warning-border); background: var(--warning-bg); }

.cls-head {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
}
.cls-id {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--muted);
  text-align: right;
}
.cls-name {
  color: var(--text);
  font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cls-pill {
  font-size: 12px;
  padding: 2px 10px;
  border-radius: 999px;
  font-weight: 500;
  white-space: nowrap;
}
.cls-pill.ok { background: var(--primary-weak); color: var(--primary); }
.cls-pill.missing { background: transparent; color: var(--error); border: 1px solid currentColor; }
.cls-pill.review { background: var(--warning-bg); color: var(--warning-text); border: 1px solid var(--warning-border); }

.cls-files {
  list-style: none; margin: 0; padding: 0 14px 10px;
  display: flex; flex-direction: column; gap: 4px;
  border-top: 1px dashed var(--border);
}

/* ---------- File result row (used in both views) ---------- */
.file-results { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }

.fr {
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  background: var(--bg-elevated);
}
.fr-head {
  display: grid;
  grid-template-columns: 18px 1fr auto auto auto;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  cursor: pointer;
  user-select: none;
}
.fr-head:hover { background: var(--bg); }
.cls-files .fr-head { grid-template-columns: 18px 1fr auto auto; }
.cls-files .fr-head .fr-class { display: none; }

.fr-caret {
  font-size: 11px;
  color: var(--muted);
  transition: transform 0.15s ease;
  width: 12px;
}
.fr-name {
  color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 14px;
}
.fr-class {
  color: var(--primary);
  font-weight: 500;
  font-size: 13px;
  max-width: 260px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.fr-class.none { color: var(--muted); font-weight: normal; font-style: italic; }

.fr-conf-wrap {
  display: inline-flex; align-items: center; gap: 6px;
  min-width: 120px; justify-content: flex-end;
}
.fr-conf-num {
  font-variant-numeric: tabular-nums;
  font-size: 12px; color: var(--muted);
  min-width: 32px; text-align: right;
}
.fr-conf-bar {
  width: 60px; height: 5px;
  background: var(--border); border-radius: 999px; overflow: hidden;
  display: inline-block;
}
.fr-conf-fill { display: block; height: 100%; background: var(--primary); }

.fr-flags { display: inline-flex; gap: 4px; }
.fr-flag {
  font-size: 10px; padding: 1px 7px; border-radius: 999px; font-weight: 500;
  letter-spacing: 0.02em;
}
.fr-flag.ocr    { background: var(--code-bg); color: var(--text-subtle); }
.fr-flag.review { background: var(--warning-bg); color: var(--warning-text); border: 1px solid var(--warning-border); }
.fr-flag.lang   { background: var(--bg); color: var(--muted); border: 1px solid var(--border); }

.fr-body {
  display: none;
  padding: 0 14px 12px;
  border-top: 1px dashed var(--border);
}
.fr[data-expanded="1"] .fr-body { display: block; }
.fr[data-expanded="1"] .fr-caret { transform: rotate(90deg); }
.fr-rationale {
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--text-subtle);
  line-height: 1.55;
}
.fr-rationale.muted { color: var(--muted); font-style: italic; }

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  header { padding: 12px 16px; }
  header h1 { font-size: 15px; }
  main { margin: 16px auto; }
  .card { padding: 18px; }
  .fl-row {
    grid-template-columns: 22px 1fr auto;
    grid-template-areas: "icon name conf" "icon class flags";
    row-gap: 2px;
  }
  .fl-row .fl-icon { grid-area: icon; align-self: start; margin-top: 2px; }
  .fl-row .fl-name { grid-area: name; }
  .fl-row .fl-class { grid-area: class; font-size: 12px; }
  .fl-row .fl-conf { grid-area: conf; }
  .fl-row .fl-flags { grid-area: flags; }
  .rs-row { grid-template-columns: 1fr 1fr; }
  .fr-head {
    grid-template-columns: 14px 1fr auto;
    grid-template-areas: "caret name conf" ". class flags";
    row-gap: 2px;
  }
  .fr-head .fr-caret { grid-area: caret; }
  .fr-head .fr-name { grid-area: name; }
  .fr-head .fr-class { grid-area: class; }
  .fr-head .fr-conf-wrap { grid-area: conf; }
  .fr-head .fr-flags { grid-area: flags; }
}
