:root {
    color-scheme: light;
    --bg: #f4f4f2;
    --surface: rgba(255, 255, 255, 0.84);
    --surface-solid: #ffffff;
    --surface-soft: #f7f7f5;
    --surface-muted: #ececea;
    --text: #171717;
    --muted: #6b6b66;
    --faint: #9a9a93;
    --line: rgba(23, 23, 23, 0.11);
    --line-strong: rgba(23, 23, 23, 0.18);
    --inverse: #111111;
    --inverse-soft: #222222;
    --inverse-text: #f8f8f7;
    --danger: #b42318;
    --danger-soft: #fff1f0;
    --code-bg: #0f1115;
    --shadow: 0 24px 80px rgba(17, 17, 17, 0.12);
    --soft-shadow: 0 12px 34px rgba(17, 17, 17, 0.08);
    --chat-max: 1120px;
}

* {
    box-sizing: border-box;
}

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

body {
    margin: 0;
    overflow: hidden;
    background:
        linear-gradient(180deg, #fbfbfa 0%, var(--bg) 42%, #eeeeeb 100%);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    letter-spacing: 0;
}

button,
input,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

.hidden {
    display: none !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.auth-panel {
    width: min(420px, 100%);
    background: var(--surface);
    border: 1px solid rgba(255, 255, 255, 0.66);
    border-radius: 14px;
    box-shadow: var(--shadow);
    padding: 32px;
    backdrop-filter: blur(22px);
}

.brand-mark {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    background: var(--inverse);
    color: var(--inverse-text);
    font-weight: 760;
}

.auth-panel h1 {
    margin: 18px 0 6px;
    font-size: 28px;
}

.auth-copy {
    margin: 0 0 24px;
    color: var(--muted);
}

.auth-form {
    display: grid;
    gap: 16px;
}

.auth-form label {
    display: grid;
    gap: 8px;
    color: var(--muted);
    font-size: 14px;
}

.auth-form input,
.composer textarea {
    width: 100%;
    border: 1px solid var(--line);
    color: var(--text);
    background: rgba(255, 255, 255, 0.92);
    outline: none;
}

.auth-form input {
    border-radius: 10px;
    padding: 12px 13px;
}

.auth-form input:focus,
.composer textarea:focus {
    border-color: var(--inverse);
    box-shadow: 0 0 0 3px rgba(17, 17, 17, 0.08);
}

.auth-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.primary-button,
.secondary-button,
.new-chat-button,
.ghost-button,
.send-button,
.icon-button,
.model-picker-button {
    min-height: 40px;
    border: 1px solid transparent;
    border-radius: 10px;
    padding: 0 14px;
    transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease, opacity 0.16s ease, transform 0.16s ease;
}

.primary-button,
.send-button,
.new-chat-button {
    background: var(--inverse);
    color: var(--inverse-text);
}

.primary-button:hover,
.send-button:hover,
.new-chat-button:hover {
    background: var(--inverse-soft);
}

.secondary-button,
.ghost-button,
.icon-button,
.model-picker-button {
    background: rgba(255, 255, 255, 0.82);
    border-color: var(--line);
    color: var(--text);
}

.secondary-button:hover,
.ghost-button:hover,
.icon-button:hover,
.model-picker-button:hover {
    background: var(--surface-solid);
    border-color: var(--line-strong);
}

.form-error {
    min-height: 20px;
    margin: 0;
    color: var(--danger);
    font-size: 14px;
}

.app-shell {
    width: 100%;
    height: 100vh;
    min-width: 0;
    min-height: 0;
    display: grid;
    grid-template-columns: 304px minmax(0, 1fr);
    overflow: hidden;
    transition: grid-template-columns 0.2s ease;
}

.app-shell.sidebar-collapsed {
    grid-template-columns: 0 minmax(0, 1fr);
}

.sidebar {
    min-width: 0;
    width: 304px;
    overflow: hidden;
    background: rgba(18, 18, 18, 0.94);
    color: var(--inverse-text);
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(24px);
    transition: transform 0.2s ease, opacity 0.2s ease, visibility 0.2s ease;
}

.app-shell.sidebar-collapsed .sidebar {
    border-right: 0;
    opacity: 0;
    visibility: hidden;
    transform: translateX(-105%);
    pointer-events: none;
}

.sidebar-header,
.sidebar-footer {
    padding: 14px;
}

.sidebar-header {
    display: flex;
    gap: 10px;
    align-items: center;
}

.new-chat-button {
    width: 100%;
    border-color: rgba(255, 255, 255, 0.14);
}

.conversation-list {
    min-height: 0;
    overflow-y: auto;
    padding: 6px 10px 12px;
}

.conversation-item {
    width: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 4px;
    border: 1px solid transparent;
    border-radius: 10px;
    color: #deded8;
}

.conversation-item:hover {
    background: rgba(255, 255, 255, 0.07);
}

.conversation-item.active {
    background: rgba(255, 255, 255, 0.13);
    border-color: rgba(255, 255, 255, 0.13);
    color: #fff;
}

.conversation-select {
    min-width: 0;
    display: grid;
    gap: 4px;
    text-align: left;
    background: transparent;
    color: inherit;
    border: 0;
    padding: 10px 8px 10px 11px;
}

.conversation-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 14px;
}

.conversation-meta {
    color: #a7a7a1;
    font-size: 12px;
}

.conversation-actions {
    display: flex;
    gap: 2px;
    padding-right: 7px;
    opacity: 0;
    transition: opacity 0.16s ease;
}

.conversation-item:hover .conversation-actions,
.conversation-item:focus-within .conversation-actions {
    opacity: 1;
}

.conversation-actions button {
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #c7c7c0;
}

.conversation-actions button:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}

.sidebar-footer {
    display: grid;
    gap: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.user-badge {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #deded8;
    font-size: 14px;
}

.sidebar-footer .ghost-button,
.sidebar .icon-button {
    color: var(--inverse-text);
    background: rgba(255, 255, 255, 0.07);
    border-color: rgba(255, 255, 255, 0.14);
}

.chat-shell {
    min-width: 0;
    min-height: 0;
    height: 100vh;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
}

.topbar {
    min-height: 58px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 18px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.72);
    backdrop-filter: blur(18px);
}

.topbar-title {
    min-width: 0;
    display: grid;
    gap: 1px;
}

.topbar-title strong {
    font-size: 15px;
}

.topbar-title span {
    color: var(--muted);
    font-size: 12px;
}

.chat-stage {
    min-height: 0;
    position: relative;
    display: grid;
}

.messages {
    min-width: 0;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 32px clamp(18px, 4vw, 60px);
}

.messages-inner {
    width: min(var(--chat-max), 100%);
    margin: 0 auto;
    display: grid;
    gap: 20px;
}

.empty-state {
    position: absolute;
    inset: 0;
    z-index: 1;
    display: grid;
    align-content: center;
    justify-items: center;
    text-align: center;
    color: var(--muted);
    padding: 32px;
    pointer-events: none;
}

.empty-state h2 {
    margin: 0 0 8px;
    color: var(--text);
    font-size: 34px;
    font-weight: 680;
}

.empty-state p {
    margin: 0;
}

.message {
    width: 100%;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    min-width: 0;
}

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

.message.assistant {
    justify-content: flex-start;
}

.avatar {
    flex: 0 0 34px;
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    background: var(--surface-muted);
    color: var(--muted);
    font-size: 12px;
    font-weight: 760;
}

.message.user .avatar {
    order: 2;
    background: var(--inverse);
    color: var(--inverse-text);
}

.message.assistant .avatar {
    background: #ffffff;
    border: 1px solid var(--line);
    color: var(--text);
}

.message-body {
    min-width: 0;
    max-width: min(900px, calc(100% - 48px));
    max-inline-size: min(900px, calc(100% - 48px));
}

.message.user .message-body {
    max-width: min(720px, calc(100% - 48px));
    max-inline-size: min(720px, calc(100% - 48px));
    overflow: hidden;
}

.message-meta {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 7px;
    color: var(--muted);
    font-size: 12px;
}

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

.message-content {
    min-width: 0;
    max-inline-size: 100%;
    overflow-wrap: anywhere;
    word-break: break-word;
    line-height: 1.72;
}

.message.user .message-content {
    background: var(--inverse);
    color: var(--inverse-text);
    border-radius: 14px;
    padding: 12px 15px;
    white-space: pre-wrap;
    box-shadow: var(--soft-shadow);
    max-inline-size: 100%;
}

.message.assistant .message-content {
    background: rgba(255, 255, 255, 0.78);
    border: 1px solid rgba(255, 255, 255, 0.72);
    border-radius: 14px;
    padding: 17px 19px;
    box-shadow: 0 10px 34px rgba(17, 17, 17, 0.06);
    backdrop-filter: blur(18px);
}

.message.assistant .message-content.is-empty {
    display: none;
}

.message-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
    justify-content: flex-end;
}

.message-attachments span {
    max-width: 240px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 999px;
    padding: 4px 9px;
    background: rgba(255, 255, 255, 0.10);
    color: var(--inverse-text);
    font-size: 12px;
}

.reasoning-panel {
    margin: 0 0 8px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.50);
    color: #777771;
    font-size: 12px;
    line-height: 1.55;
}

.reasoning-panel summary {
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 10px;
    color: #777771;
    cursor: pointer;
    user-select: none;
}

.reasoning-panel summary::-webkit-details-marker {
    display: none;
}

.reasoning-panel summary::after {
    content: "展开";
    color: var(--faint);
    font-size: 12px;
}

.reasoning-panel[open] summary::after {
    content: "收起";
}

.reasoning-text {
    padding: 0 10px 10px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.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 table,
.markdown-body .katex-display,
.markdown-body .code-block {
    margin: 0 0 13px;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
    margin: 18px 0 10px;
    line-height: 1.28;
}

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

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

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

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

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

.markdown-body blockquote {
    border-left: 3px solid var(--line-strong);
    padding: 4px 0 4px 12px;
    color: var(--muted);
}

.markdown-body code {
    border-radius: 5px;
    background: #ececea;
    padding: 2px 5px;
    font-size: 0.92em;
    font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
}

.code-block {
    max-width: 100%;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    background: var(--code-bg);
    box-shadow: 0 14px 34px rgba(15, 17, 21, 0.18);
}

.code-block-toolbar {
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 7px 9px 7px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.10);
    color: #aeb4c0;
    font-size: 12px;
}

.copy-code-button {
    min-height: 26px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.08);
    color: #f4f4f5;
    padding: 0 9px;
}

.copy-code-button:hover {
    background: rgba(255, 255, 255, 0.15);
}

.markdown-body pre {
    max-width: 100%;
    overflow-x: auto;
    margin: 0;
    background: transparent;
    color: #e5e7eb;
    padding: 14px;
}

.markdown-body pre code {
    background: transparent;
    padding: 0;
    color: inherit;
}

.markdown-body table {
    width: 100%;
    border-collapse: collapse;
    display: block;
    overflow-x: auto;
}

.markdown-body th,
.markdown-body td {
    border: 1px solid var(--line);
    padding: 8px 10px;
    text-align: left;
}

.markdown-body th {
    background: var(--surface-soft);
}

.markdown-body .katex-display {
    overflow-x: auto;
    overflow-y: hidden;
    padding: 4px 0;
}

.math-fallback {
    font-family: "Cascadia Code", Consolas, monospace;
}

.composer {
    border-top: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.72);
    padding: 14px clamp(18px, 4vw, 60px) 18px;
    backdrop-filter: blur(18px);
}

.composer-inner {
    width: min(var(--chat-max), 100%);
    min-width: 0;
    margin: 0 auto;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 10px;
    align-items: end;
}

.model-picker {
    position: relative;
}

.model-picker-button {
    width: 52px;
    min-width: 52px;
    height: 52px;
    min-height: 52px;
    display: grid;
    place-items: center;
    border-radius: 999px;
    padding: 0;
    background: var(--inverse);
    border-color: var(--inverse);
    color: var(--inverse-text);
    box-shadow: var(--soft-shadow);
}

.model-picker-button:hover {
    background: var(--inverse-soft);
    border-color: var(--inverse-soft);
}

.model-logo-image {
    width: 30px;
    height: 30px;
    display: block;
    border-radius: 999px;
}

.model-picker-popover {
    position: absolute;
    left: 0;
    bottom: calc(100% + 10px);
    z-index: 30;
    width: min(270px, calc(100vw - 32px));
    padding: 8px;
    background: rgba(255, 255, 255, 0.90);
    border: 1px solid rgba(255, 255, 255, 0.72);
    border-radius: 16px;
    box-shadow: 0 18px 54px rgba(17, 17, 17, 0.16);
    backdrop-filter: blur(22px);
}

.model-picker-header {
    display: grid;
    gap: 2px;
    padding: 8px 10px 9px;
}

.model-picker-header strong {
    font-size: 14px;
}

.model-picker-header span {
    color: var(--muted);
    font-size: 12px;
}

.model-options {
    display: grid;
    gap: 4px;
}

.model-option {
    width: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    text-align: left;
    border: 1px solid transparent;
    border-radius: 12px;
    background: transparent;
    padding: 10px 11px;
    color: var(--text);
}

.model-option:hover,
.model-option.active {
    background: rgba(17, 17, 17, 0.06);
    border-color: var(--line);
}

.model-option span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 650;
}

.model-option-check {
    width: 18px;
    min-width: 18px;
    color: var(--inverse);
    text-align: center;
}

.attach-button {
    width: 42px;
    min-width: 42px;
    height: 42px;
    min-height: 42px;
    border-radius: 999px;
    padding: 0;
    display: grid;
    place-items: center;
    font-size: 20px;
}

.composer-input {
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: 24px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 18px 50px rgba(17, 17, 17, 0.10);
    overflow: hidden;
}

.composer textarea {
    max-height: 190px;
    min-height: 50px;
    resize: none;
    border: 0;
    border-radius: 0;
    padding: 14px 15px;
    line-height: 1.5;
    background: transparent;
}

.composer-after-input {
    display: flex;
    align-items: end;
    gap: 8px;
    min-width: 0;
}

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

.attachment-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 9px 10px 0;
}

.attachment-chip {
    max-width: min(280px, 100%);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #f6f6f4;
    padding: 4px 5px 4px 10px;
    color: var(--muted);
    font-size: 12px;
}

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

.attachment-chip button {
    width: 20px;
    height: 20px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--muted);
}

.attachment-chip button:hover {
    background: rgba(17, 17, 17, 0.08);
    color: var(--text);
}

.send-button {
    width: 52px;
    min-width: 52px;
    min-height: 52px;
    border-radius: 999px;
    padding: 0;
    display: grid;
    place-items: center;
    font-size: 22px;
}

.send-button:disabled,
.new-chat-button:disabled,
.attach-button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.mobile-only {
    display: none;
}

.desktop-only {
    display: inline-grid;
    place-items: center;
}

.sidebar-overlay {
    display: none;
}

@media (max-width: 820px) {
    html,
    body {
        overflow: hidden;
    }

    .app-shell,
    .app-shell.sidebar-collapsed {
        grid-template-columns: minmax(0, 1fr);
    }

    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        width: min(86vw, 320px);
        max-width: calc(100vw - 28px);
        z-index: 20;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
    }

    .app-shell.sidebar-collapsed .sidebar {
        border-right: 1px solid rgba(255, 255, 255, 0.08);
        opacity: 1;
        visibility: visible;
        transform: translateX(-100%);
        pointer-events: auto;
    }

    .app-shell.sidebar-collapsed .sidebar.open,
    .sidebar.open {
        transform: translateX(0);
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }

    .sidebar-overlay.show {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 10;
        background: rgba(15, 15, 15, 0.42);
    }

    .mobile-only {
        display: inline-grid;
        place-items: center;
    }

    .desktop-only {
        display: none;
    }

    .topbar {
        min-height: 54px;
        padding: 8px 10px;
    }

    .topbar-title span {
        display: none;
    }

    .messages {
        padding: 18px 10px;
    }

    .messages-inner {
        gap: 15px;
    }

    .empty-state {
        padding: 24px;
    }

    .empty-state h2 {
        font-size: 26px;
    }

    .message {
        gap: 8px;
    }

    .avatar {
        flex-basis: 30px;
        width: 30px;
        height: 30px;
        border-radius: 9px;
    }

    .message-body,
    .message.user .message-body {
        max-width: calc(100% - 38px);
    }

    .message.assistant .message-content,
    .message.user .message-content {
        border-radius: 13px;
        padding: 13px 14px;
    }

    .message-meta {
        margin-bottom: 5px;
    }

    .composer {
        padding: 9px 10px 12px;
    }

    .composer-inner {
        grid-template-columns: auto minmax(0, 1fr) auto;
        gap: 7px;
        align-items: end;
    }

    .model-picker-button {
        width: 42px;
        min-width: 42px;
        height: 42px;
        min-height: 42px;
        padding: 0;
        justify-content: center;
    }

    .model-logo-image {
        width: 25px;
        height: 25px;
    }

    .model-picker-popover {
        left: 0;
        bottom: calc(100% + 8px);
        width: min(320px, calc(100vw - 20px));
    }

    .attach-button {
        width: 42px;
        min-width: 42px;
        height: 42px;
        min-height: 42px;
    }

    .composer-after-input {
        gap: 6px;
    }

    .composer-input {
        border-radius: 14px;
    }

    .composer textarea {
        min-height: 42px;
        padding: 11px 12px;
    }

    .send-button {
        width: 42px;
        min-width: 42px;
        min-height: 42px;
        border-radius: 999px;
        font-size: 20px;
    }

    .code-block-toolbar {
        padding-right: 7px;
    }
}

@media (max-width: 520px) {
    .auth-shell {
        padding: 14px;
    }

    .auth-panel {
        padding: 24px;
    }

    .composer-inner {
        grid-template-columns: auto minmax(0, 1fr) auto;
    }

    .model-picker-popover {
        position: fixed;
        left: 10px;
        right: 10px;
        bottom: 74px;
        width: auto;
    }

    .message.assistant .avatar {
        display: none;
    }

    .message.assistant .message-body {
        max-width: 100%;
    }
}
