/* ============================================================
   对话创作（Chat Mode）
   - 复用全站设计令牌（--ds-*），深色模式自动跟随；
   - 桌面：会话列表 + 对话主区；移动端：会话列表变抽屉、输入区固定底部；
   - 只新增样式，不覆盖创作页既有规则（统一挂在 .chat-view 下）。
   ============================================================ */

/* ---------- 整体骨架 ---------- */
/* 选择器比 .module-view.is-active 多一层，确保按 flex 布局（本文件先于 workspace.css 加载） */
.module-view.chat-view.is-active {
    display: flex;
    height: 100%;
    min-height: 0;
}

.chat-shell {
    display: flex;
    flex: 1;
    min-width: 0;
    min-height: 0;
    border: 1px solid var(--ds-line);
    border-radius: var(--ds-radius-card);
    background: var(--ds-surface);
    box-shadow: var(--ds-shadow-sm);
    overflow: hidden;
}

/* hidden 属性必须压过下面的 display:flex/grid（UA 样式优先级太低） */
.chat-view [hidden] {
    display: none !important;
}

/* ---------- 会话列表 ---------- */
.chat-sessions {
    display: flex;
    flex-direction: column;
    width: 268px;
    flex-shrink: 0;
    min-height: 0;
    border-right: 1px solid var(--ds-line);
    background: var(--ds-surface-muted);
}

.chat-sessions-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 14px 10px;
}

.chat-sessions-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--ds-ink);
    letter-spacing: .02em;
}

.chat-new-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-left: auto;
    padding: 6px 10px;
    border: 1px solid var(--ds-line-strong);
    border-radius: 9px;
    background: var(--ds-surface);
    color: var(--ds-primary);
    font-size: 12px;
    font-weight: 650;
    cursor: pointer;
    transition: var(--ds-ease);
}

.chat-new-btn:hover {
    border-color: var(--ds-primary);
    background: var(--ds-primary-soft);
}

.chat-drawer-close {
    display: none;
    width: 30px;
    height: 30px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--ds-muted);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
}

.chat-search-row {
    padding: 0 12px 8px;
}

.chat-search {
    width: 100%;
    height: 30px;
    padding: 0 10px;
    border: 1px solid var(--ds-line);
    border-radius: 8px;
    outline: 0;
    background: var(--ds-surface);
    color: var(--ds-ink-soft);
    font-size: 12px;
    box-sizing: border-box;
}

.chat-search:focus {
    border-color: var(--ds-primary);
}

.chat-session-item {
    position: relative;
}

.chat-session-pin {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 22px;
    height: 22px;
    padding: 0;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--ds-muted);
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    opacity: 0;
    transition: opacity var(--ds-ease), background var(--ds-ease);
}

.chat-session-item:hover .chat-session-pin,
.chat-session-item.is-pinned .chat-session-pin {
    opacity: 1;
}

.chat-session-item.is-pinned .chat-session-pin {
    color: var(--ds-warning);
}

.chat-session-pin:hover {
    background: var(--ds-surface-muted);
}

@media (hover: none) {
    .chat-session-pin {
        opacity: 1;
    }
}

.chat-session-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 4px 8px 12px;
}

.chat-session-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 30px 9px 10px;
    margin-bottom: 2px;
    border: 1px solid transparent;
    border-radius: 11px;
    background: transparent;
    color: var(--ds-ink-soft);
    text-align: left;
    cursor: pointer;
    box-sizing: border-box;
    font: inherit;
    transition: background var(--ds-ease), border-color var(--ds-ease);
}

.chat-session-item:hover {
    background: var(--ds-surface);
}

.chat-session-item.active {
    background: var(--ds-surface);
    border-color: var(--ds-line-strong);
    box-shadow: var(--ds-shadow-sm);
}

.chat-session-thumb {
    width: 38px;
    height: 38px;
    flex-shrink: 0;
    border-radius: 9px;
    background: var(--ds-surface-muted);
    object-fit: cover;
}

.chat-session-thumb.is-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--ds-muted);
}

.chat-session-info {
    display: block;
    min-width: 0;
    flex: 1;
}

.chat-session-name {
    display: block;
    overflow: hidden;
    color: var(--ds-ink);
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.chat-session-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 3px;
    color: var(--ds-muted);
    font-size: 11px;
}

.chat-session-dot {
    width: 6px;
    height: 6px;
    border-radius: 999px;
    background: var(--ds-primary);
    animation: chat-pulse 1.4s ease-in-out infinite;
}

.chat-session-skeleton {
    height: 58px;
    margin: 4px 2px;
    border-radius: 11px;
    background: linear-gradient(100deg, var(--ds-surface-muted) 20%, var(--ds-surface) 40%, var(--ds-surface-muted) 60%);
    background-size: 220% 100%;
    animation: chat-shimmer 1.4s linear infinite;
}

/* ---------- 主区 ---------- */
.chat-main {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    background: var(--ds-surface);
}

.chat-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--ds-line);
    background: var(--ds-surface);
}

.chat-head-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    border: 1px solid transparent;
    border-radius: 9px;
    background: transparent;
    color: var(--ds-muted);
    cursor: pointer;
    transition: var(--ds-ease);
}

.chat-head-icon:hover {
    border-color: var(--ds-line);
    background: var(--ds-surface-muted);
    color: var(--ds-ink);
}

.chat-head-icon:disabled {
    opacity: .4;
    cursor: default;
}

.chat-sessions-toggle {
    display: none;
}

.chat-head-text {
    min-width: 0;
    flex: 1;
}

.chat-title {
    margin: 0;
    overflow: hidden;
    color: var(--ds-ink);
    font-size: 15px;
    font-weight: 700;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.chat-subtitle {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 3px;
    min-width: 0;
    color: var(--ds-muted);
    font-size: 11.5px;
}

.chat-engine-badge {
    flex-shrink: 0;
    padding: 1px 7px;
    border: 1px solid var(--ds-line);
    border-radius: 999px;
    background: var(--ds-surface-muted);
    color: var(--ds-ink-soft);
    font-size: 10.5px;
    font-weight: 600;
}

.chat-subtitle-hint {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.chat-head-actions {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
}

/* ---------- 版本条 ---------- */
.chat-versions {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    overflow-x: auto;
    border-bottom: 1px solid var(--ds-line);
    background: var(--ds-surface-muted);
}

.chat-version {
    position: relative;
    flex-shrink: 0;
    width: 46px;
    height: 46px;
    padding: 0;
    border: 2px solid transparent;
    border-radius: 10px;
    background: var(--ds-surface);
    cursor: pointer;
    overflow: hidden;
}

.chat-version img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.chat-version.active {
    border-color: var(--ds-primary);
}

.chat-version-label {
    position: absolute;
    right: 2px;
    bottom: 2px;
    padding: 0 4px;
    border-radius: 5px;
    background: rgba(0, 0, 0, .55);
    color: #fff;
    font-size: 9px;
    line-height: 14px;
}

.chat-version-arrow {
    flex-shrink: 0;
    color: var(--ds-muted);
    font-size: 12px;
}

/* ---------- 消息流 ---------- */
.chat-thread {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 18px 18px 8px;
    scroll-behavior: smooth;
    overscroll-behavior: contain;
}

.chat-thread::-webkit-scrollbar {
    width: 10px;
}

.chat-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100%;
    padding: 18px 16px 26px;
    text-align: center;
    box-sizing: border-box;
}

.chat-empty[hidden] {
    display: none;
}

.chat-empty-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 62px;
    height: 62px;
    margin-bottom: 14px;
    border-radius: 20px;
    background: var(--ds-primary-soft);
    color: var(--ds-primary);
}

.chat-empty-title {
    color: var(--ds-ink);
    font-size: 19px;
    font-weight: 700;
}

.chat-empty-text {
    max-width: 420px;
    margin-top: 7px;
    color: var(--ds-muted);
    font-size: 13px;
    line-height: 1.65;
}

.chat-examples {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    max-width: 560px;
    margin-top: 14px;
}

.chat-example {
    padding: 8px 12px;
    border: 1px solid var(--ds-line);
    border-radius: 999px;
    background: var(--ds-surface);
    color: var(--ds-ink-soft);
    font-size: 12px;
    cursor: pointer;
    transition: var(--ds-ease);
}

.chat-example:hover {
    border-color: var(--ds-primary);
    color: var(--ds-primary);
    background: var(--ds-primary-soft);
}

.chat-empty-upload {
    margin-top: 16px;
    padding: 7px 12px;
    border: 1px dashed var(--ds-line-strong);
    border-radius: 9px;
    background: transparent;
    color: var(--ds-muted);
    font-size: 12px;
    cursor: pointer;
}

.chat-empty-upload:hover {
    border-color: var(--ds-primary);
    color: var(--ds-primary);
}

/* 用户消息 */
.chat-msg {
    display: flex;
    gap: 10px;
    max-width: 820px;
    margin: 0 auto 18px;
}

.chat-msg-user {
    flex-direction: column;
    align-items: flex-end;
}

.chat-bubble {
    max-width: min(86%, 620px);
    padding: 10px 14px;
    border-radius: 16px 16px 4px 16px;
    background: var(--ds-primary);
    color: #fff;
    font-size: 13.5px;
    line-height: 1.65;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

:root[data-theme="dark"] .chat-bubble {
    color: #06120f;
}

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

.chat-msg-attachments img {
    width: 74px;
    height: 74px;
    border: 1px solid var(--ds-line);
    border-radius: 10px;
    object-fit: cover;
    cursor: zoom-in;
}

/* 助手消息 */
.chat-msg-assistant {
    align-items: flex-start;
}

.chat-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    flex-shrink: 0;
    margin-top: 2px;
    border-radius: 9px;
    background: linear-gradient(145deg, #0f766e, #14a899);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
}

.chat-msg-body {
    min-width: 0;
    flex: 1;
}

.chat-msg-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-bottom: 7px;
    color: var(--ds-muted);
    font-size: 11px;
}

.chat-msg-meta b {
    color: var(--ds-ink-soft);
    font-weight: 600;
}

.chat-msg-meta .chat-meta-sep {
    width: 3px;
    height: 3px;
    border-radius: 999px;
    background: var(--ds-line-strong);
}

.chat-image-grid {
    display: grid;
    gap: 8px;
    max-width: 520px;
}

.chat-image-grid.images-2,
.chat-image-grid.images-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.chat-image-grid.images-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.chat-image {
    position: relative;
    margin: 0;
    border: 1px solid var(--ds-line);
    border-radius: 14px;
    overflow: hidden;
    background: var(--ds-surface-muted);
}

.chat-image-btn {
    display: block;
    width: 100%;
    padding: 0;
    border: 0;
    background: transparent;
    cursor: zoom-in;
}

.chat-image-btn img {
    display: block;
    width: 100%;
    height: auto;
    max-height: 440px;
    object-fit: contain;
    background: var(--ds-surface-muted);
}

.chat-image-actions {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    gap: 5px;
    opacity: 0;
    transition: opacity var(--ds-ease);
}

.chat-image:hover .chat-image-actions,
.chat-image:focus-within .chat-image-actions {
    opacity: 1;
}

.chat-image-action {
    width: 30px;
    height: 30px;
    border: 0;
    border-radius: 8px;
    background: rgba(14, 24, 21, .62);
    color: #fff;
    font-size: 12px;
    cursor: pointer;
    backdrop-filter: blur(4px);
}

.chat-image-action:hover {
    background: rgba(14, 24, 21, .82);
}

/* 生成中 */
.chat-loading {
    max-width: 560px;
    border: 1px solid var(--ds-line);
    border-radius: 14px;
    background: var(--ds-surface-muted);
    overflow: hidden;
}

.chat-skeleton {
    width: 100%;
    aspect-ratio: 1 / 1;
    max-height: 420px;
    background: linear-gradient(100deg, var(--ds-surface-muted) 20%, var(--ds-surface) 40%, var(--ds-surface-muted) 60%);
    background-size: 220% 100%;
    animation: chat-shimmer 1.5s linear infinite;
}

.chat-skeleton.wide {
    aspect-ratio: 16 / 9;
}

.chat-skeleton.tall {
    aspect-ratio: 3 / 4;
}

.chat-loading-text {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 13px;
    color: var(--ds-ink-soft);
    font-size: 12px;
}

.chat-loading-text .spinner {
    width: 14px;
    height: 14px;
    border-width: 2px;
}

.chat-loading-elapsed {
    margin-left: auto;
    color: var(--ds-muted);
    font-variant-numeric: tabular-nums;
}

.chat-loading-steps {
    display: flex;
    gap: 5px;
    padding: 0 13px 11px;
}

.chat-loading-step {
    flex: 1;
    height: 3px;
    border-radius: 999px;
    background: var(--ds-line);
    transition: background var(--ds-ease);
}

.chat-loading-step.done {
    background: var(--ds-primary);
}

.chat-loading-step.active {
    background: linear-gradient(90deg, var(--ds-primary) 40%, var(--ds-line) 60%);
    background-size: 200% 100%;
    animation: chat-shimmer 1.2s linear infinite;
}

/* 失败 */
.chat-error {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    max-width: 560px;
    padding: 12px 14px;
    border: 1px solid rgba(194, 65, 75, .28);
    border-radius: 12px;
    background: rgba(194, 65, 75, .07);
    color: var(--ds-danger);
    font-size: 12.5px;
    line-height: 1.6;
}

.chat-error-text {
    flex: 1;
    min-width: 0;
    overflow-wrap: anywhere;
}

.chat-error button {
    flex-shrink: 0;
    padding: 5px 10px;
    border: 1px solid rgba(194, 65, 75, .35);
    border-radius: 8px;
    background: transparent;
    color: inherit;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

.chat-error button:hover {
    background: rgba(194, 65, 75, .12);
}

/* 操作条 */
.chat-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 8px;
}

.chat-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 9px;
    border: 1px solid var(--ds-line);
    border-radius: 8px;
    background: var(--ds-surface);
    color: var(--ds-ink-soft);
    font-size: 11.5px;
    cursor: pointer;
    transition: var(--ds-ease);
}

.chat-action-btn:hover {
    border-color: var(--ds-line-strong);
    background: var(--ds-surface-muted);
    color: var(--ds-ink);
}

.chat-action-btn.primary {
    border-color: rgba(15, 118, 110, .3);
    background: var(--ds-primary-soft);
    color: var(--ds-primary);
    font-weight: 600;
}

.chat-action-btn.primary:hover {
    border-color: var(--ds-primary);
}

.chat-action-btn.danger {
    color: var(--ds-danger);
    border-color: rgba(194, 65, 75, .25);
}

.chat-action-btn.danger:hover {
    background: rgba(194, 65, 75, .08);
    border-color: rgba(194, 65, 75, .45);
    color: var(--ds-danger);
}

.chat-action-btn:disabled {
    opacity: .45;
    cursor: default;
}

/* 提示词折叠 */
.chat-prompt {
    max-width: 560px;
    margin-top: 7px;
    border: 1px solid var(--ds-line);
    border-radius: 9px;
    background: var(--ds-surface-muted);
}

.chat-prompt summary {
    padding: 6px 10px;
    color: var(--ds-muted);
    font-size: 11.5px;
    cursor: pointer;
    list-style: none;
}

.chat-prompt summary::-webkit-details-marker {
    display: none;
}

.chat-prompt summary::before {
    content: "▸ ";
    color: var(--ds-muted);
}

.chat-prompt[open] summary::before {
    content: "▾ ";
}

.chat-prompt pre {
    margin: 0;
    padding: 0 10px 9px;
    color: var(--ds-ink-soft);
    font-family: inherit;
    font-size: 11.5px;
    line-height: 1.6;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

/* 回到底部 */
.chat-jump {
    position: absolute;
    left: 50%;
    bottom: 150px;
    transform: translateX(-50%);
    z-index: 5;
    padding: 6px 12px;
    border: 1px solid var(--ds-line-strong);
    border-radius: 999px;
    background: var(--ds-surface);
    color: var(--ds-ink-soft);
    font-size: 12px;
    box-shadow: var(--ds-shadow-sm);
    cursor: pointer;
}

.chat-main {
    position: relative;
}

/* ---------- 输入区 ---------- */
.chat-composer {
    flex-shrink: 0;
    padding: 10px 16px 12px;
    border-top: 1px solid var(--ds-line);
    background: var(--ds-surface);
}

.chat-edit-chip {
    display: flex;
    align-items: center;
    gap: 9px;
    width: fit-content;
    max-width: 100%;
    margin-bottom: 8px;
    padding: 5px 8px 5px 5px;
    border: 1px solid rgba(15, 118, 110, .3);
    border-radius: 10px;
    background: var(--ds-primary-soft);
}

.chat-edit-chip img {
    width: 34px;
    height: 34px;
    border-radius: 7px;
    object-fit: cover;
}

.chat-edit-chip-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
    color: var(--ds-primary);
    font-size: 11.5px;
    font-weight: 600;
}

.chat-edit-chip-text small {
    color: var(--ds-muted);
    font-weight: 500;
}

.chat-edit-chip button {
    width: 24px;
    height: 24px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--ds-muted);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
}

.chat-edit-chip button:hover {
    background: rgba(15, 118, 110, .12);
    color: var(--ds-ink);
}

.chat-attach-row {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    margin-bottom: 8px;
}

.chat-attach-item {
    position: relative;
    width: 56px;
    height: 56px;
    border: 1px solid var(--ds-line);
    border-radius: 9px;
    overflow: hidden;
    background: var(--ds-surface-muted);
}

.chat-attach-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-attach-item button {
    position: absolute;
    top: 1px;
    right: 1px;
    width: 17px;
    height: 17px;
    padding: 0;
    border: 0;
    border-radius: 5px;
    background: rgba(14, 24, 21, .65);
    color: #fff;
    font-size: 11px;
    line-height: 1;
    cursor: pointer;
}

.chat-attach-item.is-uploading::after {
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, .55);
    animation: chat-pulse 1.2s ease-in-out infinite;
}

:root[data-theme="dark"] .chat-attach-item.is-uploading::after {
    background: rgba(0, 0, 0, .45);
}

.chat-input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 6px 6px 6px 8px;
    border: 1px solid var(--ds-line-strong);
    border-radius: 14px;
    background: var(--ds-surface);
    transition: border-color var(--ds-ease), box-shadow var(--ds-ease);
}

.chat-input-row:focus-within {
    border-color: var(--ds-primary);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, .10);
}

.chat-attach-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--ds-muted);
    cursor: pointer;
}

.chat-attach-btn:hover {
    background: var(--ds-surface-muted);
    color: var(--ds-ink);
}

#chatInput {
    flex: 1;
    min-width: 0;
    max-height: 168px;
    padding: 8px 2px;
    border: 0;
    outline: 0;
    resize: none;
    background: transparent;
    color: var(--ds-ink);
    font-size: 13.5px;
    line-height: 1.6;
}

#chatInput::placeholder {
    color: var(--ds-muted);
}

.chat-send-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    flex-shrink: 0;
    border: 0;
    border-radius: 11px;
    background: var(--ds-primary);
    color: #fff;
    cursor: pointer;
    transition: var(--ds-ease);
}

.chat-send-btn:hover {
    background: var(--ds-primary-hover);
}

.chat-send-btn:disabled {
    background: var(--ds-line-strong);
    color: var(--ds-surface);
    cursor: default;
}

.chat-send-btn .spinner {
    width: 16px;
    height: 16px;
    border-width: 2px;
}

.chat-composer.is-dragover {
    outline: 2px dashed var(--ds-primary);
    outline-offset: -4px;
    border-radius: 12px;
    background: var(--ds-primary-soft);
}

.chat-msg.is-highlight {
    border-radius: 14px;
    box-shadow: 0 0 0 2px var(--ds-primary);
}

.chat-sessions-empty {
    padding: 26px 14px;
    color: var(--ds-muted);
    font-size: 12.5px;
    line-height: 1.8;
    text-align: center;
}

.chat-sessions-empty span {
    font-size: 11.5px;
    opacity: .8;
}

.chat-composer-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
    padding: 7px 3px 0;
}

.chat-mini-field {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    color: var(--ds-muted);
    font-size: 11px;
    white-space: nowrap;
}

.chat-mini-field select {
    height: 26px;
    padding: 0 22px 0 8px;
    border: 1px solid var(--ds-line);
    border-radius: 7px;
    background-color: var(--ds-surface);
    color: var(--ds-ink-soft);
    font-size: 11.5px;
    cursor: pointer;
}

.chat-composer-hint {
    margin-left: auto;
    color: var(--ds-muted);
    font-size: 10.5px;
}

.chat-polish-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 26px;
    padding: 0 9px;
    border: 1px solid var(--ds-line);
    border-radius: 8px;
    background: var(--ds-surface);
    color: var(--ds-ink-soft);
    font-size: 11px;
    cursor: pointer;
    transition: var(--ds-ease);
}

.chat-polish-btn:hover {
    border-color: var(--ds-accent);
    color: var(--ds-accent);
}

.chat-polish-btn:disabled {
    opacity: .5;
    cursor: default;
}

.chat-polish-btn .spinner {
    width: 12px;
    height: 12px;
    border-width: 2px;
}

.chat-cost-hint {
    color: var(--ds-warning);
    font-size: 10.5px;
}

/* ---------- 两版对比 ---------- */
.chat-compare {
    position: absolute;
    inset: 0;
    z-index: 60;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
    background: rgba(12, 22, 19, .55);
    backdrop-filter: blur(3px);
}

.chat-compare-dialog {
    display: flex;
    flex-direction: column;
    width: min(920px, 100%);
    max-height: 100%;
    border-radius: 16px;
    background: var(--ds-surface);
    box-shadow: var(--ds-shadow-md);
    overflow: hidden;
}

.chat-compare-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--ds-line);
    color: var(--ds-ink);
    font-size: 13px;
    font-weight: 700;
}

.chat-compare-head button {
    width: 30px;
    height: 30px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--ds-muted);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
}

.chat-compare-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    padding: 14px;
    overflow: auto;
}

.chat-compare-grid figure {
    margin: 0;
    min-width: 0;
}

.chat-compare-grid img {
    display: block;
    width: 100%;
    max-height: 62vh;
    border: 1px solid var(--ds-line);
    border-radius: 10px;
    background: var(--ds-surface-muted);
    object-fit: contain;
}

.chat-compare-grid figcaption {
    margin-top: 6px;
    color: var(--ds-muted);
    font-size: 11.5px;
    text-align: center;
}

/* ---------- 会话抽屉（移动端） ---------- */
.chat-drawer-overlay {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 30;
    background: rgba(18, 35, 31, .30);
    backdrop-filter: blur(2px);
}

.chat-view {
    position: relative;
}

/* ---------- 隐藏与对话模式无关的全局部件 ---------- */
body.chat-mode .app-sidebar .history-sidebar {
    display: none;
}

body.chat-mode .mobile-bottom-bar {
    display: none !important;
}

/* ---------- 动画 ---------- */
@keyframes chat-shimmer {
    from { background-position: 120% 0; }
    to { background-position: -20% 0; }
}

@keyframes chat-pulse {
    0%, 100% { opacity: .35; }
    50% { opacity: 1; }
}

@keyframes chat-fade-up {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: none; }
}

.chat-msg {
    animation: chat-fade-up .18s ease both;
}

/* ---------- 响应式 ---------- */
@media (max-width: 1180px) {
    .chat-sessions {
        width: 232px;
    }
}

@media (max-width: 900px) {
    .chat-sessions {
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        z-index: 40;
        width: min(300px, 84vw);
        transform: translateX(-104%);
        transition: transform var(--ds-ease);
        box-shadow: var(--ds-shadow-md);
        background: var(--ds-surface);
    }

    .chat-view.sessions-open .chat-sessions {
        transform: none;
    }

    .chat-view.sessions-open .chat-drawer-overlay {
        display: block;
    }

    .chat-drawer-close {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .chat-sessions-toggle {
        display: inline-flex;
    }

    .chat-thread {
        padding: 14px 12px 6px;
    }

    .chat-msg {
        margin-bottom: 14px;
    }

    .chat-composer {
        padding: 8px 10px calc(10px + env(safe-area-inset-bottom));
    }

    .chat-composer-hint {
        display: none;
    }

    .chat-image-btn img {
        max-height: 62vh;
    }

    .chat-jump {
        bottom: 160px;
    }
}

@media (max-width: 560px) {
    .chat-shell {
        border: 0;
        border-radius: 0;
        box-shadow: none;
    }

    .chat-compare {
        padding: 0;
    }

    .chat-compare-dialog {
        width: 100%;
        height: 100%;
        max-height: none;
        border-radius: 0;
    }

    .chat-compare-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .chat-head {
        padding: 8px 10px;
    }

    .chat-subtitle-hint {
        display: none;
    }

    .chat-head-actions .chat-head-icon:not(#chatDeleteBtn):not(#chatRenameBtn):not(#chatExportBtn) {
        display: none;
    }

    .chat-bubble {
        max-width: 92%;
        font-size: 13px;
    }

    .chat-avatar {
        display: none;
    }

    .chat-msg-assistant {
        gap: 0;
    }

    .chat-image-grid,
    .chat-loading,
    .chat-error,
    .chat-prompt {
        max-width: 100%;
    }

    .chat-image-actions {
        opacity: 1;
    }

    .chat-action-btn {
        padding: 7px 9px;
        font-size: 12px;
    }

    .chat-composer-bar {
        gap: 8px;
    }

    .chat-cost-hint {
        width: 100%;
    }

    .chat-versions {
        padding: 6px 10px;
    }

    .chat-version {
        width: 40px;
        height: 40px;
    }
}
