:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --border: #dfe4ea;
  --border-strong: #c8d0da;
  --text: #17202a;
  --muted: #687382;
  --primary: #1677ff;
  --primary-hover: #095ecb;
  --success: #16845b;
  --warning: #a86408;
  --danger: #c43b3b;
  --shadow: 0 12px 36px rgba(24, 39, 57, 0.12);
  font-family: "Segoe UI", "Microsoft YaHei UI", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  color: var(--text);
  background: var(--bg);
}

button,
input,
select {
  font: inherit;
}

button,
select,
label,
input[type="checkbox"] {
  cursor: pointer;
}

button:disabled,
select:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
.drop-zone:focus-within {
  outline: 3px solid rgba(22, 119, 255, 0.2);
  outline-offset: 1px;
}

.is-hidden {
  display: none !important;
}

.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #eef2f6;
}

.gate-panel {
  width: min(440px, 100%);
  padding: 36px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.gate-panel h1 {
  margin: 18px 0 24px;
  font-size: 22px;
  letter-spacing: 0;
}

.gate-panel > label,
.field > label,
.modal-form > label {
  display: block;
  margin-bottom: 7px;
  color: #46515f;
  font-weight: 600;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: inline-grid;
  place-items: center;
  color: #fff;
  background: var(--primary);
  border-radius: 8px;
  font-size: 22px;
  font-weight: 700;
}

.brand-mark.small {
  width: 34px;
  height: 34px;
  font-size: 18px;
}

.key-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

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

input:hover,
select:hover {
  border-color: #9da9b6;
}

.form-error {
  min-height: 21px;
  margin: 10px 0 0;
  color: var(--danger);
}

.app {
  min-height: 100vh;
}

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 max(24px, calc((100vw - 1240px) / 2));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand,
.top-actions,
.section-heading,
.section-heading > div,
.inline-actions,
.login-state,
.file-line,
.modal-actions {
  display: flex;
  align-items: center;
}

.brand {
  gap: 11px;
}

.brand strong,
.brand span {
  display: block;
}

.brand strong {
  font-size: 15px;
}

.brand div > span {
  margin-top: 1px;
  color: var(--muted);
  font-size: 12px;
}

.top-actions {
  gap: 10px;
}

.connection {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  white-space: nowrap;
}

.connection i {
  width: 8px;
  height: 8px;
  background: var(--success);
  border-radius: 50%;
}

.connection.offline i {
  background: var(--danger);
}

button {
  min-height: 34px;
  padding: 6px 12px;
  color: #33404d;
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
}

button:hover:not(:disabled) {
  background: #f3f6f9;
  border-color: #aab4bf;
}

button.primary {
  color: #fff;
  background: var(--primary);
  border-color: var(--primary);
}

button.primary:hover:not(:disabled) {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

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

button.danger:hover:not(:disabled) {
  background: #fff3f3;
  border-color: #d98f8f;
}

button.quiet {
  border-color: transparent;
  background: transparent;
}

.icon-command,
.modal-close {
  width: 34px;
  min-width: 34px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  font-size: 20px;
}

.tabs {
  height: 48px;
  display: flex;
  gap: 28px;
  padding: 0 max(24px, calc((100vw - 1240px) / 2));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.tab {
  height: 48px;
  padding: 0 2px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  font-weight: 600;
}

.tab:hover:not(:disabled) {
  color: var(--text);
  background: transparent;
  border-color: transparent;
}

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

main {
  width: min(1240px, calc(100% - 48px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.section-heading {
  min-height: 42px;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.section-heading > div {
  gap: 12px;
  min-width: 0;
}

h2,
h3,
p {
  margin-top: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 18px;
  letter-spacing: 0;
}

.summary,
.muted,
.meta {
  color: var(--muted);
}

.summary {
  white-space: nowrap;
}

.table-shell,
.job-form,
.status-grid {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
}

.table-shell {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

th,
td {
  padding: 13px 16px;
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid #e9edf1;
  overflow-wrap: anywhere;
}

th {
  color: #596675;
  background: var(--surface-soft);
  font-size: 12px;
  font-weight: 600;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover {
  background: #fbfcfe;
}

.actions-column {
  width: 310px;
}

.account-name strong,
.account-name span,
.job-name strong,
.job-name span {
  display: block;
}

.account-name span,
.job-name span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 4px;
  color: #56616d;
  background: #edf1f5;
  font-size: 12px;
  white-space: nowrap;
}

.badge.ready,
.badge.completed,
.badge.authenticated {
  color: #0f6847;
  background: #e4f5ed;
}

.badge.login,
.badge.waiting,
.badge.starting,
.badge.submitting,
.badge.running,
.badge.claimed {
  color: #885408;
  background: #fff1d6;
}

.badge.error,
.badge.failed,
.badge.expired {
  color: #a72e2e;
  background: #fde9e9;
}

.inline-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.inline-actions button {
  min-height: 30px;
  padding: 4px 9px;
  font-size: 12px;
}

.switch {
  position: relative;
  width: 38px;
  height: 22px;
  display: inline-block;
}

.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch span {
  position: absolute;
  inset: 0;
  background: #cbd2da;
  border-radius: 11px;
  transition: background 0.16s ease;
}

.switch span::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.22);
  transition: transform 0.16s ease;
}

.switch input:checked + span {
  background: var(--primary);
}

.switch input:checked + span::after {
  transform: translateX(16px);
}

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

.job-form {
  padding: 18px;
}

.drop-zone {
  min-height: 140px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 4px;
  color: var(--muted);
  background: #fafcff;
  border: 1px dashed #aebbc9;
  border-radius: 6px;
}

.drop-zone.dragging {
  color: var(--primary);
  background: #f0f7ff;
  border-color: var(--primary);
}

.drop-zone input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.drop-zone strong {
  color: var(--primary);
  font-size: 15px;
}

.selected-files {
  max-height: 180px;
  margin-top: 12px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 5px;
}

.file-line {
  justify-content: space-between;
  gap: 18px;
  padding: 9px 12px;
  border-bottom: 1px solid #edf0f3;
}

.file-line:last-child {
  border-bottom: 0;
}

.file-line span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-line span:last-child {
  color: var(--muted);
  white-space: nowrap;
}

.job-options {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) auto auto auto;
  align-items: end;
  gap: 14px;
  margin-top: 16px;
}

.job-options > label:not(.check) {
  color: #46515f;
  font-weight: 600;
}

.job-options select {
  display: block;
  margin-top: 6px;
  font-weight: 400;
}

.check {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}

.check input {
  width: 16px;
  min-height: 16px;
  margin: 0;
}

.jobs-heading {
  margin-top: 28px;
}

.progress-track {
  width: 100%;
  height: 6px;
  margin-top: 5px;
  overflow: hidden;
  background: #e8edf2;
  border-radius: 3px;
}

.progress-track span {
  height: 100%;
  display: block;
  background: var(--primary);
  border-radius: inherit;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  overflow: hidden;
}

.status-grid > div {
  min-height: 118px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 20px;
  border-right: 1px solid var(--border);
}

.status-grid > div:last-child {
  border-right: 0;
}

.status-grid span {
  margin-bottom: 7px;
  color: var(--muted);
}

.status-grid strong {
  font-size: 17px;
  overflow-wrap: anywhere;
}

.self-test-workbench {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 24px;
  padding: 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
}

.self-test-sample {
  display: flex;
  align-items: center;
  gap: 14px;
}

.self-test-sample > div:last-child {
  min-width: 0;
}

.self-test-sample strong,
.self-test-sample span {
  display: block;
}

.self-test-sample span {
  margin-top: 5px;
  font-size: 12px;
}

.sample-preview {
  width: 84px;
  aspect-ratio: 9 / 16;
  flex: 0 0 auto;
  overflow: hidden;
  background: #edf1f5;
  border: 1px solid var(--border);
  border-radius: 4px;
}

.sample-preview img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.self-test-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr)) auto;
  align-items: end;
  gap: 14px;
}

.self-test-form label {
  color: #46515f;
  font-weight: 600;
}

.self-test-form select {
  display: block;
  margin-top: 6px;
  font-weight: 400;
}

.self-test-form button {
  min-height: 38px;
}

.test-steps {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
  margin: 0;
  padding: 18px 0 0;
  list-style: none;
  border-top: 1px solid var(--border);
}

.test-steps li {
  position: relative;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding-right: 18px;
}

.test-steps li:not(:last-child)::after {
  content: "";
  position: absolute;
  top: 15px;
  right: 6px;
  width: 12px;
  height: 1px;
  background: var(--border-strong);
}

.test-steps i {
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  display: grid;
  place-items: center;
  color: #6e7884;
  background: #edf1f5;
  border-radius: 50%;
  font-style: normal;
  font-weight: 700;
}

.test-steps strong,
.test-steps span {
  display: block;
}

.test-steps strong {
  font-size: 13px;
}

.test-steps span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.test-steps li.running i {
  color: #815006;
  background: #fff1d6;
}

.test-steps li.success i {
  color: #fff;
  background: var(--success);
}

.test-steps li.error i {
  color: #fff;
  background: var(--danger);
}

.self-test-result {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 5px;
}

.self-test-result span,
.self-test-result strong {
  display: block;
}

.self-test-result span {
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 12px;
}

.self-test-result strong {
  overflow-wrap: anywhere;
}

.modal {
  position: fixed;
  z-index: 50;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(18, 25, 33, 0.46);
}

.modal-panel {
  position: relative;
  width: min(560px, 100%);
  max-height: min(780px, calc(100vh - 40px));
  overflow: hidden;
  background: var(--surface);
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(10, 20, 32, 0.25);
}

.modal-panel.wide {
  width: min(760px, 100%);
}

.modal-header {
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  margin: 0;
  font-size: 17px;
  letter-spacing: 0;
}

.modal-close {
  border: 0;
  color: var(--muted);
  background: transparent;
}

.modal-body {
  max-height: calc(100vh - 116px);
  padding: 20px;
  overflow-y: auto;
}

.modal-form {
  display: grid;
  gap: 15px;
}

.modal-form label input {
  display: block;
  margin-top: 6px;
  font-weight: 400;
}

.modal-actions {
  justify-content: flex-end;
  gap: 8px;
  margin-top: 5px;
}

.qr-box {
  width: min(300px, 100%);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  margin: 0 auto 16px;
  padding: 12px;
  background: #fff;
  border: 1px solid var(--border);
}

.qr-box img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.login-state {
  justify-content: center;
  gap: 8px;
  text-align: center;
}

.detail-list {
  display: grid;
  grid-template-columns: 130px minmax(0, 1fr);
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.detail-list dt,
.detail-list dd {
  margin: 0;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.detail-list dt {
  color: var(--muted);
  background: var(--surface-soft);
}

.detail-list dt:last-of-type,
.detail-list dd:last-of-type {
  border-bottom: 0;
}

.downloads {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.download-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 5px;
}

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

.toast {
  position: fixed;
  z-index: 70;
  right: 24px;
  bottom: 24px;
  max-width: min(420px, calc(100vw - 48px));
  padding: 11px 15px;
  color: #fff;
  background: #27313c;
  border-radius: 5px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.16s ease, transform 0.16s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.error {
  background: #a92d2d;
}

@media (max-width: 900px) {
  .job-options {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .job-options .primary {
    min-height: 38px;
  }

  .status-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .status-grid > div:nth-child(2) {
    border-right: 0;
  }

  .status-grid > div:nth-child(-n + 2) {
    border-bottom: 1px solid var(--border);
  }

  .actions-column {
    width: 230px;
  }

  .self-test-workbench {
    grid-template-columns: minmax(0, 1fr);
  }

  .self-test-form,
  .test-steps,
  .self-test-result {
    grid-column: 1;
  }

  .self-test-result {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .topbar {
    height: auto;
    min-height: 64px;
    padding: 10px 16px;
  }

  .brand div > span,
  .connection,
  .change-key-label {
    display: none;
  }

  .top-actions {
    gap: 2px;
  }

  .tabs {
    gap: 20px;
    padding: 0 16px;
    overflow-x: auto;
  }

  .tab {
    flex: 0 0 auto;
  }

  main {
    width: calc(100% - 24px);
    padding-top: 20px;
  }

  .section-heading {
    align-items: flex-start;
  }

  .section-heading > div {
    align-items: flex-start;
    flex-direction: column;
    gap: 2px;
  }

  .job-form {
    padding: 12px;
  }

  .job-options,
  .status-grid,
  .self-test-form,
  .self-test-result {
    grid-template-columns: minmax(0, 1fr);
  }

  .self-test-workbench {
    gap: 18px;
    padding: 14px;
  }

  .test-steps {
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
  }

  .test-steps li:not(:last-child)::after {
    top: auto;
    right: auto;
    bottom: -8px;
    left: 15px;
    width: 1px;
    height: 8px;
  }

  .status-grid > div,
  .status-grid > div:nth-child(2) {
    min-height: 86px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .status-grid > div:last-child {
    border-bottom: 0;
  }

  .gate-panel {
    padding: 26px 20px;
  }

  .key-row {
    grid-template-columns: minmax(0, 1fr);
  }

  .modal {
    padding: 10px;
  }

  .modal-panel {
    max-height: calc(100vh - 20px);
  }

  .modal-body {
    max-height: calc(100vh - 76px);
    padding: 16px;
  }

  .detail-list {
    grid-template-columns: 100px minmax(0, 1fr);
  }

  .table-shell {
    overflow: hidden;
  }

  table,
  tbody {
    display: block;
  }

  thead {
    display: none;
  }

  tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px 12px;
    padding: 14px;
    border-bottom: 1px solid var(--border);
  }

  tbody tr:last-child {
    border-bottom: 0;
  }

  tbody td {
    display: block;
    padding: 0;
    border: 0;
  }

  #accountsBody td:nth-child(1),
  #jobsBody td:nth-child(1) {
    grid-column: 1;
    grid-row: 1;
  }

  #accountsBody td:nth-child(2),
  #jobsBody td:nth-child(3) {
    grid-column: 2;
    grid-row: 1;
  }

  #accountsBody td:nth-child(3) {
    grid-column: 1;
    grid-row: 2;
  }

  #accountsBody td:nth-child(3)::after {
    content: " 启用";
    margin-left: 5px;
    color: var(--muted);
    vertical-align: 5px;
  }

  #accountsBody td:nth-child(4),
  #jobsBody td:nth-child(5) {
    display: none;
  }

  #accountsBody td:nth-child(5),
  #jobsBody td:nth-child(4),
  #jobsBody td:nth-child(6) {
    grid-column: 1 / -1;
  }

  #accountsBody .inline-actions,
  #jobsBody .inline-actions {
    justify-content: flex-start;
  }

  #jobsBody td:nth-child(2) {
    grid-column: 1 / -1;
    color: var(--muted);
    font-size: 12px;
  }

  .toast {
    right: 12px;
    bottom: 12px;
    max-width: calc(100vw - 24px);
  }
}
