/* ChatGPT 图像工坊 —— 深色主题 */

* { box-sizing: border-box; }
:root {
  --bg: #0e1116;
  --bg2: #141922;
  --panel: #181f2b;
  --border: #26303f;
  --text: #e7ebf3;
  --muted: #8b94a7;
  --accent: #5b8cff;
  --accent-2: #7c5bff;
  --danger: #ff6b6b;
  --ok: #43d787;
  --radius: 12px;
}
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
}
::selection { background: rgba(91, 140, 255, 0.35); }

/* ---------- 布局 ---------- */
#app { display: flex; height: 100vh; overflow: hidden; }

#sidebar {
  width: 268px; flex: none;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.sb-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 14px 10px; gap: 8px;
}
.logo { display: inline-flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 700; letter-spacing: 0.5px; white-space: nowrap; }
.sb-list { flex: 1; overflow-y: auto; padding: 4px 8px 8px; }
.sb-footer { padding: 10px 14px; border-top: 1px solid var(--border); }

.chat-item {
  display: flex; align-items: center; gap: 6px;
  padding: 9px 10px; margin-bottom: 3px;
  border-radius: 8px; cursor: pointer;
  color: var(--muted); transition: background 0.12s;
}
.chat-item:hover { background: var(--panel); color: var(--text); }
.chat-item.active { background: var(--panel); color: var(--text); border-left: 3px solid var(--accent); }
.ci-title {
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 13px;
}
.ci-del {
  flex: none; border: 0; background: transparent; color: var(--muted);
  cursor: pointer; font-size: 12px; padding: 2px 6px; border-radius: 5px;
  opacity: 0; transition: opacity 0.12s;
}
.chat-item:hover .ci-del { opacity: 1; }
.ci-del:hover { background: rgba(255, 107, 107, 0.15); color: var(--danger); }

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

#topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; border-bottom: 1px solid var(--border);
  background: var(--bg2);
}
.top-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 聊天区 ---------- */
#chatArea {
  flex: 1; overflow-y: auto; padding: 20px 16px 12px;
  display: flex; flex-direction: column; gap: 18px;
}
.hero {
  margin: auto; text-align: center; color: var(--muted);
  padding: 40px 20px;
}
.hero h2 { color: var(--text); font-weight: 600; margin: 0 0 10px; }
.hero .hero-icon { width: 52px; height: 52px; margin: 0 auto 12px; color: var(--accent); }
.hero .hero-icon .icon { width: 52px; height: 52px; }
.hero ul { text-align: left; display: inline-block; margin: 8px auto 0; padding-left: 20px; }

.msg { display: flex; flex-direction: column; }
.msg.user { align-items: flex-end; }
.msg.user .bubble {
  background: linear-gradient(135deg, rgba(91,140,255,0.16), rgba(124,91,255,0.14));
  border: 1px solid rgba(91, 140, 255, 0.3);
}
.bubble {
  max-width: 92%;
  padding: 10px 14px; border-radius: var(--radius);
  background: var(--panel); border: 1px solid var(--border);
}
.msg-text { white-space: pre-wrap; word-break: break-word; }
.bubble.error {
  border-color: rgba(255,107,107,0.5); background: rgba(255,107,107,0.08); color: #ffb3b3;
  display: flex; gap: 8px; align-items: flex-start;
}
.bubble.error .icon { margin-top: 2px; flex: none; }

/* 图片网格 */
.img-grid {
  display: grid; gap: 10px; margin-top: 10px;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
}
.img-grid.small { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
.img-card {
  border-radius: 10px; overflow: hidden;
  border: 1px solid var(--border); background: #0a0d12;
  display: flex; flex-direction: column;
}
.img-wrap { line-height: 0; }
.img-card img { width: 100%; height: auto; display: block; }
.img-card img.broken { filter: grayscale(1) opacity(0.35); }
.img-card .img-actions {
  display: flex; gap: 4px; padding: 6px;
  background: var(--panel); border-top: 1px solid var(--border);
}
.img-card .img-actions .btn.mini {
  flex: 1; min-width: 0; display: inline-flex;
  align-items: center; justify-content: center; gap: 4px;
}
/* 小图（用户参考图）操作条只显示图标 */
.img-grid.small .img-actions { padding: 4px; gap: 2px; }
.img-grid.small .img-actions .btn-label { display: none; }
.meta { margin-top: 6px; font-size: 12px; color: var(--muted); }

/* 消息工具条：重试按钮 + 结果版本切换（普通数字圆点，不用 emoji，避免乱码） */
.msg-tools { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.msg.user .msg-tools { justify-content: flex-end; }
.variant-switch { display: flex; gap: 6px; }
.vdot {
  width: 26px; height: 26px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--panel); color: var(--muted);
  cursor: pointer; font-size: 12px; line-height: 1; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  transition: filter 0.12s;
}
.vdot:hover { filter: brightness(1.25); border-color: var(--accent-2); }
.vdot.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

/* 生成中指示 */
.gen-indicator {
  display: flex; align-items: center; gap: 10px;
  color: var(--muted); padding: 4px 2px;
}
.spinner {
  width: 18px; height: 18px; flex: none;
  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); } }

/* ---------- 输入区 ---------- */
#composer {
  flex: none; padding: 10px 16px 14px;
  border-top: 1px solid var(--border); background: var(--bg2);
}
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.chips:empty { display: none; }
.chip {
  position: relative; width: 62px; height: 62px;
  border-radius: 8px; overflow: hidden;
  border: 2px solid var(--accent);
}
.chip img { width: 100%; height: 100%; object-fit: cover; display: block; }
.chip button {
  position: absolute; top: 0; right: 0;
  border: 0; background: rgba(0,0,0,0.7); color: #fff;
  cursor: pointer; font-size: 12px; line-height: 1;
  padding: 2px 5px; border-radius: 0 0 0 6px;
}
.chip button:hover { background: var(--danger); }

.tools { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; flex-wrap: wrap; }
.tools input[type="text"], .tools input:not([type]) { width: 130px; }
#ratioSelect { width: auto; }

.input-row { display: flex; gap: 8px; align-items: flex-end; }
#input {
  flex: 1; resize: none; max-height: 160px;
  padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  font: inherit; line-height: 1.5; outline: none;
}
#input:focus { border-color: var(--accent); }

/* ---------- 控件通用 ---------- */
input, select, textarea {
  color: var(--text);
}
input[type="text"], input[type="password"], input:not([type]), select {
  padding: 7px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--panel);
  font: inherit; outline: none; color: var(--text);
}
input:focus, select:focus { border-color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  padding: 8px 14px; border-radius: 9px; cursor: pointer;
  font: inherit; font-size: 13px; transition: filter 0.12s, transform 0.05s;
}
.btn:hover { filter: brightness(1.18); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary {
  background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600;
}
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.mini { padding: 3px 8px; font-size: 12px; background: rgba(255,255,255,0.05); border-color: var(--border); }

/* 内联 SVG 图标（替代 emoji，避免不同系统渲染成乱码方块） */
.icon { width: 16px; height: 16px; flex: none; }
.icon.lg { width: 20px; height: 20px; }

/* ---------- 访问密码门 ---------- */
/* 不透明底 + 最高层级，验证通过前完全遮挡页面且不可关闭 */
.gate {
  position: fixed; inset: 0; z-index: 100;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.gate.hidden { display: none; }
.gate-box {
  width: min(380px, 92vw);
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 16px; padding: 26px 26px 22px;
  text-align: center;
}
.gate-box h2 { margin: 0 0 6px; font-size: 17px; }
.gate-box .hint { display: block; margin: 0 0 16px; }
.gate-box input, .gate-box .btn { width: 100%; }
.gate-box input { margin-bottom: 10px; }
.gate-box .btn { margin-top: 4px; }
.gate-error { color: var(--danger); font-size: 12px; text-align: left; margin: 0 0 10px; }
.gate-error.hidden { display: none; }

/* ---------- 弹层 ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(4, 7, 11, 0.72); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal.hidden { display: none; }
.modal-box {
  width: min(560px, 94vw); max-height: 90vh; overflow-y: auto;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 16px; padding: 22px 24px;
}
.modal-box h2 { margin: 0 0 16px; font-size: 17px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.form-grid label.full { grid-column: 1 / -1; }
.form-grid input, .form-grid select { width: 100%; }
.hint { font-size: 12px; color: var(--muted); opacity: 0.85; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

#lightbox { cursor: zoom-out; }
.lb-content {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  max-width: 92vw; max-height: 92vh;
}
#lbImg {
  max-width: 92vw; max-height: 78vh; border-radius: 10px;
  border: 1px solid var(--border); background: #0a0d12;
  box-shadow: 0 12px 48px rgba(0,0,0,0.6);
}
.lb-actions { display: flex; gap: 10px; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
  padding: 10px 18px; border-radius: 10px; z-index: 90;
  opacity: 0; pointer-events: none; transition: opacity 0.25s;
  max-width: 80vw; box-shadow: 0 6px 24px rgba(0,0,0,0.5);
}
#toast.show { opacity: 1; }

/* ---------- 滚动条 ---------- */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2c3648; border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: #3a465c; }

/* ---------- 窄屏 ---------- */
@media (max-width: 760px) {
  #sidebar {
    position: fixed; z-index: 40; left: 0; top: 0; bottom: 0;
    transform: translateX(-100%); transition: transform 0.2s; box-shadow: none;
  }
  #sidebar.open { transform: translateX(0); box-shadow: 8px 0 32px rgba(0,0,0,0.5); }
  .bubble { max-width: 96%; }
  .tools input[type="text"], .tools input:not([type]) { width: 110px; }
}