:root {
    --bg-color: #f3f4f6;
    --surface-color: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --success: #10b981;
    --danger: #ef4444;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --radius: 12px;
}

[data-theme="dark"] {
    --bg-color: #0f172a;
    --surface-color: #1e293b;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border-color: #334155;
    --primary: #6366f1;
    --primary-hover: #818cf8;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.5);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
}

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

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.top-nav {
    display: flex; justify-content: space-between; align-items: center;
    padding: 14px 28px; background-color: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm); z-index: 10;
}
.logo { font-size: 1.35rem; font-weight: 700; letter-spacing: -0.5px; background: linear-gradient(135deg, var(--primary), #818cf8); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.nav-controls { display: flex; align-items: center; gap: 15px; }
.room-input { padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border-color); background: var(--bg-color); color: var(--text-main); font-size: 0.95rem; outline: none; transition: border-color 0.2s, box-shadow 0.2s; }
.room-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.2); }
.icon-btn { background: none; border: none; font-size: 1.25rem; cursor: pointer; color: var(--text-main); transition: transform 0.2s, color 0.2s; opacity: 0.8; }
.icon-btn:hover { transform: scale(1.1); opacity: 1; color: var(--primary); }
.status { font-size: 0.85rem; color: var(--success); font-weight: 600; }
.status.syncing { color: var(--primary); }
.status.error { color: var(--danger); }

.status.pill {
    font-size: 0.75rem;
    padding: 4px 10px;
    border-radius: 20px;
    background-color: rgba(16, 185, 129, 0.1);
    color: var(--success);
    font-weight: 600;
    white-space: nowrap;
    border: 1px solid rgba(16, 185, 129, 0.2);
}
.status.pill.syncing { background-color: rgba(99, 102, 241, 0.1); color: var(--primary); border-color: rgba(99, 102, 241, 0.2); }
.status.pill.error { background-color: rgba(239, 68, 68, 0.1); color: var(--danger); border-color: rgba(239, 68, 68, 0.2); }

.layout-container { display: flex; flex: 1; overflow: hidden; }

/* Panels */
.panel { display: flex; flex-direction: column; border-right: 1px solid var(--border-color); background-color: var(--surface-color); }
.panel-header { padding: 14px 20px; border-bottom: 1px solid var(--border-color); background: var(--surface-color); display: flex; justify-content: space-between; align-items: center; box-shadow: 0 1px 3px rgba(0,0,0,0.02); z-index: 5; height: 64px; box-sizing: border-box; flex-shrink: 0; }
.panel-title { color: var(--text-main); font-weight: 600; font-size: 1.05rem; display: flex; align-items: center; gap: 8px; }
.panel-actions { display: flex; gap: 10px; align-items: center; }

.text-panel { flex: 2; background-color: var(--bg-color); }
.chat-panel { flex: 1; min-width: 300px; max-width: 350px; background-color: var(--bg-color); }
.files-panel { flex: 1; min-width: 300px; max-width: 350px; border-right: none; background-color: var(--bg-color); }

.sync-indicator { font-size: 0.8rem; color: var(--text-muted); font-weight: 500; margin-right: 8px; }
.toolbar-btn { padding: 8px 14px; font-size: 0.85rem; background-color: var(--bg-color); color: var(--text-main); border: 1px solid var(--border-color); border-radius: 8px; cursor: pointer; font-weight: 600; transition: all 0.2s ease; box-shadow: var(--shadow-sm); }
.toolbar-btn:hover { background-color: var(--border-color); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.toolbar-btn.active, .toolbar-btn:active { background-color: var(--primary); color: #fff; border-color: var(--primary); transform: translateY(0); box-shadow: none; }
.hidden-pane { display: none !important; }

textarea, .md-preview { flex: 1; width: 100%; border: none; resize: none; padding: 28px; font-family: inherit; font-size: 1.05rem; line-height: 1.7; color: var(--text-main); background-color: transparent; outline: none; overflow-y: auto; }
.md-preview { background-color: var(--surface-color); }
.md-preview pre { background: var(--bg-color); padding: 14px; border-radius: var(--radius); overflow-x: auto; box-shadow: inset 0 1px 3px rgba(0,0,0,0.05); border: 1px solid var(--border-color); }
.md-preview code { background: var(--bg-color); padding: 3px 6px; border-radius: 6px; font-family: monospace; border: 1px solid var(--border-color); }
textarea::placeholder { color: var(--text-muted); opacity: 0.7; }

/* Chat Panel */
.chat-messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.chat-msg { background: var(--surface-color); border: 1px solid var(--border-color); padding: 12px 14px; border-radius: var(--radius); font-size: 0.95rem; align-self: flex-start; max-width: 85%; box-shadow: var(--shadow-sm); line-height: 1.5; }
.chat-msg.burn { border-color: rgba(239, 68, 68, 0.4); background: rgba(239, 68, 68, 0.03); }
.chat-msg .meta { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 6px; display: flex; justify-content: space-between; font-weight: 500; }
.chat-input-area { padding: 16px; background: var(--surface-color); border-top: 1px solid var(--border-color); box-shadow: 0 -4px 6px -1px rgba(0, 0, 0, 0.02); }
.chat-input-wrapper { display: flex; align-items: center; background: var(--bg-color); border: 1px solid var(--border-color); border-radius: 24px; padding: 4px 8px 4px 16px; transition: border-color 0.2s, box-shadow 0.2s; gap: 8px; }
.chat-input-wrapper:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.2); }
.chat-input-wrapper input[type="text"] { flex: 1; border: none; background: transparent; padding: 8px 0; color: var(--text-main); font-size: 0.95rem; outline: none; width: 100%; }
.chat-input-wrapper input[type="text"]::placeholder { color: var(--text-muted); }
.send-btn { display: flex; align-items: center; justify-content: center; width: 36px; height: 36px; border: none; border-radius: 50%; background: var(--primary); color: #fff; cursor: pointer; transition: transform 0.2s, background 0.2s, box-shadow 0.2s; flex-shrink: 0; box-shadow: var(--shadow-sm); margin: 2px 0; }
.send-btn:hover { background: var(--primary-hover); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.send-btn:active { transform: translateY(0); box-shadow: none; }
.send-btn svg { margin-left: -2px; }

/* Files Panel */
.files-panel-content { padding: 20px; overflow-y: auto; flex: 1; }
.drop-zone { border: 2px dashed var(--border-color); border-radius: var(--radius); padding: 28px 20px; text-align: center; cursor: pointer; background-color: var(--bg-color); transition: all 0.2s ease; margin-bottom: 20px; }
.drop-zone:hover, .drop-zone.dragover { border-color: var(--primary); background-color: rgba(79, 70, 229, 0.02); }
.drop-zone .icon { font-size: 2.5rem; display: block; margin-bottom: 12px; opacity: 0.9; }
.drop-zone p { color: var(--text-muted); font-size: 0.95rem; line-height: 1.5; }
.drop-zone strong { color: var(--primary); }
.media-btns { display: flex; gap: 10px; margin-bottom: 20px; }
.media-btns button { flex: 1; }

.files-header { margin-bottom: 16px; border-bottom: 1px solid var(--border-color); padding-bottom: 10px; }
.files-header h3 { font-size: 1.05rem; font-weight: 600; color: var(--text-main); }
.files-list { list-style: none; display: flex; flex-direction: column; gap: 12px; }

.file-item { display: flex; flex-direction: column; padding: 14px; border-radius: var(--radius); background-color: var(--bg-color); border: 1px solid var(--border-color); transition: border-color 0.2s, box-shadow 0.2s; }
.file-item:hover { border-color: #cbd5e1; box-shadow: var(--shadow-sm); }
[data-theme="dark"] .file-item:hover { border-color: #475569; }
.file-header-row { display: flex; justify-content: space-between; align-items: center; }
.file-info { display: flex; flex-direction: column; overflow: hidden; padding-right: 12px; flex: 1; }
.file-name { font-size: 0.95rem; font-weight: 600; color: var(--text-main); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-meta { font-size: 0.8rem; color: var(--text-muted); margin-top: 4px; font-weight: 500; }
.file-actions { display: flex; gap: 8px; align-items: center; }

.download-btn, .delete-btn { font-size: 0.85rem; text-decoration: none; font-weight: 600; padding: 6px 12px; border-radius: 6px; cursor: pointer; border: none; transition: background-color 0.2s; }
.download-btn { color: var(--primary); background-color: rgba(79, 70, 229, 0.1); }
.download-btn:hover { background-color: rgba(79, 70, 229, 0.15); }
.delete-btn { color: var(--danger); background-color: rgba(239, 68, 68, 0.1); }
.delete-btn:hover { background-color: rgba(239, 68, 68, 0.15); }

/* File Previews */
.file-preview { margin-top: 14px; text-align: center; background: #000; border-radius: 8px; overflow: hidden; box-shadow: var(--shadow-sm); }
.file-preview img { max-width: 100%; height: auto; max-height: 180px; display: block; }
.file-preview video, .file-preview audio { width: 100%; max-height: 180px; display: block; }

.progress-bar-container { height: 6px; background-color: var(--border-color); border-radius: 3px; margin-bottom: 20px; overflow: hidden; }
.progress-bar { height: 100%; background-color: var(--primary); width: 0%; transition: width 0.2s ease-out; }

/* Modals */
.modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(15, 23, 42, 0.6); display: flex; justify-content: center; align-items: center; z-index: 100; backdrop-filter: blur(4px); }
.modal-content { background: var(--surface-color); padding: 32px; border-radius: 16px; text-align: center; position: relative; min-width: 320px; box-shadow: var(--shadow-md); border: 1px solid var(--border-color); }
.modal-content h3 { margin-bottom: 24px; color: var(--text-main); font-weight: 600; }
.close { position: absolute; top: 12px; right: 16px; font-size: 1.75rem; cursor: pointer; color: var(--text-muted); transition: color 0.2s; }
.close:hover { color: var(--danger); }
#qrcode img { margin: 0 auto; border-radius: 8px; padding: 10px; background: #fff; box-shadow: var(--shadow-sm); }

/* Toasts */
.toast-container { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 12px; z-index: 1000; }
.toast { background: var(--surface-color); color: var(--text-main); padding: 14px 24px; border-radius: var(--radius); box-shadow: var(--shadow-md); border: 1px solid var(--border-color); font-size: 0.95rem; font-weight: 500; animation: slideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

.mobile-tabs { display: none; }

@media (max-width: 1024px) {
    .layout-container { flex-direction: column; overflow: hidden; }
    
    .top-nav { flex-wrap: wrap; gap: 10px; padding: 10px 16px; flex-shrink: 0; }
    .room-input { width: 100%; order: 3; margin-top: 5px; }
    
    .panel { display: none; flex: 1; width: 100%; max-width: 100%; border: none; overflow: hidden; }
    .panel.active-panel { display: flex; flex-direction: column; }
    
    .mobile-tabs {
        display: flex; width: 100%; height: 64px; flex-shrink: 0;
        background: var(--surface-color); border-top: 1px solid var(--border-color);
        box-shadow: 0 -2px 10px rgba(0,0,0,0.05); z-index: 50; justify-content: space-around;
    }
    
    .tab-btn {
        flex: 1; background: none; border: none; padding: 8px 0; display: flex;
        flex-direction: column; align-items: center; justify-content: center; gap: 4px; color: var(--text-muted);
        font-size: 0.75rem; cursor: pointer; transition: color 0.2s; font-weight: 500; height: 100%;
    }
    
    .tab-btn.active { color: var(--primary); }
    .tab-icon { font-size: 1.3rem; margin-bottom: 2px; }
    
    body { overflow: hidden; }
    textarea, .md-preview { padding-bottom: 20px; }
}
