/* ============ 全局变量 ============ */
:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f3460;
    --bg-card: #1e2a4a;
    --bg-hover: #253358;
    --border-color: #2d3d65;
    --text-primary: #e8ecf4;
    --text-secondary: #a0aec0;
    --text-muted: #718096;
    --accent: #e94560;
    --accent-hover: #ff6b81;
    --accent-glow: rgba(233, 69, 96, 0.3);
    --user-bubble: #2d5a87;
    --ai-bubble: #2a3f5f;
    --success: #48bb78;
    --error: #f56565;
    --radius: 10px;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    --transition: all 0.2s ease;
}

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

body {
    font-family: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    line-height: 1.6;
}

/* ============ 应用布局 ============ */
.app {
    display: flex;
    height: 100vh;
    height: 100dvh;
}

/* 移动端汉堡菜单按钮：桌面端隐藏 */
.btn-menu {
    display: none;
    width: 40px;
    height: 40px;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border: none;
    border-radius: 10px;
    color: var(--text-primary);
    cursor: pointer;
    flex-shrink: 0;
}

/* 移动端抽屉遮罩：桌面端隐藏 */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 90;
}

/* 触摸端：去掉双击缩放与点击延迟 */
button,
.character-item,
.conv-item,
.checkbox-label {
    touch-action: manipulation;
}

/* ============ 侧边栏 ============ */
.sidebar {
    width: 300px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 16px;
    gap: 16px;
    overflow-y: auto;
}

.sidebar-header {
    text-align: center;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header h1 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.subtitle {
    font-size: 12px;
    color: var(--text-muted);
}

/* Ollama 状态卡 */
.status-card {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    font-size: 13px;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: pulse 2s infinite;
}

.status-card.connected .status-dot {
    background: var(--success);
    box-shadow: 0 0 8px var(--success);
}

.status-card.disconnected .status-dot {
    background: var(--error);
    box-shadow: 0 0 8px var(--error);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* 区块 */
.section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.section.flex-1 {
    flex: 1;
    min-height: 0;
}

.section-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* 模型选择 */
.select-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.select {
    width: 100%;
    padding: 10px 12px;
    padding-right: 44px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
    transition: var(--transition);
}

.select:hover {
    border-color: var(--accent);
}

.select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.btn-icon {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    padding: 4px 8px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 12px;
    line-height: 1.4;
    transition: var(--transition);
}

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

/* 角色列表 */
.character-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 200px;
    overflow-y: auto;
}

.character-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid transparent;
}

.character-item:hover {
    background: var(--bg-hover);
}

.character-item.active {
    background: var(--accent);
    border-color: var(--accent);
}

.character-item .avatar {
    font-size: 20px;
}

.character-item .char-info {
    flex: 1;
    min-width: 0;
}

.character-item .char-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.character-item.active .char-name {
    color: #fff;
}

.character-item .char-desc {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 对话列表 */
.conv-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    overflow-y: auto;
    min-height: 60px;
}

.conv-item {
    padding: 10px 12px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid transparent;
    position: relative;
}

.conv-item:hover {
    background: var(--bg-hover);
}

.conv-item.active {
    background: var(--bg-card);
    border-color: var(--accent);
}

.conv-item .conv-preview {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conv-item .conv-del {
    display: none;
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: var(--error);
    cursor: pointer;
    font-size: 14px;
    padding: 2px 6px;
    border-radius: 4px;
}

.conv-item:hover .conv-del {
    display: block;
}

/* 按钮 */
.btn-secondary {
    padding: 8px 14px;
    background: transparent;
    border: 1px dashed var(--border-color);
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 13px;
    transition: var(--transition);
    width: 100%;
}

.btn-secondary:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
    color: var(--accent);
}

.btn-primary {
    padding: 10px 20px;
    background: var(--accent);
    border: none;
    border-radius: 8px;
    color: #fff;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: var(--transition);
}

.btn-primary:hover {
    background: var(--accent-hover);
    box-shadow: 0 0 12px var(--accent-glow);
}

.btn-danger {
    padding: 10px 20px;
    background: transparent;
    border: 1px solid var(--error);
    border-radius: 8px;
    color: var(--error);
    cursor: pointer;
    font-size: 14px;
    transition: var(--transition);
}

.btn-danger:hover {
    background: var(--error);
    color: #fff;
}

/* ============ 聊天区 ============ */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
}

/* 头部 */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.chat-info {
    display: flex;
    align-items: center;
    gap: 14px;
}

.char-avatar {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    background: var(--bg-tertiary);
    border-radius: 12px;
}

.char-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.char-model {
    font-size: 12px;
    color: var(--text-muted);
}

.chat-actions {
    display: flex;
    gap: 8px;
}

.btn-tool {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border: none;
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 16px;
    transition: var(--transition);
}

.btn-tool:hover {
    background: var(--bg-hover);
    color: var(--accent);
}

/* 消息区 */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.empty-hint {
    margin: auto;
    text-align: center;
    color: var(--text-muted);
}

.empty-icon {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

/* 消息气泡 */
.message {
    display: flex;
    gap: 12px;
    max-width: 85%;
    animation: fadeInUp 0.3s ease;
}

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

.message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message .msg-avatar {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    border-radius: 10px;
    flex-shrink: 0;
}

.message.ai .msg-avatar {
    background: var(--bg-tertiary);
}

.message.user .msg-avatar {
    background: var(--user-bubble);
}

.message .msg-bubble {
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.7;
    white-space: pre-wrap;
    word-break: break-word;
}

.message.ai .msg-bubble {
    background: var(--ai-bubble);
    border-bottom-left-radius: 4px;
}

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

/* 打字光标 */
.typing-cursor {
    display: inline-block;
    width: 2px;
    height: 16px;
    background: var(--accent);
    margin-left: 2px;
    animation: blink 1s infinite;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* 加载动画 */
.loading {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.loading span {
    width: 8px;
    height: 8px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.loading span:nth-child(1) { animation-delay: -0.32s; }
.loading span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* ============ 输入区 ============ */
.input-area {
    padding: 16px 24px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
}

.input-wrapper {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 10px 12px;
    transition: var(--transition);
}

.input-wrapper:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

#userInput {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    resize: none;
    max-height: 160px;
    min-height: 24px;
    line-height: 1.6;
}

#userInput:focus {
    outline: none;
}

#userInput::placeholder {
    color: var(--text-muted);
}

.input-tools {
    display: flex;
    gap: 8px;
}

.btn-send {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent);
    border: none;
    border-radius: 10px;
    color: #fff;
    cursor: pointer;
    transition: var(--transition);
}

.btn-send:hover:not(:disabled) {
    background: var(--accent-hover);
    box-shadow: 0 0 12px var(--accent-glow);
}

.btn-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.input-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
}

.checkbox-label input {
    accent-color: var(--accent);
}

.char-count {
    font-size: 12px;
    color: var(--text-muted);
}

/* ============ 传图 ============ */
.btn-attach {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 16px;
    flex-shrink: 0;
    transition: var(--transition);
}

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

.btn-attach:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* 待发送图片预览条 */
.image-preview {
    display: none;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
}

.image-preview.has-items {
    display: flex;
}

.image-thumb {
    position: relative;
    width: 64px;
    height: 64px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
}

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

.image-thumb .thumb-status {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    font-size: 11px;
}

.image-thumb .thumb-del {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 20px;
    height: 20px;
    padding: 0;
    line-height: 18px;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.65);
    color: #fff;
    font-size: 12px;
    cursor: pointer;
}

.image-thumb.error {
    border-color: var(--error);
}

.image-thumb.error .thumb-del {
    background: var(--error);
}

/* 消息气泡里的图片 */
.msg-images {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.msg-images img {
    display: block;
    max-width: 200px;
    max-height: 200px;
    border-radius: 8px;
    cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

/* ============ 弹窗 ============ */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    width: 500px;
    max-width: 90vw;
    max-height: 85vh;
    background: var(--bg-secondary);
    border-radius: 16px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border-color);
    animation: modalIn 0.2s ease;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 24px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    font-size: 18px;
    font-weight: 600;
}

.btn-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
    transition: var(--transition);
}

.btn-close:hover {
    color: var(--accent);
}

.modal-body {
    padding: 20px 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.modal-footer {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
}

.flex-spacer {
    flex: 1;
}

/* 表单 */
.form-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-row label {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

.input {
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    transition: var(--transition);
}

.input:focus {
    outline: none;
    border-color: var(--accent);
}

.input-sm {
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 16px;
    width: 80px;
    text-align: center;
}

.textarea {
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
    min-height: 80px;
    transition: var(--transition);
}

.textarea:focus {
    outline: none;
    border-color: var(--accent);
}

/* ============ Toast ============ */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-left: 3px solid var(--accent);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    box-shadow: var(--shadow);
    animation: toastIn 0.3s ease;
}

.toast.error { border-left-color: var(--error); }
.toast.success { border-left-color: var(--success); }

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(100px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ============ 滚动条 ============ */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-color);
}

/* ============ 登录 / 注册 ============ */
.auth-gate {
    position: fixed;
    inset: 0;
    z-index: 3000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: var(--bg-primary);
}

.auth-gate.show {
    display: flex;
}

.auth-card {
    width: 100%;
    max-width: 350px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 26px 22px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.auth-card h1 {
    font-size: 24px;
    text-align: center;
}

.auth-sub {
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
    margin-top: -6px;
}

.auth-tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border-color);
    margin-top: 4px;
}

.auth-tab {
    flex: 1;
    padding: 9px 0;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
}

.auth-tab.active {
    color: var(--text-primary);
    border-bottom-color: var(--accent);
}

#authForm {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.auth-input {
    padding: 11px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 16px;
    font-family: inherit;
}

.auth-input:focus {
    outline: none;
    border-color: var(--accent);
}

.auth-btn {
    padding: 12px;
    background: var(--accent);
    border: none;
    border-radius: 8px;
    color: #fff;
    font-size: 15px;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.auth-btn:hover {
    background: var(--accent-hover);
}

.auth-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.auth-msg {
    min-height: 18px;
    font-size: 13px;
    text-align: center;
    color: var(--error);
}

.auth-msg.ok {
    color: var(--success);
}

.auth-key {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 12px;
    background: var(--bg-tertiary);
    border: 1px dashed var(--border-color);
    border-radius: 8px;
}

.auth-key-label {
    font-size: 12px;
    color: var(--text-secondary);
}

.auth-key code,
#authKeyValue {
    font-family: ui-monospace, Menlo, Consolas, monospace;
    font-size: 12px;
    word-break: break-all;
    color: var(--accent);
}

.auth-copy,
.user-copy {
    align-self: flex-start;
    padding: 4px 10px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
}

.auth-copy:hover,
.user-copy:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* ============ 侧边栏账号卡 ============ */
.user-card {
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.user-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.user-name {
    font-size: 14px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-logout {
    flex-shrink: 0;
    padding: 3px 9px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
}

.user-logout:hover {
    color: var(--error);
    border-color: var(--error);
}

.user-key-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.user-key {
    flex: 1;
    min-width: 0;
    font-family: ui-monospace, Menlo, Consolas, monospace;
    font-size: 11px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ============ 响应式：手机 / 窄屏 ============ */
@media (max-width: 768px) {
    /* 侧边栏改为可滑出的抽屉 */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(84vw, 320px);
        z-index: 100;
        padding: 14px;
        gap: 14px;
        border-right: 1px solid var(--border-color);
        box-shadow: var(--shadow);
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        -webkit-overflow-scrolling: touch;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-backdrop.show {
        display: block;
    }

    .btn-menu {
        display: flex;
    }

    /* 顶部栏：汉堡 + 信息 + 操作 */
    .chat-header {
        padding: 10px 12px;
        gap: 10px;
    }

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

    .chat-info > div {
        min-width: 0;
    }

    .char-name,
    .char-model {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .char-avatar {
        width: 38px;
        height: 38px;
        font-size: 22px;
        border-radius: 10px;
    }

    .char-name {
        font-size: 15px;
    }

    .char-model {
        font-size: 11px;
    }

    .chat-actions {
        gap: 6px;
    }

    .btn-tool {
        width: 38px;
        height: 38px;
        font-size: 15px;
    }

    /* 消息区 */
    .messages {
        padding: 14px 12px;
        gap: 14px;
    }

    /* 触摸设备没有 hover，删除对话按钮改为常驻 */
    .conv-item .conv-del {
        display: block;
        font-size: 16px;
        padding: 6px 10px;
    }

    .message {
        max-width: 94%;
        gap: 8px;
    }

    .message .msg-avatar {
        width: 34px;
        height: 34px;
        font-size: 18px;
    }

    .message .msg-bubble {
        padding: 10px 13px;
        font-size: 15px;
        line-height: 1.65;
    }

    /* 输入区：加大点击区域，字号 ≥16px 避免 iOS 聚焦时自动放大 */
    .input-area {
        padding: 10px 12px;
        padding-bottom: calc(10px + env(safe-area-inset-bottom));
    }

    .input-wrapper {
        padding: 8px 10px;
        gap: 8px;
    }

    #userInput {
        font-size: 16px;
        max-height: 120px;
    }

    .btn-send {
        width: 44px;
        height: 44px;
        border-radius: 12px;
    }

    /* 表单元素统一 16px，避免聚焦缩放 */
    .input,
    .textarea,
    .select {
        font-size: 16px;
    }

    .btn-primary,
    .btn-secondary,
    .btn-danger {
        padding-top: 11px;
        padding-bottom: 11px;
    }

    .btn-close {
        font-size: 22px;
        padding: 6px 10px;
    }

    /* 弹窗：铺满宽度，高度适配移动端可视区 */
    .modal-content {
        width: 100%;
        max-width: 100%;
        max-height: 88dvh;
        border-radius: 14px;
    }

    .modal-header,
    .modal-body,
    .modal-footer {
        padding-left: 16px;
        padding-right: 16px;
    }

    /* Toast 移到底部，避免被输入法键盘遮挡 */
    .toast-container {
        top: auto;
        bottom: calc(16px + env(safe-area-inset-bottom));
        left: 12px;
        right: 12px;
    }

    .toast {
        width: 100%;
        text-align: center;
    }
}

/* 超窄屏进一步压缩 */
@media (max-width: 380px) {
    .char-avatar {
        display: none;
    }

    .btn-tool {
        width: 34px;
        height: 34px;
        font-size: 14px;
    }
}
