/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #0f1117;
  --bg2:         #171923;
  --bg3:         #1e2130;
  --border:      #2d3148;
  --text:        #e2e8f0;
  --text2:       #94a3b8;
  --text3:       #64748b;
  --blue:        #2563eb;
  --blue-light:  #3b82f6;
  --blue-dim:    #1e3a6e;
  --green:       #22c55e;
  --red:         #ef4444;
  --yellow:      #f59e0b;
  --radius:      12px;
  --sidebar-w:   260px;
  --topbar-h:    52px;
}

html, body { height: 100%; overflow: hidden; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei",
               "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
}

/* ── 登录遮罩 ─────────────────────────────────────────────── */
.auth-overlay {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 999;
}
.auth-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 36px;
  width: 360px; max-width: 90vw;
  text-align: center;
}
.auth-logo {
  display: flex; align-items: center; justify-content: center;
  gap: 10px; margin-bottom: 8px;
  font-size: 20px; font-weight: 700; color: var(--text);
}
.auth-subtitle { color: var(--text2); font-size: 14px; margin-bottom: 24px; }
.auth-input {
  width: 100%; padding: 11px 14px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 10px; color: var(--text);
  font-size: 15px; outline: none;
  margin-bottom: 12px; letter-spacing: 3px;
  transition: border-color .2s;
}
.auth-input:focus { border-color: var(--blue-light); }
.auth-btn {
  width: 100%; padding: 11px;
  background: var(--blue); border: none; border-radius: 10px;
  color: #fff; font-size: 15px; font-weight: 600;
  cursor: pointer; transition: background .15s;
}
.auth-btn:hover { background: var(--blue-light); }
.auth-error { color: var(--red); font-size: 13px; margin-top: 10px; }

/* ── App 布局 ─────────────────────────────────────────────── */
.app { display: flex; height: 100vh; overflow: hidden; }

/* ── 侧边栏 ───────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  height: 100vh; overflow: hidden;
  transition: transform .25s ease;
}
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 14px 10px 16px; flex-shrink: 0;
}
.sidebar-logo {
  display: flex; align-items: center; gap: 8px;
  font-size: 15px; font-weight: 700; color: var(--text);
}
.new-chat-btn {
  width: 30px; height: 30px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text2);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all .15s; flex-shrink: 0;
}
.new-chat-btn:hover { background: var(--blue-dim); color: var(--blue-light); border-color: var(--blue); }

.sidebar-search {
  display: flex; align-items: center; gap: 8px;
  margin: 4px 10px 8px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px;
}
.sidebar-search input {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text); font-size: 13px;
}
.sidebar-search input::placeholder { color: var(--text3); }

.session-list {
  flex: 1; overflow-y: auto; padding: 0 6px 8px;
}
.session-list::-webkit-scrollbar { width: 4px; }
.session-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.session-group-label {
  font-size: 11px; color: var(--text3); font-weight: 600;
  padding: 10px 10px 4px; text-transform: uppercase; letter-spacing: .5px;
}
.session-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 8px;
  cursor: pointer; transition: background .15s; position: relative;
}
.session-item:hover { background: var(--bg3); }
.session-item.active { background: var(--blue-dim); }
.session-icon { flex-shrink: 0; color: var(--text3); }
.session-title {
  flex: 1; font-size: 13px; color: var(--text2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.session-item.active .session-title { color: #93c5fd; }
.session-del {
  display: flex; flex-shrink: 0;
  background: none; border: none; color: var(--text3);
  cursor: pointer; padding: 4px; border-radius: 5px;
  opacity: .55; transition: all .15s;
}
.session-item:hover .session-del { opacity: 1; }
.session-del:hover { color: var(--red); background: rgba(239,68,68,.12); }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border); flex-shrink: 0;
}
.sidebar-footer-info {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--text3);
}
.status-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text3); flex-shrink: 0; transition: background .3s;
}
.status-dot.connected    { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status-dot.disconnected { background: var(--red); }
.status-dot.connecting   { background: var(--yellow); animation: blink 1s infinite; }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:.3} }

/* ── 主区域 ───────────────────────────────────────────────── */
.main {
  flex: 1; display: flex; flex-direction: column;
  overflow: hidden; background: var(--bg);
}

/* 顶部栏 */
.topbar {
  height: var(--topbar-h); flex-shrink: 0;
  display: flex; align-items: center; gap: 10px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.menu-btn {
  display: none; background: none; border: none;
  color: var(--text2); cursor: pointer; padding: 6px;
  border-radius: 6px; transition: background .15s;
}
.menu-btn:hover { background: var(--bg3); }
.topbar-title {
  flex: 1; font-size: 15px; font-weight: 600; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.topbar-actions { display: flex; gap: 6px; }
.model-select {
  max-width: 240px; min-width: 160px;
  background: var(--bg2); border: 1px solid var(--border);
  color: var(--text2); border-radius: 8px; padding: 6px 10px;
  font-size: 13px; outline: none;
}
.model-select:focus { border-color: var(--blue-light); color: var(--text); }
.icon-btn {
  background: none; border: 1px solid var(--border);
  color: var(--text2); border-radius: 8px; padding: 5px 10px;
  cursor: pointer; transition: all .15s;
  display: flex; align-items: center; gap: 5px;
  font-size: 13px;
}
.icon-btn:hover { background: var(--bg3); color: var(--text); }
.term-toggle-btn.active {
  background: #1a2a1a; border-color: var(--green); color: var(--green);
}

/* ── 聊天面板 ─────────────────────────────────────────────── */
.chat-panel {
  flex: 1; display: flex; flex-direction: column; overflow: hidden;
}

.messages-wrap {
  flex: 1; overflow-y: auto; padding: 0; scroll-behavior: smooth;
}
.messages-wrap::-webkit-scrollbar { width: 5px; }
.messages-wrap::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* 欢迎页 */
.welcome {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  min-height: calc(100vh - var(--topbar-h) - 120px);
  padding: 40px 20px; text-align: center;
}
.welcome-icon { margin-bottom: 20px; }
.welcome h2 { font-size: 24px; font-weight: 700; margin-bottom: 8px; }
.welcome p  { color: var(--text2); font-size: 15px; margin-bottom: 32px; }
.welcome-suggestions {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 10px; max-width: 520px; width: 100%;
}
.suggestion-btn {
  background: var(--bg2); border: 1px solid var(--border);
  color: var(--text2); border-radius: 10px;
  padding: 12px 14px; font-size: 13px; text-align: left;
  cursor: pointer; transition: all .15s; line-height: 1.4;
}
.suggestion-btn:hover { background: var(--bg3); border-color: var(--blue); color: var(--text); }

/* 消息 */
.messages { padding: 20px 0 10px; }
.msg {
  display: flex; gap: 14px;
  padding: 16px 24px;
  animation: fadeIn .2s ease;
}
@keyframes fadeIn { from{opacity:0;transform:translateY(6px)} to{opacity:1;transform:none} }

.msg.user   { flex-direction: row-reverse; }
.msg.user .msg-bubble {
  background: var(--blue-dim); border: 1px solid #2d4a8a;
  border-radius: 18px 4px 18px 18px; max-width: 72%;
}
.msg.assistant .msg-bubble {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 4px 18px 18px 18px; max-width: 84%;
}
.msg-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; font-size: 14px; font-weight: 700; margin-top: 2px;
}
.msg.user .msg-avatar { background: linear-gradient(135deg,#3b82f6,#8b5cf6); color:#fff; }
.msg.assistant .msg-avatar { background: var(--blue); color:#fff; }
.msg-bubble { padding: 12px 16px; }
.msg-content { color: var(--text); font-size: 15px; line-height: 1.7; }
.msg-content p { margin: 0 0 10px; }
.msg-content p:last-child { margin-bottom: 0; }
.msg-content h1,.msg-content h2,.msg-content h3 { margin: 16px 0 8px; font-weight: 700; }
.msg-content h1 { font-size: 20px; }
.msg-content h2 { font-size: 17px; }
.msg-content h3 { font-size: 15px; }
.msg-content ul,.msg-content ol { padding-left: 20px; margin: 8px 0; }
.msg-content li { margin: 4px 0; }
.msg-content a  { color: var(--blue-light); text-decoration: none; }
.msg-content a:hover { text-decoration: underline; }
.msg-content strong { color: #f1f5f9; font-weight: 600; }
.msg-content blockquote {
  border-left: 3px solid var(--blue); padding: 4px 14px; margin: 10px 0;
  color: var(--text2); background: var(--bg3); border-radius: 0 6px 6px 0;
}
.msg-content table { width:100%; border-collapse:collapse; margin:12px 0; font-size:14px; }
.msg-content th { background:var(--bg3); padding:8px 12px; border:1px solid var(--border); font-weight:600; }
.msg-content td { padding:7px 12px; border:1px solid var(--border); color:var(--text2); }
.msg-content tr:nth-child(even) td { background:#1a1f2e; }
.msg-content pre {
  background: #0d1117; border: 1px solid var(--border);
  border-radius: 10px; overflow: hidden; margin: 12px 0;
}
.code-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px; background: #161b22; border-bottom: 1px solid var(--border);
  font-size: 12px; color: var(--text3);
}
.copy-btn {
  background: none; border: 1px solid var(--border); color: var(--text3);
  border-radius: 5px; padding: 2px 8px; font-size: 11px; cursor: pointer; transition: all .15s;
}
.copy-btn:hover { background: var(--bg3); color: var(--text); }
.copy-btn.copied { color: var(--green); border-color: var(--green); }
.msg-content pre code {
  display: block; padding: 14px 16px;
  font-family: "JetBrains Mono","Fira Code",Menlo,monospace;
  font-size: 13px; line-height: 1.65; color: #e6edf3; overflow-x: auto; background: none;
}
.msg-content code:not(pre code) {
  background: #1e2130; border: 1px solid var(--border); border-radius: 4px;
  padding: 1px 6px; font-family: "JetBrains Mono","Fira Code",monospace;
  font-size: 13px; color: #79c0ff;
}
.msg-actions {
  display: flex; gap: 6px; margin-top: 8px;
  opacity: 0; transition: opacity .15s;
}
.msg:hover .msg-actions { opacity: 1; }
.msg-action-btn {
  background: none; border: 1px solid var(--border); color: var(--text3);
  border-radius: 6px; padding: 3px 8px; font-size: 12px; cursor: pointer;
  transition: all .15s; display: flex; align-items: center; gap: 4px;
}
.msg-action-btn:hover { background: var(--bg3); color: var(--text); }

/* 流式光标 */
.typing-cursor {
  display: inline-block; width: 2px; height: 1em;
  background: var(--blue-light); margin-left: 1px;
  vertical-align: text-bottom; animation: cursor-blink .7s infinite;
}
@keyframes cursor-blink { 0%,100%{opacity:1} 50%{opacity:0} }

/* 思考动画 */
.thinking {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 24px; color: var(--text3); font-size: 14px;
}
.thinking-dots { display: flex; gap: 4px; }
.thinking-dots span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text3); animation: dot-bounce .9s infinite;
}
.thinking-dots span:nth-child(2) { animation-delay: .15s; }
.thinking-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes dot-bounce { 0%,80%,100%{transform:scale(.8);opacity:.5} 40%{transform:scale(1.2);opacity:1} }

/* 输入区 */
.input-area {
  flex-shrink: 0; padding: 12px 20px 10px;
  border-top: 1px solid var(--border); background: var(--bg);
}
.input-box {
  display: flex; align-items: flex-end; gap: 10px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 14px; padding: 10px 12px; transition: border-color .2s;
}
.input-box:focus-within { border-color: var(--blue-light); }
.input-box textarea {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text); font-size: 15px; line-height: 1.6;
  resize: none; max-height: 200px; min-height: 24px; font-family: inherit;
}
.input-box textarea::placeholder { color: var(--text3); }
.input-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.send-btn {
  width: 36px; height: 36px;
  background: var(--blue); border: none; border-radius: 10px;
  color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background .15s; flex-shrink: 0;
}
.send-btn:hover:not(:disabled) { background: var(--blue-light); }
.send-btn:disabled { background: var(--bg3); color: var(--text3); cursor: not-allowed; }
.abort-btn {
  display: flex; align-items: center; gap: 5px;
  padding: 6px 12px; background: #7f1d1d;
  border: 1px solid #991b1b; border-radius: 10px;
  color: #fca5a5; font-size: 13px; cursor: pointer; transition: background .15s;
}
.abort-btn:hover { background: #991b1b; }
.input-hint { text-align: center; font-size: 11px; color: var(--text3); margin-top: 6px; }

/* ── 终端面板 ─────────────────────────────────────────────── */
.term-panel {
  flex: 1; display: flex; flex-direction: column; overflow: hidden;
  background: #0d1117;
}
.term-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px; background: #161b22;
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.term-toolbar-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--green); font-weight: 600;
}
.term-toolbar-btn {
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text2); border-radius: 6px; padding: 4px 10px;
  font-size: 12px; cursor: pointer; transition: all .15s;
  font-family: monospace;
}
.term-toolbar-btn:hover { background: var(--bg2); color: var(--text); }
.term-toolbar-btn.active {
  background: var(--blue-dim); border-color: var(--blue); color: var(--blue-light);
}
#xterm-container {
  flex: 1; overflow: hidden; padding: 6px 4px;
}
#xterm-container .xterm { height: 100%; }
#xterm-container .xterm-viewport { overflow-y: auto !important; }

/* ── 确认菜单弹层 ─────────────────────────────────────────── */
.confirm-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  animation: fadeIn .15s ease;
}
.confirm-box {
  background: var(--bg2);
  border: 1px solid #854d0e;
  border-radius: 14px;
  padding: 24px 28px;
  width: 520px; max-width: 92vw;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.confirm-header {
  display: flex; align-items: center; gap: 10px;
  font-size: 16px; font-weight: 700; color: var(--yellow);
  margin-bottom: 16px;
}
.confirm-reason {
  font-size: 13px; color: var(--text2);
  margin-bottom: 12px; line-height: 1.5;
}
.confirm-reason strong { color: var(--text); }
.confirm-command {
  background: #0d1117; border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 14px;
  font-family: "JetBrains Mono","Fira Code",monospace;
  font-size: 13px; color: #79c0ff;
  margin-bottom: 18px; word-break: break-all;
}
.confirm-command::before { content: '$ '; color: var(--green); }
.confirm-options {
  display: flex; flex-direction: column; gap: 8px;
}
.confirm-opt-btn {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg3);
  color: var(--text); font-size: 14px; cursor: pointer;
  transition: all .15s; text-align: left;
}
.confirm-opt-btn:hover { border-color: var(--blue-light); background: var(--blue-dim); }
.confirm-opt-btn.yes  { border-color: #166534; }
.confirm-opt-btn.yes:hover  { background: #14532d; border-color: var(--green); }
.confirm-opt-btn.no   { border-color: #7f1d1d; }
.confirm-opt-btn.no:hover   { background: #450a0a; border-color: var(--red); }
.confirm-opt-icon { font-size: 16px; flex-shrink: 0; }
.confirm-opt-text { flex: 1; }
.confirm-opt-key {
  font-size: 11px; color: var(--text3);
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 4px; padding: 1px 6px; font-family: monospace;
}

/* ── 侧边栏遮罩（移动端） ─────────────────────────────────── */
.sidebar-mask {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.5); z-index: 49;
}

/* ── 文件预览卡片 ────────────────────────────────────────── */
.file-preview-card {
  padding: 8px 24px;
  animation: fadeIn .2s ease;
}
.fp-inner {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  max-width: 680px;
}
.fp-header {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg3);
}
.fp-icon { font-size: 22px; flex-shrink: 0; }
.fp-meta { flex: 1; min-width: 0; }
.fp-name {
  display: block; font-size: 14px; font-weight: 600;
  color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.fp-info { font-size: 12px; color: var(--text3); }
.fp-download {
  flex-shrink: 0; color: var(--text3); padding: 6px;
  border-radius: 6px; border: 1px solid var(--border);
  background: var(--bg2); transition: all .15s;
  display: flex; align-items: center; justify-content: center;
  text-decoration: none;
}
.fp-download:hover { color: var(--blue-light); border-color: var(--blue); }

.fp-body { padding: 14px 16px; }

/* 图片 */
.fp-image img {
  max-width: 100%; max-height: 480px;
  object-fit: contain; border-radius: 8px;
  cursor: zoom-in; display: block;
  transition: opacity .2s;
}
.fp-image img:hover { opacity: .9; }

/* 视频 */
.fp-video video { max-width: 100%; border-radius: 8px; }

/* 音频 */
.fp-audio audio { width: 100%; }

/* PDF */
.fp-pdf-toolbar {
  display: flex; gap: 8px; margin-bottom: 10px;
}

/* 代码 */
.fp-code { padding: 0; }
.fp-code-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px; background: #161b22;
  border-bottom: 1px solid var(--border);
}
.fp-code-lang { font-size: 12px; color: var(--text3); font-family: monospace; }
.fp-code-content {
  background: #0d1117; min-height: 48px;
}
.fp-placeholder {
  color: var(--text3); font-size: 13px;
  padding: 16px; text-align: center;
}

/* Markdown */
.fp-md-content { padding-top: 4px; }

/* 压缩包 / 其他 */
.fp-archive, .fp-other {
  display: flex; flex-direction: column; align-items: flex-start; gap: 10px;
}
.fp-archive-tip { font-size: 13px; color: var(--text3); }
.fp-err { color: var(--red); font-size: 13px; }

/* 通用按钮 */
.fp-btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg3);
  color: var(--text2); font-size: 13px; cursor: pointer;
  text-decoration: none; transition: all .15s;
}
.fp-btn:hover { background: var(--bg2); color: var(--text); border-color: var(--blue-light); }
.fp-btn-primary {
  background: var(--blue-dim); border-color: var(--blue); color: var(--blue-light);
}
.fp-btn-primary:hover { background: var(--blue); color: #fff; }

/* ── 响应式 ───────────────────────────────────────────────── */
@media (max-width: 768px) {
  .model-select { max-width: 150px; min-width: 120px; font-size: 12px; padding: 5px 7px; }
  .sidebar {
    position: fixed; left:0; top:0; bottom:0; z-index:50;
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-mask.open { display: block; }
  .menu-btn { display: flex; }
  .main { width: 100%; }
  .msg.user .msg-bubble { max-width: 88%; }
  .msg.assistant .msg-bubble { max-width: 96%; }
  .welcome-suggestions { grid-template-columns: 1fr; }
  .msg { padding: 12px 14px; }
  .confirm-box { padding: 20px 18px; }
}
