/* ========== CSS VARIABLES ========== */
:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-tertiary: #0f3460;
  --bg-surface: #1e2746;
  --bg-hover: #253258;
  --bg-active: #2d3a6a;
  --text-primary: #e8e8e8;
  --text-secondary: #a0a0b0;
  --text-muted: #6b6b80;
  --accent: #00b4d8;
  --accent-hover: #0096b7;
  --accent-light: rgba(0, 180, 216, 0.1);
  --success: #2ecc71;
  --warning: #f39c12;
  --danger: #e74c3c;
  --danger-hover: #c0392b;
  --border: #2a2a4a;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.4);
  --radius: 8px;
  --radius-lg: 12px;
  --radius-full: 50%;
  --sidebar-width: 280px;
  --transition: 0.2s ease;
}

/* ========== RESET & BASE ========== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

input, textarea, select, button {
  font-family: inherit;
  font-size: inherit;
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ========== UTILITIES ========== */
.screen { display: none; }
.screen.active { display: flex; width: 100%; height: 100vh; height: 100dvh; }
.view { display: none; flex-direction: column; flex: 1; overflow: hidden; }
.view.active { display: flex; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 500;
  font-size: 0.9rem;
  transition: all var(--transition);
}

.btn-primary {
  background: var(--accent);
  color: white;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.btn-secondary:hover { background: var(--bg-active); }

.btn-danger {
  background: var(--danger);
  color: white;
}
.btn-danger:hover { background: var(--danger-hover); }

.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-full { width: 100%; justify-content: center; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  background: var(--danger);
  color: white;
  font-size: 0.65rem;
  font-weight: 700;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  color: var(--accent);
  font-weight: 600;
  font-size: 1rem;
}
.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.avatar.large { width: 80px; height: 80px; font-size: 2rem; }

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.form-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: 8px;
  min-height: 20px;
}

.form-success {
  color: var(--success);
  font-size: 0.85rem;
  margin-top: 8px;
}

/* ========== AUTH SCREEN ========== */
#auth-screen {
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 50%, var(--bg-tertiary) 100%);
}

.auth-container {
  width: 100%;
  max-width: 420px;
  padding: 20px;
}

.auth-brand {
  text-align: center;
  margin-bottom: 30px;
}

.auth-brand .logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  background: var(--accent);
  border-radius: 16px;
  margin-bottom: 12px;
}
.auth-brand .logo .material-icons-outlined { font-size: 36px; color: white; }
.auth-brand h1 { font-size: 2rem; font-weight: 700; }
.auth-brand .tagline { color: var(--text-secondary); margin-top: 4px; }

.auth-form { display: none; }
.auth-form.active { display: block; }

.auth-form {
  background: var(--bg-surface);
  padding: 30px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.auth-form h2 {
  margin-bottom: 20px;
  text-align: center;
  font-size: 1.3rem;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 0.95rem;
  transition: border-color var(--transition);
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--accent);
}

.form-group textarea { resize: vertical; min-height: 80px; }
.form-group small { color: var(--text-muted); font-size: 0.8rem; }

.checkbox-label {
  display: flex !important;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.auth-switch {
  text-align: center;
  margin-top: 16px;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

/* ========== SIDEBAR ========== */
.sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  height: 100dvh;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.logo-small {
  display: flex;
  align-items: center;
  gap: 10px;
}
.logo-small .material-icons-outlined {
  color: var(--accent);
  font-size: 28px;
}
.logo-text {
  font-size: 1.1rem;
  font-weight: 700;
}

.sidebar-nav {
  padding: 12px 8px;
  border-bottom: 1px solid var(--border);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
  transition: all var(--transition);
  position: relative;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active { background: var(--accent-light); color: var(--accent); }

.sidebar-section {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  min-height: 0;
}

.sidebar-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 8px 4px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.sidebar-list { display: flex; flex-direction: column; gap: 2px; }

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--transition);
  color: var(--text-secondary);
}
.sidebar-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.sidebar-item.active { background: var(--accent-light); color: var(--accent); }

.sidebar-item .material-icons-outlined { font-size: 20px; }
.sidebar-item .item-name { 
  flex: 1; 
  font-size: 0.9rem; 
  overflow: hidden; 
  text-overflow: ellipsis; 
  white-space: nowrap; 
}

.sidebar-user {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-primary);
  flex-shrink: 0;
  z-index: 10;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.user-details { display: flex; flex-direction: column; }
.user-details .username { font-size: 0.9rem; font-weight: 600; }
.user-status-text { font-size: 0.75rem; color: var(--success); }

.user-actions {
  display: flex;
  gap: 4px;
}

/* ========== MAIN CONTENT ========== */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.mobile-header {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
}

.view-header h2 { font-size: 1.2rem; font-weight: 600; }

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 12px;
}
.search-bar input {
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 0.9rem;
  width: 200px;
  outline: none;
}
.search-bar .material-icons-outlined { color: var(--text-muted); font-size: 20px; }

/* ========== FRIENDS VIEW ========== */
.friends-tabs {
  display: flex;
  gap: 8px;
  padding: 8px 24px;
  border-bottom: 1px solid var(--border);
}

.friends-panel { display: none; }
.friends-panel.active { display: block; }

.friend-section {
  padding: 16px 24px;
  overflow-y: auto;
}

.friend-section h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.friends-grid {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* ========== PROFILE VIEW ========== */
.profile-view { padding: 24px; }
.profile-header { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; }
.profile-names h3 { margin: 0; font-size: 1.3rem; }
.profile-username { color: var(--text-muted); font-size: 0.9rem; }
.profile-status-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-left: 8px; }
.profile-status-dot.online { background: var(--success); }
.profile-status-dot.away { background: #f59e0b; }
.profile-status-dot.busy { background: var(--danger); }
.profile-status-dot.offline { background: var(--text-muted); }
.profile-details { margin-bottom: 20px; }
.profile-bio { color: var(--text-primary); margin-bottom: 8px; white-space: pre-wrap; }
.profile-custom-status { color: var(--text-muted); font-size: 0.9rem; font-style: italic; margin-bottom: 8px; }
.profile-last-seen { color: var(--text-muted); font-size: 0.85rem; }
.profile-actions { display: flex; gap: 8px; }

.friend-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--transition);
}
.friend-card:hover { background: var(--bg-hover); }

.friend-card .friend-info {
  flex: 1;
  min-width: 0;
}
.friend-card .friend-name {
  font-weight: 500;
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.friend-card .friend-status-text {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.friend-card .friend-actions {
  display: flex;
  gap: 4px;
}

.badge-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: var(--radius-full);
  background: var(--bg-tertiary);
}

.form-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}
.status-dot.online { background: var(--success); }
.status-dot.away { background: var(--warning); }
.status-dot.busy { background: var(--danger); }
.status-dot.offline { background: var(--text-muted); }

/* ========== CONVERSATIONS VIEW ========== */
.conversations-list {
  overflow-y: auto;
  flex: 1;
  padding: 8px;
}

.conversation-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--transition);
}
.conversation-item:hover { background: var(--bg-hover); }
.conversation-item.unread { background: var(--accent-light); }

.conversation-item .conv-info {
  flex: 1;
  min-width: 0;
}
.conversation-item .conv-name {
  font-weight: 500;
  font-size: 0.95rem;
}
.conversation-item .conv-preview {
  font-size: 0.8rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 200px;
}
.conversation-item .conv-time {
  font-size: 0.75rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* ========== GROUPS VIEW ========== */
.groups-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  padding: 16px 24px;
  overflow-y: auto;
}

.group-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  cursor: pointer;
  transition: all var(--transition);
}
.group-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.group-card .group-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}
.group-card .group-card-name {
  font-size: 1.1rem;
  font-weight: 600;
}
.group-card .group-card-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 12px;
}
.group-card .group-card-meta {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.group-card .group-card-meta span {
  display: flex;
  align-items: center;
  gap: 4px;
}
.group-card .group-card-meta .material-icons-outlined { font-size: 16px; }

.category-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
}

.tab {
  padding: 6px 16px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.85rem;
  transition: all var(--transition);
}
.tab:hover { border-color: var(--accent); color: var(--accent); }
.tab.active { background: var(--accent); border-color: var(--accent); color: white; }

/* ========== GROUP DETAIL ========== */
.group-detail-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.channels-panel {
  width: 240px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 12px;
  flex-shrink: 0;
}

.channels-header, .members-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 4px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.channels-list, .members-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 16px;
}

.channel-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-secondary);
  transition: all var(--transition);
}
.channel-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.channel-item.active { background: var(--accent-light); color: var(--accent); }
.channel-item .material-icons-outlined { font-size: 18px; }

.member-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: var(--radius);
  font-size: 0.85rem;
}
.member-item .avatar { width: 28px; height: 28px; font-size: 0.7rem; }
.member-item .member-name { flex: 1; }
.member-item .member-role {
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 10px;
  background: var(--bg-hover);
  color: var(--text-muted);
}
.member-item .member-role.owner { background: var(--accent-light); color: var(--accent); }
.member-item .member-role.admin { background: rgba(243, 156, 18, 0.15); color: var(--warning); }

/* ========== CHAT VIEW ========== */
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
}
.chat-header-info h3 { font-size: 1rem; font-weight: 600; }
.chat-status-text { font-size: 0.8rem; color: var(--text-muted); }

.chat-header-actions {
  display: flex;
  gap: 4px;
}

.back-btn { display: none; }

.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.messages-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.message {
  display: flex;
  gap: 12px;
  padding: 6px 8px;
  border-radius: var(--radius);
  transition: background var(--transition);
}
.message:hover { background: var(--bg-hover); }

.message .avatar { width: 36px; height: 36px; margin-top: 2px; }

.message-body { flex: 1; min-width: 0; }

.message-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 2px;
}
.message-author { font-weight: 600; font-size: 0.9rem; color: var(--accent); }
.message-time { font-size: 0.75rem; color: var(--text-muted); }
.message-edited { font-size: 0.7rem; color: var(--text-muted); font-style: italic; }

.message-content {
  font-size: 0.95rem;
  line-height: 1.4;
  word-break: break-word;
  white-space: pre-wrap;
}

.message-content a {
  color: var(--accent);
  text-decoration: underline;
}

.message-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.attachment {
  max-width: 300px;
  border-radius: var(--radius);
  overflow: hidden;
}
.attachment img {
  max-width: 100%;
  max-height: 300px;
  display: block;
  border-radius: var(--radius);
}
.attachment-file {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  text-decoration: none;
  font-size: 0.85rem;
}
.attachment-file:hover { background: var(--bg-hover); text-decoration: none; }
.attachment-file .material-icons-outlined { color: var(--accent); }

.message-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.reaction {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  cursor: pointer;
  font-size: 0.85rem;
  transition: all var(--transition);
}
.reaction:hover { border-color: var(--accent); }
.reaction.active { border-color: var(--accent); background: var(--accent-light); }
.reaction .count { font-size: 0.75rem; color: var(--text-muted); }

.message-system {
  text-align: center;
  padding: 8px;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-style: italic;
}

.typing-indicator {
  padding: 4px 24px;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
}

.message-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
}

.input-wrapper {
  flex: 1;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 14px;
}

.input-wrapper textarea {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 0.95rem;
  resize: none;
  outline: none;
  max-height: 120px;
  line-height: 1.4;
}

.send-btn { color: var(--accent) !important; }
.send-btn:hover { background: var(--accent-light) !important; }

/* ========== MODALS ========== */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.6);
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal.active { display: flex; }

.modal-content {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal-large { max-width: 700px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal-header h2 { font-size: 1.2rem; }

/* ========== SETTINGS ========== */
.settings-layout {
  display: flex;
  gap: 20px;
}

.settings-tabs {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 140px;
}

.settings-tab {
  padding: 8px 14px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
  font-size: 0.9rem;
  transition: all var(--transition);
}
.settings-tab:hover { background: var(--bg-hover); }
.settings-tab.active { background: var(--accent-light); color: var(--accent); }

.settings-content { flex: 1; }
.settings-panel { display: none; }
.settings-panel.active { display: block; }

.avatar-upload {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* ========== NOTIFICATIONS PANEL ========== */
.notifications-panel {
  position: absolute;
  top: 60px;
  right: 16px;
  width: 360px;
  max-height: 500px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 100;
  overflow: hidden;
}

.notif-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.notif-header h3 { font-size: 1rem; }

.notifications-list {
  max-height: 400px;
  overflow-y: auto;
}

.notification-item {
  display: flex;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition);
}
.notification-item:hover { background: var(--bg-hover); }
.notification-item.unread { background: var(--accent-light); }

.notification-item .notif-content { flex: 1; }
.notification-item .notif-title { font-weight: 500; font-size: 0.9rem; }
.notification-item .notif-body { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; }
.notification-item .notif-time { font-size: 0.75rem; color: var(--text-muted); margin-top: 4px; }

/* ========== CALL OVERLAY (PIP) ========== */
.call-overlay {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 1100;
  width: 320px;
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  border: 1px solid var(--border);
  overflow: hidden;
  transition: width 0.3s, height 0.3s;
}

.call-overlay.expanded {
  width: 500px;
}

.call-overlay.minimized .call-overlay-body {
  display: none;
}

.call-overlay.minimized {
  width: 280px;
}

.call-overlay-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--bg-primary);
  cursor: grab;
  user-select: none;
  border-bottom: 1px solid var(--border);
}

.call-overlay-header:active { cursor: grabbing; }

#call-overlay-name {
  font-weight: 600;
  font-size: 0.9rem;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#call-overlay-status {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.call-expand-btn {
  width: 28px !important;
  height: 28px !important;
  min-width: 28px;
}
.call-expand-btn .material-icons-outlined { font-size: 18px; }

.call-overlay .call-info {
  padding: 20px 16px;
  text-align: center;
}
.call-overlay .call-info h2 { margin-top: 12px; font-size: 1.1rem; }
.call-overlay .call-info p { color: var(--text-muted); margin-top: 4px; font-size: 0.85rem; }

.call-overlay .call-controls {
  display: flex;
  justify-content: center;
  gap: 16px;
  padding: 12px 16px 16px;
}

.call-btn {
  width: 48px !important;
  height: 48px !important;
  border-radius: var(--radius-full) !important;
  background: var(--bg-hover) !important;
}
.call-btn .material-icons-outlined { font-size: 24px; }
.call-btn.end-call { background: var(--danger) !important; color: white !important; }
.call-btn.end-call:hover { background: var(--danger-hover) !important; }
.call-btn.accept-call { background: var(--success) !important; color: white !important; }

.call-overlay .video-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 0 8px 8px;
}
.call-overlay .video-container video {
  width: 100%;
  border-radius: var(--radius);
  background: #000;
}

.call-overlay.expanded .video-container {
  grid-template-columns: 1fr;
}
.call-overlay.expanded .video-container video {
  max-height: 300px;
}

/* ========== TOAST ========== */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius);
  color: white;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  animation: slideIn 0.3s ease;
  max-width: 350px;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--accent); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
  /* --- Layout --- */
  .sidebar {
    position: fixed;
    left: -100%;
    z-index: 500;
    width: 100%;
    max-width: 300px;
    height: 100vh;
    height: 100dvh;
    transition: left 0.3s ease;
  }
  .sidebar.open { left: 0; }

  .mobile-header { display: flex; }
  .mobile-only { display: flex; }
  .back-btn { display: flex; }

  /* --- View header & actions --- */
  .view-header {
    padding: 8px 12px;
    flex-wrap: wrap;
    gap: 6px;
  }
  .header-actions { flex-wrap: wrap; gap: 4px; }

  /* --- Search --- */
  .search-bar input { width: 120px; }

  /* --- Message input --- */
  .message-input-area { padding: 8px 10px; gap: 6px; }

  /* --- Groups --- */
  .group-detail-layout { flex-direction: column; }
  .channels-panel {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 200px;
  }
  .groups-grid {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  /* --- Notifications --- */
  .notifications-panel {
    right: 8px;
    width: calc(100% - 16px);
  }

  /* --- Settings --- */
  .settings-layout { flex-direction: column; }
  .settings-tabs {
    flex-direction: row;
    overflow-x: auto;
    min-width: unset;
  }

  /* --- Modals --- */
  .modal { padding: 10px; }
  .modal-content {
    padding: 16px;
    max-height: 88vh;
    max-height: 88dvh;
  }
  .modal-large { max-width: 100%; }

  /* --- Call overlay --- */
  .call-overlay {
    width: calc(100vw - 32px);
    max-width: 320px;
    right: 16px;
  }
  .call-overlay.expanded {
    width: calc(100vw - 32px);
    max-width: 480px;
    right: 50%;
    transform: translateX(50%);
  }
  .call-overlay.minimized {
    width: calc(100vw - 32px);
    max-width: 280px;
  }

  /* --- Admin --- */
  .admin-tabs { flex-wrap: wrap; }
  .admin-tab { padding: 6px 12px; font-size: 0.85rem; }
  .admin-user-card,
  .admin-report-card { flex-wrap: wrap; }
  .admin-user-actions {
    flex-wrap: wrap;
    width: 100%;
    margin-top: 8px;
  }

  /* --- Auth form --- */
  .auth-form { padding: 20px; }
  .auth-container { padding: 12px; }

  /* --- Video --- */
  .video-container { grid-template-columns: 1fr; }
}

@media (min-width: 769px) {
  .mobile-only { display: none; }
}

/* ========== SMALL PHONE ( ≤ 480px) ========== */
@media (max-width: 480px) {
  /* Tighter view header */
  .view-header { padding: 6px 10px; }
  .view-header h2 { font-size: 1rem; }

  /* Search bar: hide on tiny screens to save space */
  .search-bar { display: none; }

  /* Icon buttons: ensure minimum touch target */
  .icon-btn { width: 40px; height: 40px; }

  /* Message input: tighter */
  .message-input-area { padding: 6px 8px; gap: 4px; }
  .input-wrapper { padding: 6px 10px; }
  .input-wrapper textarea { font-size: 0.9rem; }

  /* Modals: full-width feel */
  .modal { padding: 6px; }
  .modal-content {
    padding: 14px;
    border-radius: var(--radius);
  }

  /* Auth form */
  .auth-form { padding: 16px; }
  .auth-form h1 { font-size: 1.4rem; }

  /* Call overlay: full-width minus margin */
  .call-overlay,
  .call-overlay.expanded,
  .call-overlay.minimized {
    width: calc(100vw - 16px);
    max-width: 100%;
    right: 8px;
    bottom: 8px;
    transform: none;
  }

  /* Admin tabs: smaller text */
  .admin-tab { padding: 5px 10px; font-size: 0.8rem; }

  /* Stat cards: stack single column */
  .admin-stats { flex-direction: column; }

  /* Reduce avatar on friend/group cards */
  .avatar { width: 36px; height: 36px; }
}

/* ========== ACCESSIBILITY ========== */
@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

*:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Screen reader only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* Message Action Buttons */
.message-actions {
  display: none;
  gap: 4px;
  margin-left: auto;
}
.message:hover .message-actions { display: flex; }

.msg-action-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 6px;
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--text-muted);
  transition: all var(--transition);
  display: flex;
  align-items: center;
}
.msg-action-btn:hover { background: var(--bg-hover); color: var(--text-primary); border-color: var(--accent); }
.msg-action-btn.delete-btn:hover { color: var(--danger); border-color: var(--danger); }

/* Emoji Picker Popup */
.emoji-picker-popup {
  position: absolute;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  z-index: 1000;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  max-width: 200px;
}
.emoji-pick-btn {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: background var(--transition);
}
.emoji-pick-btn:hover { background: var(--bg-hover); }

/* Admin Panel */
.admin-tabs {
  display: flex;
  gap: 4px;
  padding: 0 16px 12px;
  border-bottom: 1px solid var(--border);
}
.admin-tab {
  padding: 8px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-surface);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.9rem;
  transition: all var(--transition);
}
.admin-tab:hover { background: var(--bg-hover); }
.admin-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.admin-tab-content {
  padding: 16px;
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.admin-list { display: flex; flex-direction: column; gap: 8px; }

.admin-user-card, .admin-report-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.admin-user-card .avatar { width: 40px; height: 40px; }

.admin-user-info { flex: 1; min-width: 0; }
.admin-user-info .name { font-weight: 600; color: var(--text-primary); font-size: 0.95rem; }
.admin-user-info .username { font-size: 0.8rem; color: var(--text-muted); }

.role-badge {
  font-size: 0.75rem;
  padding: 2px 10px;
  border-radius: 10px;
  font-weight: 600;
  text-transform: uppercase;
}
.role-badge.admin { background: var(--accent); color: #fff; }
.role-badge.user { background: var(--bg-hover); color: var(--text-secondary); }

.admin-user-actions select {
  padding: 6px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.85rem;
  cursor: pointer;
}

.admin-report-card {
  flex-direction: column;
  align-items: flex-start;
}
.report-msg-preview {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-primary);
  border-radius: var(--radius);
  margin: 8px 0;
  font-size: 0.9rem;
  color: var(--text-secondary);
  word-break: break-word;
}
.report-info {
  font-size: 0.8rem;
  color: var(--text-muted);
}
.report-reasons {
  margin-top: 4px;
}
.report-reason-item {
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 2px 0;
}
.report-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.report-actions .btn { font-size: 0.8rem; padding: 6px 14px; }
.btn-danger { background: var(--danger); color: #fff; border: none; border-radius: var(--radius); cursor: pointer; }
.btn-danger:hover { opacity: 0.9; }

/* ========== ADMIN STATS ========== */
.admin-stats {
  display: flex;
  gap: 12px;
  padding: 16px 24px;
  flex-wrap: wrap;
}
.stat-card {
  flex: 1;
  min-width: 120px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.stat-value {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--accent);
}
.stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.stat-card.stat-warning .stat-value { color: var(--danger); }

/* Admin user card enhancements */
.admin-user-card.user-banned {
  border-color: var(--danger);
  background: rgba(239, 68, 68, 0.05);
}
.banned-label {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--danger);
  background: rgba(239, 68, 68, 0.15);
  padding: 1px 6px;
  border-radius: 4px;
  margin-left: 6px;
}
.admin-user-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.role-badge.owner { background: #f59e0b; color: #000; }

.btn-sm {
  font-size: 0.8rem;
  padding: 4px 12px;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 500;
}

/* ========== GROUPS TABS ========== */
.groups-tabs {
  display: flex;
  gap: 8px;
  padding: 8px 24px;
  border-bottom: 1px solid var(--border);
}
.groups-panel { display: none; }
.groups-panel.active { display: block; }

/* ========== MESSAGE DELETED ========== */
.message-deleted-text {
  font-style: italic;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ========== INVITE PENDING BADGE ========== */
.invite-pending-badge {
  font-size: 0.75rem;
  font-weight: 600;
  color: #f59e0b;
  background: rgba(245, 158, 11, 0.15);
  padding: 2px 10px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* ========== CUSTOM DIALOG SYSTEM ========== */
.dialog-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  transition: opacity 0.2s ease;
  backdrop-filter: blur(4px);
}
.dialog-overlay.active { opacity: 1; }

.dialog-box {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.4);
  transform: scale(0.95);
  transition: transform 0.2s ease;
}
.dialog-overlay.active .dialog-box { transform: scale(1); }

.dialog-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}
.dialog-message {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 4px;
}
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}
.dialog-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.9rem;
}
.dialog-input:focus { border-color: var(--accent); outline: none; }

/* ========== ADMIN UPLOADS ========== */
.admin-upload-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.admin-upload-card .upload-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  background: var(--accent-light);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  flex-shrink: 0;
}
.admin-upload-card .upload-info { flex: 1; min-width: 0; }
.admin-upload-card .upload-info .name {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.admin-upload-card .upload-info .meta {
  font-size: 0.8rem;
  color: var(--text-muted);
}
.admin-upload-card .upload-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* ========== ADMIN ANNOUNCEMENTS ========== */
.admin-announcement-card {
  padding: 14px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.admin-announcement-card .ann-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.admin-announcement-card .ann-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-primary);
  flex: 1;
}
.admin-announcement-card .ann-content {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
  white-space: pre-wrap;
  word-break: break-word;
}
.admin-announcement-card .ann-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.priority-badge {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
  text-transform: uppercase;
}
.priority-badge.normal { background: var(--bg-hover); color: var(--text-secondary); }
.priority-badge.important { background: rgba(245, 158, 11, 0.15); color: #f59e0b; }
.priority-badge.urgent { background: rgba(239, 68, 68, 0.15); color: var(--danger); }

/* ========== ADMIN IP GROUPS ========== */
.ip-group-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.ip-group-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--bg-primary);
  cursor: pointer;
  transition: background var(--transition);
}
.ip-group-header:hover { background: var(--bg-hover); }
.ip-group-header .ip-label {
  font-weight: 600;
  font-size: 0.9rem;
  flex: 1;
  font-family: monospace;
  color: var(--text-primary);
}
.ip-group-header .ip-count {
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--bg-hover);
  padding: 2px 10px;
  border-radius: 10px;
}
.ip-group-users {
  padding: 4px 16px 8px;
}
.ip-group-users .ip-user-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  font-size: 0.85rem;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
}
.ip-group-users .ip-user-item:last-child { border-bottom: none; }
.ip-group-users .ip-user-item .avatar { width: 24px; height: 24px; font-size: 0.6rem; }
.ip-group-users .ip-user-item .status-dot { width: 8px; height: 8px; }

/* ========== GROUP SETTINGS ========== */
.group-settings-form .form-group { margin-bottom: 12px; }
.group-settings-form hr { border: none; border-top: 1px solid var(--border); }

/* ========== MESSAGE SEARCH ========== */
.msg-search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}
.msg-search-bar input {
  flex: 1;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.9rem;
}
.msg-search-bar input:focus { border-color: var(--accent); outline: none; }

.msg-search-results {
  max-height: 250px;
  overflow-y: auto;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
}
.msg-search-item {
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  cursor: default;
}
.msg-search-item:hover { background: var(--bg-hover); }
.msg-search-item:last-child { border-bottom: none; }
