:root {
  color-scheme: light;
  --page: #f7faf8;
  --panel: #ffffff;
  --text: #121915;
  --muted: #65736b;
  --line: #dfe8e2;
  --line-strong: #c7d8ce;
  --green: #16824a;
  --green-soft: #eef8f2;
  --green-pale: #f7fcf9;
  --danger: #b42318;
  --success: #147b45;
  --shadow: 0 18px 46px rgba(18, 25, 21, .07);
}

* { box-sizing: border-box; }

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

button, input, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  padding: 0 max(22px, calc((100vw - 1220px) / 2));
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .94);
  backdrop-filter: blur(12px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-weight: 850;
}

.brand-mark {
  display: inline-grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 8px;
  background: var(--text);
  color: #fff;
  font-weight: 900;
}

.topbar-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  transform: translateX(clamp(-120px, -8vw, -72px));
}

.ghost-button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 0 13px;
  font-size: 14px;
  font-weight: 750;
  cursor: pointer;
  text-decoration: none;
}

.ghost-button:hover { border-color: var(--line-strong); background: var(--green-pale); }
.ghost-button:disabled { cursor: not-allowed; color: #98a39c; background: #f2f5f3; }
.link-button { display: inline-flex; align-items: center; }

.points-balance {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  white-space: nowrap;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--green-soft);
  color: var(--green);
  padding: 0 12px;
  font-size: 14px;
  font-weight: 850;
}

.shell {
  width: min(1220px, calc(100vw - 36px));
  margin: 0 auto;
  padding: 24px 0 36px;
}

.hero-strip {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
  padding: 10px 2px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--green);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: .08em;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 28px; line-height: 1.2; }
h2 { margin-bottom: 0; font-size: 18px; line-height: 1.25; }

.status-pill {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  white-space: nowrap;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  padding: 0 12px;
  font-size: 13px;
  font-weight: 750;
}

.status-pill.is-success { color: var(--success); border-color: #bfdfca; background: var(--green-soft); }
.status-pill.is-error { color: var(--danger); border-color: #f0c8c4; background: #fff7f6; }

.workflow-grid {
  display: grid;
  grid-template-columns: minmax(320px, 390px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.form-panel, .result-panel { padding: 18px; }

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-head p, #login-note {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.result-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.workflow-progress {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 180px;
}

.workflow-progress[hidden] {
  display: none;
}

.progress-track {
  width: 120px;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #dcfce7;
  border: 1px solid #bbf7d0;
}

.progress-fill {
  display: block;
  height: 100%;
  width: 0%;
  background: #22c55e;
  transition: width 240ms ease;
}

.progress-text {
  color: #166534;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.dynamic-fields {
  display: grid;
  gap: 14px;
}

.field {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.field > span {
  color: var(--text);
  font-weight: 800;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.field small, .hint-text {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}

textarea {
  min-height: 220px;
  padding: 12px;
  resize: vertical;
  line-height: 1.65;
}

input:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid rgba(22, 130, 74, .28);
  outline-offset: 2px;
}

input:disabled, textarea:disabled {
  background: #f2f5f3;
  color: #8a958f;
}

.upload-field { gap: 9px; }

.upload-control {
  position: relative;
  display: grid;
  min-height: 124px;
  place-items: center;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: #fff;
  padding: 18px;
  cursor: pointer;
  text-align: center;
  transition: border-color .18s ease, background-color .18s ease, box-shadow .18s ease;
}

.upload-control:hover,
.upload-control:focus-within {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(22, 130, 74, .10);
}

.upload-control input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.upload-control input[type="file"]:disabled {
  cursor: not-allowed;
}

.upload-copy {
  display: grid;
  min-width: 0;
  gap: 7px;
  justify-items: center;
}

.upload-copy::before {
  content: "";
  display: block;
  width: 28px;
  height: 28px;
  margin-bottom: 2px;
  border: 2px solid #9fcbaa;
  border-radius: 8px;
  opacity: .85;
}

.upload-copy strong {
  color: var(--green);
  font-size: 15px;
  font-weight: 900;
}

.upload-copy small {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.upload-status {
  position: absolute;
  right: 14px;
  bottom: 12px;
  display: inline-flex;
  align-items: center;
  max-width: min(220px, calc(100% - 28px));
  min-height: 28px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green);
  padding: 0 10px;
  font-size: 12px;
  font-weight: 850;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-field.has-file .upload-control {
  border-style: solid;
  border-color: rgba(22, 130, 74, .55);
  background: linear-gradient(180deg, #ffffff 0%, var(--green-soft) 100%);
}

.upload-field.has-file .upload-status {
  background: var(--green);
  color: #fff;
}

.selected-images {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.selected-image {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.selected-image img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--green-pale);
}

.selected-image span {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workflow-type-badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
  background: #fff;
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.billing-notice {
  margin: 16px 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.run-button {
  width: 100%;
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: var(--text);
  color: #fff;
  font-weight: 850;
  cursor: pointer;
}

.run-button:hover { background: #243229; }
.run-button:disabled { cursor: not-allowed; background: #8b9690; }

.result-panel {
  min-height: 640px;
}

.raw-output {
  min-height: 54px;
  max-height: 190px;
  overflow: auto;
  margin: 0 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: #26352c;
  padding: 12px;
  font: 13px/1.65 ui-monospace, SFMono-Regular, Menlo, Consolas, "Microsoft YaHei", monospace;
  white-space: pre-wrap;
  word-break: break-word;
}

.image-output-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  min-height: 480px;
}

.empty-result {
  grid-column: 1 / -1;
  display: grid;
  min-height: 480px;
  align-content: center;
  justify-items: center;
  gap: 8px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: #fff;
  text-align: center;
}

.empty-result strong {
  color: var(--text);
  font-size: 18px;
}

.empty-result p {
  width: min(420px, 100%);
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

.image-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.image-card img {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  background: var(--green-pale);
}

.image-card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 42px;
  padding: 0 10px;
  color: var(--muted);
  font-size: 13px;
}

.image-card-foot a {
  color: var(--green);
  font-weight: 800;
  text-decoration: none;
}

.records-modal[hidden] { display: none; }

.records-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(18, 25, 21, .36);
}

.records-dialog {
  width: min(clamp(980px, 72vw, 1280px), calc(100vw - 48px));
  max-height: min(calc(100vh - 48px), 900px);
  overflow: hidden;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(18, 25, 21, .22);
}

.records-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.records-retention-notice {
  margin-left: auto;
  max-width: min(560px, 58vw);
  border: 1px solid rgba(22, 130, 74, .22);
  border-radius: 8px;
  background: #f0fdf4;
  color: #166534;
  padding: 8px 12px;
  font-size: 13px;
  line-height: 1.45;
  font-weight: 700;
}

.records-retention-notice[hidden] {
  display: none;
}

.icon-button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}

.records-list {
  display: grid;
  gap: 12px;
  max-height: calc(100vh - 130px);
  overflow: auto;
  padding: 16px 18px;
}

.record-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.record-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  color: var(--text);
  font-size: 13px;
}

.record-status {
  color: var(--green);
  font-weight: 800;
}

.record-item p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.65;
  word-break: break-word;
}

.record-item small {
  display: inline-block;
  margin-top: 8px;
  color: var(--green);
  font-weight: 800;
}

.harddrive-copy-button {
  width: fit-content;
  margin: 2px 0 10px;
  padding: 8px 12px;
  font-size: 12px;
}

.harddrive-details {
  border: 1px solid rgba(38, 112, 77, .16);
  border-radius: 8px;
  background: #ffffff;
  overflow: hidden;
}

.harddrive-summary {
  cursor: pointer;
  padding: 10px 12px;
  color: #17633f;
  font-size: 13px;
  font-weight: 800;
  list-style-position: inside;
}

.harddrive-summary:focus-visible {
  outline: 2px solid rgba(38, 112, 77, .35);
  outline-offset: 2px;
}

.harddrive-output {
  border-top: 1px solid rgba(38, 112, 77, .12);
  padding: 12px;
  overflow-wrap: anywhere;
}

.harddrive-output p {
  margin: 0;
  color: var(--text);
  font-size: 13px;
  line-height: 1.7;
  white-space: pre-wrap;
}

.harddrive-image-preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 10px;
  margin: 0 0 12px;
}

.harddrive-image-preview {
  display: block;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--green-pale);
}

.harddrive-image-preview:focus-visible {
  outline: 2px solid rgba(38, 112, 77, .35);
  outline-offset: 2px;
}

.harddrive-image-preview img {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
}

.harddrive-output-section {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.harddrive-output-section:last-child {
  margin-bottom: 0;
}

.harddrive-output-section > strong {
  color: var(--black);
  font-size: 13px;
}

.records-empty {
  display: grid;
  min-height: 160px;
  place-items: center;
  color: var(--muted);
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
}

.is-error { color: var(--danger); }
.is-success { color: var(--success); }

@media (max-width: 860px) {
  .topbar {
    position: static;
    align-items: flex-start;
    flex-direction: column;
    padding: 14px 18px;
  }
  .topbar-actions { width: 100%; justify-content: flex-start; transform: none; }
  .points-balance { min-height: 34px; font-size: 13px; }
  .hero-strip { align-items: flex-start; flex-direction: column; }
  .workflow-grid { grid-template-columns: minmax(0, 1fr); }
  .panel { min-width: 0; }
  .image-output-grid { grid-template-columns: 1fr; }
  .selected-images { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 520px) {
  .shell { width: min(100% - 24px, 1220px); padding-top: 16px; }
  h1 { font-size: 23px; }
  .topbar-actions {
    display: grid;
    width: 100%;
    max-width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .ghost-button, .points-balance {
    min-width: 0;
    width: 100%;
    justify-content: center;
    padding-left: 8px;
    padding-right: 8px;
  }
  .selected-images { grid-template-columns: 1fr; }
}
