:root {
  color-scheme: light;
  --page: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #f8fafb;
  --border: #d9e0e7;
  --border-strong: #bdc9d4;
  --text: #17242f;
  --muted: #647481;
  --primary: #0f766e;
  --primary-dark: #0b5f59;
  --blue: #175f9f;
  --blue-soft: #eaf2f9;
  --green: #16735a;
  --green-soft: #e9f5f0;
  --amber: #8a5a06;
  --amber-soft: #fff4dd;
  --red: #b42318;
  --red-soft: #fdebe9;
  --shadow: 0 1px 2px rgba(23, 36, 47, .05), 0 8px 24px rgba(23, 36, 47, .05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--page);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

.shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 22px 44px;
}

.hidden { display: none !important; }
[hidden] { display: none !important; }

h1, h2, p { margin: 0; }
h1 { font-size: 19px; }
h2 { font-size: 16px; }

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
}
.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-size: 17px;
  font-weight: 700;
}
.brand p {
  margin-top: 1px;
  color: var(--muted);
  font-size: 12px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.content {
  display: grid;
  grid-template-columns: minmax(400px, 452px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.submit-panel, .jobs-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.submit-panel { padding: 18px; }
.jobs-panel { padding: 0; overflow: hidden; }

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  overflow: hidden;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  background: var(--surface-soft);
}
.segmented.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.segmented label {
  position: relative;
  margin: 0;
}
.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.segmented span {
  display: block;
  padding: 9px 6px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.segmented input:checked + span {
  background: #fff;
  color: var(--primary);
  font-weight: 650;
  box-shadow: inset 0 -2px 0 var(--primary);
}
.segmented input:focus-visible + span {
  outline: 2px solid rgba(15, 118, 110, .28);
  outline-offset: -3px;
}

label {
  display: block;
  margin-top: 14px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

input, select {
  width: 100%;
  min-height: 38px;
  margin-top: 5px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--text);
  font: inherit;
  background: #fff;
}

input::placeholder { color: #9aa6b1; }
input:focus, select:focus {
  border-color: var(--primary);
  outline: 2px solid rgba(15, 118, 110, .16);
  outline-offset: 1px;
}

.field-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 132px;
  gap: 10px;
}
.field-grid label { min-width: 0; }

.list-section {
  margin-top: 18px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-soft);
}
.items-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 10px 0;
}
.items-header label {
  margin: 0;
  color: var(--text);
}
.add-item {
  margin: 0;
  padding: 6px 9px;
  font-size: 12px;
  white-space: nowrap;
}

.list-table { padding: 8px 10px 10px; }
.list-columns, .item-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 34px;
  gap: 8px;
  align-items: center;
}
.list-columns {
  padding: 0 42px 6px 0;
  color: var(--muted);
  font-size: 11px;
}
.list-columns span:nth-child(3) { visibility: hidden; }
.items { display: grid; gap: 8px; }
.item-row input {
  margin-top: 0;
  min-width: 0;
  background: #fff;
}
.list-table.delivery .list-columns {
  grid-template-columns: minmax(0, 1fr) 34px;
}
.list-table.delivery .list-columns span:nth-child(2) { display: none; }
.list-table.delivery .item-row {
  grid-template-columns: minmax(0, 1fr) 34px;
}
.list-table.delivery .item-code { display: none; }

.options-section {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.section-title {
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}
.section-title-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.section-title-actions .ghost {
  padding: 4px 8px;
  font-size: 12px;
}
.candidate-panel {
  margin-top: 14px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-soft);
}
.candidate-toggle {
  align-self: end;
}
.candidate-list {
  max-height: 220px;
  overflow: auto;
  display: grid;
  gap: 6px;
}
.candidate-item {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  padding: 6px;
  text-align: left;
  cursor: pointer;
}
.candidate-item:hover,
.candidate-item.selected { border-color: var(--primary); }
.candidate-item:disabled { opacity: .55; cursor: not-allowed; }
.candidate-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface-soft);
}
.candidate-main { min-width: 0; }
.candidate-name {
  overflow: hidden;
  color: var(--text);
  font-size: 12px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.candidate-meta {
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.candidate-badge {
  border-radius: 999px;
  padding: 3px 7px;
  font-size: 10px;
  font-weight: 700;
}
.candidate-badge.ok { color: #166534; background: #dcfce7; }
.candidate-badge.no { color: #991b1b; background: #fee2e2; }
.options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
}
.checkbox input {
  width: 16px;
  height: 16px;
  min-height: 0;
  margin: 0;
  flex: 0 0 auto;
  accent-color: var(--primary);
}
.risk-toggle {
  grid-column: 1 / -1;
  margin-top: 0;
  padding: 8px 9px;
  border-radius: 6px;
  background: var(--red-soft);
}
.risk-toggle span { color: var(--red); }

.confirm {
  margin-top: 14px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fff;
}

button {
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
}
.primary {
  width: 100%;
  margin-top: 14px;
  min-height: 40px;
  background: var(--primary);
  color: #fff;
  font-weight: 650;
}
.primary:hover { background: var(--primary-dark); }
.primary:disabled {
  background: #98bdb8;
  cursor: not-allowed;
}
.ghost {
  min-height: 32px;
  background: #edf1f4;
  color: #374552;
}
.ghost:hover { background: #e2e8ed; }

.form-message {
  min-height: 20px;
  margin: 8px 0 0;
  color: var(--red);
  font-size: 12px;
}
.form-message.ok { color: var(--green); }

.jobs-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 15px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.jobs-caption {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}
.connection-state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}
.connection-state::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #98a2ac;
}
.connection-state.connected { color: var(--green); }
.connection-state.connected::before { background: var(--green); }
.connection-state.error { color: var(--red); }
.connection-state.error::before { background: var(--red); }

.jobs {
  display: grid;
  max-height: calc(100vh - 170px);
  gap: 10px;
  margin: 0;
  padding: 12px;
  overflow: auto;
}
.job {
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fff;
  padding: 11px;
}
.job-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.job-timeline {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin: 10px 0 0;
  padding: 8px;
  border-radius: 6px;
  background: var(--surface-soft);
}
.job-timeline dt {
  color: var(--muted);
  font-size: 10px;
}
.job-timeline dd {
  margin: 0;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  white-space: nowrap;
}
.job-meta {
  display: flex;
  min-width: 0;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.job-id {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
}
.job-mode {
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 11px;
  font-weight: 600;
}
.job-count {
  color: var(--muted);
  font-size: 11px;
}
.job-douyins {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: 8px;
  padding: 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-soft);
  overflow: auto;
}
.douyin-entry {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.copy-field {
  display: inline-flex;
  max-width: 290px;
  align-items: center;
  gap: 5px;
  min-width: 0;
  padding: 3px 4px 3px 7px;
  border: 1px solid #c8d5df;
  border-radius: 6px;
  background: #fff;
  font-size: 11px;
}
.copy-field-label {
  flex: 0 0 auto;
  color: var(--muted);
  font-weight: 650;
}
.copy-field-value {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.douyin-id.copy-field-value {
  font-weight: 700;
}
.douyin-name.copy-field-value {
  max-width: 160px;
  color: var(--muted);
}
.copy-field-button {
  flex: 0 0 auto;
  padding: 2px 5px;
  border: 0;
  border-radius: 4px;
  background: var(--blue-soft);
  color: var(--blue);
  cursor: pointer;
  font: inherit;
  font-size: 10px;
  font-weight: 650;
}
.copy-field-button:hover {
  background: #dbe9fb;
}
.copy-field-button.copied {
  background: #dff5e9;
  color: #12805c;
}
.job-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 7px;
}
.status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.status::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.status-pending { color: var(--amber); background: var(--amber-soft); }
.status-running { color: var(--blue); background: var(--blue-soft); }
.status-done { color: var(--green); background: var(--green-soft); }
.status-error, .status-canceled { color: var(--red); background: var(--red-soft); }
.status-queued { color: var(--amber); background: var(--amber-soft); }
.status-leased { color: var(--blue); background: var(--blue-soft); }
.status-succeeded { color: var(--green); background: var(--green-soft); }
.status-failed { color: var(--red); background: var(--red-soft); }
.status-needs_review, .status-waiting_human { color: var(--red); background: var(--red-soft); }
.status-reviewed { color: var(--green); background: var(--green-soft); }
.job-review-reason {
  margin: 8px 0 2px;
  padding: 8px 10px;
  border-radius: 7px;
  border: 1px solid var(--red-soft);
  background: var(--red-soft);
  color: var(--text);
  font-size: 12px;
  line-height: 1.55;
  word-break: break-word;
}
.cancel {
  min-height: 24px;
  background: transparent;
  color: var(--red);
  font-size: 12px;
  padding: 2px 4px;
}
.cancel:hover { background: var(--red-soft); }
.retry {
  min-height: 24px;
  background: transparent;
  color: var(--blue);
  font-size: 12px;
  padding: 2px 4px;
}
.retry:hover {
  background: var(--blue-soft);
}

.job-result {
  margin-top: 9px;
  padding-top: 9px;
  border-top: 1px dashed var(--border);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.job-result-title {
  margin-bottom: 4px;
  color: var(--text);
  font-size: 11px;
  font-weight: 650;
}
.job-result p {
  margin: 0;
}
.job-late-result {
  margin-top: 9px;
  padding: 9px 10px;
  border-radius: 7px;
  border: 1px solid var(--amber-soft);
  background: var(--amber-soft);
  color: var(--text);
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.job-late-result p {
  margin: 0;
}

.empty {
  display: grid;
  min-height: 180px;
  place-items: center;
  border: 1px dashed var(--border-strong);
  border-radius: 7px;
  color: var(--muted);
  background: var(--surface-soft);
}

.login {
  display: grid;
  min-height: calc(100vh - 72px);
  place-items: center;
}
.login-form {
  width: min(390px, 100%);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 22px;
}
.login-brand { margin-bottom: 6px; }

@media (max-width: 960px) {
  .shell { padding: 18px 12px 32px; }
  .topbar { margin-bottom: 14px; }
  .content { grid-template-columns: 1fr; }
  .jobs { max-height: none; }
  .job-timeline { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 560px) {
  .brand p { display: none; }
  .field-grid, .options { grid-template-columns: 1fr; }
  .segmented { grid-template-columns: 1fr; }
  .segmented input:checked + span { box-shadow: inset 2px 0 0 var(--primary); }
  .list-columns { display: none; }
  .list-columns, .item-row, .list-table.delivery .item-row {
    grid-template-columns: 1fr;
  }
  .item-row { gap: 7px; }
  .item-row .remove-item { min-height: 34px; }
  .job-timeline { grid-template-columns: 1fr; }
  .job-timeline dd { white-space: normal; }
}
