:root {
  --bg: #0e1117;
  --panel: #151a23;
  --panel-2: #1b212c;
  --line: #262d3a;
  --text: #d6dce6;
  --dim: #7c8798;
  --accent: #6aa6ff;
  --include: #56b98a;
  --summarize: #d6a34a;
  --omit: #6e7787;
  --danger: #e06c6c;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6fa; --panel: #fff; --panel-2: #eef1f6; --line: #dbe1ea;
    --text: #1c2330; --dim: #626d7d; --accent: #2563eb; --include: #1f8a5c;
    --summarize: #a1701a; --omit: #8b95a3; --danger: #c33;
  }
}

* { box-sizing: border-box; }

/* The panel toggles rows that also carry a display rule, and a class selector
   outranks the browser's own [hidden] { display: none }. */
[hidden] { display: none !important; }

html, body {
  height: 100%; margin: 0;
  background: var(--bg); color: var(--text);
  font-family: var(--sans); font-size: 14px;
}

/* --- header --------------------------------------------------------- */

.bar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel);
}

.brand {
  font-family: var(--mono); font-weight: 600; letter-spacing: .5px; color: var(--accent);
}

.loader { display: flex; gap: 8px; flex: 1; max-width: 620px; }

#target {
  flex: 1; padding: 8px 11px; border-radius: 6px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
  font-family: var(--mono); font-size: 13px;
}
#target:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.engine-wrap { margin-left: auto; position: relative; }

.engine {
  padding: 5px 10px; color: var(--dim); background: transparent;
  font-family: var(--mono); font-size: 12px; white-space: nowrap;
}
.engine[aria-expanded="true"] { border-color: var(--accent); color: var(--text); }

.engine-panel {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 20; width: 380px;
  padding: 14px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); box-shadow: 0 12px 32px rgba(0, 0, 0, .35);
}
.engine-panel h3 {
  margin: 0 0 10px; font-size: 12px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .6px; color: var(--dim);
}

.opt { display: flex; gap: 9px; padding: 7px 8px; border-radius: 6px; cursor: pointer; }
.opt:hover { background: var(--panel-2); }
.opt input { margin-top: 3px; flex: none; accent-color: var(--accent); }
/* Direct child only - the description holds inline spans of its own. */
.opt > span { display: flex; flex-direction: column; gap: 2px; }
.opt b { font-size: 13px; font-weight: 600; }
.opt em { font-style: normal; color: var(--dim); font-size: 11.5px; line-height: 1.45; }
.opt input:disabled ~ span { opacity: .5; }

.fields {
  display: flex; flex-direction: column; gap: 8px;
  margin: 10px 0 0; padding: 11px 8px 3px; border-top: 1px solid var(--line);
}
.fields label {
  display: grid; grid-template-columns: 76px 1fr; align-items: center; gap: 9px;
  color: var(--dim); font-size: 12px;
}
.fields input, .fields select {
  padding: 6px 9px; border-radius: 5px; width: 100%;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
  font-family: var(--mono); font-size: 12px;
}
.fields input:focus, .fields select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.hint { margin: 2px 0 0; color: var(--dim); font-size: 11.5px; line-height: 1.5; }
.hint a { color: var(--accent); }

.engine-foot {
  display: flex; align-items: center; gap: 9px;
  margin-top: 12px; padding-top: 11px; border-top: 1px solid var(--line);
}
.engine-foot button { padding: 5px 11px; font-size: 12px; }
#engine-done { margin-left: auto; background: var(--accent); border-color: var(--accent); color: #fff; }
#engine-status {
  flex: 1; color: var(--dim); font-size: 11.5px; line-height: 1.4;
  overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3;
}
#engine-status.bad { color: var(--danger); }
#engine-status.good { color: var(--include); }

button {
  padding: 7px 12px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  font-family: inherit; font-size: 13px;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: not-allowed; }

#load, #build { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
#load:hover:not(:disabled), #build:hover:not(:disabled) { filter: brightness(1.1); }

.banner {
  margin: 0; padding: 9px 16px; background: #3a1d1d; color: #ffb4b4;
  border-bottom: 1px solid var(--line); font-family: var(--mono); font-size: 13px;
}
.banner.info { background: var(--panel-2); color: var(--dim); }

/* --- layout --------------------------------------------------------- */

main {
  display: grid; grid-template-columns: minmax(340px, 42%) 1fr;
  gap: 1px; background: var(--line);
  height: calc(100vh - 53px);
}
@media (max-width: 860px) {
  main { grid-template-columns: 1fr; height: auto; }
  .tree { max-height: 50vh; }
}

.panel { display: flex; flex-direction: column; background: var(--panel); min-height: 0; }

.panel-head {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-bottom: 1px solid var(--line);
}
.panel-head h2 {
  margin: 0; font-size: 13px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .6px; color: var(--dim); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
/* A repository name is not a label - leave its casing alone. */
#repo-name { text-transform: none; font-family: var(--mono); color: var(--text); }

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

#filter {
  margin-left: auto; width: 150px; padding: 5px 9px; border-radius: 5px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
  font-family: var(--mono); font-size: 12px;
}

.toggle { display: flex; align-items: center; gap: 5px; color: var(--dim); font-size: 12px; }

.bulk {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 8px 14px; border-bottom: 1px solid var(--line);
  color: var(--dim); font-size: 12px;
}
.bulk button { padding: 4px 9px; font-size: 12px; }

/* --- tree ----------------------------------------------------------- */

.tree { flex: 1; overflow: auto; padding: 6px 0; font-family: var(--mono); font-size: 13px; }
.tree:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.empty { padding: 22px 20px; color: var(--dim); font-family: var(--sans); line-height: 1.65; }
.empty ul { padding-left: 18px; }
.empty b { font-family: var(--mono); }

.row {
  display: flex; align-items: center; gap: 8px;
  padding: 1px 14px 1px 8px; white-space: nowrap;
}
.row:hover { background: var(--panel-2); }

.twist {
  width: 14px; flex: none; text-align: center; color: var(--dim);
  cursor: pointer; user-select: none;
}
.twist.leaf { cursor: default; opacity: 0; }

.label { flex: 1; overflow: hidden; text-overflow: ellipsis; cursor: default; }
.row.dir .label { color: var(--accent); cursor: pointer; }
.row.a-omit .label { color: var(--omit); text-decoration: line-through; }
.row.a-summarize .label { color: var(--summarize); }
.row.locked .label { font-style: italic; }

.size { color: var(--dim); font-size: 11px; flex: none; min-width: 52px; text-align: right; }

.seg { display: flex; flex: none; border: 1px solid var(--line); border-radius: 5px; overflow: hidden; }
.seg button {
  width: 22px; padding: 0; height: 19px; line-height: 17px;
  border: 0; border-radius: 0; background: transparent; color: var(--dim);
  font-family: var(--mono); font-size: 11px;
}
.seg button + button { border-left: 1px solid var(--line); }
.seg button:hover:not(:disabled) { background: var(--line); }
.seg button[aria-pressed="true"][data-a="include"]   { background: var(--include);   color: #05130d; }
.seg button[aria-pressed="true"][data-a="summarize"] { background: var(--summarize); color: #1a1204; }
.seg button[aria-pressed="true"][data-a="omit"]      { background: var(--omit);      color: #0b0e13; }
.seg button.mixed { box-shadow: inset 0 -2px 0 var(--accent); }

/* --- footer / output ------------------------------------------------- */

.foot {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; border-top: 1px solid var(--line);
}
.estimate { flex: 1; color: var(--dim); font-family: var(--mono); font-size: 12px; }
.estimate b { color: var(--text); }

.progress { padding: 10px 14px; border-bottom: 1px solid var(--line); }
.track { height: 4px; border-radius: 2px; background: var(--panel-2); overflow: hidden; }
.fill { height: 100%; width: 0; background: var(--accent); transition: width .25s ease; }
.progress-text {
  margin-top: 6px; color: var(--dim); font-family: var(--mono); font-size: 12px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.output {
  flex: 1; margin: 0; padding: 14px; overflow: auto;
  font-family: var(--mono); font-size: 12px; line-height: 1.5;
  white-space: pre; tab-size: 4; background: var(--bg);
}
.placeholder { color: var(--dim); font-family: var(--sans); white-space: normal; }

.stats {
  padding: 9px 14px; border-top: 1px solid var(--line);
  color: var(--dim); font-family: var(--mono); font-size: 12px; min-height: 34px;
}
.stats b { color: var(--text); }

.k-include { color: var(--include); }
.k-summarize { color: var(--summarize); }
.k-omit { color: var(--omit); }
