/* AI 智能工作站 V1.0 样式 —— 深浅色主题 + 响应式布局 */

:root {
  --bg: #f7f8fa;
  --bg-elevated: #ffffff;
  --sidebar-bg: #f0f2f5;
  --border: #e2e5ea;
  --border-strong: #d0d5dd;
  --text: #1a1d24;
  --text-muted: #6b7280;
  --text-faint: #9ca3af;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --bubble-user: #4f46e5;
  --bubble-user-text: #ffffff;
  --bubble-ai: #ffffff;
  --code-bg: #1e1e2e;
  --code-text: #e0e0e0;
  --hover: rgba(0,0,0,0.04);
  --active: rgba(79,70,229,0.10);
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 8px 24px rgba(0,0,0,0.04);
  --green: #16a34a;
  --red: #dc2626;
  --yellow: #d97706;
}
[data-theme="dark"] {
  --bg: #11131a;
  --bg-elevated: #1a1d27;
  --sidebar-bg: #161922;
  --border: #2a2e3b;
  --border-strong: #3a3f50;
  --text: #e8eaf0;
  --text-muted: #9aa1b1;
  --text-faint: #6b7280;
  --accent: #7c83ff;
  --accent-hover: #9298ff;
  --accent-soft: #232640;
  --bubble-user: #4f46e5;
  --bubble-user-text: #ffffff;
  --bubble-ai: #1e222e;
  --code-bg: #0d0f16;
  --code-text: #d4d7e0;
  --hover: rgba(255,255,255,0.05);
  --active: rgba(124,131,255,0.14);
  --shadow: 0 2px 6px rgba(0,0,0,0.25), 0 12px 32px rgba(0,0,0,0.18);
  --green: #4ade80;
  --red: #f87171;
  --yellow: #fbbf24;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
svg { flex-shrink: 0; }

.app { display: flex; height: 100vh; height: 100dvh; width: 100%; }

/* ---------- 侧边栏 ---------- */
.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: width .22s ease, transform .22s ease;
  overflow: hidden;
  z-index: 30;
}
.app.collapsed .sidebar { width: 0; border-right-color: transparent; }
.sidebar-head {
  height: 58px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; white-space: nowrap; overflow: hidden; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), #a855f7);
  color: #fff; font-weight: 700; font-size: 12px;
  display: flex; align-items: center; justify-content: center;
}
.brand-text { font-weight: 600; font-size: 15px; letter-spacing: .2px; }
.icon-btn {
  width: 32px; height: 32px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); transition: background .15s, color .15s;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.new-chat-btn {
  margin: 12px 12px 6px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  display: flex; align-items: center; gap: 9px;
  font-weight: 500; white-space: nowrap;
  transition: background .15s, transform .1s;
}
.new-chat-btn:hover { background: var(--accent-hover); }
.new-chat-btn:active { transform: scale(.98); }

.nav-main { flex: 1; overflow-y: auto; padding: 4px 8px 8px; min-height: 0; }
.nav-group-title {
  font-size: 11px; color: var(--text-faint); font-weight: 600;
  letter-spacing: .5px; padding: 12px 10px 5px; white-space: nowrap;
}
.nav-item {
  width: 100%; padding: 8px 10px; border-radius: 8px;
  display: flex; align-items: center; gap: 10px;
  color: var(--text-muted); white-space: nowrap; text-align: left;
  transition: background .15s, color .15s; margin-bottom: 2px;
}
.nav-item:hover { background: var(--hover); color: var(--text); }
.nav-item.active { background: var(--active); color: var(--accent); font-weight: 500; }
.nav-item em.soon {
  margin-left: auto; font-style: normal; font-size: 10px;
  color: var(--text-faint); background: var(--hover);
  padding: 1px 6px; border-radius: 10px;
}

.sidebar-foot { flex-shrink: 0; border-top: 1px solid var(--border); padding: 8px; max-height: 34vh; display: flex; flex-direction: column; }
.conv-list-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 8px; font-size: 12px; color: var(--text-muted); white-space: nowrap;
}
.conv-count { background: var(--hover); border-radius: 10px; padding: 0 7px; font-size: 11px; }
.conv-list { overflow-y: auto; min-height: 0; }
.conv-item {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 8px; border-radius: 8px; cursor: pointer;
  transition: background .15s; margin-bottom: 2px; position: relative;
}
.conv-item:hover { background: var(--hover); }
.conv-item.active { background: var(--active); }
.conv-item .conv-title {
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 13px; color: var(--text-muted);
}
.conv-item.active .conv-title { color: var(--accent); }
.conv-actions { display: none; gap: 2px; }
.conv-item:hover .conv-actions, .conv-item.active .conv-actions { display: flex; }
.conv-actions button {
  width: 24px; height: 24px; border-radius: 6px; color: var(--text-faint);
  display: flex; align-items: center; justify-content: center;
}
.conv-actions button:hover { background: var(--bg); color: var(--text); }
.conv-actions button.danger:hover { color: var(--red); }
.conv-empty { padding: 16px 8px; text-align: center; color: var(--text-faint); font-size: 12px; white-space: nowrap; }

/* ---------- 主区域 ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
.topbar {
  height: 58px; flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  display: flex; align-items: center; gap: 12px;
  padding: 0 20px; z-index: 10;
}
/* 顶栏展开按钮：桌面端平时隐藏，侧边栏收起后显示；移动端由媒体查询始终显示 */
.mobile-menu { display: none; }
.app.collapsed .mobile-menu { display: flex; }
.topbar-title { font-weight: 600; font-size: 15px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.model-box {
  display: flex; align-items: center; gap: 7px;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 9px; padding: 5px 9px;
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--yellow); flex-shrink: 0; }
.status-dot.online { background: var(--green); box-shadow: 0 0 0 3px rgba(74,222,128,.15); }
.status-dot.offline { background: var(--red); box-shadow: 0 0 0 3px rgba(248,113,113,.15); }
.model-box select {
  background: transparent; border: none; outline: none; font-size: 13px;
  color: var(--text); max-width: 160px; cursor: pointer;
}
.model-box select option { background: var(--bg-elevated); color: var(--text); }
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="light"] .icon-moon { display: none; }

.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.view.hidden { display: none; }

/* ---------- 消息区 ---------- */
.messages { flex: 1; overflow-y: auto; padding: 24px 20px 12px; scroll-behavior: smooth; }
.messages-inner { max-width: 820px; margin: 0 auto; display: flex; flex-direction: column; gap: 22px; }
.welcome {
  max-width: 620px; margin: min(12vh, 90px) auto 0; text-align: center;
  animation: fadeUp .4s ease;
}
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.welcome-logo {
  width: 56px; height: 56px; margin: 0 auto 18px; border-radius: 16px;
  background: linear-gradient(135deg, var(--accent), #a855f7);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 20px;
  box-shadow: 0 8px 24px rgba(79,70,229,.3);
}
.welcome h1 { font-size: 22px; font-weight: 600; margin-bottom: 8px; }
.welcome p { color: var(--text-muted); font-size: 14px; }
.welcome-tips { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 26px; }
.tip-card {
  border: 1px solid var(--border); background: var(--bg-elevated);
  border-radius: 12px; padding: 12px 16px; font-size: 13px;
  color: var(--text-muted); cursor: pointer; transition: border-color .15s, transform .15s;
  text-align: left;
}
.tip-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.tip-card strong { display: block; color: var(--text); font-weight: 500; margin-bottom: 2px; }

.msg { display: flex; gap: 12px; animation: fadeUp .25s ease; }
.msg.user { flex-direction: row-reverse; }
.msg-avatar {
  width: 32px; height: 32px; border-radius: 9px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: #fff;
}
.msg.user .msg-avatar { background: linear-gradient(135deg, #4f46e5, #7c3aed); }
.msg.assistant .msg-avatar { background: linear-gradient(135deg, #0ea5e9, #6366f1); }
.msg-body { max-width: min(75%, 680px); min-width: 0; }
.msg-bubble {
  padding: 10px 14px; border-radius: 14px; line-height: 1.7;
  overflow-wrap: break-word; word-break: break-word;
}
.msg.user .msg-bubble { background: var(--bubble-user); color: var(--bubble-user-text); border-bottom-right-radius: 4px; }
.msg.assistant .msg-bubble { background: var(--bubble-ai); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg.assistant .msg-bubble.error { border-color: var(--red); color: var(--red); }
.msg-meta { font-size: 11px; color: var(--text-faint); margin-top: 4px; display: flex; gap: 10px; }
.msg.streaming .msg-bubble::after {
  content: ''; display: inline-block; width: 6px; height: 14px;
  background: var(--accent); vertical-align: text-bottom; margin-left: 2px;
  animation: blink 1s step-end infinite; border-radius: 2px;
}
@keyframes blink { 50% { opacity: 0; } }

/* ---------- Markdown ---------- */
.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }
.md p { margin: 0 0 10px; }
.md h1, .md h2, .md h3, .md h4 { margin: 16px 0 8px; font-weight: 600; line-height: 1.4; }
.md h1 { font-size: 1.4em; } .md h2 { font-size: 1.25em; } .md h3 { font-size: 1.1em; }
.md ul, .md ol { margin: 0 0 10px; padding-left: 22px; }
.md li { margin-bottom: 3px; }
.md blockquote {
  border-left: 3px solid var(--accent); padding: 4px 12px;
  margin: 0 0 10px; background: var(--hover); color: var(--text-muted);
  border-radius: 0 6px 6px 0;
}
.md a { color: var(--accent); text-decoration: underline; }
.md code.inline {
  background: var(--hover); padding: 1px 5px; border-radius: 4px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; font-size: .9em;
}
.md hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.md table { border-collapse: collapse; margin: 0 0 10px; width: 100%; font-size: .92em; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.md th { background: var(--hover); }

.code-block { margin: 10px 0; border-radius: 10px; overflow: hidden; background: var(--code-bg); }
.code-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 12px; background: rgba(255,255,255,.05);
  font-size: 11px; color: #aab0c0;
}
.code-lang { text-transform: uppercase; letter-spacing: .5px; }
.copy-code {
  color: #aab0c0; font-size: 11px; padding: 2px 8px;
  border-radius: 5px; transition: background .15s, color .15s;
}
.copy-code:hover { background: rgba(255,255,255,.1); color: #fff; }
.code-block pre { margin: 0; padding: 12px 14px; overflow-x: auto; }
.code-block code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12.5px; line-height: 1.6; color: var(--code-text);
  white-space: pre; background: none;
}

/* ---------- 输入区 ---------- */
.composer-wrap { flex-shrink: 0; padding: 0 20px 14px; background: linear-gradient(to top, var(--bg) 75%, transparent); }
.composer {
  max-width: 820px; margin: 0 auto;
  background: var(--bg-elevated); border: 1px solid var(--border-strong);
  border-radius: 16px; padding: 10px 12px 8px;
  box-shadow: var(--shadow); transition: border-color .15s;
}
.composer:focus-within { border-color: var(--accent); }
.composer textarea {
  width: 100%; resize: none; border: none; outline: none; background: transparent;
  max-height: 180px; min-height: 26px; line-height: 1.6; font-size: 14px;
}
.composer textarea::placeholder { color: var(--text-faint); }
.composer-actions { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; }
.composer-hint { font-size: 11px; color: var(--text-faint); }
.send-btn {
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, transform .1s;
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn:active { transform: scale(.94); }
.send-btn:disabled { opacity: .4; cursor: not-allowed; }
.send-btn .icon-stop { display: none; }
.send-btn.is-generating { background: var(--red); }
.send-btn.is-generating .icon-send { display: none; }
.send-btn.is-generating .icon-stop { display: block; }
.composer-note { text-align: center; font-size: 11px; color: var(--text-faint); margin-top: 8px; }

/* ---------- 占位视图 ---------- */
.placeholder-view { align-items: center; justify-content: center; }
.placeholder-card { text-align: center; max-width: 400px; padding: 20px; }
.placeholder-icon { font-size: 48px; margin-bottom: 16px; }
.placeholder-card h2 { font-size: 20px; margin-bottom: 8px; }
.placeholder-card p { color: var(--text-muted); margin-bottom: 20px; }
.ghost-btn {
  padding: 9px 18px; border: 1px solid var(--border-strong);
  border-radius: 9px; color: var(--text); transition: background .15s;
}
.ghost-btn:hover { background: var(--hover); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 9px 18px; border-radius: 9px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  z-index: 100; box-shadow: var(--shadow); max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  z-index: 25; display: none;
}
.overlay.show { display: block; }

/* ---------- 响应式 ---------- */
@media (max-width: 768px) {
  .sidebar { position: fixed; top: 0; left: 0; bottom: 0; width: 280px; transform: translateX(-100%); }
  .app:not(.collapsed) .sidebar { transform: translateX(0); }
  .app.collapsed .sidebar { width: 280px; }
  .mobile-menu { display: flex; }
  .topbar { padding: 0 12px; }
  .messages { padding: 16px 12px 8px; }
  .composer-wrap { padding: 0 10px 10px; }
  .msg-body { max-width: 84%; }
  .welcome { margin-top: 8vh; }
  .model-box select { max-width: 100px; }
}
@media (min-width: 769px) {
  .overlay { display: none !important; }
  /* 桌面端侧边栏收起后：顶栏显示醒目的「展开菜单」按钮 */
  .app.collapsed .mobile-menu {
    width: auto;
    padding: 0 12px;
    gap: 6px;
    height: 34px;
    background: var(--accent-soft);
    color: var(--accent);
    border: 1px solid var(--border-strong);
  }
  .app.collapsed .mobile-menu::after {
    content: '展开菜单';
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
  }
}

/* ---------- 登录遮罩层 ---------- */
.login-overlay {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  padding: 20px;
}
.login-overlay.hidden { display: none; }
.login-card {
  width: 100%; max-width: 380px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 38px 32px 30px;
  box-shadow: var(--shadow);
  text-align: center;
  animation: fadeUp .35s ease;
}
.login-logo {
  width: 54px; height: 54px; margin: 0 auto 18px; border-radius: 15px;
  background: linear-gradient(135deg, var(--accent), #a855f7);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 19px;
  box-shadow: 0 8px 24px rgba(79,70,229,.3);
}
.login-card h1 { font-size: 20px; font-weight: 600; margin-bottom: 6px; }
.login-sub { color: var(--text-muted); font-size: 13px; margin-bottom: 24px; }
#loginForm { display: flex; flex-direction: column; gap: 12px; }
#loginPassword {
  width: 100%; padding: 12px 14px; border-radius: 10px;
  border: 1px solid var(--border-strong); background: var(--bg);
  color: var(--text); outline: none; font-size: 14px; transition: border-color .15s;
}
#loginPassword:focus { border-color: var(--accent); }
#loginBtn {
  width: 100%; padding: 12px; border-radius: 10px;
  background: var(--accent); color: #fff; font-weight: 600; font-size: 14px;
  transition: background .15s, opacity .15s;
}
#loginBtn:hover { background: var(--accent-hover); }
#loginBtn:disabled { opacity: .5; cursor: not-allowed; }
.login-error { color: var(--red); font-size: 13px; margin-top: 12px; min-height: 18px; }
.login-hint { color: var(--text-faint); font-size: 12px; margin-top: 6px; line-height: 1.6; }
.logout-btn {
  margin-top: 18px; padding: 8px 16px; border-radius: 8px;
  border: 1px solid var(--border-strong); color: var(--text-muted); font-size: 12px;
}
.logout-btn:hover { background: var(--hover); color: var(--text); }
