:root {
  color-scheme: light;
  font-family: Inter, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #17191c;
  background: #f3f4f6;
  letter-spacing: 0;
  --red: #e2231a;
  --red-dark: #bd1711;
  --green: #07a653;
  --line: #d9dde3;
  --muted: #66707b;
  --surface: #ffffff;
  --ink: #17191c;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: #f3f4f6;
  font-size: 13px;
}

button,
input,
textarea,
select {
  font: inherit;
  letter-spacing: 0;
}

.topbar {
  min-height: 56px;
  padding: 8px clamp(14px, 3vw, 36px);
  display: flex;
  align-items: center;
  gap: 13px;
  background: #202328;
  color: #fff;
  border-bottom: 3px solid var(--red);
}

.brand-mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  background: var(--red);
  border-radius: 4px;
  font-weight: 800;
  font-size: 15px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 16px;
  line-height: 1.25;
  font-weight: 650;
}

.topbar p {
  margin-top: 1px;
  color: #aeb5be;
  font-size: 11px;
}

.status-indicator {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #d5d9de;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #8b929b;
}

.status-dot.running {
  background: #f3a72f;
}

.status-dot.ready {
  background: var(--green);
}

.status-dot.failed {
  background: #ff4d45;
}

main {
  width: min(1280px, calc(100% - 24px));
  height: calc(100dvh - 80px);
  min-height: 500px;
  margin: 12px auto;
  display: grid;
  grid-template-rows: minmax(0, 1fr) clamp(150px, 21dvh, 210px);
  gap: 12px;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(360px, 0.95fr);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.control-pane,
.result-pane {
  min-width: 0;
  min-height: 0;
  padding: 18px 22px;
  overflow: auto;
}

.result-pane {
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--line);
  background: #fafbfc;
}

.section-heading {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.section-heading.compact {
  margin-bottom: 0;
}

.section-number {
  flex: 0 0 auto;
  color: var(--red);
  font-size: 12px;
  font-weight: 700;
}

.section-heading h2 {
  font-size: 15px;
  font-weight: 650;
}

.section-heading p {
  margin-top: 1px;
  color: var(--muted);
  font-size: 11px;
}

.heading-select {
  width: 112px;
  height: 30px;
  margin-left: auto;
  align-self: center;
  padding: 0 8px;
  font-size: 11px;
}

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

.single-inputs,
.batch-inputs {
  display: grid;
  gap: 5px;
}

.saved-picker-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 90px;
  gap: 8px;
  align-items: end;
  padding-bottom: 5px;
}

.saved-picker-row > div,
.account-source-grid > div {
  min-width: 0;
  display: grid;
  gap: 5px;
}

.saved-picker-row .secondary-button {
  margin-bottom: 0;
}

.batch-sku-library-picker {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.batch-sku-group-row {
  display: grid;
  grid-template-columns: minmax(100px, .35fr) minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
}

.batch-sku-group-row label { margin: 0; }

.batch-sku-library-heading,
.sku-library-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.batch-sku-library-heading {
  justify-content: space-between;
}

.sku-library-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 6px;
  max-height: 152px;
  overflow: auto;
  padding: 3px;
  border: 1px solid #cbd0d7;
  border-radius: 4px;
  background: #f8f9fa;
}

.sku-library-option {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  min-width: 0;
  margin: 0;
  padding: 8px;
  border: 1px solid #d9dde2;
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
}

.sku-library-option:has(input:checked) {
  border-color: #1f6feb;
  background: #eef5ff;
}

.sku-library-option input {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
  margin-top: 1px;
}

.sku-library-option-copy {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.sku-library-option-copy strong,
.sku-library-option-copy small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sku-library-option-copy strong { color: #1e2732; font-size: 11px; }
.sku-library-option-copy small { color: #68727d; font-size: 10px; }
.sku-library-empty { padding: 12px 8px; color: #68727d; font-size: 10px; }
.sku-library-actions .small-button { flex: 0 0 auto; }
.sku-library-actions .field-hint { flex: 1; }
.sku-library-actions button:disabled { opacity: .45; cursor: not-allowed; }

#skuBulkFile {
  height: 28px;
  padding: 3px 6px;
  font-size: 10px;
}

.field-hint {
  color: #6d7580;
  font-size: 10px;
  line-height: 1.35;
}

.account-source-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 3px 0;
}

label {
  margin-top: 2px;
  color: #3b4148;
  font-size: 11px;
  font-weight: 600;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid #cbd0d7;
  border-radius: 4px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

input,
select {
  height: 34px;
  padding: 0 10px;
}

textarea {
  padding: 8px 10px;
  resize: vertical;
  height: 96px;
  min-height: 70px;
  max-height: 130px;
  line-height: 1.45;
}

.cookie-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 166px;
  gap: 8px;
  min-width: 0;
}

.cookie-grid > div {
  display: grid;
  grid-template-rows: auto 1fr;
  align-content: start;
  gap: 5px;
  min-width: 0;
}

#cookieType {
  align-self: start;
}

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

.batch-import-grid > div,
.batch-option-grid > div {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.batch-import-grid textarea {
  height: 82px;
  min-height: 70px;
}

.batch-import-grid input[type="file"] {
  height: 28px;
  padding: 3px 6px;
  font-size: 10px;
}

.batch-option-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  align-items: end;
}

.batch-plan {
  grid-column: 1 / -1;
  align-self: center;
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.batch-result {
  min-height: 0;
  flex: 1;
  overflow: hidden;
}

.batch-result-header {
  min-height: 38px;
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.batch-result-header h3 {
  margin: 0 0 2px;
  font-size: 13px;
}

.batch-result-header p {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
}

.batch-run-mode {
  flex: 0 0 auto;
  color: #4f5965;
  font-size: 10px;
  line-height: 1.4;
  text-align: right;
}

.batch-result-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.batch-result-actions .quiet-button {
  padding: 3px 6px;
  border: 1px solid #cfd4da;
  border-radius: 4px;
  color: #4f5965;
  font-size: 10px;
}

.batch-result-actions .quiet-button:hover {
  border-color: #9ba4ae;
  color: #202328;
}

.batch-items {
  max-height: calc(100% - 47px);
  margin: 0;
  padding: 8px 2px 8px 0;
  display: grid;
  gap: 8px;
  overflow: auto;
}

.batch-card {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-left: 3px solid #9ca3ad;
  border-radius: 6px;
  background: #fff;
}

.batch-card.status-qr_ready {
  border-left-color: var(--green);
}

.batch-card.status-failed,
.batch-card.status-expired {
  border-left-color: #e0463e;
}

.batch-card.status-acquiring_proxy,
.batch-card.status-launching,
.batch-card.status-converting_cookie,
.batch-card.status-inspecting,
.batch-card.status-submitting,
.batch-card.status-cashier,
.batch-card.status-wechat {
  border-left-color: #d79218;
}

.batch-card-head {
  min-height: 24px;
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 7px;
  border-bottom: 1px solid #eceef1;
}

.batch-account-index {
  display: block;
  font-size: 12px;
}

.batch-account-label {
  display: block;
  margin-top: 1px;
  color: var(--muted);
  font-size: 10px;
}

.batch-status {
  flex: 0 0 auto;
  color: #4d5661;
  font-size: 10px;
  text-align: right;
}

.status-qr_ready .batch-status {
  color: var(--green);
  font-weight: 700;
}

.status-failed .batch-status,
.status-expired .batch-status {
  color: #c72d26;
  font-weight: 700;
}

.batch-card-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding-top: 8px;
}

.batch-card-copy {
  min-width: 0;
}

.batch-card p {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.batch-card .batch-product {
  color: #2f353c;
  font-size: 11px;
}

.batch-proxy.is-bound {
  color: #087b41;
}

.batch-proxy.is-testing {
  color: #a46700;
}

.batch-card .batch-error {
  margin-top: 7px;
  padding: 7px 8px;
  border-radius: 4px;
  background: #fff1f0;
  color: #a9231d;
}

.batch-qr {
  width: 220px;
  display: grid;
  justify-items: center;
  gap: 5px;
}

.batch-qr img {
  display: block;
  width: 220px;
  height: 220px;
  aspect-ratio: 1;
  background: #fff;
  border: 5px solid #fff;
}

.batch-qr-links {
  display: flex;
  gap: 12px;
  min-height: 16px;
  font-size: 10px;
}

.batch-qr-links a {
  color: var(--red);
  text-decoration: none;
}

.option-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1.25fr 1.15fr;
  gap: 8px;
  margin-top: 1px;
}

.network-fields {
  display: grid;
  gap: 5px;
  margin-top: 2px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.network-option-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.network-option-grid > div,
.address-fields {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.address-fields textarea {
  height: 70px;
  min-height: 60px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
}

.checkbox-label input {
  width: 14px;
  height: 14px;
  margin: 0;
}

.proxy-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
}

.proxy-grid > div {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.proxy-server-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 58px;
  gap: 5px;
  min-width: 0;
}

.secondary-button {
  height: 34px;
  border: 1px solid #cbd0d7;
  border-radius: 4px;
  background: #f7f8f9;
  color: #3b4148;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
}

.secondary-button:hover:not(:disabled) {
  border-color: #8d96a1;
  background: #eef0f2;
}

.secondary-button:disabled {
  cursor: wait;
  opacity: .6;
}

.proxy-test-result {
  min-height: 15px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.4;
}

.proxy-test-result.is-testing {
  color: #a56b00;
}

.proxy-test-result.is-ok {
  color: var(--green);
}

.proxy-test-result.is-error {
  color: var(--red);
}

.option-grid > div {
  display: grid;
  gap: 4px;
  min-width: 0;
}

input:focus,
textarea:focus,
select:focus {
  border-color: #666e78;
  box-shadow: 0 0 0 2px rgba(32, 35, 40, 0.08);
}

.primary-button {
  height: 38px;
  margin-top: 6px;
  border: 0;
  border-radius: 4px;
  background: var(--red);
  color: #fff;
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
}

.primary-button:hover:not(:disabled) {
  background: var(--red-dark);
}

.primary-button:disabled {
  cursor: wait;
  background: #a7abb1;
}

.dynamic-form {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.product-summary {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  gap: 12px;
  align-items: center;
  margin-bottom: 4px;
}

.product-summary img {
  width: 56px;
  height: 56px;
  border: 1px solid var(--line);
  border-radius: 4px;
  object-fit: cover;
}

.product-summary h3 {
  margin: 0;
  font-size: 12px;
  line-height: 1.4;
  font-weight: 600;
}

.product-summary strong {
  color: var(--red);
  font-size: 14px;
}

#dynamicFields {
  display: grid;
  gap: 5px;
}

.field-message {
  min-height: 10px;
  color: var(--muted);
  font-size: 11px;
}

.qr-empty,
.qr-result {
  min-height: 0;
  flex: 1;
}

.qr-empty {
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 11px;
}

.qr-placeholder {
  position: relative;
  width: clamp(130px, 21dvh, 220px);
  aspect-ratio: 1;
  border: 1px dashed #b8bec6;
  background: #fff;
  box-shadow: inset 0 0 0 16px #f1f3f5;
}

.qr-placeholder::before,
.qr-placeholder::after {
  content: "";
  position: absolute;
  width: 54px;
  height: 54px;
  border: 12px solid #c7ccd2;
}

.qr-placeholder::before {
  top: 36px;
  left: 36px;
}

.qr-placeholder::after {
  right: 36px;
  bottom: 36px;
}

.qr-result {
  display: grid;
  align-content: start;
  justify-items: center;
  gap: 10px;
}

.segmented-control {
  display: flex;
  width: min(320px, 100%);
  height: 32px;
  padding: 3px;
  background: #e9ecef;
  border-radius: 5px;
}

.segment-button {
  flex: 1;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: #555d66;
  cursor: pointer;
  font-size: 12px;
}

.segment-button.active {
  background: #fff;
  color: #17191c;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

#qrImage {
  display: block;
  width: min(340px, 100%);
  height: auto;
  aspect-ratio: 1;
  background: #fff;
  border: 10px solid #fff;
}

.amount-line {
  width: min(390px, 100%);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
}

.amount-line strong {
  color: var(--red);
  font-size: 18px;
}

.log-section {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: #202328;
  color: #edf0f3;
  border-radius: 6px;
  overflow: hidden;
}

.log-header {
  min-height: 48px;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #3b4047;
}

.log-header .section-heading p {
  color: #9ea5ae;
}

.quiet-button {
  border: 0;
  background: transparent;
  color: #bcc2c9;
  cursor: pointer;
  font-size: 12px;
}

.quiet-button:hover {
  color: #fff;
}

.logs {
  min-height: 0;
  max-height: none;
  margin: 0;
  padding: 6px 0;
  overflow: auto;
  list-style: none;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 11px;
}

.log-item {
  display: grid;
  grid-template-columns: 84px 58px 86px minmax(0, 1fr);
  gap: 8px;
  padding: 4px 16px;
  border-left: 2px solid transparent;
  line-height: 1.4;
}

.log-item:hover {
  background: #282c31;
}

.log-item.error {
  border-left-color: #ff4d45;
}

.log-item.warn {
  border-left-color: #f3a72f;
}

.log-time,
.log-stage {
  color: #8f98a2;
}

.log-level {
  color: #c8cdd3;
  text-transform: uppercase;
}

.log-message {
  overflow-wrap: anywhere;
}

@media (max-width: 820px) {
  main {
    width: min(100% - 20px, 620px);
    height: auto;
    min-height: 0;
    margin: 8px auto 32px;
    display: block;
  }

  .topbar {
    padding-inline: 12px;
  }

  .topbar p {
    display: none;
  }

  h1 {
    font-size: 14px;
  }

  .status-indicator {
    font-size: 11px;
  }

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

  .control-pane,
  .result-pane {
    overflow: visible;
  }

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

  .result-pane {
    display: block;
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .qr-empty,
  .qr-result {
    min-height: 340px;
  }

  .qr-placeholder {
    width: min(220px, 62vw);
  }

  .batch-result {
    overflow: visible;
  }

  .batch-items {
    max-height: none;
    overflow: visible;
  }

  .batch-card-body {
    grid-template-columns: 1fr;
  }

  .batch-qr {
    width: min(260px, 100%);
    justify-self: center;
  }

  .batch-qr img {
    width: min(260px, 100%);
    height: auto;
  }

  .log-section {
    margin-top: 18px;
    display: block;
  }

  .logs {
    min-height: 150px;
    max-height: 300px;
  }

  .log-item {
    grid-template-columns: 72px 52px minmax(0, 1fr);
  }

  .log-stage {
    display: none;
  }
}

@media (max-width: 430px) {
  .brand-mark {
    width: 32px;
    height: 32px;
  }

  .status-indicator span:last-child {
    display: none;
  }

  .control-pane,
  .result-pane {
    padding: 15px 12px;
  }

  .product-summary {
    grid-template-columns: 48px minmax(0, 1fr);
  }

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

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

  .batch-import-grid {
    grid-template-columns: 1fr;
  }

  .batch-option-grid {
    grid-template-columns: 1fr;
  }

  .batch-plan {
    grid-column: 1 / -1;
  }

  .saved-picker-row,
  .account-source-grid {
    grid-template-columns: 1fr;
  }

  .product-summary img {
    width: 48px;
    height: 48px;
  }

  .product-summary strong {
    grid-column: 2;
  }

  .log-item {
    grid-template-columns: 60px minmax(0, 1fr);
  }

  .log-level {
    display: none;
  }
}
