* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f3460;
    --text-primary: #e8e8e8;
    --text-secondary: #a0a0a0;
    --accent: #e94560;
    --accent-hover: #ff6b6b;
    --success: #4ade80;
    --border: #2a2a4a;
}
html, body { height: 100%; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
}
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh; /* 动态视口高度，避免软键盘遮挡底部导航 */
    max-width: 100%;
    margin: 0 auto;
    padding-bottom: env(safe-area-inset-bottom);
}
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.app-title {
    font-size: 1.1rem;
    background: linear-gradient(135deg, var(--accent), #ff8c00);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.role-selector { display: flex; align-items: center; gap: 6px; margin-right: 8px; }
.role-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
}
.role-btn:hover { background: var(--accent); }
.role-btn .caret { font-size: 0.8rem; opacity: .8; }
.role-manage-btn { background: none; border: none; color: var(--text-primary); cursor: pointer; font-size: 1.1rem; }
.role-manage-btn:hover { color: var(--accent); }
.role-menu {
    position: absolute;
    top: 48px;
    right: 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    width: 260px;
    max-height: 300px;
    overflow-y: auto;
    z-index: 1500;
}
.role-menu.hidden { display: none; }
.role-menu-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; cursor: pointer; }
.role-menu-item:hover { background: var(--bg-tertiary); }
.role-menu-item .avatar { font-size: 1.2rem; }
.role-menu-item .meta { display: flex; flex-direction: column; }
.role-menu-item .meta .name { font-weight: 600; }
.role-menu-item .meta .desc { font-size: 0.75rem; color: var(--text-secondary); }

.connect-controls { display: flex; gap: 8px; }
.connect-btn, .disconnect-btn {
    padding: 6px 12px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
}
.connect-btn { background: var(--success); color: var(--bg-primary); }
.disconnect-btn { background: var(--accent); color: white; }

.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    padding-bottom: 64px; /* 为固定底部导航预留空间 */
}
.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    background: var(--bg-primary);
}
.message {
    padding: 8px 12px;
    border-radius: 12px;
    margin-bottom: 8px;
    max-width: 85%;
    word-wrap: break-word;
    animation: fadeIn 0.3s ease;
}
.user-message { background: var(--bg-tertiary); margin-left: auto; }
.assistant-message { background: var(--accent); color: white; }
.system-message { background: #333; color: #ffd75e; text-align: center; font-size: 0.85rem; margin: 4px auto; }

.visualizer-container {
    position: absolute;
    bottom: 120px;
    right: 12px;
    width: 50px;
    height: 50px;
    pointer-events: none;
}
.visualizer {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: var(--bg-secondary);
}
.camera-preview, .screen-preview {
    position: absolute;
    bottom: 120px;
    left: 12px;
    width: 320px;
    height: 240px;
    min-width: 160px;
    min-height: 90px;
    max-width: 90vw;
    max-height: 80vh;
    background: var(--bg-secondary);
    border-radius: 8px;
    border: 2px solid var(--border);
    display: none;
    overflow: hidden;
    resize: both;          /* 浏览器原生拖拽调大小 */
    pointer-events: auto;
    z-index: 50;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.camera-preview video, .screen-preview video { width: 100%; height: 100%; object-fit: contain; background: #000; }

/* 预览工具栏 */
.preview-toolbar {
    position: absolute;
    top: 4px;
    right: 4px;
    display: flex;
    gap: 4px;
    z-index: 2;
}
.pv-btn {
    background: rgba(0,0,0,0.6);
    color: white;
    border: none;
    border-radius: 4px;
    width: 24px;
    height: 24px;
    font-size: 0.75rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
}
.pv-btn:hover { background: rgba(0,0,0,0.85); }

.input-area {
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
.text-input {
    flex: 1;
    padding: 8px 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 20px;
    color: var(--text-primary);
    font-size: 1rem;
    min-height: 44px;
    touch-action: manipulation;
}
.text-input:focus { outline: none; border-color: var(--accent); }
.send-btn {
    padding: 8px 12px;
    background: var(--accent);
    border: none;
    border-radius: 20px;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    min-height: 44px;
    min-width: 44px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}
.send-btn:hover { background: var(--accent-hover); }

.bottom-nav {
    display: flex;
    justify-content: space-around;
    padding: 8px 0;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    touch-action: manipulation;
}
.nav-btn {
    flex: 1;
    background: none;
    color: var(--text-primary);
    font-size: 1.4rem;
    padding: 6px;
    border: none;
    cursor: pointer;
    min-height: 48px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    pointer-events: auto;
}
.nav-btn:hover { color: var(--accent); }
.nav-btn.active { color: var(--accent); }

/* Mic status text */
.mic-status {
    font-size: 0.7rem;
    margin-left: 4px;
    color: var(--text-secondary);
}
.nav-btn.active .mic-status {
    color: var(--accent);
    font-weight: bold;
}

.modal {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.8);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}
.modal.active { display: flex; }
.modal-content {
    background: var(--bg-secondary);
    padding: 20px;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
}
.modal-content h2 { margin-bottom: 16px; color: var(--accent); }
.modal-content label { display: block; margin-bottom: 12px; color: var(--text-secondary); }
.modal-content input, .modal-content select, .modal-content textarea {
    width: 100%;
    padding: 8px;
    margin-top: 4px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
}
.modal-content textarea { resize: vertical; }
.modal-content .hint { font-size: 0.75rem; color: var(--text-secondary); margin-bottom: 12px; }
.btn-primary, .btn-secondary {
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    margin-right: 8px;
    cursor: pointer;
}
.btn-primary { background: var(--accent); color: white; }
.btn-secondary { background: var(--bg-tertiary); color: var(--text-primary); }

.role-list { max-height: 200px; overflow-y: auto; margin-bottom: 12px; }
.role-list-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 6px;
    cursor: pointer;
}
.role-list-item:hover { background: var(--bg-tertiary); }
.role-list-item.active { background: var(--accent); color: white; }
.role-edit { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.role-edit.hidden { display: none; }
.role-edit label { display: flex; flex-direction: column; gap: 4px; color: var(--text-secondary); }
.role-edit input, .role-edit textarea {
    width: 100%;
    padding: 6px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
}
.role-edit-actions { display: flex; gap: 8px; margin-top: 8px; }

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

@media (max-width: 480px) {
    .app-title { font-size: 1rem; }
    .role-btn { padding: 4px 6px; font-size: 0.85rem; }
    .visualizer-container { width: 40px; height: 40px; bottom: 110px; right: 8px; }
    .camera-preview, .screen-preview { width: 200px; height: 150px; bottom: 110px; left: 8px; }
    .nav-btn { font-size: 1.2rem; }
}

/* ===== Toast 通知 ===== */
.toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
    max-width: calc(100vw - 32px);
}
.toast {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    padding: 10px 16px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    pointer-events: auto;
    font-size: 0.9rem;
    line-height: 1.4;
    animation: toastSlide 0.25s ease;
    border-left: 4px solid var(--accent);
    word-break: break-word;
}
.toast.error   { border-left-color: #ef4444; }
.toast.success { border-left-color: #4ade80; }
.toast.info    { border-left-color: #0ea5e9; }
.toast.fadeout { opacity: 0; transform: translateX(120%); transition: all 0.3s ease; }
@keyframes toastSlide {
    from { transform: translateX(120%); opacity: 0; }
    to   { transform: translateX(0); opacity: 1; }
}

/* ===== Theme toggle & 亮色主题 ===== */
.theme-toggle {
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 4px 8px;
    border-radius: 6px;
    margin-right: 4px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}
.theme-toggle:hover { background: var(--bg-tertiary); }
html.light {
    --bg-primary: #ffffff;
    --bg-secondary: #f3f4f6;
    --bg-tertiary: #e5e7eb;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --border: #d1d5db;
}
html.light body { background: #ffffff; color: #111827; }

/* ===== 消息增强：时间戳 + 复制按钮 ===== */
.message {
    position: relative;
    padding: 8px 32px 22px 12px;
}
.message .timestamp {
    position: absolute;
    bottom: 4px;
    right: 8px;
    font-size: 0.65rem;
    opacity: 0.55;
}
.message .copy-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    background: none;
    border: none;
    color: inherit;
    opacity: 0;
    cursor: pointer;
    font-size: 0.75rem;
    padding: 2px 6px;
    border-radius: 4px;
    transition: opacity .2s;
}
.message:hover .copy-btn { opacity: 0.7; }
.message .copy-btn:hover { opacity: 1; background: rgba(127,127,127,0.15); }
.message.system .copy-btn,
.message.system .timestamp { display: none; }
