
/* --- THEME VARIABLES --- */
:root {
    --primary: #3b82f6;
    --primary-glow: rgba(59, 130, 246, 0.4);
    --bg-body: #f8fafc;
    --bg-sidebar: rgba(255, 255, 255, 0.85);
    --bg-card: #ffffff;
    --bg-hover: #f1f5f9;
    --bg-input: rgba(255, 255, 255, 0.5);
    --border: #e2e8f0;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    --glass-blur: blur(12px);
    --success: #10b981;
    --danger: #ef4444;
}

[data-theme="dark"] {
    --primary: #818cf8;
    --primary-glow: rgba(129, 140, 248, 0.3);
    --bg-body: linear-gradient(135deg, #020617 0%, #1e1b4b 50%, #172554 100%);
    --bg-sidebar: rgba(15, 23, 42, 0.6);
    --bg-card: rgba(30, 41, 59, 0.7);
    --bg-hover: rgba(51, 65, 85, 0.8);
    --bg-input: rgba(15, 23, 42, 0.6);
    --border: rgba(255, 255, 255, 0.08);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
    --glass-blur: blur(20px); 
}

/* --- TYPING INDICATOR (Moved up for priority) --- */
.typing-indicator { 
    display: flex; gap: 4px; padding: 12px 16px; 
    align-self: flex-start; background: var(--bg-hover); 
    border-radius: 18px; border: 1px solid var(--border); 
    width: fit-content; margin-bottom: 10px;
}
.dot { 
    width: 6px; height: 6px; background: var(--text-muted); 
    border-radius: 50%; animation: bounce 1.4s infinite ease-in-out both; 
}
.dot:nth-child(1) { animation-delay: -0.32s; }
.dot:nth-child(2) { animation-delay: -0.16s; }
@keyframes bounce { 
    0%, 80%, 100% { transform: scale(0); } 
    40% { transform: scale(1); } 
}

/* --- RESET & BASE --- */
* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Inter', sans-serif; transition: background 0.4s ease, color 0.2s ease, border-color 0.3s ease; }
body { height: 100vh; display: flex; background: var(--bg-body); background-size: 200% 200%; color: var(--text-main); overflow: hidden; }

/* --- SIDEBAR --- */
.sidebar { width: 270px; background: var(--bg-sidebar); backdrop-filter: var(--glass-blur); border-right: 1px solid var(--border); padding: 24px 16px; display: flex; flex-direction: column; z-index: 20; flex-shrink: 0; overflow-y: auto; }
.sidebar::-webkit-scrollbar { width: 5px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.logo-container { display: flex; align-items: center; gap: 12px; padding: 0 12px 20px; }
.logo-icon { width: 34px; height: 34px; background: linear-gradient(135deg, var(--primary), #4f46e5); border-radius: 8px; display: flex; align-items: center; justify-content: center; box-shadow: 0 0 15px var(--primary-glow); overflow: hidden; }
.logo-img { width: 100%; height: 100%; object-fit: cover; }
.logo-text { font-size: 1.3rem; font-weight: 700; color: var(--text-main); }
.sidebar-divider { height: 1px; background: var(--border); margin: 8px 8px 20px; }
.section-label { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; color: var(--text-muted); letter-spacing: 0.05em; margin: 20px 12px 10px; }

.nav-item { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: 12px; color: var(--text-muted); text-decoration: none; font-size: 0.95rem; font-weight: 500; margin-bottom: 4px; cursor: pointer; position: relative; overflow: hidden; z-index: 1; }
.nav-item::before { content: ''; position: absolute; top: 0; left: 0; bottom: 0; right: 0; background: var(--bg-hover); z-index: -1; border-radius: 12px; transform: scaleX(0); transform-origin: left; transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1); }
.nav-item.active { color: var(--primary); font-weight: 600; }
.nav-item.active::before { transform: scaleX(1); background: var(--bg-hover); opacity: 0.5; }
.nav-item.active i { color: var(--primary); }
.nav-item:hover { color: var(--text-main); transform: translateX(6px); }
.nav-item:hover::before { transform: scaleX(1); }
.nav-item i { width: 24px; text-align: center; transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1); }
.nav-item:hover i { transform: scale(1.15) rotate(5deg); color: var(--primary); }

/* --- HEADER --- */
.main-layout { flex: 1; display: flex; flex-direction: column; position: relative; overflow: hidden; }
.top-bar { height: 72px; padding: 0 32px; display: flex; align-items: center; justify-content: space-between; background: var(--bg-sidebar); backdrop-filter: var(--glass-blur); border-bottom: 1px solid var(--border); z-index: 10; }
.search-wrapper { position: relative; width: 400px; }
.search-input { width: 100%; padding: 11px 16px 11px 44px; border-radius: 12px; border: 1px solid var(--border); background: var(--bg-input); color: var(--text-main); font-size: 0.9rem; }
.search-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow); background: var(--bg-card); }
.search-icon { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); color: var(--text-muted); }
.header-actions { display: flex; align-items: center; gap: 16px; }
.action-btn { width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--border); background: var(--bg-card); color: var(--text-muted); display: flex; align-items: center; justify-content: center; cursor: pointer; transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1); }
.action-btn:hover { background: var(--bg-hover); color: var(--text-main); border-color: var(--primary); transform: translateY(-2px); }
.profile-avatar { width: 42px; height: 42px; border-radius: 12px; background: linear-gradient(135deg, #6366f1, #d946ef); display: flex; align-items: center; justify-content: center; color: white; font-weight: 700; cursor: pointer; }

/* Hamburger Menu Button (Hidden on Desktop) */
.mobile-menu-btn { display: none; margin-right: 15px; background: transparent; border: none; font-size: 1.4rem; color: var(--text-muted); cursor: pointer; }

/* --- CHANNEL LAYOUT --- */
.channel-container {
    flex: 1;
    display: flex;
    overflow: hidden;
    background: var(--bg-body);
}

/* 1. Left Sidebar: Channels List */
.channel-sidebar {
    width: 260px;
    background: var(--bg-hover);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    padding: 20px;
    transition: width 0.3s ease;
    flex-shrink: 0;
    overflow: hidden; /* Changed from auto to hidden to use internal scroll area */
}

/* Sidebar Scroll Area Container */
.sidebar-scroll-area {
    flex: 1;
    overflow-y: auto;
    margin-bottom: 10px;
    padding-right: 5px; /* Prevent scrollbar overlap */
    /* Firefox */
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

/* Custom Scrollbar for Sidebar Area */
.sidebar-scroll-area::-webkit-scrollbar { width: 5px; }
.sidebar-scroll-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
.sidebar-scroll-area::-webkit-scrollbar-track { background: transparent; }

.branch-select-wrapper { margin-bottom: 20px; position: relative; flex-shrink: 0; }
.branch-select {
    width: 100%; padding: 12px; border-radius: 12px;
    background: var(--bg-card); border: 1px solid var(--border);
    color: var(--text-main); font-weight: 600; cursor: pointer; appearance: none;
    outline: none;
}
.branch-select-icon { position: absolute; right: 15px; top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; }

.channel-group-label { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; color: var(--text-muted); margin: 15px 0 8px 5px; letter-spacing: 0.05em; }

.channel-item {
    padding: 10px 12px; border-radius: 8px;
    color: var(--text-muted); font-weight: 500; font-size: 0.95rem;
    cursor: pointer; display: flex; align-items: center; gap: 10px;
    transition: all 0.2s;
    white-space: nowrap; overflow: hidden;
}
.channel-item:hover { background: rgba(0,0,0,0.05); color: var(--text-main); }
.channel-item.active { background: var(--bg-card); color: var(--primary); font-weight: 600; box-shadow: var(--shadow); }
.channel-hash { color: var(--text-muted); opacity: 0.6; font-size: 1.1rem; flex-shrink: 0; }
.channel-text { overflow: hidden; text-overflow: ellipsis; }

/* Branch Item Specifics */
.branch-item { border: 1px solid transparent; }
.branch-item.active { border-color: var(--primary); background: rgba(59, 130, 246, 0.1); }

.create-group-btn {
    margin-top: auto;
    width: 100%; padding: 12px;
    border: 1px dashed var(--primary); background: rgba(59, 130, 246, 0.05);
    color: var(--primary); border-radius: 10px; font-weight: 600;
    cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px;
    transition: all 0.2s; white-space: nowrap; overflow: hidden;
    flex-shrink: 0; /* Ensures it stays fixed size */
}
.create-group-btn:hover { background: var(--primary); color: white; }

/* 2. Middle: Main Chat Area */
.chat-area {
    flex: 1;
    display: flex; flex-direction: column;
    background: var(--bg-card);
    position: relative;
    min-width: 0; 
}

.chat-area-header {
    height: 70px; padding: 0 25px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
}
.chat-title h3 { font-size: 1.2rem; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.chat-desc { font-size: 0.85rem; color: var(--text-muted); margin-top: 2px; }

.messages-feed {
    flex: 1; overflow-y: auto; padding: 25px;
    display: flex; flex-direction: column; gap: 20px;
}

.message-group { display: flex; gap: 15px; animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

.user-avatar { 
    width: 40px; height: 40px; border-radius: 12px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; color: white; font-size: 0.9rem;
}
.msg-content { flex: 1; min-width: 0; }
.msg-header { display: flex; align-items: baseline; gap: 10px; margin-bottom: 4px; }
.username { font-weight: 600; color: var(--text-main); }
.timestamp { font-size: 0.75rem; color: var(--text-muted); }
.msg-text { line-height: 1.5; color: var(--text-muted); font-size: 0.95rem; white-space: pre-wrap; word-break: break-word; }

/* Locked Screen Style */
.locked-view {
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    height: 100%; color: var(--text-muted); text-align: center;
    padding: 20px;
    animation: fadeIn 0.4s ease;
}
.locked-icon { font-size: 4rem; margin-bottom: 20px; color: #ef4444; opacity: 0.8; }
.locked-title { font-size: 1.5rem; font-weight: 700; color: var(--text-main); margin-bottom: 10px; }
.locked-btn { margin-top: 20px; padding: 12px 24px; background: var(--primary); color: white; border: none; border-radius: 8px; font-weight: 600; cursor: pointer; transition: transform 0.2s; }
.locked-btn:hover { transform: translateY(-2px); box-shadow: 0 4px 12px var(--primary-glow); }

/* Attachment Styling */
.attachment-preview {
    display: inline-flex; align-items: center; gap: 10px;
    background: var(--bg-hover); border: 1px solid var(--border);
    padding: 10px 15px; border-radius: 8px; margin-top: 8px;
    cursor: pointer; transition: background 0.2s;
}
.attachment-preview:hover { background: var(--bg-input); border-color: var(--primary); }
.attachment-icon { color: var(--primary); font-size: 1.2rem; }
.attachment-name { font-weight: 500; color: var(--text-main); font-size: 0.9rem; }

.chat-input-area {
    padding: 20px 25px;
    border-top: 1px solid var(--border);
    background: var(--bg-card);
}
.input-wrapper {
    background: var(--bg-hover); border-radius: 12px;
    display: flex; align-items: center; padding: 5px;
    border: 1px solid var(--border);
}
.input-wrapper:focus-within { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-glow); }
.chat-btn { width: 40px; height: 40px; border: none; background: transparent; color: var(--text-muted); cursor: pointer; font-size: 1.1rem; border-radius: 8px; flex-shrink: 0; }
.chat-btn:hover { color: var(--text-main); background: rgba(0,0,0,0.05); }
.chat-field { flex: 1; background: transparent; border: none; padding: 10px; font-size: 0.95rem; color: var(--text-main); outline: none; min-width: 0; }
.send-msg-btn { background: var(--primary); color: white; margin-left: 5px; }
.send-msg-btn:hover { background: #2563eb; color: white; }

/* 3. Right: Info Panel */
.info-panel {
    width: 280px;
    background: var(--bg-hover);
    border-left: 1px solid var(--border);
    padding: 20px;
    overflow-y: auto;
    display: flex; flex-direction: column; gap: 25px;
    flex-shrink: 0;
}
.info-section h4 { font-size: 0.9rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; margin-bottom: 12px; letter-spacing: 0.05em; }

.pinned-item {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 10px; padding: 12px; margin-bottom: 10px;
    font-size: 0.9rem; cursor: pointer; transition: transform 0.2s;
}
.pinned-item:hover { transform: translateX(3px); border-color: var(--primary); }
.pin-header { display: flex; align-items: center; gap: 8px; font-weight: 600; margin-bottom: 4px; color: var(--primary); font-size: 0.8rem; }

.user-list-item { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; font-size: 0.9rem; font-weight: 500; cursor: pointer; padding: 5px; border-radius: 8px; transition: background 0.2s; }
.user-list-item:hover { background: var(--bg-card); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; border: 2px solid var(--bg-hover); position: absolute; bottom: -2px; right: -2px; }
.avatar-wrapper { position: relative; width: 32px; height: 32px; }
.avatar-img { width: 100%; height: 100%; border-radius: 8px; object-fit: cover; }

/* --- MODAL STYLES (Create Group) --- */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5); backdrop-filter: blur(5px);
    display: none; align-items: center; justify-content: center; z-index: 2000;
}
.modal-content {
    background: var(--bg-card); padding: 30px; border-radius: 20px;
    width: 420px; border: 1px solid var(--border); box-shadow: var(--shadow);
    animation: popIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.form-label { display: block; font-size: 0.9rem; font-weight: 600; margin-bottom: 6px; color: var(--text-main); }
.form-input { width: 100%; padding: 12px; background: var(--bg-input); border: 1px solid var(--border); border-radius: 10px; color: var(--text-main); outline: none; margin-bottom: 15px; }
.form-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow); }

.icon-selector { display: flex; gap: 10px; margin-bottom: 20px; }
.icon-option { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg-hover); display: flex; align-items: center; justify-content: center; cursor: pointer; font-size: 1.2rem; }
.icon-option.selected { border-color: var(--primary); background: var(--primary-glow); }

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
.btn-cancel { background: transparent; border: 1px solid var(--border); padding: 10px 20px; border-radius: 8px; cursor: pointer; color: var(--text-muted); font-weight: 600; }
.btn-create { background: var(--primary); border: none; padding: 10px 20px; border-radius: 8px; cursor: pointer; color: white; font-weight: 600; }

/* AI WIDGET STYLES */
.ai-widget { position: absolute; bottom: 30px; right: 30px; z-index: 999; }
.ai-minimized { background: var(--bg-card); backdrop-filter: blur(16px); border: 1px solid var(--border); border-radius: 50px; padding: 12px 24px; box-shadow: var(--shadow); color: var(--text-main); font-weight: 600; cursor: pointer; display: flex; align-items: center; gap: 10px; transition: transform 0.3s; }
.ai-minimized:hover { transform: translateY(-3px) scale(1.02); }
.widget-status { width: 8px; height: 8px; background: #10b981; border-radius: 50%; box-shadow: 0 0 10px #10b981; }
.chat-interface { position: absolute; bottom: 0; right: 0; width: 380px; height: 550px; background: var(--bg-card); backdrop-filter: blur(20px); border: 1px solid var(--border); border-radius: 24px; box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25); display: flex; flex-direction: column; overflow: hidden; opacity: 0; pointer-events: none; transform: translateY(20px) scale(0.95); transition: all 0.4s; }
.ai-widget.expanded .chat-interface { opacity: 1; pointer-events: auto; transform: translateY(0) scale(1); }
.ai-widget.expanded .ai-minimized { opacity: 0; pointer-events: none; display: none; }
.chat-header { padding: 18px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; background: rgba(255, 255, 255, 0.05); }
.ai-profile { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.ai-avatar-small { width: 32px; height: 32px; border-radius: 8px; background: linear-gradient(135deg, #10b981, #059669); display: flex; align-items: center; justify-content: center; color: white; }
.close-chat { background: none; border: none; color: var(--text-muted); cursor: pointer; }
.chat-body { flex: 1; padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.msg { padding: 12px 16px; font-size: 0.9rem; line-height: 1.5; max-width: 85%; border-radius: 12px; white-space: pre-wrap; }
.msg-user { align-self: flex-end; background: linear-gradient(135deg, #6366f1, #8b5cf6); color: white; border-radius: 18px 18px 0 18px; }
.msg-ai { align-self: flex-start; background: var(--bg-hover); border: 1px solid var(--border); color: var(--text-main); border-radius: 18px 18px 18px 0; }
.chat-footer { padding: 16px; }
.chat-input-container { background: var(--bg-card); border: 1px solid var(--border); border-radius: 50px; padding: 6px 6px 6px 16px; display: flex; align-items: center; }
.chat-input { flex: 1; border: none; background: transparent; outline: none; color: var(--text-main); }
.send-btn { width: 36px; height: 36px; border-radius: 50%; background: var(--primary); color: white; border: none; cursor: pointer; }

/* Mobile Responsive Adjustments */
@media (max-width: 1024px) {
    /* Reveal Main Sidebar on Button Click */
    .sidebar { position: fixed; transform: translateX(-100%); transition: transform 0.3s; z-index: 30; height: 100%; box-shadow: 2px 0 10px rgba(0,0,0,0.1); }
    .sidebar.open { transform: translateX(0); }
    
    .mobile-menu-btn { display: block; }
    .search-wrapper { max-width: 200px; }
    
    .info-panel { display: none; } 
}

/* Stricter mobile styles for very small screens */
@media (max-width: 768px) {
    /* Compact Channel Sidebar */
    .channel-sidebar { width: 70px; padding: 10px; } 
    .channel-group-label, .branch-select-icon, .create-group-btn span { display: none; }
    .channel-item .channel-text { display: none; }
    .channel-item { justify-content: center; padding: 10px 0; }
    .channel-hash { margin: 0; font-size: 1.3rem; opacity: 1; }
    .create-group-btn { padding: 10px 0; }
    .create-group-btn i { margin: 0; }
    
    .chat-area-header { padding: 0 15px; }
}

/* --- Responsive fixes (small screens) --- */
@media (max-width: 600px) {
    .top-bar { padding: 0 16px; gap: 10px; }
    .search-wrapper { width: auto; flex: 1; min-width: 0; }
    .header-actions { gap: 8px; flex-shrink: 0; }
    .action-btn { width: 38px; height: 38px; }
    .mobile-menu-btn { margin-right: 4px; }
}
