:root {
  color-scheme: light;
  --ink: #20302a;
  --muted: #637369;
  --line: #dbe4de;
  --paper: #ffffff;
  --panel: #f4f7f5;
  --green: #22714e;
  --green-dark: #185c3e;
  --green-pale: #e7f3ec;
  --warning: #9c392e;
  font: 15px/1.6 system-ui, -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; }
a { color: inherit; text-decoration: none; }
button, textarea { font: inherit; }
button { color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
button, a, textarea { touch-action: manipulation; }
:focus-visible { outline: 2px solid var(--green); outline-offset: 3px; }
[hidden] { display: none !important; }
svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.workspace {
  display: grid;
  grid-template: 60px minmax(0, 1fr) / 248px minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  background: var(--paper);
}
.workspace.history-closed { grid-template-columns: 0 minmax(0, 1fr); }
.topbar {
  grid-column: 1 / -1;
  z-index: 3;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}
.topbar-main, .topbar-actions, .brand { display: flex; align-items: center; gap: 12px; }
.topbar-main { min-width: 0; }
.brand { gap: 8px; font-size: 16px; font-weight: 700; white-space: nowrap; }
.brand-mark, .welcome-mark {
  display: grid;
  place-items: center;
  border: 1px solid #cfe5d7;
  background: var(--green-pale);
  color: var(--green-dark);
  border-radius: 8px;
}
.brand-mark { width: 32px; height: 32px; }
.quiet-link, .account-link { font-size: 13px; white-space: nowrap; }
.quiet-link { color: var(--muted); }
.quiet-link:hover, .account-link:hover { text-decoration: underline; }
.account-link {
  border: 1px solid var(--line);
  padding: 5px 12px;
  border-radius: 6px;
  color: var(--green-dark);
  font-weight: 650;
}
.icon-button {
  display: grid;
  place-items: center;
  flex: none;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #516358;
}
.icon-button:hover { background: #e9efeb; color: var(--ink); }

.history {
  grid-column: 1;
  grid-row: 2;
  min-height: 0;
  padding: 18px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  background: var(--panel);
  border-right: 1px solid var(--line);
}
.history-closed .history { visibility: hidden; padding: 0; }
.new-chat {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid #bdd8c7;
  border-radius: 8px;
  min-height: 42px;
  font-weight: 650;
  color: var(--green-dark);
  background: var(--green-pale);
}
.new-chat:hover { background: #dceee3; }
.history-heading { margin: 10px 8px 0; color: var(--muted); font-size: 12px; font-weight: 650; }
.conversation-list { display: grid; gap: 4px; }
.history-empty { padding: 4px 8px; margin: 0; font-size: 13px; color: var(--muted); }
.conversation-row {
  display: grid;
  align-items: center;
  grid-template-columns: minmax(0, 1fr) 34px;
  min-height: 56px;
  border-radius: 6px;
}
.conversation-row:hover, .conversation-row.active { background: #e5eee8; }
.conversation-row .icon-button { width: 30px; height: 32px; }
.conversation-row .icon-button svg { width: 15px; height: 15px; }
.conversation-title {
  text-align: left;
  border: 0;
  padding: 6px 9px;
  background: transparent;
  min-width: 0;
}
.conversation-title strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.conversation-title time { display: block; font-size: 11px; color: var(--muted); }
.more-button { background: transparent; border: 0; color: var(--green-dark); text-align: center; padding: 6px; }
.overlay { display: none; }

.chat { grid-column: 2; grid-row: 2; display: grid; min-height: 0; min-width: 0; grid-template-rows: minmax(0, 1fr) auto; }
.reading-pane { overflow: auto; padding: 32px 26px 18px; }
.welcome {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 20px 0 54px;
  text-align: center;
}
.welcome-mark { width: 58px; height: 58px; }
.welcome-mark svg { width: 30px; height: 30px; }
.welcome h1 { margin: 18px 0 22px; font-size: 28px; line-height: 1.35; overflow-wrap: anywhere; }
.suggestions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.suggestions button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  padding: 7px 12px;
  min-height: 40px;
}
.suggestions button:hover { background: var(--panel); border-color: #a6bcae; }
.suggestions svg { color: var(--green-dark); width: 16px; height: 16px; }
.suggestions button:nth-child(2) svg { color: #987035; }
.messages { list-style: none; max-width: 760px; margin: 0 auto; padding: 0; display: grid; gap: 24px; }
.message { min-width: 0; padding: 0; }
.message-user { justify-self: end; max-width: min(95%, 620px); }
.message-user .message-body { padding: 10px 14px; border-radius: 8px; background: var(--green-pale); }
.message-assistant { display: grid; align-items: start; grid-template-columns: 32px minmax(0, 1fr); gap: 10px; }
.message-body { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.75; }
.markdown-body { white-space: normal; }
.markdown-body > :first-child { margin-top: 0; }
.markdown-body > :last-child { margin-bottom: 0; }
.markdown-body :is(p, ul, ol, blockquote, pre, table) { margin: 0 0 0.8em; }
.markdown-body :is(h1, h2, h3, h4, h5, h6) { font-size: 1em; margin: 1.1em 0 0.45em; }
.markdown-body :is(ul, ol) { padding-inline-start: 1.5em; }
.markdown-body li + li { margin-top: 0.25em; }
.markdown-body li > p { margin-bottom: 0.4em; }
.markdown-body a { color: var(--green-dark); text-decoration: underline; text-underline-offset: 3px; }
.markdown-body blockquote { border-inline-start: 3px solid var(--line); padding-inline-start: 12px; }
.markdown-body :is(pre, code) { background: var(--panel); border-radius: 4px; }
.markdown-body code { padding: 0.12em 0.28em; }
.markdown-body pre { overflow-x: auto; padding: 10px 12px; }
.markdown-body pre > code { padding: 0; }
.markdown-body table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; }
.markdown-body :is(th, td) { border: 1px solid var(--line); padding: 6px 10px; }
.markdown-body th { background: var(--panel); }
.markdown-body img { max-width: 100%; height: auto; border-radius: 8px; }
.assistant-content { min-width: 0; padding-top: 3px; }
.progress { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; margin: 4px 0; }
.spinner { display: inline-block; width: 13px; height: 13px; border: 2px solid #d7e2da; border-top-color: #6e8b78; border-radius: 50%; animation: spin 0.85s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
.message-error { margin: 8px 0 0; color: var(--warning); font-size: 13px; overflow-wrap: anywhere; }
.references { display: grid; gap: 8px; margin-top: 16px; }
.references h2 { margin: 0; font-size: 13px; color: var(--muted); }
.reference-card {
  display: grid;
  align-items: center;
  grid-template-columns: 84px minmax(0, 1fr) 18px;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 82px;
  padding: 8px;
  background: var(--paper);
}
a.reference-card:hover { border-color: #a4bfae; background: var(--panel); }
.reference-cover { width: 84px; height: 64px; display: grid; place-items: center; border-radius: 5px; background: var(--green-pale); color: var(--green); overflow: hidden; }
.reference-cover > img { width: 100%; height: 100%; object-fit: cover; grid-area: 1 / 1; }
.reference-cover > svg { grid-area: 1 / 1; }
.reference-text { min-width: 0; }
.reference-text strong { display: block; overflow-wrap: anywhere; font-size: 14px; }
.reference-text p { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; overflow-wrap: anywhere; margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.reference-card > svg { width: 15px; height: 15px; color: var(--muted); }

.composer-area { padding: 10px 26px max(20px, env(safe-area-inset-bottom)); background: var(--paper); }
.notice { max-width: 760px; margin: 0 auto 7px; font-size: 13px; color: var(--warning); }
.composer {
  max-width: 760px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  align-items: end;
  gap: 10px;
  border: 1px solid #b9cbc0;
  border-radius: 8px;
  padding: 10px;
  background: var(--paper);
}
.composer:focus-within { border-color: var(--green); box-shadow: 0 0 0 2px #e1efe6; }
.composer textarea {
  max-height: 136px;
  min-height: 50px;
  padding: 4px 5px;
  resize: vertical;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
}
.composer textarea::placeholder { color: #6e7c73; }
.send-button { display: grid; place-items: center; width: 42px; height: 42px; background: var(--green); color: #fff; border: 0; border-radius: 7px; }
.send-button:disabled { background: #dbe6de; color: #63796a; }
.send-button:not(:disabled):hover { background: var(--green-dark); }
.delete-dialog { border: 1px solid var(--line); border-radius: 8px; padding: 20px; width: min(360px, calc(100% - 32px)); color: var(--ink); }
.delete-dialog::backdrop { background: rgb(20 36 29 / 40%); }
.delete-dialog h2 { margin: 0; font-size: 18px; }
.delete-dialog p { color: var(--muted); }
.delete-dialog form > div { display: flex; justify-content: end; gap: 8px; }
.delete-dialog button { border: 1px solid var(--line); background: var(--paper); padding: 5px 12px; border-radius: 6px; }
.delete-dialog button.danger { color: #fff; background: var(--warning); border-color: var(--warning); }

.drawer-login { display: none; }
.drawer-login:has(.account-link:not([hidden])) { display: block; margin-top: 18px; }

@media (max-width: 700px) {
  .workspace, .workspace.history-closed { grid-template-columns: 0 minmax(0, 1fr); grid-template-rows: 54px minmax(0, 1fr); }
  .topbar { padding: 0 12px; }
  .topbar-main { gap: 4px; }
  .topbar-actions { gap: 8px; }
  .brand { font-size: 14px; }
  .brand-mark { width: 28px; height: 28px; }
  .quiet-link { font-size: 12px; }
  .history, .history-closed .history {
    display: flex;
    visibility: hidden;
    position: fixed;
    z-index: 2;
    inset: 54px auto 0 0;
    width: min(300px, calc(100% - 43px));
    padding: 16px 12px;
  }
  .history-mobile-open .history { visibility: visible; }
  .history-mobile-open .overlay {
    display: block;
    position: fixed;
    z-index: 1;
    inset: 54px 0 0;
    border: 0;
    background: rgb(18 38 28 / 26%);
  }
  .reading-pane { padding: 20px 14px 12px; }
  .welcome h1 { font-size: 22px; }
  .welcome { padding-bottom: 20px; }
  .composer-area { padding: 7px 12px max(12px, env(safe-area-inset-bottom)); }
  .message-assistant { grid-template-columns: 27px minmax(0, 1fr); gap: 7px; }
  .reference-card { grid-template-columns: 60px minmax(0, 1fr) 14px; gap: 8px; }
  .reference-cover { width: 60px; height: 52px; }
}

.chat-embedded .topbar,
.chat-embedded:not(.chat-embedded-expanded) :is(.history, .overlay) { display: none; }
.chat-embedded .workspace { grid-template-rows: minmax(0, 1fr); }
.chat-embedded :is(.chat, .history) { grid-row: 1; }
.chat-embedded:not(.chat-embedded-expanded) .workspace { grid-template-columns: minmax(0, 1fr); }
.chat-embedded:not(.chat-embedded-expanded) .chat { grid-column: 1; }
