:root {
  --ink: #16212b;
  --muted: #66737f;
  --subtle: #96a0aa;
  --line: #dde4e8;
  --panel: #ffffff;
  --panel-soft: #f8fafb;
  --bg: #eef2f4;
  --accent: #df5a3a;
  --accent-dark: #bd432b;
  --accent-soft: #fff0eb;
  --ok: #259b6a;
  --warn: #c77818;
  --shadow: 0 16px 36px rgba(24, 34, 44, .08);
}

* { box-sizing: border-box; }

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "DM Sans", "Noto Sans SC", sans-serif;
  font-size: 14px;
}

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

button {
  border: 0;
  color: inherit;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: .62;
}

button,
input,
textarea,
select {
  transition: border-color .2s, box-shadow .2s, background .2s, color .2s, opacity .2s;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 0;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(223, 90, 58, .16);
}

.app-shell {
  height: 100vh;
  overflow: hidden;
}

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

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

.brand-logo {
  width: 38px;
  height: 38px;
  display: block;
  object-fit: contain;
  flex: 0 0 auto;
}

.brand strong {
  display: block;
  font-size: 15px;
  letter-spacing: 0;
}

.brand span {
  display: block;
  margin-top: 2px;
  color: var(--subtle);
  font-size: 9px;
  letter-spacing: 0;
}

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

.connection-status {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 10px;
  color: var(--muted);
  font-size: 12px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.connection-status i {
  width: 7px;
  height: 7px;
  background: var(--ok);
  border-radius: 50%;
}

.connection-status[data-state="idle"] i {
  background: #a7b1b9;
}

.connection-status[data-state="online"] {
  color: #245f45;
  background: #eef9f3;
  border-color: #d5eadf;
}

.update-status {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 10px;
  color: var(--muted);
  font-size: 12px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.update-status i {
  width: 7px;
  height: 7px;
  background: #a7b1b9;
  border-radius: 50%;
}

.update-status[data-state="idle"] {
  color: var(--muted);
}

.update-status[data-state="ready"] {
  color: #8a4a11;
  background: #fff6e9;
  border-color: #f1ddb5;
}

.update-status[data-state="ready"] i {
  background: var(--warn);
}

.update-status[data-state="updating"] {
  color: #245f45;
  background: #eef9f3;
  border-color: #d5eadf;
}

.update-status[data-state="updating"] i {
  background: var(--ok);
}

.update-status[data-state="blocked"] {
  color: #8f3d2d;
  background: #fff2ef;
  border-color: #f0cdc5;
}

.update-status[data-state="blocked"] i {
  background: #cf694f;
}

.update-status[data-state="error"] {
  color: #9a2440;
  background: #fff0f3;
  border-color: #f2ced7;
}

.update-status[data-state="error"] i {
  background: #d65b7a;
}

.icon-button,
.avatar {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.avatar {
  color: #aa412a;
  background: var(--accent-soft);
  font-weight: 700;
}

.icon-button {
  position: relative;
}

.toolbar-tools button,
.secret-input button,
.tiny-action,
.result-card button {
  position: relative;
}

.tiny-action {
  color: var(--accent);
}

.icon-button i,
.tiny-action i,
.secret-input button i,
.toolbar-tools button i,
.result-card button i,
.preview-item button i,
.history-delete i,
.generate-button i,
.empty-icon i {
  display: block;
  font-size: 16px;
  line-height: 1;
}

.toolbar-tools button i,
.result-card button i,
.generate-button i {
  font-size: 15px;
}

.secret-input button i,
.tiny-action i,
.preview-item button i,
.history-delete i {
  font-size: 14px;
}

.generate-button i {
  flex: 0 0 auto;
}

.empty-icon i {
  font-size: 22px;
}

.result-card button {
  color: #fff;
}

.workspace {
  height: calc(100vh - 64px);
  display: grid;
  grid-template-columns: 304px minmax(0, 1fr) 272px;
  overflow: hidden;
}

.sidebar {
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 18px;
  overflow: auto;
  scrollbar-gutter: stable;
  background: var(--panel);
}

.left-panel { border-right: 1px solid var(--line); }
.right-panel { border-left: 1px solid var(--line); }

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

.eyebrow,
.step,
.count {
  color: var(--subtle);
  font-size: 11px;
  letter-spacing: 0;
}

.eyebrow {
  font-weight: 700;
}

.panel-heading h1 {
  margin: 4px 0 0;
  font-size: 19px;
  letter-spacing: 0;
}

.field-label {
  display: flex;
  justify-content: space-between;
  margin: 0 0 7px;
  color: #4e5a64;
  font-size: 12px;
  font-weight: 700;
}

.field-label span {
  color: var(--subtle);
  font-weight: 500;
}

.prompt-wrap {
  position: relative;
}

.prompt-wrap textarea,
input,
select {
  width: 100%;
  min-height: 40px;
  padding: 10px 11px;
  color: var(--ink);
  background: #fbfcfd;
  border: 1px solid var(--line);
  border-radius: 8px;
}

textarea {
  min-height: 120px;
  resize: none;
  line-height: 1.55;
}

.tiny-action {
  position: absolute;
  right: 8px;
  bottom: 8px;
  min-width: 40px;
  height: 32px;
  padding: 0 10px;
  color: var(--accent);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 12px;
  font-weight: 700;
}

.prompt-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 7px;
  color: var(--subtle);
  font-size: 11px;
}

.prompt-meta button {
  min-height: 32px;
  padding: 0 8px;
  color: var(--accent);
  background: transparent;
  border-radius: 7px;
  font-size: 11px;
  font-weight: 700;
}

.prompt-meta button:hover,
.tiny-action:hover {
  background: var(--accent-soft);
}

.upload-box {
  position: relative;
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  min-height: 84px;
  padding: 13px;
  margin-bottom: 10px;
  background: #fbfcfd;
  border: 1px dashed #cfd8de;
  border-radius: 8px;
}

.upload-box.dragging {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.upload-box input {
  min-height: 34px;
  padding: 0;
  background: transparent;
  border: 0;
}

.upload-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.upload-copy strong {
  color: #3d4a54;
  font-size: 12px;
}

.upload-copy span {
  color: var(--subtle);
  font-size: 11px;
  line-height: 1.45;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.preview-item {
  position: relative;
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

.preview-item button {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 28px;
  height: 28px;
  color: #4d5962;
  background: rgba(255, 255, 255, .92);
  border: 1px solid var(--line);
  border-radius: 7px;
}

.divider {
  height: 1px;
  margin: 16px 0;
  background: var(--line);
}

.section-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.no-margin { margin: 0; }

.model-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  color: #a64029;
  background: var(--accent-soft);
  border-radius: 6px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0;
}

.secret-input {
  position: relative;
  margin-bottom: 14px;
}

.secret-input input {
  padding-right: 46px;
}

.secret-input button {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 38px;
  height: 36px;
  color: var(--muted);
  background: transparent;
  border-radius: 7px;
}

.section-title {
  margin-bottom: 10px;
  font-size: 12px;
  font-weight: 800;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  margin-bottom: 12px;
  background: #edf1f3;
  border-radius: 8px;
}

.segmented button {
  min-height: 34px;
  color: #6f7c87;
  background: transparent;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
}

.segmented button:hover {
  color: var(--ink);
  background: rgba(255, 255, 255, .55);
}

.segmented button.active {
  color: var(--ink);
  background: #fff;
  box-shadow: 0 1px 6px rgba(21, 34, 43, .12);
}

.generate-button {
  width: 100%;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 14px;
  color: #fff;
  background: var(--accent);
  border-radius: 8px;
  box-shadow: 0 8px 18px rgba(223, 90, 58, .24);
  font-weight: 800;
}

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

.generate-button b {
  font-size: 10px;
  font-weight: 600;
  opacity: .75;
}

.privacy-note {
  margin: 9px 0 0;
  color: var(--subtle);
  font-size: 10px;
  line-height: 1.45;
  text-align: center;
}

.canvas-area {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.canvas-toolbar {
  height: 56px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 0 20px;
  background: #fafbfc;
  border-bottom: 1px solid var(--line);
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: #7c8791;
  font-size: 12px;
}

.breadcrumb span {
  color: #b8c0c7;
}

.task-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  color: var(--warn);
  background: #fff6e7;
  border-radius: 6px;
  font-size: 10px;
  font-style: normal;
  font-weight: 800;
  letter-spacing: 0;
}

.task-badge.hidden {
  display: none;
}

.toolbar-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #6d7882;
}

.toolbar-tools button {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 17px;
}

.toolbar-tools button:hover {
  color: var(--ink);
  border-color: #c8d2d9;
}

.toolbar-tools span {
  width: 46px;
  text-align: center;
  font-size: 11px;
}

.canvas-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: 22px;
  background-color: #f0f3f5;
  background-image:
    linear-gradient(45deg, #e5eaed 25%, transparent 25%),
    linear-gradient(-45deg, #e5eaed 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e5eaed 75%),
    linear-gradient(-45deg, transparent 75%, #e5eaed 75%);
  background-size: 22px 22px;
  background-position: 0 0, 0 11px, 11px -11px, -11px 0;
}

.empty-state {
  max-width: 390px;
  padding: 0 18px;
  color: #73808a;
  text-align: center;
}

.empty-icon {
  position: relative;
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  margin: 0 auto 16px;
  color: #fff;
  background: var(--ink);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.empty-state h2 {
  margin: 0 0 7px;
  color: #34424d;
  font-size: 18px;
}

.empty-state p {
  margin: 0 0 14px;
  font-size: 12px;
  line-height: 1.6;
}

.empty-hint {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--subtle);
  font-size: 11px;
}

.empty-hint span {
  min-width: 24px;
  padding: 3px 6px;
  color: #65717b;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 5px;
}

.result-grid {
  width: min(100%, 840px);
  max-height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  align-items: center;
}

.result-grid[data-count="2"] {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.result-card {
  position: relative;
  min-width: 0;
  overflow: hidden;
  background: #fff;
  border: 1px solid #d9e0e5;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.result-card img {
  display: block;
  width: 100%;
  height: auto;
  max-height: calc(100vh - 220px);
  object-fit: contain;
  background: #fff;
  transform-origin: center center;
  transition: transform .18s ease;
}

.result-card button {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 38px;
  min-width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  color: #fff;
  background: rgba(17, 24, 39, .92);
  border-radius: 8px;
  box-shadow: 0 8px 18px rgba(17, 24, 39, .22);
}

.result-card button:hover {
  background: #0b1220;
}

.canvas-footer {
  height: 40px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 20px;
  color: var(--subtle);
  background: #fff;
  border-top: 1px solid var(--line);
  font-size: 11px;
}

.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 20px;
  color: #75818a;
  text-align: center;
}

.loading-state strong {
  color: #3f4c56;
  font-size: 15px;
}

.loading-state span {
  font-size: 12px;
  line-height: 1.5;
}

.loader {
  width: 34px;
  height: 34px;
  border: 3px solid #f4c6bb;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

.hidden { display: none !important; }

.history-list {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: auto;
}

.history-empty {
  padding: 24px 10px;
  color: var(--subtle);
  border: 1px dashed #d6dee3;
  border-radius: 8px;
  font-size: 11px;
  line-height: 1.5;
  text-align: center;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 54px;
  padding: 6px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
}

.history-item:hover,
.history-item.active {
  background: var(--panel-soft);
  border-color: var(--line);
}

.history-item img {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  object-fit: cover;
  background: #edf1f3;
  border-radius: 7px;
}

.history-item strong {
  max-width: 160px;
  display: block;
  overflow: hidden;
  color: #2f3b45;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item span {
  display: block;
  margin-top: 3px;
  color: var(--subtle);
  font-size: 10px;
}

.history-item > div {
  min-width: 0;
  flex: 1;
}

.history-delete {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  color: #9aa5ad;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 7px;
  opacity: .78;
}

.history-delete:hover {
  color: #b8442d;
  background: var(--accent-soft);
  border-color: #f0c8bd;
  opacity: 1;
}

.tips {
  margin-top: 14px;
  padding-top: 14px;
  color: #737f88;
  border-top: 1px solid var(--line);
}

.tips strong {
  color: #46535d;
  font-size: 12px;
}

.tips p {
  margin: 8px 0 0;
  font-size: 11px;
  line-height: 1.6;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  z-index: 5;
  max-width: min(520px, calc(100vw - 32px));
  padding: 11px 16px;
  color: #fff;
  background: #1d2832;
  border-radius: 8px;
  box-shadow: 0 14px 32px rgba(17, 24, 39, .18);
  font-size: 12px;
  line-height: 1.45;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 18px);
  transition: opacity .2s, transform .2s;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
}

@media (max-width: 1120px) {
  .workspace {
    grid-template-columns: 292px minmax(0, 1fr);
  }

  .right-panel {
    display: none;
  }
}

@media (max-height: 860px) {
  .topbar {
    height: 58px;
    padding: 0 16px;
  }

  .workspace {
    height: calc(100vh - 58px);
  }

  .sidebar {
    padding: 14px;
  }

  .panel-heading {
    margin-bottom: 12px;
  }

  .divider {
    margin: 12px 0;
  }

  textarea {
    min-height: 104px;
  }

  .canvas-toolbar {
    height: 50px;
    padding: 0 16px;
  }

  .canvas-stage {
    padding: 16px;
  }
}

@media (max-width: 720px) {
  html,
  body {
    overflow: auto;
  }

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

  .topbar {
    height: 62px;
    padding: 0 14px;
  }

  .connection-status {
    display: none;
  }

  .update-status {
    display: none;
  }

  .workspace {
    display: block;
    height: auto;
    min-height: calc(100vh - 62px);
    overflow: visible;
  }

  .sidebar {
    overflow: visible;
  }

  .left-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .canvas-area {
    min-height: 560px;
  }

  .canvas-toolbar {
    height: auto;
    min-height: 54px;
    align-items: flex-start;
    flex-direction: column;
    padding: 12px 14px;
  }

  .toolbar-tools {
    width: 100%;
    justify-content: space-between;
  }

  .canvas-stage {
    min-height: 430px;
    padding: 16px;
  }

  .result-grid,
  .result-grid[data-count="2"] {
    grid-template-columns: 1fr;
  }

  .canvas-footer {
    min-height: 40px;
    height: auto;
    flex-wrap: wrap;
    padding: 10px 14px;
  }
}
