:root {
  --bg: #ffffff;
  --sidebar: #f7f7f8;
  --line: #e7e7e8;
  --text: #171717;
  --muted: #707070;
  --soft: #f4f4f5;
  --blue: #315efb;
  --blue-soft: #eef3ff;
  --danger: #b42318;
  --warning: #b54708;
  --success: #027a48;
  --shadow: 0 12px 36px rgba(20, 25, 38, 0.08);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); overflow: hidden; }
button, textarea { font: inherit; }
button { color: inherit; }

.app-shell { height: 100vh; display: grid; grid-template-columns: 260px minmax(0, 1fr); }
.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  padding: 14px 12px 14px;
  display: flex;
  flex-direction: column;
  min-width: 0;
  z-index: 30;
}
.brand-row { display: flex; align-items: center; gap: 10px; padding: 4px 6px 14px; }
.brand-mark, .welcome-mark, .assistant-avatar {
  display: grid; place-items: center; color: #fff; font-weight: 700; letter-spacing: -.02em;
  background: linear-gradient(135deg, #2f5df5, #6e58ff);
}
.brand-mark { width: 32px; height: 32px; border-radius: 9px; font-size: 13px; flex: 0 0 auto; }
.brand-copy { min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.brand-copy strong { font-size: 14px; }
.brand-copy span { margin-top: 4px; font-size: 11px; color: var(--muted); }

.new-chat {
  width: 100%; height: 42px; border: 0; border-radius: 10px; background: transparent;
  display: flex; align-items: center; gap: 10px; padding: 0 12px; cursor: pointer; font-weight: 600;
}
.new-chat:hover, .nav-item:hover { background: #ececee; }
.new-chat-icon { font-size: 19px; font-weight: 400; }
.side-nav { margin-top: 14px; }
.nav-label { padding: 0 12px 8px; color: #929292; font-size: 11px; }
.nav-item {
  width: 100%; height: 40px; border: 0; background: transparent; border-radius: 9px;
  display: flex; align-items: center; gap: 10px; padding: 0 12px; cursor: pointer; text-align: left;
  font-size: 13px;
}
.nav-icon { width: 18px; color: #5f6368; text-align: center; font-size: 15px; }
.sidebar-spacer { flex: 1; min-height: 20px; }
.portfolio-note { margin: 8px 8px 0; padding-top: 12px; border-top: 1px solid #e2e2e3; font-size: 10px; color: #999; line-height: 1.7; }

.main-panel { min-width: 0; height: 100vh; display: grid; grid-template-rows: 54px minmax(0, 1fr) auto; }
.topbar {
  height: 54px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 22px; border-bottom: 1px solid rgba(0,0,0,.055); background: rgba(255,255,255,.94);
  backdrop-filter: blur(12px); position: relative; z-index: 20;
}
.topbar-title { font-size: 14px; font-weight: 600; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.status-pill { display: inline-flex; align-items: center; gap: 7px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 999px; font-size: 11px; color: #666; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #13a66a; box-shadow: 0 0 0 3px rgba(19,166,106,.1); }
.text-btn { border: 0; background: transparent; cursor: pointer; font-size: 12px; color: #555; padding: 8px 9px; border-radius: 8px; }
.text-btn:hover { background: var(--soft); }
.icon-btn { width: 34px; height: 34px; border: 0; background: transparent; border-radius: 8px; cursor: pointer; font-size: 20px; display: grid; place-items: center; }
.icon-btn:hover { background: var(--soft); }
.mobile-only, .desktop-hidden { display: none; }

.chat-stage { min-height: 0; overflow-y: auto; overscroll-behavior: contain; scroll-behavior: smooth; }
.welcome { min-height: 100%; max-width: 790px; margin: 0 auto; padding: 12vh 24px 130px; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.welcome-mark { width: 44px; height: 44px; border-radius: 14px; margin-bottom: 22px; font-size: 15px; box-shadow: 0 8px 24px rgba(49,94,251,.18); }
.welcome h1 { margin: 0; font-size: clamp(25px, 3vw, 34px); letter-spacing: -.035em; font-weight: 650; text-align: center; }
.welcome p { margin: 12px 0 28px; color: var(--muted); font-size: 13px; text-align: center; line-height: 1.7; }
.suggestions { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.suggestion {
  border: 1px solid var(--line); background: #fff; border-radius: 14px; padding: 15px 16px; text-align: left; cursor: pointer;
  transition: .18s ease; min-height: 72px;
}
.suggestion:hover { border-color: #d7d7d9; box-shadow: 0 4px 18px rgba(0,0,0,.045); transform: translateY(-1px); }
.suggestion strong { display: block; font-size: 13px; margin-bottom: 6px; }
.suggestion span { display: block; color: #888; font-size: 11px; line-height: 1.5; }

.message-list { width: 100%; padding: 22px 0 120px; }
.message { width: 100%; }
.message-inner { max-width: 820px; margin: 0 auto; padding: 18px 24px; }
.user-message .message-inner { display: flex; justify-content: flex-end; }
.user-bubble { max-width: min(76%, 640px); padding: 12px 16px; background: #f1f1f2; border-radius: 18px; font-size: 14px; line-height: 1.7; white-space: pre-wrap; overflow-wrap: anywhere; }
.assistant-message .message-inner { display: grid; grid-template-columns: 28px minmax(0,1fr); gap: 14px; }
.assistant-avatar { width: 28px; height: 28px; border-radius: 8px; font-size: 9px; margin-top: 1px; }
.assistant-content { min-width: 0; }
.assistant-body { font-size: 14px; line-height: 1.85; color: #222; }
.assistant-body h2, .assistant-body h3 { margin: 20px 0 8px; line-height: 1.45; }
.assistant-body h2 { font-size: 17px; }
.assistant-body h3 { font-size: 14px; }
.assistant-body p { margin: 8px 0; }
.assistant-body ul { margin: 8px 0; padding-left: 20px; }
.assistant-body li { margin: 5px 0; }
.assistant-body code { background: #f5f5f6; padding: 2px 5px; border-radius: 5px; font-family: Consolas, monospace; font-size: 12px; }
.assistant-body table { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 12px; }
.assistant-body th, .assistant-body td { border-bottom: 1px solid var(--line); padding: 9px 8px; text-align: left; vertical-align: top; }
.assistant-body th { color: #666; font-weight: 600; background: #fafafa; }
.risk-badge { display: inline-flex; align-items: center; padding: 3px 7px; border-radius: 6px; font-weight: 600; font-size: 11px; }
.risk-high { background: #fff0ed; color: var(--danger); }
.risk-medium { background: #fff7e8; color: var(--warning); }
.risk-low { background: #ecfdf3; color: var(--success); }
.evidence-line { margin-top: 13px; display: flex; flex-wrap: wrap; gap: 7px; }
.evidence-chip { display: inline-flex; align-items: center; gap: 5px; border: 1px solid #e4e7ec; background: #fafafa; color: #667085; border-radius: 999px; padding: 5px 8px; font-size: 10px; }

.trace-details { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }
.trace-details summary { cursor: pointer; color: #777; font-size: 11px; user-select: none; list-style: none; }
.trace-details summary::-webkit-details-marker { display: none; }
.trace-details summary::before { content: "›"; display: inline-block; margin-right: 7px; transition: transform .15s; }
.trace-details[open] summary::before { transform: rotate(90deg); }
.trace-content { margin-top: 10px; border-left: 2px solid #e5e7eb; padding: 4px 0 4px 12px; color: #7a7a7a; font-size: 11px; line-height: 1.7; }
.trace-step { margin: 5px 0; }
.trace-step b { color: #565656; }

.loading-dots { display: inline-flex; gap: 4px; padding: 6px 0; }
.loading-dots i { width: 6px; height: 6px; border-radius: 50%; background: #9a9a9a; animation: pulse 1.2s infinite ease-in-out; }
.loading-dots i:nth-child(2) { animation-delay: .14s; }
.loading-dots i:nth-child(3) { animation-delay: .28s; }
@keyframes pulse { 0%,80%,100%{ opacity:.25; transform:scale(.8)} 40%{opacity:1; transform:scale(1)} }

.composer-wrap { width: 100%; background: linear-gradient(180deg, rgba(255,255,255,0), #fff 20%, #fff 100%); padding: 10px 24px 14px; position: relative; z-index: 15; }
.composer { max-width: 820px; margin: 0 auto; border: 1px solid #dedfe1; border-radius: 22px; min-height: 54px; display: flex; align-items: flex-end; gap: 10px; padding: 10px 10px 10px 16px; background: #fff; box-shadow: 0 5px 18px rgba(0,0,0,.055); }
.composer:focus-within { border-color: #c9cbd0; box-shadow: 0 7px 24px rgba(0,0,0,.07); }
.composer textarea { flex: 1; min-width: 0; border: 0; outline: 0; resize: none; max-height: 160px; min-height: 28px; padding: 5px 0; font-size: 14px; line-height: 1.45; color: #222; background: transparent; }
.composer textarea::placeholder { color: #999; }
.send-btn { width: 34px; height: 34px; flex: 0 0 34px; border: 0; border-radius: 50%; background: #111; color: #fff; font-size: 18px; cursor: pointer; display: grid; place-items: center; }
.send-btn:disabled { background: #c9c9ca; cursor: not-allowed; }
.composer-foot { max-width: 820px; margin: 7px auto 0; text-align: center; color: #aaa; font-size: 9px; }

.drawer-backdrop, .mobile-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.28); opacity: 0; pointer-events: none; transition: .18s ease; z-index: 70; }
.project-drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(460px, 92vw); background: #fff; z-index: 80; transform: translateX(101%); transition: transform .22s ease; box-shadow: -16px 0 46px rgba(0,0,0,.12); display: flex; flex-direction: column; }
.project-drawer.open { transform: translateX(0); }
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }
.drawer-head { padding: 22px 22px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: flex-start; justify-content: space-between; }
.eyebrow { font-size: 9px; letter-spacing: .14em; color: #9b9b9b; margin-bottom: 7px; }
.drawer-head h2 { margin: 0; font-size: 20px; }
.drawer-body { overflow-y: auto; padding: 8px 22px 28px; }
.drawer-section { padding: 18px 0; border-bottom: 1px solid var(--line); }
.drawer-section h3 { font-size: 13px; margin: 0 0 10px; }
.drawer-section p { font-size: 12px; color: #666; line-height: 1.8; margin: 0; }
.mini-grid { display: grid; gap: 8px; }
.mini-grid > div { border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: grid; grid-template-columns: 28px 1fr; column-gap: 8px; }
.mini-grid b { color: var(--blue); font-size: 11px; }
.mini-grid span { font-weight: 600; font-size: 12px; }
.mini-grid small { grid-column: 2; color: #8a8a8a; font-size: 10px; margin-top: 4px; line-height: 1.5; }
.tech-list { display: grid; gap: 0; }
.tech-list > div { display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px dashed #ececec; font-size: 11px; }
.tech-list > div:last-child { border-bottom: 0; }
.tech-list span { color: #929292; }
.tech-list strong { font-weight: 600; text-align: right; }
.soft-box { border: 0; background: #f7f8fa; border-radius: 12px; padding: 14px; margin-top: 16px; }

@media (max-width: 860px) {
  body { overflow: hidden; }
  .app-shell { display: block; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: min(290px, 88vw); transform: translateX(-102%); transition: transform .2s ease; box-shadow: 14px 0 40px rgba(0,0,0,.12); }
  .sidebar.open { transform: translateX(0); }
  .mobile-only, .desktop-hidden { display: grid; }
  .mobile-backdrop.open { opacity: 1; pointer-events: auto; z-index: 25; }
  .main-panel { height: 100dvh; }
  .topbar { padding: 0 12px; }
  .topbar-title { flex: 1; padding-left: 8px; }
  .text-btn { display: none; }
  .status-pill { padding: 6px 8px; font-size: 10px; }
  .welcome { padding: 8vh 16px 110px; }
  .suggestions { grid-template-columns: 1fr; }
  .suggestion { min-height: 64px; }
  .message-inner { padding: 15px 16px; }
  .user-bubble { max-width: 88%; }
  .composer-wrap { padding: 8px 12px 10px; }
  .composer { border-radius: 20px; }
  .composer-foot { display: none; }
}

@media (max-width: 520px) {
  .welcome h1 { font-size: 25px; }
  .welcome p { font-size: 12px; margin-bottom: 20px; }
  .assistant-message .message-inner { grid-template-columns: 24px minmax(0,1fr); gap: 10px; }
  .assistant-avatar { width: 24px; height: 24px; border-radius: 7px; font-size: 8px; }
  .assistant-body { font-size: 13px; }
  .project-drawer { width: 100%; }
}
