:root[data-theme="light"] {
  --bg: #f4f6f9;
  --sidebar: #eceef2;
  --panel: #ffffff;
  --text: #0f1115;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #3b5bdb;
  --accent-hover: #2d4bc4;
  --bubble-user: #e8edff;
  --bubble-ai: #ffffff;
  --shadow: 0 1px 3px rgba(15, 17, 21, 0.06);
}

:root[data-theme="dark"] {
  --bg: #0d0d0f;
  --sidebar: #161618;
  --panel: #1a1a1e;
  --text: #ececf1;
  --muted: #9ca3af;
  --border: #2a2a30;
  --accent: #5b7cfa;
  --accent-hover: #7c94fc;
  --bubble-user: #252532;
  --bubble-ai: #1e1e24;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  height: 100%;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app {
  display: flex;
  height: 100%;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
}

.brand {
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
  padding: 0 8px;
}

.brand small {
  display: block;
  font-weight: 400;
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 4px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 16px;
}

.nav button {
  text-align: left;
  padding: 12px 14px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.15s;
}

.nav button:hover {
  background: rgba(91, 124, 250, 0.12);
}

.nav button.active {
  background: rgba(91, 124, 250, 0.2);
  font-weight: 600;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--muted);
  padding-left: 8px;
}

.theme-btn {
  margin-top: 10px;
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: 960px;
  margin: 0 auto;
  width: 100%;
  padding: 20px 24px 28px;
}

.chat-main {
  min-height: 0;
}

.sidebar-hint,
.sidebar-note {
  font-size: 0.78rem;
  color: var(--muted);
  padding: 0 8px;
  line-height: 1.5;
  margin: 12px 0 0;
}

.sidebar-hint code {
  font-size: 0.85em;
  background: var(--panel);
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.sidebar-note {
  margin-top: 10px;
  opacity: 0.92;
}

.scene-label {
  font-size: 0.75rem;
  color: var(--muted);
  padding: 0 8px;
  margin-top: 14px;
  display: block;
}

.scene-select {
  width: calc(100% - 16px);
  margin: 6px 8px 0;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 0.85rem;
}

.composer-bar {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

/* 输入区：缩略图在灰色输入框「上方」独立一条 */
.composer-main-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.attach-thumbs {
  display: none;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-start;
  align-content: flex-start;
  max-height: 104px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 2px 0;
  flex: 0 0 auto;
  width: 100%;
}

.attach-thumbs.has-files {
  display: flex;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px dashed var(--border);
  background: rgba(91, 124, 250, 0.06);
}

:root[data-theme="dark"] .attach-thumbs.has-files {
  background: rgba(91, 124, 250, 0.12);
}

.attach-thumb-wrap {
  position: relative;
  width: 64px;
  height: 64px;
  flex-shrink: 0;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.attach-thumb-wrap img.attach-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.attach-thumb-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  padding: 0;
  line-height: 20px;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  color: #fff;
  background: rgba(0, 0, 0, 0.6);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.attach-thumb-remove:hover {
  background: rgba(200, 50, 50, 0.95);
}

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

.btn-attach {
  flex-shrink: 0;
  align-self: flex-start;
  margin-top: 2px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
  line-height: 1;
}

.btn-attach:hover {
  background: rgba(91, 124, 250, 0.1);
}

.attach-label {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 6px;
  padding-left: 4px;
}

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

.ai-text-block {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.65;
  font-size: 0.95rem;
}

.ai-text-block .ai-copy-inline-img {
  display: block;
  max-width: min(100%, 480px);
  height: auto;
  margin: 10px 0;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.ai-copy-ref-cap {
  margin-top: 14px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
}

.ai-copy-ref-gallery {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

.ai-copy-ref-img {
  width: 120px;
  height: 120px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.btn-mini {
  padding: 6px 12px;
  font-size: 0.8rem;
  border-radius: 8px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  line-height: 1.3;
}

.btn-mini-ico {
  display: inline-flex;
  flex-shrink: 0;
  line-height: 0;
  opacity: 0.92;
}

.btn-mini-ico svg {
  display: block;
}

.result-img-inline,
.result-video-inline {
  max-width: min(100%, 520px);
  border-radius: 10px;
  margin-top: 8px;
  border: 1px solid var(--border);
}

.panel {
  display: none;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

.panel.active {
  display: flex;
}

.panel h1 {
  font-size: 1.35rem;
  font-weight: 600;
  margin: 0 0 6px;
}

.panel .hint {
  color: var(--muted);
  font-size: 0.88rem;
  margin-bottom: 20px;
}

.chat-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 0 4px 0 0;
  margin-bottom: 16px;
}

#chat-messages {
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: stretch;
}

/* 共用排版；AI 像 DeepSeek 一样铺在背景上，不用独立灰底块圈住整段 */
.msg {
  line-height: 1.6;
  font-size: 0.95rem;
  white-space: pre-wrap;
  word-break: break-word;
  box-sizing: border-box;
}

.msg.user {
  align-self: flex-end;
  margin-left: auto;
  margin-right: 0;
  max-width: min(92%, 720px);
  width: -moz-fit-content;
  width: fit-content;
  padding: 12px 16px;
  border-radius: 14px;
  background: var(--bubble-user);
  border: 1px solid var(--border);
}

.msg.user .user-attach-preview-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
  max-width: 100%;
}

.msg.user .user-attach-preview {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  display: block;
}

.msg.ai {
  align-self: stretch;
  width: 100%;
  max-width: 100%;
  margin: 0;
  padding: 6px 0 18px;
  border-radius: 0;
  background: transparent;
  border: none;
  box-shadow: none;
  color: var(--text);
}

.msg.ai[data-ai-loading='1'] {
  padding: 4px 0 12px;
  color: var(--muted);
  font-size: 0.9rem;
}

.ai-loading-row {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

.ai-loading-text {
  line-height: 1.5;
}

.ai-spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: ai-spin 0.75s linear infinite;
}

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

.composer-panel {
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.composer-row {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: flex-end;
  gap: 10px;
  width: 100%;
}

.composer-panel .composer-row textarea,
.field textarea {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 52px;
  max-height: 180px;
  resize: vertical;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1.45;
  font-family: inherit;
  outline: none;
}

.btn {
  padding: 10px 20px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  white-space: nowrap;
}

/* 发送：固定小块，不被 flex 拉成整行高度 */
.btn-send {
  flex: 0 0 auto;
  align-self: flex-end;
  padding: 8px 16px;
  font-size: 0.85rem;
  border-radius: 10px;
  line-height: 1.25;
}

.btn:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--border);
  cursor: pointer;
}

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.field input[type="text"],
.field input[type="file"],
.field select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 0.9rem;
}

.result-img {
  margin-top: 20px;
  max-width: 100%;
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.result-video {
  margin-top: 20px;
  max-width: 100%;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.err {
  color: #dc2626;
  font-size: 0.88rem;
  margin-top: 8px;
}

.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}

@media (max-width: 720px) {
  .app {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 12px;
  }
  .nav {
    flex-direction: row;
    flex-wrap: wrap;
    margin-top: 0;
    flex: 1;
  }
  .sidebar-footer {
    border: none;
    margin: 0;
    padding: 0;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
}
