:root {
  color-scheme: light;
  --bg: #eef3f8;
  --panel: rgba(255, 255, 255, 0.94);
  --text: #101828;
  --muted: #667085;
  --line: #d8e1ed;
  --soft-line: rgba(112, 132, 158, 0.24);
  --accent: #1677ff;
  --accent-dark: #0f55bd;
  --accent-soft: #e8f2ff;
  --success: #12b76a;
  --danger: #f04438;
  --warm: #fff4f2;
  --shadow: 0 18px 48px rgba(20, 42, 72, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", sans-serif;
  color: var(--text);
  background: var(--bg);
}

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

button {
  border: 0;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(340px, 400px) 1fr;
  height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  overflow-y: auto;
  border-right: 1px solid var(--soft-line);
  background: rgba(244, 248, 252, 0.92);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 4px 4px;
}

.brand-mark {
  position: relative;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  overflow: visible;
  border-radius: 12px 12px 12px 4px;
  background: linear-gradient(135deg, #1677ff, #13b8a6);
  transform: rotate(-8deg);
  box-shadow: 0 8px 16px rgba(22, 119, 255, 0.22);
}

.brand-orbit {
  position: absolute;
  width: 23px;
  height: 15px;
  border: 3px solid #fff;
  border-radius: 50%;
  transform: rotate(-12deg);
}

.brand-eye {
  position: absolute;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #fff;
}

.brand-tail {
  position: absolute;
  right: -8px;
  top: 13px;
  width: 15px;
  height: 16px;
  border: 3px solid #ff5b68;
  border-left: 0;
  border-radius: 0 12px 12px 0;
  transform: rotate(-22deg);
}

.brand-dot {
  position: absolute;
  left: 7px;
  bottom: 6px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #ffcf5a;
}

.brand-block h1 {
  margin: 0;
  font-size: 21px;
  line-height: 1.1;
}

.brand-block p,
.section-head p,
.hint,
.history-empty,
.dock-empty {
  color: var(--muted);
}

.brand-block p {
  margin: 4px 0 0;
  font-size: 13px;
}

.panel {
  padding: 16px;
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 10px 30px rgba(20, 42, 72, 0.08);
}

.mode-panel,
.primary-panel {
  border-color: rgba(22, 119, 255, 0.24);
}

.section-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 14px;
}

.section-head > span {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  border-radius: 8px;
  color: var(--accent-dark);
  font-weight: 800;
  background: var(--accent-soft);
}

.section-head h2 {
  margin: 0;
  font-size: 17px;
}

.section-head p {
  margin: 4px 0 0;
  font-size: 12px;
  line-height: 1.5;
}

.field {
  display: block;
  margin-top: 12px;
}

.prompt-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 7px;
}

.prompt-tools {
  display: flex;
  align-items: center;
  gap: 6px;
}

.prompt-tool-button,
.quality-option {
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--muted);
  background: #fff;
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
}

.prompt-tool-button {
  padding: 6px 8px;
}

.prompt-tool-button:hover,
.quality-option:hover {
  color: var(--accent-dark);
  border-color: rgba(22, 119, 255, 0.4);
}

.quality-options {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.quality-option {
  min-height: 38px;
  padding: 8px 6px;
}

.quality-option.active {
  color: var(--accent-dark);
  border-color: rgba(22, 119, 255, 0.58);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px rgba(22, 119, 255, 0.14);
}

.prompt-label-row > span {
  font-size: 13px;
  font-weight: 800;
}

.prompt-expand-button {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid rgba(22, 119, 255, 0.28);
  border-radius: 7px;
  color: var(--accent-dark);
  background: var(--accent-soft);
  cursor: pointer;
  font-size: 17px;
  line-height: 1;
}

.prompt-expand-button:hover {
  border-color: var(--accent);
  background: #dbeaff;
}

.prompt-expand-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.field > span {
  display: block;
  margin-bottom: 7px;
  font-size: 13px;
  font-weight: 800;
}

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

textarea {
  min-height: 132px;
  resize: vertical;
  line-height: 1.6;
}

input:focus,
textarea:focus,
select:focus {
  border-color: rgba(22, 119, 255, 0.72);
  box-shadow: 0 0 0 4px rgba(22, 119, 255, 0.12);
}

.secret-row {
  display: grid;
  grid-template-columns: 1fr 44px;
  gap: 8px;
}

.icon-button,
.mini-actions button,
.toolbar-actions button,
.prompt-chips button,
.mode-button,
.secondary-button,
.history-actions button,
.history-actions a,
.latest-preview-actions button,
.latest-preview-actions a,
.history-tile button,
.history-tile a,
.drag-handle,
.download-button,
.image-node-toolbar button {
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #fff;
  cursor: pointer;
  text-decoration: none;
}

.key-visibility-button {
  display: grid;
  place-items: center;
  min-width: 44px;
}

.eye-icon {
  position: relative;
  display: block;
  width: 21px;
  height: 14px;
  border: 2px solid currentColor;
  border-radius: 75% 15%;
  transform: rotate(45deg);
}

.eye-icon::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  transform: translate(-50%, -50%);
}

.eye-closed {
  width: 22px;
  height: 10px;
  border-top: 2px solid currentColor;
  border-right: 0;
  border-bottom: 0;
  border-left: 0;
  border-radius: 50% 50% 0 0;
  transform: rotate(0deg);
}

.eye-closed::before {
  content: "";
  position: absolute;
  left: 1px;
  top: -2px;
  width: 24px;
  border-top: 2px solid currentColor;
  transform: rotate(-28deg);
}

.eye-closed::after {
  display: none;
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.mode-button {
  padding: 11px 12px;
  font-weight: 800;
  color: var(--muted);
  background: #f9fbff;
}

.mode-button.active {
  color: var(--accent-dark);
  border-color: rgba(22, 119, 255, 0.4);
  background: var(--accent-soft);
}

.secondary-button {
  padding: 11px 14px;
  font-weight: 800;
}

.authorization-state-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 10px;
  margin-top: 4px;
}

.section-head .authorization-state-row p {
  margin: 0;
}

.authorization-state-row p:not(.authorized) {
  flex-basis: 100%;
}

.authorization-button {
  flex-basis: 100%;
  width: 100%;
  min-height: 42px;
  padding: 10px 14px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  font-weight: 800;
  cursor: pointer;
}

.authorization-button.authorized {
  flex: 0 0 auto;
  width: auto;
  min-height: 0;
  padding: 0;
  border: 0;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
  font-weight: 700;
}

.authorization-button.authorized:hover {
  color: var(--accent-dark);
}

#authorizationStatus.authorized {
  color: #067647;
  font-weight: 800;
}

.authorization-dialog {
  width: min(440px, calc(100vw - 32px));
  max-width: none;
  max-height: calc(100vh - 24px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #fff;
  box-shadow: var(--shadow);
}

.authorization-dialog::backdrop {
  background: rgba(16, 24, 40, 0.48);
}

.authorization-dialog form {
  max-height: calc(100vh - 24px);
  padding: 20px;
  overflow-y: auto;
}

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

.authorization-dialog-head h2,
.authorization-dialog-head p {
  margin: 0;
}

.authorization-dialog-head h2 {
  font-size: 18px;
}

.authorization-dialog-head p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.dialog-close-button {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #fff;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.authorization-error {
  margin: 12px 0 0;
  color: #b42318;
  font-size: 13px;
  font-weight: 700;
}

.authorization-subsection {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--soft-line);
}

.authorization-subsection h3,
.authorization-subsection p {
  margin: 0;
}

.authorization-subsection h3 {
  font-size: 14px;
}

.authorization-subsection p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.authorization-subsection .field-grid {
  margin-top: 0;
}

.prompt-advisor-dialog {
  width: min(620px, calc(100vw - 32px));
  max-width: none;
  max-height: calc(100vh - 24px);
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #fff;
  box-shadow: var(--shadow);
}

.prompt-advisor-dialog::backdrop {
  background: rgba(16, 24, 40, 0.48);
}

.prompt-advisor-shell {
  display: grid;
  grid-template-rows: auto minmax(180px, 1fr) auto auto auto;
  max-height: calc(100vh - 24px);
  padding: 20px;
}

.prompt-advisor-messages {
  min-height: 180px;
  max-height: 360px;
  margin-top: 16px;
  padding: 14px;
  overflow-y: auto;
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  background: #f8fafc;
}

.prompt-advisor-message {
  width: fit-content;
  max-width: 86%;
  margin: 0 0 10px;
  padding: 9px 11px;
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  background: #fff;
  font-size: 13px;
  line-height: 1.65;
  white-space: pre-wrap;
}

.prompt-advisor-message.user {
  margin-left: auto;
  border-color: rgba(22, 119, 255, 0.24);
  background: var(--accent-soft);
}

.prompt-advisor-message:last-child {
  margin-bottom: 0;
}

.prompt-advisor-input {
  display: block;
  margin-top: 14px;
}

.prompt-advisor-input span {
  display: block;
  margin-bottom: 7px;
  font-size: 13px;
  font-weight: 800;
}

.prompt-advisor-input textarea {
  min-height: 82px;
  resize: vertical;
}

.prompt-advisor-actions,
.prompt-advisor-actions > div {
  display: flex;
  align-items: center;
  gap: 8px;
}

.prompt-advisor-actions {
  justify-content: space-between;
  margin-top: 14px;
}

#finishPromptAdvisor {
  padding: 11px 16px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  font-weight: 800;
  cursor: pointer;
}

.authorization-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.authorization-actions #saveAuthorization {
  padding: 11px 16px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  font-weight: 800;
  cursor: pointer;
}

.destructive-button {
  border-color: rgba(240, 68, 56, 0.28) !important;
  color: #b42318 !important;
  background: #fff4f2 !important;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.advanced-block {
  margin-top: 14px;
  border-top: 1px solid var(--soft-line);
  padding-top: 12px;
}

.advanced-block summary {
  cursor: pointer;
  color: var(--accent-dark);
  font-weight: 800;
  font-size: 13px;
}

.mini-actions,
.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.hint {
  margin: 10px 0 0;
  font-size: 12px;
  line-height: 1.6;
}

.model-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.model-pill {
  padding: 10px;
  border-radius: 8px;
  background: #f7faff;
  border: 1px solid var(--soft-line);
}

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

.model-pill strong {
  display: block;
  margin-top: 3px;
  font-size: 13px;
}

.prompt-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.prompt-chips button {
  padding: 8px 10px;
  color: var(--accent-dark);
  background: var(--accent-soft);
  border-color: transparent;
  font-size: 12px;
  font-weight: 800;
}

.action-row,
.host-upload-row,
.history-actions-head {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin-top: 14px;
}

.generate-button {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  width: 100%;
  padding: 15px 16px;
  border-radius: 8px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), #21a6ff);
  box-shadow: 0 16px 34px rgba(22, 119, 255, 0.26);
  cursor: pointer;
}

.generate-button span {
  font-size: 17px;
  font-weight: 900;
}

.generate-button small {
  opacity: 0.9;
}

.reference-preview {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  padding: 8px;
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  background: #f8fbff;
}

.reference-preview img {
  display: block;
  width: 64px;
  height: 64px;
  border-radius: 6px;
  object-fit: cover;
  background: #edf3fa;
}

.reference-preview span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 12px;
}

.workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  height: 100vh;
}

.workspace-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--soft-line);
  background: rgba(255, 255, 255, 0.86);
}

.workspace-toolbar strong {
  display: block;
  font-size: 15px;
}

.workspace-toolbar span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

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

.toolbar-actions button {
  min-width: 40px;
  padding: 9px 11px;
  font-size: 13px;
}

.novice-board {
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 24px;
  background: #f7fafc;
}

.novice-card {
  width: min(560px, 100%);
  padding: 26px;
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.novice-card h2 {
  margin: 0 0 8px;
  font-size: 24px;
}

.novice-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.canvas-viewport {
  position: relative;
  overflow: hidden;
  min-height: 0;
  background: #f8f6f1;
  cursor: grab;
  touch-action: none;
  padding-top: 56px;
  padding-right: 18px;
  padding-bottom: 18px;
  padding-left: 18px;
}

.canvas-hidden {
  display: none;
}

.canvas-viewport.dragging {
  cursor: grabbing;
}

.canvas-bg {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(120, 110, 95, 0.09) 1px, transparent 1px),
    linear-gradient(90deg, rgba(120, 110, 95, 0.09) 1px, transparent 1px);
  background-size: 32px 32px;
  opacity: 0.9;
}

.canvas-content {
  position: absolute;
  left: 0;
  top: 0;
  width: 1px;
  height: 1px;
  transform-origin: 0 0;
  z-index: 2;
}

.empty-state {
  position: absolute;
  left: 50%;
  top: 47%;
  width: min(460px, calc(100% - 48px));
  padding: 28px;
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow);
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
}

.empty-state h2 {
  margin: 0 0 8px;
}

.empty-state p {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.image-node {
  position: absolute;
  width: 320px;
  border: 1px solid rgba(255, 100, 100, 0.25);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 18px 40px rgba(20, 42, 72, 0.14);
  overflow: visible;
  user-select: none;
  cursor: grab;
  transition: box-shadow 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.image-node-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px;
  border-bottom: 1px solid rgba(255, 100, 100, 0.2);
  background: #fffafa;
}

.drag-handle,
.download-button {
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 800;
}

.image-node-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--accent-dark);
  font-size: 13px;
}

.image-node-toolbar {
  display: flex;
  gap: 6px;
}

.image-node-toolbar button {
  padding: 6px 7px;
  font-size: 12px;
}

.image-node-canvas {
  display: grid;
  place-items: center;
  min-height: 190px;
  margin: 12px;
  border: 1px dashed rgba(255, 100, 100, 0.35);
  border-radius: 8px;
  background: #fafafa;
  overflow: hidden;
}

.image-node-canvas img {
  display: block;
  width: 100%;
  max-height: 260px;
  object-fit: contain;
}

.image-edit-result.is-running {
  border-color: rgba(22, 119, 255, 0.55);
}

.image-edit-result.is-error {
  border-color: rgba(220, 38, 38, 0.55);
}

.upscale-result.is-running {
  border-color: rgba(22, 119, 255, 0.55);
}

.upscale-progress {
  display: block;
  width: min(180px, 100%);
  height: 6px;
  overflow: hidden;
  border-radius: 3px;
  background: #d9dee8;
}

.upscale-progress i {
  display: block;
  width: 0;
  height: 100%;
  background: #1677ff;
  transition: width 180ms ease;
}

.upscale-hardware-note {
  max-width: 220px;
  color: #667085;
  font-size: 11px;
  line-height: 1.5;
}

.terminal-node .image-node-canvas {
  border-color: rgba(22, 119, 255, 0.28);
}

.image-edit-error {
  display: grid;
  width: 100%;
  min-height: 188px;
  padding: 18px;
  place-content: center;
  gap: 10px;
  color: var(--danger);
  text-align: left;
}

.image-edit-error span {
  max-height: 88px;
  overflow: auto;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.image-edit-error button {
  justify-self: start;
  padding: 8px 12px;
  border-color: rgba(22, 119, 255, 0.35);
  color: var(--accent-dark);
  background: #fff;
}

.image-node-note {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  min-height: 48px;
  margin: 0 12px 10px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.connection-dot {
  position: absolute;
  right: 8px;
  top: calc(50% - 9px);
  width: 18px;
  height: 18px;
  border: 2px solid #ff6464;
  border-radius: 50%;
  background: #fff;
  cursor: crosshair;
  touch-action: none;
  z-index: 4;
}

.connection-line {
  position: absolute;
  left: 0;
  top: 0;
  width: 1px;
  height: 1px;
  overflow: visible;
  pointer-events: none;
  z-index: 1;
}

.connection-line path {
  fill: none;
  stroke: rgba(22, 119, 255, 0.62);
  stroke-width: 3px;
  stroke-linecap: round;
}

.connection-preview path {
  stroke: rgba(22, 119, 255, 0.46);
  stroke-dasharray: 8 8;
}

.workflow-step-menu {
  position: absolute;
  z-index: 20;
  display: grid;
  width: 164px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 16px 36px rgba(20, 42, 72, 0.16);
}

.workflow-step-menu strong {
  padding: 6px 8px 8px;
  color: var(--muted);
  font-size: 12px;
}

.workflow-step-menu .upscale-menu-title {
  margin-top: 5px;
  border-top: 1px solid var(--soft-line);
  padding-top: 10px;
}

.workflow-step-menu button {
  padding: 9px 10px;
  border: 0;
  border-radius: 6px;
  color: var(--text);
  background: transparent;
  cursor: pointer;
  text-align: left;
}

.workflow-step-menu button[data-upscale-target] {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.workflow-step-menu button[data-upscale-target] small {
  color: var(--muted);
  font-size: 10px;
}

.workflow-step-menu button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.workflow-step-menu .local-engine-download {
  margin: 5px 4px 2px;
  padding: 7px 6px 3px;
  border-top: 1px solid var(--soft-line);
  color: var(--accent-dark);
  font-size: 11px;
  text-decoration: none;
}

.workflow-step-menu button:hover {
  color: var(--accent-dark);
  background: var(--accent-soft);
}

.image-edit-node {
  width: 300px;
  padding-bottom: 12px;
}

.image-edit-source {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) minmax(42px, auto);
  align-items: center;
  gap: 10px;
  margin: 12px;
  padding: 8px;
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  color: var(--muted);
  background: #f8fbff;
  font-size: 12px;
}

.image-edit-source img {
  display: block;
  width: 58px;
  height: 58px;
  border-radius: 6px;
  object-fit: cover;
}

.image-edit-reference-button {
  display: grid;
  width: 48px;
  height: 48px;
  padding: 0;
  place-items: center;
  overflow: hidden;
  border: 1px dashed var(--line);
  border-radius: 6px;
  color: var(--accent-dark);
  background: #fff;
  cursor: pointer;
  font-size: 22px;
}

.image-edit-references {
  display: flex;
  gap: 5px;
}

.image-edit-reference {
  position: relative;
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.image-edit-reference img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.image-edit-reference button {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: #fff;
  background: rgba(17, 24, 39, 0.78);
  font-size: 14px;
  line-height: 18px;
}

.image-edit-field {
  display: block;
  margin: 0 12px 10px;
}

.image-edit-field span {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 800;
}

.image-edit-field textarea {
  min-height: 92px;
  resize: vertical;
}

.image-edit-submit {
  width: calc(100% - 24px);
  margin: 0 12px;
  padding: 10px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  cursor: pointer;
  font-weight: 800;
}

.loading-box,
.error-box {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 190px;
  padding: 18px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.generation-loading {
  gap: 10px;
  align-content: center;
  background: linear-gradient(135deg, #f5f9ff, #fff);
}

.generation-loading strong {
  color: var(--text);
  font-size: 14px;
}

.generation-loading small {
  color: var(--muted);
}

.generation-spinner {
  width: 30px;
  height: 30px;
  border: 3px solid rgba(22, 119, 255, 0.18);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: generation-spin 0.8s linear infinite;
}

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

.error-box {
  color: #b42318;
  background: #fff4f2;
}

.latest-preview {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 12px;
  padding: 10px;
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  background: #fbfdff;
}

.latest-preview img,
.history-item img,
.history-tile img {
  object-fit: cover;
  background: #edf3fa;
}

.latest-preview img {
  width: 120px;
  height: 120px;
  border-radius: 6px;
}

.latest-preview-image,
.history-row-image {
  display: block;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
}

.latest-preview-image {
  width: 120px;
  height: 120px;
}

.history-row-image {
  width: 76px;
  height: 76px;
}

.latest-preview-body {
  min-width: 0;
}

.latest-preview-body strong,
.history-body strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.latest-preview-body p,
.history-body p {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  margin: 7px 0 10px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.latest-preview-actions,
.history-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.latest-preview-actions button,
.latest-preview-actions a,
.history-actions button,
.history-actions a {
  padding: 7px 8px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
}

.empty-preview {
  display: grid;
  place-items: center;
  min-height: 150px;
  color: var(--muted);
  text-align: center;
}

.image-host-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 12px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  font-size: 13px;
  font-weight: 800;
  text-align: center;
  text-decoration: none;
}

.history-list {
  display: grid;
  gap: 10px;
  max-height: 220px;
  overflow: auto;
  padding-right: 2px;
}

.history-item {
  display: grid;
  grid-template-columns: 76px 1fr;
  gap: 10px;
  padding: 9px;
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  background: #fbfdff;
}

.history-item img {
  width: 76px;
  height: 76px;
  border-radius: 6px;
}

.history-body {
  min-width: 0;
}

.history-body > span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 7px;
}

.history-empty {
  margin: 8px 0 0;
  font-size: 12px;
}

.history-dock {
  display: grid;
  grid-template-columns: 170px 1fr;
  gap: 12px;
  min-height: 150px;
  padding: 12px;
  border-top: 1px solid rgba(240, 68, 56, 0.24);
  background: var(--warm);
}

.history-dock-label h3 {
  margin: 0 0 6px;
  color: #b42318;
  font-size: 14px;
}

.history-dock-label p {
  margin: 0 0 10px;
  color: #b42318;
  font-size: 12px;
  line-height: 1.6;
}

.history-dock-label .secondary-button {
  width: 100%;
  padding: 9px 10px;
  font-size: 12px;
}

.history-dock-grid {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 120px;
  gap: 8px;
  overflow-x: auto;
  align-items: start;
}

.history-tile {
  position: relative;
  display: grid;
  gap: 6px;
  padding: 8px;
  border: 1px solid rgba(240, 68, 56, 0.26);
  border-radius: 8px;
  background: #fff;
}

.history-delete-button {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 50%;
  background: rgba(20, 24, 28, 0.78);
  color: #fff;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.history-delete-button:hover {
  background: #b42318;
}

.history-tile img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 6px;
}

.history-image-button {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
}

.history-image-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.history-image-dialog {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #fff;
  box-shadow: var(--shadow);
}

.history-image-dialog::backdrop {
  background: rgba(16, 24, 40, 0.38);
}

.history-image-dialog strong {
  display: block;
  margin-bottom: 14px;
}

.history-image-dialog div {
  display: flex;
  gap: 8px;
}

.history-image-dialog button {
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  background: #fff;
  cursor: pointer;
}

.uploaded-image-link {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 9px 12px;
  border: 1px solid var(--accent);
  border-radius: 7px;
  color: #fff;
  background: var(--accent);
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}


.history-tile div {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
}

.history-tile button,
.history-tile a {
  display: grid;
  place-items: center;
  min-height: 28px;
  padding: 5px;
  color: var(--accent-dark);
  font-size: 11px;
  font-weight: 800;
}

.dock-empty {
  align-self: center;
  margin: 0;
  font-size: 13px;
}

.hidden {
  display: none !important;
}

@media (max-width: 940px) {
  body {
    overflow: auto;
  }

  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
  }

  .sidebar {
    height: auto;
    overflow: visible;
    border-right: 0;
    border-bottom: 1px solid var(--soft-line);
  }

  .workspace {
    height: 78vh;
  }

  .workspace-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .image-node {
    width: 300px;
  }

  .workflow-step-menu .upscale-menu-title,
  .workflow-step-menu button[data-upscale-target],
  .workflow-step-menu .local-engine-download {
    display: none;
  }
}

@media (max-width: 520px) {
  .sidebar {
    padding: 12px;
  }

  .field-grid,
  .mini-actions,
  .action-row,
  .host-upload-row,
  .history-actions-head,
  .history-dock {
    grid-template-columns: 1fr;
  }

  .model-meta {
    grid-template-columns: 1fr;
  }

  .workspace {
    height: 74vh;
  }

  .history-dock-grid {
    grid-auto-columns: 108px;
  }

  .history-image-dialog {
    width: calc(100vw - 24px);
    max-width: none;
  }

  .authorization-dialog {
    width: calc(100% - 24px);
  }

  .prompt-advisor-dialog {
    width: calc(100% - 24px);
  }

  .prompt-advisor-shell {
    padding: 16px;
  }

  .prompt-advisor-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .prompt-advisor-actions > div,
  .prompt-advisor-actions button {
    width: 100%;
  }

  .authorization-dialog form {
    padding: 16px;
  }

  .history-image-dialog div {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .history-image-dialog button,
  .uploaded-image-link {
    justify-content: center;
    min-width: 0;
  }
}
.canvas-action-bar {
  position: absolute;
  left: 50%;
  top: 14px;
  z-index: 4;
  display: inline-flex;
  gap: 8px;
  align-items: center;
  transform: translateX(-50%);
  padding: 8px;
  border: 1px solid rgba(15, 85, 189, 0.18);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 14px 30px rgba(20, 42, 72, 0.1);
  backdrop-filter: blur(14px);
}

.canvas-action-bar button {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
}
.image-node.selected {
  border-color: rgba(22, 119, 255, 0.9);
  box-shadow: 0 0 0 2px rgba(22, 119, 255, 0.16), 0 18px 40px rgba(20, 42, 72, 0.16);
}

.image-node:focus-visible {
  outline: 2px solid rgba(22, 119, 255, 0.85);
  outline-offset: 2px;
}

.icp-link {
  display: block;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
  text-decoration: none;
}

.icp-link:hover {
  color: var(--accent-dark);
  text-decoration: underline;
}
