:root {
  --accent: #4f46e5;
  --accent-dark: #4338ca;
  --accent-light: #eef2ff;
  --bg: #f5f5f5;
  --bg-sidebar: #fafafa;
  --bg-chat: #ffffff;
  --bg-thinking: #f8f8ff;
  --text: #1a1a2e;
  --text-secondary: #666;
  --text-muted: #999;
  --border: #e5e7eb;
  --shadow: 0 1px 3px rgba(0,0,0,0.06);
  --radius: 12px;
  --sidebar-w: 260px;
  --rightnav-collapsed: 20px;
  --rightnav-expanded: 200px;
  --header-h: 48px;
  --content-max: 720px;
}

*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
.hidden{display:none !important}
html,body{height:100%}
body{
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","PingFang SC","Microsoft YaHei",sans-serif;
  font-size:15px;color:var(--text);background:var(--bg);
  overflow:hidden;
}

/* ===== 登录弹窗 ===== */
.modal-overlay{
  position:fixed;inset:0;background:rgba(0,0,0,0.4);z-index:1000;
  display:flex;align-items:center;justify-content:center;
}
.modal-overlay.hidden{display:none}
.modal-box{
  background:#fff;border-radius:16px;padding:36px 28px 28px;width:90%;max-width:360px;
  box-shadow:0 8px 32px rgba(0,0,0,0.12);text-align:center;
}
.modal-box h2{font-size:22px;color:var(--accent);margin-bottom:4px;font-weight:600}
.modal-box p{font-size:13px;color:var(--text-secondary);margin-bottom:20px}
.modal-box input{
  width:100%;padding:12px 16px;border:2px solid var(--border);border-radius:10px;
  font-size:15px;outline:none;margin-bottom:12px;transition:border-color .2s;
}
.modal-box input:focus{border-color:var(--accent)}
.modal-box .btn{
  width:100%;padding:12px;background:var(--accent);color:#fff;border:none;
  border-radius:10px;font-size:15px;font-weight:600;cursor:pointer;transition:background .2s;
}
.modal-box .btn:hover{background:var(--accent-dark)}
.modal-box .btn:disabled{background:#ccc;cursor:not-allowed}
.modal-error{color:#e53935;font-size:13px;margin-top:8px;min-height:20px}

/* ===== 首页 ===== */
.home-view{
  display:flex;flex-direction:column;align-items:center;justify-content:center;
  height:100vh;gap:8px;
}
.home-view .icon{font-size:56px;opacity:.5}
.home-view .title{font-size:16px;color:var(--text-secondary);font-weight:300}
.login-trigger{
  position:fixed;right:12px;bottom:12px;width:18px;height:18px;
  opacity:0;cursor:pointer;z-index:10;border-radius:4px;
}

/* ===== 聊天布局 ===== */
.chat-layout{display:flex;height:100vh;overflow:hidden}

/* 顶栏（移动端） */
.chat-header{
  display:none;height:var(--header-h);background:var(--accent);color:#fff;
  align-items:center;padding:0 14px;flex-shrink:0;z-index:20;
  justify-content:space-between;font-weight:500;
}
#menuToggle{background:none;border:none;color:#fff;font-size:20px;cursor:pointer;padding:4px 8px}
#mobileRightNav{background:none;border:none;color:#fff;font-size:18px;cursor:pointer;padding:4px 8px}
#logoutBtn{background:rgba(255,255,255,0.15);border:none;color:#fff;padding:5px 10px;border-radius:6px;font-size:12px;cursor:pointer}

/* ===== 左侧会话列表 ===== */
.sidebar{
  width:var(--sidebar-w);min-width:var(--sidebar-w);background:var(--bg-sidebar);
  border-right:1px solid var(--border);display:flex;flex-direction:column;flex-shrink:0;
  transition:transform .25s;
}
.sidebar-header{padding:12px 14px;border-bottom:1px solid var(--border);flex-shrink:0}
.sidebar-header .new-btn{
  width:100%;padding:9px;background:var(--accent);color:#fff;border:none;
  border-radius:8px;font-size:14px;cursor:pointer;font-weight:500;transition:background .2s;
}
.sidebar-header .new-btn:hover{background:var(--accent-dark)}
.session-list{flex:1;overflow-y:auto;padding:6px 0}
.sidebar-footer{
  padding:10px 14px;border-top:1px solid var(--border);flex-shrink:0;
}
.logout-link{
  background:none;border:none;color:var(--text-muted);font-size:12px;
  cursor:pointer;padding:4px 0;transition:color .15s;
}
.logout-link:hover{color:#e53935}
.session-group-label{font-size:11px;color:var(--text-muted);padding:10px 14px 4px;font-weight:500;text-transform:uppercase;letter-spacing:.3px}
.session-item{
  padding:9px 14px;cursor:pointer;font-size:13px;color:var(--text);
  white-space:nowrap;overflow:hidden;text-overflow:ellipsis;
  border-radius:0 6px 6px 0;margin:0 8px 2px 0;transition:background .12s;
}
.session-item:hover{background:var(--accent-light)}
.session-item.active{background:var(--accent-light);color:var(--accent);font-weight:500}

/* ===== 中间聊天 ===== */
.chat-main{
  flex:1;display:flex;flex-direction:column;min-width:0;min-height:0;
  background:var(--bg-chat);position:relative;
}
/* 桌面端顶栏 */
.chat-topbar{
  display:flex;align-items:center;justify-content:space-between;
  height:var(--header-h);padding:0 20px;border-bottom:1px solid var(--border);
  background:#fff;flex-shrink:0;
}
.chat-topbar .chat-title{font-size:15px;font-weight:500;color:var(--text)}
.chat-topbar .chat-actions{display:flex;gap:8px}
.chat-topbar .icon-btn{
  background:none;border:none;font-size:16px;cursor:pointer;padding:4px 6px;
  color:var(--text-secondary);border-radius:6px;transition:background .15s;
}
.chat-topbar .icon-btn:hover{background:var(--accent-light)}

/* 消息区域 — 居中 wrapper */
.message-list{
  flex:1;overflow-y:auto;padding:24px 20px 8px;
}
.message-list-inner{
  max-width:var(--content-max);margin:0 auto;
}
.message-list-placeholder{
  text-align:center;color:var(--text-muted);padding:80px 20px;font-size:15px;
}

/* 消息气泡 */
.turn-group{margin-bottom:24px}
.turn-anchor{scroll-margin-top:20px}
.msg-row{display:flex;margin-bottom:4px}
.msg-row.user{justify-content:flex-end}
.msg-bubble{
  max-width:80%;padding:10px 16px;border-radius:14px;line-height:1.55;
  word-break:break-word;white-space:pre-wrap;font-size:14px;
}
.msg-row.user .msg-bubble{
  background:var(--accent);color:#fff;
  border-bottom-right-radius:4px;
}
.msg-row.assistant .msg-bubble{
  background:#fff;color:var(--text);
  border-bottom-left-radius:4px;
}

/* thinking */
.thinking-block{
  margin:4px 0 10px;border-left:3px solid var(--accent);
  background:var(--bg-thinking);border-radius:0 8px 8px 0;
  overflow:hidden;
}
.thinking-header{
  display:flex;align-items:center;gap:6px;padding:8px 14px;
  cursor:pointer;font-size:12px;color:var(--text-secondary);user-select:none;
  transition:background .15s;
}
.thinking-header:hover{background:rgba(79,70,229,0.05)}
.thinking-header .arrow{transition:transform .2s;font-size:9px;color:var(--text-muted)}
.thinking-header .arrow.open{transform:rotate(90deg)}
.thinking-body{
  padding:6px 14px 12px;font-size:13px;color:var(--text-secondary);
  line-height:1.6;white-space:pre-wrap;display:none;
  border-top:1px solid rgba(79,70,229,0.12);
}
.thinking-body.open{display:block}

/* 元信息 */
.meta-line{font-size:11px;color:var(--text-muted);margin-top:2px}

/* Markdown 渲染 */
.msg-bubble p{margin:0 0 6px}.msg-bubble p:last-child{margin-bottom:0}
.msg-bubble code{background:rgba(0,0,0,0.06);padding:1px 5px;border-radius:3px;font-size:13px;font-family:monospace}
.msg-bubble pre{background:rgba(0,0,0,0.04);padding:10px 14px;border-radius:6px;overflow-x:auto;margin:6px 0;font-size:13px}
.msg-bubble pre code{background:none;padding:0;font-size:13px}
.msg-bubble ul,.msg-bubble ol{padding-left:18px;margin:4px 0}
.msg-bubble li{margin:2px 0}
.msg-bubble h2,.msg-bubble h3,.msg-bubble h4,.msg-bubble h5{margin:8px 0 4px;font-weight:600}
.msg-bubble h2{font-size:16px}.msg-bubble h3{font-size:15px}.msg-bubble h4{font-size:14px}.msg-bubble h5{font-size:13px}
.msg-bubble a{color:var(--accent)}
.msg-bubble strong{font-weight:600}
.msg-bubble em{font-style:italic}
.msg-bubble del{text-decoration:line-through;color:var(--text-muted)}
.msg-bubble blockquote{border-left:2px solid var(--accent);padding:4px 0 4px 12px;margin:6px 0;color:var(--text-secondary);font-size:14px}
.msg-bubble hr{border:none;border-top:1px solid var(--border);margin:10px 0}
.msg-bubble table{border-collapse:collapse;width:100%;margin:6px 0;font-size:13px}
.msg-bubble th,.msg-bubble td{border:1px solid var(--border);padding:6px 10px;text-align:left}
.msg-bubble th{background:rgba(0,0,0,0.03);font-weight:600}
.msg-bubble img{max-width:100%;border-radius:6px;margin:4px 0}

/* ===== 输入区 ===== */
.input-area-wrapper{
  padding:0 20px 16px;flex-shrink:0;background:var(--bg-chat);
}
.input-area-outer{
  max-width:var(--content-max);margin:0 auto;
  border:1px solid var(--border);border-radius:16px;
  background:#fff;box-shadow:0 2px 8px rgba(0,0,0,0.04);
  transition:border-color .2s,box-shadow .2s;
}
.input-area-outer:focus-within{
  border-color:var(--accent);
  box-shadow:0 2px 12px rgba(79,70,229,0.08);
}
.input-area-inner{
  display:flex;align-items:flex-end;gap:8px;padding:8px 12px 8px 16px;
}
.input-area-inner textarea{
  flex:1;padding:6px 0;border:none;font-size:15px;font-family:inherit;
  outline:none;resize:none;background:transparent;
  max-height:160px;line-height:1.5;
}
.input-area-inner textarea::placeholder{color:var(--text-muted)}
.input-area-inner .send-btn{
  width:36px;height:36px;border-radius:50%;background:var(--accent);
  color:#fff;border:none;font-size:15px;cursor:pointer;flex-shrink:0;
  display:flex;align-items:center;justify-content:center;transition:background .15s;
}
.input-area-inner .send-btn:hover{background:var(--accent-dark)}
.input-area-inner .send-btn:disabled{background:#ccc;cursor:not-allowed}
.typing-hint{font-size:12px;color:var(--text-muted);padding:4px 16px 0;background:var(--bg-chat);flex-shrink:0}

/* ===== 右侧轮次导航 ===== */
.right-nav{
  width:0;min-width:0;
  background:var(--bg-sidebar);border-left:1px solid var(--border);
  display:flex;flex-direction:column;flex-shrink:0;
  transition:width .2s ease,min-width .2s ease;overflow:hidden;
}
.right-nav.open{width:var(--rightnav-expanded);min-width:var(--rightnav-expanded)}
.right-nav .nav-title{
  font-size:12px;color:var(--text-muted);padding:14px 16px 8px;
  border-bottom:1px solid var(--border);flex-shrink:0;white-space:nowrap;
}
.turn-list{
  flex:1;overflow-y:auto;padding:8px 6px;
  scrollbar-width:none; /* Firefox */
  -ms-overflow-style:none; /* IE/Edge */
}
.turn-list::-webkit-scrollbar{display:none} /* Chrome/Safari */
.turn-dot{
  display:flex;align-items:center;gap:8px;padding:6px 10px;
  cursor:pointer;font-size:13px;color:var(--text-secondary);
  white-space:nowrap;overflow:hidden;border-radius:6px;margin-bottom:2px;
  transition:background .12s;
}
.turn-dot:hover{background:var(--accent-light)}
.turn-dot .dot{
  width:5px;height:5px;border-radius:50%;background:var(--text-muted);flex-shrink:0;
}
.turn-dot.active .dot{background:var(--accent)}
.turn-dot .dot-label{overflow:hidden;text-overflow:ellipsis;flex-shrink:1}

/* ===== 响应式：移动端 ===== */
@media (max-width:767px){
  :root{--sidebar-w:280px;--content-max:100%}

  html,body{height:100%;overflow:hidden}
  #chatView:not(.hidden){height:100%;display:flex;flex-direction:column}
  .chat-header{display:flex;flex-shrink:0}
  .chat-topbar{display:none}
  .chat-layout{flex:1 1 0%;min-height:0;display:flex;overflow:hidden;position:relative}
  .chat-main{position:absolute;top:0;left:0;right:0;bottom:0;display:flex;flex-direction:column}
  .message-list{flex:1 1 0%;overflow-y:auto}
  .input-area-wrapper{flex-shrink:0}

  .sidebar{
    position:fixed;left:0;top:var(--header-h);bottom:0;z-index:30;
    transform:translateX(-100%);box-shadow:2px 0 16px rgba(0,0,0,0.1);
  }
  .sidebar.open{transform:translateX(0)}

  .right-nav{
    position:fixed;right:0;top:var(--header-h);bottom:0;z-index:30;
    width:var(--rightnav-expanded);min-width:var(--rightnav-expanded);
    transform:translateX(100%);box-shadow:-2px 0 16px rgba(0,0,0,0.1);
    transition:transform .25s;
  }
  .right-nav.open{transform:translateX(0)}
  .right-nav .turn-dot .dot-label{opacity:1}

  .drawer-overlay{
    position:fixed;inset:0;background:rgba(0,0,0,0.3);z-index:25;
  }
  .drawer-overlay.hidden{display:none}

  .message-list{padding:16px 12px 8px}
  .input-area-wrapper{padding:0 10px 12px}
  .msg-bubble{max-width:88%}
}

/* 桌面端 */
@media (min-width:768px){
  .chat-header{display:none}
}
