:root {
  --bg: #f6f3ec;
  --bg-tint: #f0ece2;
  --panel: #fffdf9;
  --ink: #2a2521;
  --ink-soft: #756f64;
  --line: #e7e1d6;
  --line-soft: #efeae0;
  --accent: #b06a3f;
  --accent-deep: #8f5430;
  --accent-soft: #f1e7db;
  --user-bubble: #eef1f0;
  --assistant-bubble: #fffdf9;
  --shadow: 0 1px 2px rgba(60, 45, 30, 0.05), 0 4px 16px rgba(60, 45, 30, 0.04);
  --shadow-soft: 0 1px 2px rgba(60, 45, 30, 0.04);
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Segoe UI", sans-serif;
  --font-serif: "Songti SC", "STSong", "Noto Serif SC", "Source Han Serif SC",
    Georgia, "Times New Roman", serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.hidden {
  display: none !important;
}

/* 细滚动条（仅 WebKit）——更克制的视觉 */
.session-list,
.messages,
.report-body {
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.session-list::-webkit-scrollbar,
.messages::-webkit-scrollbar,
.report-body::-webkit-scrollbar {
  width: 9px;
}
.session-list::-webkit-scrollbar-thumb,
.messages::-webkit-scrollbar-thumb,
.report-body::-webkit-scrollbar-thumb {
  background: var(--line);
  border: 3px solid transparent;
  background-clip: padding-box;
  border-radius: 99px;
}
.session-list::-webkit-scrollbar-thumb:hover,
.messages::-webkit-scrollbar-thumb:hover,
.report-body::-webkit-scrollbar-thumb:hover {
  background: #d8d0c2;
  background-clip: padding-box;
  border: 3px solid transparent;
}

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

/* ---------- 侧边栏 ---------- */
.sidebar {
  width: 268px;
  flex-shrink: 0;
  background: var(--bg-tint);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}

.sidebar-head {
  padding: 20px 16px 14px;
  border-bottom: 1px solid var(--line);
}

.brand {
  font-family: var(--font-serif);
  font-size: 21px;
  font-weight: 600;
  margin: 0 0 14px;
  letter-spacing: 0.5px;
  color: var(--accent-deep);
}

.btn-new {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s ease, transform 0.08s ease;
}
.btn-new:hover {
  background: var(--accent-deep);
}
.btn-new:active {
  transform: translateY(1px);
}

.session-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.session-item {
  padding: 10px 12px;
  border-radius: 9px;
  cursor: pointer;
  margin-bottom: 4px;
  position: relative;
  transition: background 0.12s;
}
.session-item:hover {
  background: var(--accent-soft);
}
.session-item.active {
  background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}
.session-item .s-title {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 22px;
}
.session-item .s-meta {
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 2px;
}
.session-item .s-badge {
  display: inline-block;
  font-size: 11px;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 0 5px;
  margin-top: 4px;
}
.session-item .s-del {
  position: absolute;
  top: 8px;
  right: 8px;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.12s;
}
.session-item:hover .s-del {
  opacity: 1;
}
.session-item .s-del:hover {
  color: #c0392b;
}

.sidebar-foot {
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--ink-soft);
}

/* ---------- 主区 ---------- */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.topbar-title strong {
  display: block;
  font-family: var(--font-serif);
  font-size: 18px;
  letter-spacing: 0.3px;
}
.topbar-title small {
  color: var(--ink-soft);
  font-size: 12.5px;
}

.icon-btn {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 14px;
}
.icon-btn:hover {
  background: var(--accent-soft);
}
.only-mobile {
  display: none;
}

/* ---------- 对话视图 ---------- */
.chat-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px clamp(16px, 6vw, 80px);
}

.msg {
  display: flex;
  margin-bottom: 20px;
  animation: msg-in 0.34s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}
@keyframes msg-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
@media (prefers-reduced-motion: reduce) {
  .msg {
    animation: none;
  }
}
.msg.user {
  justify-content: flex-end;
}
.bubble {
  max-width: 740px;
  padding: 13px 17px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  white-space: pre-wrap;
  word-break: break-word;
}
.msg.assistant .bubble {
  background: var(--assistant-bubble);
  border: 1px solid var(--line);
  border-top-left-radius: 5px;
}
.msg.user .bubble {
  background: var(--user-bubble);
  border-top-right-radius: 5px;
}
.bubble :first-child {
  margin-top: 0;
}
.bubble :last-child {
  margin-bottom: 0;
}
.bubble p {
  margin: 0.5em 0;
}
.bubble ul,
.bubble ol {
  margin: 0.5em 0;
  padding-left: 1.4em;
}
.bubble li {
  margin: 0.25em 0;
}
.bubble strong {
  color: var(--accent-deep);
}
.bubble code {
  background: var(--bg-tint);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.92em;
}
.bubble .cursor {
  display: inline-block;
  width: 7px;
  height: 1.05em;
  background: var(--accent);
  vertical-align: text-bottom;
  margin-left: 1px;
  animation: blink 1s steps(1) infinite;
}
@keyframes blink {
  50% {
    opacity: 0;
  }
}

.empty-hint {
  color: var(--ink-soft);
  text-align: center;
  margin-top: 14vh;
  font-size: 14px;
}

/* ---------- 输入区 ---------- */
.composer {
  border-top: 1px solid var(--line);
  padding: 14px clamp(16px, 6vw, 80px);
  background: var(--panel);
}
.composer-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}
#input {
  flex: 1;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.6;
  max-height: 180px;
  outline: none;
  background: var(--panel);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
#input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.btn-send {
  padding: 12px 22px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-size: 15px;
  white-space: nowrap;
  transition: background 0.15s ease, transform 0.08s ease;
}
.btn-send:hover {
  background: var(--accent-deep);
}
.btn-send:active {
  transform: translateY(1px);
}
.btn-send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.composer-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
}
.btn-report {
  padding: 7px 14px;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  border-radius: 8px;
  cursor: pointer;
  font-size: 13.5px;
  transition: all 0.15s;
}
.btn-report:not(:disabled):hover {
  background: var(--accent);
  color: #fff;
}
.btn-report:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  border-color: var(--line);
  color: var(--ink-soft);
}
.btn-report.ready {
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.hint {
  font-size: 12.5px;
  color: var(--ink-soft);
}

/* ---------- 报告视图 ---------- */
.report-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.report-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px clamp(16px, 6vw, 80px);
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.report-toolbar-right {
  display: flex;
  gap: 10px;
}
.btn-ghost {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: 7px 13px;
  cursor: pointer;
  font-size: 13.5px;
}
.btn-ghost:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.report-body {
  flex: 1;
  overflow-y: auto;
  padding: 44px clamp(20px, 10vw, 160px);
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
  font-size: 16px;
  line-height: 1.85;
}
.report-body h1,
.report-body h2,
.report-body h3 {
  font-family: var(--font-serif);
  line-height: 1.4;
  letter-spacing: 0.3px;
  margin: 1.7em 0 0.6em;
  text-wrap: pretty;
}
.report-body h1 {
  font-size: 30px;
  color: var(--accent-deep);
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.4em;
  margin-top: 0.2em;
}
.report-body h2 {
  font-size: 22px;
  color: var(--accent);
}
.report-body h3 {
  font-size: 18px;
  color: var(--ink);
}
.report-body p {
  margin: 0.9em 0;
}
.report-body ul,
.report-body ol {
  padding-left: 1.5em;
  margin: 0.7em 0;
}
.report-body li {
  margin: 0.4em 0;
}
.report-body strong {
  color: var(--accent-deep);
}
.report-loading {
  color: var(--ink-soft);
  text-align: center;
  margin-top: 12vh;
}
.report-body blockquote {
  border-left: 3px solid var(--accent);
  margin: 1em 0;
  padding: 0.2em 1em;
  color: var(--ink-soft);
  background: var(--accent-soft);
  border-radius: 0 8px 8px 0;
}
.report-body code {
  background: #f0ede7;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.92em;
}
.report-body hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 1.8em 0;
}

/* ---------- 响应式 ---------- */
@media (max-width: 760px) {
  .sidebar {
    position: fixed;
    z-index: 20;
    height: 100%;
    transform: translateX(-100%);
    transition: transform 0.2s;
    box-shadow: 2px 0 14px rgba(0, 0, 0, 0.12);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .only-mobile {
    display: inline-block;
  }
}

/* ---------- 打印：只印报告 ---------- */
@media print {
  .sidebar,
  .topbar,
  .report-toolbar,
  .chat-view {
    display: none !important;
  }
  .layout,
  .main,
  .report-view {
    display: block;
    height: auto;
    overflow: visible;
  }
  .report-body {
    overflow: visible;
    padding: 0;
    max-width: none;
  }
  body {
    background: #fff;
  }
}
