/* ========================================
   OwnChat — Dark Futuristic Theme System
   ======================================== */

/* ═══ THEME VARIABLES ═══ */
:root {
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --radius: 8px;
  --transition: 150ms ease;
  --primary: #0A84FF;
  --primary-hover: #0070E0;
  --danger: #E01E5A;
}

/* Default theme — Dark Blue Futuristic */
[data-theme="default"], :root {
  --workspace-bg: #0A0E1A;
  --workspace-text: rgba(160,200,255,.85);
  --workspace-hover: rgba(80,160,255,.1);
  --workspace-active: #111833;
  --sidebar-bg: #0F1528;
  --sidebar-text: #B0C8E8;
  --sidebar-text-muted: rgba(160,190,230,.45);
  --sidebar-hover: rgba(80,160,255,.08);
  --sidebar-active: #0A84FF;
  --sidebar-active-text: #fff;
  --sidebar-border: rgba(80,130,200,.12);
  --main-bg: #0C1220;
  --main-text: #C8D8F0;
  --main-text-muted: #6B80A0;
  --main-header-bg: #0C1220;
  --main-header-border: rgba(80,130,200,.15);
  --input-bg: #131B2E;
  --input-border: rgba(80,130,200,.25);
  --input-text: #C8D8F0;
  --msg-hover: rgba(80,160,255,.04);
  --badge-bg: #E01E5A;
  --badge-text: #fff;
  --scrollbar-track: transparent;
  --scrollbar-thumb: rgba(80,130,200,.2);
}

[data-theme="aubergine"] {
  --workspace-bg: #3F0E40;
  --workspace-text: rgba(255,255,255,.8);
  --workspace-hover: rgba(255,255,255,.1);
  --workspace-active: #4A154B;
  --sidebar-bg: #3F0E40;
  --sidebar-text: #ccc;
  --sidebar-text-muted: rgba(255,255,255,.5);
  --sidebar-hover: rgba(255,255,255,.06);
  --sidebar-active: #1264A3;
  --sidebar-active-text: #fff;
  --sidebar-border: rgba(255,255,255,.1);
  --main-bg: #222529;
  --main-text: #D1D2D3;
  --main-text-muted: #ABABAD;
  --main-header-bg: #222529;
  --main-header-border: #393B3F;
  --input-bg: #36383D;
  --input-border: #565856;
  --input-text: #D1D2D3;
  --msg-hover: rgba(255,255,255,.03);
  --badge-bg: #E01E5A;
  --badge-text: #fff;
  --scrollbar-track: transparent;
  --scrollbar-thumb: rgba(255,255,255,.15);
}

[data-theme="midnight"] {
  --workspace-bg: #0D1B2A;
  --workspace-text: rgba(180,210,240,.9);
  --workspace-hover: rgba(100,180,255,.08);
  --workspace-active: #1B263B;
  --sidebar-bg: #1B263B;
  --sidebar-text: #B4D2F0;
  --sidebar-text-muted: rgba(180,210,240,.45);
  --sidebar-hover: rgba(100,180,255,.08);
  --sidebar-active: #415A77;
  --sidebar-active-text: #E0E8F0;
  --sidebar-border: rgba(100,150,200,.15);
  --main-bg: #0D1B2A;
  --main-text: #C8D8E8;
  --main-text-muted: #778DA9;
  --main-header-bg: #0D1B2A;
  --main-header-border: #1B263B;
  --input-bg: #1B263B;
  --input-border: #415A77;
  --input-text: #C8D8E8;
  --msg-hover: rgba(100,180,255,.04);
  --badge-bg: #E63946;
  --badge-text: #fff;
  --scrollbar-track: transparent;
  --scrollbar-thumb: rgba(100,150,200,.2);
}

[data-theme="ocean"] {
  --workspace-bg: #003B4F;
  --workspace-text: rgba(200,240,255,.9);
  --workspace-hover: rgba(0,200,255,.08);
  --workspace-active: #005F73;
  --sidebar-bg: #005F73;
  --sidebar-text: #A8DADC;
  --sidebar-text-muted: rgba(168,218,220,.5);
  --sidebar-hover: rgba(0,200,255,.08);
  --sidebar-active: #0A9396;
  --sidebar-active-text: #fff;
  --sidebar-border: rgba(0,200,255,.12);
  --main-bg: #001219;
  --main-text: #E0F4F5;
  --main-text-muted: #8ECAE6;
  --main-header-bg: #001219;
  --main-header-border: #005F73;
  --input-bg: #003B4F;
  --input-border: #0A9396;
  --input-text: #E0F4F5;
  --msg-hover: rgba(0,200,255,.04);
  --badge-bg: #EE6C4D;
  --badge-text: #fff;
  --scrollbar-track: transparent;
  --scrollbar-thumb: rgba(0,200,200,.2);
}

[data-theme="emerald"] {
  --workspace-bg: #1A3A2A;
  --workspace-text: rgba(200,240,200,.9);
  --workspace-hover: rgba(100,255,100,.06);
  --workspace-active: #2D5A3F;
  --sidebar-bg: #2D5A3F;
  --sidebar-text: #A8D5B8;
  --sidebar-text-muted: rgba(168,213,184,.5);
  --sidebar-hover: rgba(100,255,100,.06);
  --sidebar-active: #3B8B5F;
  --sidebar-active-text: #fff;
  --sidebar-border: rgba(100,200,100,.12);
  --main-bg: #0E1F15;
  --main-text: #D0E8D0;
  --main-text-muted: #7DB88F;
  --main-header-bg: #0E1F15;
  --main-header-border: #2D5A3F;
  --input-bg: #1A3A2A;
  --input-border: #3B8B5F;
  --input-text: #D0E8D0;
  --msg-hover: rgba(100,255,100,.04);
  --badge-bg: #E63946;
  --badge-text: #fff;
  --scrollbar-track: transparent;
  --scrollbar-thumb: rgba(100,200,100,.2);
}

[data-theme="sunset"] {
  --workspace-bg: #2D1B34;
  --workspace-text: rgba(255,200,200,.9);
  --workspace-hover: rgba(255,120,80,.08);
  --workspace-active: #4A2545;
  --sidebar-bg: #4A2545;
  --sidebar-text: #E8B4B4;
  --sidebar-text-muted: rgba(232,180,180,.5);
  --sidebar-hover: rgba(255,120,80,.08);
  --sidebar-active: #D35400;
  --sidebar-active-text: #fff;
  --sidebar-border: rgba(255,150,100,.12);
  --main-bg: #1A0F1E;
  --main-text: #F0D0D0;
  --main-text-muted: #C08080;
  --main-header-bg: #1A0F1E;
  --main-header-border: #4A2545;
  --input-bg: #2D1B34;
  --input-border: #D35400;
  --input-text: #F0D0D0;
  --msg-hover: rgba(255,120,80,.04);
  --badge-bg: #F39C12;
  --badge-text: #fff;
  --scrollbar-track: transparent;
  --scrollbar-thumb: rgba(255,150,100,.2);
}

[data-theme="light"] {
  --workspace-bg: #1A3A6A;
  --workspace-text: rgba(255,255,255,.9);
  --workspace-hover: rgba(255,255,255,.1);
  --workspace-active: #0F2850;
  --sidebar-bg: #F8F8F8;
  --sidebar-text: #333;
  --sidebar-text-muted: rgba(0,0,0,.5);
  --sidebar-hover: rgba(0,0,0,.04);
  --sidebar-active: #0A84FF;
  --sidebar-active-text: #fff;
  --sidebar-border: #E0E0E0;
  --main-bg: #FFFFFF;
  --main-text: #1D1C1D;
  --main-text-muted: #616061;
  --main-header-bg: #FFFFFF;
  --main-header-border: #E8E8E8;
  --input-bg: #F0F0F0;
  --input-border: #D0D0D0;
  --input-text: #1D1C1D;
  --msg-hover: rgba(0,0,0,.02);
  --badge-bg: #E01E5A;
  --badge-text: #fff;
  --scrollbar-track: transparent;
  --scrollbar-thumb: rgba(0,0,0,.15);
}

/* ═══ RESET & BASE ═══ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body { font-family: var(--font); font-size: 15px; line-height: 1.46; background: var(--main-bg); color: var(--main-text); -webkit-font-smoothing: antialiased; }
::selection { background: var(--primary); color: #fff; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
input, textarea, select, button { font-family: inherit; font-size: inherit; }
a { color: #4DA6FF; text-decoration: none; }
a:hover { text-decoration: underline; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--scrollbar-track); }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 3px; }

/* ═══ AUTH SCREEN — FUTURISTIC ═══ */
.auth-screen { height: 100vh; display: flex; align-items: center; justify-content: center; background: #060B18; position: relative; overflow: hidden; }
.auth-bg-shapes { position: absolute; inset: 0; pointer-events: none; }
.shape { position: absolute; border-radius: 50%; filter: blur(80px); opacity: .5; }
.shape-1 { width: 500px; height: 500px; background: radial-gradient(circle, #0A84FF, transparent 70%); top: -10%; left: -5%; animation: float1 12s ease-in-out infinite; }
.shape-2 { width: 400px; height: 400px; background: radial-gradient(circle, #00D4FF, transparent 70%); bottom: -10%; right: -5%; animation: float2 10s ease-in-out infinite; }
.shape-3 { width: 350px; height: 350px; background: radial-gradient(circle, #7B2FFF, transparent 70%); top: 20%; right: 15%; animation: float3 14s ease-in-out infinite; }
.shape-4 { width: 300px; height: 300px; background: radial-gradient(circle, #FF3CAC, transparent 70%); bottom: 15%; left: 10%; animation: float1 11s ease-in-out infinite reverse; }
.shape-5 { width: 200px; height: 200px; background: radial-gradient(circle, #00F5D4, transparent 70%); top: 50%; left: 50%; transform: translate(-50%, -50%); animation: float2 9s ease-in-out infinite; }

@keyframes float1 { 0%, 100% { transform: translate(0, 0); } 50% { transform: translate(30px, -40px); } }
@keyframes float2 { 0%, 100% { transform: translate(0, 0); } 50% { transform: translate(-25px, 30px); } }
@keyframes float3 { 0%, 100% { transform: translate(0, 0); } 50% { transform: translate(20px, 25px); } }

.auth-container { width: 380px; background: rgba(12, 18, 35, .85); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); border: 1px solid rgba(80,130,200,.15); border-radius: 16px; padding: 36px; box-shadow: 0 20px 80px rgba(0,0,0,.5), 0 0 0 1px rgba(255,255,255,.03) inset; position: relative; z-index: 1; }
.auth-logo { text-align: center; margin-bottom: 28px; }
.auth-logo svg { margin-bottom: 12px; }
.auth-logo h1 { color: #fff; font-size: 26px; font-weight: 700; letter-spacing: -.5px; }
.auth-logo p { color: #6B80A0; font-size: 14px; margin-top: 4px; }
.auth-form .form-group { margin-bottom: 16px; }
.auth-form label { display: block; font-size: 13px; font-weight: 600; color: #B0C8E8; margin-bottom: 6px; }
.auth-form input[type="text"], .auth-form input[type="password"] { width: 100%; padding: 10px 12px; background: rgba(20,30,50,.8); border: 1px solid rgba(80,130,200,.25); border-radius: 8px; color: #C8D8F0; }
.auth-form input:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px rgba(10,132,255,.15); }
.error-msg { color: var(--danger); font-size: 13px; margin-top: 8px; min-height: 20px; }
.auth-switch { text-align: center; font-size: 13px; color: #6B80A0; margin-top: 16px; }
.demo-hint { text-align: center; font-size: 12px; color: #4A5A78; margin-top: 16px; background: rgba(255,255,255,.03); padding: 8px; border-radius: 8px; }
.demo-hint span { font-weight: 600; }
.demo-hint code { background: rgba(10,132,255,.15); padding: 2px 6px; border-radius: 3px; color: #4DA6FF; }

/* OAuth Divider & Buttons */
.auth-divider { display: flex; align-items: center; gap: 12px; margin: 18px 0; }
.auth-divider::before, .auth-divider::after { content: ''; flex: 1; height: 1px; background: rgba(80,130,200,.2); }
.auth-divider span { font-size: 12px; color: #4A5A78; white-space: nowrap; }
.oauth-buttons { display: flex; gap: 10px; margin-bottom: 4px; }
.oauth-btn { flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 14px; border: 1px solid rgba(80,130,200,.2); border-radius: 8px; background: rgba(20,30,50,.6); color: #B0C8E8; cursor: pointer; font-size: 13px; font-weight: 500; transition: var(--transition); }
.oauth-btn:hover { background: rgba(40,60,90,.6); border-color: rgba(80,130,200,.35); }
.oauth-btn svg { flex-shrink: 0; }

/* ═══ BUTTONS ═══ */
.btn-primary { width: 100%; padding: 10px; background: var(--primary); color: #fff; border: none; border-radius: 8px; font-weight: 600; cursor: pointer; transition: var(--transition); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { padding: 8px 16px; background: transparent; border: 1px solid var(--input-border); color: var(--main-text); border-radius: 6px; cursor: pointer; font-weight: 500; transition: var(--transition); }
.btn-secondary:hover { background: var(--msg-hover); }
.btn-danger { padding: 8px 16px; background: transparent; border: 1px solid var(--danger); color: var(--danger); border-radius: 6px; cursor: pointer; font-weight: 500; }
.btn-danger:hover { background: rgba(224,30,90,.1); }
.btn-text { background: none; border: none; color: var(--primary); cursor: pointer; font-weight: 500; font-size: 13px; }
.btn-text:hover { text-decoration: underline; }
.btn-text-sm { background: none; border: none; color: var(--primary); cursor: pointer; font-size: 12px; }
.btn-file { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font-size: 13px; }
.icon-btn { background: none; border: none; color: var(--main-text-muted); cursor: pointer; padding: 6px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; transition: var(--transition); }
.icon-btn:hover { background: var(--msg-hover); color: var(--main-text); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.small svg { width: 16px; height: 16px; }

/* ═══ APP LAYOUT ═══ */
.app { 
  display: flex; 
  height: 100vh; 
  height: 100dvh; /* Dynamic viewport height for mobile */
  width: 100vw; 
  overflow: hidden; 
  position: relative;
}

/* Workspace Bar */
.workspace-bar { width: 60px; background: var(--workspace-bg); display: flex; flex-direction: column; align-items: center; padding: 12px 0; flex-shrink: 0; }
.workspace-icon { width: 36px; height: 36px; background: var(--workspace-active); border-radius: 10px; display: flex; align-items: center; justify-content: center; color: var(--workspace-text); margin-bottom: 16px; }
.workspace-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.workspace-bottom { display: flex; flex-direction: column; gap: 4px; align-items: center; }
.ws-nav-btn { width: 40px; height: 40px; border: none; background: none; color: var(--workspace-text); border-radius: 8px; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: var(--transition); position: relative; }
.ws-nav-btn:hover { background: var(--workspace-hover); }
.ws-nav-btn.active { background: var(--workspace-active); color: #fff; }
.ws-nav-btn svg { width: 20px; height: 20px; }

/* Sidebar */
.sidebar { width: 260px; background: var(--sidebar-bg); display: flex; flex-direction: column; border-right: 1px solid var(--sidebar-border); flex-shrink: 0; overflow: hidden; }
.sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--sidebar-border); }
.sidebar-header h2 { font-size: 16px; font-weight: 700; color: var(--sidebar-text); }
.sidebar-panel { flex: 1; overflow-y: auto; padding: 8px 0; }
.sidebar-panel.sidebar-split { display: flex; flex-direction: column; }
.sidebar-section { padding: 0 8px; }
.sidebar-section-half { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; }
.sidebar-section-half .nav-list { flex: 1; overflow-y: auto; }
.section-header { display: flex; align-items: center; gap: 4px; padding: 6px 8px; font-size: 13px; font-weight: 600; color: var(--sidebar-text-muted); text-transform: uppercase; letter-spacing: .5px; }
.section-chevron { width: 14px; height: 14px; }
.nav-list { display: flex; flex-direction: column; gap: 1px; }
.nav-item { display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 6px; cursor: pointer; color: var(--sidebar-text); font-size: 14px; transition: var(--transition); position: relative; }
.nav-item:hover { background: var(--sidebar-hover); }
.nav-item.active { background: var(--sidebar-active); color: var(--sidebar-active-text); }
.nav-item.has-unread .nav-label { font-weight: 700; color: var(--sidebar-text); }
.nav-item.active.has-unread .nav-label { color: var(--sidebar-active-text); }
.nav-icon { font-size: 14px; opacity: .7; width: 18px; text-align: center; flex-shrink: 0; }
.nav-icon i { width: 16px; height: 16px; }
.nav-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unread-badge { background: var(--badge-bg); color: var(--badge-text); font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 10px; margin-left: auto; min-width: 18px; text-align: center; flex-shrink: 0; }

/* Sidebar Bottom */
.sidebar-bottom { 
  padding: 8px; 
  border-top: 1px solid var(--sidebar-border); 
  flex-shrink: 0;
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.sidebar-bottom .nav-item {
  width: 100%;
  color: var(--sidebar-text);
  background: none;
  border: none;
  cursor: pointer;
}
.sidebar-bottom .nav-item:hover {
  background: var(--sidebar-hover);
}
.sidebar-bottom .nav-item .nav-icon {
  display: flex;
  align-items: center;
  justify-content: center;
}
.sidebar-bottom .nav-item .mini-avatar {
  width: 18px;
  height: 18px;
  font-size: 10px;
}

/* Main */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--main-bg); }
.main-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 20px; border-bottom: 1px solid var(--main-header-border); background: var(--main-header-bg); flex-shrink: 0; min-height: 52px; gap: 12px; }
.header-left { display: flex; align-items: center; gap: 8px; min-width: 0; flex-shrink: 0; }
.header-left h3 { font-size: 16px; font-weight: 700; color: var(--main-text); white-space: nowrap; }
.header-desc { font-size: 13px; color: var(--main-text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header-right { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.badge { font-size: 11px; background: var(--main-text-muted); color: var(--main-bg); border-radius: 8px; padding: 0 5px; margin-left: 2px; }

/* Header Search Bar */
.header-search { flex: 1; max-width: 480px; min-width: 120px; }
.header-search-wrap { display: flex; align-items: center; gap: 6px; background: var(--input-bg); border: 1px solid var(--input-border); border-radius: 6px; padding: 5px 10px; transition: var(--transition); }
.header-search-wrap:focus-within { border-color: var(--primary); }
.header-search-icon { width: 16px; height: 16px; color: var(--main-text-muted); flex-shrink: 0; }
.header-search-wrap input { flex: 1; background: none; border: none; color: var(--main-text); outline: none; font-size: 13px; }
.header-search-wrap input::placeholder { color: var(--main-text-muted); }

/* Messages */
.main-body { 
  flex: 1; 
  display: flex; 
  flex-direction: column; 
  overflow: hidden; 
  position: relative;
  min-height: 0;
}
.messages-container { 
  flex: 1; 
  overflow-y: auto; 
  padding: 16px 20px;
  -webkit-overflow-scrolling: touch;
  min-height: 0;
}
.load-more { text-align: center; padding: 8px; }

.date-divider { display: flex; align-items: center; gap: 12px; padding: 8px 0; margin: 8px 0; }
.date-divider::before, .date-divider::after { content: ''; flex: 1; height: 1px; background: var(--main-header-border); }
.date-divider span { font-size: 12px; font-weight: 600; color: var(--main-text-muted); white-space: nowrap; padding: 2px 10px; background: var(--main-bg); border-radius: 12px; border: 1px solid var(--main-header-border); }

.message { display: flex; gap: 10px; padding: 6px 4px; border-radius: 6px; transition: background var(--transition); position: relative; }
.message:hover { background: var(--msg-hover); }
.message.deleted { opacity: .5; }
.message.system { justify-content: center; }
.message.system .msg-content { color: var(--main-text-muted); font-style: italic; font-size: 13px; }

.msg-avatar { width: 36px; height: 36px; border-radius: 8px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; color: #fff; background-size: cover; background-position: center; cursor: pointer; }
.msg-body { flex: 1; min-width: 0; }
.msg-header { display: flex; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.msg-author { font-weight: 700; font-size: 14px; color: var(--main-text); cursor: pointer; }
.msg-author:hover { text-decoration: underline; }
.msg-time { font-size: 12px; color: var(--main-text-muted); }
.msg-edited { font-size: 11px; color: var(--main-text-muted); }
.msg-content { font-size: 15px; line-height: 1.46; word-break: break-word; }
.msg-content code { background: rgba(80,160,255,.1); padding: 1px 4px; border-radius: 3px; font-family: 'JetBrains Mono', monospace; font-size: 13px; }
.msg-content pre { background: rgba(80,160,255,.06); padding: 12px; border-radius: 6px; margin: 4px 0; overflow-x: auto; }
.msg-content pre code { background: none; padding: 0; }
.msg-content strong { font-weight: 700; }
.msg-content em { font-style: italic; }
.msg-content del { text-decoration: line-through; opacity: .6; }
.msg-content .mention { background: rgba(10,132,255,.25); color: #4DA6FF; padding: 1px 4px; border-radius: 3px; font-weight: 600; cursor: pointer; }
.msg-content a { color: #4DA6FF; }

/* Message File Attachment */
.msg-file { margin-top: 6px; display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; background: rgba(80,160,255,.05); border: 1px solid var(--main-header-border); border-radius: 8px; }
.msg-file a { color: var(--primary); font-weight: 500; font-size: 13px; }
.msg-file-size { font-size: 12px; color: var(--main-text-muted); }
.msg-file-download { background: none; border: none; color: var(--main-text-muted); cursor: pointer; padding: 4px; border-radius: 4px; display: flex; align-items: center; margin-left: auto; }
.msg-file-download:hover { color: var(--primary); background: var(--msg-hover); }
.msg-file-download svg { width: 16px; height: 16px; }
.msg-image-container { margin-top: 6px; }
.msg-image { max-width: 400px; max-height: 300px; border-radius: 8px; cursor: pointer; display: block; transition: opacity 0.2s; }
.msg-image:hover { opacity: 0.9; }
.msg-gif { max-width: 300px; max-height: 250px; border-radius: 8px; cursor: pointer; display: block; transition: opacity 0.2s; }
.msg-gif:hover { opacity: 0.9; }

/* Pinned badge */
.msg-pin-badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; color: #ECB22E; margin-left: 8px; }
.msg-pin-badge svg { width: 12px; height: 12px; }

/* Thread reply count link */
.thread-reply-link { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--primary); cursor: pointer; margin-top: 4px; padding: 2px 0; }
.thread-reply-link:hover { text-decoration: underline; }
.thread-reply-link svg { width: 14px; height: 14px; }

/* Message Actions (hover) */
.msg-actions { position: absolute; top: -8px; right: 8px; display: none; background: var(--input-bg); border: 1px solid var(--input-border); border-radius: 6px; padding: 2px; }
.message:hover .msg-actions { display: flex; }
.msg-action-btn { background: none; border: none; color: var(--main-text-muted); cursor: pointer; padding: 4px 6px; border-radius: 4px; display: flex; align-items: center; }
.msg-action-btn:hover { background: var(--msg-hover); color: var(--main-text); }
.msg-action-btn svg { width: 16px; height: 16px; }

/* Reactions */
.reactions-row { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.reaction-btn { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; background: rgba(80,160,255,.06); border: 1px solid var(--main-header-border); border-radius: 12px; cursor: pointer; font-size: 13px; color: var(--main-text); }
.reaction-btn:hover { background: rgba(80,160,255,.1); }
.reaction-btn.own { border-color: var(--primary); background: rgba(10,132,255,.15); }
.reaction-count { font-size: 12px; color: var(--main-text-muted); }

/* Typing */
.typing-indicator { display: flex; align-items: center; gap: 8px; padding: 4px 20px; font-size: 13px; color: var(--main-text-muted); }
.typing-dots { display: flex; gap: 3px; }
.typing-dots span { width: 5px; height: 5px; border-radius: 50%; background: var(--main-text-muted); animation: typeBounce .6s infinite alternate; }
.typing-dots span:nth-child(2) { animation-delay: .15s; }
.typing-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes typeBounce { to { opacity: .3; transform: translateY(-3px); } }

/* Message Input */
.message-input-container { padding: 8px 20px 16px; flex-shrink: 0; position: relative; }
.edit-banner { display: flex; align-items: center; justify-content: space-between; background: rgba(10,132,255,.15); padding: 6px 12px; border-radius: 6px 6px 0 0; font-size: 13px; color: var(--primary); }
.input-wrapper { display: flex; align-items: center; gap: 4px; background: var(--input-bg); border: 1px solid var(--input-border); border-radius: 8px; padding: 4px 8px; }
.input-wrapper:focus-within { border-color: var(--primary); }
.input-text-wrap { flex: 1; position: relative; }
#message-input { width: 100%; padding: 8px 4px; background: none; border: none; color: var(--input-text); outline: none; font-size: 14px; }
#message-input::placeholder { color: var(--main-text-muted); }
.input-action { background: none; border: none; color: var(--main-text-muted); cursor: pointer; padding: 6px; border-radius: 6px; display: flex; align-items: center; }
.input-action:hover { color: var(--main-text); background: var(--msg-hover); }
.input-action svg { width: 18px; height: 18px; }
.send-btn { color: var(--primary); }

/* Attach Dropdown */
.attach-dropdown-container { position: relative; }
.attach-dropdown { position: absolute; bottom: 100%; left: 0; margin-bottom: 6px; background: var(--input-bg); border: 1px solid var(--input-border); border-radius: 8px; box-shadow: 0 4px 20px rgba(0,0,0,.4); z-index: 100; min-width: 180px; padding: 4px; }
.attach-dropdown-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 12px; border: none; background: none; color: var(--main-text); cursor: pointer; border-radius: 6px; font-size: 13px; text-align: left; }
.attach-dropdown-item:hover { background: var(--msg-hover); }
.attach-dropdown-item svg { width: 16px; height: 16px; color: var(--main-text-muted); }

.file-preview { display: flex; gap: 8px; padding: 8px 0; flex-wrap: wrap; }
.file-preview-item { display: flex; align-items: center; gap: 6px; padding: 6px 10px; background: var(--input-bg); border: 1px solid var(--input-border); border-radius: 6px; font-size: 13px; color: var(--main-text); }
.file-preview-img { width: 40px; height: 40px; object-fit: cover; border-radius: 4px; }
.remove-file { cursor: pointer; color: var(--main-text-muted); margin-left: 4px; }

/* ═══ MENTION POPUP ═══ */
.mention-popup { position: absolute; bottom: 100%; left: 0; width: 280px; max-height: 200px; overflow-y: auto; background: var(--input-bg); border: 1px solid var(--input-border); border-radius: 8px; box-shadow: 0 4px 20px rgba(0,0,0,.4); z-index: 100; }
.mention-item { display: flex; align-items: center; gap: 8px; padding: 8px 12px; cursor: pointer; font-size: 13px; color: var(--main-text); }
.mention-item:hover, .mention-item.selected { background: var(--primary); color: #fff; }
.mini-avatar { width: 28px; height: 28px; border-radius: 6px; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; color: #fff; flex-shrink: 0; background-size: cover; background-position: center; }

/* ═══ SLASH COMMAND POPUP ═══ */
.slash-popup { position: absolute; bottom: 100%; left: 0; right: 0; max-height: 240px; overflow-y: auto; background: var(--input-bg); border: 1px solid var(--input-border); border-radius: 8px; box-shadow: 0 4px 20px rgba(0,0,0,.4); z-index: 100; margin-bottom: 4px; }
.slash-item { display: flex; align-items: center; gap: 10px; padding: 10px 14px; cursor: pointer; border-bottom: 1px solid var(--main-header-border); }
.slash-item:last-child { border-bottom: none; }
.slash-item:hover, .slash-item.selected { background: var(--primary); color: #fff; }
.slash-item .slash-name { font-weight: 600; font-size: 14px; color: var(--main-text); }
.slash-item .slash-desc { font-size: 12px; color: var(--main-text-muted); }
.slash-item:hover .slash-name, .slash-item.selected .slash-name,
.slash-item:hover .slash-desc, .slash-item.selected .slash-desc { color: #fff; }

/* ═══ THREAD PANEL ═══ */
.thread-panel { width: 360px; background: var(--main-bg); border-left: 1px solid var(--main-header-border); display: flex; flex-direction: column; flex-shrink: 0; }
.thread-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--main-header-border); }
.thread-header h3 { font-size: 15px; font-weight: 700; }
.thread-parent-msg { padding: 12px 16px; border-bottom: 1px solid var(--main-header-border); }
.thread-parent-msg .message { padding: 0; }
.thread-parent-msg .message:hover { background: none; }
.thread-divider { padding: 8px 16px; font-size: 12px; color: var(--main-text-muted); border-bottom: 1px solid var(--main-header-border); }
.thread-replies-list { flex: 1; overflow-y: auto; padding: 8px 16px; }
.thread-replies-list .message { padding: 6px 0; }
.thread-input-container { padding: 8px 16px 12px; border-top: 1px solid var(--main-header-border); }
.thread-input-container .input-wrapper { padding: 4px 8px; }
#thread-input { width: 100%; padding: 8px 4px; background: none; border: none; color: var(--input-text); outline: none; font-size: 14px; }
#thread-input::placeholder { color: var(--main-text-muted); }

/* ═══ MEMBERS PANEL ═══ */
.members-panel { width: 260px; background: var(--main-bg); border-left: 1px solid var(--main-header-border); display: flex; flex-direction: column; flex-shrink: 0; }
.members-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--main-header-border); }
.members-header h3 { font-size: 15px; font-weight: 700; }
.members-list { flex: 1; overflow-y: auto; padding: 8px; }
.member-item { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.member-item:hover { background: var(--msg-hover); }
.member-avatar { width: 32px; height: 32px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; color: #fff; position: relative; background-size: cover; background-position: center; flex-shrink: 0; }
.presence { position: absolute; bottom: -1px; right: -1px; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--main-bg); }
.presence.online { background: #2EB67D; }
.presence.offline { background: transparent; border-color: var(--main-text-muted); }
.member-info { min-width: 0; }
.member-name { font-size: 14px; font-weight: 600; color: var(--main-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-status { font-size: 12px; color: var(--main-text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-role-badge { display: inline-block; font-size: 10px; background: rgba(10,132,255,.3); color: var(--primary); padding: 1px 5px; border-radius: 3px; margin-left: 4px; font-weight: 600; vertical-align: middle; }

/* Pinned */
.pinned-list { flex: 1; overflow-y: auto; padding: 8px; }
.pinned-card { padding: 10px 12px; margin: 4px 0; background: rgba(80,160,255,.04); border-radius: 6px; border-left: 3px solid #ECB22E; }
.pinned-card-author { font-size: 13px; font-weight: 600; color: var(--main-text); }
.pinned-card-text { font-size: 13px; color: var(--main-text-muted); margin-top: 2px; }
.pinned-card-time { font-size: 11px; color: var(--main-text-muted); margin-top: 4px; }

/* Search */
.search-sidebar { padding: 8px; }
.search-results { overflow-y: auto; max-height: calc(100vh - 120px); }
.search-result { padding: 8px; border-radius: 6px; cursor: pointer; margin-bottom: 4px; }
.search-result:hover { background: var(--sidebar-hover); }
.search-result-meta { display: flex; gap: 8px; font-size: 12px; color: var(--sidebar-text-muted); margin-bottom: 2px; }
.search-result-text { font-size: 13px; color: var(--sidebar-text); }
.search-result mark { background: rgba(10,132,255,.3); color: var(--sidebar-text); border-radius: 2px; }

/* Bookmarks */
.bookmark-item { padding: 8px; border-radius: 6px; cursor: pointer; margin-bottom: 4px; }
.bookmark-item:hover { background: var(--sidebar-hover); }
.bookmark-meta { display: flex; gap: 8px; font-size: 12px; color: var(--sidebar-text-muted); margin-bottom: 2px; }
.bookmark-text { font-size: 13px; color: var(--sidebar-text); }

/* ═══ MODALS ═══ */
.modal { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.6); }
.modal-content { position: relative; background: var(--main-bg); border: 1px solid var(--main-header-border); border-radius: 12px; width: 480px; max-height: 80vh; display: flex; flex-direction: column; box-shadow: 0 16px 60px rgba(0,0,0,.5); }
.modal-content.modal-wide { width: 640px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--main-header-border); }
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-body { flex: 1; overflow-y: auto; padding: 20px; }
.modal-footer { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--main-header-border); }
.modal-subtitle { font-size: 13px; color: var(--main-text-muted); margin-bottom: 12px; }
.modal-section-title { font-size: 14px; font-weight: 600; margin: 16px 0 8px; color: var(--main-text); }

.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; color: var(--main-text); margin-bottom: 6px; }
.form-group .optional { font-weight: 400; color: var(--main-text-muted); }
.form-group input[type="text"], .form-group input[type="password"], .form-group textarea, .form-group select {
  width: 100%; padding: 8px 12px; background: var(--input-bg); border: 1px solid var(--input-border); border-radius: 6px; color: var(--input-text); resize: vertical;
}
.form-group input:focus, .form-group textarea:focus, .form-group select:focus { border-color: var(--primary); outline: none; }
.checkbox-label { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--main-text); cursor: pointer; }

/* Users List (modal) */
.users-list { max-height: 250px; overflow-y: auto; }
.users-list.compact { max-height: 180px; }
.user-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 6px; cursor: pointer; transition: var(--transition); }
.user-item:hover { background: var(--msg-hover); }
.user-item.selected { background: rgba(10,132,255,.2); border: 1px solid var(--primary); }

/* Profile */
.profile-card .modal-body { padding: 0; }
.profile-banner { height: 80px; background: linear-gradient(135deg, var(--workspace-bg), var(--sidebar-active)); border-radius: 11px 11px 0 0; }
.profile-avatar-lg { width: 72px; height: 72px; border-radius: 16px; margin: -36px auto 8px; border: 4px solid var(--main-bg); display: flex; align-items: center; justify-content: center; font-size: 24px; font-weight: 700; color: #fff; background-size: cover; background-position: center; }
.profile-name { text-align: center; font-size: 20px; font-weight: 700; }
.profile-title-text { text-align: center; font-size: 14px; color: var(--main-text-muted); margin-bottom: 16px; }
.profile-details { padding: 0 20px 20px; }
.profile-detail-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--main-header-border); font-size: 14px; }
.profile-detail-row .label { color: var(--main-text-muted); }
.profile-detail-row .value { color: var(--main-text); font-weight: 500; }

/* Avatar Upload */
.avatar-upload-section { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }
.avatar-lg { width: 64px; height: 64px; border-radius: 16px; display: flex; align-items: center; justify-content: center; font-size: 22px; font-weight: 700; color: #fff; flex-shrink: 0; background-size: cover; background-position: center; }

/* Avatar Crop */
.crop-container { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.crop-container canvas { max-width: 100%; border-radius: 8px; background: #000; cursor: move; }
.crop-controls { display: flex; gap: 20px; width: 100%; }
.crop-controls label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--main-text-muted); flex: 1; }
.crop-controls input[type="range"] { width: 100%; accent-color: var(--primary); }

/* ═══ ADMIN PANEL ═══ */
.admin-section { margin-bottom: 24px; }
.admin-section h4 { font-size: 15px; font-weight: 600; margin-bottom: 12px; color: var(--main-text); }
.admin-form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.admin-users-list { max-height: 350px; overflow-y: auto; }
.admin-user-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-bottom: 1px solid var(--main-header-border); }
.admin-user-row:last-child { border-bottom: none; }
.admin-user-info { flex: 1; min-width: 0; }
.admin-user-info .name { font-weight: 600; font-size: 14px; }
.admin-user-info .meta { font-size: 12px; color: var(--main-text-muted); }
.admin-user-actions { display: flex; gap: 6px; }
.admin-user-actions button { padding: 4px 10px; font-size: 12px; border-radius: 4px; cursor: pointer; border: 1px solid var(--input-border); background: none; color: var(--main-text-muted); }
.admin-user-actions button:hover { background: var(--msg-hover); color: var(--main-text); }
.admin-user-actions button.danger { border-color: var(--danger); color: var(--danger); }
.admin-user-actions button.danger:hover { background: rgba(224,30,90,.1); }

/* ═══ THEME PICKER ═══ */
.theme-list { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.theme-card { display: flex; align-items: center; gap: 10px; padding: 12px; border-radius: 8px; border: 2px solid var(--input-border); cursor: pointer; transition: var(--transition); }
.theme-card:hover { border-color: var(--primary); }
.theme-card.active { border-color: var(--primary); background: rgba(10,132,255,.1); }
.theme-preview { width: 40px; height: 28px; border-radius: 4px; flex-shrink: 0; display: flex; overflow: hidden; }
.theme-preview-bar { width: 12px; height: 100%; }
.theme-preview-main { flex: 1; }
.theme-name { font-size: 14px; font-weight: 600; color: var(--main-text); }

/* ═══ GIF PICKER ═══ */
.gif-picker { position: absolute; bottom: 80px; left: 20px; width: 360px; max-height: 420px; background: var(--input-bg); border: 1px solid var(--input-border); border-radius: 12px; box-shadow: 0 8px 30px rgba(0,0,0,.5); z-index: 200; display: flex; flex-direction: column; overflow: hidden; }
.gif-picker-header { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-bottom: 1px solid var(--main-header-border); }
.gif-picker-header input { flex: 1; background: var(--main-bg); border: 1px solid var(--input-border); border-radius: 6px; padding: 6px 10px; color: var(--input-text); outline: none; font-size: 13px; }
.gif-picker-header input:focus { border-color: var(--primary); }
.gif-results { flex: 1; overflow-y: auto; padding: 8px; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; min-height: 200px; }
.gif-results img { width: 100%; border-radius: 6px; cursor: pointer; display: block; }
.gif-results img:hover { opacity: .85; }
.gif-hint { grid-column: 1 / -1; text-align: center; color: var(--main-text-muted); font-size: 13px; padding: 40px 10px; }
.gif-powered { text-align: center; font-size: 10px; color: var(--main-text-muted); padding: 4px; border-top: 1px solid var(--main-header-border); }

/* Slash Commands Management */
.cmd-list { max-height: 300px; overflow-y: auto; }
.cmd-item { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; border-bottom: 1px solid var(--main-header-border); }
.cmd-item:last-child { border-bottom: none; }
.cmd-item-info .cmd-name { font-weight: 600; font-size: 14px; color: var(--main-text); }
.cmd-item-info .cmd-desc { font-size: 12px; color: var(--main-text-muted); }

/* ═══ DROPDOWN / CONTEXT MENU ═══ */
.dropdown-menu { 
  position: fixed; 
  background: var(--input-bg); 
  border: 1px solid var(--input-border); 
  border-radius: 10px; 
  padding: 8px; 
  min-width: 240px; 
  width: auto;
  max-width: calc(100vw - 32px);
  box-shadow: 0 8px 30px rgba(0,0,0,.5); 
  z-index: 500; 
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  white-space: nowrap;
}
.dropdown-user-info { padding: 8px 10px; }
.dropdown-name { font-weight: 700; font-size: 14px; color: var(--main-text); }
.dropdown-username { font-size: 12px; color: var(--main-text-muted); }
.dropdown-divider { height: 1px; background: var(--main-header-border); margin: 4px 0; }
.dropdown-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: none; background: none; color: var(--main-text); cursor: pointer; border-radius: 6px; font-size: 14px; text-align: left; }
.dropdown-item:hover { background: var(--msg-hover); }
.dropdown-item svg { width: 16px; height: 16px; color: var(--main-text-muted); }

.context-menu { position: fixed; background: var(--input-bg); border: 1px solid var(--input-border); border-radius: 8px; padding: 4px; min-width: 180px; box-shadow: 0 4px 20px rgba(0,0,0,.4); z-index: 500; }
.context-menu-item { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 10px; border: none; background: none; color: var(--main-text); cursor: pointer; border-radius: 4px; font-size: 13px; text-align: left; }
.context-menu-item:hover { background: var(--msg-hover); }
.context-menu-item.danger { color: var(--danger); }
.context-menu-item svg { width: 14px; height: 14px; }
.context-menu-divider { height: 1px; background: var(--main-header-border); margin: 4px 0; }

/* Emoji Picker */
.emoji-picker { position: fixed; background: var(--input-bg); border: 1px solid var(--input-border); border-radius: 10px; padding: 8px; box-shadow: 0 4px 20px rgba(0,0,0,.4); z-index: 500; }
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; }
.emoji-grid button { background: none; border: none; font-size: 22px; padding: 4px; cursor: pointer; border-radius: 4px; line-height: 1.2; }
.emoji-grid button:hover { background: var(--msg-hover); }

/* Toast */
.toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 10px 16px; border-radius: 8px; font-size: 13px; font-weight: 500; color: #fff; box-shadow: 0 4px 20px rgba(0,0,0,.3); animation: toastIn .3s ease; }
.toast.success { background: #2EB67D; }
.toast.error { background: #E01E5A; }
.toast.info { background: #0A84FF; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* ═══ RESPONSIVE DESIGN ═══ */
.mobile-only { display: none; }
.sidebar-overlay { display: none; }

/* ═══ LARGE SCREENS (> 1400px) ═══ */
@media (min-width: 1400px) {
  .sidebar { width: 280px; }
  .main { flex: 1; }
  .thread-panel { width: 400px; }
  .members-panel { width: 300px; }
  .modal-content { max-width: 600px; }
  .modal-content.modal-wide { max-width: 800px; }
}

/* ═══ TABLETS (768px - 1024px) ═══ */
@media (min-width: 768px) and (max-width: 1024px) {
  .workspace-bar { width: 50px; }
  .sidebar { width: 240px; }
  .main-header { padding: 10px 16px; }
  .header-search { max-width: 300px; }
  .thread-panel { width: 320px; }
  .members-panel { width: 240px; }
  .modal-content { width: 90%; max-width: 520px; }
  .modal-content.modal-wide { width: 95%; max-width: 700px; }
  .messages-container { padding: 16px; }
  .message-input-container { padding: 8px 16px 16px; }
  .msg-image { max-width: 350px; max-height: 250px; }
  .gif-picker { width: 320px; }
}

/* ═══ MOBILE (< 768px) ═══ */
@media (max-width: 768px) {
  .mobile-only { display: flex; }
  
  /* Layout adjustments */
  .workspace-bar { display: none; }
  .sidebar { 
    position: fixed; 
    left: -280px; 
    top: 0; 
    bottom: 0;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    z-index: 150; /* Higher than message input to overlap it */
    transition: left .3s ease; 
    width: 280px;
    box-shadow: 2px 0 10px rgba(0,0,0,.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  .sidebar.open {
    z-index: 150;
  }
  /* Hide message input when sidebar is open */
  .sidebar.open ~ .main .message-input-container,
  .sidebar.open + .main .message-input-container {
    z-index: 50; /* Lower than sidebar */
  }
  .sidebar-panel {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    min-height: 0;
  }
  .sidebar-section-half {
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .sidebar-section-half .nav-list {
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 12px;
  }
  .sidebar.open { left: 0; }
  .sidebar-overlay { 
    position: fixed; 
    inset: 0; 
    background: rgba(0,0,0,.6); 
    z-index: 149; /* Just below sidebar */
    pointer-events: none;
    backdrop-filter: blur(4px);
  }
  .sidebar-overlay.active,
  .sidebar.open ~ .sidebar-overlay,
  .sidebar.open + .sidebar-overlay { 
    display: block; 
    pointer-events: auto; 
  }
  .thread-panel { 
    display: none !important; 
  }
  
  /* Members panel as mobile modal */
  .members-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    height: 70vh;
    max-height: 70vh;
    border-left: none;
    border-top: 1px solid var(--main-header-border);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 20px rgba(0,0,0,.3);
    z-index: 200;
    transform: translateY(100%);
    transition: transform .3s ease;
  }
  .members-panel.mobile-open {
    transform: translateY(0);
  }
  .members-panel .members-header {
    padding: 16px;
    border-bottom: 1px solid var(--main-header-border);
  }
  .members-panel .members-list {
    padding: 12px;
    max-height: calc(70vh - 60px);
  }
  
  /* Main content */
  .main { width: 100%; }
  .main-header { 
    padding: 8px 12px; 
    gap: 8px; 
    flex-wrap: wrap;
    min-height: 48px;
  }
  .header-left { 
    flex-shrink: 1; 
    min-width: 0; 
    order: 1;
    flex-basis: auto;
  }
  .header-left h3 { 
    font-size: 15px; 
    overflow: hidden; 
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 200px;
  }
  .header-desc { 
    display: none; 
  }
  .header-search { 
    flex: 1 1 100%; 
    min-width: 0;
    max-width: none; 
    order: 3;
    margin-top: 4px;
  }
  .header-search-wrap { 
    padding: 6px 10px; 
  }
  .header-search-wrap input { 
    font-size: 14px; 
  }
  .header-right { 
    flex-shrink: 0; 
    gap: 4px; 
    order: 2;
  }
  .header-right .icon-btn { 
    width: 36px; 
    height: 36px; 
    padding: 8px;
  }
  .header-right .icon-btn svg { 
    width: 18px; 
    height: 18px; 
  }
  /* Hide channel settings button from header on mobile */
  #channel-settings-btn { 
    display: none; 
  }
  #mobile-menu-btn {
    display: flex;
    width: 36px;
    height: 36px;
  }
  
  /* Messages */
  .messages-container { 
    padding: 12px 16px; 
  }
  .message { 
    padding: 8px 4px; 
  }
  .msg-avatar { 
    width: 32px; 
    height: 32px; 
    font-size: 12px; 
  }
  .msg-author { 
    font-size: 13px; 
  }
  .msg-time { 
    font-size: 11px; 
  }
  .msg-content { 
    font-size: 14px; 
    line-height: 1.5; 
  }
  .msg-image { 
    max-width: 100%; 
    max-height: 250px; 
    width: auto;
  }
  .msg-gif { 
    max-width: 100%; 
    max-height: 200px; 
  }
  .msg-file { 
    padding: 6px 10px; 
    font-size: 12px; 
  }
  
  /* Message input - ensure always visible */
  .message-input-container { 
    padding: 10px 12px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 8px));
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--main-bg);
    z-index: 100; /* Lower than sidebar when sidebar is open */
    border-top: 1px solid var(--main-header-border);
    box-shadow: 0 -2px 10px rgba(0,0,0,.2);
    max-width: 100vw;
    width: 100%;
    transition: z-index 0s; /* Instant transition */
  }
  /* Hide message input behind sidebar when sidebar is open */
  .sidebar.open ~ .main .message-input-container {
    z-index: 50;
  }
  .main-body {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    padding-bottom: calc(75px + env(safe-area-inset-bottom, 0));
  }
  .messages-container {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 12px;
    min-height: 0;
  }
  .input-wrapper { 
    padding: 6px 8px; 
  }
  #message-input { 
    padding: 8px 4px; 
    font-size: 14px; 
  }
  .input-action { 
    padding: 6px; 
    min-width: 36px;
    min-height: 36px;
  }
  .input-action svg { 
    width: 18px; 
    height: 18px; 
  }
  
  /* Sidebar */
  .sidebar-header { 
    padding: 12px 14px; 
  }
  .sidebar-header h2 { 
    font-size: 15px; 
  }
  .nav-item { 
    padding: 8px 12px; 
    font-size: 14px; 
  }
  .section-header { 
    padding: 8px 10px; 
    font-size: 12px; 
  }
  
  /* Modals */
  .modal { 
    padding: 16px; 
    align-items: flex-start;
    padding-top: 20px;
  }
  .modal-content { 
    width: 100%; 
    max-width: 100%;
    max-height: 90vh;
    margin: 0;
    border-radius: 12px 12px 0 0;
  }
  .modal-content.modal-wide { 
    width: 100%; 
  }
  .modal-header { 
    padding: 14px 16px; 
  }
  .modal-header h3 { 
    font-size: 15px; 
  }
  .modal-body { 
    padding: 16px; 
  }
  .modal-footer { 
    padding: 12px 16px; 
    flex-wrap: wrap;
    gap: 8px;
  }
  .modal-footer button { 
    flex: 1;
    min-width: 120px;
  }
  
  /* Forms */
  .form-group { 
    margin-bottom: 16px; 
  }
  .form-group input[type="text"], 
  .form-group input[type="password"], 
  .form-group input[type="email"],
  .form-group textarea, 
  .form-group select {
    padding: 10px 12px;
    font-size: 15px;
  }
  
  /* Auth screen */
  .auth-container { 
    width: 90%; 
    max-width: 400px;
    padding: 28px 24px; 
    margin: 20px;
  }
  .auth-logo h1 { 
    font-size: 24px; 
  }
  .auth-logo p { 
    font-size: 13px; 
  }
  .oauth-buttons { 
    flex-direction: column; 
    gap: 8px; 
  }
  .oauth-btn { 
    width: 100%; 
  }
  
  /* Dropdowns and popups */
  .mention-popup { 
    width: calc(100% - 24px); 
    max-width: 280px; 
  }
  .slash-popup { 
    max-height: 200px; 
  }
  .attach-dropdown { 
    min-width: 160px; 
  }
  .dropdown-menu { 
    min-width: 280px; 
    width: auto;
    max-width: calc(100vw - 32px);
    padding: 10px;
  }
  .dropdown-item {
    padding: 10px 12px;
    font-size: 15px;
  }
  .dropdown-user-info {
    padding: 10px 12px;
  }
  .context-menu { 
    min-width: 160px; 
    max-width: calc(100vw - 32px);
  }
  
  /* GIF Picker */
  .gif-picker { 
    bottom: 70px; 
    left: 12px; 
    right: 12px;
    width: auto;
    max-width: none;
    max-height: 50vh;
  }
  .gif-results { 
    grid-template-columns: repeat(2, 1fr); 
    gap: 4px; 
  }
  
  /* Thread panel - hidden on mobile */
  .thread-panel { 
    display: none !important; 
  }
  
  /* Members list */
  .members-list { 
    padding: 8px 12px; 
  }
  .member-item { 
    padding: 8px 10px; 
  }
  
  /* Profile */
  .profile-card .modal-body { 
    padding: 0; 
  }
  .profile-banner { 
    height: 60px; 
  }
  .profile-avatar-lg { 
    width: 60px; 
    height: 60px; 
    margin: -30px auto 8px; 
    font-size: 20px; 
  }
  .profile-name { 
    font-size: 18px; 
  }
  
  /* Admin panel */
  .admin-form-row { 
    grid-template-columns: 1fr; 
    gap: 12px; 
  }
  
  /* Theme picker */
  .theme-list { 
    grid-template-columns: 1fr; 
    gap: 8px; 
  }
  
  /* Toast */
  .toast-container { 
    bottom: 16px; 
    right: 16px; 
    left: 16px;
    right: auto;
  }
  .toast { 
    width: 100%;
    max-width: none;
  }
  
  /* Call overlay */
  .call-content { 
    padding: 32px 24px; 
  }
  .call-participants { 
    gap: 12px; 
  }
  .call-participant { 
    width: 60px; 
    height: 60px; 
    font-size: 18px; 
  }
  .call-control-btn { 
    width: 48px; 
    height: 48px; 
  }
  
  /* Incoming call */
  .incoming-call { 
    left: 16px; 
    right: 16px;
    transform: none;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
  }
  .incoming-call-actions { 
    width: 100%;
    justify-content: stretch;
  }
  .incoming-call-actions button { 
    flex: 1;
  }
  
  /* Link previews */
  .link-preview { 
    max-width: 100%; 
    flex-direction: column;
  }
  .link-preview-image { 
    width: 100%; 
    height: 150px; 
  }
  
  /* File preview */
  .file-preview { 
    gap: 6px; 
  }
  .file-preview-item { 
    font-size: 12px; 
    padding: 6px 8px; 
  }
  
  /* Emoji picker */
  .emoji-grid { 
    grid-template-columns: repeat(6, 1fr); 
  }
  .emoji-grid button { 
    font-size: 20px; 
    padding: 6px; 
  }
  
  /* Better touch targets */
  button, 
  .icon-btn, 
  .nav-item, 
  .member-item,
  .user-item {
    min-height: 44px;
    min-width: 44px;
  }
  
  /* Mobile profile button */
  #user-menu-btn-mobile {
    display: flex;
    align-items: center;
    justify-content: center;
  }
  #user-menu-btn-mobile .mini-avatar {
    width: 28px;
    height: 28px;
    font-size: 11px;
  }
  
  /* Ensure header buttons are visible */
  .header-right {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: nowrap;
  }
  
  /* Mobile panel overlay */
  .mobile-panel-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 199;
    display: none;
    backdrop-filter: blur(4px);
  }
  .mobile-panel-overlay.active {
    display: block;
  }
  
  /* Pinned panel mobile */
  .pinned-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    height: 70vh;
    max-height: 70vh;
    border-left: none;
    border-top: 1px solid var(--main-header-border);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 20px rgba(0,0,0,.3);
    z-index: 200;
    transform: translateY(100%);
    transition: transform .3s ease;
  }
  .pinned-panel.mobile-open {
    transform: translateY(0);
  }
  
  /* Close panels when clicking overlay */
  .mobile-panel-overlay.active ~ .members-panel.mobile-open,
  .mobile-panel-overlay.active ~ .pinned-panel.mobile-open {
    transform: translateY(100%);
  }
  
  /* Improved spacing */
  .sidebar-panel { 
    padding: 6px 0; 
  }
  .load-more { 
    padding: 12px; 
  }
  
  /* Typing indicator */
  .typing-indicator { 
    padding: 6px 16px; 
    font-size: 12px; 
  }
}

/* ═══ SMALL MOBILE (< 480px) ═══ */
@media (max-width: 480px) {
  .auth-container { 
    padding: 24px 20px; 
  }
  .main-header { 
    padding: 8px 10px; 
  }
  .header-left h3 { 
    font-size: 14px; 
    max-width: 150px;
  }
  .messages-container { 
    padding: 10px 12px; 
  }
  .message-input-container { 
    padding: 8px 10px 10px; 
  }
  .modal-body { 
    padding: 14px; 
  }
  .gif-results { 
    grid-template-columns: 1fr 1fr; 
  }
  .emoji-grid { 
    grid-template-columns: repeat(5, 1fr); 
  }
  .header-search { 
    order: 3;
    margin-top: 6px;
  }
  .header-right { 
    gap: 2px; 
  }
  .header-right .icon-btn { 
    width: 32px; 
    height: 32px; 
    padding: 6px;
  }
}

/* ═══ PRIVATE CHANNEL VISUAL DISTINCTION ═══ */
.nav-icon-private {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.private-lock-icon {
  width: 14px;
  height: 14px;
  opacity: 0.7;
  flex-shrink: 0;
}
.nav-item-private .nav-label {
  font-style: italic;
  opacity: 0.85;
}
.nav-item-private::after {
  content: '';
  display: none;
}

/* ═══ CHANNEL MEMBER MANAGEMENT ═══ */
.member-row {
  display: flex;
  align-items: center;
  padding: 8px 10px;
  border-radius: 6px;
  gap: 10px;
}
.member-row:hover {
  background: var(--sidebar-hover);
}
.member-row .member-info {
  flex: 1;
  min-width: 0;
}
.member-username {
  font-size: 12px;
  color: var(--main-text-muted);
}
.member-role-tag {
  font-size: 10px;
  background: var(--primary);
  color: white;
  padding: 1px 6px;
  border-radius: 3px;
  margin-left: 6px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.member-role-tag:empty {
  display: none;
}
.btn-remove-member {
  background: none;
  border: none;
  color: var(--main-text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  opacity: 0;
  transition: all .2s;
  flex-shrink: 0;
}
.member-row:hover .btn-remove-member {
  opacity: 1;
}
.btn-remove-member:hover {
  color: #ff4d4f;
  background: rgba(255,77,79,.1);
}
.add-members-actions {
  margin-bottom: 10px;
}
.btn-sm {
  font-size: 12px;
  padding: 5px 12px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.btn-sm i, .btn-sm svg {
  width: 14px;
  height: 14px;
}
#channel-members-list {
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid var(--sidebar-hover);
  border-radius: 6px;
  padding: 4px;
}

/* ═══ LINK PREVIEWS ═══ */
.link-preview {
  display: flex;
  margin-top: 8px;
  max-width: 480px;
  background: rgba(80,160,255,.04);
  border: 1px solid var(--main-header-border);
  border-left: 3px solid var(--primary);
  border-radius: 0 8px 8px 0;
  overflow: hidden;
  cursor: pointer;
  transition: background var(--transition);
}
.link-preview:hover {
  background: rgba(80,160,255,.08);
}
.link-preview-image {
  width: 100px;
  flex-shrink: 0;
}
.link-preview-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.link-preview-body {
  padding: 8px 12px;
  min-width: 0;
  flex: 1;
}
.link-preview-site {
  font-size: 11px;
  font-weight: 600;
  color: var(--main-text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 2px;
}
.link-preview-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--primary);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.link-preview-desc {
  font-size: 13px;
  color: var(--main-text-muted);
  margin-top: 2px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ═══ CALL OVERLAY ═══ */
.call-overlay {
  position: fixed;
  inset: 0;
  z-index: 1500;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6,11,24,.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.call-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
  padding: 48px;
}
.call-status {
  font-size: 18px;
  font-weight: 600;
  color: #fff;
  letter-spacing: -.3px;
}
.call-participants {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
}
.call-participant {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  border: 3px solid rgba(255,255,255,.15);
  box-shadow: 0 0 24px rgba(10,132,255,.3);
  animation: callPulse 2s ease-in-out infinite;
}
@keyframes callPulse {
  0%, 100% { box-shadow: 0 0 24px rgba(10,132,255,.3); }
  50% { box-shadow: 0 0 36px rgba(10,132,255,.5); }
}
.call-controls {
  display: flex;
  gap: 16px;
}
.call-control-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,.12);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  font-size: 0;
}
.call-control-btn:hover {
  background: rgba(255,255,255,.2);
}
.call-control-btn.danger {
  background: var(--danger);
}
.call-control-btn.danger:hover {
  background: #c4174d;
}
.call-control-btn.muted {
  background: rgba(255,255,255,.25);
}
.call-control-btn svg,
.call-control-btn i {
  width: 22px;
  height: 22px;
}

/* ═══ INCOMING CALL BANNER ═══ */
.incoming-call {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 20px;
  background: rgba(12,18,35,.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(10,132,255,.4);
  border-radius: 14px;
  box-shadow: 0 8px 40px rgba(0,0,0,.5), 0 0 0 1px rgba(255,255,255,.04) inset;
  animation: slideDown .3s ease;
}
@keyframes slideDown {
  from { opacity: 0; transform: translateX(-50%) translateY(-20px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}
.incoming-call-info {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
}
.incoming-call-info svg,
.incoming-call-info i {
  width: 20px;
  height: 20px;
  color: #2EB67D;
  animation: ring 1.2s ease-in-out infinite;
}
@keyframes ring {
  0%, 100% { transform: rotate(0deg); }
  20% { transform: rotate(15deg); }
  40% { transform: rotate(-10deg); }
  60% { transform: rotate(8deg); }
  80% { transform: rotate(-5deg); }
}
.incoming-call-actions {
  display: flex;
  gap: 8px;
}

/* ═══ HIGHLIGHT MESSAGE (jump-to) ═══ */
.highlight-message {
  animation: highlightFlash 3s ease;
}
@keyframes highlightFlash {
  0% { background: rgba(10,132,255,.3); }
  30% { background: rgba(10,132,255,.2); }
  100% { background: transparent; }
}

/* ═══ EMAIL INPUT IN FORMS ═══ */
.form-group input[type="email"] {
  width: 100%; padding: 8px 12px; background: var(--input-bg); border: 1px solid var(--input-border); border-radius: 6px; color: var(--input-text);
}
.form-group input[type="email"]:focus { border-color: var(--primary); outline: none; }

/* ═══ PASSWORD CHANGE SECTION ═══ */
.password-change-section {
  border-top: 1px solid var(--input-border);
  padding-top: 8px;
  margin-top: 12px;
}
.password-change-section .form-group { margin-bottom: 10px; }
.password-change-section input[type="password"] {
  width: 100%; padding: 8px 12px; background: var(--input-bg); border: 1px solid var(--input-border); border-radius: 6px; color: var(--input-text); font-size: 13px;
}
.password-change-section input[type="password"]:focus { border-color: var(--primary); outline: none; }
#change-pw-btn { margin-top: 4px; }

/* ═══ IMAGE VIEWER MODAL ═══ */
.image-viewer-content {
  width: 90vw;
  max-width: 1200px;
  height: 90vh;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  padding: 0;
}
.image-viewer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--main-header-border);
  flex-shrink: 0;
}
.image-viewer-filename {
  font-size: 14px;
  font-weight: 600;
  color: var(--main-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}
.image-viewer-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.image-viewer-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: 20px;
  min-height: 0;
}
.image-viewer-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
}
