:root {
    --background: #f4f6f3;
    --surface: #ffffff;
    --surface-soft: #f8faf7;
    --border: #dfe5dc;
    --border-strong: #cbd5c8;
    --text: #1d291f;
    --muted: #6d786f;
    --primary: #287a4b;
    --primary-dark: #1f633d;
    --primary-soft: #e9f5ed;
    --danger: #b84444;
    --danger-soft: #fff0f0;
    --shadow: 0 16px 36px rgba(36, 57, 42, 0.08);
    font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
    color: var(--text);
    background: var(--background);
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    min-width: 320px;
    height: 100%;
    margin: 0;
}

body.drawer-open {
    overflow: hidden;
}

button,
input,
textarea,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.48;
}

.app-shell {
    display: grid;
    grid-template-columns: clamp(220px, 18vw, 280px) minmax(0, 1fr);
    width: 100%;
    height: 100vh;
    overflow: hidden;
}

.sidebar,
.chat-panel {
    min-width: 0;
    min-height: 0;
    height: 100%;
}

.sidebar {
    background: var(--surface-soft);
}

.sidebar {
    display: flex;
    flex-direction: column;
    padding: clamp(16px, 1.6vw, 22px) clamp(12px, 1.2vw, 16px) 16px;
    overflow: hidden;
    border-right: 1px solid var(--border);
}

.brand {
    display: flex;
    align-items: center;
    gap: 11px;
    margin-bottom: 22px;
}

.brand-mark {
    display: grid;
    width: 40px;
    height: 40px;
    place-items: center;
    border-radius: 13px;
    color: #fff;
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0.08em;
    background: linear-gradient(145deg, #348d5a, #1f633d);
    box-shadow: 0 7px 18px rgba(40, 122, 75, 0.22);
}

.brand strong,
.brand span {
    display: block;
}

.brand strong {
    font-size: 15px;
}

.brand span {
    margin-top: 3px;
    color: var(--muted);
    font-size: 12px;
}

.primary-button,
.secondary-button,
.danger-ghost-button,
.tool-button,
.token-input-row button {
    min-height: 38px;
    padding: 0 15px;
    border: 1px solid transparent;
    border-radius: 10px;
    font-weight: 650;
    transition: 0.16s ease;
}

.primary-button,
.token-input-row button {
    color: #fff;
    background: var(--primary);
}

.primary-button:hover:not(:disabled),
.token-input-row button:hover {
    background: var(--primary-dark);
}

.secondary-button,
.tool-button {
    color: var(--text);
    border-color: var(--border-strong);
    background: var(--surface);
}

.secondary-button:hover:not(:disabled),
.tool-button:hover:not(:disabled) {
    border-color: #9fb2a3;
    background: #f5f9f5;
}

.danger-ghost-button {
    color: var(--danger);
    border-color: #efcccc;
    background: var(--danger-soft);
}

.wide-button {
    width: 100%;
}

.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 36px;
    margin-top: 16px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.04em;
}

.icon-button,
.text-button {
    padding: 4px 6px;
    border: 0;
    color: var(--muted);
    background: transparent;
}

.icon-button {
    font-size: 18px;
}

.session-list {
    flex: 1;
    min-height: 100px;
    overflow-y: scroll;
    scrollbar-gutter: stable;
}

.session-row {
    position: relative;
    width: 100%;
    margin-bottom: 5px;
    border: 1px solid transparent;
    border-radius: 11px;
}

.session-item {
    width: 100%;
    min-height: 58px;
    padding: 11px 42px 11px 12px;
    border: 0;
    border-radius: 10px;
    color: var(--text);
    text-align: left;
    background: transparent;
}

.session-row:hover {
    background: #edf2ec;
}

.session-row.active {
    border-color: #c6dfcc;
    background: var(--primary-soft);
}

.session-item strong,
.session-item span {
    display: block;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.session-item strong {
    font-size: 13px;
}

.session-item span {
    margin-top: 5px;
    color: var(--muted);
    font-size: 11px;
}

.session-more-button {
    position: absolute;
    top: 50%;
    right: 7px;
    display: grid;
    width: 30px;
    height: 30px;
    padding: 0;
    place-items: center;
    border: 0;
    border-radius: 8px;
    color: var(--muted);
    font-size: 12px;
    letter-spacing: -1px;
    background: transparent;
    opacity: 0.48;
    transform: translateY(-50%);
    transition: 0.15s ease;
}

.session-row:hover .session-more-button,
.session-row.active .session-more-button,
.session-more-button:focus-visible {
    color: var(--text);
    background: rgba(255, 255, 255, 0.72);
    opacity: 1;
}

.session-context-menu {
    position: fixed;
    z-index: 30;
    display: grid;
    min-width: 132px;
    padding: 6px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    box-shadow: 0 12px 30px rgba(36, 57, 42, 0.18);
}

.session-context-menu button {
    min-height: 34px;
    padding: 0 10px;
    border: 0;
    border-radius: 7px;
    color: var(--text);
    text-align: left;
    background: transparent;
}

.session-context-menu button:hover,
.session-context-menu button:focus-visible {
    outline: none;
    background: #edf2ec;
}

.session-context-menu button.danger {
    color: var(--danger);
}

.session-context-menu button.danger:hover,
.session-context-menu button.danger:focus-visible {
    background: var(--danger-soft);
}

.account-area {
    position: relative;
    flex: none;
}

.token-editor {
    padding: 13px;
    border: 1px solid var(--border);
    border-radius: 13px;
    background: var(--surface);
    box-shadow: 0 8px 24px rgba(36, 57, 42, 0.08);
}

.account-menu {
    display: grid;
    gap: 5px;
    margin: -5px -5px 10px;
}

.account-menu button,
.account-menu a {
    display: flex;
    min-height: 52px;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 10px;
    border: 0;
    border-radius: 9px;
    color: var(--text);
    text-align: left;
    text-decoration: none;
    background: transparent;
}

.account-menu button:hover,
.account-menu button:focus-visible,
.account-menu a:hover,
.account-menu a:focus-visible {
    outline: none;
    background: var(--primary-soft);
}

.account-menu button > span:first-child,
.account-menu a > span:first-child {
    min-width: 0;
}

.account-menu strong {
    display: block;
    font-size: 12px;
}

.account-menu small,
.token-editor .account-menu small {
    display: block;
    margin: 3px 0 0;
    color: var(--muted);
    font-size: 10px;
    line-height: 1.4;
}

.account-menu button > span:last-child,
.account-menu a > span:last-child {
    color: var(--muted);
    font-size: 22px;
}

.account-menu-divider {
    height: 1px;
    margin: 0 -2px 11px;
    background: var(--border);
}

.token-editor label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 650;
}

.account-button {
    display: grid;
    grid-template-columns: 36px minmax(0, 1fr) 18px;
    align-items: center;
    gap: 10px;
    width: clamp(176px, 16vw, 210px);
    min-height: 56px;
    padding: 9px 10px;
    border: 1px solid var(--border);
    border-radius: 13px;
    color: var(--text);
    text-align: left;
    background: var(--surface);
    transition: 0.16s ease;
}

.account-popover {
    position: absolute;
    top: calc(100% + 9px);
    right: 0;
    z-index: 30;
    width: min(340px, calc(100vw - 28px));
}

.account-button:hover,
.account-button[aria-expanded="true"] {
    border-color: #b8c9bb;
    background: #f5f9f5;
}

.account-avatar {
    display: grid;
    width: 36px;
    height: 36px;
    place-items: center;
    border-radius: 11px;
    color: var(--muted);
    background: #edf1ed;
}

.account-avatar svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.8;
}

.account-button.configured .account-avatar {
    color: #fff;
    background: var(--primary);
}

.account-copy {
    min-width: 0;
}

.account-copy strong,
.account-status {
    display: flex;
    align-items: center;
}

.account-copy strong {
    margin-bottom: 4px;
    font-size: 12px;
}

.account-status {
    gap: 7px;
    color: var(--muted);
    font-size: 10px;
}

.account-chevron {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: var(--muted);
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 2;
    transition: transform 0.16s ease;
}

.account-button[aria-expanded="true"] .account-chevron {
    transform: rotate(180deg);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #a8aea9;
}

.status-dot.connected {
    background: #38a463;
    box-shadow: 0 0 0 4px #e4f5e9;
}

.token-input-row {
    display: flex;
    gap: 6px;
}

.token-input-row input {
    min-width: 0;
    flex: 1;
}

.token-input-row button {
    min-height: 34px;
    padding: 0 10px;
}

.token-editor small {
    display: block;
    margin-top: 7px;
    color: #899189;
    font-size: 10px;
    line-height: 1.45;
}

input,
textarea,
select {
    width: 100%;
    border: 1px solid var(--border-strong);
    border-radius: 9px;
    color: var(--text);
    outline: none;
    background: var(--surface);
}

input,
select {
    min-height: 36px;
    padding: 0 10px;
}

textarea {
    padding: 13px 14px;
    line-height: 1.55;
    resize: none;
}

input:focus,
textarea:focus,
select:focus {
    border-color: #74a986;
    box-shadow: 0 0 0 3px rgba(40, 122, 75, 0.1);
}

.chat-panel {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    overflow: hidden;
    background: var(--surface);
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 72px;
    gap: 16px;
    padding: 14px clamp(16px, 2.4vw, 32px);
    border-bottom: 1px solid var(--border);
}

.conversation-heading {
    flex: 1;
    min-width: 0;
}

.conversation-heading h1 {
    max-width: min(100%, 720px);
    margin: 0;
    overflow: hidden;
    font-size: 18px;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.composer-actions,
.composer-tools {
    display: flex;
    align-items: center;
    gap: 8px;
}

.composer-tools {
    min-width: 0;
    flex: 1 1 520px;
    flex-wrap: wrap;
}

.composer-actions {
    flex: 0 0 auto;
}

.message-list {
    min-height: 0;
    padding: clamp(18px, 3vw, 32px)
        max(clamp(16px, 3vw, 40px), calc((100% - 900px) / 2));
    overflow-y: scroll;
    scrollbar-gutter: stable;
    scroll-behavior: smooth;
}

.welcome-card {
    max-width: 650px;
    margin: 9vh auto 0;
    padding: 30px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: linear-gradient(145deg, #fff, #f6faf6);
    box-shadow: var(--shadow);
}

.eyebrow {
    color: var(--primary);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.13em;
}

.welcome-card h2 {
    margin: 10px 0 8px;
    font-size: 27px;
}

.welcome-card p {
    margin: 0;
    color: var(--muted);
    line-height: 1.65;
}

.suggestion-list {
    display: grid;
    gap: 8px;
    margin-top: 22px;
}

.suggestion-list button {
    padding: 11px 13px;
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    text-align: left;
    background: rgba(255, 255, 255, 0.82);
}

.suggestion-list button:hover {
    border-color: #a9c7b1;
    background: var(--primary-soft);
}

.message-row {
    display: flex;
    margin-bottom: 22px;
}

.message-row > * {
    min-width: 0;
}

.message-row.user {
    justify-content: flex-end;
}

.message-bubble {
    max-width: min(82%, 760px);
    padding: 13px 16px;
    border-radius: 16px;
    line-height: 1.72;
    white-space: pre-wrap;
    word-break: break-word;
}

.message-row.user .message-bubble {
    color: #fff;
    border-bottom-right-radius: 5px;
    background: var(--primary);
}

.message-row.assistant .message-bubble {
    border: 1px solid var(--border);
    border-bottom-left-radius: 5px;
    background: var(--surface-soft);
}

.message-footer {
    display: flex;
    min-height: 24px;
    align-items: center;
    gap: 8px;
    margin-top: 5px;
}

.message-row.user .message-footer {
    justify-content: flex-end;
}

.message-footer .message-meta {
    margin-top: 0;
}

.message-copy-button {
    min-height: 0;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 6px;
    border: 0;
    border-radius: 6px;
    color: var(--muted);
    font-size: 10px;
    background: transparent;
    opacity: 0;
    transition: color 0.16s ease, background 0.16s ease, opacity 0.16s ease;
}

.message-copy-button svg {
    width: 13px;
    height: 13px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.8;
}

.message-row:hover .message-copy-button,
.message-copy-button:focus-visible,
.message-copy-button.copied {
    opacity: 1;
}

.message-copy-button:hover,
.message-copy-button.copied {
    color: var(--primary);
    background: var(--primary-soft);
}

.message-edit-button:hover {
    color: var(--primary-dark);
    background: var(--primary-soft);
}

.message-remember-button:hover {
    color: var(--primary-dark);
}

.message-copy-button:disabled {
    cursor: default;
}

.clipboard-fallback {
    position: fixed;
    top: -1000px;
    left: -1000px;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.message-task {
    max-width: min(82%, 760px);
}

.message-task-bubble {
    max-width: 100%;
}

.message-task.thinking {
    width: max-content;
    min-width: min(180px, 100%);
}

.message-task-bubble.thinking {
    display: flex;
    width: 100%;
    min-width: 0;
    align-items: center;
    white-space: nowrap;
}

.message-task-status-text {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.message-task-bubble.failed,
.message-task-bubble.cancelled {
    border-color: #efcccc;
    color: var(--danger);
    background: var(--danger-soft);
}

.message-task-actions {
    display: flex;
    align-items: center;
    gap: 9px;
    margin: 7px 0 0 4px;
}

.message-task-actions button {
    min-height: 0;
    padding: 4px 8px;
    border: 0;
    border-radius: 7px;
    font-size: 11px;
    background: transparent;
}

.message-task-confirm {
    color: var(--primary);
    font-weight: 700;
}

.message-task-stop {
    color: var(--muted);
}

.message-task-confirm:hover {
    background: var(--primary-soft);
}

.message-task-stop:hover {
    color: var(--danger);
    background: var(--danger-soft);
}

.message-task-thinking-dots {
    display: inline-flex;
    flex: none;
    align-items: center;
    gap: 3px;
    margin-left: 6px;
}

.message-task-thinking-dots i {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--primary);
    animation: message-task-thinking 1.2s infinite ease-in-out;
}

.message-task-thinking-dots i:nth-child(2) {
    animation-delay: 0.15s;
}

.message-task-thinking-dots i:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes message-task-thinking {
    0%,
    60%,
    100% {
        opacity: 0.28;
        transform: translateY(0);
    }

    30% {
        opacity: 1;
        transform: translateY(-2px);
    }
}

.message-file-result {
    width: min(100%, 430px);
    margin-top: 14px;
}

.message-attachments {
    width: min(100%, 430px);
    margin-left: auto;
}

.message-attachments .message-file-result {
    margin-top: 8px;
}

.message-attachments .message-file-card {
    margin-top: 0;
}

.message-image-preview-button {
    width: 100%;
    display: block;
    overflow: hidden;
    padding: 0;
    border: 1px solid #c9ddcf;
    border-radius: 14px;
    background: #edf6f0;
}

.message-image-preview-button:hover {
    border-color: var(--primary);
    box-shadow: 0 9px 22px rgba(42, 132, 83, 0.14);
}

.message-image-preview {
    width: 100%;
    max-height: 520px;
    display: block;
    object-fit: contain;
}

.image-preview-open {
    overflow: hidden;
}

.image-preview-modal {
    position: fixed;
    inset: 0;
    z-index: 55;
    display: grid;
    padding: clamp(12px, 3vw, 32px);
    place-items: center;
    background: rgba(8, 14, 10, 0.84);
    backdrop-filter: blur(4px);
}

.image-preview-dialog {
    width: min(1180px, 96vw);
    max-height: 94vh;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 16px;
    background: #172119;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.38);
}

.image-preview-header {
    display: flex;
    min-width: 0;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 14px 12px 18px;
    color: #fff;
    background: rgba(255, 255, 255, 0.06);
}

.image-preview-header h2 {
    min-width: 0;
    margin: 0;
    overflow: hidden;
    font-size: 14px;
    font-weight: 650;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.image-preview-actions {
    display: flex;
    flex: none;
    align-items: center;
    gap: 8px;
}

.image-preview-actions button {
    min-height: 34px;
    padding: 7px 11px;
    border: 1px solid rgba(255, 255, 255, 0.24);
    border-radius: 9px;
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
}

.image-preview-actions button:hover {
    border-color: rgba(255, 255, 255, 0.48);
    background: rgba(255, 255, 255, 0.14);
}

.image-preview-actions .image-preview-close {
    width: 34px;
    padding: 0;
    font-size: 22px;
    line-height: 1;
}

.image-preview-stage {
    position: relative;
    min-height: min(68vh, 680px);
    display: grid;
    overflow: auto;
    padding: 16px;
    place-items: center;
    color: rgba(255, 255, 255, 0.7);
}

.image-preview-stage img {
    max-width: 100%;
    max-height: calc(94vh - 90px);
    display: none;
    object-fit: contain;
}

.image-preview-stage img.loaded {
    display: block;
}

.message-file-card {
    width: 100%;
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    margin-top: 8px;
    padding: 12px;
    border: 1px solid #c9ddcf;
    border-radius: 12px;
    color: var(--text);
    text-align: left;
    background: #fff;
}

.message-file-card:hover {
    border-color: var(--primary);
    box-shadow: 0 7px 18px rgba(42, 132, 83, 0.12);
}

.message-file-icon {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    color: #fff;
    font-size: 11px;
    font-weight: 800;
    background: var(--primary);
}

.message-file-info {
    min-width: 0;
    display: grid;
    gap: 2px;
}

.message-file-info strong,
.message-file-info span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.message-file-info span {
    color: var(--muted);
    font-size: 12px;
}

.message-file-download {
    color: var(--primary);
    font-size: 13px;
    font-weight: 700;
}

.markdown-body {
    white-space: normal;
}

.markdown-body > :first-child {
    margin-top: 0;
}

.markdown-body > :last-child {
    margin-bottom: 0;
}

.markdown-body p,
.markdown-body ul,
.markdown-body ol,
.markdown-body blockquote,
.markdown-body pre,
.markdown-body .markdown-table-wrap {
    margin: 10px 0;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
    margin: 18px 0 8px;
    line-height: 1.35;
}

.markdown-body h1 {
    font-size: 20px;
}

.markdown-body h2 {
    font-size: 18px;
}

.markdown-body h3 {
    font-size: 16px;
}

.markdown-body h4 {
    font-size: 14px;
}

.markdown-body ul,
.markdown-body ol {
    padding-left: 24px;
}

.markdown-body li + li {
    margin-top: 4px;
}

.markdown-body blockquote {
    padding: 7px 12px;
    color: #536058;
    border-left: 3px solid #79a989;
    background: rgba(40, 122, 75, 0.06);
}

.markdown-body code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.markdown-body :not(pre) > code {
    padding: 2px 5px;
    border: 1px solid #d9e1da;
    border-radius: 5px;
    color: #b13b3b;
    background: #f4f6f3;
}

.markdown-body pre {
    position: relative;
    max-width: 100%;
    padding: 16px;
    overflow: auto;
    border: 1px solid #27382e;
    border-radius: 10px;
    color: #e8f2eb;
    line-height: 1.6;
    white-space: pre;
    background: #17241c;
}

.markdown-body pre[data-language] {
    padding-top: 30px;
}

.markdown-body pre[data-language]::before {
    content: attr(data-language);
    position: absolute;
    top: 7px;
    right: 10px;
    color: #91aa99;
    font-size: 10px;
    text-transform: uppercase;
}

.markdown-body a {
    color: #176d42;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.markdown-body hr {
    height: 1px;
    margin: 16px 0;
    border: 0;
    background: var(--border);
}

.markdown-table-wrap {
    max-width: 100%;
    overflow-x: auto;
}

.markdown-body table {
    width: 100%;
    min-width: 420px;
    border-collapse: collapse;
    font-size: 12px;
}

.markdown-body th,
.markdown-body td {
    padding: 8px 10px;
    border: 1px solid #d4ddd5;
    text-align: left;
    vertical-align: top;
}

.markdown-body th {
    background: #eaf2ec;
}

.message-meta {
    margin-top: 6px;
    color: var(--muted);
    font-size: 10px;
}

.typing::after {
    content: "●";
    display: inline-block;
    margin-left: 4px;
    color: var(--primary);
    animation: blink 1s infinite;
}

@keyframes blink {
    50% {
        opacity: 0.25;
    }
}

.composer {
    position: relative;
    padding: 12px clamp(16px, 2.4vw, 32px) clamp(14px, 2vw, 22px);
    border-top: 1px solid var(--border);
    background: var(--surface);
}

.message-input-shell {
    overflow: hidden;
    border: 1px solid var(--border-strong);
    border-radius: 12px;
    background: var(--surface);
    transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.message-input-shell:focus-within {
    border-color: #74a986;
    box-shadow: 0 0 0 3px rgba(40, 122, 75, 0.1);
}

.composer textarea {
    min-height: 76px;
    max-height: 180px;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
}

.composer textarea:focus {
    border: 0;
    box-shadow: none;
}

.composer-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 9px;
}

.composer-tools span {
    color: var(--muted);
    font-size: 11px;
}

.request-tags-bar,
.selected-files-bar {
    display: flex;
    align-items: center;
    gap: 6px;
}

.request-tags-bar {
    max-width: 100%;
    padding: 10px 12px 0;
    overflow-x: auto;
}

.selected-files-bar {
    flex: 0 1 auto;
}

.file-chip {
    display: inline-flex;
    min-width: 0;
    max-width: min(360px, calc(100vw - 64px));
    flex: 0 1 auto;
    align-items: center;
    gap: 7px;
    min-height: 38px;
    padding: 5px 6px;
    border-radius: 8px;
    color: var(--primary-dark);
    font-size: 11px;
    background: var(--primary-soft);
}

.file-chip-preview,
.file-chip-type {
    width: 28px;
    height: 28px;
    flex: none;
    border-radius: 6px;
}

.file-chip-preview {
    object-fit: cover;
    background: #dfe9e1;
}

.file-chip-type {
    display: grid;
    place-items: center;
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    background: var(--primary);
}

.file-chip-name {
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.message-edit-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    color: var(--primary-dark);
    font-size: 11px;
    background: var(--primary-soft);
}

.message-edit-bar button {
    min-height: 26px;
    padding: 0 8px;
    border: 0;
    border-radius: 6px;
    color: var(--primary-dark);
    background: rgba(255, 255, 255, 0.72);
}

.file-chip-remove {
    display: grid;
    width: 20px;
    height: 20px;
    flex: none;
    padding: 0;
    place-items: center;
    border: 0;
    border-radius: 6px;
    color: #5f7565;
    background: rgba(255, 255, 255, 0.72);
}

.file-chip-remove:hover {
    color: #fff;
    background: var(--danger);
}

.drawer-backdrop {
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgba(21, 31, 24, 0.24);
    backdrop-filter: blur(1px);
}

.session-files-drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 41;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    width: min(clamp(340px, 36vw, 460px), 94vw);
    padding: clamp(16px, 2vw, 22px);
    border-left: 1px solid var(--border);
    background: var(--surface);
    box-shadow: -18px 0 48px rgba(31, 55, 38, 0.16);
}

.drawer-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.drawer-header h2 {
    margin: 0;
    font-size: 17px;
}

.drawer-header p {
    margin: 6px 0 0;
    color: var(--muted);
    font-size: 11px;
    line-height: 1.55;
}

.drawer-actions {
    display: flex;
    gap: 5px;
}

.drawer-file-list {
    max-height: none;
    padding-top: 16px;
    overflow-y: auto;
}

.settings-drawer {
    width: min(clamp(360px, 40vw, 520px), 96vw);
}

.compact-button {
    min-height: 32px;
    padding: 0 10px;
    font-size: 11px;
}

.drawer-form,
.memory-drawer-content {
    min-height: 0;
    overflow-y: auto;
}

.drawer-form {
    display: grid;
    align-content: start;
    gap: 20px;
    padding: 20px 2px 2px;
}

.preference-fieldset {
    min-width: 0;
    padding: 0;
    margin: 0;
    border: 0;
}

.preference-fieldset legend,
.form-field > span {
    display: block;
    margin-bottom: 8px;
    color: var(--text);
    font-size: 12px;
    font-weight: 700;
}

.segmented-options {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
}

.segmented-options label {
    min-width: 0;
}

.segmented-options input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.segmented-options span {
    display: grid;
    min-height: 38px;
    padding: 6px;
    place-items: center;
    border: 1px solid var(--border);
    border-radius: 9px;
    color: var(--muted);
    font-size: 11px;
    text-align: center;
    background: var(--surface-soft);
    cursor: pointer;
}

.segmented-options input:checked + span {
    border-color: #8db99a;
    color: var(--primary-dark);
    font-weight: 700;
    background: var(--primary-soft);
}

.segmented-options input:focus-visible + span {
    outline: 2px solid rgba(40, 122, 75, 0.28);
    outline-offset: 2px;
}

.form-field {
    display: block;
}

.form-field small {
    display: block;
    margin-top: 6px;
    color: var(--muted);
    font-size: 10px;
}

.preference-switches {
    display: grid;
    gap: 2px;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}

.preference-switches label {
    display: flex;
    min-height: 64px;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 10px 2px;
}

.preference-switches label + label {
    border-top: 1px solid var(--border);
}

.preference-switches strong,
.preference-switches small {
    display: block;
}

.preference-switches strong {
    font-size: 12px;
}

.preference-switches small {
    margin-top: 4px;
    color: var(--muted);
    font-size: 10px;
}

.preference-switches input[role="switch"] {
    width: 38px;
    min-height: 22px;
    height: 22px;
    flex: none;
    padding: 0;
    appearance: none;
    border: 0;
    border-radius: 999px;
    background: #c8d0c9;
    transition: 0.18s ease;
}

.preference-switches input[role="switch"]::before {
    display: block;
    width: 18px;
    height: 18px;
    margin: 2px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 4px rgba(20, 37, 25, 0.18);
    transition: transform 0.18s ease;
    content: "";
}

.preference-switches input[role="switch"]:checked {
    background: var(--primary);
}

.preference-switches input[role="switch"]:checked::before {
    transform: translateX(16px);
}

.drawer-form-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding-top: 4px;
}

.memory-drawer-content {
    padding-top: 16px;
}

.memory-form {
    display: grid;
    gap: 15px;
    padding: 15px;
    margin-bottom: 16px;
    border: 1px solid #bcd4c2;
    border-radius: 12px;
    background: #f5faf6;
}

.memory-form-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.memory-form-heading strong {
    font-size: 13px;
}

.memory-form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.form-hint {
    margin: -5px 0 0;
    color: var(--muted);
    font-size: 10px;
    line-height: 1.5;
}

.memory-form textarea {
    resize: vertical;
}

.memory-list {
    display: grid;
    gap: 10px;
}

.memory-card {
    display: grid;
    gap: 11px;
    padding: 13px;
    border: 1px solid var(--border);
    border-radius: 11px;
    background: var(--surface-soft);
}

.memory-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
}

.memory-tags,
.memory-card-actions {
    display: flex;
    align-items: center;
    gap: 5px;
}

.memory-tags {
    min-width: 0;
    flex-wrap: wrap;
}

.memory-tag {
    padding: 4px 7px;
    border-radius: 999px;
    font-size: 9px;
    white-space: nowrap;
}

.memory-tag.type {
    color: var(--primary-dark);
    background: var(--primary-soft);
}

.memory-tag.scope {
    color: #5e6a61;
    background: #edf0ed;
}

.memory-card-actions button {
    min-height: 26px;
    padding: 0 5px;
    border: 0;
    color: var(--muted);
    font-size: 10px;
    background: transparent;
}

.memory-card-actions button:hover {
    color: var(--primary);
}

.memory-card-actions button.danger:hover {
    color: var(--danger);
}

.memory-content {
    margin: 0;
    color: var(--text);
    font-size: 12px;
    line-height: 1.65;
    overflow-wrap: anywhere;
}

.memory-meta {
    color: var(--muted);
    font-size: 9px;
}

.memory-empty {
    padding: 34px 18px;
    border: 1px dashed var(--border-strong);
    border-radius: 12px;
    text-align: center;
}

.memory-empty strong {
    font-size: 13px;
}

.memory-empty p {
    margin: 8px auto 14px;
    color: var(--muted);
    font-size: 11px;
    line-height: 1.55;
}

.knowledge-drawer-content {
    min-height: 0;
    padding-top: 16px;
    overflow-y: auto;
}

.knowledge-upload-panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 14px;
    padding: 14px;
    margin-bottom: 16px;
    border: 1px solid #bcd4c2;
    border-radius: 12px;
    background: #f5faf6;
}

.knowledge-upload-panel strong {
    font-size: 13px;
}

.knowledge-upload-panel p {
    margin: 5px 0 0;
    color: var(--muted);
    font-size: 10px;
    line-height: 1.55;
}

.knowledge-upload-panel .primary-button {
    min-height: 36px;
    padding: 0 12px;
    white-space: nowrap;
}

.knowledge-list {
    display: grid;
    gap: 10px;
}

.knowledge-card {
    display: grid;
    gap: 12px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-soft);
}

.knowledge-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.knowledge-card-heading {
    display: grid;
    min-width: 0;
    gap: 4px;
}

.knowledge-card-heading strong {
    font-size: 12px;
    line-height: 1.45;
    overflow-wrap: anywhere;
}

.knowledge-card-heading span {
    color: var(--muted);
    font-size: 9px;
}

.knowledge-status {
    flex: none;
    padding: 4px 7px;
    border-radius: 999px;
    color: #5e6a61;
    font-size: 9px;
    font-weight: 700;
    background: #edf0ed;
}

.knowledge-status.ready {
    color: var(--primary-dark);
    background: var(--primary-soft);
}

.knowledge-status.failed {
    color: var(--danger);
    background: #fff0ef;
}

.knowledge-status.processing {
    color: #8a6518;
    background: #fff6da;
}

.knowledge-details summary {
    color: var(--primary-dark);
    font-size: 10px;
    cursor: pointer;
}

.knowledge-details p,
.knowledge-error,
.knowledge-processing {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 10px;
    line-height: 1.6;
}

.knowledge-error {
    color: var(--danger);
}

.knowledge-card-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    padding-top: 2px;
}

.knowledge-card-actions button {
    min-height: 26px;
    padding: 0;
    border: 0;
    color: var(--muted);
    font-size: 10px;
    background: transparent;
}

.knowledge-card-actions button:hover {
    color: var(--primary);
}

.knowledge-card-actions button.primary-text {
    color: var(--primary-dark);
    font-weight: 700;
}

.knowledge-card-actions button.danger {
    color: var(--danger);
}

.knowledge-empty {
    padding: 34px 18px;
    border: 1px dashed var(--border-strong);
    border-radius: 12px;
    text-align: center;
}

.knowledge-empty strong {
    font-size: 13px;
}

.knowledge-empty p {
    margin: 8px auto 14px;
    color: var(--muted);
    font-size: 11px;
    line-height: 1.6;
}

.memory-danger-zone {
    display: flex;
    justify-content: center;
    padding: 18px 0 4px;
    margin-top: 18px;
    border-top: 1px solid var(--border);
}

.danger-text-button {
    color: var(--danger);
}

.danger-text-button:hover:not(:disabled) {
    background: var(--danger-soft);
}

.file-check {
    width: 15px;
    min-height: auto;
    height: 15px;
}

.file-list {
    display: grid;
    max-height: 280px;
    gap: 8px;
    overflow-y: auto;
}

.file-card {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 9px;
    padding: 9px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface-soft);
}

.file-card.selected {
    border-color: #9bc3a6;
    background: var(--primary-soft);
}

.file-info {
    min-width: 0;
}

.file-info strong,
.file-info span {
    display: block;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.file-info strong {
    font-size: 12px;
}

.file-info span {
    margin-top: 4px;
    color: var(--muted);
    font-size: 10px;
}

.file-actions {
    display: flex;
    gap: 3px;
}

.file-actions button {
    min-width: 25px;
    height: 25px;
    padding: 0;
    border: 0;
    border-radius: 7px;
    color: var(--muted);
    background: transparent;
}

.file-actions button:hover {
    color: var(--text);
    background: #e5ebe4;
}

.file-actions .file-delete-button {
    width: auto;
    padding: 0 6px;
    color: var(--danger);
    font-size: 10px;
}

.file-actions .file-delete-button:hover {
    color: #fff;
    background: var(--danger);
}

.session-list,
.message-list,
.request-tags-bar,
.file-list {
    scrollbar-width: thin;
    scrollbar-color: #aab8ad #edf1ed;
}

.session-list::-webkit-scrollbar,
.message-list::-webkit-scrollbar,
.request-tags-bar::-webkit-scrollbar,
.file-list::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

.session-list::-webkit-scrollbar-track,
.message-list::-webkit-scrollbar-track,
.request-tags-bar::-webkit-scrollbar-track,
.file-list::-webkit-scrollbar-track {
    border-radius: 999px;
    background: #edf1ed;
}

.session-list::-webkit-scrollbar-thumb,
.message-list::-webkit-scrollbar-thumb,
.request-tags-bar::-webkit-scrollbar-thumb,
.file-list::-webkit-scrollbar-thumb {
    border: 2px solid #edf1ed;
    border-radius: 999px;
    background: #aab8ad;
}

.session-list::-webkit-scrollbar-thumb:hover,
.message-list::-webkit-scrollbar-thumb:hover,
.request-tags-bar::-webkit-scrollbar-thumb:hover,
.file-list::-webkit-scrollbar-thumb:hover {
    background: #819485;
}

.muted-placeholder {
    margin: 12px 2px;
    color: #929a93;
    font-size: 11px;
    line-height: 1.55;
}

.toast {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 60;
    max-width: min(420px, calc(100vw - 44px));
    padding: 12px 16px;
    border-radius: 11px;
    color: #fff;
    font-size: 13px;
    background: #26352a;
    box-shadow: var(--shadow);
    opacity: 0;
    pointer-events: none;
    transform: translateY(10px);
    transition: 0.2s ease;
}

.toast.visible {
    opacity: 1;
    transform: translateY(0);
}

.toast.error {
    background: #9f3d3d;
}

.hidden {
    display: none !important;
}

.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;
}

@media (max-width: 1120px) {
    .app-shell {
        grid-template-columns: clamp(210px, 24vw, 230px) minmax(0, 1fr);
    }

    .composer-footer {
        align-items: stretch;
        flex-direction: column;
    }

    .composer-actions {
        justify-content: flex-end;
    }
}

@media (max-width: 860px) {
    body {
        height: auto;
        min-height: 100%;
    }

    .app-shell {
        display: flex;
        min-height: 100vh;
        height: auto;
        overflow: visible;
        flex-direction: column;
    }

    .sidebar {
        height: auto;
        max-height: 320px;
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }

    .session-list {
        max-height: 150px;
    }

    .chat-panel {
        height: auto;
        min-height: 760px;
    }

    .message-list {
        min-height: 420px;
    }

    .message-copy-button {
        opacity: 1;
    }

}

@media (hover: none), (pointer: coarse) {
    .message-copy-button {
        opacity: 1;
    }
}

@media (max-width: 560px) {
    .settings-drawer,
    .session-files-drawer {
        width: 100vw;
        padding: 16px 14px;
        border-left: 0;
    }

    .memory-form-grid {
        grid-template-columns: 1fr;
    }

    .knowledge-upload-panel {
        grid-template-columns: 1fr;
    }

    .knowledge-upload-panel .primary-button {
        width: 100%;
    }

    .segmented-options {
        gap: 5px;
    }

    .drawer-header {
        gap: 10px;
    }

    .drawer-actions {
        align-items: center;
    }

    .chat-header,
    .composer {
        padding-right: 14px;
        padding-left: 14px;
    }

    .chat-header {
        align-items: center;
        flex-direction: row;
        gap: 10px;
    }

    .conversation-heading {
        flex: 1;
    }

    .account-button {
        grid-template-columns: 34px 16px;
        width: auto;
        min-height: 44px;
        padding: 5px 8px;
    }

    .account-copy {
        display: none;
    }

    .account-popover {
        position: fixed;
        top: 68px;
        right: 14px;
    }

    .composer-tools {
        flex-wrap: wrap;
    }

    .composer-tools > span {
        width: 100%;
    }

    .message-list {
        padding: 18px 14px;
    }

    .message-bubble {
        max-width: 94%;
    }

    .message-task {
        max-width: 94%;
    }

    .image-preview-modal {
        padding: 0;
    }

    .image-preview-dialog {
        width: 100vw;
        max-height: 100vh;
        height: 100vh;
        border: 0;
        border-radius: 0;
    }

    .image-preview-stage {
        min-height: 0;
        padding: 10px;
    }

    .image-preview-stage img {
        max-height: calc(100vh - 70px);
    }

    .composer-actions {
        align-items: stretch;
        flex-direction: column;
    }
}
