/* ===== SOLOOMO Mobile WebUI Stylesheet (Kimi-inspired + Segment Rendering) ===== */

/* ---------- 配色变量 ---------- */
:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f7f7f8;
    --bg-chat: #ffffff;
    --text-primary: #1a1a1a;
    --text-secondary: #8e8e93;
    --text-tertiary: #b0b0b5;
    --accent: #6366f1;
    --accent-hover: #5558e0;
    --accent-light: rgba(99, 102, 241, 0.1);
    --danger: #ff3b30;
    --success: #34c759;
    --warning: #ff9500;
    --border: #ececec;
    --border-strong: #e0e0e0;
    --shadow: rgba(0, 0, 0, 0.06);
    --shadow-strong: rgba(0, 0, 0, 0.12);
    --msg-user: #e6e6e6;
    --msg-user-text: #1a1a1a;
    --code-bg: #f4f4f5;
    --code-border: #e8e8ea;
    --header-bg: var(--bg-primary);
    --header-text: var(--text-primary);
    --overlay: rgba(0, 0, 0, 0.35);
    --transition: 0.2s ease-out;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-xl: 22px;
    --reasoning-bg: rgba(99, 102, 241, 0.06);
    --reasoning-border: rgba(99, 102, 241, 0.2);
    --tool-card-bg: rgba(99, 102, 241, 0.04);
    --tool-card-border: rgba(99, 102, 241, 0.15);
}

[data-theme="dark"] {
    --bg-primary: #1a1a1a;
    --bg-secondary: #212121;
    --bg-chat: #1a1a1a;
    --text-primary: #ececec;
    --text-secondary: #8e8e93;
    --text-tertiary: #6a6a6f;
    --accent: #818cf8;
    --accent-hover: #6f78e8;
    --accent-light: rgba(129, 140, 248, 0.12);
    --border: #2f2f2f;
    --border-strong: #3a3a3a;
    --shadow: rgba(0, 0, 0, 0.3);
    --shadow-strong: rgba(0, 0, 0, 0.5);
    --msg-user: #333334;
    --msg-user-text: #ececec;
    --code-bg: #2a2a2a;
    --code-border: #353535;
    --header-bg: var(--bg-primary);
    --header-text: var(--text-primary);
    --overlay: rgba(0, 0, 0, 0.5);
    --reasoning-bg: rgba(129, 140, 248, 0.08);
    --reasoning-border: rgba(129, 140, 248, 0.2);
    --tool-card-bg: rgba(129, 140, 248, 0.06);
    --tool-card-border: rgba(129, 140, 248, 0.15);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Segoe UI", Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 16px;
    line-height: 1.65;
    -webkit-font-smoothing: antialiased;
}

.page {
    display: none;
    width: 100%;
    height: 100%;
    flex-direction: column;
    position: absolute;
    top: 0;
    left: 0;
    background: var(--bg-primary);
}
.page.active { display: flex; }
.sub-page { z-index: 10; }

/* ===== Login Page ===== */
.login-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 30px 24px;
    padding-top: max(60px, env(safe-area-inset-top));
    background: var(--bg-primary);
}
.login-logo { text-align: center; margin-bottom: 48px; color: var(--text-primary); }
.logo-icon { font-size: 56px; display: block; margin-bottom: 12px; }
.login-logo h1 { font-size: 26px; font-weight: 700; letter-spacing: 0.5px; }
.login-subtitle { font-size: 14px; color: var(--text-secondary); margin-top: 6px; }
.login-form { width: 100%; max-width: 340px; }
.input-group { margin-bottom: 18px; }
.input-group label { display: block; font-size: 14px; color: var(--text-secondary); margin-bottom: 8px; font-weight: 500; }
.input-group input {
    width: 100%; padding: 14px 16px; border: 1.5px solid var(--border-strong);
    border-radius: var(--radius-md); font-size: 16px; background: var(--bg-primary);
    color: var(--text-primary); transition: border-color var(--transition);
}
.input-group input:focus { outline: none; border-color: var(--accent); }
.input-group input::placeholder { color: var(--text-tertiary); }

.auth-switch { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-bottom: 18px; font-size: 13px; color: var(--text-secondary); }
.auth-switch .switch { width: 44px; height: 26px; }
.auth-switch .slider:before { height: 22px; width: 22px; }
.auth-switch .switch input:checked + .slider:before { transform: translateX(18px); }

.btn-primary {
    width: 100%; padding: 14px; border: none; border-radius: var(--radius-md);
    background: var(--accent); color: #fff; font-size: 16px; font-weight: 600;
    cursor: pointer; transition: background var(--transition), transform var(--transition);
}
.btn-primary:active { transform: scale(0.97); background: var(--accent-hover); }
.login-error { color: var(--danger); font-size: 13px; text-align: center; margin-top: 14px; min-height: 18px; }
.login-footer { margin-top: 36px; text-align: center; }
.login-footer p { color: var(--text-secondary); font-size: 12px; line-height: 1.6; }
.login-footer code {
    background: var(--bg-secondary); padding: 3px 8px; border-radius: 6px;
    font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 12px; color: var(--accent);
}

/* ===== Chat Header ===== */
.chat-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 8px; background: var(--header-bg); color: var(--header-text);
    min-height: 48px; padding-top: env(safe-area-inset-top);
    border-bottom: 0.5px solid var(--border); transition: background var(--transition);
}
.header-btn {
    background: none; border: none; color: var(--header-text); font-size: 20px;
    width: 40px; height: 40px; display: flex; align-items: center; justify-content: center;
    cursor: pointer; border-radius: var(--radius-sm); transition: background var(--transition);
}
.header-btn:active { background: var(--bg-secondary); }
.header-title {
    display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: 15px;
    flex: 1; justify-content: center; position: relative; cursor: pointer;
    padding: 4px 12px; border-radius: var(--radius-sm); transition: background var(--transition);
    max-width: 200px;
}
.header-title:active { background: var(--bg-secondary); }
.header-title #currentAgent { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.agent-dropdown-arrow { font-size: 12px; color: var(--text-secondary); flex-shrink: 0; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; }
.status-dot.online { background: var(--success); }
.status-dot.offline { background: var(--danger); }

/* ===== Agent Dropdown (重新设计) ===== */
.agent-dropdown {
    position: absolute; top: calc(100% + 6px); left: 50%; transform: translateX(-50%);
    min-width: 220px; max-width: 300px; max-height: 320px; overflow-y: auto;
    background: var(--bg-primary); border: 0.5px solid var(--border-strong);
    border-radius: var(--radius-md); box-shadow: 0 8px 32px var(--shadow-strong);
    z-index: 200; padding: 4px 0; animation: dropdownFadeIn 0.15s ease-out;
}
.agent-dropdown.hidden { display: none !important; }
@keyframes dropdownFadeIn {
    from { opacity: 0; transform: translateX(-50%) translateY(-4px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}
.agent-dropdown-item {
    display: flex; align-items: center; gap: 10px; padding: 10px 16px;
    cursor: pointer; transition: background var(--transition);
}
.agent-dropdown-item:active { background: var(--accent-light); }
.agent-dropdown-item.active { background: var(--accent-light); }
.agent-dropdown-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.agent-dropdown-name {
    font-size: 14px; font-weight: 500; color: var(--text-primary);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.agent-dropdown-meta { font-size: 11px; color: var(--text-tertiary); }
.agent-dropdown-check { font-size: 14px; color: var(--accent); flex-shrink: 0; }
.agent-dropdown-loading { color: var(--text-tertiary) !important; font-size: 13px; justify-content: center; }

/* ===== Message List ===== */
.message-list {
    flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
    padding: 16px; background: var(--bg-chat);
}
.welcome-msg { text-align: center; margin-top: 20vh; padding: 0 20px; }
.welcome-icon { font-size: 48px; margin-bottom: 16px; }
.welcome-title { font-size: 22px; font-weight: 700; color: var(--text-primary); margin-bottom: 8px; }
.welcome-subtitle { font-size: 15px; color: var(--text-secondary); margin-bottom: 28px; line-height: 1.5; }
.welcome-cards { display: flex; flex-direction: column; gap: 10px; max-width: 340px; margin: 0 auto; }
.welcome-card {
    background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-md);
    padding: 14px 18px; font-size: 14px; color: var(--text-primary); text-align: left;
    cursor: pointer; transition: background var(--transition), border-color var(--transition);
}
.welcome-card:active { background: var(--accent-light); border-color: var(--accent); }

/* Message bubbles */
.msg-bubble {
    max-width: 80%; padding: 10px 16px; border-radius: var(--radius-lg); margin-bottom: 16px;
    word-wrap: break-word; word-break: break-word; animation: fadeIn 0.25s ease-out;
    position: relative; font-size: 16px; line-height: 1.65;
}
.msg-bubble.user { background: var(--msg-user); color: var(--msg-user-text); margin-left: auto; border-bottom-right-radius: 6px; }
.msg-bubble.bot { background: transparent; color: var(--text-primary); max-width: 100%; border-radius: 0; padding: 0 0 4px 0; margin-bottom: 16px; }
.msg-bubble.system { background: transparent; color: var(--text-secondary); text-align: center; font-size: 13px; max-width: 100%; margin: 8px auto; padding: 4px 12px; }

.msg-bubble pre { background: var(--code-bg); border: 1px solid var(--code-border); padding: 12px 14px; border-radius: 10px; overflow-x: auto; font-size: 14px; margin: 8px 0; line-height: 1.5; }
.msg-bubble pre code { background: none; padding: 0; }
.msg-bubble.user pre { background: rgba(0, 0, 0, 0.08); border-color: transparent; }
[data-theme="dark"] .msg-bubble.user pre { background: rgba(255, 255, 255, 0.08); }
.msg-bubble code { font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 14px; background: var(--code-bg); padding: 2px 6px; border-radius: 4px; }
.msg-bubble p { margin: 0 0 8px 0; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble img { max-width: 100%; border-radius: 10px; margin: 6px 0; }
.msg-bubble strong { font-weight: 600; }
.msg-bubble a { color: var(--accent); text-decoration: none; }
.msg-bubble a:active { text-decoration: underline; }
.msg-bubble ul, .msg-bubble ol { padding-left: 20px; margin: 6px 0; }
.msg-bubble li { margin: 3px 0; }
.msg-bubble table { border-collapse: collapse; width: 100%; margin: 8px 0; font-size: 14px; }
.msg-bubble th, .msg-bubble td { border: 1px solid var(--border-strong); padding: 6px 10px; text-align: left; }
.msg-bubble th { background: var(--bg-secondary); font-weight: 600; }
.msg-agent { font-size: 12px; color: var(--text-secondary); margin-bottom: 4px; font-weight: 500; }
.msg-time { font-size: 10px; color: var(--text-tertiary); text-align: right; margin-top: 4px; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.stream-cursor { display: inline-block; width: 2px; height: 1.1em; background: var(--accent); vertical-align: text-bottom; margin-left: 2px; animation: blink 1s steps(2, start) infinite; }
@keyframes blink { to { visibility: hidden; } }

/* Segment: Reasoning Block */
.reasoning-block { background: var(--reasoning-bg); border: 1px solid var(--reasoning-border); border-radius: var(--radius-md); margin: 8px 0; overflow: hidden; transition: max-height 0.3s ease; }
.reasoning-header { display: flex; align-items: center; gap: 8px; padding: 10px 14px; cursor: pointer; user-select: none; transition: background var(--transition); }
.reasoning-header:active { background: var(--accent-light); }
.reasoning-icon { font-size: 14px; }
.reasoning-label { font-size: 13px; font-weight: 500; color: var(--accent); flex: 1; }
.reasoning-expand { font-size: 12px; color: var(--text-tertiary); transition: transform 0.2s ease; }
.reasoning-block.expanded .reasoning-expand { transform: rotate(180deg); }
.reasoning-body { max-height: 0; overflow: hidden; transition: max-height 0.3s ease, padding 0.3s ease; padding: 0 14px; }
.reasoning-block.expanded .reasoning-body { max-height: 500px; padding: 0 14px 12px 14px; }
.reasoning-content { font-size: 14px; line-height: 1.6; color: var(--text-secondary); }
.reasoning-content p { margin: 0 0 6px 0; }

/* Segment: Tool Call Card */
.tool-call-card { background: var(--tool-card-bg); border: 1px solid var(--tool-card-border); border-radius: var(--radius-md); margin: 8px 0; overflow: hidden; transition: border-color var(--transition); }
.tool-call-card.success { border-color: rgba(52, 199, 89, 0.25); }
.tool-call-card.error { border-color: rgba(255, 59, 48, 0.25); }
.tool-call-card.running { border-color: rgba(255, 149, 0, 0.25); }
.tool-call-header { display: flex; align-items: center; gap: 8px; padding: 10px 14px; cursor: pointer; user-select: none; transition: background var(--transition); }
.tool-call-header:active { background: var(--accent-light); }
.tool-icon { font-size: 15px; flex-shrink: 0; }
.tool-name { font-size: 14px; font-weight: 500; color: var(--text-primary); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tool-status { font-size: 12px; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.3px; }
.tool-status.success { color: var(--success); }
.tool-status.error { color: var(--danger); }
.tool-status.running { color: var(--warning); }
.tool-expand { font-size: 12px; color: var(--text-tertiary); transition: transform 0.2s ease; }
.tool-call-card.expanded .tool-expand { transform: rotate(180deg); }
.tool-call-body { max-height: 0; overflow: hidden; transition: max-height 0.3s ease, padding 0.3s ease; }
.tool-call-card.expanded .tool-call-body { max-height: 600px; }
.tool-section-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-tertiary); padding: 4px 14px 2px; }
.tool-args, .tool-result { font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 12px; white-space: pre-wrap; word-break: break-all; background: var(--code-bg); margin: 0 14px 8px; padding: 8px 10px; border-radius: 6px; color: var(--text-primary); max-height: 300px; overflow-y: auto; }
.tool-result.error { color: var(--danger); }
.tool-indicator { font-size: 13px; color: var(--accent); padding: 6px 12px; background: var(--accent-light); border-radius: 10px; margin: 6px 0; display: inline-block; }
.tool-indicator.success { color: var(--success); background: rgba(52, 199, 89, 0.1); }
.tool-indicator.error { color: var(--danger); background: rgba(255, 59, 48, 0.1); }

.streaming-indicator { text-align: center; padding: 8px; }
.typing-dots span { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--text-tertiary); margin: 0 2px; animation: typing 1.4s infinite; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing { 0%, 60%, 100% { opacity: 0.25; } 30% { opacity: 1; } }

/* ===== Input Bar ===== */
.input-bar { display: flex; align-items: flex-end; gap: 0; padding: 8px 12px; background: var(--bg-primary); border-top: 0.5px solid var(--border); padding-bottom: max(8px, env(safe-area-inset-bottom)); position: relative; }
.input-wrapper { flex: 1; position: relative; display: flex; align-items: flex-end; gap: 4px; }
.input-icon-btn { width: 36px; height: 44px; border: none; background: none; color: var(--text-secondary); font-size: 20px; cursor: pointer; flex-shrink: 0; display: flex; align-items: center; justify-content: center; border-radius: var(--radius-sm); transition: background var(--transition); }
.input-icon-btn:active { background: var(--bg-secondary); }
#msgInput { flex: 1; border: none; border-radius: var(--radius-xl); padding: 11px 48px 11px 14px; font-size: 16px; resize: none; min-height: 44px; max-height: 120px; background: var(--bg-secondary); color: var(--text-primary); line-height: 1.5; font-family: inherit; transition: background var(--transition); }
#msgInput:focus { outline: none; background: var(--bg-secondary); }
#msgInput::placeholder { color: var(--text-tertiary); }
.send-btn { position: absolute; right: 6px; bottom: 6px; width: 32px; height: 32px; border: none; border-radius: 50%; background: var(--accent); color: #fff; font-size: 15px; cursor: pointer; flex-shrink: 0; display: flex; align-items: center; justify-content: center; transition: transform var(--transition), background var(--transition), opacity var(--transition); }
.send-btn:active { transform: scale(0.88); }
.send-btn:disabled { background: var(--text-tertiary); opacity: 0.5; cursor: default; }
.send-btn.stop-mode { background: var(--danger); opacity: 1; }
.send-btn.stop-mode:active { transform: scale(0.88); background: #d70015; }

/* ===== Attachment Preview ===== */
.attachment-preview { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px 12px 0; background: var(--bg-primary); }
.attachment-preview.hidden { display: none !important; }
.attachment-item { position: relative; width: 64px; height: 64px; border-radius: var(--radius-sm); overflow: hidden; background: var(--bg-secondary); border: 1px solid var(--border); }
.attachment-item img { width: 100%; height: 100%; object-fit: cover; }
.attachment-item .video-placeholder { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; font-size: 24px; color: var(--text-secondary); }
.attachment-item .remove-btn { position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; border-radius: 50%; background: rgba(0, 0, 0, 0.5); color: #fff; font-size: 12px; border: none; display: flex; align-items: center; justify-content: center; cursor: pointer; line-height: 1; }
.attachment-item .filename-label { position: absolute; bottom: 0; left: 0; right: 0; font-size: 9px; color: #fff; background: rgba(0, 0, 0, 0.5); padding: 1px 4px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.attachment-item.attachment-doc { width: auto; min-width: 64px; max-width: 120px; height: 64px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 4px 8px; }
.attachment-doc .doc-placeholder { font-size: 24px; color: var(--accent); }

/* ===== Autocomplete Panel ===== */
.autocomplete-panel { position: absolute; bottom: 100%; left: 12px; right: 12px; max-height: 220px; overflow-y: auto; background: var(--bg-primary); border: 0.5px solid var(--border-strong); border-radius: var(--radius-md); box-shadow: 0 -4px 16px var(--shadow); z-index: 50; margin-bottom: 4px; }
.autocomplete-panel.hidden { display: none !important; }
.autocomplete-item { display: flex; align-items: center; gap: 10px; padding: 12px 16px; cursor: pointer; transition: background var(--transition); border-bottom: 0.5px solid var(--border); }
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:active { background: var(--accent-light); }
.autocomplete-item .ac-icon { font-size: 16px; flex-shrink: 0; }
.autocomplete-item .ac-text { flex: 1; min-width: 0; }
.autocomplete-item .ac-cmd { font-size: 14px; font-weight: 500; color: var(--text-primary); }
.autocomplete-item .ac-desc { font-size: 12px; color: var(--text-secondary); margin-top: 1px; }

/* ===== Mode Switcher Bar ===== */
.mode-switcher-bar { display: flex; gap: 4px; padding: 6px 12px; background: var(--bg-primary); border-top: 0.5px solid var(--border); }
.mode-btn { flex: 1; padding: 6px 12px; border: none; border-radius: var(--radius-sm); background: var(--bg-secondary); color: var(--text-secondary); font-size: 13px; font-weight: 500; cursor: pointer; transition: background var(--transition), color var(--transition); }
.mode-btn.active { background: var(--accent-light); color: var(--accent); }

/* ===== Sidebar ===== */
.sidebar-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: var(--overlay); z-index: 99; display: none; opacity: 0; transition: opacity 0.25s ease; }
.sidebar-overlay.active { display: block; opacity: 1; }
.sidebar { position: fixed; top: 0; left: -280px; width: 280px; height: 100%; background: var(--bg-primary); z-index: 100; transition: left 0.25s ease; display: flex; flex-direction: column; box-shadow: 2px 0 16px var(--shadow); }
.sidebar.open { left: 0; }
.sidebar-header { display: flex; justify-content: space-between; align-items: center; padding: 16px; padding-top: max(16px, env(safe-area-inset-top)); border-bottom: 0.5px solid var(--border); }
.sidebar-header h2 { font-size: 17px; font-weight: 600; }
.sidebar-header button { background: none; border: none; font-size: 18px; color: var(--text-secondary); width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; border-radius: var(--radius-sm); }
.sidebar-nav { flex: 1; padding: 8px 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.sidebar-nav button { display: flex; align-items: center; gap: 14px; width: 100%; padding: 14px 20px; background: none; border: none; font-size: 15px; color: var(--text-primary); text-align: left; cursor: pointer; transition: background var(--transition); }
.sidebar-nav button:active { background: var(--bg-secondary); }
.sidebar-footer { padding: 16px; padding-bottom: max(16px, env(safe-area-inset-bottom)); border-top: 0.5px solid var(--border); }
.new-session-btn { width: 100%; padding: 12px; border: none; border-radius: var(--radius-md); background: var(--accent); color: #fff; font-size: 15px; font-weight: 600; cursor: pointer; transition: background var(--transition), transform var(--transition); }
.new-session-btn:active { transform: scale(0.97); background: var(--accent-hover); }
.sidebar-reconnect-btn { width: 100%; padding: 10px; margin-bottom: 8px; border: 0.5px solid var(--border); border-radius: var(--radius-md); background: var(--bg-secondary); color: var(--text-primary); font-size: 14px; font-weight: 500; cursor: pointer; transition: background var(--transition), transform var(--transition); }
.sidebar-reconnect-btn:active { transform: scale(0.97); background: var(--bg-tertiary, var(--bg-secondary)); }

/* ===== Sub Pages ===== */
.sub-header { display: grid; grid-template-columns: 40px 1fr 40px; align-items: center; padding: 0 8px; background: var(--bg-primary); color: var(--text-primary); min-height: 48px; padding-top: env(safe-area-inset-top); border-bottom: 0.5px solid var(--border); }
.sub-header button { background: none; border: none; color: var(--text-primary); font-size: 18px; padding: 6px; width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; border-radius: var(--radius-sm); cursor: pointer; }
.sub-header button:active { background: var(--bg-secondary); }
.sub-header span { font-weight: 600; font-size: 16px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 4px; }
.list-container { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; background: var(--bg-primary); }
.list-item { display: flex; align-items: center; padding: 14px 16px; cursor: pointer; transition: background var(--transition); min-height: 56px; }
.list-item:active { background: var(--bg-secondary); }
.list-item-icon { margin-right: 14px; font-size: 20px; flex-shrink: 0; }
.list-item-content { flex: 1; min-width: 0; }
.list-item-title { font-size: 15px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-primary); }
.list-item-sub { font-size: 13px; color: var(--text-secondary); margin-top: 3px; }
.list-item-badge { font-size: 14px; color: var(--text-tertiary); flex-shrink: 0; margin-left: 8px; }
.badge-active { color: var(--accent); }
.list-item + .list-item { border-top: 0.5px solid var(--border); }
.list-item:first-child { border-top: none; }

/* ===== Session List Actions ===== */
.session-list-item { position: relative; }
.session-actions { display: flex; align-items: center; gap: 2px; flex-shrink: 0; margin-left: 4px; }
.session-action-btn { width: 32px; height: 32px; border: none; background: none; color: var(--text-secondary); font-size: 16px; cursor: pointer; display: flex; align-items: center; justify-content: center; border-radius: var(--radius-sm); transition: background var(--transition), color var(--transition); }
.session-action-btn:active { background: var(--bg-secondary); }
.session-action-danger:active { background: rgba(255, 59, 48, 0.1); color: var(--danger); }

/* ===== File Viewer ===== */
.file-viewer-container { flex: 1; overflow: auto; padding: 16px; background: var(--bg-primary); -webkit-overflow-scrolling: touch; }
.file-content { font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 13px; line-height: 1.6; white-space: pre-wrap; word-break: break-all; color: var(--text-primary); }

/* ===== Settings ===== */
.settings-container { flex: 1; overflow-y: auto; padding: 16px; background: var(--bg-primary); }
.setting-item { display: flex; justify-content: space-between; align-items: center; padding: 16px 0; border-bottom: 0.5px solid var(--border); }
.setting-item:last-of-type { border-bottom: none; }
.setting-item label { font-size: 16px; color: var(--text-primary); }
.setting-item select { padding: 8px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--bg-primary); color: var(--text-primary); font-size: 14px; }
.setting-arrow { font-size: 20px; color: var(--text-tertiary); margin-left: 8px; }
.setting-item input[type="text"], .setting-item input[type="number"] { width: 60%; padding: 8px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--bg-primary); color: var(--text-primary); font-size: 14px; text-align: right; }

/* iOS-style switch (unified - used globally + in modals) */
.switch { position: relative; display: inline-block; width: 48px; height: 28px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background: var(--border-strong); border-radius: 28px; transition: 0.3s; width: 44px;}
.slider:before { content: ""; position: absolute; height: 24px; width: 24px; left: 2px; bottom: 2px; background: #fff; border-radius: 50%; transition: 0.3s; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); }
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider:before { transform: translateX(20px); }

.btn-danger { width: 100%; padding: 14px; border: none; border-radius: var(--radius-md); background: var(--danger); color: #fff; font-size: 16px; font-weight: 600; cursor: pointer; margin-top: 32px; transition: transform var(--transition); }
.btn-danger:active { transform: scale(0.97); }

/* ===== Popup Menu ===== */
.popup-menu { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: var(--overlay); z-index: 200; display: flex; align-items: flex-start; justify-content: flex-end; }
.popup-menu-content { background: var(--bg-primary); border-radius: var(--radius-md); margin: calc(56px + env(safe-area-inset-top)) 12px 0 0; padding: 4px 0; min-width: 180px; box-shadow: 0 4px 24px var(--shadow-strong); overflow: hidden; }
.popup-menu-content button { display: block; width: 100%; padding: 13px 18px; border: none; background: none; font-size: 15px; color: var(--text-primary); text-align: left; cursor: pointer; transition: background var(--transition); }
.popup-menu-content button:active { background: var(--bg-secondary); }

/* ===== Modal ===== */
#createAgentModal {z-index: 400;}
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: var(--overlay); z-index: 300; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-overlay.hidden { display: none !important; }
.modal-content { background: var(--bg-primary); border-radius: var(--radius-lg); width: 100%; max-width: 95%; max-height: 95vh; overflow-y: auto; box-shadow: 0 8px 32px var(--shadow-strong); }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 0.5px solid var(--border); font-size: 17px; font-weight: 600; }
.modal-header button { background: none; border: none; font-size: 18px; color: var(--text-secondary); width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; }
.modal-body { padding: 12px 20px; }
.modal-field { display: flex; flex-direction: column; align-items: stretch; gap: 6px; border-bottom: 0.5px solid var(--border); padding: 14px 0; }
.modal-field label { font-size: 13px; color: var(--text-secondary); font-weight: 500; }
.modal-field input, .modal-field select { width: 100%; padding: 10px 12px; border: 1.5px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--bg-primary); color: var(--text-primary); font-size: 15px; }
.modal-field input:focus, .modal-field select:focus { outline: none; border-color: var(--accent); }
.modal-footer { display: flex; gap: 12px; padding: 16px 20px; border-top: 0.5px solid var(--border); }
.btn-secondary { flex: 1; padding: 12px; border: 1.5px solid var(--border-strong); border-radius: var(--radius-md); background: var(--bg-primary); color: var(--text-primary); font-size: 15px; font-weight: 600; cursor: pointer; transition: background var(--transition); }
.btn-secondary:active { background: var(--bg-secondary); }
.modal-create-btn { flex: 1; }

/* Import Preview Modal Fields */
#importPreviewModal .modal-field { flex-direction: row; align-items: center; justify-content: space-between; }
#importPreviewModal .modal-field label { flex-shrink: 0; }

/* ===== Agent List Delete Button ===== */
/* ===== Agent List Delete Button ===== */
.agent-delete-btn { width: 32px; height: 32px; border: none; background: none; color: var(--danger); font-size: 18px; cursor: pointer; flex-shrink: 0; display: flex; align-items: center; justify-content: center; border-radius: var(--radius-sm); transition: background var(--transition); }
.agent-delete-btn:active { background: rgba(255, 59, 48, 0.1); }
.agent-delete-btn.disabled { color: var(--text-tertiary); opacity: 0.4; pointer-events: none; }

/* ===== Tags & Badges ===== */
.tag-badge { font-size: 11px; padding: 2px 6px; border-radius: 4px; background: var(--accent-light); color: var(--accent); font-weight: 500; }
.status-badge { font-size: 11px; padding: 3px 8px; border-radius: 4px; font-weight: 600; }
.badge-on { color: var(--success); background: rgba(52, 199, 89, 0.12); }
.badge-off { color: var(--text-tertiary); background: var(--bg-secondary); }

/* ===== Empty Hint ===== */
.empty-hint { text-align: center; color: var(--text-tertiary); font-size: 14px; padding: 60px 20px; }

/* ===== Restart Button ===== */
.btn-restart { margin-top: 24px; margin-bottom: 12px; background: var(--warning) !important; }
.btn-restart:active { background: #e68600 !important; }

/* ===== Settings Spacing ===== */
.settings-container .btn-primary { width: 100%; padding: 14px; border: none; border-radius: var(--radius-md); font-size: 16px; font-weight: 600; cursor: pointer; transition: transform var(--transition); }
.settings-container .btn-primary:active { transform: scale(0.97); }
/* ===== Utilities ===== */
.hidden { display: none !important; }

/* Scrollbar styling */
.message-list::-webkit-scrollbar, .list-container::-webkit-scrollbar, .file-viewer-container::-webkit-scrollbar, .settings-container::-webkit-scrollbar, .tool-args::-webkit-scrollbar, .tool-result::-webkit-scrollbar, .autocomplete-panel::-webkit-scrollbar, .modal-content::-webkit-scrollbar, .agent-dropdown::-webkit-scrollbar { width: 3px; }
.message-list::-webkit-scrollbar-thumb, .list-container::-webkit-scrollbar-thumb, .file-viewer-container::-webkit-scrollbar-thumb, .settings-container::-webkit-scrollbar-thumb, .tool-args::-webkit-scrollbar-thumb, .tool-result::-webkit-scrollbar-thumb, .autocomplete-panel::-webkit-scrollbar-thumb, .modal-content::-webkit-scrollbar-thumb, .agent-dropdown::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

@media (orientation: landscape) and (max-height: 500px) {
    .login-container { padding-top: 20px; }
    .login-logo { margin-bottom: 20px; }
    .login-logo .logo-icon { font-size: 36px; }
    .login-logo h1 { font-size: 20px; }
}


/* ===== 会话忙状态视觉标识 ===== */

/* 会话列表项 - 忙状态 */
.session-list-item.session-busy {
    background: var(--accent-light);
    border-left: 3px solid var(--accent);
}

.session-busy-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    background: var(--accent);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    margin-top: 3px;
    animation: busy-pulse 1.5s ease-in-out infinite;
    white-space: nowrap;
}

@keyframes busy-pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.6;
        transform: scale(0.95);
    }
}

/* 发送按钮 - 停止模式增强 */
.send-btn.stop-mode {
    background: var(--danger) !important;
    color: #fff !important;
    animation: stop-pulse 2s ease-in-out infinite;
}

@keyframes stop-pulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(255, 59, 48, 0.4);
    }
    50% {
        box-shadow: 0 0 0 6px rgba(255, 59, 48, 0);
    }
}

/* 聊天页 header - 忙状态指示器 */
.chat-header.is-busy .header-title::after {
    content: "⏳";
    font-size: 12px;
    margin-left: 4px;
    animation: busy-pulse 1.5s ease-in-out infinite;
}

/* ===== 新增：登录页已保存设备列表 ===== */
.saved-devices-container {
    margin-top: 20px;
    width: 100%;
}
.saved-devices-title {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 10px;
    font-weight: 500;
}
.saved-device-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin-bottom: 8px;
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition);
}
.saved-device-item:active {
    background: var(--accent-light);
    border-color: var(--accent);
}
.saved-device-info {
    flex: 1;
    min-width: 0;
}
.saved-device-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.saved-device-addr {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}
.saved-device-connect {
    flex-shrink: 0;
    padding: 6px 14px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition);
}
.saved-device-connect:active {
    background: var(--accent-hover);
}
.saved-device-delete {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border: none;
    background: none;
    color: var(--text-tertiary);
    font-size: 16px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition), color var(--transition);
}
.saved-device-delete:active {
    background: rgba(255, 59, 48, 0.1);
    color: var(--danger);
}

/* ===== 新增：设备管理弹窗 ===== */
.device-manager-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 0;
    border-bottom: 0.5px solid var(--border);
}
.device-manager-item:last-child {
    border-bottom: none;
}
.device-manager-item.device-current {
    background: var(--accent-light);
    border-radius: var(--radius-sm);
    padding: 14px 12px;
    margin: 0 -12px;
}
.device-manager-info {
    flex: 1;
    min-width: 0;
}
.device-manager-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}
.device-manager-addr {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 3px;
}
.device-manager-token {
    font-size: 11px;
    color: var(--text-tertiary);
    margin-top: 2px;
    font-family: "SF Mono", Menlo, Consolas, monospace;
}
.device-manager-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}
.device-switch-btn {
    width: auto !important;
    padding: 8px 16px !important;
    font-size: 13px !important;
}
.device-delete-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: none;
    color: var(--danger);
    font-size: 18px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition);
}
.device-delete-btn:active {
    background: rgba(255, 59, 48, 0.1);
}

/* ===== 新增：Token 统计栏（消息卡片底部） ===== */
.msg-token-stats {
    margin-top: 8px;
    padding-top: 6px;
    border-top: 0.5px solid var(--border);
}
.token-stats-bar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 2px;
    font-size: 11px;
    color: var(--text-tertiary);
    line-height: 1.5;
}
.token-stat-item {
    white-space: nowrap;
}
.token-stat-sep {
    color: var(--text-tertiary);
    opacity: 0.5;
    margin: 0 1px;
}
.token-stat-global {
    color: var(--text-secondary);
    font-weight: 500;
}
.token-stats-global-row {
    margin-top: 1px;
    font-size: 10px;
    opacity: 0.85;
}

/* ===== 新增：重连徽章 ===== */
.reconnect-badge {
    background: var(--warning);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 12px;
    cursor: pointer;
    white-space: nowrap;
    animation: busy-pulse 1.5s ease-in-out infinite;
    border: none;
}
.reconnect-badge:active {
    background: #e68600;
}


/* ===== Agent Config Modal (单一定义，去除所有重复) ===== */

/* Agent 配置弹窗宽度 */
#agentModelModal .modal-content { max-width: 500px; }

/* Agent 选择工具栏：下拉框 + 新建/删除按钮 */
.agent-config-toolbar {
    display: flex !important;
    flex-direction: row !important;
    align-items: center;
    gap: 8px;
}
.agent-config-toolbar select {
    flex: 1;
    min-width: 0;
    padding: 10px 12px;
    border: 1.5px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 15px;
}
.agent-config-toolbar select:focus {
    outline: none;
    border-color: var(--accent);
}

/* 新建/删除图标按钮 */
.btn-icon-add, .btn-icon-del {
    width: 38px;
    height: 38px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 18px;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition);
}
.btn-icon-add {
    background: var(--accent-light);
    color: var(--accent);
}
.btn-icon-add:active {
    background: var(--accent);
    color: #fff;
}
.btn-icon-del {
    background: rgba(255, 59, 48, 0.1);
    color: var(--danger);
}
.btn-icon-del:active {
    background: var(--danger);
    color: #fff;
}

/* 配置分区标题 */
.config-section-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--accent);
    padding: 16px 0 6px 0;
    margin-top: 4px;
    border-top: 1px solid var(--border);
}
.config-section-title:first-child {
    border-top: none;
    margin-top: 0;
}

/* 并排字段行（两列布局） */
.modal-field-row {
    display: flex;
    gap: 12px;
    border-bottom: 0.5px solid var(--border);
    padding: 14px 0;
}
.modal-field-row .modal-field.half {
    flex: 1;
    min-width: 0;
    border-bottom: none;
    padding: 0;
}

/* 开关型字段：label 左 + switch 右 */
.modal-field.switch-field {
    flex-direction: row !important;
    align-items: center;
    justify-content: space-between;
}
.modal-field.switch-field label {
    flex: 1;
    font-size: 14px;
    color: var(--text-primary);
}

/* Prompt 文件名行：输入框 + 读取/保存按钮 */
.prompt-file-row {
    display: flex;
    gap: 8px;
    align-items: stretch;
}
.prompt-file-row input {
    flex: 1;
    min-width: 0;
}
.btn-small {
    padding: 10px 14px;
    border: 1.5px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: background var(--transition), border-color var(--transition);
}
.btn-small:active {
    background: var(--accent-light);
    border-color: var(--accent);
}

/* 提示词文本域 */
.modal-field.prompt-field {
    border-bottom: none;
    padding-bottom: 20px;
}
.prompt-field textarea {
    width: 100%;
    min-height: 200px;
    max-height: 400px;
    padding: 12px;
    border: 1.5px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 13px;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    line-height: 1.5;
    resize: vertical;
}
.prompt-field textarea:focus {
    outline: none;
    border-color: var(--accent);
}

/* 深色模式适配 */
body.dark-mode .config-section-title { color: var(--accent); }
body.dark-mode .btn-small,
body.dark-mode .btn-icon-add,
body.dark-mode .btn-icon-del {
    background: var(--bg-secondary);
    border-color: var(--border-strong);
}

/* 深色模式适配 */
body.dark-mode .config-section-title { color: var(--accent); }
body.dark-mode .btn-small,
body.dark-mode .btn-icon-add,
body.dark-mode .btn-icon-del {
    background: var(--bg-secondary);
    border-color: var(--border-strong);
}

/* ================================================================ */
/* ===== v2 增强样式：UX 提升、动画、安全区、代码复制、Toast 等 ===== */
/* ================================================================ */

/* ===== 页面切换过渡动画 ===== */
.page {
    transition: opacity 0.2s ease-out;
}
.page.active {
    animation: pageFadeIn 0.25s ease-out;
}
@keyframes pageFadeIn {
    from { opacity: 0; transform: translateX(8px); }
    to { opacity: 1; transform: translateX(0); }
}
.sub-page.active {
    animation: subPageSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes subPageSlideIn {
    from { opacity: 0; transform: translateX(30px); }
    to { opacity: 1; transform: translateX(0); }
}

/* ===== 底部安全区完善 ===== */
.input-bar {
    padding-bottom: env(safe-area-inset-bottom, 0px);
}
.mode-switcher-bar {
    padding-bottom: 0;
}
.mode-switcher-bar + .input-bar {
    padding-bottom: env(safe-area-inset-bottom, 0px);
}
.modal-footer {
    padding-bottom: max(16px, env(safe-area-inset-bottom));
}
.sidebar-footer {
    padding-bottom: max(16px, env(safe-area-inset-bottom));
}

/* ===== 代码块复制按钮 ===== */
.msg-bubble pre {
    position: relative;
}
.code-copy-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    padding: 3px 10px;
    border: none;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.12);
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s ease, background 0.2s ease;
    -webkit-appearance: none;
    z-index: 1;
}
.msg-bubble pre:active .code-copy-btn,
.msg-bubble.user pre .code-copy-btn {
    opacity: 1;
}
@media (hover: none) {
    /* 移动端始终显示复制按钮 */
    .code-copy-btn {
        opacity: 0.7;
    }
}
.code-copy-btn:active {
    background: var(--accent);
    color: #fff;
    opacity: 1;
}
[data-theme="dark"] .code-copy-btn {
    background: rgba(255, 255, 255, 0.12);
    color: var(--text-secondary);
}

/* ===== Toast 浮层提示 ===== */
.mobile-toast {
    position: fixed;
    bottom: max(80px, calc(80px + env(safe-area-inset-bottom)));
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    padding: 10px 24px;
    border-radius: 20px;
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
    white-space: nowrap;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}
.mobile-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ===== 连接质量指示器 ===== */
.conn-indicator {
    display: none;
    font-size: 11px;
    font-weight: 500;
    padding: 2px 8px;
    border-radius: 10px;
    white-space: nowrap;
    transition: opacity 0.3s ease;
}
.conn-indicator.conn-good {
    display: inline-block;
    color: var(--success);
    background: rgba(52, 199, 89, 0.1);
}
.conn-indicator.conn-poor {
    display: inline-block;
    color: var(--warning);
    background: rgba(255, 149, 0, 0.1);
    animation: connPulse 1.5s ease-in-out infinite;
}
.conn-indicator.conn-disconnected {
    display: inline-block;
    color: var(--danger);
    background: rgba(255, 59, 48, 0.1);
}
.conn-indicator.conn-reconnecting {
    display: inline-block;
    color: var(--accent);
    background: var(--accent-light);
    animation: connPulse 1s ease-in-out infinite;
}
@keyframes connPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ===== 欢迎页增强 ===== */
.welcome-msg {
    text-align: center;
    margin-top: 12vh;
    padding: 0 20px;
    animation: welcomeFadeIn 0.5s ease-out;
}
@keyframes welcomeFadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}
.welcome-icon {
    font-size: 56px;
    margin-bottom: 16px;
    animation: welcomeFloat 3s ease-in-out infinite;
}
@keyframes welcomeFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}
.welcome-title {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}
.welcome-subtitle {
    font-size: 15px;
    color: var(--text-secondary);
    margin-bottom: 28px;
    line-height: 1.5;
}
.welcome-cards {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 340px;
    margin: 0 auto;
}
.welcome-card {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px 18px;
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition), transform 0.15s ease;
    text-align: left;
}
.welcome-card:active {
    background: var(--accent-light);
    border-color: var(--accent);
    transform: scale(0.98);
}
.welcome-card-icon {
    font-size: 22px;
    flex-shrink: 0;
}
.welcome-card-text {
    font-size: 14px;
    color: var(--text-primary);
    font-weight: 500;
}

/* ===== 消息长按菜单已复用 popup-menu 样式 ===== */
#msgContextMenu .popup-menu-content {
    min-width: 160px;
}

/* ===== 会话忙碌样式增强 ===== */
.session-list-item.session-busy {
    opacity: 0.85;
}
.session-busy-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    color: var(--warning);
    background: rgba(255, 149, 0, 0.12);
    padding: 2px 8px;
    border-radius: 8px;
    margin-top: 3px;
    animation: busyBadgePulse 1.5s ease-in-out infinite;
}
@keyframes busyBadgePulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* ===== 输入框 iOS 键盘适配 ===== */
.input-bar {
    /* 使用视觉视口适配键盘弹出 */
    transition: transform 0.25s ease;
}
@supports (height: 100dvh) {
    html, body {
        height: 100dvh;
    }
    .page {
        height: 100dvh;
    }
}

/* ===== 流式光标增强 ===== */
.stream-cursor {
    display: inline-block;
    width: 3px;
    height: 1.1em;
    background: var(--accent);
    vertical-align: text-bottom;
    margin-left: 2px;
    border-radius: 1px;
    animation: cursorBlink 1s steps(2, start) infinite;
}
@keyframes cursorBlink {
    to { opacity: 0; }
}

/* ===== 暗色模式增强 ===== */
[data-theme="dark"] .msg-bubble pre {
    background: #1e1e1e;
}
[data-theme="dark"] .welcome-card {
    background: #252525;
    border-color: #333;
}
[data-theme="dark"] .mobile-toast {
    background: rgba(40, 40, 40, 0.95);
    border: 0.5px solid rgba(255, 255, 255, 0.1);
}

/* ===== 触摸反馈优化 ===== */
.list-item,
.agent-dropdown-item,
.autocomplete-item,
.welcome-card,
.session-action-btn {
    -webkit-tap-highlight-color: transparent;
}

/* ===== 输入框增强 ===== */
#msgInput {
    transition: height 0.15s ease;
}

/* ===== 滚动条优化 ===== */
.message-list::-webkit-scrollbar {
    width: 3px;
}
.message-list::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 3px;
}
.message-list::-webkit-scrollbar-track {
    background: transparent;
}

/* ===== 骨架屏加载动画 ===== */
.skeleton-shimmer {
    background: linear-gradient(
        90deg,
        var(--bg-secondary) 25%,
        var(--border) 50%,
        var(--bg-secondary) 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 8px;
}
@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ===== 附件预览增强 ===== */
.attachment-item {
    transition: transform 0.15s ease;
}
.attachment-item:active {
    transform: scale(0.92);
}

/* ===== 重连徽章增强 ===== */
.reconnect-badge {
    transition: opacity 0.3s ease, transform 0.3s ease;
}
.reconnect-badge.hidden {
    opacity: 0;
    transform: scale(0.8);
    pointer-events: none;
}

/* ===== Modal 过渡动画 ===== */
.modal-overlay {
    transition: opacity 0.2s ease;
}
.modal-overlay:not(.hidden) {
    animation: modalFadeIn 0.2s ease-out;
}
@keyframes modalFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
.modal-content {
    animation: modalSlideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes modalSlideUp {
    from { opacity: 0; transform: translateY(20px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ===== Sidebar 过渡增强 ===== */
.sidebar {
    transition: left 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    will-change: left;
}

/* ===== Agent Dropdown 增强 ===== */
.agent-dropdown {
    will-change: transform, opacity;
}

/* ===== 工具调用卡片折叠动画增强 ===== */
.tool-call-body,
.reasoning-body {
    transition: max-height 0.3s cubic-bezier(0.16, 1, 0.3, 1), padding 0.3s ease;
}

/* ===== 防止文字选中（移动端体验优化） ===== */
.chat-header,
.sub-header,
.sidebar-nav button,
.mode-btn,
.header-btn,
.session-action-btn {
    -webkit-user-select: none;
    user-select: none;
}

/* ===== 消息气泡选中优化 ===== */
.msg-bubble.bot,
.msg-bubble.user {
    -webkit-user-select: text;
    user-select: text;
}

/* ===== 输入栏模式切换动画 ===== */
.mode-btn {
    transition: background var(--transition), color var(--transition), transform 0.15s ease;
}
.mode-btn:active {
    transform: scale(0.96);
}

/* ===== 发送按钮动画 ===== */
.send-btn {
    transition: background var(--transition), transform 0.15s ease, opacity var(--transition);
}
.send-btn:not(:disabled):active {
    transform: scale(0.88);
}

/* ===== 图片懒加载占位 ===== */
.msg-bubble img {
    background: var(--bg-secondary);
    min-height: 60px;
}
