:root {
  color: #18201e;
  background: #f4f6f5;
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
  letter-spacing: 0;
  --ink: #18201e;
  --muted: #68736f;
  --line: #d9dfdc;
  --surface: #ffffff;
  --accent: #0d6b57;
  --accent-dark: #095141;
  --accent-soft: #eaf4f0;
  --money: #8a5a00;
  --money-soft: #fff8e7;
  --danger: #b42318;
  --danger-soft: #fff1f0;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: #f4f6f5;
}

button,
input,
textarea {
  font: inherit;
}

button,
a,
label {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.topbar {
  min-height: 76px;
  padding: 14px clamp(20px, 4vw, 56px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.97);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  flex: 0 0 auto;
  width: 12px;
  height: 36px;
  border-radius: 3px;
  background: var(--accent);
}

h1 {
  font-size: 17px;
  line-height: 1.3;
  font-weight: 700;
}

.brand p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

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

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

.connection.ready .status-dot {
  background: #1f9d73;
  box-shadow: 0 0 0 3px #dff3eb;
}

.connection.failed .status-dot {
  background: var(--danger);
  box-shadow: 0 0 0 3px #fde2df;
}

.balance-display {
  min-width: 108px;
  padding-right: 12px;
  border-right: 1px solid var(--line);
  text-align: right;
}

.balance-display span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.balance-display strong {
  display: block;
  margin-top: 2px;
  color: var(--money);
  font-size: 16px;
}

.quiet-button,
.small-button,
.job-action {
  border: 1px solid #c8d0cc;
  border-radius: 5px;
  background: white;
  color: #27312e;
  cursor: pointer;
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}

.quiet-button {
  min-height: 36px;
  padding: 0 12px;
}

.quiet-button:hover,
.small-button:hover,
.job-action:hover:not(:disabled) {
  border-color: #89938f;
  background: #f8faf9;
}

.auth-layout {
  min-height: calc(100vh - 120px);
  padding: 56px 20px;
  display: grid;
  place-items: start center;
}

.login-card {
  width: min(420px, 100%);
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  box-shadow: 0 12px 36px rgba(24, 32, 30, 0.08);
}

.login-card h2 {
  margin-bottom: 26px;
}

.login-card input,
.field-input,
.admin-form input {
  width: 100%;
  height: 44px;
  padding: 0 13px;
  border: 1px solid #c8d0cc;
  border-radius: 6px;
  outline: none;
  background: var(--surface);
  color: var(--ink);
}

.login-card input {
  font-family: Consolas, monospace;
}

.login-card input:focus,
.field-input:focus,
.admin-form input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(13, 107, 87, 0.13);
}

.form-message,
.submit-message {
  min-height: 20px;
  color: var(--danger);
  font-size: 12px;
  line-height: 1.5;
}

.form-message {
  margin: 8px 0 10px;
}

.submit-message {
  margin-top: 8px;
}

.workspace {
  width: min(1440px, 100%);
  min-height: calc(100vh - 120px);
  margin: 0 auto;
  padding: clamp(24px, 4vw, 52px) clamp(20px, 4vw, 56px);
  display: grid;
  grid-template-columns: minmax(320px, 0.88fr) minmax(420px, 1.12fr);
  gap: clamp(28px, 5vw, 72px);
}

.composer,
.result,
.jobs {
  min-width: 0;
}

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

.section-heading {
  min-height: 56px;
  margin-bottom: 20px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.eyebrow {
  margin-bottom: 6px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
}

h2 {
  font-size: 22px;
  line-height: 1.3;
}

.account-name,
.state-badge {
  max-width: 220px;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface);
  color: #45504c;
  font-size: 11px;
  overflow-wrap: anywhere;
}

.state-badge {
  white-space: nowrap;
}

.state-badge.working {
  border-color: #a8d5c6;
  color: var(--accent);
  background: #edf8f4;
}

.state-badge.failed {
  border-color: #efb8b3;
  color: var(--danger);
  background: var(--danger-soft);
}

.mode-switch {
  height: 44px;
  margin-bottom: 24px;
  padding: 3px;
  border: 1px solid #c8d0cc;
  border-radius: 6px;
  background: #e8ecea;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 3px;
}

.mode-switch button {
  min-width: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: #58635f;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 650;
}

.mode-switch button[aria-selected="true"] {
  background: white;
  color: var(--accent);
  box-shadow: 0 1px 3px rgba(24, 32, 30, 0.14);
}

.mode-switch svg,
.primary-button svg,
.secondary-button svg,
.upload-icon svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

label {
  display: inline-block;
  margin-bottom: 9px;
  font-size: 14px;
  font-weight: 650;
}

textarea {
  width: 100%;
  min-height: 190px;
  resize: vertical;
  padding: 16px;
  border: 1px solid #c8d0cc;
  border-radius: 6px;
  outline: none;
  background: var(--surface);
  color: var(--ink);
  line-height: 1.65;
}

.prompt-meta {
  margin-top: 8px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}

.image-upload-section {
  margin-bottom: 20px;
}

.upload-zone {
  width: 100%;
  min-height: 142px;
  margin: 0;
  padding: 20px;
  border: 1px dashed #9eaaa6;
  border-radius: 6px;
  background: #f9fbfa;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 7px;
  text-align: center;
}

.upload-zone:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

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

.upload-zone strong {
  color: var(--ink);
  font-size: 14px;
}

.upload-zone span:last-child {
  font-size: 12px;
  font-weight: 400;
}

.upload-icon {
  color: var(--accent);
}

.image-preview {
  min-height: 92px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) 36px;
  align-items: center;
  gap: 12px;
}

.image-preview img {
  width: 72px;
  height: 72px;
  border-radius: 4px;
  object-fit: cover;
  background: #e8ecea;
}

.image-preview div {
  min-width: 0;
}

.image-preview strong,
.image-preview span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-preview strong {
  font-size: 13px;
}

.image-preview span {
  margin-top: 6px;
  color: var(--muted);
  font-size: 11px;
}

.generation-options {
  margin: 22px 0;
  padding: 18px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(150px, 0.65fr);
  gap: 24px;
}

.option-control {
  min-width: 0;
}

.option-title {
  display: block;
  margin-bottom: 9px;
  font-size: 14px;
  font-weight: 650;
}

.segmented-control {
  height: 48px;
  padding: 3px;
  border: 1px solid #c8d0cc;
  border-radius: 6px;
  background: #eef1ef;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 3px;
}

.segmented-control label {
  position: relative;
  min-width: 0;
  height: 100%;
  margin: 0;
  cursor: pointer;
}

.segmented-control input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.segmented-control label > span {
  width: 100%;
  height: 100%;
  border-radius: 4px;
  color: #58635f;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.segmented-control strong {
  font-size: 13px;
}

.segmented-control small {
  color: var(--money);
  font-size: 10px;
  font-weight: 650;
}

.segmented-control input:checked + span {
  background: white;
  color: var(--accent);
  box-shadow: 0 1px 3px rgba(24, 32, 30, 0.14);
}

.segmented-control input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.fixed-option {
  height: 48px;
  padding: 0 12px;
  border: 1px solid #c8d0cc;
  border-radius: 6px;
  background: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.fixed-option strong {
  font-size: 13px;
}

.fixed-option span {
  color: var(--muted);
  font-size: 12px;
}

.primary-button,
.secondary-button,
.icon-button {
  min-height: 44px;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  text-decoration: none;
}

.primary-button {
  width: 100%;
  padding: 0 20px;
  background: var(--accent);
  color: white;
  font-weight: 700;
}

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

.primary-button:disabled,
.quiet-button:disabled,
.small-button:disabled {
  cursor: wait;
  opacity: 0.58;
}

.secondary-button,
.icon-button {
  border-color: #c8d0cc;
  background: white;
  color: #27312e;
}

.secondary-button {
  padding: 0 14px;
  font-size: 13px;
  font-weight: 650;
}

.secondary-button:hover,
.icon-button:hover {
  border-color: #89938f;
  background: #f8faf9;
}

.icon-button {
  width: 36px;
  min-height: 36px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
}

.result-stage {
  aspect-ratio: 16 / 10;
  min-height: 320px;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: #111614;
  color: white;
  display: grid;
  place-items: center;
}

.empty-state,
.loading-state,
.error-state {
  max-width: 440px;
  padding: 32px;
  text-align: center;
}

.empty-state {
  color: #aab4b0;
}

.empty-state svg {
  width: 44px;
  height: 44px;
  margin-bottom: 12px;
  fill: #64706c;
}

.empty-state p,
.loading-state p {
  font-size: 14px;
}

.loading-state span {
  display: block;
  margin-top: 8px;
  color: #9eaaa6;
  font-size: 12px;
}

.spinner {
  width: 32px;
  height: 32px;
  margin: 0 auto 15px;
  border: 3px solid #38433f;
  border-top-color: #63d5b0;
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

#video-player {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #050706;
}

.error-state {
  color: #f9d8d5;
}

.error-code {
  display: inline-block;
  margin-bottom: 13px;
  padding: 4px 7px;
  border: 1px solid #75413d;
  border-radius: 4px;
  color: #ffb9b2;
  font-size: 11px;
}

.error-state h3 {
  margin-bottom: 9px;
  color: white;
  font-size: 18px;
}

.error-state p {
  color: #d8c3c0;
  font-size: 13px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.result-actions {
  margin-top: 12px;
  display: flex;
  justify-content: flex-end;
}

.jobs {
  grid-column: 1 / -1;
  margin-top: 10px;
  padding-top: 32px;
  border-top: 1px solid var(--line);
}

.jobs-heading {
  margin-bottom: 14px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
}

.jobs-title-row {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.job-count {
  color: var(--muted);
  font-size: 12px;
}

.job-list {
  border-top: 1px solid var(--line);
}

.jobs-empty {
  min-height: 126px;
  padding: 30px 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  text-align: center;
}

.jobs-empty p {
  margin-bottom: 6px;
  color: #3e4945;
  font-size: 14px;
  font-weight: 650;
}

.jobs-empty span {
  font-size: 12px;
}

.job-row {
  min-height: 92px;
  padding: 16px 10px;
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: minmax(240px, 1.6fr) minmax(130px, 0.75fr) 96px 105px auto;
  align-items: center;
  gap: 20px;
  cursor: pointer;
}

.job-row:hover,
.job-row.selected {
  background: #eef3f1;
}

.job-row.selected {
  box-shadow: inset 3px 0 var(--accent);
}

.job-summary {
  min-width: 0;
}

.job-summary h3 {
  margin-bottom: 7px;
  overflow: hidden;
  color: var(--ink);
  font-size: 14px;
  font-weight: 650;
  line-height: 1.45;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.job-summary p {
  overflow: hidden;
  color: var(--muted);
  font: 11px/1.4 Consolas, monospace;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.job-progress {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(72px, 1fr) 36px;
  align-items: center;
  gap: 9px;
}

.progress-line {
  height: 6px;
  overflow: hidden;
  border-radius: 3px;
  background: #dce3e0;
}

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

.progress-text {
  color: var(--muted);
  font-size: 11px;
  text-align: right;
}

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

.job-cost strong {
  color: var(--money);
  font-size: 13px;
}

.job-cost span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 10px;
}

.job-state {
  justify-self: start;
  padding: 5px 8px;
  border: 1px solid #cbd4d0;
  border-radius: 4px;
  background: white;
  color: #55615d;
  font-size: 11px;
  white-space: nowrap;
}

.job-state.processing,
.job-state.queued,
.job-state.submitting {
  border-color: #a8d5c6;
  background: #edf8f4;
  color: var(--accent);
}

.job-state.done {
  border-color: #9fd1b3;
  background: #edf8f1;
  color: #237047;
}

.job-state.failed {
  border-color: #efb8b3;
  background: var(--danger-soft);
  color: var(--danger);
}

.job-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.job-action {
  min-width: 48px;
  height: 34px;
  padding: 0 9px;
}

.job-action.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.job-action.primary:hover:not(:disabled) {
  border-color: var(--accent-dark);
  background: var(--accent-dark);
}

.job-action.danger {
  color: var(--danger);
}

footer {
  min-height: 44px;
  padding: 0 clamp(20px, 4vw, 56px);
  border-top: 1px solid var(--line);
  color: #77817e;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  font: 11px Consolas, monospace;
}

/* Admin */
.admin-workspace {
  width: min(1180px, 100%);
  min-height: calc(100vh - 120px);
  margin: 0 auto;
  padding: 40px clamp(20px, 4vw, 56px) 64px;
}

.admin-summary {
  margin-bottom: 32px;
  padding-bottom: 26px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
}

.admin-summary p:last-child {
  max-width: 620px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 40px 56px;
}

.admin-section {
  min-width: 0;
  padding-bottom: 34px;
  border-bottom: 1px solid var(--line);
}

.admin-section.wide {
  grid-column: 1 / -1;
}

.admin-section-heading {
  margin-bottom: 20px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.admin-section-heading h2 {
  font-size: 18px;
}

.admin-status {
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: white;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.admin-status.ready {
  border-color: #9fd1b3;
  background: #edf8f1;
  color: #237047;
}

.admin-form {
  display: grid;
  gap: 16px;
}

.admin-form label {
  width: 100%;
  margin: 0;
}

.admin-form label > span {
  display: block;
  margin-bottom: 8px;
  color: #38433f;
  font-size: 12px;
}

.admin-form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.admin-form-message {
  min-height: 20px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.admin-form-message.error {
  color: var(--danger);
}

.customer-metrics {
  margin-bottom: 20px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  border: 1px solid var(--line);
  background: var(--line);
}

.customer-metrics div {
  min-width: 0;
  padding: 14px;
  background: white;
}

.customer-metrics span,
.customer-metrics strong {
  display: block;
}

.customer-metrics span {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 10px;
}

.customer-metrics strong {
  overflow: hidden;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.switch-row {
  min-height: 44px;
  display: flex !important;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.switch-row input {
  width: 18px;
  height: 18px;
}

.one-time-code {
  margin-top: 16px;
  padding: 14px;
  border: 1px solid #e1c584;
  border-radius: 6px;
  background: var(--money-soft);
}

.one-time-code span,
.one-time-code code {
  display: block;
}

.one-time-code span {
  color: var(--money);
  font-size: 11px;
}

.one-time-code code {
  margin: 8px 0 12px;
  overflow-wrap: anywhere;
  color: #443000;
  font: 13px/1.5 Consolas, monospace;
}

.admin-table-wrap {
  overflow-x: auto;
  border-top: 1px solid var(--line);
}

.admin-table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  font-size: 12px;
}

.admin-table th,
.admin-table td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.admin-table th {
  color: var(--muted);
  font-size: 10px;
  font-weight: 650;
}

.admin-table td {
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.amount-positive {
  color: #237047;
}

.amount-negative {
  color: var(--danger);
}

[hidden] {
  display: none !important;
}

@media (max-width: 980px) {
  .job-row {
    grid-template-columns: minmax(0, 1fr) 110px auto;
    gap: 13px 18px;
  }

  .job-summary {
    grid-column: 1 / -1;
  }

  .job-progress {
    grid-column: 1;
  }

  .job-cost {
    grid-column: 2;
  }

  .job-state {
    grid-column: 3;
  }

  .job-actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }
}

@media (max-width: 860px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .balance-display {
    text-align: left;
  }

  .workspace {
    grid-template-columns: 1fr;
    min-height: auto;
    gap: 48px;
  }

  .result-stage {
    min-height: 250px;
  }

  .jobs-heading {
    align-items: stretch;
    flex-direction: column;
  }

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

  .admin-section.wide {
    grid-column: 1;
  }
}

@media (max-width: 520px) {
  .workspace,
  .topbar,
  .admin-workspace {
    padding-left: 16px;
    padding-right: 16px;
  }

  .topbar-actions {
    gap: 10px;
  }

  .connection {
    width: 100%;
    order: 3;
  }

  .section-heading,
  .admin-summary,
  .admin-section-heading {
    min-height: 0;
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }

  .prompt-meta,
  footer {
    align-items: flex-start;
    flex-direction: column;
  }

  .result-stage {
    aspect-ratio: 4 / 3;
    min-height: 230px;
  }

  .generation-options {
    grid-template-columns: 1fr;
  }

  .job-row {
    padding-left: 8px;
    padding-right: 8px;
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .job-summary {
    grid-column: 1 / -1;
  }

  .job-progress {
    grid-column: 1 / -1;
  }

  .job-cost {
    grid-column: 1;
  }

  .job-state {
    grid-column: 2;
  }

  .job-actions {
    grid-column: 1 / -1;
  }

  .login-card {
    padding: 24px 20px;
  }

  .customer-metrics {
    grid-template-columns: 1fr;
  }

  .admin-form-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .admin-form-actions .quiet-button,
  .admin-form-actions .small-button {
    width: 100%;
  }

  footer {
    padding-top: 12px;
    padding-bottom: 12px;
  }
}
