/* ==========================================================================
   ChitterChatter — Stylesheet (Light, Dark & Device Theme Support)
   ========================================================================== */

:root,
[data-theme="light"] {
  --bg-primary: #f4f6fb;
  --bg-surface: #ffffff;
  --bg-elevated: #f8fafd;
  --bg-hover: #eef2f9;
  --bg-active: #e3ebfa;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  --border-strong: #cbd5e1;

  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: rgba(79, 70, 229, 0.12);
  --accent-text: #ffffff;

  --official-gradient: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  --admin-gradient: linear-gradient(135deg, #f59e0b 0%, #ea580c 100%);
  --admin-bg: #fffbeb;
  --admin-border: #fde68a;
  --admin-text: #92400e;

  --msg-own-bg: #4f46e5;
  --msg-own-text: #ffffff;
  --msg-other-bg: #f1f5f9;
  --msg-other-text: #0f172a;
  --msg-official-bg: linear-gradient(135deg, rgba(79, 70, 229, 0.1), rgba(124, 58, 237, 0.12));
  --msg-official-border: #c7d2fe;

  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.1);
  --success: #10b981;
  --success-soft: rgba(16, 185, 129, 0.12);

  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.14);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
}

[data-theme="dark"] {
  --bg-primary: #0b0f19;
  --bg-surface: #131b2e;
  --bg-elevated: #1a243b;
  --bg-hover: #212d48;
  --bg-active: #283759;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border-color: #1e293b;
  --border-strong: #334155;

  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-soft: rgba(99, 102, 241, 0.18);
  --accent-text: #ffffff;

  --official-gradient: linear-gradient(135deg, #6366f1 0%, #9333ea 100%);
  --admin-gradient: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  --admin-bg: rgba(245, 158, 11, 0.1);
  --admin-border: rgba(245, 158, 11, 0.35);
  --admin-text: #fbbf24;

  --msg-own-bg: #6366f1;
  --msg-own-text: #ffffff;
  --msg-other-bg: #1e293b;
  --msg-other-text: #f1f5f9;
  --msg-official-bg: linear-gradient(135deg, rgba(99, 102, 241, 0.16), rgba(147, 51, 234, 0.16));
  --msg-official-border: rgba(129, 140, 248, 0.35);

  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.16);
  --success: #34d399;
  --success-soft: rgba(52, 211, 153, 0.16);

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 14px 36px rgba(0, 0, 0, 0.6);
}

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

html,
body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  transition: background-color 0.2s ease, color 0.2s ease;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
}

.hidden {
  display: none !important;
}

button,
input,
textarea {
  font-family: inherit;
}

/* ==========================================================================
   TOP NAVIGATION BAR
   ========================================================================== */
.topbar {
  height: 64px;
  min-height: 64px;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  box-shadow: var(--shadow-sm);
  z-index: 40;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  user-select: none;
}

.brand-logo {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--official-gradient);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 10px rgba(99, 102, 241, 0.35);
}

.brand-name {
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: var(--official-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.connection-badge,
#connection-badge {
  display: none !important;
}

/* Top-Left Tabs: Chat & Contacts */
.nav-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-elevated);
  padding: 4px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.nav-tab {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 15px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.nav-tab:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.nav-tab.active {
  background: var(--accent);
  color: var(--accent-text);
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.3);
}

.tab-badge {
  background: #ef4444;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
}

/* Top-Right Controls */
.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

/* Admin Mode Toggle Switch */
.admin-toggle-wrapper {
  display: flex;
  align-items: center;
  background: var(--admin-bg);
  border: 1px solid var(--admin-border);
  padding: 5px 12px;
  border-radius: 999px;
}

.switch-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--admin-text);
}

.toggle-switch {
  position: relative;
  width: 38px;
  height: 20px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: rgba(146, 64, 14, 0.3);
  border-radius: 999px;
  transition: 0.2s;
}

.toggle-slider::before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background-color: #ffffff;
  border-radius: 50%;
  transition: 0.2s;
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--admin-gradient);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(18px);
}

/* 3-Way Theme Toggle Switch (Light / Device / Dark) */
.theme-switcher {
  display: inline-flex;
  align-items: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}

.theme-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.theme-btn:hover {
  color: var(--text-primary);
}

.theme-btn.active {
  background: var(--bg-surface);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}

/* Profile Pic & Dropdown Menu */
.profile-menu-container {
  position: relative;
}

.profile-pic-btn {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  padding: 0;
  background: var(--bg-elevated);
  cursor: pointer;
  overflow: visible;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.profile-pic-btn:hover {
  transform: scale(1.04);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.avatar-img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

.online-dot {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--success);
  border: 2px solid var(--bg-surface);
}

.profile-dropdown {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: 260px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 8px;
  z-index: 100;
}

.dropdown-user-info {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
}

.dropdown-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border-strong);
}

.dropdown-user-details {
  overflow: hidden;
}

.dropdown-nickname {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dropdown-account-name {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dropdown-email {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dropdown-divider {
  height: 1px;
  background: var(--border-color);
  margin: 6px 0;
}

.dropdown-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-primary);
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s ease;
}

.dropdown-item:hover {
  background: var(--bg-hover);
}

.dropdown-item-danger {
  color: var(--danger);
}

.dropdown-item-danger:hover {
  background: var(--danger-soft);
}

/* ==========================================================================
   AUTHENTICATION VIEW
   ========================================================================== */
.auth-view {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
}

.auth-card {
  width: 100%;
  max-width: 430px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow-lg);
}

.auth-header {
  text-align: center;
  margin-bottom: 22px;
}

.auth-logo-circle {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: var(--official-gradient);
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.35);
}

.auth-header h1 {
  font-size: 1.45rem;
  font-weight: 800;
  margin-bottom: 6px;
}

.auth-subtitle {
  font-size: 0.88rem;
  color: var(--text-secondary);
}

.banned-screen-card {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.banned-icon-circle {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: var(--danger-soft);
  border: 1px solid rgba(239, 68, 68, 0.35);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
}

.banned-screen-title {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--text-primary);
  margin: 0;
}

.banned-relogin-btn,
.banned-switch-btn {
  margin-top: 4px;
}

.auth-mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--bg-elevated);
  padding: 4px;
  border-radius: var(--radius-sm);
  margin-bottom: 18px;
  border: 1px solid var(--border-color);
}

.auth-mode-tab {
  padding: 8px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
}

.auth-mode-tab.active {
  background: var(--bg-surface);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

.btn-google {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.btn-google:hover {
  background: var(--bg-hover);
}

.auth-divider {
  display: flex;
  align-items: center;
  margin: 18px 0;
  color: var(--text-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border-color);
}

.auth-divider span {
  padding: 0 10px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.form-group input,
.form-group textarea {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 0.92rem;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-group input:focus,
.form-group textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-secondary:hover {
  background: var(--bg-hover);
}

.btn-full {
  width: 100%;
}

.auth-footer {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

.quick-demo-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.quick-demo-label {
  font-size: 0.76rem;
  color: var(--text-muted);
  font-weight: 600;
}

.btn-chip {
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-chip:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.btn-link {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.78rem;
  cursor: pointer;
  text-decoration: underline;
}

.btn-link:hover {
  color: var(--text-primary);
}

.alert-box {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
  margin-bottom: 14px;
}

.alert-error {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

/* ==========================================================================
   MAIN APP LAYOUT & ADMIN CONSOLE
   ========================================================================== */
.app-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Admin Mode Panel */
.admin-console-panel {
  background: var(--admin-bg);
  border-bottom: 2px solid var(--admin-border);
  padding: 12px 20px;
  z-index: 25;
}

.admin-console-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.admin-console-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.admin-title-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.admin-crown {
  font-size: 1.35rem;
}

.admin-title-group h3 {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--admin-text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.admin-title-group p {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.admin-send-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.admin-target-selector {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.radio-card {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.admin-specific-users-wrap {
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px;
}

.admin-users-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.admin-select-actions {
  display: flex;
  gap: 6px;
}

.btn-mini {
  padding: 2px 8px;
  font-size: 0.72rem;
  border-radius: 4px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-primary);
  cursor: pointer;
}

.admin-recipients-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 95px;
  overflow-y: auto;
}

.recipient-checkbox-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  font-size: 0.8rem;
  cursor: pointer;
  user-select: none;
}

.recipient-checkbox-pill input:checked + span {
  font-weight: 700;
  color: var(--accent);
}

.admin-message-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.admin-message-row input,
.admin-message-row textarea {
  flex: 1;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--admin-border);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem;
  line-height: 1.4;
  resize: none;
  max-height: 120px;
  overflow-y: auto;
  outline: none;
}

.btn-admin-send {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--admin-gradient);
  color: #ffffff;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 2px 10px rgba(245, 158, 11, 0.35);
}

.btn-admin-send:hover {
  filter: brightness(1.06);
}

/* ==========================================================================
   TAB 1: CHAT WORKSPACE (Main Chat Left + Sidebar Right)
   ========================================================================== */
.tab-content {
  flex: 1;
  display: flex;
  overflow: hidden;
}

.chat-workspace {
  flex: 1;
  display: flex;
  flex-direction: row;
  overflow: hidden;
}

/* Left/Center Main Conversation Pane */
.chat-main-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  overflow: hidden;
}

.chat-pane-header {
  height: 68px;
  min-height: 68px;
  padding: 0 24px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Admin Mode Second Top Bar in ChitterChatter Official Chat */
.admin-official-users-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 18px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-color);
  min-height: 48px;
}

.admin-official-bar-label {
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
  flex-shrink: 0;
}

.admin-official-users-scroll {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: thin;
  padding-bottom: 2px;
  flex: 1;
  min-width: 0;
}

.admin-official-user-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

.admin-official-user-pill:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
}

.admin-official-user-pill.active {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.35);
}

.admin-official-user-avatar {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.chat-partner-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--official-gradient);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
  flex-shrink: 0;
  overflow: hidden;
}

.chat-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.chat-partner-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-partner-title-row h2 {
  font-size: 1.05rem;
  font-weight: 700;
}

.official-badge {
  font-size: 0.65rem;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--official-gradient);
  color: #ffffff;
  letter-spacing: 0.04em;
}

.chat-partner-subtitle {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.chat-header-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.e2ee-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--success);
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.35);
  padding: 5px 11px;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease;
}

.e2ee-status-pill:hover {
  background: rgba(16, 185, 129, 0.2);
}

.e2ee-msg-lock {
  font-size: 0.68rem;
  opacity: 0.85;
  cursor: help;
}

.your-nickname-pill {
  font-size: 0.8rem;
  color: var(--text-secondary);
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  padding: 5px 12px;
  border-radius: 999px;
}

.your-nickname-pill strong {
  color: var(--accent);
}

/* Messages Feed */
.messages-container {
  flex: 1;
  padding: 20px 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  max-width: 78%;
}

.message-row.own {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message-row.other {
  align-self: flex-start;
}

.message-mini-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
  overflow: hidden;
  border: 1px solid var(--border-color);
}

.message-mini-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.message-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  position: relative;
  box-shadow: var(--shadow-sm);
  line-height: 1.45;
  font-size: 0.92rem;
  word-break: break-word;
}

.message-text {
  white-space: pre-wrap;
  word-break: break-word;
}

.message-media-wrap {
  margin-top: 6px;
  margin-bottom: 4px;
  border-radius: 10px;
  overflow: hidden;
  max-width: 310px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(0, 0, 0, 0.08);
}

.message-media-img {
  display: block;
  width: 100%;
  max-height: 280px;
  object-fit: contain;
  cursor: pointer;
  transition: transform 0.15s ease;
}

.message-media-img:hover {
  transform: scale(1.015);
}

.message-media-video {
  display: block;
  width: 100%;
  max-height: 280px;
  border-radius: 10px;
  background: #000000;
  outline: none;
}

.message-row.own .message-bubble {
  background: var(--msg-own-bg);
  color: var(--msg-own-text);
  border-bottom-right-radius: 4px;
}

.message-row.other .message-bubble {
  background: var(--msg-other-bg);
  color: var(--msg-other-text);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border-color);
}

.message-row.official-msg .message-bubble {
  background: var(--msg-official-bg);
  border: 1px solid var(--msg-official-border);
  color: var(--text-primary);
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  font-size: 0.74rem;
}

.message-sender-name {
  font-weight: 700;
}

.message-row.own .message-meta {
  justify-content: flex-end;
  color: rgba(255, 255, 255, 0.85);
}

.message-row.other .message-sender-name {
  color: var(--accent);
}

.message-time {
  opacity: 0.75;
  font-size: 0.7rem;
}

.message-target-tag {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--official-gradient);
  color: #fff;
}

/* Quoted Reply Block inside Message Bubble */
.message-reply-quote {
  padding: 6px 10px;
  margin-bottom: 6px;
  border-radius: 8px;
  border-left: 3px solid var(--accent);
  background: rgba(0, 0, 0, 0.14);
  font-size: 0.78rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.message-row.own .message-reply-quote {
  border-left-color: rgba(255, 255, 255, 0.85);
  background: rgba(255, 255, 255, 0.16);
}

.message-reply-sender {
  font-weight: 700;
  font-size: 0.74rem;
}

.message-reply-snippet {
  opacity: 0.9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 320px;
}

/* Reply Preview Banner above Input Bar */
.reply-preview-bar {
  padding: 8px 24px;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.reply-preview-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  border-left: 3px solid var(--accent);
  padding-left: 10px;
}

.reply-preview-label {
  font-size: 0.76rem;
  color: var(--text-secondary);
}

.reply-preview-label strong {
  color: var(--accent);
}

.reply-preview-text {
  font-size: 0.82rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-cancel-reply {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.btn-cancel-reply:hover {
  color: var(--danger);
  border-color: var(--danger);
}

/* Media Attachment Preview Bar above Input */
.media-preview-bar {
  padding: 10px 24px;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.media-preview-content {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

#media-preview-img,
#media-preview-video {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
}

.media-preview-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.media-type-pill {
  align-self: flex-start;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.media-preview-filename {
  font-size: 0.82rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 260px;
}

/* GIF Picker Popover */
.gif-picker-popover {
  padding: 12px 20px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-strong);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 290px;
}

.gif-picker-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.gif-search-input {
  flex: 1;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 0.85rem;
  outline: none;
}

.gif-search-input:focus {
  border-color: var(--accent);
}

.gif-picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(115px, 1fr));
  gap: 8px;
  overflow-y: auto;
  max-height: 215px;
  padding-right: 4px;
}

.gif-picker-item {
  position: relative;
  height: 92px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease;
}

.gif-picker-item:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
}

.gif-picker-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.gif-picker-item-label {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 2px 6px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.75));
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-media-buttons {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.btn-media-action {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.btn-media-action:hover {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

.btn-gif-badge {
  width: auto;
  padding: 0 11px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

/* Chat Input Bar */
.chat-input-bar {
  padding: 14px 24px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: flex-end;
  gap: 12px;
}

.chat-input-bar input,
.chat-input-bar textarea {
  flex: 1;
  padding: 11px 16px;
  border-radius: 20px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.93rem;
  line-height: 1.4;
  resize: none;
  max-height: 130px;
  overflow-y: auto;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.chat-input-bar input:focus,
.chat-input-bar textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.btn-send {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 20px;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  color: #ffffff;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.btn-send:hover {
  background: var(--accent-hover);
}

/* ==========================================================================
   LEFT SIDEBAR: ALL YOUR CHATS (Inside Chat Tab)
   ========================================================================== */
.chat-left-sidebar {
  width: 340px;
  min-width: 300px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  height: 68px;
  min-height: 68px;
  padding: 0 18px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-header h3 {
  font-size: 1rem;
  font-weight: 700;
}

.sidebar-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-group-new {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 32px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.btn-group-new:hover {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

.btn-group-members {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 0.76rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn-group-members:hover {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

.group-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.64rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.contacts-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.group-members-checklist {
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.group-member-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  cursor: pointer;
  user-select: none;
  transition: border-color 0.12s ease, background 0.12s ease;
}

.group-member-option:hover {
  border-color: var(--accent);
}

.group-member-option-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.group-member-option-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
}

.group-member-option-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.group-member-option-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.group-member-option-name {
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.group-member-option-sub {
  font-size: 0.74rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-icon-small {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.btn-icon-small:hover {
  background: var(--bg-hover);
  color: var(--accent);
}

.mobile-sidebar-toggle-btn,
.mobile-sidebar-backdrop {
  display: none;
}

.sidebar-search {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-color);
}

.sidebar-search input {
  width: 100%;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 0.85rem;
  outline: none;
}

.sidebar-search input:focus {
  border-color: var(--accent);
}

.chats-sidebar-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 0.15s ease;
  border: 1px solid transparent;
}

.chat-list-item:hover {
  background: var(--bg-hover);
}

.chat-list-item.active {
  background: var(--bg-active);
  border-color: var(--accent-soft);
}

.chat-list-item.official-chat-item {
  background: linear-gradient(135deg, rgba(79, 70, 229, 0.08), rgba(124, 58, 237, 0.08));
  border: 1px solid rgba(99, 102, 241, 0.25);
}

.chat-list-item.official-chat-item.active {
  background: linear-gradient(135deg, rgba(79, 70, 229, 0.2), rgba(124, 58, 237, 0.2));
  border-color: var(--accent);
}

.chat-item-body {
  flex: 1;
  min-width: 0;
}

.chat-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 3px;
}

.chat-item-name {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-item-time {
  font-size: 0.72rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.chat-item-preview {
  font-size: 0.8rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ==========================================================================
   TAB 2: CONTACTS WORKSPACE
   ========================================================================== */
.contacts-workspace {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.contacts-header-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 20px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  box-shadow: var(--shadow-sm);
}

.contacts-header-card h2 {
  font-size: 1.25rem;
  font-weight: 800;
  margin-bottom: 4px;
}

.contacts-header-card p {
  font-size: 0.88rem;
  color: var(--text-secondary);
}

.contacts-search-input {
  min-width: 260px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 0.88rem;
  outline: none;
}

.add-contact-bar {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  box-shadow: var(--shadow-sm);
}

.add-contact-form {
  display: flex;
  gap: 12px;
}

.add-contact-form input {
  flex: 1;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 0.9rem;
  outline: none;
}

.contacts-sections-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.contacts-section-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-color);
}

.section-title-row h3 {
  font-size: 1rem;
  font-weight: 700;
}

.count-pill {
  font-size: 0.76rem;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
}

.contacts-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.contact-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
}

.contact-card-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.contact-details {
  min-width: 0;
}

.contact-nickname {
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-email {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-chat-now {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--accent);
  color: #ffffff;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-chat-now:hover {
  background: var(--accent-hover);
}

.btn-contact-toggle {
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-contact-toggle:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.admin-contacts-card {
  border-color: var(--admin-border);
  background: linear-gradient(180deg, var(--admin-bg), var(--bg-surface));
}

.admin-section-title-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.contact-nickname-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.banned-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.35);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.contact-card.is-banned {
  opacity: 0.78;
  border-color: rgba(239, 68, 68, 0.35);
}

.btn-email-user {
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn-email-user:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
  color: var(--accent);
}

.btn-ban-user {
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(239, 68, 68, 0.4);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.btn-ban-user:hover {
  background: var(--danger);
  color: #ffffff;
}

.btn-unban-user {
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(16, 185, 129, 0.45);
  background: var(--success-soft);
  color: var(--success);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.btn-unban-user:hover {
  background: var(--success);
  color: #ffffff;
}

.modal-form textarea {
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem;
  resize: vertical;
  outline: none;
}

.modal-form textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.empty-state {
  text-align: center;
  padding: 28px 16px;
  color: var(--text-muted);
  font-size: 0.88rem;
}

/* ==========================================================================
   MODALS & TOASTS
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 200;
}

.modal-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-lg);
}

.modal-card-wide {
  max-width: 540px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.modal-header h3 {
  font-size: 1.15rem;
  font-weight: 800;
}

.btn-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.modal-desc {
  font-size: 0.88rem;
  color: var(--text-secondary);
  margin-bottom: 18px;
  line-height: 1.45;
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.toast-container {
  position: fixed;
  bottom: 20px;
  left: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 300;
}

.toast {
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--text-primary);
  border-left: 4px solid var(--accent);
  box-shadow: var(--shadow-lg);
  font-size: 0.86rem;
  font-weight: 600;
  animation: slideIn 0.2s ease;
}

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

.pin-badge {
  font-size: 0.72rem;
  color: var(--accent);
  flex-shrink: 0;
}

/* Right-Click Context Menu */
.chat-context-menu {
  position: fixed;
  min-width: 150px;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  padding: 5px;
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ctx-menu-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-primary);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s ease;
}

.ctx-menu-item:hover {
  background: var(--bg-hover);
}

.ctx-menu-item-danger {
  color: var(--danger);
}

.ctx-menu-item-danger:hover {
  background: var(--danger-soft);
}

/* ==========================================================================
   SETTINGS & CHAT CUSTOMIZATION MODALS
   ========================================================================== */
.settings-avatar-editor {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 14px;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
}

.settings-avatar-preview-wrap {
  width: 78px;
  height: 78px;
  border-radius: 50%;
  overflow: hidden;
  border: 3px solid var(--accent);
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
  background: var(--bg-surface);
}

.settings-avatar-preview-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.settings-avatar-controls {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.settings-btn-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.settings-color-swatches-label {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.avatar-color-swatches {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.color-swatch-btn {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.7);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform 0.12s ease;
}

.color-swatch-btn:hover {
  transform: scale(1.18);
}

.customize-url-input {
  width: 100%;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 0.82rem;
  outline: none;
}

.customize-url-input:focus {
  border-color: var(--accent);
}

.chat-bg-presets-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 8px;
}

.chat-bg-preset-card {
  height: 54px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border-color);
  cursor: pointer;
  display: flex;
  align-items: flex-end;
  padding: 5px 8px;
  position: relative;
  overflow: hidden;
  transition: transform 0.12s ease, border-color 0.12s ease;
}

.chat-bg-preset-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
}

.chat-bg-preset-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.chat-bg-preset-card span {
  font-size: 0.7rem;
  font-weight: 700;
  color: #ffffff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85);
}

.customize-bg-extra-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.custom-color-picker-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.custom-color-picker-label input[type="color"] {
  width: 24px;
  height: 24px;
  border: none;
  padding: 0;
  background: transparent;
  cursor: pointer;
}

.customize-chat-bg-preview {
  margin-top: 8px;
  height: 64px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  background-size: cover;
  background-position: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: #ffffff;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.85);
}

/* ============================================================================
   MOBILE PHONE MODE (auto-detected phone device or <= 860px viewport)
   ============================================================================ */
html.is-mobile-phone .topbar {
  padding: 0 10px;
  gap: 8px;
}

html.is-mobile-phone .topbar-left {
  gap: 8px;
  min-width: 0;
}

html.is-mobile-phone .topbar-right {
  gap: 8px;
  flex-shrink: 0;
}

html.is-mobile-phone .brand-name,
html.is-mobile-phone .your-nickname-pill {
  display: none !important;
}

html.is-mobile-phone .nav-tab {
  padding: 7px 9px;
  min-width: 34px;
  justify-content: center;
}

html.is-mobile-phone .nav-tab .nav-tab-label,
html.is-mobile-phone #tab-btn-chat span:not(.tab-badge),
html.is-mobile-phone #tab-btn-contacts span:not(.tab-badge) {
  display: none !important;
}

html.is-mobile-phone .theme-switcher {
  padding: 2px;
  gap: 2px;
}

html.is-mobile-phone .theme-btn {
  padding: 6px 8px;
  min-width: 32px;
  justify-content: center;
}

html.is-mobile-phone .admin-toggle-wrapper {
  padding: 4px 8px;
}

html.is-mobile-phone .theme-btn span,
html.is-mobile-phone .admin-label-text,
html.is-mobile-phone #btn-new-group-from-sidebar span,
html.is-mobile-phone #btn-manage-group-members .btn-label-text,
html.is-mobile-phone #e2ee-status-pill span,
html.is-mobile-phone #chat-send-btn span,
html.is-mobile-phone #btn-new-group-from-contacts .btn-label-text {
  display: none !important;
}

html.is-mobile-phone #btn-new-group-from-sidebar,
html.is-mobile-phone #btn-manage-group-members,
html.is-mobile-phone #e2ee-status-pill,
html.is-mobile-phone #chat-send-btn,
html.is-mobile-phone #btn-new-group-from-contacts {
  padding: 7px 9px;
  gap: 4px;
  min-width: 36px;
  justify-content: center;
}

html.is-mobile-phone .mobile-sidebar-toggle-btn {
  display: inline-flex;
  flex-shrink: 0;
}

html.is-mobile-phone .chat-workspace {
  position: relative;
  overflow: hidden;
  flex-direction: row;
}

html.is-mobile-phone .chat-left-sidebar {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(300px, 84vw);
  height: 100%;
  min-width: 0;
  max-width: 100%;
  z-index: 40;
  transform: translateX(-105%);
  visibility: hidden;
  transition: transform 0.22s ease, box-shadow 0.22s ease, visibility 0.22s ease;
  box-shadow: none;
  pointer-events: none;
  border-right: 1px solid var(--border-color);
  border-bottom: none;
}

html.is-mobile-phone .chat-workspace:not(.mobile-sidebar-open) .chat-left-sidebar {
  transform: translateX(-105%) !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

html.is-mobile-phone .chat-workspace.mobile-sidebar-open .chat-left-sidebar {
  transform: translateX(0) !important;
  visibility: visible !important;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  pointer-events: auto !important;
}

html.is-mobile-phone .chat-workspace.mobile-sidebar-open .mobile-sidebar-backdrop:not(.hidden) {
  display: block;
  position: absolute;
  inset: 0;
  z-index: 30;
  background: rgba(0, 0, 0, 0.45);
}

html.is-mobile-phone .chat-pane-header {
  padding: 0 12px;
  gap: 8px;
}

html.is-mobile-phone .chat-partner-info {
  min-width: 0;
  gap: 10px;
}

html.is-mobile-phone .chat-partner-info > div:last-child {
  min-width: 0;
}

html.is-mobile-phone .chat-partner-subtitle {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

html.is-mobile-phone .chat-header-meta {
  gap: 6px;
  flex-shrink: 0;
}

html.is-mobile-phone .messages-container {
  padding: 14px 12px;
}

html.is-mobile-phone .chat-input-bar {
  padding: 10px 10px;
  gap: 8px;
}

html.is-mobile-phone .contacts-workspace {
  padding: 14px;
}

html.is-mobile-phone .contacts-search-input {
  min-width: 0;
  flex: 1;
}

/* Responsive adjustments & <= 860px viewport mobile layout */
@media (max-width: 860px) {
  .contacts-sections-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    padding: 0 10px;
    gap: 8px;
  }

  .topbar-left {
    gap: 8px;
    min-width: 0;
  }

  .topbar-right {
    gap: 8px;
    flex-shrink: 0;
  }

  .brand-name,
  .your-nickname-pill {
    display: none !important;
  }

  .nav-tab {
    padding: 7px 9px;
    min-width: 34px;
    justify-content: center;
  }

  .nav-tab .nav-tab-label,
  #tab-btn-chat span:not(.tab-badge),
  #tab-btn-contacts span:not(.tab-badge) {
    display: none !important;
  }

  .theme-switcher {
    padding: 2px;
    gap: 2px;
  }

  .theme-btn {
    padding: 6px 8px;
    min-width: 32px;
    justify-content: center;
  }

  .admin-toggle-wrapper {
    padding: 4px 8px;
  }

  .theme-btn span,
  .admin-label-text,
  #btn-new-group-from-sidebar span,
  #btn-manage-group-members .btn-label-text,
  #e2ee-status-pill span,
  #chat-send-btn span,
  #btn-new-group-from-contacts .btn-label-text {
    display: none !important;
  }

  #btn-new-group-from-sidebar,
  #btn-manage-group-members,
  #e2ee-status-pill,
  #chat-send-btn,
  #btn-new-group-from-contacts {
    padding: 7px 9px;
    gap: 4px;
    min-width: 36px;
    justify-content: center;
  }

  .mobile-sidebar-toggle-btn {
    display: inline-flex;
    flex-shrink: 0;
  }

  .chat-workspace {
    position: relative;
    overflow: hidden;
    flex-direction: row;
  }

  .chat-left-sidebar {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(300px, 84vw);
    height: 100%;
    min-width: 0;
    max-width: 100%;
    z-index: 40;
    transform: translateX(-105%);
    visibility: hidden;
    transition: transform 0.22s ease, box-shadow 0.22s ease, visibility 0.22s ease;
    box-shadow: none;
    pointer-events: none;
    border-right: 1px solid var(--border-color);
    border-bottom: none;
  }

  .chat-workspace:not(.mobile-sidebar-open) .chat-left-sidebar {
    transform: translateX(-105%) !important;
    visibility: hidden !important;
    pointer-events: none !important;
  }

  .chat-workspace.mobile-sidebar-open .chat-left-sidebar {
    transform: translateX(0) !important;
    visibility: visible !important;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
    pointer-events: auto !important;
  }

  .chat-workspace.mobile-sidebar-open .mobile-sidebar-backdrop:not(.hidden) {
    display: block;
    position: absolute;
    inset: 0;
    z-index: 30;
    background: rgba(0, 0, 0, 0.45);
  }

  .chat-pane-header {
    padding: 0 12px;
    gap: 8px;
  }

  .chat-partner-info {
    min-width: 0;
    gap: 10px;
  }

  .chat-partner-info > div:last-child {
    min-width: 0;
  }

  .chat-partner-subtitle {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .chat-header-meta {
    gap: 6px;
    flex-shrink: 0;
  }

  .messages-container {
    padding: 14px 12px;
  }

  .chat-input-bar {
    padding: 10px 10px;
    gap: 8px;
  }

  .contacts-workspace {
    padding: 14px;
  }

  .contacts-search-input {
    min-width: 0;
    flex: 1;
  }
}

/* Group manager toggle in member checklist */
.group-manager-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
  margin-right: 10px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  white-space: nowrap;
}
.group-manager-toggle input[type='checkbox'] {
  width: 14px;
  height: 14px;
}
.group-member-option input[type='checkbox']:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
