/* =========================================================
 * AstrBot Web Chat - 极简风格（无侧边栏）
 * ======================================================= */

/* ---------- CSS 变量（默认：深色主题） ---------- */
:root {
  --bg-1: #0b1020;
  --bg-2: #121835;
  --surface: rgba(255, 255, 255, 0.04);
  --surface-hover: rgba(255, 255, 255, 0.08);
  --border: rgba(255, 255, 255, 0.08);
  --text: #e8ecf7;
  --text-dim: #9aa3c7;
  --text-muted: #6b7396;
  --primary: #7c5cff;
  --primary-2: #3dd5ff;
  --primary-soft: rgba(124, 92, 255, 0.18);
  --danger: #ff5c7a;
  --success: #3dd598;
  --user-bubble: linear-gradient(135deg, #7c5cff 0%, #3dd5ff 100%);
  --bot-bubble: rgba(255, 255, 255, 0.06);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.5);
  --radius: 14px;
}

/* 浅色主题 */
html[data-theme="light"] {
  --bg-1: #f6f7fb;
  --bg-2: #ffffff;
  --surface: rgba(0, 0, 0, 0.03);
  --surface-hover: rgba(0, 0, 0, 0.06);
  --border: rgba(0, 0, 0, 0.08);
  --text: #1c2040;
  --text-dim: #5a6085;
  --text-muted: #8a91b0;
  --primary: #6c49ff;
  --primary-2: #00a8e0;
  --primary-soft: rgba(108, 73, 255, 0.1);
  --bot-bubble: #ffffff;
  --shadow-md: 0 4px 16px rgba(20, 30, 80, 0.08);
  --shadow-lg: 0 20px 60px rgba(20, 30, 80, 0.12);
}

/* ---------- 基础 ---------- */
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  color: var(--text);
  background:
    radial-gradient(circle at 10% 10%, rgba(124, 92, 255, 0.18), transparent 40%),
    radial-gradient(circle at 90% 90%, rgba(61, 213, 255, 0.12), transparent 45%),
    linear-gradient(160deg, var(--bg-1), var(--bg-2));
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
.hidden { display: none !important; }

/* ---------- 整体布局 ---------- */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
}

/* ---------- 顶部栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
  flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.brand-icon { font-size: 22px; }
.actions { display: flex; gap: 4px; }

/* ---------- 历史会话浮窗 ---------- */
.history-panel {
  position: fixed;
  top: 64px;
  right: 24px;
  width: 320px;
  max-height: 70vh;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  z-index: 500;
  overflow: hidden;
  animation: fadeInDown 0.2s ease;
}
@keyframes fadeInDown {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.history-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  color: var(--text-dim);
}
.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
.history-item {
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 2px;
}
.history-item:hover { background: var(--surface-hover); }
.history-item.active { background: var(--primary-soft); }
.history-title {
  flex: 1;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.history-action-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 14px;
}
.history-action-btn:hover { color: var(--text); background: var(--surface-hover); }
.history-empty {
  padding: 30px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* ---------- 欢迎页 ---------- */
.welcome {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
}
.welcome-inner { max-width: 720px; text-align: center; width: 100%; }
.welcome-emoji { font-size: 56px; margin-bottom: 12px; filter: drop-shadow(0 4px 12px rgba(124, 92, 255, 0.4)); }
.welcome-title {
  font-size: 32px; font-weight: 800; margin: 0 0 12px;
  background: linear-gradient(90deg, var(--primary), var(--primary-2));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.welcome-subtitle { color: var(--text-dim); font-size: 15px; line-height: 1.7; margin: 0 0 28px; }
.welcome-input { max-width: 680px; margin: 0 auto 28px; }

.welcome-tips {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  max-width: 680px;
  margin: 0 auto;
}
.tip-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  text-align: left;
  cursor: pointer;
  transition: all 0.15s;
}
.tip-card:hover {
  background: var(--surface-hover);
  transform: translateY(-2px);
  border-color: var(--primary);
}
.tip-title { font-weight: 600; margin-bottom: 4px; color: var(--primary-2); font-size: 14px; }
.tip-text { color: var(--text-dim); font-size: 13px; line-height: 1.6; }

/* ---------- 聊天 ---------- */
.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 6%;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}
.msg { display: flex; gap: 12px; max-width: 85%; }
.msg.from-user { align-self: flex-end; flex-direction: row-reverse; }

.msg-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--surface-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.msg.from-user .msg-avatar {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
}
.msg-bubble {
  background: var(--bot-bubble);
  padding: 12px 16px;
  border-radius: 14px;
  border-top-left-radius: 4px;
  line-height: 1.7;
  word-break: break-word;
  box-shadow: var(--shadow-md);
}
.msg.from-user .msg-bubble {
  background: var(--user-bubble);
  color: #fff;
  border-top-left-radius: 14px;
  border-top-right-radius: 4px;
}
.msg-text { white-space: pre-wrap; }

/* Markdown */
.msg-bubble p { margin: 0 0 8px; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble code {
  background: rgba(124, 92, 255, 0.2);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 13px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}
.msg-bubble pre {
  background: rgba(0, 0, 0, 0.3);
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
}
.msg-bubble pre code { background: transparent; padding: 0; }
.msg-bubble ul, .msg-bubble ol { margin: 6px 0; padding-left: 22px; }
.msg-bubble li { margin: 2px 0; }
.msg-bubble strong { color: var(--primary-2); font-weight: 600; }
.msg.from-user .msg-bubble strong { color: #fff; }
.msg-bubble blockquote {
  border-left: 3px solid var(--primary);
  margin: 6px 0;
  padding: 4px 12px;
  color: var(--text-dim);
}

/* 打字指示 */
.typing .msg-bubble { display: flex; align-items: center; gap: 4px; padding: 14px 16px; }
.typing-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: blink 1.4s infinite ease-in-out both;
}
.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }
@keyframes blink {
  0%, 80%, 100% { opacity: 0.25; transform: scale(0.9); }
  40% { opacity: 1; transform: scale(1); }
}
.cursor::after {
  content: "▊";
  animation: blink 1s steps(2) infinite;
  opacity: 0.6;
  margin-left: 2px;
  color: var(--primary-2);
}

/* ---------- 输入框 ---------- */
.composer {
  padding: 12px 6% 20px;
}
.input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 8px 8px 8px 16px;
  max-width: 780px;
  margin: 0 auto;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input-wrap:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
textarea#messageInput,
textarea#welcomeInput {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  resize: none;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.5;
  padding: 8px 0;
  max-height: 180px;
}
textarea::placeholder { color: var(--text-muted); }

.send-btn, .stop-btn {
  width: 38px; height: 38px;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: transform 0.1s, opacity 0.15s;
  flex-shrink: 0;
}
.send-btn { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff; }
.send-btn:hover { transform: scale(1.05); }
.send-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.stop-btn { background: var(--danger); color: #fff; }
.stop-btn:hover { opacity: 0.9; }

.composer-hint { text-align: center; color: var(--text-muted); font-size: 12px; margin-top: 8px; min-height: 16px; }

/* ---------- 通用按钮 ---------- */
.icon-btn {
  background: transparent;
  border: none;
  color: var(--text);
  width: 36px; height: 36px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 15px;
  transition: background 0.15s;
}
.icon-btn:hover { background: var(--surface-hover); }

.primary-btn {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
  font-size: 14px;
  transition: transform 0.1s, box-shadow 0.2s;
  box-shadow: var(--shadow-md);
}
.primary-btn:hover { transform: translateY(-1px); box-shadow: 0 8px 24px rgba(124, 92, 255, 0.35); }

.secondary-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 18px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s;
}
.secondary-btn:hover { background: var(--surface-hover); }

/* ---------- 弹窗 ---------- */
.modal {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
}
.modal-mask { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(4px); }
.modal-body {
  position: relative;
  width: min(480px, 92vw);
  max-height: 88vh;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-header {
  padding: 14px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.modal-content {
  padding: 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.modal-footer {
  padding: 12px 18px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  border-top: 1px solid var(--border);
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; color: var(--text-dim); font-weight: 500; }
.field > small { color: var(--text-muted); font-size: 12px; line-height: 1.5; }
.field input {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 10px;
  outline: none;
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.15s;
}
.field input:focus { border-color: var(--primary); }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.test-result { font-size: 13px; }
.test-result.ok { color: var(--success); }
.test-result.err { color: var(--danger); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20, 25, 50, 0.95);
  color: #fff;
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 14px;
  z-index: 2000;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.25s ease;
  max-width: 90vw;
}
@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------- 滚动条 ---------- */
.messages::-webkit-scrollbar,
.history-list::-webkit-scrollbar,
.modal-content::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-track,
.history-list::-webkit-scrollbar-track,
.modal-content::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb,
.history-list::-webkit-scrollbar-thumb,
.modal-content::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}
.messages::-webkit-scrollbar-thumb:hover,
.history-list::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ---------- 响应式 ---------- */
@media (max-width: 768px) {
  .topbar { padding: 10px 16px; }
  .messages { padding: 16px 4%; }
  .composer { padding: 12px 4% 16px; }
  .msg { max-width: 92%; }
  .welcome-title { font-size: 26px; }
  .welcome-tips { grid-template-columns: 1fr; }
  .history-panel { right: 16px; left: 16px; width: auto; top: 60px; }
  .brand-text { display: none; }
  .brand-icon { font-size: 24px; }
}
