:root {
  color-scheme: dark;
  --bg: #07080a;
  --panel: #141519;
  --panel-2: #1b1d23;
  --panel-3: #24272f;
  --line: #2b2f38;
  --line-strong: #4d89e8;
  --text: #f4f7fb;
  --muted: #8f96a3;
  --blue: #2e7bff;
  --blue-soft: rgba(46, 123, 255, 0.18);
  --purple: #9b5cff;
  --green: #52d37e;
  --danger: #ff4d5d;
  --shadow: 0 18px 54px rgba(0, 0, 0, 0.35);
}

body.light {
  color-scheme: light;
  --bg: #f4f6fa;
  --panel: #ffffff;
  --panel-2: #f6f7fa;
  --panel-3: #ebedf2;
  --line: #d9dee8;
  --line-strong: #246bea;
  --text: #151922;
  --muted: #697180;
  --blue-soft: rgba(36, 107, 234, 0.12);
  --shadow: 0 18px 42px rgba(44, 58, 82, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

[hidden] {
  display: none !important;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(7, 8, 10, 0.92);
  backdrop-filter: blur(14px);
}

.login-screen.hidden {
  display: none;
}

.login-card {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 32px;
  display: grid;
  gap: 16px;
}

.login-logo {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #16d6ff, #7657ff);
  font-weight: 900;
  color: white;
}

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

.login-card p {
  margin: 0;
  color: var(--muted);
}

.login-card input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  padding: 14px 16px;
}

.login-card button {
  padding: 13px 16px;
  background: var(--blue);
  border-color: var(--blue);
  font-weight: 800;
}

#loginError {
  min-height: 20px;
  color: var(--danger);
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  pointer-events: auto;
}

button:hover {
  border-color: var(--line-strong);
}

.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  min-height: 100vh;
  overflow: hidden;
  transition: grid-template-columns 0.18s ease;
}

.app-shell.sidebar-collapsed {
  grid-template-columns: 54px minmax(0, 1fr);
}

.sidebar {
  background: #07080a;
  border-right: 1px solid var(--line);
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow: hidden;
}

body.light .sidebar {
  background: #f8f9fc;
}

.side-head,
.brand,
.actions,
.node-head,
.panel-head,
.node-controls,
.preview-actions {
  display: flex;
  align-items: center;
}

.side-head {
  height: 40px;
  gap: 10px;
  font-size: 22px;
}

.side-icon {
  color: var(--blue);
}

.icon-btn {
  margin-left: auto;
  width: 34px;
  height: 34px;
}

.sidebar-collapsed .sidebar {
  padding: 16px 9px;
  align-items: center;
}

.sidebar-collapsed .side-head {
  width: 100%;
  justify-content: center;
}

.sidebar-collapsed .side-icon,
.sidebar-collapsed .side-head strong,
.sidebar-collapsed .new-project,
.sidebar-collapsed .side-section {
  display: none;
}

.sidebar-collapsed .icon-btn {
  margin-left: 0;
  width: 36px;
  height: 36px;
}

.new-project {
  height: 48px;
  font-weight: 700;
  font-size: 16px;
}

.side-section {
  display: grid;
  gap: 8px;
}

.section-title {
  border: 0;
  background: transparent;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  padding: 8px 4px;
}

.project-list {
  display: grid;
  gap: 6px;
}

.list-row {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px;
  gap: 4px;
  align-items: center;
}

.project-item,
.tutorial {
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  background: transparent;
  border-color: transparent;
  color: var(--text);
  text-align: left;
}

.row-more {
  width: 34px;
  height: 34px;
  padding: 0;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  opacity: 0;
}

.list-row:hover .row-more,
.project-item.active + .row-more {
  opacity: 1;
}

.project-item.active {
  background: #112746;
  border-color: #1c64c7;
  color: #62a6ff;
}

body.light .project-item.active {
  background: #e7f0ff;
}

.tutorial {
  color: #d7c1ff;
}

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

.row-menu {
  display: none;
  position: fixed;
  z-index: 60;
  width: 170px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(42, 45, 53, 0.98);
  box-shadow: var(--shadow);
}

.row-menu.open {
  display: grid;
  gap: 4px;
}

.row-menu button {
  height: 42px;
  padding: 0 12px;
  border-color: transparent;
  background: transparent;
  color: #fff;
  text-align: left;
  font-weight: 700;
}

.row-menu button:hover {
  background: rgba(255, 255, 255, 0.12);
}

.row-menu .danger {
  color: #ff7878;
}

.workspace {
  min-width: 0;
  display: grid;
  grid-template-rows: 64px minmax(0, 1fr);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px 0 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(7, 8, 10, 0.94);
}

body.light .topbar {
  background: rgba(255, 255, 255, 0.94);
}

.brand {
  gap: 12px;
}

.logo {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 900;
  background: conic-gradient(from 120deg, #216cff, #984fff, #24d7a0, #216cff);
}

.brand strong {
  font-size: 20px;
}

.brand span {
  color: var(--muted);
}

.actions {
  gap: 10px;
}

.actions button,
.preview-actions button {
  height: 36px;
  padding: 0 14px;
}

.work-area {
  min-height: 0;
  display: grid;
  grid-template-columns: 68px minmax(0, 1fr);
}

.rail {
  background: var(--bg);
  border-right: 1px solid var(--line);
  padding: 24px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.rail-btn {
  width: 48px;
  height: 48px;
  font-size: 20px;
  background: transparent;
  color: var(--muted);
}

.rail-btn.active,
.rail-btn:hover {
  background: var(--panel-3);
  color: var(--text);
}

.rail-spacer {
  flex: 1;
}

.canvas-wrap {
  position: relative;
  overflow: hidden;
  background-color: #0a0c10;
  background-image: radial-gradient(circle, rgba(128, 139, 158, 0.26) 1px, transparent 1px);
  background-size: 25px 25px;
  cursor: grab;
}

.canvas-wrap.panning {
  cursor: grabbing;
}

.zoom-controls {
  position: absolute;
  right: 18px;
  bottom: 18px;
  z-index: 18;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(18, 20, 25, 0.94);
  box-shadow: var(--shadow);
}

.zoom-controls button {
  height: 32px;
  min-width: 34px;
  padding: 0 10px;
  font-weight: 800;
}

.zoom-controls span {
  min-width: 48px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.history-panel {
  position: absolute;
  z-index: 12;
  left: 0;
  top: 0;
  bottom: 0;
  width: 460px;
  background: rgba(18, 20, 25, 0.98);
  border-right: 1px solid var(--line);
  transform: translateX(-100%);
  transition: transform 160ms ease;
  box-shadow: var(--shadow);
}

.history-panel.open {
  transform: translateX(0);
}

.history-panel header {
  height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
}

.history-panel header strong {
  font-size: 20px;
}

.history-panel header div {
  display: flex;
  gap: 8px;
}

.history-panel header button {
  width: 34px;
  height: 34px;
  padding: 0;
}

.history-list {
  height: calc(100% - 70px);
  overflow: auto;
  padding: 16px;
  display: grid;
  align-content: start;
  gap: 12px;
}

.history-empty {
  color: var(--muted);
  padding: 28px 8px;
  line-height: 1.7;
}

.history-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  padding: 12px;
  display: grid;
  gap: 8px;
}

.history-thumb {
  height: 118px;
  border-radius: 8px;
  border: 1px solid var(--line);
  overflow: hidden;
  background:
    linear-gradient(90deg, transparent 0 18%, rgba(255,255,255,.12) 18% 19%, transparent 19% 43%, rgba(255,255,255,.12) 43% 44%, transparent 44%),
    linear-gradient(180deg, #1b2432 0 58%, #2b3a37 58% 100%);
}

.history-thumb.has-media img,
.history-thumb.has-media video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.history-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

.history-item button {
  height: 32px;
}

body.light .canvas-wrap {
  background-color: #f8fafc;
  background-image: radial-gradient(circle, rgba(67, 81, 107, 0.22) 1px, transparent 1px);
}

.canvas {
  position: relative;
  width: 1800px;
  height: 1000px;
  transform-origin: 0 0;
}

.connections {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.node {
  position: absolute;
  z-index: 2;
  background: rgba(22, 24, 29, 0.96);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  user-select: none;
  cursor: default;
  will-change: transform, left, top;
  contain: layout style;
}

.node.dragging {
  z-index: 12;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.28);
  cursor: grabbing;
}

.node-grip {
  position: absolute;
  left: 50%;
  top: -7px;
  transform: translateX(-50%);
  width: 38px;
  height: 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 0 14px rgba(102, 166, 255, 0.55);
  cursor: grab;
}

.node-grip:active {
  cursor: grabbing;
}

body.light .node {
  background: rgba(255, 255, 255, 0.98);
}

.node.selected {
  border-color: var(--line-strong);
  box-shadow: 0 0 0 1px rgba(46, 123, 255, 0.32), 0 18px 54px rgba(16, 73, 164, 0.22);
}

.node.selected::after {
  content: "";
  position: absolute;
  left: 20px;
  right: 20px;
  bottom: -18px;
  height: 34px;
  border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(75, 157, 255, 0.72), rgba(46, 123, 255, 0.26) 45%, transparent 72%);
  filter: blur(6px);
  pointer-events: none;
  z-index: -1;
}

.node.dragging::after {
  display: none;
}

.upload-node {
  left: 120px;
  top: 220px;
  width: 300px;
  height: 300px;
  display: grid;
  place-items: center;
  cursor: grab;
}

.upload-node.dragging {
  cursor: grabbing;
}

.upload-node .node-grip {
  width: 58px;
  height: 16px;
  top: -9px;
  z-index: 8;
}

.drop-zone {
  position: relative;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  color: var(--muted);
  text-align: center;
  padding: 24px;
}

.drop-zone.dragging {
  background: var(--blue-soft);
}

.image-badge {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: var(--panel-3);
  color: var(--muted);
  font-size: 28px;
}

#sourcePreview {
  display: none;
  max-width: 240px;
  max-height: 150px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--line);
}

.drop-zone.has-image #sourcePreview {
  display: block;
}

.drop-zone.has-image .image-badge {
  display: none;
}

#removeImageBtn {
  display: none;
  position: absolute;
  top: 12px;
  right: 12px;
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 50%;
  background: rgba(255, 91, 91, 0.92);
  border-color: rgba(255, 255, 255, 0.18);
  color: #fff;
  font-size: 20px;
  font-weight: 900;
  line-height: 1;
  z-index: 3;
}

.drop-zone.has-image #removeImageBtn {
  display: grid;
  place-items: center;
}

#pickImageBtn,
.run-btn,
.chips button.active {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
  font-weight: 700;
}

.drop-zone p {
  margin: 0;
  font-size: 13px;
  line-height: 1.7;
}

.generator-node {
  left: 560px;
  top: 145px;
  width: 560px;
  min-height: 650px;
  padding: 14px;
}

.preview-node {
  left: 1240px;
  top: 165px;
  width: 460px;
  min-height: 380px;
  padding: 12px;
}

.generic-node {
  width: 270px;
  min-height: 190px;
  padding: 12px;
}

.connection-ghost-node {
  pointer-events: none;
  opacity: 0.72;
  border-color: rgba(96, 165, 250, 0.95);
  box-shadow: 0 0 0 1px rgba(96, 165, 250, 0.35), 0 18px 46px rgba(37, 99, 235, 0.3);
  transform: scale(0.98);
}

.connection-ghost-node .node-upload-box {
  border-color: rgba(147, 197, 253, 0.95);
  background: rgba(37, 99, 235, 0.16);
}

.generic-node p {
  margin: 0 0 12px;
  color: var(--muted);
  line-height: 1.6;
  font-size: 13px;
}

.generic-node textarea {
  height: 76px;
}

.node-media {
  width: 100%;
  height: 128px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0d1118;
}

.node-media img,
.node-media video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.node-upload-box {
  width: 100%;
  height: 128px;
  margin-bottom: 10px;
  border: 1px dashed rgba(96, 165, 250, 0.7);
  border-radius: 8px;
  background: rgba(37, 99, 235, 0.08);
  color: #dbeafe;
  display: grid;
  place-items: center;
  text-align: center;
  cursor: pointer;
  overflow: hidden;
}

.node-upload-box span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 6px;
  background: #2f7df6;
  color: #fff;
  font-weight: 800;
}

.node-upload-box small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
}

.node-upload-box.dragging {
  border-color: #fff;
  background: rgba(47, 125, 246, 0.2);
}

.node-upload-box img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.node-result-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.generic-node .port.out {
  min-width: 82px;
  height: 30px;
  right: -82px;
  border-radius: 15px;
  gap: 5px;
  padding: 0 8px 0 2px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

.mini-delete {
  width: 28px;
  height: 28px;
  padding: 0;
}

.node-head {
  justify-content: space-between;
  margin-bottom: 10px;
}

.mode-tabs {
  display: inline-flex;
  gap: 6px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
}

.mode-tabs button {
  height: 30px;
  padding: 0 12px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.mode-tabs button.active {
  background: var(--blue);
  color: #fff;
}

.node-head span {
  color: var(--muted);
  font-size: 13px;
}

.generation-timer {
  height: 34px;
  margin-bottom: 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: rgba(47, 125, 246, 0.18);
  color: #8cc7ff;
  display: grid;
  place-items: center;
  font-weight: 800;
  letter-spacing: 0;
}

.generation-timer.hidden {
  display: none;
}

.generation-timer.done {
  border-color: rgba(82, 211, 126, 0.65);
  background: rgba(82, 211, 126, 0.12);
  color: var(--green);
}

.generation-timer.error {
  border-color: rgba(255, 77, 93, 0.65);
  background: rgba(255, 77, 93, 0.12);
  color: var(--danger);
}

#statusPill.running {
  color: #ffd166;
}

#statusPill.done {
  color: var(--green);
}

textarea {
  width: 100%;
  height: 170px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(8, 9, 12, 0.82);
  color: var(--text);
  padding: 14px;
  line-height: 1.65;
}

body.light textarea {
  background: #f8fafc;
}

.prompt-panel {
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.panel-head {
  gap: 10px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 13px;
}

.panel-head button {
  height: 30px;
  padding: 0 10px;
}

.panel-head button.active {
  border-color: rgba(47, 125, 246, 0.75);
  background: var(--blue);
  color: #fff;
}

.panel-head span {
  margin-left: auto;
}

.chips {
  height: 104px;
  overflow: auto;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 8px;
}

.prompt-chip {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px 6px 4px 10px;
  background: rgba(255, 255, 255, 0.03);
}

.prompt-chip.active {
  border-color: var(--line-strong);
  background: var(--blue-soft);
}

.prompt-chip button {
  height: 32px;
  white-space: nowrap;
  border-radius: 6px;
}

.prompt-chip-label {
  max-width: 190px;
  padding: 0;
  border: 0;
  overflow: hidden;
  background: transparent;
  color: var(--text);
  text-overflow: ellipsis;
}

.prompt-chip-apply {
  padding: 0 9px;
  border-color: transparent;
  background: var(--blue);
  color: #fff;
  font-weight: 800;
}

.prompt-chip-delete {
  display: none;
  padding: 0 9px;
  border-color: rgba(255, 77, 93, 0.5);
  background: rgba(255, 77, 93, 0.14);
  color: #ff9aa6;
  font-weight: 800;
}

.prompt-panel.managing .prompt-chip {
  border-color: rgba(255, 77, 93, 0.35);
}

.prompt-panel.managing .prompt-chip-apply {
  display: none;
}

.prompt-panel.managing .prompt-chip-delete {
  display: inline-flex;
}

.prompt-panel.collapsed .chips,
.prompt-panel.collapsed .custom-prompt {
  display: none;
}

.preset-tool-panel {
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.02);
}

.preset-tool-panel .panel-head strong {
  color: var(--text);
  font-size: 13px;
}

.preset-tools {
  max-height: 148px;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.preset-tool {
  min-height: 34px;
  padding: 6px 10px;
  text-align: left;
  line-height: 1.35;
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
}

.preset-tool:hover,
.preset-tool.active {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
  font-weight: 700;
}

.node-controls {
  gap: 8px;
  margin-top: 10px;
}

.select-wrap {
  position: relative;
  flex: 1;
}

.select-field {
  width: 100%;
  height: 36px;
  text-align: left;
  padding: 0 12px;
}

.menu {
  display: none;
  position: absolute;
  left: 0;
  bottom: 42px;
  width: 220px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  z-index: 10;
  pointer-events: auto;
}

.menu.open {
  display: grid;
  gap: 4px;
}

.menu button {
  height: 34px;
  padding: 0 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-color: transparent;
  background: transparent;
  color: var(--text);
}

.menu button:hover {
  background: var(--panel-3);
}

#ratioBtn,
#qualityBtn,
.run-btn {
  width: 48px;
  height: 36px;
}

.preview-stage {
  height: 280px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111318;
  display: grid;
  place-items: center;
  overflow: hidden;
}

body.light .preview-stage {
  background: #f4f6fa;
}

.empty-preview {
  color: var(--muted);
  text-align: center;
  line-height: 1.7;
  font-size: 13px;
}

.empty-preview span {
  font-size: 32px;
}

.mock-result {
  width: 100%;
  height: 100%;
  padding: 18px;
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 12px;
}

.result-media {
  width: 100%;
  min-height: 0;
  height: 100%;
  object-fit: contain;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: #0b0d12;
}

.mock-scene {
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background:
    linear-gradient(90deg, transparent 0 17%, rgba(255,255,255,.16) 17% 18%, transparent 18% 43%, rgba(255,255,255,.14) 43% 44%, transparent 44%),
    linear-gradient(180deg, #1b2432 0 58%, #2b3a37 58% 100%);
  position: relative;
  overflow: hidden;
}

.mock-watermark {
  position: absolute;
  right: 14px;
  top: 14px;
  padding: 6px 10px;
  border: 1px solid rgba(255, 209, 102, 0.45);
  border-radius: 8px;
  color: #ffd166;
  background: rgba(0, 0, 0, 0.36);
  font-size: 12px;
  font-weight: 800;
}

.mock-scene::before {
  content: "";
  position: absolute;
  left: 9%;
  right: 9%;
  bottom: 14%;
  height: 32%;
  border: 1px solid rgba(255,255,255,.22);
  background: rgba(221, 230, 224, 0.14);
}

.mock-scene::after {
  content: "";
  position: absolute;
  left: 18%;
  top: 20%;
  width: 64%;
  height: 22%;
  border: 1px solid rgba(255,255,255,.18);
  background: rgba(117, 143, 178, 0.24);
}

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

.preview-actions {
  gap: 8px;
  margin-top: 10px;
}

.preview-actions button {
  flex: 1;
  padding: 0 8px;
  font-size: 13px;
}

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

.reference-tools button {
  min-height: 34px;
  padding: 6px 8px;
  font-size: 12px;
}

.reference-tools span {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 12px;
}

.chat-panel {
  position: fixed;
  top: 72px;
  right: 0;
  bottom: 0;
  z-index: 500;
  width: min(500px, 42vw);
  min-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  border-left: 1px solid var(--line);
  background: rgba(14, 15, 19, 0.98);
  box-shadow: -20px 0 50px rgba(0, 0, 0, 0.35);
  transform: translateX(100%);
  transition: transform 0.18s ease;
  overflow-y: auto;
}

.chat-panel.open {
  transform: translateX(0);
}

.chat-panel header,
.chat-model-row,
.chat-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-panel header {
  justify-content: space-between;
}

.chat-panel header button {
  width: 34px;
  height: 34px;
}

.chat-model-row input,
.chat-model-row select {
  min-width: 0;
  flex: 1;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  padding: 0 10px;
}

.chat-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex: 0 0 auto;
}

.chat-presets button {
  height: 36px;
  padding: 0 10px;
  border-radius: 6px;
}

.chat-draft-tools {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
}

.chat-draft-tools select,
.chat-draft-tools button {
  height: 36px;
  min-width: 0;
  border-radius: 6px;
}

.chat-draft-box {
  display: grid;
  gap: 8px;
  min-height: 0;
  flex: 0 0 auto;
}

.chat-draft-box span {
  color: var(--muted);
  font-size: 13px;
}

.chat-draft-box textarea {
  min-height: 112px;
  height: clamp(112px, 20vh, 160px);
  max-height: 160px;
  resize: vertical;
  overflow: auto;
  line-height: 1.65;
  border-color: var(--line-strong);
  font-size: 15px;
}

.chat-preview {
  min-height: 66px;
  flex: 0 0 auto;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 8px 0;
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
}

.chat-preview img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--line);
}

.chat-preview > div {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.chat-ref-thumbs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  align-items: center;
  max-width: 100%;
  padding-bottom: 2px;
}

.chat-ref-item {
  position: relative;
  flex: 0 0 auto;
  display: inline-grid;
}

.chat-preview img.chat-ref-thumb {
  width: 34px;
  height: 34px;
  border-color: var(--line-strong);
}

.chat-ref-item button {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  padding: 0;
  border-radius: 50%;
  background: var(--red);
  border-color: var(--red);
  color: #fff;
  font-size: 13px;
  line-height: 1;
}

.chat-clear-refs {
  height: 28px;
  padding: 0 8px;
  flex: 0 0 auto;
  border-radius: 6px;
  color: var(--muted);
}

.chat-log {
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 10px;
  max-height: 116px;
  min-height: 44px;
  flex: 0 0 auto;
}

.chat-message {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  line-height: 1.6;
}

.chat-message.user {
  border-color: var(--line-strong);
}

.chat-message.muted {
  color: var(--muted);
}

.chat-input-row {
  align-items: flex-end;
  flex: 0 0 auto;
  margin-top: auto;
  position: relative;
  z-index: 5;
  pointer-events: auto;
}

.chat-input-row .chat-attach-btn,
.chat-input-row .chat-send-btn {
  width: 44px;
  min-width: 44px;
  height: 46px;
  flex: 0 0 auto;
  font-size: 14px;
  font-weight: 800;
}

.chat-input-row input[type="text"] {
  height: 46px;
  flex: 1;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  padding: 0 14px;
  font-size: 15px;
  outline: none;
  pointer-events: auto;
}

.chat-input-row input[type="text"]:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(47, 126, 255, 0.18);
}

.chat-input-row .chat-send-btn {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
  font-weight: 900;
  font-size: 20px;
}

.chat-input-row .chat-send-btn:disabled {
  opacity: 0.75;
  cursor: progress;
}

.chat-apply-btn {
  width: 100%;
  height: 46px;
  flex: 0 0 auto;
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
  font-weight: 800;
}

.port {
  position: absolute;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  background: var(--panel-3);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 12px;
  user-select: none;
}

.port.out {
  right: -10px;
  top: 50%;
  transform: translateY(-50%);
  cursor: pointer;
  touch-action: none;
  z-index: 8;
}

.upload-node .port.out {
  min-width: 86px;
  height: 30px;
  right: -86px;
  border-radius: 15px;
  gap: 5px;
  padding: 0 8px 0 2px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

.port.out b {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--panel-3);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
}

.port.out em {
  font-style: normal;
  color: var(--muted);
}

.plus-port {
  width: 22px;
  min-width: 22px;
  height: 22px;
  right: -12px;
  border-radius: 50%;
  background: transparent;
  border: 0;
  padding: 0;
}

.plus-port b {
  width: 22px;
  height: 22px;
  background: var(--panel-2);
  border-color: var(--line);
}

.port.out:hover b,
.plus-port:hover b {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

.port.in {
  left: -10px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--line-strong);
}

dialog {
  border: 0;
  padding: 0;
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.modal {
  width: min(520px, calc(100vw - 28px));
  padding: 20px;
}

.modal header,
.modal menu {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0;
}

.modal h2 {
  margin: 0;
}

.modal label {
  display: grid;
  gap: 8px;
  margin-top: 16px;
  color: var(--muted);
}

.modal input,
.custom-prompt input,
.custom-prompt textarea,
.model-card input,
.model-card select {
  height: 42px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 8px;
  padding: 0 12px;
}

.hint {
  color: var(--muted);
  line-height: 1.7;
}

.custom-prompt {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.custom-prompt textarea {
  height: 78px;
  resize: none;
  padding: 10px 12px;
}

.custom-prompt button,
.model-config-head button {
  height: 36px;
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
  font-weight: 700;
}

.compact-select {
  flex: 0 0 48px;
}

.compact-select .menu {
  width: 108px;
  right: 0;
  left: auto;
}

.node-menu {
  display: none;
  position: absolute;
  z-index: 20;
  width: 230px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(48, 51, 59, 0.96);
  box-shadow: var(--shadow);
}

.node-menu.open {
  display: grid;
  gap: 4px;
}

.node-menu button {
  height: 42px;
  padding: 0 14px;
  border-color: transparent;
  background: transparent;
  color: #fff;
  text-align: left;
  font-weight: 700;
}

.node-menu button:hover {
  background: rgba(255, 255, 255, 0.14);
}

.switch-row {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.switch-row small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

.switch-row input {
  width: 48px;
  accent-color: var(--blue);
}

.model-config-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
  color: var(--muted);
}

.model-config-head span {
  flex: 1;
}

#presetApiyiBtn {
  background: var(--panel-3);
  border-color: var(--line-strong);
  color: var(--text);
}

.model-config-list {
  display: grid;
  gap: 12px;
  margin-top: 12px;
  max-height: 370px;
  overflow: auto;
  padding-right: 6px;
}

.model-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  padding: 14px;
  display: grid;
  gap: 10px;
}

.model-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.model-card strong {
  font-size: 18px;
}

.model-card header button {
  height: 30px;
  padding: 0 10px;
}

.model-grid {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 10px;
  align-items: center;
}

.model-card label {
  margin: 0;
}

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

  .sidebar {
    display: none;
  }

  .actions {
    overflow-x: auto;
  }
}

@media (max-height: 760px) {
  .chat-panel {
    top: 36px;
    gap: 6px;
    padding: 10px;
  }

  .chat-panel header button {
    width: 30px;
    height: 30px;
  }

  .chat-model-row input,
  .chat-model-row select,
  .chat-draft-tools select,
  .chat-draft-tools button,
  .chat-presets button {
    height: 32px;
  }

  .chat-presets {
    gap: 6px;
  }

  .chat-preview {
    min-height: 52px;
    padding: 6px 0;
  }

  .chat-preview img {
    width: 46px;
    height: 46px;
  }

  .chat-draft-box textarea {
    min-height: 92px;
    height: 92px;
    max-height: 110px;
  }

  .chat-log {
    display: grid;
    min-height: 38px;
    max-height: 72px;
  }

  .chat-input-row input[type="text"] {
    height: 40px;
  }

  .chat-input-row .chat-attach-btn,
  .chat-input-row .chat-send-btn,
  .chat-apply-btn {
    height: 40px;
  }
}
