* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --shadow-panel: 0 20px 60px rgba(0, 0, 0, 0.35);
    --shadow-soft: 0 10px 30px rgba(0, 0, 0, 0.18);
    --shell-rail-width: 56px;
    --sidebar-inline-padding: 14px;
    --ui-copy-size: 14px;
    --ui-copy-weight: 500;
    --ui-copy-line-height: 1.4;
    --ui-copy-tracking: 0.01em;
}

body[data-theme="dark"] {
    --primary-color: #10a37f;
    --primary-strong: #0f8d6f;
    --accent-color: #10a37f;
    --danger-color: #ff6b81;
    /* 应用壳：侧栏浅、主区深（扁平分区，非卡片气泡） */
    --app-chrome-sidebar: #1e1e1e;
    --app-chrome-main: #131314;
    --bg-main: #131314;
    --bg-elevated: #171717;
    --bg-elevated-strong: #2f2f2f;
    --bg-soft: #2a2a2a;
    --bg-soft-hover: #343434;
    --border-color: rgba(255, 255, 255, 0.09);
    --border-strong: rgba(16, 163, 127, 0.3);
    --text-primary: #ececec;
    --text-secondary: #b4b4b4;
    --text-tertiary: #8b8b8b;
    --bubble-user: #303030;
    --bubble-assistant: transparent;
    --code-bg: rgba(255, 255, 255, 0.04);
    --shadow-panel: none;
    --shadow-soft: none;
}

body[data-theme="light"] {
    --primary-color: #4f46e5;
    --primary-strong: #7c3aed;
    --accent-color: #059669;
    --danger-color: #e11d48;
    --app-chrome-sidebar: #f6f7fb;
    --app-chrome-main: #eef2ff;
    --bg-main: #eef2ff;
    --bg-elevated: rgba(255, 255, 255, 0.9);
    --bg-elevated-strong: rgba(255, 255, 255, 0.97);
    --bg-soft: rgba(79, 70, 229, 0.06);
    --bg-soft-hover: rgba(79, 70, 229, 0.1);
    --border-color: rgba(79, 70, 229, 0.12);
    --border-strong: rgba(79, 70, 229, 0.24);
    --text-primary: #111827;
    --text-secondary: #5b6478;
    --text-tertiary: #8891a7;
    --bubble-user: linear-gradient(135deg, #4f46e5, #7c3aed);
    --bubble-assistant: rgba(255, 255, 255, 0.75);
    --code-bg: rgba(17, 24, 39, 0.05);
    --shadow-panel: 0 20px 60px rgba(79, 70, 229, 0.12);
    --shadow-soft: 0 10px 30px rgba(79, 70, 229, 0.08);
}

html,
body {
    height: 100%;
    min-height: -webkit-fill-available;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--app-chrome-main);
    color: var(--text-primary);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

body,
button,
input,
select,
textarea {
    font-size: var(--ui-copy-size);
    font-weight: var(--ui-copy-weight);
    line-height: var(--ui-copy-line-height);
    letter-spacing: var(--ui-copy-tracking);
}

.login-screen {
    /* 非 0 时增加错误提示与按钮栈之间的固定间距（四段 flex 空白仍彼此相等） */
    --login-stack-offset-top: 0px;
    --login-oauth-radius: 22px;
    /* 登录三条入口统一最小高度（Google 外链 + 两枚占位按钮 + 内层 label 联动） */
    --login-btn-min-height: 96px;
    --login-btn-stack-gap: clamp(8px, 1.4vh, 16px);
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: row;
    align-items: stretch;
    justify-content: space-between;
    gap: 24px;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 28px 8vw 28px 36px;
    box-sizing: border-box;
    background: var(--app-chrome-main);
    z-index: 100;
}

.login-screen--hidden {
    display: none;
}

/*
 * hero 左：品牌区垂直居中；右：登录按钮顶对齐（整体在轮换词 / assistant 一带上方）。
 */
.login-screen-hero {
    flex: 1 1 auto;
    display: flex;
    flex-direction: row;
    align-items: stretch;
    align-self: stretch;
    justify-content: flex-start;
    gap: clamp(16px, 3vw, 32px);
    min-width: 0;
    min-height: 0;
    width: 100%;
}

.login-screen-hero-brand-wrap {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    min-width: 0;
    min-height: 0;
}

.login-screen-brand-cluster {
    flex: 0 1 auto;
    max-width: min(58vw, 720px);
    min-width: 0;
    min-height: 0;
}

/*
 * 登录品牌唯一尺度：--brand-a-cap（与视口的 min(vh,vw,cap) 一致）。
 * A 的 font-size、轮换词、占位高度全部用 calc(cap * 比例)，无 transform 缩放。
 */
.login-screen-brand-a {
    --brand-a-cap: min(92vh, 56vw, 720px);
    --brand-word-ratio: 0.32;
    --brand-word-ratio-em: 0.38;
    position: relative;
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    margin: 60px 0 0 120px;
    padding: 0 4px 0 0;
    user-select: none;
}

/* * 锚在 A 字形右上角 */
.login-screen-brand-a-inner {
    position: relative;
    display: inline-block;
    font-family: "Playfair Display", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, ui-serif, serif;
    font-weight: 700;
    font-style: italic;
    font-synthesis: none;
    letter-spacing: -0.05em;
    line-height: 0.88;
    color: var(--text-primary);
    /* 比 --brand-a-cap 略大：只放大 A*，轮换词仍用 cap 算字号 */
    font-size: calc(var(--brand-a-cap) * 1.14);
}

.login-screen-brand-a-letter {
    display: inline-block;
}

/* 星号：无衬线，尺寸相对 A 的 em */
.login-screen-brand-a-star {
    position: absolute;
    top: 0.02em;
    right: -0.4em;
    font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-style: normal;
    font-weight: 400;
    font-size: 0.66em;
    line-height: 1;
    letter-spacing: 0;
    color: inherit;
    pointer-events: none;
}

/* 锚点：相对 .login-screen-brand-a 右下角；nudge-y 负值 = 相对 A 往上移（随 cap 比例） */
.login-screen-brand-words {
    --login-brand-anchor-gap-x: clamp(6px, 1.2vw, 20px);
    --login-brand-anchor-nudge-x: 0px;
    --login-brand-anchor-nudge-y: calc(var(--brand-a-cap) * -0.001);
    position: absolute;
    left: 100%;
    bottom: 0;
    margin: 0 0 0 var(--login-brand-anchor-gap-x);
    transform: translate(var(--login-brand-anchor-nudge-x), var(--login-brand-anchor-nudge-y));
    display: flex;
    align-items: flex-end;
    justify-content: flex-start;
    min-width: 0;
    min-height: 0;
    padding: 0;
}

/* 占位高度与最大一行（I）同步，避免切换时跳动 */
.login-screen-brand-rotate {
    position: relative;
    flex: 0 0 auto;
    min-height: calc(var(--brand-a-cap) * var(--brand-word-ratio-em) * 1.05);
    min-width: calc(var(--brand-a-cap) * 0.42);
}

.login-screen-brand-line {
    position: absolute;
    left: 0;
    bottom: 0;
    margin: 0;
    padding: 0;
    font-family: "Playfair Display", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, ui-serif, serif;
    font-style: italic;
    font-synthesis: none;
    font-weight: 600;
    letter-spacing: -0.05em;
    line-height: 1;
    color: var(--text-primary);
    white-space: nowrap;
    font-size: calc(var(--brand-a-cap) * var(--brand-word-ratio));
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.55s ease;
}

.login-screen-brand-line--em {
    font-weight: 700;
    font-size: calc(var(--brand-a-cap) * var(--brand-word-ratio-em));
}

.login-screen-brand-line--visible {
    opacity: 1;
    z-index: 1;
}

/* 右侧：顶对齐，按钮紧凑竖排（与左侧 assistant 词带上下错开） */
.login-screen-actions {
    flex: 0 1 420px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    align-self: flex-start;
    width: min(420px, 38vw);
    min-width: min(280px, 100%);
    min-height: 0;
    box-sizing: border-box;
    padding-top: var(--login-stack-offset-top);
}

.login-screen-button-stack {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    flex: 0 0 auto;
    gap: var(--login-btn-stack-gap);
    width: 100%;
    box-sizing: border-box;
}

.login-screen-button-stack .login-screen-oauth-btn,
.login-screen-button-stack .login-screen-btn {
    flex: 0 0 auto;
    min-height: var(--login-btn-min-height);
    width: 100%;
    max-width: none;
    box-sizing: border-box;
}

/* 登录页 Google：与占位按钮同圆角，内部文字垂直居中并随条带增高 */
.login-screen .auth-google-capsule--hero.login-screen-oauth-btn {
    min-height: var(--login-btn-min-height);
    border-radius: var(--login-oauth-radius);
    padding: 0 24px;
    align-items: stretch;
}

.login-screen .auth-google-capsule--hero .auth-google-capsule-label {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: var(--login-btn-min-height);
    font-size: 34px;
    font-weight: 600;
}

.login-screen-btn {
    margin: 0;
    padding: 12px 24px;
    border: 1px solid var(--border-color);
    border-radius: var(--login-oauth-radius);
    background: var(--bg-elevated);
    color: var(--text-secondary);
    font: inherit;
    font-size: 30px;
    font-weight: 600;
    line-height: 1.2;
    text-align: center;
    cursor: not-allowed;
    opacity: 0.72;
    transition: border-color 0.2s ease, background 0.2s ease;
}

.login-screen-btn:disabled {
    pointer-events: none;
}

.login-screen-message {
    flex-shrink: 0;
    margin: 0 0 4px;
    min-height: 22px;
    width: 100%;
    color: var(--danger-color);
    font-size: 13px;
    text-align: left;
}

.login-screen-message--hidden {
    visibility: hidden;
}

.login-auth-hidden {
    display: none !important;
}

.login-screen-email-block {
    display: flex;
    flex-direction: column;
    gap: var(--login-btn-stack-gap);
    width: 100%;
}

.login-screen-input {
    margin: 0;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--login-oauth-radius);
    background: var(--bg-elevated);
    color: var(--text-primary);
    font: inherit;
    font-size: 18px;
    line-height: 1.3;
    box-sizing: border-box;
    width: 100%;
}

.login-screen-email-row {
    width: 100%;
}

.login-screen-btn:not(:disabled) {
    cursor: pointer;
    opacity: 1;
    color: var(--text-primary);
}

.login-screen-btn--primary {
    background: var(--accent-color);
    color: #fff;
    border-color: transparent;
}

.login-screen-btn--primary:hover {
    filter: brightness(1.06);
}

.login-screen-email-message {
    margin: 0;
    min-height: 18px;
    font-size: 13px;
    color: var(--danger-color);
    text-align: left;
}

@media (max-width: 900px) {
    .login-screen {
        flex-direction: column;
        align-items: stretch;
        padding: 20px 20px 24px;
        gap: 20px;
    }

    .login-screen-hero {
        flex: 0 0 auto;
        flex-direction: column;
        align-items: stretch;
        min-height: min(42vh, 320px);
    }

    .login-screen-hero-brand-wrap {
        flex: 0 0 auto;
        min-height: min(38vh, 280px);
        justify-content: center;
    }

    .login-screen-brand-cluster {
        max-width: none;
        width: 100%;
    }

    .login-screen-brand-a {
        --brand-a-cap: min(34vh, 46vw, 248px);
        margin: 50px 0 0 50px;
    }

    .login-screen-actions {
        flex: 0 0 auto;
        order: -1;
        width: 100%;
        max-width: none;
        min-width: 0;
        align-self: stretch;
        padding-top: 0;
    }
}

.app-container {
    display: flex;
    align-items: stretch;
    height: 100vh;
    height: 100dvh;
    padding: 0;
    gap: 0;
    position: relative;
    background: var(--app-chrome-main);
}

.app-container--hidden {
    display: none;
}

/* 常驻栏 + 会话列表：底栏在 .sidebar 内，仅展开侧栏时可见 */
.sidebar-dock {
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    min-height: 0;
    align-self: stretch;
    border: none;
    border-radius: 0;
    background: var(--app-chrome-sidebar);
    box-shadow: none;
    overflow: hidden;
}

.sidebar-dock-main {
    display: flex;
    flex-direction: row;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    position: relative;
}

/* 登录与版本号：贴在侧栏最底，与会话项同尺寸的胶囊，悬停高亮 */
.sidebar-dock-foot {
    flex-shrink: 0;
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    padding: 8px 0 2px;
}

.sidebar-capsule {
    position: relative;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    min-height: 52px;
    padding: 12px 14px;
    border: 1px solid transparent;
    border-radius: 16px;
    background: transparent;
    color: var(--text-secondary);
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.sidebar-capsule:hover {
    background: var(--bg-soft);
    border-color: var(--border-color);
    color: var(--text-primary);
}

.sidebar-capsule--auth .auth-panel-inner {
    width: 100%;
    min-width: 0;
}

.sidebar-capsule--clickable {
    cursor: pointer;
    text-decoration: none;
    color: inherit;
}

.sidebar-capsule--clickable:hover {
    color: var(--text-primary);
}

.sidebar-capsule--clickable:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.auth-google-capsule {
    width: 100%;
    min-height: 56px;
    padding: 0 18px;
    flex-direction: column;
    align-items: stretch;
    justify-content: center;
    gap: 0;
}

.auth-google-capsule-label {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 56px;
    font-size: var(--ui-copy-size);
    font-weight: var(--ui-copy-weight);
    line-height: var(--ui-copy-line-height);
    color: var(--text-secondary);
    text-align: center;
}

.auth-google-capsule--hero {
    width: min(100%, 420px);
    min-height: 88px;
    border-radius: 24px;
    background: var(--bg-elevated);
    border-color: var(--border-color);
}

.auth-google-capsule--hero .auth-google-capsule-label {
    min-height: 88px;
    font-size: 28px;
    font-weight: 600;
    color: var(--text-primary);
}

.sidebar-capsule--clickable:hover .auth-google-capsule-label {
    color: var(--text-primary);
}

.auth-panel-hint--in-capsule {
    margin: 0;
    text-align: center;
    color: var(--text-secondary);
}

.sidebar-capsule--clickable:hover .auth-panel-hint--in-capsule {
    color: var(--text-secondary);
}

/* 左侧常驻：侧栏开关 + 新建（无独立外框，贴在 dock 内左侧） */
.shell-rail {
    width: var(--shell-rail-width);
    flex: 0 0 var(--shell-rail-width);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    align-self: stretch;
    gap: 10px;
    padding: 12px 0;
    border: none;
    border-radius: 0;
    border-right: 1px solid var(--border-color);
    background: transparent;
    box-shadow: none;
}

.shell-rail-btn {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.18s ease, color 0.18s ease;
}

.shell-rail-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

body[data-theme="light"] .shell-rail-btn:hover {
    background: rgba(0, 0, 0, 0.06);
}

.shell-rail-btn:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.shell-rail-btn--accent {
    font-size: calc(var(--ui-copy-size) + 8px);
    font-weight: 400;
    line-height: 1;
    color: var(--text-secondary);
}

.shell-rail-btn--accent:hover {
    color: var(--text-primary);
}

.theme-toggle-rail-btn {
    font-size: 18px;
}

.theme-toggle-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
}

.theme-toggle-icon .theme-toggle-svg {
    display: block;
}

.shell-rail-plus {
    transform: translateY(-1px);
}

.shell-rail-chevron {
    transition: transform 0.24s ease;
}

.app-container.sidebar-collapsed .shell-rail-chevron {
    transform: rotate(180deg);
}

.sidebar {
    width: 286px;
    flex-shrink: 0;
    min-height: 0;
    align-self: stretch;
    display: flex;
    flex-direction: column;
    padding: 18px var(--sidebar-inline-padding);
    border: none;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    overflow: hidden;
    transition: width 0.24s ease, padding 0.24s ease, opacity 0.24s ease, transform 0.28s ease;
}

.sidebar-status {
    width: 100%;
    margin-left: 0;
    padding: 4px 0 16px;
    text-align: center;
    color: var(--text-secondary);
}

.sidebar-status--hidden {
    display: none;
}

.conversations-list--status-visible {
    min-height: 0;
}

.conversations-list--status-visible .conversations-container {
    overflow: hidden;
}

.app-container.sidebar-collapsed {
    gap: 0;
}

.app-container.sidebar-collapsed .sidebar {
    width: 0;
    padding-left: 0;
    padding-right: 0;
    opacity: 0;
    pointer-events: none;
    overflow: hidden;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo--compact {
    gap: 10px;
}

.logo--header-brand {
    gap: 0;
}

/* 与登录页 A* 同族：Playfair Display 斜体 + 右上角无衬线星号 */
.app-brand-mark {
    position: relative;
    display: inline-block;
    font-family: "Playfair Display", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, ui-serif, serif;
    font-weight: 700;
    font-style: italic;
    font-synthesis: none;
    letter-spacing: -0.05em;
    line-height: 0.88;
    color: var(--text-primary);
    user-select: none;
}

.app-brand-mark-inner {
    position: relative;
    display: inline-block;
}

.app-brand-mark-letter {
    display: inline-block;
}

.app-brand-mark-star {
    position: absolute;
    top: 0.02em;
    right: -0.4em;
    font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-style: normal;
    font-weight: 400;
    font-size: 0.66em;
    line-height: 1;
    letter-spacing: 0;
    color: inherit;
    pointer-events: none;
}

.app-brand-mark--header {
    font-size: clamp(27px, 4vw, 38px);
}

.app-brand-mark--avatar {
    font-size: 24px;
    line-height: 0.88;
}

.app-brand-mark--avatar .app-brand-mark-star {
    font-size: 0.66em;
    right: -0.4em;
}

.logo--compact .logo-icon {
    width: 34px;
    height: 34px;
    border-radius: 12px;
    font-size: 15px;
}

.logo--compact .logo-text {
    font-size: 15px;
}

.logo--compact .logo-subtext {
    font-size: 11px;
}

.logo-icon {
    width: 38px;
    height: 38px;
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-strong));
    box-shadow: none;
}

.logo-copy {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.logo-text {
    font-size: var(--ui-copy-size);
    font-weight: var(--ui-copy-weight);
    letter-spacing: var(--ui-copy-tracking);
    color: var(--text-secondary);
}

.logo-subtext {
    font-size: var(--ui-copy-size);
    color: var(--text-secondary);
}

.conversations-list {
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.conversations-container {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-right: 2px;
}

.conversations-container,
.messages-area {
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.12) transparent;
}

.conversations-container::-webkit-scrollbar,
.messages-area::-webkit-scrollbar {
    width: 6px;
}

.conversations-container::-webkit-scrollbar-thumb,
.messages-area::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.12);
    border-radius: 999px;
}

.conversations-container::-webkit-scrollbar-track,
.messages-area::-webkit-scrollbar-track {
    background: transparent;
}

.conversation-item {
    position: relative;
    display: flex;
    align-items: center;
    min-height: 52px;
    padding: 12px 40px 12px 14px;
    border: 1px solid transparent;
    border-radius: 16px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.conversation-item-label {
    display: block;
    min-width: 0;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-item:hover {
    background: var(--bg-soft);
    border-color: var(--border-color);
    color: var(--text-primary);
}

.conversation-item.active {
    background: var(--bg-soft-hover);
    border-color: var(--border-strong);
    color: var(--text-primary);
}

.conversation-item .delete-btn {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 26px;
    height: 26px;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: inherit;
    opacity: 0;
    cursor: pointer;
    transition: all 0.2s ease;
    z-index: 2;
}

.conversation-item:hover .delete-btn {
    opacity: 0.72;
}

.conversation-item .delete-btn:hover {
    background: rgba(255, 107, 129, 0.12);
    color: #ff8ea1;
    opacity: 1;
}

.empty-state {
    padding: 28px 12px;
    color: var(--text-secondary);
    text-align: center;
}

.auth-panel {
    margin-top: 0;
    padding: 0;
    border: none;
    border-radius: 0;
    background: transparent;
    width: 100%;
}

.auth-panel--hidden {
    display: none;
}

.auth-panel--login-cta {
    display: flex;
    justify-content: center;
}

.auth-panel-inner {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
    flex-wrap: wrap;
}

.auth-panel-user {
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
    flex: 1;
}

.auth-panel-logout {
    flex-shrink: 0;
    padding: 4px 0;
    border-radius: 0;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
}

.auth-panel-logout:hover {
    color: var(--text-primary);
    text-decoration: none;
}

.auth-panel-hint {
    margin-top: 6px;
    color: var(--text-secondary);
    text-align: left;
    line-height: 1.4;
}

.footer-version {
    padding: 0;
    border: none;
    border-radius: 0;
    background: transparent;
    color: var(--text-secondary);
}

.main-content {
    position: relative;
    z-index: 1;
    flex: 1;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    border: none;
    border-radius: 0;
    background: var(--app-chrome-main);
    box-shadow: none;
    overflow: hidden;
}

.main-chrome-stack {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    position: relative;
}

.main-chrome {
    flex-shrink: 0;
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 52px;
    padding: 10px 16px 10px 18px;
    border-bottom: none;
    background: transparent;
}

.main-chrome-brand {
    min-width: 0;
    position: relative;
    z-index: 1;
}

.main-chrome-spacer {
    display: none;
}

.main-chrome-brand,
.main-chrome-spacer {
    min-width: 0;
}

/* 桌面端侧栏按钮在 shell-rail；移动端顶栏左侧展开 + 右侧新对话/主题 */
.main-chrome-rail-toggle,
.main-chrome-rail-trailing {
    display: none;
}

.main-chrome-title {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    width: min(calc(100% - 32px), 320px);
    min-width: 0;
    margin: 0;
    padding: 0 8px;
    font-size: var(--ui-copy-size);
    font-weight: var(--ui-copy-weight);
    letter-spacing: var(--ui-copy-tracking);
    color: var(--text-secondary);
    text-align: center;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    z-index: 0;
}

.chat-container {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    width: 100%;
}

.chat-container.chat-container--composer-centered {
    justify-content: center;
}

.chat-container.chat-container--composer-centered .messages-area {
    display: none;
}

.composer-dock {
    flex-shrink: 0;
    width: 100%;
    box-sizing: border-box;
}

.chat-container.chat-container--composer-centered .composer-dock {
    width: min(100%, 940px);
    margin: 0 auto;
    padding: 0 28px;
}

.chat-container.chat-container--composer-centered .input-area {
    width: 100%;
    padding-left: 0;
    padding-right: 0;
}

.empty-composer-greeting {
    display: none;
    margin: 0 0 22px;
    padding-left: 15px;
    text-align: left;
}

.chat-container.chat-container--composer-centered .empty-composer-greeting {
    display: block;
}

.empty-composer-greeting-line1 {
    font-size: 25px;
    font-weight: 500;
    color: var(--text-primary);
    margin: 0 0 10px;
    line-height: 1.35;
}

.empty-composer-greeting-line2 {
    font-size: clamp(22px, 4.2vw, 32px);
    font-weight: 650;
    color: var(--text-primary);
    margin: 0;
    line-height: 1.2;
    letter-spacing: -0.02em;
}

.messages-area {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 20px 28px 18px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.messages-area-loading {
    flex: 1;
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: var(--text-secondary);
}

.messages-area-older-loading {
    flex-shrink: 0;
    padding: 8px 0 4px;
    text-align: center;
    font-size: 13px;
    color: var(--text-secondary);
}

.welcome-section {
    flex: 1;
    min-height: 280px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.welcome-orb {
    position: relative;
    width: 180px;
    height: 180px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.welcome-orb-core,
.welcome-orb-ring {
    position: absolute;
    border-radius: 50%;
}

.welcome-orb-core {
    width: 72px;
    height: 72px;
    background: radial-gradient(circle at 30% 30%, #ffffff, var(--primary-color) 40%, rgba(157, 124, 255, 0.9) 100%);
    box-shadow: 0 0 50px rgba(124, 156, 255, 0.45);
}

.welcome-orb-ring {
    border: 1px solid rgba(255, 255, 255, 0.12);
}

.welcome-orb-ring-one {
    width: 126px;
    height: 126px;
    animation: orbitPulse 5s linear infinite;
}

.welcome-orb-ring-two {
    width: 174px;
    height: 174px;
    border-color: rgba(124, 156, 255, 0.2);
    animation: orbitPulse 7s linear infinite reverse;
}

@keyframes orbitPulse {
    0% { transform: rotate(0deg) scale(1); opacity: 0.45; }
    50% { transform: rotate(180deg) scale(1.04); opacity: 0.75; }
    100% { transform: rotate(360deg) scale(1); opacity: 0.45; }
}

.message {
    width: min(100%, 920px);
    margin: 0 auto;
    display: flex;
    gap: 12px;
    animation: fadeUp 0.28s ease;
}

@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

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

.message-avatar {
    width: 34px;
    height: 34px;
    border-radius: 14px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    margin-top: 2px;
    border: 1px solid var(--border-color);
    background: var(--bg-soft);
}

.message.user .message-avatar {
    color: white;
    background: var(--primary-color);
}

.message.user .message-avatar.message-avatar--initial {
    font-size: 16px;
    font-weight: 700;
    font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    line-height: 1;
}

.message.assistant .message-avatar {
    color: var(--accent-color);
}

.message.assistant .message-avatar.message-avatar--brand {
    width: auto;
    height: auto;
    min-width: 0;
    min-height: 0;
    padding: 0;
    margin-top: 4px;
    border: none;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    color: var(--text-primary);
    overflow: visible;
    font-size: unset;
    line-height: 0;
    align-self: flex-start;
}

.message-bubble {
    max-width: min(75%, 720px);
    padding: 14px 16px;
    border-radius: 20px;
    font-size: 14px;
    line-height: 1.7;
    word-break: break-word;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-soft);
}

.message.user .message-bubble {
    background: var(--bubble-user);
    color: white;
    border-color: transparent;
    border-bottom-right-radius: 8px;
}

.message.assistant .message-bubble {
    background: var(--bubble-assistant);
    color: var(--text-primary);
    border-bottom-left-radius: 8px;
    border-color: transparent;
}

.message-bubble-pending {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-height: 52px;
    color: var(--text-secondary);
}

.pending-label {
    white-space: nowrap;
}

.pending-dots {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.pending-dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-tertiary);
    animation: pendingDotPulse 1.2s infinite ease-in-out;
}

.pending-dots span:nth-child(2) {
    animation-delay: 0.18s;
}

.pending-dots span:nth-child(3) {
    animation-delay: 0.36s;
}

@keyframes pendingDotPulse {
    0%, 80%, 100% {
        opacity: 0.35;
        transform: scale(0.85);
    }
    40% {
        opacity: 1;
        transform: scale(1);
    }
}

.message-image {
    display: block;
    max-width: 100%;
    max-height: 320px;
    margin-top: 10px;
    border-radius: 14px;
}

.message-image-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.message-image--thumb {
    width: 120px;
    height: 120px;
    max-width: none;
    max-height: none;
    margin-top: 0;
    object-fit: cover;
}

.input-area {
    width: min(100%, 940px);
    margin: 0 auto;
    padding: 0 28px 22px;
}

.uploaded-files {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
    flex-basis: 100%;
    min-height: 0;
    margin-bottom: 0;
    padding: 2px 2px 0;
}

.uploaded-files:empty {
    display: none;
}

.file-tag {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 76px;
    height: 76px;
    padding: 0;
    border: 1px solid var(--border-color);
    border-radius: 18px;
    background: var(--bg-soft);
}

.file-tag-preview {
    width: 100%;
    height: 100%;
    border-radius: inherit;
    object-fit: cover;
    display: block;
    background: rgba(255, 255, 255, 0.04);
}

.file-tag .remove-btn {
    position: absolute;
    top: -6px;
    right: -6px;
    z-index: 1;
    width: 24px;
    height: 24px;
    border: none;
    border-radius: 999px;
    background: var(--bg-elevated-strong);
    color: var(--text-secondary);
    box-shadow: var(--shadow-soft);
    cursor: pointer;
}

.file-tag .remove-btn:hover {
    color: var(--danger-color);
    background: var(--bg-soft);
}

.input-box-container {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    row-gap: 10px;
    padding: 10px 10px 10px 8px;
    border: 1px solid var(--border-color);
    border-radius: 26px;
    background: var(--bg-elevated-strong);
    box-shadow: var(--shadow-panel);
    transition: border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.input-box-container:focus-within {
    border-color: var(--border-strong);
    box-shadow: 0 0 0 4px rgba(124, 156, 255, 0.12), var(--shadow-panel);
}

.attach-btn,
.send-btn {
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    border: none;
    border-radius: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.attach-btn {
    background: transparent;
    color: var(--text-tertiary);
}

.attach-btn:hover {
    background: var(--bg-soft);
    color: var(--text-primary);
}

.message-input {
    display: block;
    align-self: center;
    flex: 1;
    min-height: 44px;
    max-height: 140px;
    height: 44px;
    padding: 11px 6px 11px 2px;
    margin: 0;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font: inherit;
    font-size: 15px;
    line-height: 22px;
    resize: none;
    overflow: hidden;
    scrollbar-width: none;
}

.message-input:focus {
    outline: none;
}

.message-input::-webkit-scrollbar {
    display: none;
}

.message-input::placeholder {
    color: var(--text-tertiary);
}

.input-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.source-select-wrap {
    position: relative;
    display: inline-flex;
    align-items: stretch;
}

.source-select-lock-hitbox {
    position: absolute;
    inset: 0;
    margin: 0;
    padding: 0;
    border: none;
    border-radius: 16px;
    background: transparent;
    cursor: pointer;
    z-index: 2;
}

.source-select-lock-hitbox:focus {
    outline: none;
}

.source-select-lock-hitbox:focus-visible {
    outline: 2px solid var(--border-strong);
    outline-offset: 2px;
}

.source-lock-toast {
    position: fixed;
    /* left / bottom / transform 由 showSourceLockHint 按选择器位置计算 */
    z-index: 10000;
    padding: 10px 16px;
    border-radius: 12px;
    background: var(--bg-elevated-strong);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-soft);
    font-size: 13px;
    font-weight: 500;
    max-width: min(90vw, 320px);
    text-align: center;
    pointer-events: none;
}

.source-lock-toast[hidden] {
    display: none !important;
}

.source-select-inline {
    height: 42px;
    min-width: 152px;
    max-width: 200px;
    padding: 0 10px;
    border: 1px solid var(--border-color);
    border-radius: 16px;
    background-color: var(--bg-soft);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    appearance: auto;
    -webkit-appearance: menulist;
    cursor: pointer;
    transition: all 0.2s ease;
}

.source-select-inline:hover,
.source-select-inline:focus {
    outline: none;
    color: var(--text-primary);
    border-color: var(--border-strong);
}

.source-select-inline:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.send-btn {
    color: white;
    background: var(--primary-color);
    box-shadow: none;
}

.send-btn:hover:not(:disabled) {
    transform: translateY(-1px);
}

.send-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    box-shadow: none;
}

.send-btn.send-btn--stop {
    width: auto;
    padding: 0 14px;
    border-radius: 16px;
    background: #ef4444;
    box-shadow: none;
}

.send-btn-stop-inner {
    font-size: 12px;
    font-weight: 700;
}

.app-meta {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0;
    padding-top: 10px;
    color: var(--text-tertiary);
    font-size: 11px;
}

.message-bubble-md {
    line-height: 1.7;
}

.message-bubble-md .katex-display {
    overflow-x: auto;
    overflow-y: hidden;
    max-width: 100%;
    padding: 0.4em 0;
}

.message-bubble-md .katex {
    font-size: 1.04em;
}

.message-bubble-md .math-fallback {
    font-family: ui-monospace, monospace;
    font-size: 0.85em;
    color: var(--text-secondary);
}

.message-bubble-md .math-error {
    font-family: ui-monospace, monospace;
    font-size: 0.85em;
    color: var(--danger-color);
}

.message-bubble-md p {
    margin: 0 0 0.7em;
}

.message-bubble-md p:last-child {
    margin-bottom: 0;
}

.message-bubble-md h1,
.message-bubble-md h2,
.message-bubble-md h3,
.message-bubble-md h4 {
    margin: 0.9em 0 0.45em;
    line-height: 1.35;
    font-weight: 700;
}

.message-bubble-md ul,
.message-bubble-md ol {
    margin: 0.45em 0 0.7em;
    padding-left: 1.35em;
}

.message-bubble-md li {
    margin: 0.22em 0;
}

.message-bubble-md pre {
    margin: 0.7em 0;
    padding: 13px 14px;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    background: var(--code-bg);
    overflow-x: auto;
}

.message-bubble-md code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    background: var(--code-bg);
    padding: 0.15em 0.38em;
    border-radius: 6px;
}

.message-bubble-md pre code {
    background: transparent;
    padding: 0;
}

.message-bubble-md blockquote {
    margin: 0.7em 0;
    padding-left: 12px;
    border-left: 3px solid var(--primary-color);
    color: var(--text-secondary);
}

.message-bubble-md a {
    color: var(--primary-color);
}

/* GFM 表格：单元格边框 + 表头底纹；外包 .table-scroll 便于横向滚动 */
.message-bubble-md .table-scroll {
    margin: 0.65em 0;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    background: var(--code-bg);
}

.message-bubble-md .table-scroll table {
    margin: 0;
    width: max-content;
    min-width: 100%;
    border-collapse: collapse;
    font-size: 0.96em;
    background: transparent;
}

.message-bubble-md table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.96em;
    margin: 0.65em 0;
}

.message-bubble-md th,
.message-bubble-md td {
    border: 1px solid var(--border-color);
    padding: 8px 11px;
    vertical-align: top;
    text-align: left;
}

.message-bubble-md thead th {
    background: var(--bg-soft);
    font-weight: 600;
    color: var(--text-primary);
}

body[data-theme="dark"] .message-bubble-md thead th {
    background: rgba(255, 255, 255, 0.06);
}

.message-bubble-md tbody tr:nth-child(even) td {
    background: rgba(127, 127, 127, 0.05);
}

body[data-theme="dark"] .message-bubble-md tbody tr:nth-child(even) td {
    background: rgba(255, 255, 255, 0.03);
}

.message-bubble-md .md-block + .message-image,
.message-bubble-md .message-image {
    margin-top: 10px;
}

@media (max-width: 960px) {
    .sidebar {
        width: 250px;
    }

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

@media (max-width: 768px) {
    :root {
        --shell-rail-width: 48px;
        --main-chrome-mobile-toolbar-h: 52px;
    }

    .app-container {
        padding: 0;
        gap: 0;
    }

    /* 不占水平宽度：会话抽屉改为 fixed 全屏偏左 */
    .sidebar-dock {
        flex: 0 0 0;
        width: 0;
        min-width: 0;
        max-width: 0;
        position: relative;
        z-index: 25;
        align-self: stretch;
        border: none;
        border-radius: 0;
        box-shadow: none;
        overflow: visible;
        pointer-events: none;
    }

    .sidebar-dock-main {
        overflow: visible;
        width: 0;
        min-width: 0;
    }

    .shell-rail {
        display: none;
    }

    .sidebar-dock-main .sidebar {
        position: fixed;
        top: calc(var(--main-chrome-mobile-toolbar-h) + env(safe-area-inset-top, 0px));
        left: 0;
        bottom: 0;
        z-index: 28;
        width: min(88vw, 320px);
        max-width: min(88vw, 100vw);
        padding: 16px var(--sidebar-inline-padding) 18px;
        border: none;
        border-radius: 0;
        background: var(--app-chrome-sidebar);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.12);
        overflow: hidden;
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transform: translateX(-12px);
        transition: transform 0.22s ease, opacity 0.18s ease, visibility 0.18s ease;
    }

    body[data-theme="dark"] .sidebar-dock-main .sidebar {
        box-shadow: 4px 0 28px rgba(0, 0, 0, 0.45);
    }

    .app-container.sidebar-collapsed .sidebar-dock-main .sidebar {
        width: min(88vw, 320px);
        max-width: min(88vw, 100vw);
        padding: 16px var(--sidebar-inline-padding) 18px;
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
    }

    .sidebar.show {
        pointer-events: auto;
        transform: translateX(0);
        opacity: 1;
        visibility: visible;
    }

    .app-container.mobile-sidebar-open .main-chrome-rail-toggle .shell-rail-chevron {
        transform: rotate(180deg);
    }

    .auth-panel--login-cta .auth-google-capsule {
        min-height: 64px;
        border-radius: 20px;
    }

    .auth-panel--login-cta .auth-google-capsule-label {
        min-height: 64px;
    }

    .main-content {
        border-radius: 0;
        border: none;
        flex: 1;
        min-width: 0;
        padding-top: calc(env(safe-area-inset-top, 0px) + var(--main-chrome-mobile-toolbar-h));
        box-sizing: border-box;
    }

    /* fixed 顶栏：安全区用 padding-top + 主色底，主区用 padding-top 占位 */
    .main-chrome-stack {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        width: 100%;
        box-sizing: border-box;
        z-index: 30;
        padding-top: env(safe-area-inset-top, 0px);
        background: var(--app-chrome-main);
        pointer-events: none;
    }

    .main-chrome-stack .main-chrome {
        pointer-events: auto;
    }

    .main-chrome {
        position: relative;
        padding: 6px max(12px, env(safe-area-inset-right, 0px)) 6px max(10px, env(safe-area-inset-left, 0px));
        min-height: var(--main-chrome-mobile-toolbar-h);
        justify-content: space-between;
        align-items: center;
        gap: 0;
        width: 100%;
        box-sizing: border-box;
        background: var(--app-chrome-main);
    }

    .main-chrome-rail-toggle {
        display: inline-flex;
        flex-shrink: 0;
    }

    .main-chrome-rail-trailing {
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 6px;
        flex-shrink: 0;
        margin-left: auto;
    }

    .main-chrome .shell-rail-btn {
        width: 38px;
        height: 38px;
    }

    .main-chrome-brand,
    .main-chrome-title {
        display: none;
    }

    .messages-area {
        padding: 16px 16px 14px;
    }

    .input-area {
        width: 100%;
        max-width: 100%;
        margin-left: auto;
        margin-right: auto;
        padding: 0 16px 16px;
        box-sizing: border-box;
    }

    .chat-container.chat-container--composer-centered .composer-dock {
        width: 100%;
        max-width: 100%;
        margin-left: auto;
        margin-right: auto;
        padding: 0 16px;
        box-sizing: border-box;
    }

    .empty-composer-greeting {
        margin-bottom: 18px;
        text-align: center;
        padding-left: 0;
    }

    .input-box-container {
        align-items: stretch;
    }

    /* iOS：输入/下拉字号 ≥16px 避免聚焦时整页缩放 */
    .message-input {
        order: 1;
        width: 100%;
        flex-basis: 100%;
        align-self: stretch;
        padding: 8px 10px 2px;
        font-size: 16px;
        line-height: 24px;
    }

    .attach-btn {
        order: 2;
    }

    .input-actions {
        order: 3;
        flex: 1;
        min-width: 0;
        margin-left: 0;
        max-width: none;
        justify-content: flex-end;
    }

    .source-select-wrap {
        flex: 1 1 auto;
        min-width: 0;
        max-width: none;
    }

    .source-select-inline {
        flex: 1 1 auto;
        min-width: 0;
        max-width: none;
        width: 100%;
        font-size: 16px;
    }

}

@media (max-width: 480px) {
    .messages-area {
        padding: 12px 12px 12px;
    }

    .message {
        gap: 10px;
    }

    .message-avatar {
        width: 30px;
        height: 30px;
        border-radius: 12px;
    }

    .message.assistant .message-avatar.message-avatar--brand {
        width: auto;
        height: auto;
    }

    .message.user .message-avatar.message-avatar--initial {
        font-size: 14px;
    }

    .app-brand-mark--avatar {
        font-size: 21px;
    }

    .message-bubble {
        max-width: calc(100% - 42px);
        padding: 12px 14px;
    }

    .message-image--thumb {
        width: 88px;
        height: 88px;
    }

    .attach-btn,
    .send-btn,
    .source-select-inline {
        height: 40px;
    }

    .file-tag {
        width: 60px;
        height: 60px;
        border-radius: 16px;
    }

}
