/* 亚马逊 Listing 生成器 — Mini App 视觉基线
   变量取自 --mcode-* 语义角色；组件样式不直接写主题色值。 */

:root,
[data-theme='light'] {
  --mcode-bg: #ffffff;
  --mcode-bg-secondary: #f5f5f5;
  --mcode-surface: #ffffff;
  --mcode-surface-muted: #fafafa;
  --mcode-text: #171717;
  --mcode-text-muted: #666666;
  --mcode-text-subtle: #adadad;
  --mcode-border: #0a0a0a14;
  --mcode-border-strong: #0a0a0af2;
  --mcode-accent: #0094fc;
  --mcode-success: #04b54b;
  --mcode-warning: #f56811;
  --mcode-danger: #f73646;
  --mcode-primary-action-bg: #171717;
  --mcode-primary-action-text: #ffffff;
  --mcode-shadow: 0 0 20px rgb(10 10 10 / 8%);
}

[data-theme='dark'] {
  --mcode-bg: #171717;
  --mcode-bg-secondary: #1c1c1c;
  --mcode-surface: #262626;
  --mcode-surface-muted: #262626;
  --mcode-text: #ededed;
  --mcode-text-muted: #949494;
  --mcode-text-subtle: #666666;
  --mcode-border: #ffffff14;
  --mcode-border-strong: #fffffff2;
  --mcode-accent: #0077d9;
  --mcode-success: #009c3d;
  --mcode-warning: #e25507;
  --mcode-danger: #e31937;
  --mcode-primary-action-bg: #ffffff;
  --mcode-primary-action-text: #171717;
  --mcode-shadow: 0 0 20px rgb(0 0 0 / 32%);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --mcode-bg: #171717;
    --mcode-bg-secondary: #1c1c1c;
    --mcode-surface: #262626;
    --mcode-surface-muted: #262626;
    --mcode-text: #ededed;
    --mcode-text-muted: #949494;
    --mcode-text-subtle: #666666;
    --mcode-border: #ffffff14;
    --mcode-border-strong: #fffffff2;
    --mcode-accent: #0077d9;
    --mcode-success: #009c3d;
    --mcode-warning: #e25507;
    --mcode-danger: #e31937;
    --mcode-primary-action-bg: #ffffff;
    --mcode-primary-action-text: #171717;
    --mcode-shadow: 0 0 20px rgb(0 0 0 / 32%);
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--mcode-bg-secondary);
  color: var(--mcode-text);
  font-family: ui-sans-serif, -apple-system, system-ui, 'Segoe UI', Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 600;
  line-height: 1.35;
}

p {
  margin: 0;
}

ul,
ol {
  margin: 0;
  padding: 0;
  list-style: none;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 2px solid var(--mcode-accent);
  outline-offset: 2px;
}

/* ---------- 布局 ---------- */

.shell {
  display: flex;
  min-height: 100vh;
  align-items: stretch;
}

.sidebar {
  width: 232px;
  flex: 0 0 232px;
  border-right: 1px solid var(--mcode-border);
  background: var(--mcode-bg);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sidebar-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.brand {
  font-size: 15px;
  font-weight: 600;
}

.brand-sub {
  color: var(--mcode-text-subtle);
  font-size: 12px;
}

.nav-label {
  color: var(--mcode-text-subtle);
  font-size: 12px;
  letter-spacing: 0.02em;
}

.project-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.project-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

.project-del {
  flex: 0 0 auto;
  opacity: 0.55;
}

.project-row:hover .project-del,
.project-del:focus-visible {
  opacity: 1;
}

.project-item {
  flex: 1;
  min-width: 0;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  color: var(--mcode-text);
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
  font: inherit;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.project-item:hover {
  background: var(--mcode-surface-muted);
}

.project-item[aria-current='true'] {
  background: var(--mcode-surface-muted);
  border-color: var(--mcode-border-strong);
}

.project-name {
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-meta {
  font-size: 12px;
  color: var(--mcode-text-subtle);
  display: flex;
  align-items: center;
  gap: 6px;
}

.runtime-status {
  border-top: 1px solid var(--mcode-border);
  padding-top: 12px;
  font-size: 12px;
  color: var(--mcode-text-muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.main {
  flex: 1;
  min-width: 0;
  padding: 24px 24px 56px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.page-head h1 {
  font-size: 18px;
  line-height: 28px;
}

.page-desc {
  color: var(--mcode-text-muted);
  margin-top: 4px;
  max-width: 62ch;
}

.page-head-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* 流程指示：出方案 → 拍板 → 出全案 */
.steps {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
  flex: 0 0 auto;
}

.steps li {
  font-size: 12px;
  color: var(--mcode-text-subtle);
  border: 1px solid var(--mcode-border);
  border-radius: 999px;
  padding: 3px 10px;
  white-space: nowrap;
}

.steps li.is-done {
  color: var(--mcode-success);
  border-color: var(--mcode-success);
}

.steps li.is-current {
  color: var(--mcode-accent);
  border-color: var(--mcode-accent);
  font-weight: 500;
}

.foot-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.run-status {
  font-size: 12px;
  color: var(--mcode-text-muted);
}

.run-status.is-error {
  color: var(--mcode-danger);
}

.revise-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.revise-row input[type='text'] {
  flex: 1;
  min-width: 0;
}

/* ---------- 卡片 ---------- */

.card {
  background: var(--mcode-surface);
  border: 1px solid var(--mcode-border);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.card-head h2 {
  font-size: 16px;
  line-height: 24px;
}

.card-hint {
  color: var(--mcode-text-subtle);
  font-size: 12px;
}

.card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.save-hint {
  color: var(--mcode-text-subtle);
  font-size: 12px;
}

/* ---------- 表单 ---------- */

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

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field-wide {
  grid-column: 1 / -1;
}

.field-label {
  font-size: 13px;
  color: var(--mcode-text);
  display: flex;
  align-items: center;
  gap: 6px;
}

.field-label em {
  font-style: normal;
  font-size: 11px;
  color: var(--mcode-danger);
  border: 1px solid var(--mcode-danger);
  border-radius: 999px;
  padding: 0 6px;
  line-height: 16px;
}

.field-note {
  font-size: 12px;
  color: var(--mcode-text-subtle);
}

input[type='text'],
textarea,
select {
  font: inherit;
  color: var(--mcode-text);
  background: var(--mcode-surface-muted);
  border: 1px solid var(--mcode-border);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
  min-height: 36px;
}

textarea {
  resize: vertical;
  line-height: 1.6;
}

input[type='text']::placeholder,
textarea::placeholder {
  color: var(--mcode-text-subtle);
}

input[type='text']:focus,
textarea:focus {
  border-color: var(--mcode-border-strong);
  background: var(--mcode-surface);
}

/* ---------- 按钮 ---------- */

.btn {
  font: inherit;
  font-size: 13px;
  height: 34px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid var(--mcode-border);
  background: var(--mcode-surface-muted);
  color: var(--mcode-text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background-color 150ms ease-out, opacity 150ms ease-out;
}

.btn:hover:not(:disabled) {
  border-color: var(--mcode-border-strong);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--mcode-primary-action-bg);
  color: var(--mcode-primary-action-text);
  border-color: transparent;
}

.btn-primary:hover:not(:disabled) {
  opacity: 0.88;
}

.btn-danger {
  color: var(--mcode-danger);
  border-color: var(--mcode-danger);
  background: transparent;
}

.btn-sm {
  height: 28px;
  padding: 0 10px;
  font-size: 12px;
}

.btn-upload {
  border-style: dashed;
  height: 40px;
  padding: 0 20px;
}

/* ---------- 状态标签 ---------- */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  line-height: 20px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--mcode-border);
  background: var(--mcode-surface-muted);
  color: var(--mcode-text-muted);
  white-space: nowrap;
}

.pill-running {
  color: var(--mcode-accent);
  border-color: var(--mcode-accent);
}

.pill-done {
  color: var(--mcode-success);
  border-color: var(--mcode-success);
}

.pill-failed {
  color: var(--mcode-danger);
  border-color: var(--mcode-danger);
}

.pill-waiting {
  color: var(--mcode-warning);
  border-color: var(--mcode-warning);
}

/* ---------- 空状态 ---------- */

.empty-state {
  background: var(--mcode-surface);
  border: 1px solid var(--mcode-border);
  border-radius: 12px;
  padding: 48px 24px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.empty-state h2 {
  font-size: 16px;
}

.empty-state p {
  color: var(--mcode-text-muted);
  max-width: 46ch;
}

/* ---------- 上传 ---------- */

.upload-zone {
  border: 1px dashed var(--mcode-border-strong);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: var(--mcode-surface-muted);
}

.upload-note {
  color: var(--mcode-text-subtle);
  font-size: 12px;
}

.upload-label {
  font-size: 13px;
  color: var(--mcode-text);
}

.file-input {
  font: inherit;
  font-size: 13px;
  color: var(--mcode-text);
  max-width: 100%;
}

.file-input::file-selector-button {
  font: inherit;
  font-size: 13px;
  height: 34px;
  padding: 0 14px;
  margin-right: 10px;
  border-radius: 8px;
  border: 1px solid var(--mcode-border);
  background: var(--mcode-surface);
  color: var(--mcode-text);
  cursor: pointer;
}

.file-input::file-selector-button:hover {
  border-color: var(--mcode-border-strong);
}

.source-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 12px;
}

.source-card {
  border: 1px solid var(--mcode-border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--mcode-surface-muted);
  display: flex;
  flex-direction: column;
}

.source-thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  background: var(--mcode-bg);
  display: block;
}

.source-foot {
  padding: 6px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 12px;
  color: var(--mcode-text-muted);
}

.source-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  border: 1px solid var(--mcode-border);
  background: var(--mcode-surface);
  color: var(--mcode-text-muted);
  border-radius: 6px;
  width: 24px;
  height: 24px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.icon-btn:hover {
  color: var(--mcode-danger);
  border-color: var(--mcode-danger);
}

.icon-btn.is-danger {
  color: var(--mcode-danger);
  border-color: var(--mcode-danger);
}

.row-confirm {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* ---------- 运行 ---------- */

.run-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.ask-card {
  border: 1px solid var(--mcode-warning);
  border-radius: 12px;
  padding: 16px;
  background: var(--mcode-surface);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ask-card h3 {
  font-size: 15px;
}

.ask-reason {
  color: var(--mcode-text);
}

.ask-meta {
  color: var(--mcode-text-muted);
  font-size: 12px;
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  word-break: break-all;
}

.ask-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.q-step {
  border: 1px solid var(--mcode-border);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--mcode-surface-muted);
}

.q-step + .q-step {
  margin-top: 8px;
}

.q-question {
  font-weight: 500;
}

.q-desc {
  color: var(--mcode-text-muted);
  font-size: 12px;
}

.q-options {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.q-option {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  border: 1px solid var(--mcode-border);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--mcode-surface);
  cursor: pointer;
}

.q-option:hover {
  border-color: var(--mcode-border-strong);
}

.q-option input {
  margin: 3px 0 0;
  accent-color: var(--mcode-accent);
}

.q-option-body {
  display: flex;
  flex-direction: column;
}

.q-other {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.progress {
  border: 1px solid var(--mcode-border);
  border-radius: 8px;
  padding: 12px;
  background: var(--mcode-surface-muted);
}

.progress > summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--mcode-text-muted);
  user-select: none;
}

.event-log {
  margin-top: 10px;
  max-height: 260px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.event-row {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  font-size: 12px;
  color: var(--mcode-text-muted);
}

.event-time {
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--mcode-text-subtle);
  flex: 0 0 auto;
}

.event-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-top: 7px;
  flex: 0 0 auto;
  background: var(--mcode-text-subtle);
}

.event-text {
  min-width: 0;
  word-break: break-word;
}

.event-error .event-dot {
  background: var(--mcode-danger);
}

.event-question .event-dot {
  background: var(--mcode-warning);
}

.event-permission .event-dot {
  background: var(--mcode-accent);
}

.event-status .event-dot {
  background: var(--mcode-success);
}

.stream-text {
  margin: 10px 0 0;
  padding: 10px;
  max-height: 220px;
  overflow: auto;
  background: var(--mcode-surface);
  border: 1px solid var(--mcode-border);
  border-radius: 8px;
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------- 交付 ---------- */

.deliver-body {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.deliver-empty {
  color: var(--mcode-text-subtle);
  font-size: 13px;
  padding: 12px 0;
}

.listing-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.listing-block + .listing-block {
  margin-top: 14px;
}

.listing-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.listing-title {
  font-size: 14px;
  font-weight: 600;
}

.listing-count {
  font-size: 12px;
  color: var(--mcode-text-subtle);
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

.listing-text {
  background: var(--mcode-surface-muted);
  border: 1px solid var(--mcode-border);
  border-radius: 8px;
  padding: 10px 12px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.65;
}

.copy-btn {
  border: 1px solid var(--mcode-border);
  background: var(--mcode-surface);
  color: var(--mcode-text-muted);
  border-radius: 6px;
  height: 24px;
  padding: 0 8px;
  font-size: 12px;
  cursor: pointer;
}

.copy-btn:hover {
  color: var(--mcode-accent);
  border-color: var(--mcode-accent);
}

.shot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.shot {
  border: 1px solid var(--mcode-border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--mcode-surface-muted);
  display: flex;
  flex-direction: column;
}

.shot img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  background: var(--mcode-bg);
  cursor: zoom-in;
  display: block;
}

.shot-foot {
  padding: 6px 8px;
  font-size: 12px;
  color: var(--mcode-text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.shot-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.file-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 8px;
  border-radius: 8px;
  font-size: 13px;
}

.file-row:hover {
  background: var(--mcode-surface-muted);
}

.file-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-size {
  color: var(--mcode-text-subtle);
  font-size: 12px;
  flex: 0 0 auto;
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

.note-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.note-item {
  border: 1px solid var(--mcode-border);
  border-left: 3px solid var(--mcode-warning);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--mcode-surface-muted);
  font-size: 13px;
}

.note-item.is-question {
  border-left-color: var(--mcode-accent);
}

.note-title {
  font-weight: 500;
  margin-bottom: 2px;
}

.note-sub {
  color: var(--mcode-text-muted);
  font-size: 12px;
}

.subhead {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
}

/* ---------- 灯箱 / 提示 ---------- */

.lightbox {
  border: 1px solid var(--mcode-border);
  border-radius: 12px;
  padding: 20px;
  background: var(--mcode-surface);
  color: var(--mcode-text);
  max-width: min(860px, 92vw);
  box-shadow: var(--mcode-shadow);
}

.lightbox::backdrop {
  background: rgb(0 0 0 / 55%);
}

.lightbox img {
  max-width: 100%;
  max-height: 70vh;
  display: block;
  border-radius: 8px;
}

.lightbox-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid var(--mcode-border);
  background: var(--mcode-surface);
  color: var(--mcode-text);
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
}

.lightbox-caption {
  margin-top: 10px;
  font-size: 12px;
  color: var(--mcode-text-muted);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: var(--mcode-text);
  color: var(--mcode-bg);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: var(--mcode-shadow);
  z-index: 40;
}

/* 失败提示：红色常驻显示，点一下关闭。 */
.toast.is-error {
  background: var(--mcode-danger);
  color: #fff;
  cursor: pointer;
  max-width: min(90vw, 640px);
}

/* ---------- 窄屏 ---------- */

@media (max-width: 900px) {
  .shell {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    flex: none;
    border-right: none;
    border-bottom: 1px solid var(--mcode-border);
    max-height: 220px;
  }

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

  .main {
    padding: 16px 16px 48px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}
