:root {
  color-scheme: light;
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-subtle: #f7f8fa;
  --border: #dfe3e8;
  --border-strong: #cbd2d9;
  --text: #161a1d;
  --muted: #68717a;
  --green: #16794a;
  --green-dark: #0e5e38;
  --green-soft: #e7f5ed;
  --blue: #2867b2;
  --blue-soft: #eaf2fb;
  --amber: #9a6300;
  --amber-soft: #fff4d8;
  --red: #b4232d;
  --red-soft: #fdecef;
  --shadow: 0 16px 48px rgba(24, 32, 39, 0.12);
  --radius: 8px;
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  letter-spacing: 0;
}

button, input, textarea { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.55; }

svg { width: 18px; height: 18px; flex: 0 0 auto; }

.app-shell { min-height: 100vh; }

.topbar {
  min-height: 68px;
  padding: 10px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand-block, .topbar-actions, .section-heading, .label-row, .submit-row,
.control-row, .dialog-heading, .dialog-actions, .result-header, .result-actions {
  display: flex;
  align-items: center;
}

.brand-block { gap: 12px; min-width: 0; }
.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  color: #fff;
  background: #182c25;
  border-radius: 7px;
}
.brand-mark svg { width: 20px; height: 20px; }

h1, h2, p { margin: 0; }
h1 { font-size: 16px; line-height: 1.3; font-weight: 700; }
h2 { font-size: 17px; line-height: 1.35; font-weight: 700; }
.brand-block p, .section-heading p, .result-header p {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.topbar-actions { gap: 8px; }
.quota {
  min-width: 104px;
  height: 38px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  gap: 9px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-subtle);
}
.quota span { color: var(--muted); font-size: 12px; white-space: nowrap; }
.quota strong { font-size: 16px; color: var(--green); }

.icon-button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: #3c464f;
  display: inline-grid;
  place-items: center;
  padding: 0;
}
.icon-button:hover { border-color: var(--border-strong); background: var(--surface-subtle); }
.icon-button:focus-visible, .primary-button:focus-visible, .secondary-button:focus-visible,
.tab-button:focus-visible, .upload-zone:focus-visible, textarea:focus-visible, input:focus-visible,
.segments input:focus-visible + span {
  outline: 3px solid rgba(40, 103, 178, 0.18);
  outline-offset: 2px;
}

.workspace {
  min-height: calc(100vh - 68px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 420px);
  max-width: 1480px;
  margin: 0 auto;
  background: var(--surface);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

.composer { padding: 26px 30px 36px; min-width: 0; }
.jobs-panel {
  border-left: 1px solid var(--border);
  background: var(--surface-subtle);
  min-width: 0;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 68px);
  position: sticky;
  top: 68px;
}

.section-heading { justify-content: space-between; gap: 18px; margin-bottom: 26px; }
.section-heading.compact {
  min-height: 74px;
  padding: 14px 18px;
  margin: 0;
  border-bottom: 1px solid var(--border);
  align-items: flex-start;
}
.worker-state {
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  font-size: 12px;
  white-space: nowrap;
}
.worker-state span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #8d959d;
}
.worker-state.online span { background: var(--green); }
.worker-state.error span { background: var(--red); }

#jobForm { max-width: 860px; }
.field-group { margin: 0 0 24px; min-width: 0; border: 0; padding: 0; }
.field-group > label, .field-group legend, .label-row label, dialog label {
  display: block;
  font-size: 13px;
  line-height: 1.4;
  font-weight: 650;
  margin-bottom: 8px;
}
.label-row { justify-content: space-between; gap: 12px; }
.label-row span, .field-meta { color: var(--muted); font-size: 12px; }
.field-meta { display: flex; justify-content: flex-end; margin-top: 6px; }

textarea, dialog input {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  padding: 12px 13px;
  line-height: 1.65;
  resize: vertical;
}
textarea { min-height: 184px; max-height: 420px; }
textarea::placeholder, input::placeholder { color: #99a1a8; }
textarea:focus, dialog input:focus { border-color: var(--blue); outline: none; }

.control-row { align-items: flex-end; gap: 18px; margin-bottom: 24px; }
.control-row .field-group { margin: 0; flex: 1; }
.segments {
  display: grid;
  grid-template-columns: repeat(6, minmax(62px, 1fr));
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 40px;
}
.segments label { min-width: 0; }
.segments input { position: absolute; opacity: 0; pointer-events: none; }
.segments span {
  min-height: 40px;
  display: grid;
  place-items: center;
  padding: 0 8px;
  border-left: 1px solid var(--border);
  color: #4f5962;
  background: #fff;
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
  cursor: pointer;
}
.segments label:first-child span { border-left: 0; }
.segments input:checked + span { background: var(--green-soft); color: var(--green-dark); }
.fixed-setting {
  min-width: 108px;
  min-height: 40px;
  padding: 0 12px;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-subtle);
}
.fixed-setting span { font-size: 12px; color: var(--muted); }
.fixed-setting strong { white-space: nowrap; }

.upload-zone {
  width: 100%;
  min-height: 92px;
  border: 1px dashed #aeb8c1;
  border-radius: var(--radius);
  background: var(--surface-subtle);
  color: #404a53;
  display: grid;
  grid-template-columns: 24px auto;
  grid-template-rows: auto auto;
  align-content: center;
  justify-content: center;
  column-gap: 10px;
  text-align: left;
}
.upload-zone svg { grid-row: 1 / 3; align-self: center; color: var(--blue); }
.upload-zone span { font-weight: 650; }
.upload-zone small { color: var(--muted); font-size: 11px; }
.upload-zone:hover { border-color: var(--blue); background: var(--blue-soft); }

.asset-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}
.asset-item {
  aspect-ratio: 1;
  position: relative;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  background: #e9ecef;
}
.asset-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.asset-item .asset-progress {
  position: absolute;
  inset: auto 0 0;
  height: 4px;
  background: rgba(255,255,255,0.65);
}
.asset-item .asset-progress progress {
  width: 100%;
  height: 4px;
  display: block;
  border: 0;
  appearance: none;
  background: rgba(255,255,255,0.65);
}
.asset-item .asset-progress progress::-webkit-progress-bar { background: rgba(255,255,255,0.65); }
.asset-item .asset-progress progress::-webkit-progress-value { background: var(--blue); }
.asset-item .asset-progress progress::-moz-progress-bar { background: var(--blue); }
.asset-item.uploaded .asset-progress { display: none; }
.asset-item.failed { border-color: var(--red); }
.asset-remove {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 6px;
  display: grid;
  place-items: center;
  padding: 0;
  color: #fff;
  background: rgba(19, 24, 28, 0.78);
}
.asset-remove svg { width: 15px; height: 15px; }

.submit-row {
  justify-content: space-between;
  gap: 16px;
  padding-top: 22px;
  border-top: 1px solid var(--border);
}
.submit-status { color: var(--muted); font-size: 12px; min-height: 18px; }
.submit-status.error { color: var(--red); }

.primary-button, .secondary-button {
  min-height: 40px;
  border-radius: 7px;
  padding: 0 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 650;
  text-decoration: none;
  white-space: nowrap;
}
.primary-button { color: #fff; background: var(--green); border: 1px solid var(--green); }
.primary-button:hover { background: var(--green-dark); border-color: var(--green-dark); }
.secondary-button { color: #364049; background: #fff; border: 1px solid var(--border-strong); }
.secondary-button:hover { background: var(--surface-subtle); }

.view-tabs { display: flex; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; }
.tab-button {
  height: 30px;
  border: 0;
  border-left: 1px solid var(--border);
  padding: 0 9px;
  background: #fff;
  color: var(--muted);
  font-size: 11px;
}
.tab-button:first-child { border-left: 0; }
.tab-button.active { color: var(--green-dark); background: var(--green-soft); font-weight: 650; }

.jobs-list { overflow-y: auto; padding: 8px 0 24px; }
.job-row {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: inherit;
}
.job-row:hover { background: #fff; }
.job-main {
  min-width: 0;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 12px 10px 12px 18px;
  border: 0;
  background: transparent;
  text-align: left;
  color: inherit;
}
.job-main:focus-visible, .job-cancel:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: -2px;
}
.job-cancel {
  width: 32px;
  height: 32px;
  margin-right: 10px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}
.job-cancel:hover { background: var(--red-soft); color: var(--red); }
.job-cancel svg { width: 16px; height: 16px; }
.job-icon {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: #e9edf0;
  color: #59636c;
}
.job-icon.active { background: var(--blue-soft); color: var(--blue); }
.job-icon.success { background: var(--green-soft); color: var(--green); }
.job-icon.failed { background: var(--red-soft); color: var(--red); }
.job-copy { min-width: 0; }
.job-prompt {
  display: block;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.job-meta { display: flex; align-items: center; gap: 7px; margin-top: 5px; color: var(--muted); font-size: 11px; }
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: #8d959d; }
.status-dot.active { background: var(--blue); }
.status-dot.success { background: var(--green); }
.status-dot.failed { background: var(--red); }
.job-progress { min-width: 44px; text-align: right; font-size: 12px; color: var(--muted); }

.empty-state {
  min-height: 260px;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 9px;
  color: #8a929a;
}
.empty-state svg { width: 28px; height: 28px; }

body.dialog-open { overflow: hidden; }
dialog {
  width: min(430px, calc(100vw - 32px));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  box-shadow: var(--shadow);
  padding: 22px;
}
dialog::backdrop { background: rgba(20, 26, 30, 0.45); }
dialog[open] { animation: dialog-in 120ms ease-out; }
@keyframes dialog-in { from { opacity: 0; transform: translateY(5px); } }
.dialog-heading, .result-header { justify-content: space-between; gap: 20px; margin-bottom: 20px; }
dialog input { height: 42px; margin-bottom: 6px; }
.dialog-error { min-height: 19px; color: var(--red); font-size: 12px; }
.dialog-actions, .result-actions { justify-content: flex-end; gap: 8px; margin-top: 20px; }

.result-dialog { width: min(940px, calc(100vw - 32px)); }
.result-dialog video {
  width: 100%;
  max-height: 70vh;
  aspect-ratio: 16 / 9;
  display: block;
  object-fit: contain;
  background: #0f1214;
  border-radius: 6px;
}

.toast-stack {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 100;
  display: grid;
  gap: 8px;
  width: min(360px, calc(100vw - 36px));
}
.toast {
  min-height: 46px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-left: 4px solid var(--green);
  border-radius: 7px;
  background: #fff;
  box-shadow: 0 10px 30px rgba(24, 32, 39, 0.14);
}
.toast.error { border-left-color: var(--red); }
.toast p { line-height: 1.45; }

@media (max-width: 980px) {
  .workspace { grid-template-columns: 1fr; border: 0; }
  .jobs-panel {
    position: static;
    max-height: none;
    min-height: 420px;
    border-left: 0;
    border-top: 1px solid var(--border);
  }
  .jobs-list { max-height: 520px; }
}

@media (max-width: 680px) {
  .topbar { padding: 9px 12px; }
  .brand-block p { display: none; }
  .quota { min-width: 0; padding: 0 9px; }
  .quota span { display: none; }
  .composer { padding: 20px 14px 28px; }
  .section-heading { margin-bottom: 22px; }
  .control-row { align-items: stretch; flex-direction: column; }
  .segments { grid-template-columns: repeat(3, 1fr); }
  .segments label:nth-child(4) span { border-left: 0; border-top: 1px solid var(--border); }
  .segments label:nth-child(5) span, .segments label:nth-child(6) span { border-top: 1px solid var(--border); }
  .fixed-setting { width: 100%; }
  .asset-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .submit-row { align-items: stretch; flex-direction: column; }
  .primary-button { width: 100%; }
  .section-heading.compact { min-height: 104px; flex-direction: column; }
  .job-main { padding-left: 14px; padding-right: 8px; }
  .job-cancel { margin-right: 8px; }
  .result-dialog { padding: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; scroll-behavior: auto !important; }
}
