:root {
  --bg: #f5f5f7;
  --panel: #ffffff;
  --border: #e5e5ea;
  --text: #1c1c1e;
  --text-dim: #8a8a8e;
  --accent: #2f6fed;
  --accent-text: #ffffff;
  --error-bg: #fdecea;
  --error-text: #b3261e;
  --sidebar-w: 260px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
textarea { font-family: inherit; }

/* ---------- 激活码界面 ---------- */
.gate {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #eef2ff, #f5f5f7);
  padding: 20px;
}
.gate-card {
  background: var(--panel);
  border-radius: 20px;
  padding: 36px 28px;
  width: 100%; max-width: 360px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.08);
  text-align: center;
}
.gate-card h1 { margin: 0 0 6px; font-size: 24px; }
.gate-sub { color: var(--text-dim); margin: 0 0 24px; font-size: 14px; }
.gate-card input {
  width: 100%; padding: 14px 16px; font-size: 16px;
  border: 1px solid var(--border); border-radius: 12px;
  margin-bottom: 14px; text-align: center; letter-spacing: 1px;
}
.gate-card input:focus { outline: none; border-color: var(--accent); }
.gate-card button {
  width: 100%; padding: 14px; font-size: 16px; font-weight: 600;
  background: var(--accent); color: var(--accent-text);
  border: none; border-radius: 12px;
}
.gate-card button:disabled { opacity: 0.6; }
.gate-error { color: var(--error-text); font-size: 13px; margin: 12px 0 0; }

/* ---------- 主界面布局 ---------- */
.app {
  display: flex;
  height: 100dvh;
  overflow: hidden;
}
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 20;
}
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 14px;
  overflow-y: auto;
}
.new-conv-btn {
  padding: 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg); font-size: 14px; font-weight: 600;
  margin-bottom: 12px;
}
.conv-list { display: flex; flex-direction: column; gap: 4px; flex: 1; overflow-y: auto; }
.conv-item {
  padding: 10px 12px; border-radius: 10px; font-size: 14px;
  color: var(--text); cursor: pointer; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.conv-item:hover { background: var(--bg); }
.conv-item.active { background: #eaf0ff; color: var(--accent); font-weight: 600; }

.main {
  flex: 1; display: flex; flex-direction: column;
  min-width: 0;
  height: 100dvh;
}
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex-shrink: 0;
}
.icon-btn {
  background: none; border: none; font-size: 20px;
  padding: 4px 8px; border-radius: 8px;
}
.icon-btn:hover { background: var(--bg); }
.conv-title { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.messages {
  flex: 1; overflow-y: auto;
  padding: 16px;
  display: flex; flex-direction: column; gap: 14px;
}
.msg { display: flex; flex-direction: column; max-width: 78%; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.assistant { align-self: flex-start; align-items: flex-start; }
.bubble {
  padding: 11px 14px; border-radius: 16px; font-size: 15px; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word;
}
.msg.user .bubble { background: var(--accent); color: var(--accent-text); border-bottom-right-radius: 4px; }
.msg.assistant .bubble { background: var(--panel); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg.error .bubble { background: var(--error-bg); color: var(--error-text); border: 1px solid #f5c6c2; }

.img-wrap { max-width: 100%; }
.img-wrap img {
  max-width: 100%; width: 320px; border-radius: 14px; display: block;
  border: 1px solid var(--border);
}
.img-hint { font-size: 12px; color: var(--text-dim); margin-top: 6px; }
.img-actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.img-actions button, .img-actions a {
  font-size: 12px; padding: 6px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  text-decoration: none;
}
.retry-btn {
  margin-top: 8px; font-size: 12px; padding: 6px 12px; border-radius: 8px;
  border: 1px solid var(--error-text); background: none; color: var(--error-text);
}

.thinking { display: flex; align-items: center; gap: 8px; color: var(--text-dim); font-size: 14px; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-dim); animation: blink 1.4s infinite ease-in-out; }
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.2; } 40% { opacity: 1; } }

.send-form {
  display: flex; gap: 10px; align-items: flex-end;
  padding: 10px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--panel);
  flex-shrink: 0;
}
.send-form textarea {
  flex: 1; resize: none; max-height: 120px;
  padding: 11px 14px; font-size: 15px;
  border: 1px solid var(--border); border-radius: 14px;
  background: var(--bg);
}
.send-form textarea:focus { outline: none; border-color: var(--accent); }
.send-form button {
  padding: 0 18px; height: 42px; border-radius: 14px; border: none;
  background: var(--accent); color: var(--accent-text); font-weight: 600; font-size: 14px;
  flex-shrink: 0;
}
.send-form button:disabled { opacity: 0.5; }

/* ---------- 移动端：侧栏变抽屉 ---------- */
@media (max-width: 768px) {
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0;
    z-index: 30;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 4px 0 20px rgba(0,0,0,0.15);
  }
  .sidebar.open { transform: translateX(0); }
  .msg { max-width: 88%; }
  .img-wrap img { width: 100%; max-width: 280px; }
  .desktop-only-download { display: none; }
}

@media (min-width: 769px) {
  #menu-btn { display: none; }
  .overlay { display: none !important; }
}
