:root {
    color-scheme: light;
    --page: #f1f0f7;
    --rail: #f8f7fc;
    --white: #fff;
    --ink: #23233d;
    --muted: #5d5d76;
    --border: #e4e1ef;
    --accent: #5143a8;
    --accent-strong: #3d3189;
    --selection: #ece8fa;
    --focus: #7160ca;
    --nav: #2d284b;
    --nav-ink: #f1ebff;
    --reading: 776px;
    --gutter: clamp(20px, 3.5vw, 44px);
    font: 15px/1.5 "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--page); color: var(--ink); }
h1, h2, h3, h4, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .48; }
button, a, input, select, textarea, summary { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
a { color: var(--accent); text-underline-offset: 3px; }
summary { cursor: pointer; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.primary {
    border: 1px solid var(--accent);
    border-radius: 9px;
    min-height: 42px;
    padding: 9px 15px;
    background: var(--accent);
    color: #fff;
    font-weight: 650;
}
.primary:not(:disabled):hover { background: var(--accent-strong); }
.text-button, .icon-button {
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
}
.text-button { padding: 7px 8px; }
.icon-button { display: inline-grid; place-items: center; min-width: 36px; min-height: 36px; font-size: 1.2rem; }
.text-button:hover, .icon-button:hover { background: var(--selection); color: var(--ink); }

.app-shell { min-height: 100vh; min-height: 100dvh; }
.app-notice {
    position: fixed;
    inset: 14px 14px auto;
    z-index: 5;
    max-width: 490px;
    margin: 0 auto;
    padding: 11px 16px;
    border: 1px solid #eccbbd;
    border-radius: 9px;
    background: #fff3ed;
    color: #803826;
    overflow-wrap: anywhere;
}
.brand-mark {
    width: 32px;
    height: 32px;
    display: inline-grid;
    place-items: center;
    border-radius: 9px;
    background: var(--accent);
    color: #fff;
    font: 750 11px/1 system-ui, sans-serif;
    letter-spacing: -.05em;
}
.language-switch { display: flex; gap: 2px; align-items: center; }
.language-switch a { padding: 5px 7px; border-radius: 5px; color: var(--muted); text-decoration: none; font-weight: 650; font-size: .8rem; }
.language-switch a:hover, .language-switch a[aria-current=true] { background: var(--selection); color: var(--accent-strong); }


#workspacePicker { display: grid; gap: 5px; color: var(--muted); font-size: .86rem; font-weight: 650; }
.sidebar select { min-width: 0; width: 100%; border: 1px solid var(--border); padding: 9px 10px; border-radius: 8px; background: var(--white); color: var(--ink); }

.workspace {
    --sidebar-width: 264px;
    height: 100vh;
    height: 100dvh;
    display: grid;
    grid-template-columns: 56px var(--sidebar-width) minmax(0, 1fr);
    gap: 9px;
    padding: 9px 9px 9px 0;
}
.desk-rail {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    min-height: 0;
    padding: 12px 0 9px;
    background: var(--nav);
    color: var(--nav-ink);
    border-radius: 0 18px 18px 0;
}
.rail-mark { background: #6558a9; width: 34px; height: 34px; border-radius: 10px; margin-bottom: 11px; font-size: .8rem; }
.rail-button {
    display: grid;
    place-items: center;
    width: 40px;
    min-height: 40px;
    flex: 0 0 auto;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: inherit;
}
.rail-button:hover, .rail-button[aria-expanded=true] { background: #494164; }
.rail-account { margin-top: auto; border-top: 1px solid #5b517a; }
.nav-history, .nav-compose, .nav-file, .nav-library, .nav-person, .nav-search {
    position: relative;
    display: inline-block;
    flex: none;
    width: 16px;
    height: 16px;
}
.nav-history { border: 1.5px solid currentColor; border-radius: 4px; }
.nav-history::after { content: ""; position: absolute; inset: 0 auto 0 4px; border-left: 1.5px solid currentColor; }
.nav-file { border: 1.5px solid currentColor; border-radius: 3px; width: 13px; }
.nav-file::before, .nav-file::after { content: ""; position: absolute; inset: 5px 2px auto; border-top: 1.5px solid currentColor; }
.nav-file::after { top: 9px; right: 4px; }
.nav-library { border-bottom: 1.5px solid currentColor; }
.nav-library::before, .nav-library::after { content: ""; position: absolute; top: 1px; bottom: 2px; width: 4px; border: 1.4px solid currentColor; border-radius: 1px; }
.nav-library::before { left: 2px; box-shadow: 4px 0 currentColor; }
.nav-library::after { right: 1px; transform: rotate(-16deg); transform-origin: bottom; }
.nav-compose { border: 1.5px solid currentColor; border-radius: 4px; }
.nav-compose::before, .nav-compose::after { content: ""; position: absolute; top: 6px; left: 3px; width: 7px; border-top: 1.5px solid currentColor; }
.nav-compose::after { transform: rotate(90deg); }
.nav-person::before, .nav-person::after {
    content: "";
    position: absolute;
    border: 1.5px solid currentColor;
    left: 50%;
    transform: translateX(-50%);
}
.nav-person::before { width: 7px; height: 7px; top: 0; border-radius: 50%; }
.nav-person::after { width: 14px; height: 7px; bottom: 0; border-radius: 6px 6px 2px 2px; }
.nav-search { width: 13px; height: 13px; border: 1.5px solid currentColor; border-radius: 50%; margin-right: 3px; }
.nav-search::after { content: ""; position: absolute; top: 9px; left: 9px; width: 6px; border-top: 1.5px solid currentColor; transform-origin: left; transform: rotate(45deg); }

.sidebar {
    min-height: 0;
    min-width: 0;
    background: var(--rail);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 16px 13px 10px;
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    gap: 14px;
}
.sidebar-brand { display: flex; justify-content: space-between; align-items: center; padding-inline: 6px; min-height: 36px; }
.workspace-brand { font-size: 1.27rem; font-weight: 780; letter-spacing: -.045em; }
.sidebar-commands { display: grid; gap: 6px; min-width: 0; }
.new-chat { min-height: 42px; display: flex; align-items: center; gap: 9px; border: 1px solid #dfd7f4; border-radius: 9px; padding: 8px 11px; color: var(--accent-strong); background: var(--selection); font-weight: 650; text-align: left; }
.new-chat:hover { background: #e1daf4; }
.sidebar-conversations { min-height: 0; overflow-y: auto; scrollbar-width: thin; padding: 2px 1px 5px; }
.sidebar-conversations h2 { margin: 0 0 8px; padding-inline: 7px; color: var(--ink); font-size: .79rem; font-weight: 720; }
.history-filter { display: flex; align-items: center; gap: 7px; margin: 0 1px 9px; padding: 0 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--white); color: var(--muted); }
.history-filter:focus-within { outline: 2px solid var(--focus); outline-offset: 1px; }
.history-filter input { width: 100%; min-width: 0; min-height: 34px; padding: 4px 0; border: 0; outline: 0; background: transparent; font-size: .87rem; }
.chat-history { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; }
.chat-history li { min-width: 0; }
.chat-history button { display: block; width: 100%; min-width: 0; min-height: 35px; text-align: left; padding: 7px 10px; border: 0; border-inline-start: 2px solid transparent; border-radius: 6px; background: transparent; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; font-size: .9rem; }
.chat-history button:hover { background: #f0edf8; }
.chat-history button[aria-current] { background: var(--selection); border-inline-start-color: var(--accent); color: var(--accent-strong); font-weight: 650; }
.history-empty { padding: 4px 8px; color: var(--muted); font-size: .85rem; }
.sidebar-footer { border-top: 1px solid var(--border); padding-top: 8px; display: grid; gap: 8px; }
.account { position: relative; min-width: 0; }
.account-trigger {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr) 12px;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 48px;
    padding: 6px 9px;
    border: 1px solid transparent;
    border-radius: 10px;
    background: transparent;
    text-align: left;
}
.account-trigger:hover, .account-trigger[aria-expanded=true] {
    border-color: var(--border);
    background: var(--selection);
}
.account-avatar {
    display: inline-grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 11px;
    background: #e4ddf8;
    color: var(--accent-strong);
    font-size: .8rem;
    font-weight: 750;
    letter-spacing: .025em;
}
.account-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .88rem; font-weight: 650; }
.account-chevron { width: 8px; height: 8px; border: solid var(--muted); border-width: 1px 1px 0 0; transform: rotate(-45deg); }
.account-panel {
    position: absolute;
    inset: auto auto calc(100% + 8px) 0;
    z-index: 2;
    display: grid;
    gap: 3px;
    width: min(276px, calc(100vw - 32px));
    max-height: min(420px, 65dvh);
    overflow-y: auto;
    padding: 6px;
    border: 1px solid var(--border);
    border-radius: 13px;
    background: var(--white);
    box-shadow: 0 14px 32px #20362921;
}
.account-identity { display: grid; gap: 2px; padding: 10px 10px 12px; border-bottom: 1px solid var(--border); font-weight: 650; overflow-wrap: anywhere; }
.account-role { color: var(--accent); font-size: .78rem; font-weight: 600; }
.account-action { min-height: 40px; padding: 8px 10px; border: 0; border-radius: 7px; text-align: left; background: transparent; }
.account-action:hover { background: var(--selection); }
a.account-action { display: block; color: inherit; text-decoration: none; }
.account-language { display: flex; align-items: center; justify-content: space-between; min-height: 40px; padding: 4px 10px; }
.account-logout { color: #7b4033; }
.drawer-backdrop, .mobile-menu, .drawer-close { display: none; }
.menu-icon { display: block; width: 16px; height: 12px; border-block: 1.5px solid currentColor; position: relative; }
.menu-icon::after { content: ""; position: absolute; top: 50%; width: 11px; border-top: 1.5px solid currentColor; }

.chat-main { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; background: var(--white); border: 1px solid var(--border); border-radius: 18px; overflow: hidden; }
.chat-header {
    min-width: 0;
    min-height: 57px;
    border-bottom: 1px solid var(--border);
    background: var(--white);
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 8px clamp(13px, 2.1vw, 30px);
}
.chat-heading { flex: 1; min-width: 0; display: flex; align-items: center; justify-content: space-between; gap: 10px 18px; }
.chat-heading h1 { min-width: 0; overflow: hidden; text-overflow: ellipsis; font-size: 1rem; font-weight: 730; white-space: nowrap; }
.active-document { flex: 0 1 auto; min-width: 0; max-width: min(65%, 540px); display: flex; align-items: center; gap: 7px; padding: 4px 5px 4px 9px; border: 1px solid var(--border); border-radius: 9px; background: var(--rail); }
.active-document-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); font-size: .83rem; font-weight: 630; }
.active-document select { min-width: 0; max-width: 100%; padding: 2px 4px; border: 0; background: transparent; color: var(--ink); font-size: .83rem; font-weight: 630; }
.document-version { flex-shrink: 0; padding: 2px 5px; border-radius: 4px; background: #eeebf5; color: var(--muted); font-size: .72rem; line-height: 1.4; white-space: nowrap; }
.active-document[data-draft=true] .document-version { color: var(--accent-strong); background: var(--selection); }

.chat-thread { --timeline-gap: 26px; min-height: 0; overflow: auto; overscroll-behavior: contain; scrollbar-width: thin; }
.chat-timeline { width: min(100%, calc(var(--reading) + 2 * var(--gutter))); min-height: 100%; margin-inline: auto; padding: 31px var(--gutter) 24px; display: flex; flex-direction: column; gap: var(--timeline-gap); }
.empty-chat { width: 100%; max-width: 586px; margin: auto; text-align: center; padding: 24px 0 43px; }
.empty-chat .brand-mark { width: 45px; height: 45px; margin-bottom: 17px; border-radius: 13px; font-size: 16px; background: var(--selection); color: var(--accent-strong); }
.empty-chat h2 { font: 720 clamp(1.55rem, 3vw, 2.15rem)/1.2 system-ui, sans-serif; letter-spacing: -.042em; }
.empty-chat p { max-width: 42ch; margin: 9px auto 0; color: var(--muted); }
.prompt-choices { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 21px; }
.prompt-choices button { padding: 8px 11px; border: 1px solid var(--border); background: var(--white); border-radius: 8px; color: var(--accent-strong); }
.prompt-choices button:hover { background: var(--selection); }

.chat-message { min-width: 0; overflow-wrap: anywhere; }
.chat-user { align-self: flex-end; max-width: min(84%, 600px); padding: 12px 15px; border: 1px solid #ece6fa; border-radius: 14px 14px 4px 14px; background: #f3effa; white-space: pre-wrap; }
.chat-assistant { width: 100%; display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 11px; align-items: start; scroll-margin-top: 19px; }
.chat-assistant > .brand-mark { width: 28px; height: 28px; border-radius: 8px; font-size: .65rem; margin-top: 2px; }
.reply-body { min-width: 0; }
.reply-actions { display: flex; margin-top: 11px; }
.reply-copy { display: inline-flex; align-items: center; gap: 7px; font-size: .8rem; padding: 4px 7px; min-height: 32px; }
.copy-icon { position: relative; width: 11px; height: 12px; margin: 1px 3px 0 0; border: 1.5px solid currentColor; border-radius: 3px; }
.copy-icon::after { content: ""; position: absolute; inset: -4px -4px 2px 2px; border: solid currentColor; border-width: 1.5px 1.5px 0 0; border-radius: 0 3px 0 0; }
.chat-answer { font-size: 1.01rem; line-height: 1.72; }
.chat-answer > * + * { margin-top: .8em; }
.chat-answer h2, .chat-answer h3, .chat-answer h4 { font-size: 1.02em; font-weight: 740; line-height: 1.38; }
.chat-answer ul, .chat-answer ol { padding-left: 1.45em; margin-bottom: 0; }
.chat-answer li + li { margin-top: .55em; }
.chat-answer pre { padding: 10px 12px; background: var(--rail); white-space: pre-wrap; overflow-wrap: anywhere; border-radius: 8px; }
.chat-answer strong { font-weight: 750; }
.chat-source, .chat-scope { margin-top: 9px; color: var(--muted); font-size: .83rem; }
.pending-reply { color: var(--muted); padding-top: 3px; }
.reply-details { margin-top: 12px; border: 1px solid var(--border); background: var(--white); border-radius: 9px; }
.reply-details summary { padding: 9px 12px; color: var(--accent-strong); font-size: .89rem; font-weight: 650; }
.reply-details[open] summary { border-bottom: 1px solid var(--border); }
.sources-body, .proposal-body { padding: 11px 12px; }
.chat-quote { border-left: 2px solid #c8bee8; padding: 2px 0 2px 9px; margin: 0; line-height: 1.6; font-size: .9rem; white-space: pre-wrap; }
.chat-quote + .chat-quote { margin-top: 9px; }
.quote-label { color: var(--accent-strong); font-weight: 650; }
.chat-diff + .chat-diff { margin-top: 13px; }
.proposal-item-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 6px 12px; margin-bottom: 6px; }
.chat-diff h3 { font-weight: 650; font-size: .86rem; }
.proposal-accept { color: var(--accent-strong); border: 1px solid var(--border); min-height: 36px; font-size: .84rem; font-weight: 650; }
.proposal-item-accepted { color: #175239; font-size: .84rem; font-weight: 650; }
.diff-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.diff-grid > div { border: 1px solid var(--border); padding: 8px 9px; border-radius: 7px; background: #fafbf8; min-width: 0; }
.diff-grid > div > span { color: var(--muted); font-size: .77rem; font-weight: 680; }
.diff-grid p { margin-top: 4px; font-size: .9rem; line-height: 1.6; white-space: pre-wrap; }
.diff-grid .chat-after p:empty { min-height: 1.4em; }
.chat-layout-details { color: var(--muted); font-size: .8rem; }
.diff-grid mark { background: #fbe3db; color: #703124; }
.chat-after mark { background: #dcefe3; color: #175239; }
.proposal-actions { display: flex; gap: 8px 14px; flex-wrap: wrap; align-items: center; margin-top: 11px; }
.proposal-actions .primary { font-size: .87rem; min-height: 36px; padding: 6px 12px; }
.proposal-actions a { font-size: .86rem; font-weight: 620; }
.proposal-applied { color: var(--accent-strong); }

.composer-area { position: relative; padding: 9px var(--gutter) max(13px, env(safe-area-inset-bottom)); background: var(--white); }
.chat-composer { max-width: var(--reading); margin-inline: auto; }
.composer-card {
    position: relative;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: end;
    gap: 5px 8px;
    padding: 7px 8px;
    border: 1px solid #ded8ee;
    border-radius: 16px;
    background: var(--rail);
}
.composer-card:focus-within { border-color: #9282c9; box-shadow: 0 0 0 2px #ece8fa; }
.composer-card textarea {
    width: 100%;
    min-width: 0;
    min-height: 40px;
    max-height: min(132px, 30dvh);
    field-sizing: content;
    resize: none;
    padding: 9px 2px 8px;
    border: 0;
    outline: 0;
    background: transparent;
    line-height: 1.5;
}
.composer-card textarea::placeholder { color: var(--muted); }
.composer-tool-toggle {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0;
    color: var(--accent-strong);
    background: var(--white);
}
.composer-tool-toggle:not(:disabled):hover, .composer-tool-toggle[aria-expanded=true] { background: var(--selection); border-color: #d7cef1; }
.chat-jump { position: absolute; z-index: 1; inset: -38px var(--gutter) auto auto; border: 1px solid var(--border); background: var(--white); box-shadow: 0 3px 11px #29204819; }
.nav-arrow { position: relative; display: inline-block; width: 15px; height: 16px; }
.nav-arrow::before { content: ""; position: absolute; inset: 3px auto 0 7px; border-left: 1.6px solid currentColor; }
.nav-arrow::after { content: ""; position: absolute; left: 3px; top: 2px; width: 9px; height: 9px; border: solid currentColor; border-width: 1.6px 0 0 1.6px; transform: rotate(45deg); }
.nav-arrow-down { transform: rotate(180deg); }
.tool-plus { display: grid; place-items: center; width: 16px; height: 16px; }
.tool-plus::before, .tool-plus::after { content: ""; grid-area: 1 / 1; width: 15px; height: 1.5px; border-radius: 1px; background: currentColor; }
.tool-plus::after { transform: rotate(90deg); }
.composer-tool-menu {
    position: absolute;
    z-index: 2;
    inset-block-end: calc(100% + 6px);
    inset-inline-start: 11px;
    width: max-content;
    min-width: 192px;
    max-width: calc(100vw - 44px);
    display: grid;
    gap: 2px;
    padding: 5px;
    border: 1px solid var(--border);
    border-radius: 13px;
    background: var(--white);
    box-shadow: 0 8px 28px #29204826, 0 2px 5px #2920480b;
}
.composer-tool-menu button {
    display: grid;
    grid-template-columns: 20px 1fr;
    gap: 10px;
    align-items: center;
    min-height: 42px;
    padding: 7px 11px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--ink);
    font-size: .91rem;
    font-weight: 580;
    text-align: start;
}
.composer-tool-menu button:hover, .composer-tool-menu button:focus-visible { background: var(--rail); color: var(--accent-strong); }
.composer-tool-menu button:focus-visible { outline-offset: -2px; }
.clip-icon { justify-self: center; width: 8px; height: 16px; border: 1.5px solid currentColor; border-radius: 5px; transform: rotate(35deg); }
.form-icon { position: relative; justify-self: center; width: 14px; height: 17px; border: 1.5px solid currentColor; border-radius: 3px; }
.form-icon::before, .form-icon::after { content: ""; position: absolute; inset: 5px 2.5px auto; border-top: 1.5px solid currentColor; }
.form-icon::after { top: 9px; right: 4px; }
.chat-send { width: 42px; min-height: 40px; padding: 0; border-radius: 10px; display: grid; place-items: center; }
.chat-send:disabled { color: #635889; background: #e8e1f4; border-color: transparent; opacity: 1; }
.attachment-pill { grid-column: 1 / -1; max-width: 100%; width: fit-content; padding: 2px 4px 2px 9px; margin-bottom: 4px; display: flex; align-items: center; gap: 7px; border: 1px solid var(--border); border-radius: 7px; background: var(--rail); color: var(--accent-strong); font-size: .84rem; }
.attachment-pill #chatAttachmentName { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.attachment-pill button { flex-shrink: 0; min-width: 28px; min-height: 28px; }
.composer-meta { display: grid; justify-items: center; gap: 4px; margin-top: 6px; color: var(--muted); font-size: .74rem; text-align: center; }
.chat-status { min-width: 0; overflow-wrap: anywhere; }
.chat-error { color: #8a3525; }


.unlock-dialog {
    width: min(420px, calc(100% - 32px));
    padding: 20px;
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--ink);
    background: var(--white);
}
.unlock-dialog::backdrop { background: #182a2299; }
.unlock-dialog form { display: grid; gap: 10px; }
.unlock-dialog h2 { font-size: 1.05rem; }
.unlock-dialog #chatUnlockFile { color: var(--muted); overflow-wrap: anywhere; }
.unlock-dialog label { display: grid; gap: 4px; }
.unlock-dialog input { width: 100%; padding: 8px; border: 1px solid var(--border); border-radius: 6px; }
.unlock-note { color: var(--muted); font-size: .85rem; }
.unlock-actions { display: flex; justify-content: flex-end; gap: 8px; }

.preview-trigger {
    flex: 0 0 auto;
    min-height: 32px;
    padding: 4px 9px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--white);
    color: var(--accent-strong);
    font-size: .8rem;
    font-weight: 650;
    white-space: nowrap;
}
.preview-trigger:hover, .preview-trigger[aria-expanded=true] { background: var(--selection); }
.preview-source {
    display: block;
    width: fit-content;
    margin-top: 6px;
    padding: 2px 0;
    border: 0;
    background: transparent;
    color: var(--accent-strong);
    font-size: .8rem;
    text-align: left;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.document-preview {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    min-width: 0;
    min-height: 0;
    background: #f1eff7;
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
}
.preview-header {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--white);
}
.preview-toolbar { position: relative; display: flex; align-items: center; gap: 8px; min-width: 0; }
.preview-toolbar h2 {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: .94rem;
    font-weight: 700;
}
.preview-actions { display: flex; flex: none; align-items: center; gap: 4px; }
.preview-icon-button, .preview-version-toggle {
    display: inline-flex;
    min-height: 36px;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--white);
    color: var(--muted);
    text-decoration: none;
}
.preview-icon-button { width: 36px; }
.preview-icon-button:hover, .preview-version-toggle:hover, .preview-version-toggle[aria-expanded=true] {
    background: var(--selection);
    color: var(--accent-strong);
}
.preview-version-toggle {
    flex: 0 1 auto;
    max-width: 43%;
    min-width: 0;
    gap: 8px;
    padding-inline: 10px;
    color: var(--accent-strong);
    font-size: .8rem;
    font-weight: 650;
}
.preview-version-toggle :first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview-chevron {
    flex: none;
    width: 6px;
    height: 6px;
    margin-block-start: -3px;
    border: solid currentColor;
    border-width: 0 1.5px 1.5px 0;
    transform: rotate(45deg);
}
.preview-version-toggle[aria-expanded=true] .preview-chevron { transform: rotate(225deg); margin-block-start: 3px; }
.preview-download-icon, .preview-close-icon { position: relative; display: grid; place-items: center; width: 18px; height: 18px; }
.preview-download-icon .nav-arrow { margin-block-start: -4px; transform: scale(.72) rotate(180deg); }
.preview-download-icon::after {
    content: "";
    position: absolute;
    inset: auto 2px 1px;
    height: 5px;
    border: solid currentColor;
    border-width: 0 1.5px 1.5px;
    border-radius: 0 0 3px 3px;
}
.preview-close-icon::before, .preview-close-icon::after {
    content: "";
    grid-area: 1 / 1;
    width: 15px;
    height: 1.5px;
    border-radius: 2px;
    background: currentColor;
    transform: rotate(45deg);
}
.preview-close-icon::after { transform: rotate(-45deg); }
.preview-version-menu {
    position: absolute;
    z-index: 2;
    inset-block-start: calc(100% + 6px);
    inset-inline-end: 0;
    width: min(320px, 100%);
    max-height: min(360px, 54dvh);
    overflow: auto;
    overscroll-behavior: contain;
    padding: 5px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--white);
    box-shadow: 0 10px 28px #29204826;
}
.preview-version-group + .preview-version-group { margin-top: 4px; padding-top: 4px; border-top: 1px solid var(--border); }
.preview-version-family { overflow-wrap: anywhere; padding: 6px 9px; color: var(--muted); font-size: .76rem; font-weight: 650; }
.preview-version-option {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 16px;
    align-items: center;
    gap: 8px;
    width: 100%;
    min-height: 36px;
    padding: 7px 9px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    text-align: start;
    overflow-wrap: anywhere;
    font-size: .84rem;
}
.preview-version-option[aria-checked=true] { background: var(--selection); color: var(--accent-strong); }
.preview-version-option:hover { background: var(--page); }
.preview-version-option:focus-visible { outline-offset: -2px; }
.preview-version-option small { display: block; margin-top: 2px; color: var(--muted); font-size: .72rem; }
.preview-version-check { visibility: hidden; width: 7px; height: 11px; border: solid currentColor; border-width: 0 1.7px 1.7px 0; transform: rotate(45deg); }
.preview-version-option[aria-checked=true] .preview-version-check { visibility: visible; }
.preview-lifecycle { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 6px; font-size: .85rem; }
.preview-lifecycle p { margin: 0; color: var(--muted); }
.preview-lifecycle button, .preview-lifecycle a { font-size: inherit; }
.preview-lifecycle > :is(button, a) {
    padding: 4px 9px;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: var(--rail);
    color: var(--accent-strong);
    text-decoration: none;
}
.preview-lifecycle > :is(button, a):hover { background: var(--selection); }
.preview-lifecycle form { display: grid; gap: 8px; flex-basis: 100%; padding: 10px; border: 1px solid var(--border); border-radius: 8px; }
.preview-lifecycle input[type="file"] { min-width: 0; max-width: 100%; }
.preview-lifecycle form button { justify-self: start; }
.preview-lifecycle .preview-confirm { display: flex; gap: 8px; align-items: baseline; }
.preview-lifecycle #previewLifecycleNotice { flex-basis: 100%; }
.preview-body { min-width: 0; overflow: auto; overflow-anchor: none; overscroll-behavior: contain; scrollbar-width: thin; padding: clamp(10px, 2.4vw, 24px); }
.preview-body:focus-visible { outline-offset: -3px; }
.preview-sheet, .preview-paper { width: min(100%, 720px); margin-inline: auto; background: var(--white); box-shadow: 0 2px 12px #263c2922; }
.preview-pages { display: grid; gap: clamp(12px, 2vw, 20px); }
.preview-sheet { display: grid; place-items: center; }
.preview-page { display: block; width: 100%; height: auto; }
.preview-sheet-status { text-align: center; padding: 12px; }
.preview-paper { padding: clamp(16px, 2.5vw, 30px); }
.preview-paper p, .preview-paper h3 { margin: 0 0 .8em; white-space: pre-wrap; overflow-wrap: anywhere; }
.preview-paper p { font-size: .92rem; line-height: 1.64; }
.preview-paper h3 { margin-top: 1em; font-size: .98rem; }
.preview-paper :first-child { margin-top: 0; }
.preview-paper :last-child { margin-bottom: 0; }
.preview-highlight { background: #fff1bc; outline: 4px solid #fff1bc; border-radius: 2px; }
.preview-notice { padding: 7px 0; color: var(--muted); font-size: .86rem; }
.preview-position {
    padding: 8px 10px;
    border-top: 1px solid var(--border);
    background: var(--page);
    color: var(--muted);
    text-align: center;
    font-size: .82rem;
}

@media (min-width: 831px) {
    .workspace[data-sidebar-collapsed=true] { grid-template-columns: 56px minmax(0, 1fr); }
    .workspace[data-sidebar-collapsed=true] .sidebar { display: none; }
}

@media (min-width: 1051px) {
    .workspace:has(.document-preview:not([hidden])) { --sidebar-width: 219px; grid-template-columns: 56px var(--sidebar-width) minmax(0, 1fr) clamp(340px, 37vw, 700px); }
    .workspace[data-sidebar-collapsed=true]:has(.document-preview:not([hidden])) { grid-template-columns: 56px minmax(0, 1fr) clamp(340px, 37vw, 700px); }
    .workspace:has(.document-preview:not([hidden])) .chat-heading { flex-wrap: wrap; gap: 4px 10px; }
    .workspace:has(.document-preview:not([hidden])) .active-document { max-width: 100%; }
}

@media (max-width: 1050px) {
    .document-preview { position: fixed; inset: 0; z-index: 4; border: 0; border-radius: 0; }
    .preview-icon-button { width: 44px; }
    .preview-icon-button, .preview-version-toggle, .preview-version-option { min-height: 44px; }
}

@media (max-width: 830px) {
    .workspace { display: block; padding: 0; }
    .desk-rail { display: none; }
    .chat-main { height: 100%; border: 0; border-radius: 0; }
    .sidebar { display: none; position: fixed; top: 0; bottom: 0; left: 0; z-index: 3; width: min(86vw, 300px); border-radius: 0 18px 18px 0; }
    .sidebar[data-open=true] { display: grid; }
    .drawer-backdrop { display: block; position: fixed; inset: 0; z-index: 2; border: 0; background: #201b3d68; }
    .drawer-close, .mobile-menu { display: inline-grid; min-width: 44px; min-height: 44px; }
    .chat-header { padding-left: 8px; }
}

@media (max-width: 550px) {
    .chat-heading { align-items: flex-start; flex-direction: column; gap: 3px; }
    .chat-heading h1 { max-width: 100%; font-size: .94rem; }
    .chat-header { min-height: 54px; gap: 5px; }
    .active-document { max-width: 100%; padding: 3px 4px 3px 7px; gap: 5px; }
    .active-document-name { font-size: .76rem; }
    .document-version { font-size: .68rem; }
    .preview-trigger { padding-inline: 7px; font-size: .73rem; }
    .chat-thread { --timeline-gap: 20px; }
    .chat-timeline { padding-top: 18px; }
    .chat-assistant { grid-template-columns: 23px minmax(0, 1fr); gap: 9px; }
    .chat-assistant > .brand-mark { width: 23px; height: 23px; border-radius: 6px; font-size: .57rem; }
    .chat-answer { font-size: .96rem; }
    .diff-grid { grid-template-columns: minmax(0, 1fr); }
    .composer-area { padding-inline: 12px; }
    .composer-card { padding-inline: 6px; gap: 4px; }
    .composer-card textarea { font-size: 16px; }
    .chat-send { width: 44px; min-height: 44px; }
    .chat-jump { inset-inline-end: 12px; }
}

.template-library {
    position: fixed;
    inset: 0;
    margin: auto;
    width: min(640px, calc(100% - 24px));
    height: fit-content;
    max-height: min(720px, calc(100dvh - 24px));
    padding: 0;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 18px;
    color: var(--ink);
    background: var(--white);
    box-shadow: 0 18px 54px #12282036;
}
.template-library[open] { display: flex; flex-direction: column; }
.template-library::backdrop { background: #192c2466; }
.template-header { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 18px 11px 22px; border-bottom: 1px solid var(--border); }
.template-header h2 { font-size: 1.12rem; font-weight: 720; }
.template-header h2:focus { outline: 0; }
.template-header .icon-button { min-width: 38px; min-height: 38px; font-size: 1.35rem; line-height: 1; }
.template-notice { flex: none; padding: 12px 22px; border-bottom: 1px solid var(--border); color: var(--muted); font-size: .85rem; }
.template-notice.chat-error { color: #8a3525; }
.template-body { min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 18px 22px 22px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; align-content: start; }
.template-body h3 { font-size: 1rem; }
.template-filter, .template-form { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.template-search { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 8px; }
.template-filter-fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.template-body label { display: grid; gap: 5px; font-size: .83rem; font-weight: 600; color: var(--muted); min-width: 0; }
.template-body input, .template-body select, .template-body textarea {
    min-width: 0;
    width: 100%;
    min-height: 42px;
    padding: 8px 10px;
    border: 1px solid #d3ded4;
    border-radius: 8px;
    background: var(--white);
    color: var(--ink);
    font-weight: 450;
}
.template-body input[type=search] { font-size: .94rem; }
.template-body select {
    appearance: none;
    padding-inline-end: 29px;
    background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
    background-position: right 16px center, right 12px center;
    background-size: 4px 4px;
    background-repeat: no-repeat;
    text-overflow: ellipsis;
}
.template-body textarea { resize: vertical; }
.template-body > .text-button { justify-self: start; }
.template-body .primary { font-size: .88rem; }
.template-actions { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; }
.template-actions:empty { display: none; }
.template-actions a { text-decoration: none; }
.template-management { width: min(100%, 1240px); margin-inline: auto; padding: clamp(14px, 3vw, 36px); }
.template-management-header { margin-bottom: 18px; }
.template-management-header h1 { font-size: clamp(1.45rem, 3vw, 2.1rem); margin-block: 10px 2px; }
.template-management-header p { color: var(--muted); overflow-wrap: anywhere; }
.template-management-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-items: start; }
.template-management-card { min-width: 0; background: var(--white); border: 1px solid var(--border); border-radius: 16px; }
.template-management-card > .template-body { padding: clamp(14px, 2.5vw, 24px); }
.template-management .document-preview { position: static; height: clamp(360px, 70dvh, 900px); border: 1px solid var(--border); border-radius: 16px; }
@media (min-width: 1051px) {
    .template-management-layout:has(.document-preview:not([hidden])) { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
    .template-management .document-preview { position: sticky; top: 16px; }
}
.template-results { display: grid; gap: 8px; list-style: none; margin: 0; padding: 0; }
.template-result { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; overflow-wrap: anywhere; }
.template-result:focus-within, .template-result:hover { background: #f8faf6; border-color: #cbdacf; }
.template-link { padding: 0; background: transparent; border: 0; text-align: left; color: var(--accent-strong); font-weight: 650; }
.template-link:hover { text-decoration: underline; }
.template-meta { color: var(--muted); font-size: .81rem; }
.template-description { margin-top: 5px; font-size: .9rem; }
.template-detail { display: grid; gap: 4px; overflow-wrap: anywhere; }
.template-empty {
    display: grid;
    justify-items: center;
    gap: 9px;
    padding: 24px 12px;
    border: 1px solid var(--border);
    border-radius: 11px;
    background: var(--rail);
    color: var(--muted);
    font-size: .87rem;
    text-align: center;
}
.template-empty-icon { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; background: var(--selection); color: var(--accent-strong); }

@media(max-width: 550px) {
    .composer-tool-toggle { width: 44px; height: 44px; }
    .composer-tool-menu { inset-inline-start: 9px; }
    .composer-tool-menu button { min-height: 44px; }
    .template-library { border-radius: 14px; }
    .template-header { padding: 8px 10px 8px 15px; }
    .template-header .icon-button { min-width: 44px; min-height: 44px; }
    .template-notice, .template-body { padding-inline: 14px; }
    .template-body { padding-block: 12px 16px; }
    .template-filter-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .template-filter-fields > :last-child { grid-column: 1 / -1; }
    .template-body :is(input, select, textarea, input[type=search]) { font-size: 16px; }
}
.chat-template-suggestions { display: grid; gap: 7px; margin-block: 10px; }
.chat-word-file { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-block: 10px; padding: 9px 12px; border: 1px solid var(--border); border-radius: 10px; }
.chat-word-file strong { flex: 1 1 180px; min-width: 0; overflow-wrap: anywhere; }
.chat-word-file a { text-decoration: none; }
.delegation-panel { display: flex; justify-content: space-between; align-items: start; gap: 10px; max-width: var(--reading); margin: 0 auto 8px; border: 1px solid var(--border); border-radius: 12px; padding: 9px 12px; background: var(--white); }
.delegation-panel div { min-width: 0; max-height: min(160px, 26dvh); overflow: auto; overflow-wrap: anywhere; }
.delegation-panel p { color: var(--muted); font-size: .84rem; }
.delegation-panel button { flex: none; }
.chat-template-suggestions button { justify-self: start; padding: 6px 9px; border: 1px solid var(--border); border-radius: 7px; }
.corpus-dialog {
    width: min(840px, calc(100% - 28px));
    max-height: min(780px, calc(100dvh - 28px));
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: #f8faf6;
    color: var(--ink);
    box-shadow: 0 24px 68px #14251d36;
}
.corpus-dialog[open] { display: grid; grid-template-rows: auto auto minmax(0, 1fr); }
.corpus-dialog::backdrop { background: #182c245c; }
.corpus-header { grid-row: 1; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 13px 20px; border-bottom: 1px solid var(--border); background: var(--white); }
.corpus-header h2 { font-size: 1.25rem; letter-spacing: -.025em; }
.corpus-body { grid-row: 3; min-height: 0; min-width: 0; overflow: auto; padding: 17px 20px 20px; display: grid; align-content: start; gap: 15px; }
@media (max-width: 550px) {
    .corpus-header, .corpus-body { padding-left: 12px; padding-right: 12px; }
}
