:root {
  --bg: #f8f8f8;
  --side: #ffffff;
  --panel: #ffffff;
  --soft: #f4f4f4;
  --soft-2: #eeeeee;
  --ink: #171717;
  --muted: #7b7b7b;
  --line: #e6e6e6;
  --blue: #2374ff;
  --blue-dark: #1d64df;
  --danger: #d64545;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "MiSans VF", "MiSans", Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.viewer-open {
  overflow: hidden;
}

button,
input,
a,
textarea {
  font: inherit;
}

h1,
h2,
h3,
strong,
b {
  font-weight: 500;
}

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

button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 16px;
  background: #fff;
  color: var(--ink);
  font-weight: 500;
  cursor: pointer;
}

button:hover,
.ghost-button:hover,
.download-button:hover {
  border-color: #cfcfcf;
  background: #fafafa;
}

.app-frame {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
}

.global-sidebar {
  min-height: 100vh;
  padding: 24px;
  border-right: 1px solid var(--line);
  background: var(--side);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 17px;
  color: var(--ink);
  font-size: 20px;
  font-weight: 700;
  text-decoration: none;
}

.brand-mark {
  width: 30px;
  height: 30px;
  display: inline-grid;
  place-items: center;
  border-radius: 8px;
  background: var(--blue);
  color: #fff;
  font-size: 18px;
}

.brand-mark img,
.nav-icon img,
.icon-button img,
.plus-mark img,
.empty-icon img,
.task-state img {
  display: block;
  width: 100%;
  height: 100%;
}

.brand-mark img {
  width: 20px;
  height: 20px;
}

.global-nav {
  display: grid;
  gap: 10px;
}

.global-nav-item {
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: var(--radius);
  padding: 0 14px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
}

.global-nav-item.active {
  background: #ededed;
}

.nav-icon {
  width: 16px;
  height: 16px;
  color: var(--ink);
  flex: 0 0 16px;
}

.app-main {
  min-width: 0;
  padding: 26px 16px 52px;
}

.page-bar {
  width: 100%;
  height: 29px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.page-bar h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 500;
  letter-spacing: 0;
}

.ghost-button,
.download-button {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 10px;
  background: #fff;
  color: var(--ink);
  font-weight: 500;
  text-decoration: none;
}

.workbench-layout {
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.project-panel {
  align-self: start;
  width: 190px;
  min-height: 317px;
  border-radius: var(--radius);
  padding: 16px;
  background: var(--panel);
}

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

.project-panel h2 {
  margin: 0;
  font-size: 14px;
}

.blue-button {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

.blue-button:hover {
  border-color: var(--blue-dark);
  background: var(--blue-dark);
}

.blue-button.compact {
  min-height: 28px;
  border-radius: 6px;
  padding: 0 10px;
  font-size: 14px;
}

.project-list {
  display: grid;
  gap: 8px;
  max-height: calc(100vh - 178px);
  overflow: auto;
}

.project-item {
  min-height: 50px;
  display: grid;
  align-content: center;
  justify-items: start;
  gap: 2px;
  border: 0;
  border-radius: 6px;
  padding: 8px 10px;
  background: transparent;
  text-align: left;
}

.project-item.active,
.project-item:hover {
  background: #f0f0f0;
}

.project-item strong {
  max-width: 100%;
  overflow: hidden;
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-item span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.project-workspace {
  min-width: 0;
  width: 100%;
  border-radius: var(--radius);
  padding: 16px;
  background: var(--panel);
}

.project-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.project-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.danger-button {
  color: var(--danger);
}

.danger-button:hover {
  border-color: rgba(214, 69, 69, 0.24);
  background: rgba(214, 69, 69, 0.06);
  color: var(--danger);
}

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

.project-title-input {
  max-width: 280px;
  border: 0;
  border-radius: 6px;
  padding: 4px 2px;
  background: transparent;
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
  outline: none;
}

.project-title-input:focus {
  background: #f7f7f7;
  box-shadow: none;
}

.icon-button {
  min-width: 28px;
  min-height: 28px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
}

.icon-button img {
  width: 12px;
  height: 12px;
}

.top-grid {
  display: grid;
  grid-template-columns: 370px minmax(496px, 1fr);
  gap: 24px;
  align-items: center;
  margin-bottom: 16px;
}

.upload-card {
  min-width: 0;
}

.product-drop {
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 10px;
  height: 340px;
  min-height: 340px;
  border: 1px solid #f6f6f6;
  border-radius: var(--radius);
  padding: 16px;
  background: #fff;
}

.product-image-target {
  display: grid;
  cursor: pointer;
}

.product-image-target input {
  display: none;
}

.product-image-target > img {
  width: 100%;
  height: 281px;
  display: none;
  object-fit: contain;
  border-radius: 6px;
  background: linear-gradient(#f3f3f3 0 16%, #fff 16% 84%, #f3f3f3 84%);
}

.upload-empty {
  min-height: 281px;
  border: 1px dashed #e9e9e9;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  border-radius: 6px;
  background: #f1f1f1;
  color: var(--ink);
  text-align: center;
}

.upload-empty small {
  color: #999;
  font-size: 12px;
  font-weight: 500;
}

.plus-mark {
  width: 48px;
  height: 48px;
}

.plus-mark img {
  object-fit: contain;
}

.image-meta {
  min-height: 28px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0;
  color: #333;
  font-size: 12px;
  font-weight: 500;
}

.image-meta span {
  white-space: nowrap;
}

.image-meta strong {
  color: #999;
}

.image-meta button {
  margin-left: auto;
  min-height: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  line-height: 1;
  white-space: nowrap;
}

.flow-panel h2 {
  margin: 0 0 13px;
  font-size: 14px;
}

.task-cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  height: 190px;
  margin-bottom: 24px;
}

.task-card {
  min-height: 190px;
  height: 190px;
  display: grid;
  align-content: space-between;
  gap: 8px;
  border-radius: var(--radius);
  padding: 16px;
  background: #f8f8f8;
}

.task-card h3 {
  margin: 0;
  font-size: 14px;
  line-height: 14px;
  text-transform: uppercase;
}

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

.task-card strong {
  font-size: 14px;
  line-height: 14px;
}

.task-card span {
  color: #6b6b6b;
  font-size: 14px;
  line-height: 14px;
}

.task-card button {
  width: fit-content;
  min-height: 32px;
  margin-top: 0;
  border-radius: 6px;
  padding: 0 16px;
  font-size: 14px;
}

.task-state {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 0;
  color: #bbb;
  font-size: 14px;
  font-weight: 500;
}

.task-state::before {
  content: none;
}

.task-card.done .task-state,
.task-card.running .task-state {
  color: var(--blue);
}

.task-state img {
  width: 20px;
  height: 20px;
}

.progress-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: #858585;
  font-size: 14px;
  margin-bottom: 11px;
}

.progress-track {
  position: relative;
  height: 18px;
  margin-bottom: 21px;
}

.progress-track::before,
.progress-fill {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 7px;
  height: 4px;
  border-radius: 999px;
  background: #d7d7d7;
}

.progress-fill {
  right: auto;
  width: 0;
  background: var(--blue);
  transition: width 0.2s ease;
}

.progress-dot {
  position: absolute;
  top: 0;
  width: 14px;
  height: 14px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #d1d1d1;
  color: #fff;
  font-size: 10px;
  font-weight: 500;
  transform: translateX(-50%);
}

.progress-dot:nth-of-type(1) {
  left: 33.33%;
}

.progress-dot:nth-of-type(2) {
  left: 66.66%;
}

.progress-dot:nth-of-type(3) {
  left: 100%;
}

.progress-dot.active,
.progress-dot.done {
  background: var(--blue);
}

.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
}

.status {
  min-height: 36px;
  display: flex;
  align-items: center;
  border-radius: var(--radius);
  padding: 0 16px;
  background: #f9f9f9;
  color: #333;
  font-weight: 500;
}

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

.run-all {
  min-height: 36px;
  width: 157px;
  flex: 0 0 157px;
}

.result-section {
  width: 100%;
  margin-top: 16px;
}

.result-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.result-title h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
}

.result-title h2 span {
  margin-left: 6px;
}

.stage-badge {
  min-height: 24px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0 12px;
  background: #e8e8e8;
  color: #333;
  font-size: 12px;
  font-weight: 500;
}

.stage-badge.done,
.stage-badge.running {
  background: var(--blue);
  color: #fff;
}

.prompt-editor {
  width: 100%;
  height: 400px;
  min-height: 400px;
  max-height: 400px;
  border: 1px solid #d7d7d7;
  border-radius: var(--radius);
  padding: 16px;
  background: #fff;
  color: var(--ink);
  line-height: 1.55;
  overflow: auto;
  resize: none;
  outline: none;
}

.prompt-editor:focus,
input:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(47, 120, 246, 0.12);
}

.result-media {
  position: relative;
  height: 400px;
  min-height: 400px;
  max-height: 400px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: var(--radius);
  background: #f5f5f5;
}

.result-media.large {
  height: 400px;
  min-height: 400px;
  max-height: 400px;
}

.result-media > img {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 400px;
  display: none;
  object-fit: contain;
}

.result-media video {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 400px;
  display: none;
  object-fit: contain;
}

.empty-state {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  color: #aaa;
  font-size: 14px;
  font-weight: 500;
}

.empty-icon {
  width: 48px;
  height: 48px;
}

.media-actions {
  position: absolute;
  right: 16px;
  bottom: 16px;
  display: inline-flex;
  gap: 8px;
}

.download-button {
  border-color: var(--line);
}

.image-viewer {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  place-items: center;
  padding: 32px;
  background: rgba(0, 0, 0, 0.86);
  overflow: auto;
  cursor: default;
}

.image-viewer.open {
  display: grid;
}

.image-viewer img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  transform-origin: center center;
  transition: transform 0.12s ease;
  user-select: none;
  -webkit-user-drag: none;
  touch-action: none;
}

.image-viewer.zoomed img {
  cursor: grab;
}

.image-viewer.dragging img {
  cursor: grabbing;
  transition: none;
}

.image-viewer-toolbar {
  position: absolute;
  top: 20px;
  right: 20px;
  z-index: 1;
  display: inline-flex;
  gap: 8px;
}

.image-viewer-toolbar button {
  border-color: rgba(255, 255, 255, 0.24);
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
}

.image-viewer-toolbar button:hover {
  border-color: rgba(255, 255, 255, 0.62);
  background: rgba(0, 0, 0, 0.32);
  color: #fff;
}

.raw-page-card {
  border-radius: var(--radius);
  padding: 22px;
  background: #fff;
}

.raw-page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.raw-page-head p {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

.raw-page-head h2 {
  margin: 0;
  font-size: 20px;
}

pre {
  max-height: calc(100vh - 180px);
  margin: 0;
  padding: 18px;
  overflow: auto;
  border-radius: var(--radius);
  background: #161616;
  color: #e9e9e9;
  font-size: 13px;
  line-height: 1.55;
}

.topbar {
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 28px;
  background: #fff;
}

.topbar h1 {
  margin: 0;
  font-size: 28px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: uppercase;
}

.top-actions,
.settings-actions,
.tabs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.compact-actions {
  gap: 8px;
}

.nav-button,
.export-button {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 14px;
  background: #fff;
  color: var(--ink);
  font-weight: 500;
  text-decoration: none;
}

.settings-workspace {
  padding: 22px 28px 44px;
}

.settings-panel {
  max-width: 980px;
  margin: 0 auto;
  border-radius: var(--radius);
  padding: 22px;
  background: #fff;
}

.section-heading {
  margin-bottom: 16px;
}

.section-heading h2 {
  margin: 0;
  font-size: 20px;
}

.tab.active {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

.config-form {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

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

label {
  display: grid;
  gap: 7px;
  color: #555;
  font-size: 13px;
  font-weight: 500;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

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

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
}

.toggle input {
  width: 18px;
  height: 18px;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.login-card {
  width: min(420px, 100%);
  border-radius: var(--radius);
  padding: 28px;
  background: #fff;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.06);
}

.login-card .brand {
  margin-bottom: 24px;
}

.login-card h1 {
  margin: 0 0 18px;
  font-size: 22px;
}

.login-form {
  display: grid;
  gap: 14px;
}

.login-form button {
  margin-top: 4px;
}

.login-status {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.auth-dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.42);
}

.auth-dialog {
  width: min(420px, 100%);
  border-radius: var(--radius);
  padding: 20px;
  background: #fff;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.16);
}

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

.auth-dialog-head h2 {
  margin: 0;
  font-size: 18px;
}

.auth-dialog-form {
  display: grid;
  gap: 12px;
}

.auth-dialog-status {
  min-height: 18px;
  margin: 0;
  color: var(--danger);
  font-size: 13px;
}

.sync-panel {
  display: grid;
  gap: 14px;
}

.sync-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.sync-panel-head strong {
  display: block;
  margin-bottom: 6px;
  font-size: 15px;
}

.sync-panel-head p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.sync-progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e6e6e6;
}

.sync-progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--blue);
  transition: width 0.2s ease;
}

.sync-log {
  max-height: 220px;
  background: #f7f7f7;
  color: #333;
}

@media (max-width: 1439px) {
  .app-frame {
    grid-template-columns: 240px minmax(0, 1fr);
  }

  .global-sidebar {
    padding: 22px 18px;
  }

  .app-main {
    padding: 24px 16px 48px;
  }

  .page-bar {
    width: 100%;
  }

  .workbench-layout {
    grid-template-columns: minmax(170px, 190px) minmax(0, 1fr);
  }

  .project-panel,
  .project-workspace,
  .result-section {
    width: 100%;
  }

  .top-grid {
    grid-template-columns: minmax(300px, 370px) minmax(430px, 1fr);
  }

  .status-row {
    gap: 16px;
  }
}

@media (max-width: 1180px) {
  .app-frame {
    grid-template-columns: 220px minmax(0, 1fr);
  }

  .workbench-layout {
    grid-template-columns: 1fr;
  }

  .project-panel {
    min-height: auto;
  }

  .project-list {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    max-height: 188px;
  }

  .top-grid {
    grid-template-columns: minmax(300px, 370px) minmax(420px, 1fr);
  }
}

@media (max-width: 980px) {
  .app-frame {
    grid-template-columns: 200px minmax(0, 1fr);
  }

  .brand {
    font-size: 18px;
  }

  .global-nav-item {
    padding: 0 10px;
  }

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

  .product-drop {
    height: auto;
    min-height: 300px;
  }

  .product-image-target > img,
  .upload-empty {
    height: 260px;
    min-height: 260px;
  }

  .flow-panel {
    min-width: 0;
  }

  .task-cards {
    height: auto;
  }
}

@media (max-width: 760px) {
  .app-frame {
    grid-template-columns: 1fr;
  }

  .global-sidebar {
    min-height: auto;
    padding: 18px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .brand {
    margin-bottom: 14px;
  }

  .app-main {
    padding: 18px;
  }

  .task-cards,
  .status-row,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .status-row {
    align-items: stretch;
    gap: 12px;
  }

  .project-list {
    grid-template-columns: 1fr;
  }

  .project-toolbar,
  .page-bar,
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .page-bar {
    height: auto;
  }

  .project-toolbar {
    gap: 10px;
  }

  .project-actions {
    width: 100%;
    margin-left: 0;
  }

  .project-title-input {
    max-width: min(280px, calc(100vw - 120px));
  }

  .image-meta {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .image-meta button {
    margin-left: 0;
  }

  .result-media video {
    max-width: 100%;
  }
}

@media (max-width: 520px) {
  .app-main {
    padding: 14px;
  }

  .project-workspace,
  .project-panel,
  .settings-panel,
  .raw-page-card {
    padding: 14px;
  }

  .task-card {
    min-height: 168px;
    height: auto;
  }

  .product-drop {
    padding: 12px;
  }

  .product-image-target > img,
  .upload-empty {
    height: 220px;
    min-height: 220px;
  }

  .media-actions {
    right: 12px;
    bottom: 12px;
  }
}
