:root {
  --bg-primary: #0a0e17;
  --bg-secondary: #111827;
  --bg-tertiary: #1f2937;
  --bg-card: rgba(17, 24, 39, 0.75);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-active: rgba(6, 182, 212, 0.4);
  --text-main: #f9fafb;
  --text-muted: #9ca3af;
  --accent-cyan: #06b6d4;
  --accent-cyan-hover: #0891b2;
  --accent-emerald: #10b981;
  --bubble-outgoing: #0e7490;
  --bubble-incoming: #1f2937;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

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

/* Global Custom Cyberpunk Scrollbars (Firefox & WebKit) */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(6, 182, 212, 0.4) rgba(0, 0, 0, 0.25);
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.25);
}
::-webkit-scrollbar-thumb {
  background: rgba(6, 182, 212, 0.35);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--accent-cyan);
}

html, body {
  background-color: var(--bg-primary);
  color: var(--text-main);
  font-family: var(--font-sans);
  height: 100%;
  height: 100dvh;
  margin: 0;
  padding: 0;
  width: 100%;
  -webkit-text-size-adjust: 100%;
}

/* Fixed viewport lock applied only to sovereign chat client, never admin console */
html:not(.admin-page), body:not(.admin-body) {
  overflow: hidden;
  position: fixed;
}

/* Glassmorphism helpers */
.glass {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
}

/* Container */
#app-container {
  display: flex;
  width: 100%;
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  position: relative;
  overflow: hidden;
}

/* Sidebar Backdrop for Mobile Drawer */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 990;
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
}
.sidebar-backdrop.active {
  display: block;
  opacity: 1;
  pointer-events: auto;
}

/* Auth Modal */
#auth-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.auth-card {
  width: 440px;
  padding: 32px;
  border-radius: 16px;
  background: #111827;
  border: 1px solid var(--border-active);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6), 0 0 30px rgba(6, 182, 212, 0.15);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.auth-logo {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: linear-gradient(135deg, #06b6d4, #3b82f6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}

.pqc-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: rgba(16, 185, 129, 0.12);
  color: var(--accent-emerald);
  border: 1px solid rgba(16, 185, 129, 0.3);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-group input {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: #fff;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus {
  border-color: var(--accent-cyan);
}

.btn-primary {
  width: 100%;
  padding: 12px;
  background: linear-gradient(135deg, var(--accent-cyan), #0284c7);
  border: none;
  border-radius: 8px;
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: opacity 0.2s;
}

.btn-primary:hover {
  opacity: 0.95;
}

.auth-switch {
  margin-top: 16px;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
}

.auth-switch a {
  color: var(--accent-cyan);
  text-decoration: none;
  font-weight: 600;
  cursor: pointer;
}

/* Sidebar */
#sidebar {
  width: 360px;
  min-width: 300px;
  max-width: 420px;
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  flex-shrink: 0;
  z-index: 5;
  transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.user-profile {
  display: flex;
  align-items: center;
  gap: 12px;
}

.avatar-wrap {
  position: relative;
  width: 42px;
  height: 42px;
  flex-shrink: 0;
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0284c7, #06b6d4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  color: #fff;
  user-select: none;
}

.status-indicator {
  position: absolute;
  bottom: 0px;
  right: 0px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--bg-secondary);
  background: #64748b;
  transition: all 0.2s ease;
}

.status-indicator.online {
  background: var(--accent-emerald);
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.7);
}

.status-indicator.offline {
  background: #475569;
}

.sidebar-search {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  gap: 8px;
  align-items: center;
}

.sidebar-search input {
  flex: 1;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: #fff;
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
}

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

.btn-icon {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 16px;
  transition: all 0.2s;
  flex-shrink: 0;
}

.btn-icon:hover {
  color: #fff;
  border-color: var(--accent-cyan);
  background: rgba(6, 182, 212, 0.12);
}

.btn-icon.spinning span {
  display: inline-block;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  100% { transform: rotate(360deg); }
}

.chat-list {
  flex: 1;
  overflow-y: auto;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  transition: background 0.15s;
}

.chat-item:hover, .chat-item.active {
  background: rgba(6, 182, 212, 0.08);
}

.chat-item.active {
  border-left: 3px solid var(--accent-cyan);
}

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

.chat-item-name {
  font-weight: 600;
  font-size: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-item-handle {
  font-size: 11px;
  color: var(--text-muted);
  font-family: monospace;
  margin-top: 1px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-item-preview {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 3px;
}

.auth-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 20px;
  background: rgba(0, 0, 0, 0.35);
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--border-color);
}

.auth-tab {
  flex: 1;
  padding: 10px 14px;
  border: none;
  border-radius: 7px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s ease;
  background: transparent;
  color: var(--text-muted);
}

.auth-tab.active {
  background: linear-gradient(135deg, var(--accent-cyan), #0284c7);
  color: #fff;
  box-shadow: 0 2px 8px rgba(6, 182, 212, 0.3);
}

/* Chat Main View */
#chat-main {
  flex: 1 1 0%;
  width: 100%;
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  min-width: 0;
  min-height: 0; /* CRITICAL: prevents child messages from expanding parent vertically */
  overflow: hidden; /* CRITICAL: forces children to scroll inside */
  position: relative;
}

.chat-header {
  flex-shrink: 0; /* CRITICAL: header never shrinks */
  padding: 12px 18px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-secondary);
  z-index: 10;
}

.chat-header-user {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.chat-header-details {
  min-width: 0;
  overflow: hidden;
}

.btn-drawer-toggle {
  display: none;
  background: transparent;
  border: none;
  color: var(--accent-cyan);
  cursor: pointer;
  padding: 8px;
  margin-right: 6px;
  margin-left: -6px;
  border-radius: 8px;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: all 0.15s ease;
  line-height: 0;
  flex-shrink: 0;
}

.btn-drawer-toggle:active {
  background: rgba(6, 182, 212, 0.2);
  transform: scale(0.95);
}

.btn-drawer-close {
  display: none;
}

.btn-back-mobile {
  display: none;
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-security {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: rgba(6, 182, 212, 0.1);
  border: 1px solid var(--border-active);
  border-radius: 6px;
  color: var(--accent-cyan);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.chat-messages {
  flex: 1 1 0%; /* CRITICAL: 0% basis so it never forces parent to grow */
  min-height: 0; /* CRITICAL: Allows scrolling */
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

.empty-chat {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  gap: 12px;
  padding: 24px;
}

.message-bubble {
  max-width: 60%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.45;
  position: relative;
  word-break: break-word;
}

.message-bubble.incoming {
  align-self: flex-start;
  background: var(--bubble-incoming);
  border-bottom-left-radius: 2px;
}

.message-bubble.outgoing {
  align-self: flex-end;
  background: var(--bubble-outgoing);
  border-bottom-right-radius: 2px;
}

.message-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.6);
  margin-top: 4px;
}

.status-check {
  font-weight: bold;
}
.status-check.read {
  color: #38bdf8;
}

/* Chat Input Bar */
.chat-input-bar {
  flex-shrink: 0; /* CRITICAL: strictly pinned at bottom, never pushed down */
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
  z-index: 10;
}

.chat-input-bar input {
  flex: 1;
  padding: 12px 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: #fff;
  font-size: 14px;
  outline: none;
}

.chat-input-bar input:focus {
  border-color: var(--accent-cyan);
}

.btn-send {
  padding: 12px 20px;
  background: linear-gradient(135deg, var(--accent-cyan), #0284c7);
  border: none;
  border-radius: 8px;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

/* Chat Input Bar Action Icons */
.btn-input-icon {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}
.btn-input-icon:hover {
  border-color: var(--accent-cyan);
  background: rgba(6, 182, 212, 0.15);
  transform: scale(1.05);
}

/* Header Voice Call Button */
.btn-header-call {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.4);
  border-radius: 6px;
  color: var(--accent-emerald);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-header-call:hover {
  background: rgba(16, 185, 129, 0.25);
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.4);
}

/* Voice Recording Active Ribbon */
.voice-recording-bar {
  position: absolute;
  inset: 0;
  background: #111827;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 15;
}

.recording-pulse {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #ef4444;
  animation: pulse-red 1s infinite ease-in-out;
}

@keyframes pulse-red {
  0% { transform: scale(0.9); opacity: 0.8; box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
  70% { transform: scale(1.2); opacity: 1; box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
  100% { transform: scale(0.9); opacity: 0.8; box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

.recording-timer {
  font-family: var(--font-mono);
  color: #ef4444;
  font-weight: 700;
  font-size: 13px;
}

.btn-record-action {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 14px;
  font-weight: bold;
  transition: transform 0.15s;
}
.btn-record-action:active {
  transform: scale(0.92);
}
.btn-record-action.cancel {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
  border: 1px solid rgba(239, 68, 68, 0.4);
}
.btn-record-action.send {
  background: var(--accent-emerald);
  color: #fff;
}

/* Encrypted File Card */
.file-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 4px;
  min-width: 220px;
}

.file-icon {
  font-size: 26px;
  flex-shrink: 0;
}

.file-info {
  flex: 1;
  min-width: 0;
}

.file-name {
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-download-file {
  padding: 6px 12px;
  background: rgba(6, 182, 212, 0.15);
  border: 1px solid var(--border-active);
  border-radius: 6px;
  color: var(--accent-cyan);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.2s;
  text-decoration: none;
}
.btn-download-file:hover {
  background: var(--accent-cyan);
  color: #080d1a;
}

/* Image previews */
.msg-img-preview {
  max-width: 100%;
  max-height: 280px;
  border-radius: 8px;
  cursor: pointer;
  display: block;
  object-fit: cover;
  border: 1px solid rgba(255, 255, 255, 0.1);
  margin-bottom: 4px;
}

/* Custom Voice Note Player */
.audio-player-bubble {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(0, 0, 0, 0.35);
  padding: 8px 12px;
  border-radius: 20px;
  min-width: 210px;
  max-width: 280px;
}

.btn-play-audio {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-cyan);
  border: none;
  color: #080d1a;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 12px;
  flex-shrink: 0;
}

.audio-progress {
  flex: 1;
  height: 4px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
  cursor: pointer;
  position: relative;
}

.audio-progress-bar {
  height: 100%;
  background: var(--accent-cyan);
  border-radius: 2px;
  width: 0%;
}

.audio-duration {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  flex-shrink: 0;
}

/* Expired File Card */
.file-expired-card {
  padding: 10px 14px;
  background: rgba(239, 68, 68, 0.1);
  border: 1px dashed rgba(239, 68, 68, 0.4);
  border-radius: 8px;
  color: #fca5a5;
  font-size: 12px;
}

/* Incoming Call Dialog */
.call-dialog {
  background: #111827;
  border: 1px solid rgba(16, 185, 129, 0.4);
  border-radius: 20px;
  padding: 32px 24px;
  text-align: center;
  width: 320px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8), 0 0 30px rgba(16, 185, 129, 0.2);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.call-avatar {
  width: 74px;
  height: 74px;
  border-radius: 50%;
  background: linear-gradient(135deg, #10b981, #06b6d4);
  color: #fff;
  font-size: 28px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: call-pulse 1.6s infinite ease-in-out;
}

@keyframes call-pulse {
  0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { box-shadow: 0 0 0 16px rgba(16, 185, 129, 0); }
  100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.call-actions {
  display: flex;
  gap: 16px;
  width: 100%;
  margin-top: 8px;
}

.btn-call-action {
  flex: 1;
  padding: 12px;
  border-radius: 12px;
  border: none;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s;
}
.btn-call-action:active { transform: scale(0.95); }

.btn-call-action.accept {
  background: #10b981;
  color: #fff;
}
.btn-call-action.decline {
  background: #ef4444;
  color: #fff;
}

/* Active Floating Call Bar */
.active-call-bar {
  position: absolute;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(17, 24, 39, 0.95);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(16, 185, 129, 0.5);
  border-radius: 30px;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  z-index: 100;
  box-shadow: 0 8px 24px rgba(0,0,0,0.6), 0 0 16px rgba(16, 185, 129, 0.2);
}

.call-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.call-pulse-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #10b981;
  animation: pulse-green 1.2s infinite;
}

@keyframes pulse-green {
  0% { transform: scale(0.9); opacity: 0.8; }
  50% { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(0.9); opacity: 0.8; }
}

.call-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-call-ctrl {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  transition: all 0.2s;
}
.btn-call-ctrl:hover {
  background: rgba(255, 255, 255, 0.2);
}
.btn-call-ctrl.hangup {
  background: #ef4444;
}
.btn-call-ctrl.muted {
  background: #f59e0b;
}

/* Modal for Security Verification */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.security-card {
  width: 480px;
  padding: 24px;
  border-radius: 12px;
  background: #111827;
  border: 1px solid var(--border-active);
}

.fingerprint-box {
  background: #0b0f19;
  padding: 12px;
  border-radius: 8px;
  font-family: var(--font-mono);
  font-size: 14px;
  text-align: center;
  letter-spacing: 1px;
  color: var(--accent-cyan);
  margin: 16px 0;
  border: 1px dashed var(--border-color);
}

/* Header Action Icons & Badges */
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-icon-badge {
  position: relative;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  border-radius: 8px;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
}

.btn-icon-badge:hover {
  color: #fff;
  border-color: var(--accent-cyan);
  background: rgba(6, 182, 212, 0.12);
}

.badge-count {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #ef4444;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  border-radius: 999px;
  padding: 1px 5px;
  min-width: 16px;
  text-align: center;
  box-shadow: 0 0 6px rgba(239, 68, 68, 0.7);
}

/* Sidebar Navigation Tabs */
.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-color);
  background: rgba(0, 0, 0, 0.25);
}

.sidebar-tab {
  flex: 1;
  padding: 10px 8px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
  user-select: none;
}

.sidebar-tab:hover {
  color: var(--text-primary);
}

.sidebar-tab.active {
  color: var(--accent-cyan);
  border-bottom-color: var(--accent-cyan);
  background: rgba(6, 182, 212, 0.08);
}

/* Modern Modals */
.modal-dialog {
  width: 500px;
  max-width: 95vw;
  max-height: 85vh;
  background: #111827;
  border: 1px solid var(--border-active);
  border-radius: 14px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8), 0 0 30px rgba(6, 182, 212, 0.1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-dialog-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-dialog-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-dialog-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.search-result-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  background: var(--bg-tertiary);
  border-radius: 8px;
  margin-bottom: 8px;
  border: 1px solid var(--border-color);
}

.btn-small-action {
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
}

.btn-small-action.primary {
  background: var(--accent-cyan);
  color: #fff;
}

.btn-small-action.success {
  background: var(--accent-emerald);
  color: #fff;
}

.btn-small-action.danger {
  background: #ef4444;
  color: #fff;
}

.btn-small-action.disabled {
  background: #374151;
  color: #9ca3af;
  cursor: not-allowed;
}

/* Group Message Sender Tag */
.msg-sender-tag {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent-cyan);
  margin-bottom: 3px;
}

/* =========================================================================
   MOBILE & TABLET SLIDER DRAWER (Screens <= 960px)
   ========================================================================= */
@media (max-width: 960px) {
  html, body {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
    height: 100dvh;
    -webkit-text-size-adjust: 100%;
  }

  #app-container {
    width: 100% !important;
    height: 100% !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    overflow: hidden !important;
    position: relative !important;
  }

  /* Sidebar as Slide-out Drawer from the Left Pane */
  #sidebar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    bottom: 0 !important;
    width: 320px !important;
    max-width: 85vw !important;
    height: 100% !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    z-index: 1000 !important;
    background: #0f1623 !important;
    border-right: 1px solid var(--border-active) !important;
    box-shadow: 12px 0 45px rgba(0, 0, 0, 0.85) !important;
    transform: translateX(-100%) !important;
    transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1) !important;
    will-change: transform;
    display: flex !important;
  }

  /* When drawer is open, slides in from left */
  #sidebar.drawer-open {
    transform: translateX(0) !important;
  }

  /* Close button on drawer header */
  .btn-drawer-close {
    display: flex !important;
    color: #ef4444 !important;
  }

  /* Chat Main View takes 100% MAXIMUM SPACE */
  #chat-main {
    width: 100% !important;
    flex: 1 1 0% !important;
    height: 100% !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    display: flex !important;
    min-height: 0 !important;
    overflow: hidden !important;
    position: relative !important;
  }

  /* Hamburger Drawer Toggle in Chat Header */
  .btn-drawer-toggle {
    display: inline-flex !important;
  }

  /* Chat Header */
  .chat-header {
    padding: 10px 14px !important;
    min-height: 56px !important;
    background: #0f1623 !important;
    flex-shrink: 0 !important;
  }

  .chat-header-user {
    gap: 8px !important;
    flex: 1;
    min-width: 0;
  }

  .chat-header-details {
    flex: 1;
    min-width: 0;
  }

  #active-chat-name {
    font-size: 14px !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #active-chat-status {
    font-size: 11px !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .btn-security {
    padding: 6px 10px !important;
    font-size: 11px !important;
    white-space: nowrap;
  }

  .btn-security-label {
    display: none;
  }

  .btn-call-label {
    display: none;
  }

  .btn-header-call {
    padding: 6px 10px !important;
  }

  .btn-input-icon {
    width: 34px !important;
    height: 34px !important;
    font-size: 15px !important;
  }

  /* Chat Messages - strictly contained so chat bar NEVER goes down */
  .chat-messages {
    flex: 1 1 0% !important;
    min-height: 0 !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    padding: 12px 10px !important;
    gap: 10px !important;
    -webkit-overflow-scrolling: touch;
  }

  .message-bubble {
    max-width: 86% !important;
    padding: 9px 12px !important;
    font-size: 14px !important;
    border-radius: 14px !important;
  }

  /* Chat Input Bar - permanently pinned at bottom */
  .chat-input-bar {
    flex-shrink: 0 !important;
    padding: 8px 10px !important;
    padding-bottom: max(8px, env(safe-area-inset-bottom)) !important;
    gap: 8px !important;
    background: #0f1623 !important;
    z-index: 10 !important;
  }

  .chat-input-bar input {
    font-size: 16px !important;
    padding: 10px 14px !important;
    border-radius: 20px !important;
  }

  .btn-send {
    padding: 10px 16px !important;
    border-radius: 20px !important;
    font-size: 13px !important;
    font-weight: 700 !important;
    min-height: 40px;
  }

  /* Sidebar Profile Header */
  .sidebar-header {
    padding: 12px 14px !important;
  }

  .header-actions {
    gap: 6px !important;
  }

  .btn-icon-badge {
    width: 36px !important;
    height: 36px !important;
    font-size: 15px !important;
  }

  /* Sidebar Search & Tabs */
  .sidebar-tabs {
    background: rgba(0, 0, 0, 0.4);
  }

  .sidebar-tab {
    padding: 11px 8px !important;
    font-size: 12.5px !important;
  }

  .sidebar-search {
    padding: 10px 14px !important;
  }

  .sidebar-search input {
    font-size: 14px !important;
    padding: 9px 12px !important;
  }

  .chat-item {
    padding: 12px 14px !important;
  }

  /* Auth Modal on Mobile */
  #auth-modal {
    padding: 14px !important;
    align-items: center;
  }

  .auth-card {
    width: 100% !important;
    max-width: 380px !important;
    padding: 22px 18px !important;
    margin: auto !important;
    border-radius: 16px !important;
    max-height: 94vh !important;
    overflow-y: auto !important;
  }

  .auth-brand {
    margin-bottom: 18px !important;
  }

  .auth-logo {
    width: 40px !important;
    height: 40px !important;
    font-size: 20px !important;
  }

  .form-group {
    margin-bottom: 14px !important;
  }

  .form-group input {
    font-size: 16px !important;
    padding: 11px 12px !important;
  }

  .btn-primary {
    padding: 13px !important;
    font-size: 14px !important;
    border-radius: 10px !important;
  }

  /* Modals on Mobile */
  .modal-dialog {
    width: 95vw !important;
    max-width: 420px !important;
    border-radius: 14px !important;
    max-height: 90vh !important;
  }

  .modal-dialog-header {
    padding: 14px 16px !important;
  }

  .modal-dialog-body {
    padding: 14px 16px !important;
  }

  .modal-dialog-footer {
    padding: 12px 16px !important;
  }

  .security-card {
    width: 95vw !important;
    max-width: 420px !important;
    padding: 18px 16px !important;
    border-radius: 14px !important;
  }

  .fingerprint-box {
    font-size: 12px !important;
    padding: 10px 8px !important;
  }
}
