/* ============================================================
   AI 创作台 — 极简暗色主题
   ============================================================ */

:root {
  --bg: #20242b;
  --bg-panel: #282d35;
  --bg-elevated: #31363f;
  --bg-hover: #3a404b;
  --border: #414854;
  --border-soft: #363c46;
  --text: #dee3e9;
  --text-dim: #abb3bf;
  --text-faint: #848d99;
  --accent: #6b93ff;
  --accent-soft: rgba(107, 147, 255, 0.17);
  --danger: #ff7070;
  --scrollbar: #454d5a;
  --radius: 12px;
  --sidebar-w: 264px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
}

/* 浅色主题：通过 html[data-theme="light"] 启用 */
html[data-theme="light"] {
  --bg: #f3f4f7;
  --bg-panel: #ffffff;
  --bg-elevated: #eef0f4;
  --bg-hover: #e6e9ee;
  --border: #dde1e7;
  --border-soft: #e8ebef;
  --text: #2b3138;
  --text-dim: #5d6570;
  --text-faint: #98a1ac;
  --accent: #3b6cf5;
  --accent-soft: rgba(59, 108, 245, 0.09);
  --danger: #e05252;
  --scrollbar: #c8cdd6;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}

select, textarea, input {
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
}

select:focus, textarea:focus, input:focus { border-color: var(--accent); }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  color: var(--text-dim);
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }

/* ============ 布局 ============ */

.app {
  display: flex;
  height: 100dvh;
  overflow: hidden;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ============ 侧边栏 ============ */

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border-right: 1px solid var(--border-soft);
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 14px 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.brand-mark {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  background:
    radial-gradient(circle at 30% 30%, #8fb0ff, transparent 60%),
    var(--accent);
  box-shadow: 0 0 10px rgba(79, 124, 255, 0.45);
}

.sidebar-close { display: none; }

.new-chat-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 12px 12px;
  padding: 9px 14px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 500;
  transition: background 0.15s;
}
.new-chat-btn:hover { background: rgba(79, 124, 255, 0.22); }

.session-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 8px;
}

.session-group-label {
  padding: 10px 8px 6px;
  font-size: 11px;
  color: var(--text-faint);
}

.session-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 8px 8px 12px;
  margin: 1px 0;
  border-radius: 9px;
  cursor: pointer;
  color: var(--text-dim);
  transition: background 0.15s, color 0.15s;
}
.session-item:hover { background: var(--bg-hover); color: var(--text); }
.session-item.active { background: var(--bg-elevated); color: var(--text); }

.session-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.session-time {
  flex-shrink: 0;
  font-size: 10.5px;
  color: var(--text-faint);
}

.session-actions {
  display: none;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}
.session-item:hover .session-actions { display: inline-flex; }

.session-actions .icon-btn { width: 24px; height: 24px; }
.session-actions .icon-btn svg { width: 14px; height: 14px; }
.session-actions .icon-btn.danger:hover { color: var(--danger); }

.session-empty {
  padding: 24px 16px;
  text-align: center;
  color: var(--text-faint);
  font-size: 12.5px;
  line-height: 1.7;
}

.sidebar-foot {
  padding: 12px 14px 14px;
  border-top: 1px solid var(--border-soft);
}

.foot-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-tools {
  flex-shrink: 0;
  padding: 10px 8px;
  border-top: 1px solid var(--border-soft);
}

.tools-label {
  padding: 0 8px 6px;
  font-size: 11px;
  color: var(--text-faint);
}

.tool-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 9px;
  color: var(--text-dim);
  font-size: 13px;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
.tool-link:hover { background: var(--bg-hover); color: var(--text); }
.tool-link svg { flex-shrink: 0; }
.tool-link .ext { margin-left: auto; opacity: 0.5; }
.tool-link:hover .ext { opacity: 0.9; }

.sidebar-hint {
  margin: 0 0 10px;
  font-size: 11.5px;
  color: var(--text-faint);
  line-height: 1.5;
}

.settings-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border-radius: 9px;
  color: var(--text-dim);
  font-size: 13px;
  transition: background 0.15s, color 0.15s;
}
.settings-btn:hover { background: var(--bg-hover); color: var(--text); }

.scrim {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 40;
}

/* ============ 顶栏 ============ */

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 52px;
  padding: 0 16px;
  flex-shrink: 0;
}

.menu-btn { display: none; }

.topbar-title {
  font-size: 13.5px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ============ 消息区 ============ */

.chat-scroll {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
}

.empty-state {
  max-width: 720px;
  margin: 0 auto;
  padding: 12vh 24px 40px;
  text-align: center;
  animation: fadeUp 0.4s ease both;
}

.empty-state h1 {
  margin: 0 0 8px;
  font-size: 26px;
  font-weight: 600;
}

.empty-sub {
  margin: 0 0 32px;
  color: var(--text-dim);
  font-size: 14px;
}

.examples {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.example-chip {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-panel);
  color: var(--text-dim);
  font-size: 13px;
  text-align: left;
  line-height: 1.55;
  transition: border-color 0.15s, color 0.15s, transform 0.15s;
}
.example-chip:hover {
  border-color: var(--accent);
  color: var(--text);
  transform: translateY(-1px);
}

.messages {
  max-width: 760px;
  margin: 0 auto;
  padding: 8px 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.msg { animation: fadeUp 0.3s ease both; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* 用户消息 */
.msg.user { display: flex; flex-direction: column; align-items: flex-end; }

.msg.user .bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px 14px 4px 14px;
  background: var(--accent-soft);
  border: 1px solid rgba(79, 124, 255, 0.25);
  color: var(--text);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.user .params {
  margin-top: 6px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.chip {
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  color: var(--text-faint);
  font-size: 11px;
}

/* 助手结果卡片 */
.result-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-panel);
  overflow: hidden;
}

.result-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-soft);
  color: var(--text-dim);
  font-size: 12.5px;
}

.result-head .spinner {
  width: 13px;
  height: 13px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.result-body { padding: 14px; }

.img-grid {
  display: grid;
  gap: 10px;
}
.img-grid.cols-1 { grid-template-columns: minmax(0, 460px); }
.img-grid.cols-2 { grid-template-columns: 1fr 1fr; }

.img-cell {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-elevated);
  line-height: 0;
}
.img-grid.cols-1 .img-cell { justify-self: start; width: 100%; max-width: 460px; }

.img-cell img {
  width: 100%;
  height: auto;
  display: block;
  cursor: zoom-in;
}

.img-cell .dl-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: rgba(10, 12, 15, 0.72);
  color: #fff;
  opacity: 0;
  transition: opacity 0.15s;
  backdrop-filter: blur(4px);
}
.img-cell:hover .dl-btn { opacity: 1; }

/* 骨架屏 */
.skeleton-grid {
  display: grid;
  gap: 10px;
}
.skeleton-grid.cols-1 { grid-template-columns: minmax(0, 460px); }
.skeleton-grid.cols-2 { grid-template-columns: 1fr 1fr; }

.skeleton {
  aspect-ratio: 3 / 2;
  border-radius: 10px;
  background: linear-gradient(100deg,
    var(--bg-elevated) 40%, var(--bg-hover) 50%, var(--bg-elevated) 60%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease infinite;
}
.skeleton-grid.cols-1 .skeleton { width: 100%; max-width: 460px; }

@keyframes shimmer {
  to { background-position: -200% 0; }
}

/* 错误态 */
.error-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border: 1px solid rgba(255, 107, 107, 0.35);
  border-radius: 10px;
  background: rgba(255, 107, 107, 0.07);
}
.error-box .error-text {
  color: var(--danger);
  font-size: 13px;
  line-height: 1.6;
  word-break: break-all;
}

.result-actions {
  display: flex;
  gap: 8px;
  padding: 0 14px 14px;
  flex-wrap: wrap;
}

.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-dim);
  font-size: 12.5px;
  transition: border-color 0.15s, color 0.15s;
}
.action-btn:hover { border-color: var(--accent); color: var(--text); }
.action-btn svg { width: 13px; height: 13px; }

/* ============ 输入区 ============ */

.composer-wrap {
  flex-shrink: 0;
  padding: 8px 20px calc(14px + env(safe-area-inset-bottom));
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
}

.composer {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--bg-panel);
  transition: border-color 0.15s;
}
.composer:focus-within { border-color: #3a4656; }

.composer textarea {
  display: block;
  width: 100%;
  padding: 14px 16px 6px;
  background: transparent;
  border: none;
  resize: none;
  font-size: 14px;
  line-height: 1.6;
  max-height: 180px;
}
.composer textarea:focus { border: none; }
.composer textarea::placeholder { color: var(--text-faint); }

/* 参考图缩略条 */
.ref-strip {
  display: flex;
  gap: 8px;
  padding: 2px 12px 0;
  flex-wrap: wrap;
}
.ref-strip[hidden] { display: none; }

.ref-thumb {
  position: relative;
  width: 54px;
  height: 54px;
  border-radius: 9px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
}
.ref-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.ref-thumb .rm {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: rgba(10, 12, 15, 0.78);
  color: #fff;
  font-size: 11px;
  line-height: 17px;
  text-align: center;
  cursor: pointer;
}
.ref-thumb .rm:hover { background: rgba(220, 60, 60, 0.9); }

.ref-add {
  width: 54px;
  height: 54px;
  border: 1px dashed var(--border);
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  cursor: pointer;
  background: transparent;
  font-size: 20px;
  line-height: 1;
}
.ref-add:hover { border-color: var(--accent); color: var(--accent); }

.ref-btn { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }

/* 用户消息携带的参考图 */
.msg-refs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.msg-ref {
  width: 52px;
  height: 52px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.composer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 10px 10px 12px;
  flex-wrap: wrap;
}

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

.mode-tabs {
  display: flex;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 2px;
}

.mode-tab {
  padding: 5px 12px;
  border-radius: 7px;
  font-size: 12.5px;
  color: var(--text-dim);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s, color 0.15s;
}
.mode-tab.active {
  background: var(--accent);
  color: #fff;
}
.mode-tab.is-disabled { color: var(--text-faint); cursor: not-allowed; }

.soon-tag {
  font-size: 9.5px;
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--bg-hover);
  color: var(--text-faint);
}

.ctl {
  height: 30px;
  padding: 0 8px;
  font-size: 12.5px;
  cursor: pointer;
}

.send-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 11px;
  background: var(--accent);
  color: #fff;
  flex-shrink: 0;
  transition: opacity 0.15s, transform 0.15s;
}
.send-btn:hover { transform: translateY(-1px); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.composer-note {
  margin: 8px 4px 0;
  text-align: center;
  font-size: 11px;
  color: var(--text-faint);
}

/* ============ 弹窗 ============ */

.modal-scrim {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-scrim[hidden] { display: none; }

.modal {
  width: 100%;
  max-width: 420px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
  animation: fadeUp 0.2s ease both;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 14px;
}

.field { display: block; margin-bottom: 12px; }
.field span {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--text-dim);
}
.field input {
  width: 100%;
  padding: 9px 12px;
  font-size: 13px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

.ghost-btn, .primary-btn {
  padding: 8px 16px;
  border-radius: 9px;
  font-size: 13px;
  transition: opacity 0.15s;
}
.ghost-btn {
  border: 1px solid var(--border);
  color: var(--text-dim);
  margin-right: auto;
}
.ghost-btn:hover { color: var(--text); border-color: var(--text-faint); }
.primary-btn { background: var(--accent); color: #fff; font-weight: 500; }
.ghost-btn:hover, .primary-btn:hover { opacity: 0.9; }

.modal-note {
  margin: 12px 0 0;
  font-size: 11.5px;
  color: var(--text-faint);
  line-height: 1.6;
}

/* ============ 帮助页 ============ */

.help-view {
  flex: 1;
  overflow-y: auto;
}
.help-view[hidden] { display: none; }

.help-inner {
  max-width: 660px;
  margin: 0 auto;
  padding: 12px 20px 48px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: fadeUp 0.3s ease both;
}

.help-back { align-self: flex-start; }

.help-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-panel);
  padding: 16px 18px;
}

.help-card h2 {
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 600;
}

.help-card p, .help-card li {
  margin: 0;
  color: var(--text-dim);
  font-size: 13.5px;
  line-height: 1.8;
}

.help-card ul, .help-card ol {
  margin: 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.help-card strong { color: var(--text); font-weight: 600; }

.help-card code {
  padding: 1px 6px;
  border-radius: 5px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

/* ============ Toast ============ */

.toast {
  position: fixed;
  left: 50%;
  bottom: 110px;
  transform: translateX(-50%);
  z-index: 60;
  padding: 9px 18px;
  border-radius: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  animation: fadeUp 0.2s ease both;
  max-width: 80vw;
  text-align: center;
}

/* ============ 移动端 ============ */

@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 41;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
  }
  .sidebar.open { transform: none; }
  .sidebar-close { display: inline-flex; }
  .scrim.show { display: block; }
  .menu-btn { display: inline-flex; }

  .examples { grid-template-columns: 1fr; }
  .empty-state { padding-top: 7vh; }
  .messages, .composer-wrap { padding-left: 14px; padding-right: 14px; }
  .img-grid.cols-2 { grid-template-columns: 1fr; }
  .controls { width: 100%; }
  .composer-bar { align-items: flex-end; }
  .msg.user .bubble { max-width: 92%; }
}
