/* ===== ChatGPT 风格明亮主题 ===== */
:root {
  --bg: #ffffff;
  --bg-sidebar: #f9f9f9;
  --bg-composer: #f4f4f4;
  --bg-hover: #ececec;
  --bg-active: #e3e3e3;
  --bg-bubble: #f1f1f1;
  --text: #0d0d0d;
  --text-2: #5d5d5d;
  --text-3: #8f8f8f;
  --border: rgba(0, 0, 0, 0.1);
  --danger: #d93025;
  --radius: 26px;
  --font: ui-sans-serif, -apple-system, "Segoe UI", "Helvetica Neue", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.6;
  overflow: hidden;
}
button { font-family: inherit; color: inherit; background: none; border: none; cursor: pointer; }
select { font-family: inherit; cursor: pointer; }
.hidden { display: none !important; }

.app { display: flex; height: 100vh; height: 100dvh; }

/* ===== 侧边栏 ===== */
.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  padding: 10px;
}
.sidebar-head { display: flex; align-items: center; gap: 9px; padding: 8px 8px 12px; }
.brand-icon { display: inline-flex; }
.brand-icon svg { display: block; }
.brand-name { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  text-align: left;
  transition: background 0.15s;
}
.nav-item:hover { background: var(--bg-active); }

.chat-list { flex: 1; overflow-y: auto; margin-top: 14px; scrollbar-width: thin; scrollbar-color: #c5c5c5 transparent; }
.section-label { font-size: 12px; color: var(--text-3); padding: 0 10px 8px; font-weight: 600; }
.chat-item {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 14px;
  color: var(--text-2);
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.15s;
  position: relative;
}
.chat-item:hover { background: var(--bg-active); }
.chat-item.active { background: var(--bg-active); color: var(--text); }
.chat-item span { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.chat-item .del-btn {
  display: none;
  color: var(--text-3);
  padding: 2px;
  border-radius: 6px;
  flex-shrink: 0;
}
.chat-item:hover .del-btn { display: inline-flex; }
.chat-item .del-btn:hover { color: var(--danger); }

.backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 40;
}

/* ===== 主区域 ===== */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }

.topbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-spacer { flex: 1; }
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border-radius: 10px;
  color: var(--text-2);
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--bg-active); color: var(--text); }
.menu-btn { display: none; }

/* ===== 弹层 ===== */
.pop-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  text-align: left;
  font-size: 14px;
  transition: background 0.15s;
}
.pop-item:hover { background: var(--bg-hover); }
.pop-item.danger:hover { color: var(--danger); }

/* ===== 聊天区 ===== */
.chat-scroll {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  scrollbar-width: thin;
  scrollbar-color: #c5c5c5 transparent;
}
.messages {
  margin: auto;
  width: 100%;
  max-width: 768px;
  padding: 24px 20px 40px;
}
.hero { text-align: center; padding: 26vh 0 48px; }
.hero-logo { color: var(--text); display: inline-flex; margin-bottom: 18px; }
.hero h1 { font-size: 30px; font-weight: 600; letter-spacing: -0.01em; }

.msg { margin-bottom: 28px; }
.msg-user { display: flex; flex-direction: column; align-items: flex-end; }
.msg-user .bubble {
  background: var(--bg-bubble);
  border-radius: 22px;
  padding: 10px 20px;
  max-width: 78%;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 16px;
}
.ref-thumbs { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-bottom: 8px; max-width: 78%; }
.ref-thumbs img {
  width: 72px; height: 72px;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.msg-assistant { display: flex; gap: 14px; align-items: flex-start; }
.ai-avatar {
  width: 28px; height: 28px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
  overflow: hidden;
}
.ai-avatar svg { display: block; }
.msg-body { min-width: 0; flex: 1; }
.msg-text { white-space: pre-wrap; word-break: break-word; }
.msg-error { color: var(--danger); }
.msg-meta { font-size: 12px; color: var(--text-3); margin-top: 6px; }

/* 生成中的占位骨架 */
.skeleton {
  border-radius: 16px;
  background: linear-gradient(100deg, #eeeeee 40%, #dedede 50%, #eeeeee 60%);
  background-size: 200% 100%;
  animation: shimmer 1.6s infinite linear;
  border: 1px solid var(--border);
  max-width: 420px;
}
@keyframes shimmer { to { background-position: -200% 0; } }
.thinking { display: inline-flex; align-items: center; gap: 8px; color: var(--text-2); font-size: 14px; padding: 6px 0; }
.thinking .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-2); animation: pulse 1.2s infinite ease-in-out; }
.thinking .dot:nth-child(2) { animation-delay: 0.2s; }
.thinking .dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes pulse { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

/* 生成结果图片 */
.result-img-wrap {
  position: relative;
  display: inline-block;
  max-width: min(100%, 420px);
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg-composer);
}
.result-img-wrap img { display: block; width: 100%; height: auto; cursor: zoom-in; }
.img-actions {
  display: flex;
  gap: 4px;
  margin-top: 8px;
}
.act-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px;
  border-radius: 8px;
  color: var(--text-3);
  font-size: 12px;
  transition: background 0.15s, color 0.15s;
}
.act-btn:hover { background: var(--bg-active); color: var(--text); }

/* ===== 输入区 ===== */
.composer-wrap {
  padding: 0 20px 14px;
  max-width: 804px;
  width: 100%;
  margin: 0 auto;
}

/* 模板标签 */
.prompt-tags {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 6px 10px;
  scrollbar-width: none;
}
.prompt-tags::-webkit-scrollbar { display: none; }
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  color: var(--text-2);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.tag-chip:hover { background: var(--bg-hover); color: var(--text); border-color: rgba(0, 0, 0, 0.18); }

.composer {
  position: relative;
  background: var(--bg-composer);
  border-radius: var(--radius);
  padding: 10px 10px 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}
.composer-row { display: flex; align-items: flex-end; gap: 8px; }
.plus-btn { margin-bottom: 4px; }
#promptInput {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
  line-height: 1.55;
  padding: 10px 0 4px;
  min-height: 96px;
  max-height: 240px;
}
#promptInput::placeholder { color: var(--text-3); }
.send-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--text);
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s, transform 0.15s;
  margin-bottom: 2px;
}
.send-btn:hover { transform: scale(1.05); }
.send-btn:disabled { background: var(--text); opacity: 0.2; cursor: default; transform: none; }

.composer-tools { display: flex; gap: 8px; padding: 6px 4px 2px; flex-wrap: wrap; }
.tool-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  color: var(--text-2);
  font-size: 13px;
  transition: background 0.15s, color 0.15s;
}
.tool-pill:hover { background: var(--bg-hover); color: var(--text); }
.tool-pill select {
  background: transparent;
  border: none;
  outline: none;
  color: inherit;
  font-size: 13px;
  appearance: none;
  padding-right: 2px;
}
.tool-pill select option { background: #ffffff; color: var(--text); }

.plus-menu {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 10px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.12);
  padding: 6px;
  min-width: 210px;
  z-index: 60;
}

.ref-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 6px 10px;
}
.ref-chip { position: relative; }
.ref-chip img {
  width: 56px; height: 56px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border);
  display: block;
}
.ref-chip .rm {
  position: absolute;
  top: -6px; right: -6px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--text-3);
  color: #ffffff;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
}
.ref-chip .rm:hover { background: var(--danger); }

.disclaimer {
  text-align: center;
  font-size: 12px;
  color: var(--text-3);
  padding: 10px 0 4px;
}

/* ===== 登录门 ===== */
.login-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  width: 320px;
  max-width: 90vw;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
}
.login-logo { display: inline-flex; justify-content: center; }
.login-title { font-size: 24px; font-weight: 700; letter-spacing: -0.01em; }
.login-sub { font-size: 14px; color: var(--text-3); margin-top: -6px; }
.login-card input {
  background: var(--bg-composer);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  padding: 12px 14px;
  font-size: 15px;
  outline: none;
  text-align: center;
  font-family: inherit;
}
.login-card input:focus { border-color: #999; }
.login-error { font-size: 13px; color: var(--danger); margin: 0; }
.login-btn {
  background: var(--text);
  color: #ffffff;
  border-radius: 12px;
  padding: 12px;
  font-weight: 600;
  font-size: 15px;
  transition: opacity 0.15s;
}
.login-btn:hover { opacity: 0.85; }
.login-btn:disabled { opacity: 0.5; cursor: default; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 110px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #ffffff;
  padding: 10px 18px;
  border-radius: 12px;
  font-size: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
  z-index: 100;
  max-width: 90vw;
}

/* ===== 移动端 ===== */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    width: 280px;
  }
  .sidebar.open { transform: translateX(0); }
  .menu-btn { display: inline-flex; }
  .hero { padding-top: 18vh; }
  .hero h1 { font-size: 24px; }
  .messages { padding: 16px 14px 24px; }
  .composer-wrap { padding: 0 12px 10px; }
}
