@viewport { width: device-width; zoom: 1; }
html, body, .app-container { 
    height: 100vh !important;
    height: 100dvh !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
}

/* 强制沉浸式（让地址栏自动隐藏） */
html { 
    overflow: hidden;
}
body { 
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
}

/* 主题变量 */
:root {
    --bg: #0d0d1a;
    --sidebar: rgba(15,15,35,0.95);
    --card: rgba(30,30,60,0.7);
    --user: linear-gradient(135deg,#8b5cf6,#ec4899);
    --ai: rgba(60,60,100,0.6);
    --text: #e0e0ff;
    --accent: #a78bfa;
    --blur: blur(32px);
    --radius: 20px;
}
[data-theme="light"] {
    --bg: #fafafa;
    --sidebar: rgba(255,255,255,0.95);
    --card: rgba(255,255,255,0.9);
    --user: linear-gradient(135deg,#7c3aed,#ec4899);
    --ai: rgba(240,240,255,0.9);
    --text: #333;
    --accent: #8b5cf6;
}

/* 全局 */
* { margin:0; padding:0; box-sizing:border-box; }
body {
    font-family: 'MiSans', system-ui, sans-serif;
    background: var(--bg) url('https://api.lxixi.top') center/cover no-repeat fixed;
    color: var(--text);
    min-height: 100dvh !important;
    position: relative;
    overflow: hidden;
}
body::before {
    content: ""; position: absolute; inset: 0;
    background: inherit;
    filter: blur(12px) brightness(0.92);
    z-index: -1;
}

/* 主容器 */
.app-container {
    display: flex;
    height: 100dvh !important;
    width: 100vw;
    background: rgba(0,0,0,0.1);
    backdrop-filter: var(--blur);
}

/* 侧边栏（移动端抽屉） */
.history-sidebar {
    width: 300px;
    background: var(--sidebar);
    backdrop-filter: var(--blur);
    border-right: 1px solid rgba(255,255,255,0.1);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    z-index: 10;
}
.history-header { padding: 20px; border-bottom: 1px solid rgba(255,255,255,0.1); }
.new-chat-btn { width: 100%; padding: 12px; background: var(--accent); border-radius: 12px; color: white; cursor: pointer; }
.history-list { flex: 1; overflow-y: auto; padding: 10px; }
.history-item {
    padding: 12px; margin: 8px 0; background: rgba(255,255,255,0.1);
    border-radius: 12px; cursor: pointer; transition: all 0.2s;
}
.history-item:hover, .history-item.active { background: var(--accent); transform: translateY(-2px); }

/* 主聊天区 */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: rgba(0,0,0,0.05);
    backdrop-filter: var(--blur);
    height: 100dvh;
}

/* 顶部栏 */
.header {
    padding: 15px 20px;
    background: rgba(0,0,0,0.2);
    backdrop-filter: var(--blur);
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    z-index: 10;
}
.header h1 { font-size: 1.6em; font-weight: 500; }
.header-actions { display: flex; align-items: center; gap: 16px; font-size: 1.4em; }

/* 消息区 */
.messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    -webkit-overflow-scrolling: touch;
}
.message { 
    max-width: 78%;
    padding: 14px 20px;
    border-radius: var(--radius);
    line-height: 1.6;
    word-wrap: break-word;
    backdrop-filter: var(--blur);
}
.message.user { align-self: flex-end; background: var(--user); color: white; }
.message.ai { align-self: flex-start; background: var(--ai); }

/* 输入区（固定底部） */
.input-container {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 16px 20px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
    background: rgba(0,0,0,0.2);
    backdrop-filter: var(--blur);
    border-top: 1px solid rgba(255,255,255,0.1);
    display: flex;
    gap: 12px;
    align-items: end;
    z-index: 99;
}
#userInput {
    flex: 1;
    padding: 14px 20px;
    background: rgba(255,255,255,0.12);
    border: none;
    border-radius: 28px;
    color: var(--text);
    resize: none;
    min-height: 48px;
    max-height: 160px;
}
.send-btn, .stop-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    color: white;
    font-size: 1.4em;
    cursor: pointer;
}

/* ============= 移动端强制修复 ============= */
@media (max-width: 768px) {
    .history-sidebar {
        position: fixed;
        top: 0;
        left: -100%;
        width: 86vw;
        max-width: 340px;
        height: 100dvh;
        z-index: 1001;
        transition: left 0.35s ease;
    }
    .history-sidebar.open { left: 0; }
    
    .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(12px);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    pointer-events: none;                    /* 关闭时完全不拦截任何点击 */
}
.sidebar-overlay.open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;                    /* 打开时才拦截点击（关闭侧边栏） */
}
    .hamburger-menu { display: block !important; }
    
    .header { padding: 12px 16px; }
    .messages { padding: 16px; }
    
    /* 输入区绝对固定 */
    .input-container {
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
    }
}

/* 超小屏 */
@media (max-width: 480px) {
    .header { padding: 10px 12px; font-size: 1.3em; }
    .messages { padding: 12px; }
    .input-container { padding: 10px; }
}