/* ============ 基础 & 液态玻璃主题 ============ */
:root {
  --glass-bg: rgba(255, 255, 255, 0.62);
  --glass-bg-strong: rgba(255, 255, 255, 0.78);
  --glass-border: rgba(255, 255, 255, 0.65);
  --glass-shadow: 0 8px 32px rgba(31, 64, 120, 0.12), inset 0 1px 0 rgba(255,255,255,0.8);
  --text-primary: #1a2540;
  --text-secondary: #5a6a8a;
  --text-muted: #8a98b5;
  --accent: #2f7cf6;
  --accent-soft: rgba(47, 124, 246, 0.12);
  --accent-gradient: linear-gradient(135deg, #3b9dff 0%, #2f7cf6 50%, #5b6cff 100%);
  --user-bubble: linear-gradient(135deg, #3b9dff, #2f7cf6);
  --ai-bubble: rgba(255, 255, 255, 0.85);
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  --mono: "SF Mono", "JetBrains Mono", Consolas, "Courier New", monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  color: var(--text-primary);
  background: linear-gradient(135deg, #e8f0ff 0%, #f0f6ff 35%, #eaf7ff 70%, #f5f0ff 100%);
  background-attachment: fixed;
  overflow: hidden;
  font-size: 15px;
  line-height: 1.6;
}

/* 背景漂浮光斑 */
.bg-blobs { position: fixed; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; }
.blob { position: absolute; border-radius: 50%; filter: blur(80px); opacity: 0.55; animation: float 18s ease-in-out infinite; }
.blob.b1 { width: 420px; height: 420px; background: #9ec8ff; top: -120px; left: -80px; }
.blob.b2 { width: 380px; height: 380px; background: #a8e6ff; bottom: -100px; right: -60px; animation-delay: -6s; }
.blob.b3 { width: 300px; height: 300px; background: #c5b8ff; top: 40%; left: 55%; animation-delay: -12s; opacity: 0.4; }
@keyframes float {
  0%, 100% { transform: translate(0,0) scale(1); }
  33% { transform: translate(40px, -30px) scale(1.08); }
  66% { transform: translate(-30px, 25px) scale(0.95); }
}

.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(22px) saturate(180%);
  -webkit-backdrop-filter: blur(22px) saturate(180%);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
}
.glass-strong {
  background: var(--glass-bg-strong);
  backdrop-filter: blur(28px) saturate(180%);
  -webkit-backdrop-filter: blur(28px) saturate(180%);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
}

/* ============ 登录 / 注册 ============ */
.auth-wrap {
  position: relative; z-index: 1;
  min-height: 100vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 20px;
}
.auth-card {
  width: 100%; max-width: 400px;
  border-radius: var(--radius-lg);
  padding: 36px 32px 28px;
  animation: riseIn 0.5s cubic-bezier(.2,.8,.2,1);
}
@keyframes riseIn { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: none; } }
.auth-logo { text-align: center; margin-bottom: 22px; }
.logo-orb {
  width: 56px; height: 56px; margin: 0 auto 12px; border-radius: 50%;
  background: var(--accent-gradient);
  box-shadow: 0 8px 24px rgba(47,124,246,0.4), inset 0 2px 6px rgba(255,255,255,0.5);
  position: relative;
}
.logo-orb::after {
  content: ''; position: absolute; inset: 10px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(255,255,255,0.9), transparent 60%);
}
.logo-orb.small { width: 30px; height: 30px; margin: 0; }
.auth-logo h1 { font-size: 24px; font-weight: 700; letter-spacing: 0.5px; }
.auth-logo .sub { color: var(--text-secondary); font-size: 13px; margin-top: 4px; }
.auth-tabs { display: flex; background: rgba(255,255,255,0.5); border-radius: 12px; padding: 4px; margin-bottom: 20px; }
.auth-tabs .tab {
  flex: 1; border: none; background: transparent; padding: 9px 0;
  font-size: 14px; font-family: var(--font); color: var(--text-secondary);
  border-radius: 9px; cursor: pointer; transition: all 0.25s; font-weight: 500;
}
.auth-tabs .tab.active { background: #fff; color: var(--accent); box-shadow: 0 2px 8px rgba(47,124,246,0.15); }
.auth-form { display: none; flex-direction: column; gap: 6px; }
.auth-form.active { display: flex; animation: fadeIn 0.3s; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.auth-form label { font-size: 13px; color: var(--text-secondary); font-weight: 500; margin-top: 6px; }
.auth-form label .hint { color: var(--text-muted); font-weight: 400; font-size: 12px; }
.auth-form input {
  border: 1px solid rgba(120,140,180,0.25); background: rgba(255,255,255,0.7);
  border-radius: var(--radius-sm); padding: 11px 14px; font-size: 14px;
  font-family: var(--font); color: var(--text-primary); outline: none;
  transition: all 0.2s;
}
.auth-form input:focus { border-color: var(--accent); background: #fff; box-shadow: 0 0 0 3px var(--accent-soft); }
.btn-primary {
  margin-top: 18px; border: none; border-radius: var(--radius-sm);
  padding: 12px; font-size: 15px; font-weight: 600; font-family: var(--font);
  color: #fff; background: var(--accent-gradient); cursor: pointer;
  box-shadow: 0 6px 18px rgba(47,124,246,0.35); transition: transform 0.15s, box-shadow 0.2s;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 8px 22px rgba(47,124,246,0.45); }
.btn-primary:active { transform: translateY(0); }
.auth-msg { font-size: 13px; min-height: 18px; margin-top: 10px; text-align: center; color: #e5484d; }
.auth-footer { position: relative; z-index: 1; margin-top: 18px; font-size: 12px; color: var(--text-muted); }

/* ============ 主应用布局 ============ */
.app { position: relative; z-index: 1; display: flex; height: 100vh; height: 100dvh; }

/* 侧边栏 */
.sidebar {
  width: 280px; flex-shrink: 0; display: flex; flex-direction: column;
  border-radius: 0; border-top: none; border-bottom: none; border-left: none;
  padding: 16px 12px; gap: 12px; z-index: 30;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 8px; }
.logo-mini { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.new-chat-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid rgba(120,140,180,0.2); background: rgba(255,255,255,0.6);
  border-radius: var(--radius-sm); padding: 10px; font-size: 14px; font-weight: 600;
  font-family: var(--font); color: var(--text-primary); cursor: pointer; transition: all 0.2s;
}
.new-chat-btn:hover { background: #fff; border-color: var(--accent); color: var(--accent); box-shadow: 0 4px 12px rgba(47,124,246,0.15); }
.history-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; padding: 4px 2px; }
.history-item {
  display: flex; align-items: center; gap: 8px; padding: 9px 10px;
  border-radius: var(--radius-sm); font-size: 13.5px; color: var(--text-secondary);
  cursor: pointer; transition: all 0.15s; white-space: nowrap; overflow: hidden; position: relative;
}
.history-item:hover { background: rgba(255,255,255,0.7); color: var(--text-primary); }
.history-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.history-item .hi-title { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.history-item .hi-del {
  opacity: 0; border: none; background: transparent; color: var(--text-muted);
  cursor: pointer; padding: 2px 4px; font-size: 14px; border-radius: 4px;
}
.history-item:hover .hi-del { opacity: 1; }
.history-item .hi-del:hover { color: #e5484d; background: rgba(229,72,77,0.1); }
.history-empty { text-align: center; color: var(--text-muted); font-size: 12.5px; padding: 20px 10px; }
.sidebar-foot {
  display: flex; align-items: center; gap: 10px; padding: 10px;
  border-top: 1px solid rgba(120,140,180,0.15); margin-top: auto;
}
.user-avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; flex-shrink: 0; border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,0.1); }
.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11.5px; color: var(--text-muted); }
.icon-btn {
  border: none; background: transparent; color: var(--text-secondary); cursor: pointer;
  padding: 6px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.icon-btn:hover { background: rgba(255,255,255,0.8); color: var(--accent); }
#closeSidebar { display: none; }
.sidebar-mask { display: none; }

/* 主区域 */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
.navbar {
  display: flex; align-items: center; gap: 12px; padding: 10px 18px;
  border-radius: 0; border-left: none; border-right: none; border-top: none;
  z-index: 20; flex-shrink: 0;
}
.menu-btn { display: none; }
.nav-title { font-weight: 600; font-size: 15px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-toggles { display: flex; align-items: center; gap: 10px; }
.toggle { display: flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }
.toggle input { display: none; }
.toggle .slider {
  width: 34px; height: 20px; border-radius: 10px; background: rgba(120,140,180,0.3);
  position: relative; transition: all 0.25s; flex-shrink: 0;
}
.toggle .slider::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: all 0.25s;
}
.toggle input:checked + .slider { background: var(--accent); }
.toggle input:checked + .slider::after { left: 16px; }
.toggle-label { font-size: 12.5px; color: var(--text-secondary); white-space: nowrap; }
.toggle input:checked ~ .toggle-label { color: var(--accent); font-weight: 600; }
.model-select {
  border: 1px solid rgba(120,140,180,0.25); border-radius: 8px; padding: 6px 8px;
  font-size: 12.5px; font-family: var(--font); color: var(--text-primary);
  background: rgba(255,255,255,0.6); outline: none; cursor: pointer; max-width: 150px;
}

/* 聊天区 */
.chat-area { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; }
.welcome { margin: auto; text-align: center; max-width: 560px; padding: 20px; animation: riseIn 0.5s; }
.welcome-orb {
  width: 72px; height: 72px; margin: 0 auto 18px; border-radius: 50%;
  background: var(--accent-gradient); position: relative;
  box-shadow: 0 12px 32px rgba(47,124,246,0.35), inset 0 2px 8px rgba(255,255,255,0.5);
  animation: pulse 3s ease-in-out infinite;
}
.welcome-orb::after {
  content: ''; position: absolute; inset: 14px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(255,255,255,0.9), transparent 60%);
}
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.06); } }
.welcome h2 { font-size: 26px; font-weight: 700; margin-bottom: 8px; }
.welcome p { color: var(--text-secondary); font-size: 14.5px; margin-bottom: 26px; }
.quick-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.quick-card {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 16px 8px; border-radius: var(--radius-md); cursor: pointer;
  border: 1px solid rgba(120,140,180,0.18); background: rgba(255,255,255,0.55);
  backdrop-filter: blur(12px); font-family: var(--font); font-size: 13px;
  color: var(--text-secondary); transition: all 0.2s;
}
.quick-card:hover { transform: translateY(-3px); background: #fff; border-color: var(--accent); color: var(--accent); box-shadow: 0 8px 20px rgba(47,124,246,0.18); }
.qc-icon { font-size: 22px; }

.messages { display: flex; flex-direction: column; gap: 18px; max-width: 900px; width: 100%; margin: 0 auto; }
.msg { display: flex; gap: 12px; animation: msgIn 0.3s ease; }
@keyframes msgIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.msg.user { flex-direction: row-reverse; }
.msg .avatar {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0; object-fit: cover;
  border: 2px solid rgba(255,255,255,0.8); box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.msg.ai .avatar {
  background: var(--accent-gradient); display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 15px;
}
.msg .bubble {
  max-width: calc(100% - 60px); padding: 12px 16px; border-radius: 16px;
  font-size: 14.5px; line-height: 1.7; word-wrap: break-word; overflow-wrap: anywhere;
}
.msg.user .bubble {
  background: var(--user-bubble); color: #fff; border-bottom-right-radius: 4px;
  box-shadow: 0 4px 14px rgba(47,124,246,0.3);
}
.msg.ai .bubble {
  background: var(--ai-bubble); backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.7); border-bottom-left-radius: 4px;
  box-shadow: 0 4px 14px rgba(31,64,120,0.08); color: var(--text-primary);
}
.msg .bubble p { margin: 6px 0; }
.msg .bubble p:first-child { margin-top: 0; }
.msg .bubble p:last-child { margin-bottom: 0; }
.msg .bubble ul, .msg .bubble ol { margin: 6px 0; padding-left: 22px; }
.msg .bubble li { margin: 3px 0; }
.msg .bubble h1, .msg .bubble h2, .msg .bubble h3, .msg .bubble h4 { margin: 12px 0 6px; line-height: 1.4; }
.msg .bubble h1 { font-size: 1.4em; } .msg .bubble h2 { font-size: 1.25em; } .msg .bubble h3 { font-size: 1.1em; }
.msg .bubble a { color: var(--accent); text-decoration: none; border-bottom: 1px dashed var(--accent); }
.msg .bubble a:hover { border-bottom-style: solid; }
.msg .bubble table { border-collapse: collapse; margin: 8px 0; font-size: 13px; }
.msg .bubble th, .msg .bubble td { border: 1px solid rgba(120,140,180,0.3); padding: 6px 10px; }
.msg .bubble th { background: rgba(47,124,246,0.08); }
.msg .bubble blockquote {
  border-left: 3px solid var(--accent); padding: 4px 12px; margin: 8px 0;
  background: rgba(47,124,246,0.06); border-radius: 0 8px 8px 0; color: var(--text-secondary);
}
.msg .bubble code:not(pre code) {
  background: rgba(47,124,246,0.1); color: #c2410c; padding: 1.5px 6px;
  border-radius: 5px; font-size: 0.88em; font-family: var(--mono);
}
.msg.user .bubble code:not(pre code) { background: rgba(255,255,255,0.25); color: #fff; }

/* 思考过程折叠块 */
.thinking-block {
  background: rgba(120,110,200,0.08); border: 1px solid rgba(120,110,200,0.2);
  border-radius: 10px; margin: 6px 0 10px; overflow: hidden;
}
.thinking-head {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px; cursor: pointer;
  font-size: 12.5px; color: #6d5fc9; font-weight: 600; user-select: none;
}
.thinking-head .dot { width: 8px; height: 8px; border-radius: 50%; background: #8b7fe8; animation: blink 1.2s infinite; }
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }
.thinking-body { padding: 8px 14px 12px; font-size: 13px; color: var(--text-secondary); display: none; white-space: pre-wrap; font-family: var(--mono); line-height: 1.6; max-height: 300px; overflow-y: auto; }
.thinking-block.open .thinking-body { display: block; }

/* 搜索来源卡片 */
.search-sources {
  display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 4px;
}
.search-source {
  display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px;
  padding: 3px 9px; border-radius: 20px; background: rgba(47,124,246,0.08);
  color: var(--accent); text-decoration: none; border: 1px solid rgba(47,124,246,0.15);
  max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.search-source:hover { background: var(--accent-soft); }

/* 代码块 */
.code-block {
  margin: 10px 0; border-radius: 12px; overflow: hidden;
  border: 1px solid rgba(30,41,59,0.12); background: #0d1117;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
}
.code-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 12px; background: rgba(255,255,255,0.06);
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.code-lang { font-size: 12px; color: #8b98b5; font-family: var(--mono); text-transform: uppercase; letter-spacing: 0.5px; }
.code-actions { display: flex; gap: 6px; }
.code-btn {
  border: 1px solid rgba(255,255,255,0.15); background: rgba(255,255,255,0.08);
  color: #c9d4e8; font-size: 11.5px; padding: 4px 10px; border-radius: 6px;
  cursor: pointer; font-family: var(--font); transition: all 0.15s;
}
.code-btn:hover { background: rgba(255,255,255,0.18); color: #fff; }
.code-btn.copied { background: #22c55e; color: #fff; border-color: #22c55e; }
.code-block pre { margin: 0; padding: 14px 16px; overflow-x: auto; }
.code-block pre code {
  background: transparent !important; padding: 0 !important; font-size: 13px;
  line-height: 1.6; font-family: var(--mono); color: #e6edf3;
}
.hljs { background: transparent !important; }

/* 输入区 */
.input-area { padding: 12px 20px 16px; flex-shrink: 0; }
.input-box {
  max-width: 900px; margin: 0 auto; border-radius: 18px; padding: 10px 10px 8px 16px;
  display: flex; flex-direction: column; gap: 6px; transition: box-shadow 0.2s;
}
.input-box:focus-within { box-shadow: 0 8px 32px rgba(47,124,246,0.18), 0 0 0 2px var(--accent-soft), var(--glass-shadow); }
#inputBox {
  width: 100%; border: none; background: transparent; outline: none; resize: none;
  font-family: var(--font); font-size: 14.5px; color: var(--text-primary);
  max-height: 160px; line-height: 1.5;
}
#inputBox::placeholder { color: var(--text-muted); }
.input-actions { display: flex; align-items: center; justify-content: space-between; }
.hint-text { font-size: 11.5px; color: var(--text-muted); }
.send-btn {
  width: 38px; height: 38px; border-radius: 12px; border: none; cursor: pointer;
  background: var(--accent-gradient); color: #fff; display: flex;
  align-items: center; justify-content: center; transition: all 0.2s;
  box-shadow: 0 4px 12px rgba(47,124,246,0.3);
}
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; }
.send-btn:not(:disabled):hover { transform: scale(1.06); }
.input-footer { text-align: center; font-size: 11px; color: var(--text-muted); margin-top: 8px; }

/* 打字光标 */
.typing-cursor { display: inline-block; width: 2px; height: 15px; background: var(--accent); margin-left: 2px; vertical-align: text-bottom; animation: blink 0.8s infinite; }

/* 预览弹窗 */
.modal-mask {
  display: none; position: fixed; inset: 0; background: rgba(20,30,60,0.4);
  backdrop-filter: blur(6px); z-index: 100; align-items: center; justify-content: center; padding: 20px;
}
.modal-mask.show { display: flex; animation: fadeIn 0.2s; }
.modal {
  width: 100%; max-width: 900px; height: 80vh; border-radius: var(--radius-lg);
  display: flex; flex-direction: column; overflow: hidden; animation: riseIn 0.3s;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px; font-weight: 600; font-size: 14px;
  border-bottom: 1px solid rgba(120,140,180,0.15);
}
#previewFrame { flex: 1; border: none; background: #fff; width: 100%; }

/* 滚动条 */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(120,140,180,0.3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(120,140,180,0.5); }

/* ============ 手机端适配 ============ */
@media (max-width: 768px) {
  body { font-size: 14px; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 280px; max-width: 82vw;
    transform: translateX(-105%); transition: transform 0.3s cubic-bezier(.2,.8,.2,1);
    border-radius: 0 18px 18px 0;
  }
  .sidebar.open { transform: translateX(0); box-shadow: 8px 0 40px rgba(0,0,0,0.15); }
  .sidebar-mask {
    display: block; position: fixed; inset: 0; background: rgba(20,30,60,0.35);
    backdrop-filter: blur(3px); z-index: 25; opacity: 0; pointer-events: none; transition: opacity 0.3s;
  }
  .sidebar-mask.show { opacity: 1; pointer-events: auto; }
  #closeSidebar { display: inline-flex; }
  .menu-btn { display: inline-flex; }
  .navbar { padding: 10px 12px; gap: 8px; }
  .nav-toggles { gap: 6px; }
  .toggle-label { display: none; }
  .model-select { max-width: 100px; font-size: 11.5px; padding: 5px 6px; }
  .chat-area { padding: 14px 12px; }
  .input-area { padding: 8px 12px 12px; }
  .msg .bubble { max-width: calc(100% - 50px); padding: 10px 13px; font-size: 14px; }
  .msg .avatar { width: 30px; height: 30px; }
  .quick-cards { grid-template-columns: repeat(2, 1fr); }
  .welcome h2 { font-size: 22px; }
  .auth-card { padding: 28px 22px 22px; }
  .modal { height: 90vh; }
  .blob { filter: blur(60px); }
}
