:root {
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  color: #23382f;
  background: #f7f8f4;
  --ink: #23382f;
  --muted: #56675d;
  --line: #d8dfd6;
  --green: #285d48;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .5; }
:focus-visible { outline: 3px solid #548c72; outline-offset: 3px; }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(1.45rem, 3vw, 1.85rem); line-height: 1.4; letter-spacing: -.04em; }
.masthead {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  min-height: 72px; padding: 12px clamp(18px, 5vw, 76px); border-bottom: 1px solid var(--line);
}
.brand, .account, .label-row, .sidebar-heading, .composer-actions { display: flex; align-items: center; gap: 12px; }
.brand { flex: none; font-size: 1.04rem; font-weight: 700; letter-spacing: .05em; }
.brand-mark { position: relative; width: 29px; height: 26px; }
.brand-mark::before, .brand-mark::after { content: ""; position: absolute; width: 19px; height: 14px; border-radius: 5px 5px 5px 1px; }
.brand-mark::before { top: 1px; left: 0; border: 2px solid var(--green); }
.brand-mark::after { bottom: 1px; right: 0; border: 2px solid #f7f8f4; background: var(--green); }
.account { min-width: 0; font-size: .85rem; }
#account-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quiet, .text-action { border: 0; background: transparent; color: var(--green); font-weight: 600; padding: 6px 0; }
.quiet { white-space: nowrap; }
.quiet:hover, .text-action:hover { text-decoration: underline; }
.notice { margin: 12px auto 0; width: min(680px, calc(100% - 36px)); padding: 10px 16px; color: #7f3525; background: #fff2e9; border: 1px solid #e7c9b5; border-radius: 8px; }
.auth, .loading { flex: 1; display: grid; place-items: center; padding: 32px 18px; }
.auth-card { width: min(100%, 390px); padding: 34px; background: #fff; border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 12px 40px #23382f09; }
.auth-card h1 { margin-bottom: 26px; }
label { display: inline-block; font-size: .9rem; font-weight: 600; }
.optional { font-size: .8rem; font-weight: 400; color: var(--muted); }
.field { margin-top: 16px; }
input, textarea { color: var(--ink); background: #fff; border: 1px solid #b7c4b8; border-radius: 8px; }
input { display: block; width: 100%; padding: 11px 12px; margin-top: 6px; }
.primary, .secondary { min-height: 38px; padding: 8px 16px; border: 1px solid transparent; border-radius: 8px; font-size: .88rem; font-weight: 600; }
.primary { background: var(--green); color: #fff; }
.primary:hover:enabled { background: #194b37; }
.secondary { background: #fff; color: var(--green); border-color: #b6c8ba; }
.secondary:hover:enabled { background: #eef4ee; }
.auth-submit { width: 100%; margin-top: 24px; }
.text-action { display: block; margin: 14px auto 0; font-size: .85rem; }
.help { position: relative; display: inline-flex; }
.help-trigger { border: 1px solid #8a9c90; border-radius: 50%; background: transparent; color: #486352; width: 22px; height: 22px; font-size: .78rem; }
.tip { position: absolute; z-index: 1; bottom: calc(100% + 8px); left: 0; width: min(240px, 65vw); padding: 10px 12px; border-radius: 8px; background: #263c30; color: white; line-height: 1.7; font-size: .82rem; box-shadow: 0 4px 16px #20352820; }
.workspace {
  flex: 1; display: grid; grid-template-columns: minmax(185px, 23%) minmax(0, 1fr); width: min(1240px, calc(100% - 48px));
  margin: 20px auto 0; border: 1px solid var(--line); border-radius: 15px; overflow: hidden; background: #fff;
}
.sidebar { background: #eff3ec; padding: 20px 12px; min-width: 0; border-right: 1px solid var(--line); }
.sidebar-heading { justify-content: space-between; margin: 0 5px 18px; }
h2 { font-size: 1rem; }
.sidebar .secondary { min-height: 32px; padding: 5px 10px; font-size: .8rem; }
.conversations { display: flex; flex-direction: column; gap: 3px; overflow: auto; max-height: calc(100dvh - 260px); }
.conversations a { color: #43564a; padding: 10px 12px; border-radius: 7px; font-size: .9rem; text-decoration: none; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; }
.conversations a:hover { background: #e3ecdf; }
.conversations a[aria-current="page"] { color: #244c36; background: #dce8d8; font-weight: 600; }
.thread { min-width: 0; display: flex; flex-direction: column; height: calc(100dvh - 154px); min-height: 330px; }
.thread-heading { padding: 19px clamp(18px, 3vw, 40px); border-bottom: 1px solid var(--line); }
.thread-heading h1 { font-size: 1.16rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.transcript { flex: 1; overflow: auto; overflow-anchor: none; min-height: 0; padding: 20px clamp(14px, 4vw, 58px); }
.history-action { display: block; margin: 10px auto; padding: 5px 10px; border: 0; border-radius: 5px; background: transparent; color: var(--green); font-size: .83rem; text-align: center; }
.history-action:hover:enabled, .message-link:hover, .message-action:hover:enabled { text-decoration: underline; }
.empty { height: 100%; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 15px; color: var(--muted); }
.messages { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 18px; }
.message { max-width: min(85%, 720px); align-self: flex-start; }
.message.user { align-self: flex-end; }
.message.located .message-body { outline: 2px solid #5d866b; outline-offset: 2px; }
.message-meta { display: flex; gap: 10px; align-items: baseline; margin-bottom: 5px; color: var(--muted); font-size: .75rem; }
.user .message-meta { justify-content: flex-end; }
.message-body { background: #f1f3ef; padding: 10px 15px; border-radius: 12px; overflow-wrap: anywhere; line-height: 1.65; }
.user .message-body { background: #e1eddf; }
.message-body p { white-space: pre-wrap; }
.message-image { margin: 0; }
.message-image + .message-image { padding-top: 7px; }
.message-body > * + .message-image, .message-image + p { margin-top: 8px; }
.asset-preview { display: block; max-width: min(100%, 350px); max-height: 240px; border-radius: 7px; object-fit: contain; }
.message-image figcaption { display: flex; flex-wrap: wrap; align-items: baseline; gap: 3px 12px; padding-top: 4px; font-size: .76rem; }
.asset-detail, .preview-missing { color: var(--muted); }
.preview-missing { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 9px; font-size: .8rem; }
.picture-actions { flex-basis: 100%; display: flex; flex-wrap: wrap; gap: 3px 14px; }
.reference-image { display: flex; align-items: center; gap: 8px; min-width: 0; overflow-wrap: anywhere; }
.reference-image .asset-preview { width: 54px; height: 44px; border-radius: 5px; }
.reference-image figcaption { min-width: 0; padding-top: 0; }
.reply-state .reference-image { flex-basis: 100%; justify-content: flex-end; }
.asset-link { color: var(--green); text-underline-offset: 2px; }
.message-link { color: inherit; text-decoration: none; }
.outbox { margin-top: 18px; }
.unconfirmed .message-body { background: #f6f8f3; border: 1px dashed #a2b4a6; }
.reply-state { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; margin-top: 5px; color: var(--muted); font-size: .78rem; }
.user .reply-state { justify-content: flex-end; }
.message-action { padding: 2px 0; border: 0; background: transparent; color: var(--green); font-size: inherit; font-weight: 600; }
.answer-sources { margin-top: 5px; min-width: 0; font-size: .82rem; overflow-wrap: anywhere; }
.answer-sources > summary { width: fit-content; cursor: pointer; }
.answer-sources > summary:hover { text-decoration: underline; }
.answer-source-list { display: grid; gap: 10px; list-style: none; margin: 5px 0 0; padding: 0 0 0 10px; border-inline-start: 2px solid var(--line); }
.answer-source-list > li { display: grid; gap: 4px; min-width: 0; }
.composer { margin: 0 clamp(14px, 3vw, 40px) 18px; border: 1px solid #b7c4b8; border-radius: 12px; padding: 10px 12px; }
.composer:focus-within { border-color: #5d866b; }
.composer-modes { display: flex; flex-wrap: wrap; gap: 3px; margin: 0 0 5px; padding: 0; border: 0; min-width: 0; }
.composer-modes label { position: relative; display: inline-flex; }
.composer-modes input { position: absolute; width: 1px; height: 1px; opacity: 0; padding: 0; margin: 0; }
.composer-modes span { padding: 4px 9px; border: 1px solid transparent; border-radius: 6px; color: var(--muted); font-size: .78rem; cursor: pointer; }
.composer-modes input:checked + span { background: #e5eee3; border-color: #bdcdbf; color: #244c36; }
.composer-modes input:focus-visible + span { outline: 2px solid #548c72; outline-offset: 1px; }
.composer-modes label:hover span { background: #eef3eb; }
.reference-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; padding: 5px 3px; font-size: .8rem; }
#selected-reference { flex: 1 1 210px; min-width: 0; }
.composer textarea { display: block; width: 100%; resize: vertical; min-height: 44px; max-height: 18vh; border: 0; line-height: 1.5; padding: 3px; }
.composer textarea:focus { outline: 0; }
.composer-actions { flex-wrap: wrap; justify-content: space-between; gap: 8px 12px; }
.model-choice { display: flex; align-items: center; gap: 6px; margin-inline-start: auto; }
.model-choice label { font-size: .8rem; }
.model-choice select { max-width: 12em; min-height: 32px; padding: 3px 4px; border: 1px solid #b6c8ba; border-radius: 6px;
  color: var(--ink); background: #fff; font: inherit; font-size: .8rem; }
.composer-actions .primary { margin-inline-start: auto; }
.image-tools, .upload-actions { display: flex; align-items: center; gap: 10px; }
.image-tools { position: relative; }
.image-tools .help { position: static; }
.image-tools > .secondary { min-height: 32px; padding: 5px 10px; font-size: .8rem; }
.draft-images {
  display: flex; flex-wrap: wrap; gap: 6px; overflow-y: auto; max-height: 16vh;
  margin: 0; padding: 3px; list-style: none;
}
.upload-card {
  display: flex; align-items: center; gap: 8px; min-width: 0; max-width: 100%;
  padding: 6px 9px; border: 1px solid var(--line); border-radius: 8px; background: #f7f8f4;
}
.upload-card img { width: 44px; height: 44px; border-radius: 4px; object-fit: contain; }
.upload-info { display: grid; gap: 2px; min-width: 0; font-size: .75rem; }
.upload-info strong { max-width: 20ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-info [role=status], .draft-limit { color: var(--muted); }
.upload-actions { flex-wrap: wrap; }
.draft-limit { margin: 4px 0; font-size: .8rem; }
.picture-picker { width: min(590px, calc(100% - 28px)); max-height: 80dvh; padding: 0 18px 16px; color: var(--ink); border: 1px solid var(--line); border-radius: 12px; }
.picture-picker::backdrop { background: #172b2259; }
.picker-heading { position: sticky; top: 0; display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 14px 0; background: white; }
.picker-heading .quiet { padding: 4px 6px; font-size: .85rem; }
.picker-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 150px), 1fr)); gap: 10px; margin: 0; padding: 0; list-style: none; }
.picture-candidate { display: flex; flex-direction: column; gap: 3px; min-width: 0; padding: 9px; overflow-wrap: anywhere; border: 1px solid var(--line); border-radius: 8px; font-size: .8rem; }
.candidate-preview { display: block; width: 100%; height: 104px; object-fit: contain; border-radius: 5px; background: #f1f3ef; }
.picture-candidate time, .candidate-filename, .picker-status { color: var(--muted); }
.candidate-filename { font-size: .75rem; }
.candidate-actions { margin-top: auto; padding-top: 6px; display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; }
.select-candidate { min-height: 32px; padding: 3px 8px; font-size: .78rem; }
.picker-status { margin: 10px 0; font-size: .85rem; }
.picker-empty { display: flex; flex-direction: column; align-items: flex-start; gap: 12px; color: var(--muted); font-size: .85rem; }
.memory-launch { flex: none; min-height: 32px; padding: 5px 10px; font-size: .82rem; }
.memory-browser {
  width: min(750px, calc(100% - 28px)); height: min(710px, 82dvh); max-height: calc(100dvh - 24px);
  padding: 0; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 14px;
}
.memory-browser[open] { display: flex; flex-direction: column; }
.memory-browser::backdrop { background: #172b2259; }
.memory-heading, .memory-nav, .memory-panel { padding-inline: clamp(14px, 3vw, 28px); }
.memory-heading { display: flex; justify-content: space-between; align-items: center; padding-block: 14px 10px; }
.memory-heading h2 { font-size: 1.25rem; }
.memory-heading .quiet { font-size: .85rem; }
.memory-nav { display: flex; gap: 16px; border-bottom: 1px solid var(--line); }
.memory-nav button { padding: 7px 2px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); font-size: .88rem; }
.memory-nav button[aria-pressed="true"] { color: var(--green); border-color: var(--green); font-weight: 700; }
.memory-panel { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding-block: 12px 22px; }
.memory-search { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: end; gap: 10px 12px; margin: 0 0 16px; }
.memory-search label { min-width: 0; font-size: .82rem; }
.memory-search input, .memory-search select { display: block; width: 100%; min-width: 0; min-height: 36px; margin-top: 4px; padding: 5px 7px;
  border: 1px solid #b7c4b8; background: #fff; color: var(--ink); border-radius: 7px; font: inherit; font-weight: 400; }
.memory-search .primary { justify-self: start; }
.memory-search.memory-recall-form { grid-template-columns: minmax(0, 1fr) auto; }
.memory-list { list-style: none; margin: 0; padding: 0; }
.memory-list > li + li { border-top: 1px solid var(--line); }
.memory-image-match { display: grid; grid-template-columns: minmax(0, 1fr) clamp(72px, 18vw, 104px); gap: 12px; }
.memory-match-preview { min-width: 0; padding-block: 12px; font-size: .78rem; }
.memory-match-preview .memory-preview { width: 100%; max-height: 82px; margin-bottom: 4px; }
.memory-related { margin: 14px 0 0; color: var(--muted); font-size: .88rem; }
.memory-entry { min-width: 0; overflow-wrap: anywhere; }
.memory-entry > summary { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 12px 3px; cursor: pointer; list-style: none; }
.memory-entry > summary::-webkit-details-marker { display: none; }
.memory-entry > summary:focus-visible { outline-offset: -2px; border-radius: 5px; }
.memory-entry > summary:hover .memory-disclose { text-decoration: underline; }
.memory-text, .memory-observation { white-space: pre-wrap; line-height: 1.55; }
.memory-disclose { flex: none; color: var(--green); font-size: .8rem; font-weight: 600; }
.memory-meta, .memory-status, .memory-observation, .memory-source-heading, .memory-provenance { color: var(--muted); }
.memory-meta { display: block; margin-top: 3px; font-size: .76rem; }
.memory-detail { margin: 0 0 12px 3px; padding-inline-start: clamp(9px, 2vw, 18px); border-inline-start: 2px solid var(--line); }
.memory-unlinked { padding: 12px 3px; }
.memory-observation { margin-bottom: 6px; font-size: .88rem; }
.memory-feedback { display: flex; align-items: baseline; flex-wrap: wrap; gap: 6px 12px; padding: 8px 2px; }
.memory-status { font-size: .85rem; }
.memory-feedback .secondary { min-height: 32px; padding: 5px 10px; font-size: .8rem; }
.memory-source-heading, .memory-image figcaption, .memory-provenance { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; font-size: .78rem; }
.memory-source-heading strong, .memory-image strong { color: var(--ink); }
.memory-original { display: grid; gap: 10px; min-width: 0; }
.memory-quote { margin: 0; padding: 9px 12px; background: #f1f3ef; border-radius: 8px; white-space: pre-wrap; line-height: 1.65; }
.memory-image { margin: 0; }
.memory-preview { display: block; max-width: 100%; max-height: 190px; object-fit: contain; border-radius: 6px; }
.memory-image figcaption { padding-top: 5px; }
.memory-provenance { flex-basis: 100%; }
footer { display: flex; justify-content: center; flex-wrap: wrap; gap: 4px 20px; padding: 14px 16px; font-size: .74rem; color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@media (max-width: 700px) {
  body { height: 100vh; height: 100dvh; }
  .masthead { min-height: 55px; }
  .workspace { display: flex; flex-direction: column; min-height: 0; width: 100%; margin: 0; border: 0; border-radius: 0; }
  .sidebar { padding: 8px 14px; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar-heading { margin: 0; }
  .conversations { flex-direction: row; max-height: none; }
  .conversations:not(:empty) { margin-top: 6px; }
  .conversations a { flex: none; max-width: 170px; padding: 6px 10px; }
  .thread { flex: 1; min-height: 0; height: auto; }
  .transcript { flex: 1 1 0; min-height: 0; }
  .message { max-width: 94%; }
  .thread-heading { padding: 10px 18px; }
  .composer { margin-bottom: 8px; }
  .composer-modes span { padding: 4px 6px; }
  .auth-card { padding: 25px; }
  footer { padding: 8px 10px; }
}
@media (max-width: 560px) {
  .account { gap: 7px; }
  .memory-browser { height: calc(100dvh - 24px); width: calc(100% - 16px); }
  .memory-search { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .memory-query, .memory-search:not(.memory-recall-form) .primary { grid-column: 1 / -1; }
}
