:root {
  color-scheme: light;
  --bg: #f4f6f2;
  --surface: #ffffff;
  --surface-soft: #f8faf7;
  --line: #d8dfd5;
  --line-strong: #aeb9ab;
  --text: #18221b;
  --muted: #637064;
  --teal: #176c66;
  --teal-strong: #0f514c;
  --rust: #ad5633;
  --amber: #d7a23a;
  --danger: #b43131;
  --shadow: 0 18px 40px rgba(35, 48, 40, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft YaHei", sans-serif;
  line-height: 1.5;
}

button,
input,
textarea,
select {
  font: inherit;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 24px 28px 18px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfa;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.2;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 16px;
}

.topbar-actions,
.action-row,
.secret-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.action-row {
  flex-wrap: wrap;
}

.action-row .primary-button,
.action-row .secondary-button,
.action-row .danger-button {
  flex: 1 1 calc(50% - 5px);
  min-width: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface);
  font-size: 13px;
  white-space: nowrap;
}

.badge-ready {
  border-color: rgba(23, 108, 102, 0.35);
  color: var(--teal-strong);
  background: #eaf4f1;
}

.badge-warn {
  border-color: rgba(173, 86, 51, 0.35);
  color: var(--rust);
  background: #fff1e9;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 18px;
  padding: 18px;
}

.control-panel,
.status-panel {
  min-width: 0;
}

.control-panel {
  position: sticky;
  top: 18px;
  align-self: start;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.control-panel > form > * {
  min-width: 0;
}

.status-panel {
  display: grid;
  gap: 14px;
}

form {
  display: grid;
  gap: 14px;
}

.field,
.number-grid label {
  display: grid;
  gap: 7px;
}

.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

label,
.metric-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
textarea,
select {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface-soft);
  color: var(--text);
  outline: none;
}

.control-panel input,
.control-panel textarea,
.control-panel select {
  overflow-wrap: anywhere;
  word-break: break-word;
}

input {
  height: 40px;
  padding: 0 11px;
}

select {
  height: 40px;
  padding: 0 10px;
}

textarea {
  resize: vertical;
  min-height: 86px;
  padding: 10px 11px;
  word-break: break-word;
}

.forum-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  max-height: 184px;
  overflow: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
}

.forum-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  min-height: 32px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
}

.forum-chip input {
  width: 15px;
  height: 15px;
  accent-color: var(--teal);
  flex: 0 0 auto;
}

.forum-chip span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(23, 108, 102, 0.14);
}

.number-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.secret-row input {
  flex: 1;
}

.switch-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.switch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
  color: var(--text);
}

.switch-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--teal);
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition:
    background 120ms ease,
    border-color 120ms ease,
    color 120ms ease,
    transform 120ms ease;
}

.primary-button,
.secondary-button,
.danger-button,
.ghost-button {
  min-height: 42px;
  padding: 0 14px;
  font-weight: 800;
}

.compact-button {
  min-height: 40px;
  padding: 0 12px;
}

.primary-button {
  flex: 1;
  background: var(--teal);
  color: #ffffff;
}

.primary-button:hover {
  background: var(--teal-strong);
}

.secondary-button,
.ghost-button,
.danger-button {
  background: var(--surface);
  border-color: var(--line-strong);
  color: var(--text);
}

.secondary-button:hover,
.ghost-button:hover {
  border-color: var(--teal);
  color: var(--teal-strong);
}

.danger-button {
  color: var(--danger);
}

.danger-button:hover {
  border-color: var(--danger);
  background: #fff0f0;
}

.icon-button {
  width: 42px;
  height: 40px;
  flex: 0 0 42px;
  background: var(--surface);
  border-color: var(--line-strong);
  color: var(--teal-strong);
  font-weight: 900;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.status-strip > div,
.log-shell,
.records-shell {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.status-strip > div {
  display: grid;
  min-height: 86px;
  align-content: center;
  gap: 6px;
  padding: 16px;
}

.status-strip strong {
  overflow-wrap: anywhere;
  font-size: 24px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
}

.panel-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
}

.select-page-control {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--text);
  white-space: nowrap;
}

.select-page-control input {
  width: 16px;
  height: 16px;
  accent-color: var(--teal);
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.log-shell pre {
  width: 100%;
  min-height: 260px;
  max-height: 420px;
  margin: 0;
  overflow: auto;
  padding: 14px 16px;
  background: #111a17;
  color: #e9f4ed;
  font-family: "Cascadia Mono", Consolas, "SFMono-Regular", monospace;
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
}

.table-wrap {
  width: 100%;
  overflow: auto;
}

table {
  width: 100%;
  min-width: 840px;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  background: var(--surface-soft);
}

td a {
  color: var(--teal-strong);
  font-weight: 700;
  text-decoration: none;
}

td a:hover {
  color: var(--rust);
  text-decoration: underline;
}

.empty-cell {
  height: 88px;
  color: var(--muted);
  text-align: center;
  vertical-align: middle;
}

.is-running #startButton {
  background: var(--amber);
}

.results-page {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.results-toolbar {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 140px minmax(150px, 180px) minmax(170px, 220px) 100px 110px;
  align-items: end;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.search-field,
.page-size-field,
.facet-field {
  min-width: 0;
}

.compact-switch {
  min-height: 40px;
}

.results-metrics {
  grid-template-columns: 160px 160px minmax(0, 1fr);
}

.results-metrics strong {
  font-size: 18px;
  line-height: 1.35;
}

.excerpt-text {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.subtle-line {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.text-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  margin-left: 8px;
  padding: 0 9px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--teal-strong);
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
}

.text-button:hover {
  border-color: var(--teal);
}

.danger-text {
  color: var(--danger);
}

.danger-text:hover {
  border-color: var(--danger);
  background: #fff0f0;
}

.result-list {
  display: grid;
}

.result-row {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  gap: 16px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.record-select {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 3px;
}

.record-select input {
  width: 18px;
  height: 18px;
  accent-color: var(--teal);
}

.result-row:last-child {
  border-bottom: 0;
}

.result-main {
  min-width: 0;
}

.result-title-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.result-forum {
  flex: 0 0 auto;
  padding: 2px 7px;
  border: 1px solid rgba(23, 108, 102, 0.2);
  border-radius: 6px;
  background: #eaf4f1;
  color: var(--teal-strong);
  font-size: 12px;
  font-weight: 800;
}

.result-title {
  min-width: 0;
  color: var(--teal-strong);
  font-size: 15px;
  font-weight: 800;
  line-height: 1.4;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.result-title:hover {
  color: var(--rust);
  text-decoration: underline;
}

.result-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin-top: 9px;
  color: var(--muted);
  font-size: 12px;
}

.result-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(64px, auto));
  align-content: start;
  justify-items: end;
  gap: 8px;
  min-width: 184px;
}

.count-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 28px;
  min-width: 64px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.count-pill strong {
  color: var(--text);
  font-size: 13px;
}

.result-actions .text-button {
  min-width: 64px;
  margin-left: 0;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding-bottom: 18px;
}

.inline-pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 16px;
}

.inline-pager .secondary-button {
  min-height: 34px;
  padding: 0 12px;
  font-size: 13px;
}

@media (max-width: 920px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .results-toolbar,
  .results-metrics {
    grid-template-columns: 1fr 1fr;
  }

  .result-row {
    grid-template-columns: 28px 1fr;
  }

  .result-actions {
    grid-template-columns: repeat(4, max-content);
    justify-content: start;
    justify-items: start;
    min-width: 0;
  }

  .control-panel {
    position: static;
  }
}

@media (max-width: 560px) {
  .topbar,
  .workspace {
    padding-left: 12px;
    padding-right: 12px;
  }

  .topbar-actions,
  .action-row {
    width: 100%;
    align-items: stretch;
    flex-direction: column;
  }

  .ghost-button,
  .primary-button,
  .secondary-button,
  .danger-button {
    width: 100%;
  }

  .number-grid,
  .forum-options,
  .switch-list,
  .status-strip,
  .results-toolbar,
  .results-metrics {
    grid-template-columns: 1fr;
  }

  .result-title-line {
    align-items: flex-start;
    flex-direction: column;
  }

  .panel-actions {
    align-items: flex-end;
    flex-direction: column;
  }

  .result-actions {
    grid-template-columns: repeat(2, minmax(0, max-content));
  }
}

.badge-muted {
  color: var(--muted);
  background: var(--surface);
}

.badge-ok {
  border-color: rgba(23, 108, 102, 0.35);
  color: var(--teal-strong);
  background: #eaf4f1;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(20, 32, 24, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}

.modal[hidden] {
  display: none;
}

.modal-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 22px 22px 18px;
}

.modal-card h2 {
  margin: 0 0 6px;
  font-size: 18px;
}

.modal-card label {
  display: block;
  margin: 12px 0 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.modal-card input {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--text);
  font-size: 14px;
}

.modal-card input:focus {
  outline: none;
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(23, 108, 102, 0.18);
}

.modal-actions {
  margin-top: 18px;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.error-text {
  margin: 10px 0 0;
  color: var(--danger);
  font-size: 13px;
}

.error-text[hidden] {
  display: none;
}
