:root {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-soft: #f3f4f6;
  --text: #202124;
  --text-soft: #4b5563;
  --muted: #6b7280;
  --muted-2: #9aa0a6;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --accent: #2563eb;
  --accent-soft: #eef2ff;
  --green: #0f9d58;
  --orange: #d97706;
  --red: #dc2626;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(17, 24, 39, .04), 0 10px 30px rgba(17, 24, 39, .04);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, p { margin-top: 0; }
svg { display: block; }
::selection { background: #dbeafe; }

.app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }

/* Sidebar */
.sidebar {
  width: 276px;
  flex: 0 0 276px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 18px 14px 14px;
  background: #fbfbfc;
  border-right: 1px solid var(--border);
  z-index: 50;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 18px;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: #111827;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
}
.brand-copy { display: flex; flex-direction: column; line-height: 1.25; }
.brand-copy strong { font-size: 13.5px; font-weight: 600; }
.brand-copy small { color: var(--muted); font-size: 11px; }
.sidebar-nav { display: flex; flex-direction: column; gap: 3px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--text-soft);
  font-size: 13.5px;
  text-align: left;
}
.nav-item svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.nav-item:hover { background: #f1f2f4; color: var(--text); }
.nav-item.active { background: var(--surface); color: var(--text); border-color: var(--border); box-shadow: 0 1px 2px rgba(17, 24, 39, .04); font-weight: 600; }

.sidebar-section {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.icon-btn {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
}
.icon-btn:hover { background: #eef0f2; color: var(--text); }
.section-hint { margin: 8px 8px 10px; color: var(--muted); font-size: 11px; line-height: 1.6; }
.upload-button {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0 2px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text-soft);
  font-size: 12.5px;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
}
.upload-button:hover, .upload-button.dragover { border-color: var(--border-strong); background: #fff; }
.upload-button input { display: none; }
.upload-plus { color: var(--muted); font-size: 15px; line-height: 1; }
.doc-list { display: flex; flex-direction: column; gap: 2px; margin-top: 10px; overflow-y: auto; min-height: 0; }
.doc-empty { margin: 4px 8px; color: var(--muted-2); font-size: 11.5px; line-height: 1.6; }
.doc-card {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
}
.doc-card:hover { background: #f1f2f4; }
.doc-card.selected { background: var(--accent-soft); border-color: #dbe4ff; }
.doc-card input { margin: 3px 0 0; width: 13px; height: 13px; accent-color: #111827; flex: 0 0 auto; }
.doc-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.doc-name { color: var(--text); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-meta { display: flex; align-items: center; gap: 5px; color: var(--muted-2); font-size: 10.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--muted-2); flex: 0 0 auto; }
.status-dot.ready { background: var(--green); }
.status-dot.processing { background: var(--orange); animation: pulse 1.2s infinite; }
.status-dot.failed { background: var(--red); }
@keyframes pulse { 50% { opacity: .35; } }
.doc-del {
  border: 0;
  background: transparent;
  color: var(--muted-2);
  padding: 0 2px;
  font-size: 15px;
  line-height: 1;
}
.doc-del:hover { color: var(--red); }
.selected-summary { margin: 8px 8px 0; color: var(--muted); font-size: 10.5px; }
.sidebar-footer { flex: 0 0 auto; padding: 14px 8px 2px; border-top: 1px solid var(--border); }
.back-link { color: var(--text-soft); font-size: 12px; }
.back-link:hover { color: var(--text); text-decoration: underline; }
.sidebar-footer p { margin: 6px 0 0; color: var(--muted-2); font-size: 10.5px; line-height: 1.5; }
.sidebar-overlay { display: none; }

/* Main */
.main { flex: 1; min-width: 0; height: 100%; overflow: hidden; background: var(--bg); }
.tab-panel { display: none; height: 100%; }
.tab-panel.active { display: block; }
.chat-page { display: flex; flex-direction: column; height: 100%; }
.page-topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 72px;
  padding: 14px 28px;
  background: rgba(255, 255, 255, .82);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
}
.page-title { min-width: 0; flex: 1; }
.page-title h1 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: -.01em; }
.page-title p { margin: 2px 0 0; color: var(--muted); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page-actions { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.model-picker { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 11.5px; }
.model-picker select {
  width: auto;
  min-width: 150px;
  padding: 7px 26px 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 12px;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, #9ca3af 50%), linear-gradient(135deg, #9ca3af 50%, transparent 50%);
  background-position: calc(100% - 13px) 50%, calc(100% - 9px) 50%;
  background-size: 4px 4px, 4px 4px;
  background-repeat: no-repeat;
}
.ghost-btn {
  padding: 7px 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text-soft);
  font-size: 12px;
}
.ghost-btn:hover { border-color: var(--border-strong); color: var(--text); }
.sidebar-toggle {
  display: none;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text-soft);
  flex: 0 0 auto;
}
.sidebar-toggle svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }

/* Chat */
.chat-scroll { flex: 1; overflow-y: auto; padding: 38px 24px 10px; scroll-behavior: smooth; }
.chat-welcome { max-width: 760px; margin: 5vh auto 0; text-align: center; }
.welcome-symbol { color: #9ca3af; font-size: 26px; line-height: 1; }
.chat-welcome h2 { margin: 12px 0 6px; font-size: 27px; font-weight: 600; letter-spacing: -.03em; }
.chat-welcome > p { margin: 0 auto; max-width: 520px; color: var(--muted); font-size: 13px; }
.suggestions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; margin-top: 28px; text-align: left; }
.suggestions button {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 13px 14px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface);
  text-align: left;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.suggestions button:hover { border-color: var(--border-strong); box-shadow: 0 2px 8px rgba(17, 24, 39, .04); }
.suggestions strong { color: var(--text); font-size: 12.5px; font-weight: 600; }
.suggestions span { color: var(--muted); font-size: 11.5px; }
.messages { display: flex; flex-direction: column; gap: 26px; max-width: 820px; margin: 0 auto; padding-bottom: 8px; }
.message { display: flex; flex-direction: column; gap: 5px; }
.message-user { align-items: flex-end; }
.msg-role { color: var(--muted-2); font-size: 10.5px; padding: 0 2px; }
.msg-bubble { max-width: 100%; font-size: 14.5px; line-height: 1.8; color: var(--text); word-break: break-word; }
.message-user .msg-bubble {
  max-width: min(680px, 88%);
  padding: 10px 15px;
  border-radius: 18px;
  background: #f1f3f4;
  color: #1f2329;
  border-bottom-right-radius: 5px;
}
.message-assistant .msg-bubble { background: transparent; padding: 0; border: 0; }
.msg-bubble.streaming { white-space: pre-wrap; }
.msg-sources { display: flex; flex-wrap: wrap; gap: 5px; max-width: 760px; margin-top: 4px; }
.source-chip {
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: #fbfbfc;
  color: var(--muted);
  font-size: 10.5px;
  line-height: 1.6;
}
.msg-error { color: var(--red); font-size: 12px; }
.loading-dots { display: inline-flex; gap: 4px; padding: 6px 0; }
.loading-dots i { width: 5px; height: 5px; border-radius: 50%; background: #9ca3af; animation: bounce 1s infinite; }
.loading-dots i:nth-child(2) { animation-delay: .15s; }
.loading-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 100% { transform: translateY(0); opacity: .45; } 50% { transform: translateY(-4px); opacity: 1; } }

.composer-wrap { flex: 0 0 auto; padding: 12px 24px 18px; background: var(--bg); }
.composer { max-width: 820px; margin: 0 auto; }
.composer-box {
  padding: 9px 11px 8px;
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(17, 24, 39, .03);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.composer-box:focus-within { border-color: #9ca3af; box-shadow: 0 4px 16px rgba(17, 24, 39, .06); }
.composer-box textarea {
  display: block;
  width: 100%;
  min-height: 42px;
  max-height: 180px;
  padding: 4px 4px 6px;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.65;
}
.composer-box textarea::placeholder { color: var(--muted-2); }
.composer-toolbar { display: flex; align-items: center; gap: 12px; padding: 2px 1px 0 4px; }
.composer-status { flex: 1; color: var(--muted-2); font-size: 10.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.send-button {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 9px;
  background: #111827;
  color: #fff;
  flex: 0 0 auto;
}
.send-button:hover:not(:disabled) { background: #374151; }
.send-button:disabled { opacity: .35; cursor: not-allowed; }
.send-button svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.composer-note { margin: 7px 0 0; color: var(--muted-2); font-size: 10.5px; text-align: center; }

/* Report */
.report-page { display: flex; flex-direction: column; height: 100%; }
.report-grid {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 18px;
  padding: 20px 28px 28px;
}
.report-form, .report-document {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.report-form { padding: 20px; height: fit-content; }
.field { display: flex; flex-direction: column; gap: 5px; margin-top: 12px; color: var(--text-soft); font-size: 11.5px; }
.field:first-child { margin-top: 0; }
.field em { color: var(--red); font-style: normal; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field-submit { justify-content: flex-end; }
.field-submit .primary-btn { width: 100%; }
input, textarea, select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  outline: none;
  background: #fff;
  color: var(--text);
  font-size: 12.5px;
}
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, #9ca3af 50%), linear-gradient(135deg, #9ca3af 50%, transparent 50%); background-position: calc(100% - 13px) 50%, calc(100% - 9px) 50%; background-size: 4px 4px, 4px 4px; background-repeat: no-repeat; padding-right: 26px; }
textarea { resize: vertical; line-height: 1.6; }
input:focus, textarea:focus, select:focus { border-color: #9ca3af; box-shadow: 0 0 0 3px rgba(17, 24, 39, .05); }
.report-docs { display: flex; flex-direction: column; gap: 2px; max-height: 150px; overflow-y: auto; padding: 4px; border: 1px solid var(--border); border-radius: 8px; background: #fbfbfc; }
.report-doc { display: flex; align-items: center; gap: 7px; padding: 4px 5px; border-radius: 6px; color: var(--text-soft); font-size: 11.5px; }
.report-doc:hover { background: #f1f2f4; }
.report-doc input { width: 13px; height: 13px; accent-color: #111827; }
.report-empty { padding: 5px; color: var(--muted-2); font-size: 11px; line-height: 1.6; }
.primary-btn {
  border: 0;
  border-radius: 8px;
  padding: 8px 16px;
  background: #111827;
  color: #fff;
  font-size: 12.5px;
  font-weight: 500;
}
.primary-btn:hover:not(:disabled) { background: #374151; }
.primary-btn:disabled { opacity: .35; cursor: not-allowed; }
.status-line { margin: 10px 0 0; color: var(--muted-2); font-size: 10.5px; line-height: 1.5; }
.report-document { padding: 26px 34px; min-height: 520px; }
.document-head { display: flex; align-items: baseline; gap: 10px; padding-bottom: 14px; border-bottom: 1px solid var(--border); }
.document-kicker { color: var(--muted-2); font-size: 9.5px; letter-spacing: .12em; }
.document-head h2 { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: -.02em; }
.report-preview { padding: 22px 0; }
.empty-preview { display: grid; place-items: center; gap: 8px; min-height: 360px; color: var(--muted-2); text-align: center; }
.empty-doc { color: #c4c7cc; font-size: 30px; line-height: 1; }
.empty-preview p { max-width: 330px; font-size: 11.5px; line-height: 1.7; }
.report-sources { display: flex; flex-wrap: wrap; gap: 5px; padding-top: 12px; border-top: 1px solid var(--border); }

/* Markdown */
.md-body { max-width: 760px; color: #2b2f36; font-size: 13.5px; line-height: 1.9; }
.md-body h1, .md-body h2, .md-body h3 { color: #111827; line-height: 1.4; margin: 1.3em 0 .5em; letter-spacing: -.01em; }
.md-body h1 { font-size: 22px; }
.md-body h2 { font-size: 17px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.md-body h3 { font-size: 15px; }
.md-body p { margin: .65em 0; }
.md-body ul, .md-body ol { padding-left: 1.45em; }
.md-body li { margin: .25em 0; }
.md-body table { width: 100%; border-collapse: collapse; margin: 1em 0; font-size: 12px; }
.md-body th, .md-body td { padding: 7px 9px; border: 1px solid var(--border); text-align: left; }
.md-body th { background: #f9fafb; font-weight: 600; }
.md-body blockquote { margin: .8em 0; padding: .35em 1em; border-left: 2px solid var(--border-strong); color: var(--muted); background: #fbfbfc; }
.md-body pre { overflow: auto; padding: 12px; border: 1px solid var(--border); border-radius: 8px; background: #fbfbfc; }
.md-body code { font-family: "Cascadia Code", Consolas, monospace; font-size: .9em; background: #f3f4f6; padding: 1px 3px; border-radius: 3px; }
.md-body pre code { background: transparent; padding: 0; }
.md-body a { color: var(--accent); text-decoration: underline; }
.md-body hr { border: 0; border-top: 1px solid var(--border); margin: 1.2em 0; }

/* Scrollbars */
.doc-list::-webkit-scrollbar, .chat-scroll::-webkit-scrollbar, .report-grid::-webkit-scrollbar, .report-preview::-webkit-scrollbar { width: 8px; }
.doc-list::-webkit-scrollbar-thumb, .chat-scroll::-webkit-scrollbar-thumb, .report-grid::-webkit-scrollbar-thumb, .report-preview::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 99px; border: 2px solid transparent; background-clip: content-box; }

@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: 20px 0 60px rgba(17, 24, 39, .1);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; position: fixed; inset: 0; z-index: 40; background: rgba(17, 24, 39, .22); }
  .sidebar-toggle { display: grid; }
  .page-topbar { padding: 12px 14px; min-height: 64px; gap: 10px; }
  .page-title p { display: none; }
  .page-actions .model-picker > span { display: none; }
  .page-actions .model-picker select { min-width: 128px; }
  .chat-scroll { padding: 24px 15px 8px; }
  .chat-welcome { margin-top: 3vh; }
  .chat-welcome h2 { font-size: 23px; }
  .suggestions { grid-template-columns: 1fr; margin-top: 20px; }
  .composer-wrap { padding: 10px 12px 14px; }
  .report-grid { grid-template-columns: 1fr; padding: 14px; }
  .report-document { padding: 20px; min-height: 360px; }
  .report-form { padding: 16px; }
}
@media (max-width: 520px) {
  .page-actions .model-picker { display: none; }
  .field-row { grid-template-columns: 1fr; }
  .composer-note { font-size: 9.5px; }
  .document-head h2 { font-size: 16px; }
  .report-document { padding: 16px; }
}
