/* Haven - Base Styles */

/* CSS Reset & Variables */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Prevent zoom/resize on all devices */
html {
  touch-action: manipulation;
  -ms-touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
  -moz-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  touch-action: pan-x pan-y;
  -ms-content-zooming: none;
  overscroll-behavior: none;
}

/* Prevent double-tap zoom */
* {
  touch-action: manipulation;
}

/* Prevent pinch zoom on the whole document */
html, body {
  overflow: hidden;
  position: fixed;
  width: 100%;
  height: 100%;
}

#app {
  width: 100%;
  height: 100%;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-tertiary: #0f0f23;
  --bg-hover: #252547;
  --bg-active: #2d2d5a;
  
  --text-primary: #ffffff;
  --text-secondary: #b9bbbe;
  --text-muted: #72767d;
  --text-link: #00aff4;
  
  --accent-primary: #5865f2;
  --accent-hover: #4752c4;
  --accent-success: #3ba55c;
  --accent-warning: #faa61a;
  --accent-danger: #ed4245;
  
  --border-color: #2f2f4a;
  --input-bg: #0f0f23;
  --input-border: #2f2f4a;
  
  --message-hover: #252547;
  --bubble-incoming: #2f2f4a;
  --bubble-outgoing: #5865f2;
  
  --sidebar-width: 240px;
  --members-width: 240px;
  --header-height: 48px;
  
  --radius-small: 4px;
  --radius-medium: 8px;
  --radius-large: 16px;
  --radius-full: 9999px;
  
  --shadow-low: 0 1px 2px rgba(0,0,0,0.2);
  --shadow-medium: 0 4px 8px rgba(0,0,0,0.3);
  --shadow-high: 0 8px 16px rgba(0,0,0,0.4);
  
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-size-xs: 11px;
  --font-size-sm: 13px;
  --font-size-md: 15px;
  --font-size-lg: 18px;
  --font-size-xl: 24px;
  
  --transition-fast: 0.1s ease;
  --transition-normal: 0.2s ease;
}

html, body {
  height: 100%;
  height: 100dvh; /* Dynamic viewport height for mobile */
  overflow: hidden;
}

body {
  font-family: var(--font-family);
  font-size: var(--font-size-md);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
}

#app {
  height: 100%;
  height: 100dvh;
  width: 100%;
  display: flex;
  flex-direction: column;
}

/* Screens */
.screen {
  display: none;
  height: 100%;
  width: 100%;
}

.screen.active {
  display: flex;
}

/* Loading Screen */
#loading-screen {
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
}

.loading-content {
  text-align: center;
  animation: fadeIn 0.5s ease;
}

.loading-logo {
  margin-bottom: 20px;
}

.loading-content h1 {
  font-size: 36px;
  font-weight: 700;
  margin-bottom: 8px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.loading-content p {
  color: var(--text-secondary);
  margin-bottom: 30px;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  margin: 0 auto;
  border: 3px solid var(--border-color);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Auth Screens */
#setup-screen,
#login-screen,
#change-password-screen {
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
}

.auth-container {
  width: 100%;
  max-width: 400px;
  padding: 40px;
  background: var(--bg-secondary);
  border-radius: var(--radius-large);
  box-shadow: var(--shadow-high);
  animation: fadeIn 0.3s ease;
}

.auth-logo {
  text-align: center;
  margin-bottom: 20px;
}

.auth-container h1 {
  text-align: center;
  font-size: var(--font-size-xl);
  font-weight: 700;
  margin-bottom: 8px;
}

.auth-subtitle {
  text-align: center;
  color: var(--text-secondary);
  margin-bottom: 30px;
}

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

/* Form Elements */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-group label {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="email"],
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 12px 16px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-medium);
  color: var(--text-primary);
  font-size: var(--font-size-md);
  font-family: inherit;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(88, 101, 242, 0.2);
}

.form-group input::placeholder,
.form-group textarea::placeholder {
  color: var(--text-muted);
}

.form-group input[type="checkbox"] {
  width: auto;
  margin-right: 8px;
}

.form-group small {
  color: var(--text-muted);
  font-size: var(--font-size-xs);
}

.form-error {
  color: var(--accent-danger);
  font-size: var(--font-size-sm);
  min-height: 20px;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 10px;
}

/* Password Strength */
.password-strength {
  height: 4px;
  background: var(--bg-tertiary);
  border-radius: 2px;
  overflow: hidden;
}

.password-strength::after {
  content: '';
  display: block;
  height: 100%;
  width: var(--strength, 0%);
  background: var(--strength-color, var(--accent-danger));
  transition: all var(--transition-normal);
}

.password-requirements {
  list-style: none;
  font-size: var(--font-size-xs);
  color: var(--text-muted);
}

.password-requirements li {
  padding: 2px 0;
}

.password-requirements li::before {
  content: '○ ';
}

.password-requirements li.valid {
  color: var(--accent-success);
}

.password-requirements li.valid::before {
  content: '● ';
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  font-size: var(--font-size-md);
  font-weight: 600;
  font-family: inherit;
  border: none;
  border-radius: var(--radius-medium);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

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

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

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

.btn-danger {
  background: var(--accent-danger);
  color: white;
}

.btn-danger:hover:not(:disabled) {
  background: #c73e41;
}

.btn-block {
  width: 100%;
}

.btn-small {
  padding: 6px 12px;
  font-size: var(--font-size-sm);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: var(--radius-medium);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

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

/* Chat Layout */
#chat-screen {
  flex-direction: column;
}

#chat-screen.active {
  display: flex;
}

.chat-layout {
  display: flex;
  height: 100%;
  width: 100%;
  flex: 1;
  min-height: 0;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  height: 100%;
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border-color);
}

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

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

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: var(--bg-hover);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.user-avatar.large {
  width: 80px;
  height: 80px;
}

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

.avatar-placeholder {
  font-size: 14px;
  color: var(--text-muted);
}

.user-avatar.large .avatar-placeholder {
  font-size: 32px;
}

.user-details {
  display: flex;
  flex-direction: column;
}

.username {
  font-weight: 600;
  font-size: var(--font-size-sm);
}

.status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}

.status-indicator.online {
  background: var(--accent-success);
}

.status-indicator.away {
  background: var(--accent-warning);
}

/* Room List */
.room-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.room-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-medium);
  cursor: pointer;
  transition: background var(--transition-fast);
}

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

.room-item.active {
  background: var(--bg-active);
}

.room-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-medium);
  background: var(--bg-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.room-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.room-icon-placeholder {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-muted);
}

.room-name {
  font-weight: 500;
  font-size: var(--font-size-sm);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.room-unread {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  background: var(--accent-danger);
  color: white;
  font-size: var(--font-size-xs);
  font-weight: 700;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border-color);
}

/* Main Chat Area */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg-primary);
  overflow: hidden;
}

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

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

.room-details h2 {
  font-size: var(--font-size-md);
  font-weight: 600;
}

.room-details p {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
}

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

.member-count {
  font-size: var(--font-size-xs);
  margin-left: 4px;
}

/* Messages Container */
.messages-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
}

.messages-list {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.no-room-selected {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  gap: 16px;
}

/* Message Styles */
.message {
  display: flex;
  gap: 12px;
  padding: 8px 16px;
  border-radius: var(--radius-medium);
  transition: background var(--transition-fast);
  position: relative;
}

.message:hover {
  background: var(--message-hover);
}

.message-avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: var(--bg-hover);
  flex-shrink: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.message-content {
  flex: 1;
  min-width: 0;
}

.message-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
}

.message-author {
  font-weight: 600;
  font-size: var(--font-size-md);
  color: var(--text-primary);
}

.message-timestamp {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
}

.edited-badge {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  margin-left: 8px;
  font-style: italic;
}

.deleted-message {
  color: var(--text-muted);
  font-style: italic;
}

.message-text {
  font-size: var(--font-size-md);
  line-height: 1.5;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.message-text a {
  color: var(--text-link);
  text-decoration: none;
}

.message-text a:hover {
  text-decoration: underline;
}

/* Mentions */
.mention {
  background: rgba(88, 101, 242, 0.3);
  color: var(--accent-primary);
  padding: 0 4px;
  border-radius: 3px;
  font-weight: 500;
}

.message.mentioned {
  background: rgba(250, 166, 26, 0.1);
  border-left: 3px solid var(--accent-warning);
}

/* Reply Snippet (shown in message when replying to another) */
.message-reply-snippet {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 10px;
  margin-bottom: 6px;
  font-size: var(--font-size-sm);
  background: var(--bg-tertiary);
  border-radius: var(--radius-small);
  border-left: 3px solid var(--accent-primary);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.message-reply-snippet:hover {
  background: var(--bg-hover);
}

.reply-snippet-author {
  font-weight: 600;
  color: var(--accent-primary);
  font-size: var(--font-size-xs);
}

.reply-snippet-text {
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Message highlight animation (when scrolling to replied message) */
.message.highlighted {
  animation: highlightPulse 2s ease-out;
}

@keyframes highlightPulse {
  0% { background: var(--accent-primary); }
  100% { background: transparent; }
}

/* Reply Preview in Input */
.message-reply {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  margin-bottom: 4px;
  font-size: var(--font-size-sm);
  color: var(--text-muted);
  background: var(--bg-tertiary);
  border-radius: var(--radius-small);
  border-left: 2px solid var(--accent-primary);
}

.message-reply-author {
  font-weight: 600;
  color: var(--text-secondary);
}

.message-reply-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Reactions */
.message-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
}

.reaction {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  background: var(--bg-hover);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  font-size: var(--font-size-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.reaction:hover {
  background: var(--bg-active);
}

.reaction.own {
  background: rgba(88, 101, 242, 0.2);
  border-color: var(--accent-primary);
}

.reaction-emoji {
  font-size: 16px;
}

.reaction-count {
  color: var(--text-secondary);
  font-weight: 500;
}

/* Attachments */
.message-attachments {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.attachment {
  max-width: 400px;
  border-radius: var(--radius-medium);
  overflow: hidden;
  background: var(--bg-secondary);
}

.attachment-image {
  max-width: 100%;
  max-height: 300px;
  cursor: pointer;
  transition: opacity var(--transition-fast);
}

.attachment-image:hover {
  opacity: 0.9;
}

.attachment-file {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
}

.attachment-icon {
  width: 40px;
  height: 40px;
  background: var(--bg-hover);
  border-radius: var(--radius-medium);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

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

.attachment-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.attachment-size {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
}

.attachment-download {
  color: var(--text-link);
  text-decoration: none;
  font-size: var(--font-size-sm);
  font-weight: 500;
}

/* Message Actions */
.message-actions {
  position: absolute;
  top: -16px;
  right: 16px;
  display: none;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-medium);
  box-shadow: var(--shadow-medium);
}

.message:hover .message-actions {
  display: flex;
}

.message-action-btn {
  padding: 6px 10px;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

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

/* Read Receipts */
.read-receipts {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 2px;
  margin-top: 4px;
}

.read-receipt-avatar {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--bg-hover);
  overflow: hidden;
  border: 1px solid var(--bg-primary);
  margin-left: -4px;
}

.read-receipt-avatar:first-child {
  margin-left: 0;
}

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

/* Typing Indicator */
.typing-indicator {
  padding: 8px 16px;
  font-size: var(--font-size-sm);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.typing-dots {
  display: flex;
  gap: 3px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-4px); }
}

/* Message Input */
.message-input-container {
  padding: 16px;
  background: var(--bg-primary);
  border-top: 1px solid var(--border-color);
}

.reply-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  margin-bottom: 8px;
  background: var(--bg-secondary);
  border-radius: var(--radius-medium);
  border-left: 3px solid var(--accent-primary);
}

.reply-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.reply-to {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
}

.reply-text {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reply-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
}

.reply-close:hover {
  color: var(--text-primary);
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.message-input-wrapper {
  flex: 1;
  position: relative;
  display: flex;
  align-items: flex-end;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-large);
  padding: 8px 12px;
  transition: border-color var(--transition-fast);
}

.message-input-wrapper:focus-within {
  border-color: var(--accent-primary);
}

#message-input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: var(--font-size-md);
  font-family: inherit;
  resize: none;
  max-height: 150px;
  line-height: 1.5;
}

#message-input:focus {
  outline: none;
}

#message-input::placeholder {
  color: var(--text-muted);
}

.emoji-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  transition: color var(--transition-fast);
}

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

.send-btn {
  background: var(--accent-primary);
  color: white;
}

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

/* Attachment Preview */
.attachment-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.attachment-preview-item {
  position: relative;
  width: 80px;
  height: 80px;
  border-radius: var(--radius-medium);
  overflow: hidden;
  background: var(--bg-secondary);
}

.attachment-preview-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.attachment-preview-item .file-icon {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.attachment-preview-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  background: var(--accent-danger);
  border: none;
  border-radius: 50%;
  color: white;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Members Panel */
.members-panel {
  width: var(--members-width);
  height: 100%;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border-color);
  display: none;
  flex-direction: column;
}

.members-panel.active {
  display: flex;
}

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

.members-header h3 {
  font-size: var(--font-size-md);
  font-weight: 600;
}

.members-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.members-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  font-size: var(--font-size-xs);
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  margin-top: 8px;
}

.members-section-header:first-child {
  margin-top: 0;
}

.members-count {
  background: var(--bg-hover);
  padding: 2px 6px;
  border-radius: var(--radius-small);
  font-size: var(--font-size-xs);
}

.members-empty {
  text-align: center;
  padding: 20px;
  color: var(--text-muted);
  font-size: var(--font-size-sm);
}

.member-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius-medium);
  cursor: pointer;
  transition: background var(--transition-fast);
}

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

.member-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: var(--bg-hover);
  overflow: hidden;
  position: relative;
}

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

.member-status {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--text-muted);
  border: 2px solid var(--bg-secondary);
}

.member-status.online {
  background: var(--accent-success);
}

.member-name {
  font-weight: 500;
  font-size: var(--font-size-sm);
}

.member-role {
  font-size: var(--font-size-xs);
  color: var(--accent-primary);
  font-weight: 600;
}

/* Modals */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
}

.modal.active {
  display: flex;
}

.modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  animation: fadeIn 0.2s ease;
}

.modal-content {
  position: relative;
  width: 90%;
  max-width: 500px;
  max-height: 90vh;
  background: var(--bg-secondary);
  border-radius: var(--radius-large);
  box-shadow: var(--shadow-high);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: modalSlideIn 0.2s ease;
}

.modal-content.modal-small {
  max-width: 400px;
}

.modal-content.modal-large {
  max-width: 700px;
}

@keyframes modalSlideIn {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}

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

.modal-header h2 {
  font-size: var(--font-size-lg);
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

.modal-close:hover {
  color: var(--text-primary);
}

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

/* Settings */
.settings-section {
  margin-bottom: 24px;
}

.settings-section:last-child {
  margin-bottom: 0;
}

.settings-section h3 {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  gap: 12px;
}

.settings-row label {
  font-weight: 500;
}

.settings-hint {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  margin-top: 8px;
  margin-bottom: 0;
}

.settings-avatar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.settings-avatar .avatar-large {
  width: 80px;
  height: 80px;
  border-radius: var(--radius-full);
  background: var(--bg-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}

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

.settings-avatar .avatar-large .avatar-placeholder {
  font-size: 32px;
  font-weight: 600;
  color: var(--text-secondary);
}

.avatar-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.avatar-upload-progress {
  width: 100%;
  max-width: 200px;
}

.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-small);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent-primary);
  border-radius: var(--radius-small);
  transition: width 0.2s ease;
  width: 0%;
}

.progress-text {
  display: block;
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  margin-top: 4px;
}

.avatar-error {
  color: var(--accent-danger) !important;
  margin-top: 8px;
}

.setting-item {
  padding: 8px 0;
}

.setting-item label {
  display: flex;
  align-items: center;
  cursor: pointer;
}

.setting-item small {
  display: block;
  margin-top: 4px;
  margin-left: 24px;
  color: var(--text-muted);
  font-size: var(--font-size-xs);
}

.setting-item select {
  width: 100%;
  padding: 10px 12px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-medium);
  color: var(--text-primary);
  font-size: var(--font-size-md);
}

.profile-edit {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.profile-avatar-edit {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

/* Admin Panel */
.admin-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.admin-tab {
  padding: 8px 16px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: var(--font-size-md);
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--radius-medium);
  transition: all var(--transition-fast);
}

.admin-tab:hover {
  background: var(--bg-hover);
}

.admin-tab.active {
  background: var(--accent-primary);
  color: white;
}

.admin-tab-content {
  display: none;
}

.admin-tab-content.active {
  display: block;
}

.admin-actions {
  margin-bottom: 16px;
}

.admin-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.admin-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-medium);
}

.admin-item-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.admin-item-avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: var(--bg-hover);
  overflow: hidden;
}

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

.admin-item-details {
  display: flex;
  flex-direction: column;
}

.admin-item-name {
  font-weight: 600;
}

.admin-item-meta {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
}

.admin-item-badge {
  font-size: var(--font-size-xs);
  padding: 2px 6px;
  border-radius: var(--radius-small);
  font-weight: 600;
}

.admin-item-badge.admin {
  background: var(--accent-primary);
  color: white;
}

.admin-item-badge.locked {
  background: var(--accent-danger);
  color: white;
}

.admin-item-actions {
  display: flex;
  gap: 8px;
}

/* Temp Password Display */
.temp-password-display {
  text-align: center;
}

.temp-password-display p {
  margin-bottom: 12px;
}

.temp-password {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-medium);
  margin-bottom: 16px;
}

.temp-password code {
  font-size: var(--font-size-lg);
  font-family: monospace;
  letter-spacing: 1px;
}

.temp-password-display .warning {
  color: var(--accent-warning);
  font-size: var(--font-size-sm);
  margin-bottom: 16px;
}

/* Manage Members */
.manage-members-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.members-column h4 {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.member-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 300px;
  overflow-y: auto;
}

.member-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-medium);
}

.member-list-item-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Emoji Picker */
.emoji-picker {
  position: absolute;
  bottom: 100%;
  right: 0;
  width: 320px;
  max-height: 350px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-medium);
  box-shadow: var(--shadow-high);
  z-index: 100;
  display: flex;
  flex-direction: column;
}

.emoji-search {
  padding: 8px;
  border-bottom: 1px solid var(--border-color);
}

.emoji-search input {
  width: 100%;
  padding: 8px 12px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-medium);
  color: var(--text-primary);
  font-size: var(--font-size-sm);
}

.emoji-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
}

.emoji-item {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  cursor: pointer;
  border-radius: var(--radius-small);
  transition: background var(--transition-fast);
}

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

/* Context Menu */
.context-menu {
  position: fixed;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-medium);
  box-shadow: var(--shadow-high);
  z-index: 1001;
  min-width: 160px;
  padding: 4px;
}

.context-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 12px;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: var(--font-size-sm);
  cursor: pointer;
  border-radius: var(--radius-small);
  transition: background var(--transition-fast);
}

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

/* Icon Upload */
.icon-upload {
  display: flex;
  align-items: center;
  gap: 12px;
}

.room-icon-preview {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-medium);
  background: var(--bg-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 700;
  color: var(--text-muted);
  overflow: hidden;
}

.room-icon-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Date Separator */
.date-separator {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 16px 0;
}

.date-separator::before,
.date-separator::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-color);
}

.date-separator span {
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--bg-hover);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--bg-active);
}

/* Sidebar Overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 99;
  opacity: 0;
  transition: opacity var(--transition-normal);
}

.sidebar-overlay.active {
  display: block;
  opacity: 1;
}

/* Menu Button (hidden on desktop) */
.menu-btn {
  display: none;
}

/* Typing Indicator - Fixed at bottom */
.typing-indicator {
  padding: 8px 16px;
  font-size: var(--font-size-sm);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-primary);
  border-top: 1px solid var(--border-color);
}

.typing-dots {
  display: flex;
  gap: 3px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(1) { animation-delay: 0s; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-4px); }
}

.typing-text {
  font-style: italic;
}

/* Responsive - Tablet and Mobile */
@media (max-width: 900px) {
  .members-panel {
    position: fixed;
    right: 0;
    top: 0;
    height: 100%;
    z-index: 100;
    transform: translateX(100%);
    transition: transform var(--transition-normal);
  }

  .members-panel.active {
    transform: translateX(0);
  }
}

/* Mobile specific */
@media (max-width: 768px) {
  :root {
    --header-height: 56px;
  }

  /* Show menu button on mobile */
  .menu-btn {
    display: flex;
    margin-right: 8px;
  }

  /* Sidebar slides in from left */
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100%;
    width: 280px;
    max-width: 85vw;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform var(--transition-normal);
    box-shadow: var(--shadow-high);
  }

  .sidebar.active {
    transform: translateX(0);
  }

  /* Chat layout takes full width */
  .chat-layout {
    flex-direction: column;
    height: 100%;
  }

  .chat-main {
    flex: 1;
    width: 100%;
    height: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }

  .messages-container {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
  }

  /* Room header adjustments */
  .chat-header {
    padding: 0 8px;
    flex-shrink: 0;
  }

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

  .room-details h2 {
    font-size: var(--font-size-md);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .room-details p {
    display: none;
  }

  /* Room list vertical on mobile */
  .room-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px;
  }

  .room-item {
    width: 100%;
  }

  /* Messages area */
  .messages-container {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  .messages-list {
    padding: 8px;
  }

  /* Input container should not shrink */
  .message-input-container {
    flex-shrink: 0;
  }

  .message {
    padding: 8px;
    gap: 8px;
    position: relative;
    -webkit-user-select: none;
    user-select: none;
    /* Allow touch scrolling to work */
    touch-action: pan-y;
  }

  .message-avatar {
    width: 32px;
    height: 32px;
  }

  .message.menu-open {
    background: var(--message-hover);
  }

  .message-actions {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-medium);
    box-shadow: var(--shadow-high);
    padding: 8px;
    flex-direction: column;
    gap: 4px;
    z-index: 50;
    min-width: 140px;
  }

  .message-actions.active {
    display: flex;
  }

  .message-action-btn {
    padding: 12px 16px;
    font-size: 15px;
    text-align: left;
    border-radius: var(--radius-small);
    background: none;
    border: none;
    color: var(--text-primary);
  }

  .message-action-btn:active {
    background: var(--bg-hover);
  }

  /* Input area */
  .message-input-container {
    padding: 8px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0));
  }

  .input-row {
    gap: 4px;
  }

  #message-input {
    font-size: 16px; /* Prevents zoom on iOS */
  }

  /* Modals */
  .modal-content {
    width: 95%;
    max-width: none;
    max-height: 90vh;
    margin: 5vh auto;
  }

  .modal-large {
    width: 95%;
  }

  /* Admin panel */
  .admin-tabs {
    flex-wrap: wrap;
  }

  .admin-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .admin-item-actions {
    width: 100%;
    justify-content: flex-end;
  }

  /* Members panel full screen on mobile */
  .members-panel {
    width: 100%;
    max-width: none;
  }

  /* Emoji picker */
  .emoji-picker {
    bottom: 60px;
    right: 8px;
    left: 8px;
    width: auto;
  }

  /* Settings */
  .settings-avatar {
    flex-direction: column;
    text-align: center;
  }

  /* Auth screens */
  .auth-container {
    padding: 24px 16px;
    width: 100%;
    max-width: none;
    margin: 0;
  }

  .auth-form {
    padding: 0;
  }
}

/* Extra small devices */
@media (max-width: 380px) {
  .chat-header-actions .member-count {
    display: none;
  }

  .room-icon {
    display: none;
  }

  .input-wrapper {
    flex: 1;
  }

  .icon-btn {
    width: 36px;
    height: 36px;
  }
}

/* ============================================================================
   Call UI Styles
   ============================================================================ */

/* Call Modal Base */
.call-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease;
}

.call-modal-content {
  text-align: center;
  padding: 40px;
}

.call-avatar {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: var(--bg-hover);
  margin: 0 auto 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: pulse 2s infinite;
}

.call-avatar .avatar-placeholder {
  font-size: 48px;
  color: var(--text-muted);
}

.call-avatar-small {
  width: 60px;
  height: 60px;
}

.call-avatar-small .avatar-placeholder {
  font-size: 24px;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.05); opacity: 0.8; }
}

.call-modal h3 {
  font-size: 24px;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.call-modal p {
  color: var(--text-muted);
  margin-bottom: 30px;
}

/* Call Action Buttons */
.call-actions {
  display: flex;
  gap: 30px;
  justify-content: center;
}

.call-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, opacity 0.2s;
}

.call-btn:hover {
  transform: scale(1.1);
}

.call-btn:active {
  transform: scale(0.95);
}

.call-accept {
  background: var(--accent-success);
  color: white;
}

.call-reject {
  background: var(--accent-danger);
  color: white;
}

/* Active Call Modal */
.call-active {
  flex-direction: column;
  background: #000;
}

.call-video-container {
  flex: 1;
  width: 100%;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

#remote-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #111;
}

#local-video {
  position: absolute;
  bottom: 20px;
  right: 20px;
  width: 150px;
  height: 112px;
  border-radius: var(--radius-medium);
  object-fit: cover;
  background: #222;
  border: 2px solid var(--border-color);
}

.call-info {
  padding: 20px;
  text-align: center;
  background: linear-gradient(transparent, rgba(0,0,0,0.8));
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
}

.call-info h3 {
  margin: 10px 0 5px;
  font-size: 18px;
}

.call-info p {
  margin: 0;
  font-size: 14px;
}

/* Call Controls */
.call-controls {
  padding: 20px;
  display: flex;
  gap: 20px;
  justify-content: center;
  background: rgba(0, 0, 0, 0.8);
}

.call-control-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--bg-hover);
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.call-control-btn:hover {
  background: var(--bg-active);
}

.call-control-btn.active {
  background: var(--accent-warning);
  color: #000;
}

.call-control-btn.call-end {
  background: var(--accent-danger);
  color: white;
}

.call-control-btn.call-end:hover {
  background: #c9363a;
}

/* Member Call Button */
.member-item {
  position: relative;
}

/* Member Call Buttons */
.member-call-btns {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  gap: 4px;
}

.member-call-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: var(--accent-success);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  opacity: 0.7;
}

.member-call-btn.video {
  background: var(--accent-primary);
}

.member-call-btn.offline {
  background: var(--text-muted);
  opacity: 0.4;
}

.member-item:hover .member-call-btn {
  opacity: 1;
}

.member-item:hover .member-call-btn.offline {
  opacity: 0.6;
}

.member-call-btn:hover {
  transform: scale(1.15);
  opacity: 1;
}

/* Call button in header */
.call-header-btn {
  color: var(--text-secondary);
}

.call-header-btn:hover {
  color: var(--accent-success);
}

/* Mobile call adjustments */
@media (max-width: 768px) {
  #local-video {
    width: 100px;
    height: 75px;
    bottom: 100px;
    right: 10px;
  }

  .call-controls {
    padding: 15px;
    gap: 15px;
  }

  .call-control-btn {
    width: 48px;
    height: 48px;
  }

  .call-btn {
    width: 56px;
    height: 56px;
  }
}

/* Toast Notifications */
#toast-container {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  pointer-events: none;
  max-width: 90vw;
}

.toast {
  background: var(--bg-secondary);
  color: var(--text-primary);
  padding: 12px 20px;
  border-radius: var(--radius-medium);
  box-shadow: var(--shadow-high);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toast-in 0.3s ease;
  pointer-events: auto;
  max-width: 100%;
  border: 1px solid var(--border-color);
}

.toast.toast-success {
  border-left: 4px solid var(--accent-success);
}

.toast.toast-error {
  border-left: 4px solid var(--accent-danger);
}

.toast.toast-warning {
  border-left: 4px solid var(--accent-warning);
}

.toast.toast-info {
  border-left: 4px solid var(--accent-primary);
}

.toast-icon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
}

.toast-message {
  font-size: var(--font-size-sm);
  line-height: 1.4;
}

.toast.toast-out {
  animation: toast-out 0.3s ease forwards;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes toast-out {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(-20px);
  }
}
