:root {
  --bg: #0c0f16;
  --surface: #161b26;
  --surface-2: #1e2533;
  --line: #2a3242;
  --text: #e8ecf3;
  --muted: #93a0b4;
  --accent: #ffb02e;
  --accent-2: #4ea1ff;
  --green: #4cd17e;
  --red: #ff6b6b;
  --amber: #ffb02e;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-2); }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: linear-gradient(180deg, #10141c 0%, rgba(16,20,28,0.97) 100%);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 14px 20px; max-width: 1200px; margin: 0 auto;
}
.app-title { font-size: 18px; font-weight: 700; }
.app-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.progress-wrap { min-width: 200px; text-align: right; }
.progress-num { font-size: 13px; color: var(--muted); margin-bottom: 6px; font-variant-numeric: tabular-nums; }
.progress-bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress-bar span { display: block; height: 100%; width: 0%; background: linear-gradient(90deg, var(--green), var(--accent-2)); transition: width .4s ease; }

main { max-width: 1200px; margin: 0 auto; padding: 16px 20px 60px; }

/* ---------- Statline ---------- */
.statline { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 16px; }
.chip-stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: 99px;
  padding: 6px 12px; font-size: 13px; color: var(--muted);
  display: inline-flex; gap: 8px; align-items: center; cursor: pointer;
}
.chip-stat:hover { border-color: var(--accent-2); }
.chip-stat b { color: var(--text); font-variant-numeric: tabular-nums; }
.chip-stat.active { border-color: var(--accent); color: var(--text); }
.dot { width: 9px; height: 9px; border-radius: 99px; background: var(--muted); }

/* ---------- Panel (Worker) ---------- */
.panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 16px;
}
.panel-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.worker-status { font-size: 14px; color: var(--muted); }
.worker-status.live { color: var(--green); }
.worker-status.err { color: var(--red); }
.panel-actions { display: flex; align-items: center; gap: 10px; }
.inline-field { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.inline-field input { width: 80px; }
.llm-warn {
  margin-top: 12px; font-size: 13px; color: #ffd9a6;
  background: rgba(255,176,46,0.08); border: 1px solid rgba(255,176,46,0.3);
  padding: 10px 12px; border-radius: 10px;
}
.llm-warn code { background: rgba(0,0,0,0.3); padding: 1px 5px; border-radius: 5px; }

/* ---------- Inputs / Buttons ---------- */
input, select {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 9px; padding: 8px 10px; font-size: 14px; outline: none;
}
input:focus, select:focus { border-color: var(--accent-2); }
input[type="number"] { font-variant-numeric: tabular-nums; }

.btn {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 9px; padding: 8px 14px; font-size: 14px; font-weight: 600;
  cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { border-color: var(--accent-2); }
.btn.primary { background: var(--accent); color: #20160a; border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.danger { background: transparent; color: var(--red); border-color: rgba(255,107,107,0.4); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar #search { flex: 1; min-width: 200px; }
.toolbar .spacer { flex: 1; }

/* ---------- Table ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table.grid { width: 100%; border-collapse: collapse; font-size: 14px; }
table.grid th, table.grid td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); }
table.grid th { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); position: sticky; top: 0; background: var(--surface); z-index: 1; }
table.grid th.num, table.grid td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.grid tbody tr:hover { background: var(--surface-2); cursor: pointer; }
table.grid tbody tr:last-child td { border-bottom: none; }
.ags { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }
.kname { font-weight: 600; }
.ktype { color: var(--muted); font-size: 12px; }
.src-cell a { font-size: 12px; }
.src-cell .stype { color: var(--muted); font-size: 11px; display: block; }
.muted { color: var(--muted); }

td .row-btn {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  border-radius: 7px; padding: 4px 8px; font-size: 12px; cursor: pointer;
}
td .row-btn:hover { border-color: var(--accent-2); color: var(--text); }

/* ---------- Status badges ---------- */
.badge { display: inline-block; padding: 3px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; }
.badge.pending { background: rgba(147,160,180,0.15); color: var(--muted); }
.badge.researching { background: rgba(78,161,255,0.15); color: var(--accent-2); }
.badge.found { background: rgba(76,209,126,0.15); color: var(--green); }
.badge.not_found { background: rgba(255,176,46,0.13); color: var(--amber); }
.badge.review { background: rgba(78,161,255,0.13); color: var(--accent-2); }
.badge.done { background: rgba(76,209,126,0.22); color: var(--green); }
.badge.failed { background: rgba(255,107,107,0.15); color: var(--red); }

.conf-bar { display: inline-block; width: 46px; height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; vertical-align: middle; }
.conf-bar span { display: block; height: 100%; background: var(--green); }

.empty { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.6); }
.sheet { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); width: 100%; max-width: 620px; max-height: 90vh; display: flex; flex-direction: column; }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { margin: 0; font-size: 18px; }
.sheet-sub { font-size: 13px; color: var(--muted); margin-top: 3px; }
.icon-btn { background: none; border: none; color: var(--muted); font-size: 26px; line-height: 1; cursor: pointer; }
.sheet-body { padding: 16px 18px; overflow-y: auto; }

.src-line { font-size: 13px; margin-bottom: 10px; }
.src-line .stype { color: var(--muted); }
.summary { font-size: 14px; color: var(--text); background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 14px; }
.summary:empty { display: none; }

.edit-form .field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.edit-form .field > span { font-size: 12px; color: var(--muted); }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }

.detail-extra { margin: 6px 0 14px; }
.detail-extra h4 { margin: 14px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }
.detail-extra table { width: 100%; border-collapse: collapse; font-size: 13px; }
.detail-extra td { padding: 4px 6px; border-bottom: 1px solid var(--line); }
.detail-extra td.num { text-align: right; font-variant-numeric: tabular-nums; }
.cond-list { margin: 4px 0 0; padding-left: 18px; font-size: 13px; color: var(--muted); }
.cond-list li { margin-bottom: 3px; }

.form-error { color: var(--red); font-size: 13px; min-height: 18px; }
.form-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 8px; }

/* ---------- Toast ---------- */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--surface-2); border: 1px solid var(--line); color: var(--text); padding: 12px 18px; border-radius: 10px; font-size: 14px; z-index: 100; box-shadow: 0 8px 30px rgba(0,0,0,0.4); }
.toast.err { border-color: rgba(255,107,107,0.5); color: #ffd0d0; }

@media (max-width: 760px) {
  .table-wrap { overflow-x: auto; }
  table.grid { min-width: 760px; }
  .progress-wrap { display: none; }
}
