:root {
    --ink: #18231e;
    --muted: #6d766f;
    --line: #dfe5df;
    --paper: #fbfcf8;
    --panel: #f1f4ee;
    --green: #165c3a;
    --green-2: #207b50;
    --mint: #dcecdf;
    --amber: #b66b20;
    --danger: #a23a35;
    --shadow: 0 18px 50px rgba(28, 49, 37, .12);
    font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
    color: var(--ink);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--paper); overflow: hidden; }
button, textarea, input, select { font: inherit; }
button { color: inherit; }
button:focus-visible, textarea:focus-visible, input:focus-visible, select:focus-visible, label:focus-within {
    outline: 3px solid rgba(32, 123, 80, .25);
    outline-offset: 2px;
}

.app-shell { height: 100dvh; display: grid; grid-template-columns: 350px minmax(0, 1fr); }
.auth-screen {
    min-height: 100dvh; display: grid; place-items: center; padding: 28px;
    background:
            radial-gradient(circle at 12% 18%, rgba(32,123,80,.14), transparent 28%),
            radial-gradient(circle at 88% 80%, rgba(182,107,32,.1), transparent 24%),
            var(--paper);
}
.auth-card {
    width: min(430px, 100%); padding: 36px; border: 1px solid var(--line);
    border-radius: 20px; background: rgba(255,255,255,.88); box-shadow: var(--shadow);
}
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 32px; }
.auth-brand img { width: 46px; height: 46px; object-fit: cover; border-radius: 13px; }
.auth-brand strong { display: block; font: 600 23px Georgia, "Songti SC", serif; letter-spacing: .08em; }
.auth-brand span { display: block; color: var(--muted); font-size: 10px; letter-spacing: .14em; }
.auth-card h1 { margin: 8px 0 10px; font: 500 29px Georgia, "Songti SC", serif; }
.auth-card > p { color: var(--muted); font-size: 13px; line-height: 1.7; }
.login-form { display: grid; gap: 8px; margin-top: 24px; }
.login-form label { margin-top: 6px; font-size: 11px; font-weight: 700; }
.login-form input {
    width: 100%; border: 1px solid #ccd6cd; border-radius: 10px;
    padding: 11px 12px; background: white;
}
.login-form .primary-button { margin-top: 10px; min-height: 42px; }
.login-hint { margin: 3px 0 0; color: var(--muted); font-size: 10px; }
.auth-privacy { margin: 18px 0 5px; padding-top: 15px; border-top: 1px solid var(--line); font-size: 10px !important; }
.sidebar-backdrop { display: none; }
.sidebar {
    min-height: 0; padding: 24px 22px 18px; display: flex; flex-direction: column;
    background: var(--panel); border-right: 1px solid var(--line); z-index: 5;
}
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.brand-logo { width: 42px; height: 42px; object-fit: cover; border-radius: 12px; }
.brand strong { display: block; font-family: Georgia, "Songti SC", serif; font-size: 23px; letter-spacing: .08em; }
.brand span { display: block; color: var(--muted); font-size: 10px; letter-spacing: .16em; margin-top: 2px; }
.brand .icon-button { margin-left: auto; }
.mode-card {
    display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; margin-bottom: 25px;
    border: 1px solid #d7e0d7; border-radius: 12px; background: rgba(255,255,255,.58);
}
.mode-card strong, .mode-card small { display: block; }
.mode-card strong { font-size: 13px; }
.mode-card small { color: var(--muted); margin-top: 3px; font-size: 11px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #35a166; box-shadow: 0 0 0 4px #d8eddf; margin-top: 5px; }
.library { min-height: 180px; display: flex; flex: 1 1 58%; flex-direction: column; }
.section-heading { display: flex; justify-content: space-between; align-items: end; margin-bottom: 12px; }
.section-heading h2 { font: 600 18px/1.2 Georgia, "Songti SC", serif; margin: 4px 0 0; }
.eyebrow { color: var(--green-2); font-size: 10px; font-weight: 700; letter-spacing: .16em; }
.count-badge { min-width: 24px; height: 24px; display: grid; place-items: center; border-radius: 12px; background: var(--mint); color: var(--green); font-size: 12px; }
.drop-zone {
    display: grid; place-items: center; min-height: 126px; padding: 16px; text-align: center; cursor: pointer;
    border: 1px dashed #9eb5a4; border-radius: 14px; background: rgba(255,255,255,.48); transition: .2s ease;
}
.drop-zone:hover, .drop-zone.dragging { border-color: var(--green-2); background: #f8fbf7; transform: translateY(-1px); }
.drop-zone strong { font-size: 13px; }
.drop-zone small { color: var(--muted); font-size: 10px; margin-top: 5px; }
.upload-icon { width: 30px; height: 30px; display: grid; place-items: center; margin-bottom: 7px; border-radius: 50%; background: var(--green); color: white; }
.upload-progress { padding: 12px; margin-top: 10px; background: white; border-radius: 10px; }
.progress-meta { display: flex; justify-content: space-between; font-size: 11px; margin-bottom: 7px; }
progress { width: 100%; height: 5px; accent-color: var(--green-2); display: block; }
.inline-error { color: var(--danger); background: #faecea; padding: 9px 11px; border-radius: 9px; font-size: 12px; margin: 10px 0 0; }
.document-list { margin-top: 13px; overflow-y: auto; display: grid; gap: 7px; }
.document-item { display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; align-items: center; gap: 8px; padding: 10px; border: 1px solid transparent; border-radius: 11px; }
.document-item:hover { background: rgba(255,255,255,.7); border-color: var(--line); }
.document-item input { accent-color: var(--green); width: 15px; height: 15px; }
.document-name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; font-weight: 600; }
.document-meta { display: flex; gap: 7px; color: var(--muted); font-size: 10px; margin-top: 4px; }
.document-status { color: var(--green-2); }
.document-status.failed { color: var(--danger); }
.document-status.processing { color: var(--amber); }
.delete-document, .icon-button, .dialog-close { border: 0; background: transparent; cursor: pointer; }
.delete-document { color: #8b948e; padding: 6px; border-radius: 7px; }
.delete-document:hover { color: var(--danger); background: #faecea; }
.document-error { grid-column: 2 / -1; color: var(--danger); font-size: 10px; margin: 0; }
.empty-documents { margin: auto; text-align: center; color: var(--muted); }
.empty-documents span { font-size: 30px; color: #aeb8b0; }
.empty-documents p { margin: 8px 0 2px; font-size: 13px; color: var(--ink); }
.empty-documents small { font-size: 10px; }
.chat-history { min-height: 110px; flex: 0 1 32%; margin-top: 16px; padding-top: 15px; border-top: 1px solid var(--line); display: flex; flex-direction: column; }
.chat-session-list { min-height: 0; overflow-y: auto; display: grid; align-content: start; gap: 5px; }
.chat-session-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px; align-items: center; padding: 8px 9px; border: 1px solid transparent; border-radius: 9px; background: transparent; cursor: pointer; text-align: left; }
.chat-session-item:hover, .chat-session-item.active { background: rgba(255,255,255,.75); border-color: var(--line); }
.chat-session-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; }
.delete-chat-session { border: 0; border-radius: 6px; padding: 2px 5px; background: transparent; color: var(--muted); cursor: pointer; }
.delete-chat-session:hover { color: var(--danger); background: #faecea; }
.empty-chat-sessions { margin: auto; color: var(--muted); font-size: 10px; text-align: center; }
.sidebar-footer { padding-top: 14px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 8px; color: var(--muted); font-size: 9px; }
.text-button { border: 0; padding: 0; background: transparent; color: var(--green); cursor: pointer; font-size: 11px; }

.main-panel { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto 1fr auto; background: radial-gradient(circle at 80% 5%, #edf4eb 0, transparent 30%), var(--paper); }
.topbar { height: 88px; display: flex; align-items: center; padding: 0 34px; border-bottom: 1px solid var(--line); background: rgba(251,252,248,.84); backdrop-filter: blur(12px); }
.topbar h1 { font: 600 23px Georgia, "Songti SC", serif; margin: 3px 0 0; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 15px; }
.user-badge { display: grid; padding-left: 14px; border-left: 1px solid var(--line); font-size: 11px; }
.user-badge small { color: var(--muted); margin-top: 1px; font-size: 8px; letter-spacing: .08em; }
.logout-button { white-space: nowrap; }
.selection-summary { color: var(--muted); font-size: 12px; }
.chat-mode-control select { border: 1px solid var(--line); border-radius: 9px; padding: 8px 28px 8px 10px; background: white; color: var(--green); font-size: 11px; cursor: pointer; }
.secondary-button, .primary-button, .danger-button, .stop-button {
    border: 1px solid var(--line); border-radius: 9px; padding: 9px 13px; background: white; cursor: pointer; font-size: 12px;
}
.primary-button { background: var(--green); color: white; border-color: var(--green); }
.danger-button { background: var(--danger); color: white; border-color: var(--danger); }
.stop-button { border-color: #dcaaa6; color: var(--danger); }
kbd { margin-left: 7px; padding: 2px 5px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; color: var(--muted); font-size: 9px; }
.conversation { min-height: 0; overflow-y: auto; padding: 36px max(24px, calc((100% - 860px) / 2)); scroll-behavior: smooth; }
.welcome { min-height: 100%; display: grid; place-content: center; text-align: center; padding-bottom: 7vh; }
.welcome-mark { width: 58px; height: 58px; display: grid; place-items: center; justify-self: center; margin-bottom: 18px; border-radius: 18px 18px 18px 4px; background: var(--green); color: white; font: 28px Georgia, serif; box-shadow: var(--shadow); }
.welcome h2 { max-width: 560px; margin: 7px auto 12px; font: 500 30px/1.35 Georgia, "Songti SC", serif; }
.welcome > p:not(.eyebrow) { color: var(--muted); font-size: 13px; }
.suggestions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 20px; }
.suggestions button { border: 1px solid var(--line); border-radius: 20px; padding: 9px 13px; background: rgba(255,255,255,.7); cursor: pointer; color: #465148; font-size: 11px; }
.suggestions button:hover { border-color: #9cb4a2; color: var(--green); }
#messages { display: grid; gap: 24px; }
.message { display: grid; grid-template-columns: 38px minmax(0, 1fr); gap: 12px; animation: enter .25s ease both; }
.message.user { grid-template-columns: minmax(0, 1fr) 38px; }
.message.user .avatar { grid-column: 2; background: #dfe5df; color: #455148; }
.message.user .message-body { grid-column: 1; grid-row: 1; justify-self: end; max-width: 78%; padding: 12px 15px; border-radius: 15px 4px 15px 15px; background: #e4eee4; white-space: pre-wrap; word-break: break-word; }
.avatar { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px 10px 10px 3px; background: var(--green); color: white; font: 14px Georgia, serif; }
.message-content { min-width: 0; line-height: 1.75; font-size: 14px; overflow-wrap: anywhere; }
.message-content > :first-child { margin-top: 2px; }
.message-content > :last-child { margin-bottom: 0; }
.message-content pre { overflow-x: auto; padding: 14px; border-radius: 10px; background: #17231d; color: #e7eee9; }
.message-content code { font-family: "Cascadia Code", Consolas, monospace; font-size: .9em; }
.message-content :not(pre) > code { padding: 2px 5px; border-radius: 4px; background: #e9eee9; color: #31533f; }
.message-content table { width: 100%; border-collapse: collapse; display: block; overflow-x: auto; }
.message-content th, .message-content td { border: 1px solid var(--line); padding: 7px 9px; text-align: left; }
.message-content blockquote { margin-left: 0; padding-left: 13px; border-left: 3px solid #86a78e; color: var(--muted); }
.typing { color: var(--muted); font-size: 12px; }
.typing::after { content: "···"; display: inline-block; animation: pulse 1.1s infinite; }
.message-error { color: var(--danger); padding: 10px 12px; border-radius: 9px; background: #faecea; font-size: 12px; }
.retry-button { margin-top: 8px; border: 0; background: transparent; color: var(--danger); text-decoration: underline; cursor: pointer; }
.citations { margin-top: 17px; padding-top: 13px; border-top: 1px solid var(--line); }
.citations h3 { margin: 0 0 9px; font-size: 11px; color: var(--muted); letter-spacing: .08em; text-transform: uppercase; }
.citation-list { display: grid; gap: 7px; }
.citation-card { border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; background: rgba(255,255,255,.6); }
.citation-title { display: flex; gap: 7px; align-items: baseline; font-size: 11px; font-weight: 600; }
.citation-number { color: var(--green); }
.citation-location { color: var(--muted); font-size: 9px; font-weight: 400; }
.citation-excerpt { margin: 5px 0 0; color: var(--muted); font-size: 10px; line-height: 1.5; }
.composer-area { padding: 16px max(24px, calc((100% - 860px) / 2)) 22px; background: linear-gradient(transparent, var(--paper) 20%); }
.composer { border: 1px solid #cfd8d0; border-radius: 15px; padding: 13px 14px 10px; background: white; box-shadow: 0 10px 32px rgba(28,49,37,.1); }
.composer:focus-within { border-color: #83a48b; box-shadow: 0 10px 32px rgba(28,49,37,.1), 0 0 0 3px rgba(32,123,80,.09); }
.composer textarea { width: 100%; min-height: 1.5em; max-height: 150px; resize: none; border: 0; outline: 0; padding: 0; background: transparent; line-height: 1.5; }
.composer-footer { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 9px; color: var(--muted); font-size: 10px; }
.send-button { border: 0; border-radius: 9px; padding: 9px 13px; background: var(--green); color: white; cursor: pointer; }
.send-button:disabled { opacity: .45; cursor: not-allowed; }
dialog { width: min(480px, calc(100% - 32px)); padding: 0; border: 0; border-radius: 16px; box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(16,27,21,.45); backdrop-filter: blur(2px); }
.dialog-content { position: relative; padding: 27px; }
.dialog-content h2 { font: 500 23px Georgia, "Songti SC", serif; margin: 7px 0 13px; }
.dialog-content p { color: var(--muted); font-size: 13px; line-height: 1.7; }
.dialog-close { position: absolute; right: 15px; top: 12px; font-size: 23px; color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.mobile-only { display: none; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }
@keyframes enter { from { opacity: 0; transform: translateY(5px); } }
@keyframes pulse { 50% { opacity: .25; } }

@media (max-width: 760px) {
    body { overflow: hidden; }
    .app-shell { grid-template-columns: 1fr; }
    .mobile-only { display: inline-grid; place-items: center; }
    .sidebar { position: fixed; inset: 0 auto 0 0; width: min(350px, 88vw); transform: translateX(-102%); transition: transform .22s ease; box-shadow: var(--shadow); }
    .sidebar.open { transform: translateX(0); }
    .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(20,30,24,.36); z-index: 4; }
    .topbar { height: 72px; padding: 0 15px; gap: 10px; }
    .topbar .eyebrow, .selection-summary, kbd { display: none; }
    .chat-mode-control select { max-width: 92px; padding: 7px 5px; }
    .user-badge { display: none; }
    .topbar h1 { font-size: 19px; }
    .topbar-actions { gap: 6px; }
    .secondary-button { padding: 8px 10px; }
    .logout-button { font-size: 10px; }
    .conversation { padding: 24px 15px; }
    .welcome h2 { font-size: 24px; }
    .suggestions { display: grid; }
    .message { grid-template-columns: 31px minmax(0, 1fr); gap: 8px; }
    .avatar { width: 29px; height: 29px; }
    .message.user { grid-template-columns: minmax(0, 1fr) 31px; }
    .message.user .message-body { max-width: 88%; }
    .composer-area { padding: 10px 10px max(10px, env(safe-area-inset-bottom)); }
    .composer-footer > span { max-width: 46%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

@media (max-width: 480px) {
    .auth-screen { padding: 14px; }
    .auth-card { padding: 25px 21px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}
