        body {
            background: #f5f7fa;
            color: #1a1a2e;
            font-family: -apple-system, 'PingFang SC', 'Helvetica Neue', 'Microsoft YaHei', sans-serif;
            height: 100vh;
            height: 100dvh; /* 动态视口高度，排除手机地址栏 */
            display: flex;
            flex-direction: column;
            overflow: hidden;
        }

        /* ── Header ── */
        header {
            padding: 0.9rem 1.5rem;
            background: #fff;
            border-bottom: 1px solid #e8eaf0;
            display: flex;
            align-items: center;
            gap: 0.6rem;
            flex-shrink: 0;
            z-index: 10;
        }
        .header-dot {
            width: 8px; height: 8px;
            border-radius: 50%;
            background: linear-gradient(135deg, #6c8ef7, #4fc3f7);
            flex-shrink: 0;
        }
        header h1 {
            font-size: 1.05rem;
            font-weight: 600;
            color: #2d3a4a;
            letter-spacing: 0.01em;
        }

        /* ── Conversation selector ── */
        #conv-selector-wrap {
            margin-left: auto;
            display: flex;
            align-items: center;
            gap: 0.5rem;
            position: relative;
        }

        /* Custom dropdown */
        #conv-dropdown-wrap {
            position: relative;
        }
        #conv-dropdown-btn {
            background: #f5f7fa;
            border: 1.5px solid #e0e4ed;
            border-radius: 1rem;
            color: #2d3a4a;
            padding: 0.28rem 0.9rem;
            font-size: 0.82rem;
            font-family: inherit;
            cursor: pointer;
            outline: none;
            max-width: 180px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            display: flex;
            align-items: center;
            gap: 0.3rem;
        }
        #conv-dropdown-btn:focus, #conv-dropdown-btn:hover { border-color: #6c8ef7; }
        #conv-dropdown-menu {
            display: none;
            position: absolute;
            top: calc(100% + 6px);
            right: 0;
            background: #fff;
            border: 1px solid #e8eaf0;
            border-radius: 0.9rem;
            box-shadow: 0 8px 24px rgba(0,0,0,0.08), 0 2px 8px rgba(0,0,0,0.04);
            min-width: 220px;
            max-width: 280px;
            z-index: 200;
            overflow: hidden;
            padding: 0.4rem;
        }
        #conv-dropdown-menu.open { display: block; max-height: 60vh; overflow-y: auto; }
        #conv-search-input {
            width: 100%;
            padding: 6px 10px;
            border: 1px solid #e0e0e0;
            border-radius: 6px;
            font-size: 13px;
            margin-bottom: 4px;
            box-sizing: border-box;
            outline: none;
        }
        #conv-search-input:focus { border-color: #6c8ef7; }
        #conv-search-input::placeholder { color: #bbb; }
        .conv-item {
            display: flex;
            align-items: center;
            padding: 0.5rem 0.65rem;
            cursor: pointer;
            border-radius: 0.6rem;
            transition: background 0.12s;
            gap: 0.5rem;
            position: relative;
        }
        .conv-item:hover { background: #f5f7fa; }
        .conv-item.active { background: #eef1fe; }
        .conv-item-icon {
            flex-shrink: 0;
            width: 26px;
            height: 26px;
            border-radius: 50%;
            background: linear-gradient(135deg, #e8edf8, #dce4f5);
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 0.65rem;
            color: #6c8ef7;
        }
        .conv-item.active .conv-item-icon {
            background: linear-gradient(135deg, #d0d9f5, #bdd0f5);
        }
        .conv-item-body {
            flex: 1;
            min-width: 0;
            display: flex;
            flex-direction: column;
            gap: 0.1rem;
        }
        .conv-item-title {
            font-size: 0.85rem;
            color: #2d3a4a;
            font-weight: 500;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            user-select: none;
        }
        .conv-item.active .conv-item-title { color: #4a72d9; }
        .conv-item-time {
            font-size: 0.71rem;
            color: #b0b8c8;
            white-space: nowrap;
        }
        .conv-item-title-input {
            font-size: 0.85rem;
            font-family: inherit;
            color: #2d3a4a;
            background: #fff;
            border: 1.5px solid #6c8ef7;
            border-radius: 0.35rem;
            padding: 0.1rem 0.4rem;
            outline: none;
            width: 100%;
            box-sizing: border-box;
        }
        .conv-item-actions {
            flex-shrink: 0;
            display: flex;
            align-items: center;
            gap: 0.1rem;
            opacity: 0;
            transition: opacity 0.15s;
        }
        .conv-item:hover .conv-item-actions { opacity: 1; }
        .conv-action-btn {
            background: none;
            border: none;
            color: #b0b8c8;
            cursor: pointer;
            padding: 0.22rem;
            border-radius: 0.3rem;
            line-height: 1;
            display: flex;
            align-items: center;
            transition: color 0.15s, background 0.15s;
        }
        .conv-action-btn:hover { color: #6b7280; background: #e8eaf0; }
        .conv-action-btn.delete:hover { color: #e05a5a; background: #fef0f0; }

        #conv-select {
            display: none;
        }

        #new-chat-btn {
            background: none;
            border: 1.5px solid #e0e4ed;
            border-radius: 1rem;
            color: #7a8fa8;
            padding: 0.3rem 0.8rem;
            font-size: 0.82rem;
            font-family: inherit;
            cursor: pointer;
            transition: border-color 0.15s, color 0.15s;
            white-space: nowrap;
        }
        #new-chat-btn:hover { border-color: #6c8ef7; color: #6c8ef7; }

        /* ── User info in header ── */
        #user-info {
            display: flex;
            align-items: center;
            gap: 0.5rem;
            margin-left: 0.5rem;
        }
        #username-label {
            font-size: 0.82rem;
            color: #5a6a80;
            font-weight: 500;
        }
        #logout-btn {
            background: none;
            border: 1.5px solid #e0e4ed;
            border-radius: 1rem;
            color: #7a8fa8;
            padding: 0.28rem 0.75rem;
            font-size: 0.82rem;
            font-family: inherit;
            cursor: pointer;
            transition: border-color 0.15s, color 0.15s;
            white-space: nowrap;
        }
        #logout-btn:hover { border-color: #e05a5a; color: #e05a5a; }

        /* ── Memory modal ── */
        #memory-btn {
            background: none;
            border: 1.5px solid #e0e4ed;
            border-radius: 1rem;
            color: #7a8fa8;
            padding: 0.28rem 0.75rem;
            font-size: 0.82rem;
            font-family: inherit;
            cursor: pointer;
            transition: border-color 0.15s, color 0.15s;
            white-space: nowrap;
        }
        #memory-btn:hover { border-color: #6c8ef7; color: #6c8ef7; }
        #memory-overlay {
            display: none;
            position: fixed;
            inset: 0;
            background: rgba(0,0,0,0.25);
            z-index: 5000;
            align-items: center;
            justify-content: center;
        }
        #memory-overlay.open { display: flex; }
        #memory-box {
            background: #fff;
            border-radius: 1.2rem;
            box-shadow: 0 8px 32px rgba(0,0,0,0.12);
            width: 480px;
            max-width: 95vw;
            max-height: 80vh;
            display: flex;
            flex-direction: column;
            overflow: hidden;
        }
        #memory-header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 1rem 1.2rem;
            border-bottom: 1px solid #e8eaf0;
        }
        #memory-header h3 { font-size: 1rem; font-weight: 600; color: #2d3a4a; }
        #memory-close {
            background: none;
            border: none;
            font-size: 1.2rem;
            color: #b0b8c8;
            cursor: pointer;
            padding: 0.2rem 0.4rem;
            border-radius: 0.4rem;
            line-height: 1;
        }
        #memory-close:hover { color: #6b7280; background: #f0f0f0; }
        #memory-body {
            flex: 1;
            overflow-y: auto;
            padding: 1rem 1.2rem;
        }
        #memory-body::-webkit-scrollbar { width: 4px; }
        #memory-body::-webkit-scrollbar-thumb { background: #d0d5e0; border-radius: 2px; }
        .memory-empty { color: #b0b8c8; font-size: 0.9rem; text-align: center; padding: 2rem 0; }
        .memory-group { margin-bottom: 1rem; }
        .memory-group-label {
            font-size: 0.75rem;
            font-weight: 600;
            color: #7a8fa8;
            text-transform: uppercase;
            letter-spacing: 0.06em;
            margin-bottom: 0.4rem;
        }
        .memory-item {
            display: flex;
            align-items: center;
            gap: 0.5rem;
            padding: 0.45rem 0.6rem;
            border-radius: 0.6rem;
            background: #f5f7fa;
            margin-bottom: 0.3rem;
        }
        .memory-item-text {
            flex: 1;
            font-size: 0.88rem;
            color: #2d3a4a;
            line-height: 1.5;
        }
        .memory-del-btn {
            flex-shrink: 0;
            background: none;
            border: none;
            color: #c8cdd8;
            cursor: pointer;
            padding: 0.15rem 0.25rem;
            border-radius: 0.3rem;
            line-height: 1;
            font-size: 0.8rem;
        }
        .memory-del-btn:hover { color: #e05a5a; background: #fef0f0; }

        /* ── New chat mode modal ── */
        #new-chat-overlay {
            display: none;
            position: fixed;
            inset: 0;
            background: rgba(0,0,0,0.25);
            z-index: 5000;
            align-items: center;
            justify-content: center;
            padding: 1rem;
        }
        #new-chat-overlay.open { display: flex; }
        #new-chat-box {
            background: #fff;
            border-radius: 1.2rem;
            box-shadow: 0 8px 32px rgba(0,0,0,0.12);
            width: 520px;
            max-width: 100%;
            max-height: 85vh;
            display: flex;
            flex-direction: column;
            overflow: hidden;
        }
        #new-chat-header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 1rem 1.2rem;
            border-bottom: 1px solid #e8eaf0;
        }
        #new-chat-header h3 {
            font-size: 1rem;
            font-weight: 600;
            color: #2d3a4a;
        }
        #new-chat-close {
            background: none;
            border: none;
            font-size: 1.2rem;
            color: #b0b8c8;
            cursor: pointer;
            padding: 0.2rem 0.4rem;
            border-radius: 0.4rem;
            line-height: 1;
        }
        #new-chat-close:hover { color: #6b7280; background: #f0f0f0; }
        #new-chat-body {
            padding: 1rem 1.2rem 1.2rem;
            display: flex;
            flex-direction: column;
            gap: 0.85rem;
            overflow-y: auto;
        }
        .new-chat-option {
            width: 100%;
            display: flex;
            align-items: flex-start;
            gap: 0.9rem;
            text-align: left;
            background: #f7f9fc;
            border: 1px solid #e8eaf0;
            border-radius: 1rem;
            padding: 1rem;
            cursor: pointer;
            transition: transform 0.14s ease, box-shadow 0.14s ease, border-color 0.14s ease, background 0.14s ease;
        }
        .new-chat-option:hover {
            transform: translateY(-1px);
            border-color: #cfd9f6;
            background: #f3f6ff;
            box-shadow: 0 8px 24px rgba(108,142,247,0.12);
        }
        .new-chat-option:active { transform: translateY(0); }
        .new-chat-option-icon {
            flex-shrink: 0;
            width: 2.5rem;
            height: 2.5rem;
            border-radius: 0.85rem;
            display: flex;
            align-items: center;
            justify-content: center;
            background: linear-gradient(135deg, #eef2ff, #e7f4ff);
            font-size: 1.2rem;
        }
        .new-chat-option-body {
            flex: 1;
            min-width: 0;
        }
        .new-chat-option-title {
            font-size: 0.96rem;
            font-weight: 600;
            color: #2d3a4a;
            margin-bottom: 0.22rem;
        }
        .new-chat-option-desc {
            font-size: 0.86rem;
            color: #6b7280;
            line-height: 1.6;
        }

        #login-overlay {
            position: fixed;
            inset: 0;
            background: rgba(245, 247, 250, 0.97);
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 9999;
        }
        #login-box {
            background: #fff;
            border: 1px solid #e8eaf0;
            border-radius: 1.2rem;
            padding: 2rem 2.2rem;
            width: 320px;
            box-shadow: 0 8px 32px rgba(0,0,0,0.08);
        }
        #login-box h2 {
            font-size: 1.1rem;
            font-weight: 600;
            color: #2d3a4a;
            margin-bottom: 1.4rem;
            text-align: center;
        }
        .login-field {
            margin-bottom: 0.9rem;
        }
        .login-field label {
            display: block;
            font-size: 0.8rem;
            color: #7a8fa8;
            margin-bottom: 0.3rem;
        }
        .login-field input {
            width: 100%;
            box-sizing: border-box;
            padding: 0.5rem 0.8rem;
            border: 1.5px solid #e0e4ed;
            border-radius: 0.6rem;
            font-size: 0.9rem;
            font-family: inherit;
            outline: none;
            transition: border-color 0.15s;
        }
        .login-field input:focus { border-color: #6c8ef7; }
        #login-error {
            color: #e05a5a;
            font-size: 0.8rem;
            min-height: 1.2em;
            margin-bottom: 0.6rem;
            text-align: center;
        }
        #login-submit {
            width: 100%;
            padding: 0.55rem;
            background: linear-gradient(135deg, #6c8ef7, #4fc3f7);
            border: none;
            border-radius: 0.7rem;
            color: #fff;
            font-size: 0.9rem;
            font-family: inherit;
            font-weight: 600;
            cursor: pointer;
            transition: opacity 0.15s;
        }
        #login-submit:hover { opacity: 0.88; }
        #login-toggle {
            text-align: center;
            margin-top: 0.9rem;
            font-size: 0.8rem;
            color: #7a8fa8;
        }
        #login-toggle a {
            color: #6c8ef7;
            cursor: pointer;
            text-decoration: none;
        }
        #login-toggle a:hover { text-decoration: underline; }

        /* ── Main layout ── */
        #main {
            flex: 1;
            display: flex;
            overflow: hidden;
            position: relative;
        }

        /* ── Preview pane ── */
        #preview-pane {
            flex: 0 0 62%;
            display: none;
            background: #eef1f8;
            border-right: 1px solid #e0e4ed;
            position: relative;
            flex-direction: column;
        }
        #preview-pane.visible { display: flex; }

        /* Preview pane header bar */
        #preview-header {
            display: flex;
            align-items: center;
            justify-content: flex-end;
            padding: 0.45rem 0.75rem;
            background: #f5f7fa;
            border-bottom: 1px solid #e0e4ed;
            flex-shrink: 0;
        }

        #chat-toggle {
            display: flex;
            align-items: center;
            gap: 0.35rem;
            background: none;
            border: 1.5px solid #d0d5e0;
            border-radius: 1rem;
            color: #6b7280;
            padding: 0.25rem 0.7rem;
            font-size: 0.8rem;
            font-family: inherit;
            font-weight: 500;
            cursor: pointer;
            transition: border-color 0.15s, color 0.15s, background 0.15s;
        }
        #chat-toggle:hover {
            border-color: #6c8ef7;
            color: #6c8ef7;
            background: #f0f3ff;
        }

        #preview-iframe {
            flex: 1;
            border: none;
            background: #fff;
            transition: opacity 0.3s ease;
        }
        .preview-loading #preview-iframe {
            opacity: 0;
        }

        /* ── Resize handle ── */
        #resize-handle {
            width: 5px;
            background: transparent;
            cursor: col-resize;
            flex-shrink: 0;
            position: relative;
            z-index: 10;
            display: none;
        }
        #resize-handle::after {
            content: '';
            position: absolute;
            left: 1px;
            top: 20%;
            bottom: 20%;
            width: 3px;
            background: #e0e4ed;
            border-radius: 3px;
            transition: background 0.15s;
        }
        #resize-handle:hover::after,
        #resize-handle.dragging::after { background: #6c8ef7; }
        #preview-pane.visible + #resize-handle { display: block; }

        /* ── Chat pane ── */
        #chat-pane {
            flex: 1;
            display: flex;
            flex-direction: column;
            overflow: hidden;
            transition: flex 0.25s ease;
            min-width: 300px;
        }

        #chat-pane.collapsed {
            flex: 0 0 0;
            min-width: 0;
            overflow: hidden;
        }

        #chat-container {
            flex: 1;
            overflow-y: auto;
            padding: 1.5rem 1.25rem;
            display: flex;
            flex-direction: column;
            gap: 1rem;
            scroll-behavior: smooth;
        }
        #chat-container::-webkit-scrollbar { width: 5px; }
        #chat-container::-webkit-scrollbar-track { background: transparent; }
        #chat-container::-webkit-scrollbar-thumb { background: #d0d5e0; border-radius: 3px; }

        .message-row {
            display: flex;
            align-items: flex-end;
            gap: 0.5rem;
        }
        .message-row.user { flex-direction: row-reverse; }

        .avatar {
            width: 30px; height: 30px;
            border-radius: 50%;
            flex-shrink: 0;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 0.7rem;
            font-weight: 600;
        }
        .avatar.ai { background: linear-gradient(135deg, #6c8ef7, #4fc3f7); color: #fff; }
        .avatar.user { background: #e8eaf0; color: #6b7280; }

        .message {
            max-width: 88%;
            padding: 0.7rem 1rem;
            border-radius: 1.1rem;
            line-height: 1.65;
            word-break: break-word;
            font-size: 0.93rem;
        }
        .message-row.user .message {
            white-space: pre-wrap;
        }
        .message-row.user .message {
            background: linear-gradient(135deg, #6c8ef7, #5ba4f5);
            color: #fff;
            border-bottom-right-radius: 0.3rem;
        }
        .message-row.assistant .message {
            background: #fff;
            color: #2d3a4a;
            border-bottom-left-radius: 0.3rem;
            box-shadow: 0 1px 4px rgba(0,0,0,0.06);
        }
        .message.error {
            background: #fff0f0;
            color: #c0392b;
            box-shadow: 0 1px 4px rgba(0,0,0,0.06);
        }
        .message.streaming::after {
            content: '▋';
            animation: blink 0.65s step-end infinite;
            color: #6c8ef7;
        }
        @keyframes blink { 50% { opacity: 0; } }

        .ui-badge {
            display: inline-block;
            margin-top: 0.4rem;
            padding: 0.2rem 0.55rem;
            background: #e8f0fe;
            color: #4a72d9;
            border-radius: 0.5rem;
            font-size: 0.78rem;
            font-weight: 500;
        }
        .ui-generating {
            display: inline-block;
            margin-top: 0.4rem;
            padding: 0.2rem 0.55rem;
            background: #f0f0f0;
            color: #888;
            border-radius: 0.5rem;
            font-size: 0.78rem;
            font-weight: 500;
        }

        /* ── Input area ── */
        #input-area {
            padding: 0.9rem 1.25rem 1rem;
            background: #fff;
            border-top: 1px solid #e8eaf0;
            display: flex;
            gap: 0.6rem;
            align-items: flex-end;
            flex-shrink: 0;
        }
        #user-input {
            flex: 1;
            background: #f5f7fa;
            border: 1.5px solid #e8eaf0;
            border-radius: 1.1rem;
            color: #2d3a4a;
            padding: 0.65rem 1rem;
            font-size: 0.93rem;
            font-family: inherit;
            resize: none;
            outline: none;
            max-height: 140px;
            line-height: 1.55;
            transition: border-color 0.15s;
        }
        #user-input::placeholder { color: #b0b8c8; }
        #user-input:focus { border-color: #6c8ef7; background: #fff; }

        #send-btn {
            background: linear-gradient(135deg, #6c8ef7, #5ba4f5);
            border: none;
            border-radius: 50%;
            color: #fff;
            width: 40px; height: 40px;
            flex-shrink: 0;
            font-size: 1.1rem;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: opacity 0.2s, transform 0.1s;
        }
        #send-btn:disabled { opacity: 0.45; cursor: not-allowed; }
        #send-btn:not(:disabled):hover { opacity: 0.88; }
        #send-btn:not(:disabled):active { transform: scale(0.93); }

        /* ── Float toggle button ── */
        #chat-toggle {
            position: fixed;
            bottom: 1.5rem;
            right: 1.5rem;
            z-index: 100;
            display: none;
            background: linear-gradient(135deg, #6c8ef7, #5ba4f5);
            color: #fff;
            border: none;
            border-radius: 2rem;
            padding: 0.6rem 1.1rem;
            font-size: 0.88rem;
            font-family: inherit;
            font-weight: 500;
            cursor: pointer;
            box-shadow: 0 4px 16px rgba(108,142,247,0.35);
            transition: opacity 0.2s, transform 0.1s;
            gap: 0.4rem;
            align-items: center;
        }
        #chat-toggle.visible { display: flex; }
        #chat-toggle:hover { opacity: 0.88; }
        #chat-toggle:active { transform: scale(0.96); }

        .welcome {
            text-align: center;
            color: #a0aab8;
            font-size: 0.88rem;
            margin: auto;
            padding: 2rem 0;
            line-height: 2;
        }
        .welcome strong {
            display: block;
            font-size: 1.05rem;
            color: #7a8fa8;
            margin-bottom: 0.25rem;
        }

        .thinking-box {
            margin-bottom: 8px;
            border: 1px solid #e0e0e0;
            border-radius: 12px;
            overflow: hidden;
            background: #fafafa;
        }
        .thinking-box.thinking {
            border-color: #f0c060;
            background: #fffdf5;
        }
        .thinking-header {
            display: flex;
            align-items: center;
            padding: 8px 12px;
            cursor: pointer;
            user-select: none;
            gap: 6px;
            font-size: 14px;
            color: #666;
        }
        .thinking-header:hover {
            background: #f0f0f0;
        }
        .thinking-icon {
            font-size: 16px;
        }
        .thinking-label {
            font-weight: 500;
            color: #333;
        }
        .thinking-time {
            color: #999;
            font-size: 13px;
        }
        .thinking-toggle {
            margin-left: auto;
            color: #999;
            font-size: 12px;
        }
        .thinking-content {
            padding: 0 12px 10px 12px;
            font-size: 13px;
            color: #666;
            line-height: 1.6;
            white-space: pre-wrap;
            word-break: break-word;
            max-height: 300px;
            overflow-y: auto;
            border-top: 1px solid #e8e8e8;
        }
        .waiting-hint {
            color: #b0b8c8;
            font-style: italic;
            font-size: 0.88rem;
        }

        /* ── Markdown styles ── */
        .message pre { background: #1e1e1e; color: #d4d4d4; padding: 12px; border-radius: 8px; overflow-x: auto; font-size: 13px; margin: 8px 0; }
        .message code { background: rgba(0,0,0,0.06); padding: 2px 5px; border-radius: 3px; font-size: 13px; }
        .message pre code { background: none; padding: 0; }
        .message ul, .message ol { padding-left: 20px; margin: 6px 0; }
        .message li { margin: 2px 0; }
        .message p { margin: 6px 0; }
        .message h1, .message h2, .message h3 { margin: 10px 0 6px; }
        .message blockquote { border-left: 3px solid #ccc; margin: 8px 0; padding: 4px 12px; color: #666; }
        .message table { border-collapse: collapse; margin: 8px 0; width: 100%; }
        .message th, .message td { border: 1px solid #ddd; padding: 6px 10px; text-align: left; }
        .message th { background: #f5f5f5; }
        .message a { color: #4a9eff; }
        /* ── Message actions (regenerate / edit) ── */
        .message-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; opacity: 0.4; transition: opacity 0.2s; }
        .message-row:hover .message-actions { opacity: 1; }
        .msg-action-btn { background: none; border: none; color: #888; font-size: 12px; cursor: pointer; padding: 2px 6px; border-radius: 4px; }
        .msg-action-btn:hover { background: rgba(0,0,0,0.06); color: #333; }
        /* ── Edit message ── */
        .edit-textarea { width: 100%; min-height: 60px; border: 1px solid #ddd; border-radius: 6px; padding: 8px; font-size: 14px; resize: vertical; font-family: inherit; box-sizing: border-box; }
        .edit-actions { display: flex; gap: 8px; margin-top: 6px; justify-content: flex-end; }
        .edit-confirm, .edit-cancel { padding: 4px 12px; border-radius: 4px; border: none; cursor: pointer; font-size: 13px; }
        .edit-confirm { background: #4a9eff; color: white; }
        .edit-cancel { background: #eee; color: #666; }

        /* ── Mobile responsive ── */
        @media (max-width: 768px) {
            /* 安全区域适配 - 不在 body 上加 padding，改为各区域分别处理 */
            body { padding: 0; }

            header {
                padding: calc(0.6rem + env(safe-area-inset-top)) 0.85rem 0.6rem;
                padding-left: calc(0.85rem + env(safe-area-inset-left));
                padding-right: calc(0.85rem + env(safe-area-inset-right));
                gap: 0.4rem;
                flex-wrap: nowrap;
            }
            header h1 { font-size: 0.95rem; }
            #conv-selector-wrap { gap: 0.3rem; }
            #conv-dropdown-btn { max-width: 100px; padding: 0.22rem 0.6rem; font-size: 0.78rem; }
            #new-chat-btn { padding: 0.22rem 0.55rem; font-size: 0.78rem; }
            #user-info { gap: 0.3rem; margin-left: 0.3rem; }
            #username-label { display: none; }
            #memory-btn, #logout-btn { padding: 0.22rem 0.55rem; font-size: 0.78rem; }

            /* 预览面板全屏覆盖 */
            #main { flex-direction: column !important; }
            #preview-pane.visible {
                position: fixed;
                top: 0; left: 0; right: 0; bottom: 0;
                z-index: 100;
                flex: none !important;
                width: 100% !important;
                height: 100% !important;
                border-right: none;
                padding-top: env(safe-area-inset-top);
            }
            #resize-handle { display: none !important; }
            #chat-pane { flex: 1; min-width: 0; }
            #chat-pane.collapsed { flex: 0 0 0; min-height: 0; }

            /* 输入区域固定底部 */
            #input-area {
                padding: 0.7rem 0.85rem 0.85rem;
                position: sticky;
                bottom: 0;
                background: white;
                z-index: 10;
                padding-bottom: calc(0.85rem + env(safe-area-inset-bottom));
            }
            #chat-container { padding: 1rem 0.85rem; }
            #user-input { font-size: 0.9rem; }

            /* 触摸优化：加大点击区域 */
            .msg-action-btn { min-height: 36px; min-width: 36px; display: flex; align-items: center; justify-content: center; }
            .message-actions { opacity: 0.6 !important; }

            /* Modals: full-width on small screens */
            #memory-box { width: 95vw; max-height: 85vh; }
            #new-chat-box { width: 95vw; max-height: 90vh; }
            #login-box { width: 90vw; padding: 1.5rem 1.2rem; }

            /* 对话列表全屏下拉 */
            #conv-dropdown-menu.open {
                position: fixed;
                top: calc(50px + env(safe-area-inset-top));
                left: 0; right: 0; bottom: 0;
                max-height: none;
                border-radius: 0;
            }

            /* 移动端返回按钮 */
            .mobile-preview-back {
                position: absolute;
                top: calc(8px + env(safe-area-inset-top));
                left: calc(8px + env(safe-area-inset-left));
                z-index: 101;
                background: rgba(0,0,0,0.6);
                color: white;
                padding: 6px 14px;
                border-radius: 20px;
                font-size: 13px;
                cursor: pointer;
                border: none;
            }
        }
