:root {
  --primary: #6C5CE7;
  --primary-dark: #5F4FD1;
  --primary-light: #A29BFE;
  --secondary: #00B894;
  --danger: #FF7675;
  --dark: #2D3436;
  --gray: #636E72;
  --light-gray: #B2BEC3;
  --bg-light: #F8F9FA;
  --white: #FFFFFF;
  --text-primary: #2D3436;
  --text-secondary: #636E72;
  --bg-primary: #FFFFFF;
  --bg-secondary: #F8F9FA;
  --bg-tertiary: #E9ECEF;
  --border-color: #E9ECEF;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.15);
  --border-radius: 12px;
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --safe-area-top: env(safe-area-inset-top, 0px);
  --safe-area-right: env(safe-area-inset-right, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
  --safe-area-left: env(safe-area-inset-left, 0px);
}

[data-theme="dark"] {
  --primary: #A29BFE;
  --primary-dark: #6C5CE7;
  --primary-light: #B5A9FE;
  --secondary: #55EFC4;
  --danger: #FF7675;
  --dark: #FAFAFA;
  --gray: #B2BEC3;
  --light-gray: #636E72;
  --bg-light: #2C3E50;
  --white: #1E272E;
  --text-primary: #FAFAFA;
  --text-secondary: #B2BEC3;
  --bg-primary: #1E272E;
  --bg-secondary: #2C3E50;
  --bg-tertiary: #34495E;
  --border-color: #34495E;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.4);
}

[data-theme="ocean"] {
  --primary: #3498DB;
  --primary-dark: #2980B9;
  --primary-light: #5DADE2;
  --secondary: #1ABC9C;
  --bg-light: #EBF5FB;
}

[data-theme="sunset"] {
  --primary: #E74C3C;
  --primary-dark: #C0392B;
  --primary-light: #EC7063;
  --secondary: #F39C12;
  --bg-light: #FADBD8;
}

[data-theme="forest"] {
  --primary: #27AE60;
  --primary-dark: #229954;
  --primary-light: #58D68D;
  --secondary: #F39C12;
  --bg-light: #D5F4E6;
}

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

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

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

::-webkit-scrollbar-thumb {
  background: var(--light-gray);
  border-radius: 4px;
  transition: background 0.3s;
}

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

/* Firefox scrollbar styling */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--light-gray) var(--bg-secondary);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: auto;
  color: var(--text-primary);
  transition: background 0.3s ease, color 0.3s ease;
  -webkit-text-size-adjust: 100%;
}

body.mobile-chat-active {
  overflow: hidden;
}

.app-container {
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  flex: 1 0 auto;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: calc(20px + var(--safe-area-top)) calc(16px + var(--safe-area-right)) 20px calc(16px + var(--safe-area-left));
  overflow-y: auto;
}

#join-footer {
  flex-shrink: 0;
  text-align: center;
  padding: 0.75rem calc(1rem + var(--safe-area-right)) calc(0.9rem + var(--safe-area-bottom)) calc(1rem + var(--safe-area-left));
  background: rgba(255, 255, 255, 0.97);
  border-top: 1px solid #e0e0e0;
  font-size: 0.875rem;
  color: #666;
  backdrop-filter: blur(8px);
}

.join-footer-notice {
  background: #fff3cd;
  border: 1px solid #ffc107;
  padding: 0.625rem 0.75rem;
  margin-bottom: 0.5rem;
  border-radius: 8px;
}

.join-footer-text {
  margin: 0;
  line-height: 1.5;
}

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

.screen.active {
  display: flex;
  justify-content: center;
  align-items: center;
}

/* ==================== JOIN SCREEN ==================== */
.join-box {
  background: var(--bg-primary);
  padding: 2.5rem;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-lg);
  max-width: 540px;
  width: 90%;
  animation: slideUp 0.4s ease;
  margin: 20px 0;
}

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

.logo {
  font-size: 4rem;
  text-align: center;
  margin-bottom: 1rem;
}

.join-box h1 {
  color: var(--primary);
  margin-bottom: 0.5rem;
  text-align: center;
  font-size: 2rem;
  font-weight: 700;
}

.subtitle {
  text-align: center;
  color: var(--text-secondary);
  margin-bottom: 2rem;
  font-size: 0.9rem;
}

.lobby-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.45rem;
  margin-bottom: 0.9rem;
  padding: 0.3rem;
  border-radius: 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
}

[data-theme="dark"] .lobby-tabs {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.16);
}

.lobby-tab-btn {
  position: relative;
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.76rem;
  font-weight: 600;
  padding: 0.45rem 0.3rem;
  cursor: pointer;
  transition: var(--transition);
}

[data-theme="dark"] .lobby-tab-btn {
  color: #d5deea;
}

.lobby-tab-btn::after {
  content: '';
  position: absolute;
  left: 18%;
  right: 18%;
  bottom: 5px;
  height: 2px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.85);
  transform: scaleX(0);
  transform-origin: center;
  transition: transform 0.22s ease;
}

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

[data-theme="dark"] .lobby-tab-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
}

.lobby-tab-btn.active {
  border-color: var(--primary-light);
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff;
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

[data-theme="dark"] .lobby-tab-btn.active {
  border-color: rgba(255, 255, 255, 0.45);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.15), 0 8px 18px rgba(0, 0, 0, 0.35);
}

.lobby-tab-btn.active::after {
  transform: scaleX(1);
}

.lobby-tab-panel {
  display: none;
}

.lobby-tab-panel.active {
  display: block;
  animation: lobbyPanelIn 0.24s cubic-bezier(0.2, 0.9, 0.2, 1);
}

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

.lobby-zone {
  margin-top: 0.9rem;
  padding: 0.9rem;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
}

.lobby-zone.quick-join-zone {
  margin-top: 0;
}

.lobby-zone-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  margin-bottom: 0.65rem;
}

.lobby-zone-header h3 {
  margin: 0;
  font-size: 0.95rem;
  color: var(--text-primary);
}

.form-group {
  margin-bottom: 1rem;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 0.875rem 1rem;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  font-size: 0.95rem;
  transition: var(--transition);
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--bg-primary);
}

.form-group input::placeholder {
  color: var(--light-gray);
}

.discover-card {
  margin-top: 0.9rem;
}

.discover-hall-note {
  margin: 0 0 0.65rem;
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--text-secondary);
}

[data-theme="dark"] .discover-hall-note {
  color: #c9d2df;
}

#discover-enter-hall-btn {
  margin-top: 0;
  margin-bottom: 0.6rem;
}

.discover-captcha-box {
  margin-bottom: 0.65rem;
}

@media (max-width: 768px) {
  .join-box {
    padding: 1.35rem 1rem;
    width: 100%;
    max-width: 100%;
    margin: 0;
    border-radius: 0;
    min-height: 100vh;
    min-height: 100dvh;
  }

  .lobby-tabs {
    position: sticky;
    top: 0;
    z-index: 5;
  }

  .lobby-tab-btn {
    min-height: 42px;
    font-size: 0.73rem;
  }

  .discover-hall-note {
    font-size: 0.75rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .lobby-tab-btn,
  .lobby-tab-btn::after,
  .lobby-tab-panel.active {
    animation: none;
    transition: none;
  }
}

.discover-header {
  margin-bottom: 0.4rem;
}

.discover-segmented {
  display: inline-flex;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  overflow: hidden;
}

.discover-segment-btn {
  border: none;
  background: var(--bg-primary);
  color: var(--text-secondary);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.35rem 0.6rem;
  min-height: 36px;
  cursor: pointer;
}

.discover-segment-btn.active {
  background: var(--primary);
  color: #fff;
}

.discover-filter-row {
  margin-bottom: 0.55rem;
}

.discover-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.discover-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  font-size: 0.72rem;
  color: var(--text-secondary);
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.legend-dot.available {
  background: #67c27c;
}

.legend-dot.busy {
  background: #e28a8a;
}

.discover-users-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  max-height: 250px;
  overflow-y: auto;
}

.discover-user-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.55rem;
  align-items: center;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  padding: 0.55rem 0.6rem;
  background: var(--bg-primary);
}

.discover-user-item.available {
  box-shadow: inset 0 0 0 1px rgba(47, 158, 85, 0.25);
}

.discover-user-item.busy {
  box-shadow: inset 0 0 0 1px rgba(187, 67, 67, 0.2);
}

.discover-user-item.gender-male {
  background: #eaf5ff;
  border-color: #c9e2ff;
}

.discover-user-item.gender-female {
  background: #ffeef7;
  border-color: #f7d1e5;
}

.discover-user-item.gender-other {
  background: #f3edff;
  border-color: #ddd0ff;
}

.discover-user-main {
  min-width: 0;
}

.discover-user-name {
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.discover-user-inline-meta {
  font-weight: 500;
  font-size: 0.72rem;
  color: var(--text-secondary);
}

.discover-user-meta {
  margin-top: 0.18rem;
  font-size: 0.73rem;
  color: var(--text-secondary);
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.discover-invite-btn {
  min-height: 34px;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 0.35rem 0.6rem;
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
}

.discover-invite-btn.available {
  background: #2f9e55;
  color: #fff;
}

.discover-invite-btn.busy {
  background: #efc4c4;
  color: #7e3e3e;
  cursor: not-allowed;
}

.discover-empty {
  font-size: 0.78rem;
  color: var(--text-secondary);
  text-align: center;
  padding: 0.8rem 0.35rem;
}

.discover-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  margin-top: 0.55rem;
}

.discover-page-btn {
  min-height: 34px;
  padding: 0.25rem 0.65rem;
  border: 1px solid var(--border-color);
  border-radius: 7px;
  font-size: 0.73rem;
  background: var(--bg-primary);
  color: var(--text-primary);
  cursor: pointer;
}

.discover-page-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.discover-page-indicator {
  font-size: 0.74rem;
  color: var(--text-secondary);
}

.discover-total-indicator {
  margin-top: 0.35rem;
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-secondary);
}

.account-links {
  margin-top: 0.55rem;
  text-align: center;
}

.account-link {
  color: var(--primary);
  text-decoration: none;
  font-size: 0.82rem;
}

/* Buttons */
.btn {
  padding: 0.875rem 1.5rem;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.btn-primary {
  background: var(--primary);
  color: var(--white);
  width: 100%;
  margin-top: 1rem;
}

.btn-primary:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.btn-primary:active {
  transform: translateY(0);
}

/* CAPTCHA */
.captcha-box {
  display: block;
  background: var(--bg-secondary);
  padding: 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  border: 2px solid var(--border-color);
}

.captcha-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 0.5rem;
}

.captcha-question {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  text-align: center;
  flex: 1;
  min-height: 1.5rem;
  padding: 0.25rem;
}

.reload-captcha-btn {
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  color: var(--text-primary);
  cursor: pointer;
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  min-width: 44px;
  min-height: 44px;
}

.reload-captcha-btn:hover {
  background: var(--primary-color);
  border-color: var(--primary-color);
  color: white;
  transform: rotate(180deg);
}

.reload-captcha-btn:active {
  transform: rotate(180deg) scale(0.95);
}

.reload-captcha-btn svg {
  width: 20px;
  height: 20px;
}

#captcha-answer {
  width: 100%;
  padding: 0.75rem;
  border: 2px solid var(--border-color);
  border-radius: 6px;
  font-size: 0.95rem;
  background: var(--bg-primary);
  color: var(--text-primary);
  text-align: center;
}

#captcha-answer:focus {
  outline: none;
  border-color: var(--primary);
}

.error-message {
  margin-top: 1rem;
  padding: 0.75rem;
  background: #FFF5F5;
  color: var(--danger);
  border-radius: 8px;
  display: none;
  text-align: center;
  font-size: 0.9rem;
  border: 1px solid #FED7D7;
}

.error-message.show {
  display: block;
  animation: shake 0.4s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

/* ==================== SETTINGS SECTION ==================== */
.settings-section {
  margin: 1rem 0;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-secondary);
}

.settings-header {
  padding: 0.875rem 1rem;
  background: var(--bg-tertiary);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  color: var(--text-primary);
  user-select: none;
}

.settings-header:hover {
  background: var(--bg-hover);
}

.settings-arrow {
  transition: transform 0.3s ease;
  font-size: 0.8rem;
}

.settings-arrow.open {
  transform: rotate(-180deg);
}

.settings-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.settings-content.open {
  max-height: 300px;
  overflow-y: auto;
}

.setting-item {
  padding: 1rem;
  border-top: 1px solid var(--border-color);
}

.setting-label {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
  font-weight: 500;
  color: var(--text-primary);
}

.setting-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.setting-description {
  margin: 0.5rem 0 0 2rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.setting-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.95rem;
  color: var(--text-primary);
}

.setting-info-label {
  font-weight: 600;
}

.setting-info-value {
  color: var(--primary);
  font-weight: 600;
}

/* ==================== CHATBOT MODE TOGGLE ==================== */
.chatbot-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.bot-mode-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  user-select: none;
}

.bot-mode-toggle input[type="checkbox"] {
  position: relative;
  width: 44px;
  height: 24px;
  appearance: none;
  background: var(--border-color);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.bot-mode-toggle input[type="checkbox"]:checked {
  background: #4CAF50;
}

.bot-mode-toggle input[type="checkbox"]::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: white;
  top: 3px;
  left: 3px;
  transition: all 0.3s ease;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.bot-mode-toggle input[type="checkbox"]:checked::before {
  left: 23px;
}

.toggle-label {
  font-size: 0.85rem;
  font-weight: 600;
  min-width: 60px;
}

/* ==================== CHATBOT FEATURES BAR ==================== */
.chatbot-features {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  flex-wrap: wrap;
  justify-content: center;
}

.feature-btn {
  width: 44px;
  height: 44px;
  border: 2px solid var(--border-color);
  background: var(--bg-primary);
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.feature-btn:hover {
  background: var(--primary);
  border-color: var(--primary);
  transform: scale(1.1);
}

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

/* ==================== CHAT SCREEN ==================== */
#chat-screen {
  display: none;
  padding: 0;
  width: 100vw;
  max-width: 100%;
}

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

/* Top Bar */
.top-bar {
  background: var(--bg-primary);
  padding: 0.875rem 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 100;
}

.room-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.room-name {
  font-weight: 700;
  color: var(--text-primary);
  font-size: 1.1rem;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lock-badge {
  font-size: 1rem;
  opacity: 0.7;
}

.top-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 8px;
  background: var(--bg-secondary);
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  color: var(--text-primary);
}

.icon-btn:hover {
  background: var(--bg-tertiary);
  transform: scale(1.05);
}

.icon-btn.leave {
  background: #FFF5F5;
  color: var(--danger);
}

.icon-btn.leave:hover {
  background: #FED7D7;
}

/* Main Content */
.main-content {
  height: calc(100vh - 56px);
  height: calc(100dvh - 56px);
  display: flex;
  background: var(--bg-secondary);
  position: relative;
}

/* Users Panel */
.users-panel {
  width: 240px;
  background: var(--bg-primary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  transition: var(--transition);
  position: relative;
  z-index: 50;
}

.users-panel.hidden {
  transform: translateX(-100%);
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
}

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

.panel-header h3 {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.user-count {
  background: var(--primary);
  color: var(--white);
  padding: 0.25rem 0.5rem;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 700;
}

.users-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
}

.user-item {
  padding: 0.75rem 1rem;
  background: var(--bg-secondary);
  border-radius: 8px;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
  color: var(--text-primary);
  font-weight: 500;
  border-left: 3px solid var(--primary);
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  justify-content: space-between;
  position: relative;
}

.user-item:hover {
  background: var(--bg-tertiary);
  transform: translateX(2px);
}

/* Moderation Actions */
.mod-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.2s;
}

.user-item:hover .mod-actions {
  opacity: 1;
}

.mod-btn {
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: background 0.2s;
}

.mod-btn:hover {
  background: rgba(0, 0, 0, 0.1);
}

.kick-btn:hover {
  background: #fff3cd;
}

.ban-btn:hover {
  background: #f8d7da;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.status-online {
  background: #28A745;
}

.status-away {
  background: #FFC107;
}

.status-busy {
  background: #DC3545;
}

/* Chat Windows Container */
.chat-windows {
  flex: 1;
  display: flex;
  gap: 1rem;
  padding: 1rem;
  overflow: hidden;
}

.chat-window {
  flex: 1;
  background: var(--bg-primary);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-width: 0;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.window-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-secondary);
  border-radius: var(--border-radius) var(--border-radius) 0 0;
  gap: 1rem;
  flex-wrap: wrap;
}

.window-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  color: var(--text-primary);
  font-size: 0.95rem;
}

/* Search Container */
.search-container {
  position: relative;
  flex: 1;
  max-width: 300px;
  display: flex;
  align-items: center;
}

.search-input {
  width: 100%;
  padding: 0.5rem 2rem 0.5rem 0.75rem;
  border: 2px solid var(--border-color);
  border-radius: 20px;
  font-size: 0.85rem;
  background: var(--bg-primary);
  color: var(--text-primary);
  transition: var(--transition);
}

.search-input:focus {
  outline: none;
  border-color: var(--primary);
}

.search-input::placeholder {
  color: var(--light-gray);
}

.clear-search-btn {
  position: absolute;
  right: 0.5rem;
  width: 20px;
  height: 20px;
  border: none;
  background: var(--light-gray);
  color: white;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.7rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.clear-search-btn:hover {
  background: var(--gray);
}

.window-icon {
  font-size: 1.25rem;
}

.close-window-btn {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 6px;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 1rem;
}

.close-window-btn:hover {
  background: var(--bg-tertiary);
  color: var(--danger);
}

/* Messages Area */
.messages-area {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  background: var(--bg-secondary);
  /* Better mobile scrolling */
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
}

.messages-area::-webkit-scrollbar {
  width: 8px;
}

.messages-area::-webkit-scrollbar-track {
  background: transparent;
}

.messages-area::-webkit-scrollbar-thumb {
  background: var(--light-gray);
  border-radius: 4px;
}

.messages-area::-webkit-scrollbar-thumb:hover {
  background: var(--gray);
}

/* Message Wrapper - contains message + actions + reactions */
.message-wrapper {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  max-width: 85%;
  flex-wrap: wrap;
  position: relative;
}

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

.message-wrapper:not(.own-message-wrapper) {
  align-self: flex-start;
}

/* Message Styles */
.message {
  padding: 0.5rem 0.75rem;
  background: var(--bg-secondary);
  border-radius: 16px 16px 16px 4px;
  animation: messageSlide 0.3s ease;
  position: relative;
  box-shadow: var(--shadow-sm);
  word-wrap: break-word;
  overflow-wrap: break-word;
  flex-shrink: 1;
  min-width: 0;
}

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

.message.own-message {
  background: var(--primary);
  color: white;
  border-radius: 18px 18px 4px 18px;
}

.message.own-message:hover {
  opacity: 0.95;
}

.message.own-message .message-nickname {
  color: rgba(255, 255, 255, 0.9);
}

.message.own-message .message-time {
  color: rgba(255, 255, 255, 0.7);
}

.message.own-message .message-text {
  color: white;
}

.message.mentioned {
  background: #FFF3CD;
  border-left: 3px solid #FFC107;
}

[data-theme="dark"] .message.mentioned {
  background: #4A4A2A;
  border-left: 3px solid #FFC107;
}

.mention {
  background: #FFC107;
  color: var(--dark);
  padding: 0 0.25rem;
  border-radius: 3px;
  font-weight: 600;
}

/* Message Reply */
.message-reply-context {
  background: rgba(0, 0, 0, 0.05);
  border-left: 3px solid var(--primary);
  padding: 0.4rem 0.6rem;
  margin-bottom: 0.4rem;
  border-radius: 4px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: var(--transition);
}

.message-reply-context:hover {
  background: rgba(0, 0, 0, 0.1);
}

.message.own-message .message-reply-context {
  background: rgba(255, 255, 255, 0.15);
  border-left-color: rgba(255, 255, 255, 0.5);
}

.reply-author {
  font-weight: 600;
  color: var(--primary);
  margin-right: 0.3rem;
}

.message.own-message .reply-author {
  color: rgba(255, 255, 255, 0.9);
}

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

.message.own-message .reply-text {
  color: rgba(255, 255, 255, 0.7);
}

/* Message Actions */
.message-actions {
  display: flex;
  gap: 0.2rem;
  opacity: 0;
  transition: opacity 0.2s;
  align-items: center;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.message-wrapper:hover .message-actions {
  opacity: 1;
}

.message-action-btn {
  width: 28px;
  height: 28px;
  border: none;
  background: rgba(0, 0, 0, 0.1);
  cursor: pointer;
  border-radius: 4px;
  font-size: 0.8rem;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
}

.message-action-btn:hover {
  background: rgba(0, 0, 0, 0.2);
  transform: scale(1.1);
}

.message.own-message .message-action-btn {
  background: rgba(255, 255, 255, 0.2);
  color: white;
}

.message.own-message .message-action-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* New Messages Divider */
.new-messages-divider {
  display: flex;
  align-items: center;
  margin: 1rem 0;
  gap: 0.5rem;
}

.new-messages-divider::before,
.new-messages-divider::after {
  content: '';
  flex: 1;
  height: 2px;
  background: linear-gradient(to right, transparent, var(--danger), transparent);
}

.new-messages-text {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--danger);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Search Highlight */
.search-highlight {
  background: yellow;
  color: black;
  padding: 0 2px;
  border-radius: 2px;
}

[data-theme="dark"] .search-highlight {
  background: #FFC107;
}

/* Message Links */
.message-link {
  color: var(--primary);
  text-decoration: underline;
  transition: var(--transition);
}

.message-link:hover {
  color: var(--primary-dark);
}

.message.own-message .message-link {
  color: rgba(255, 255, 255, 0.9);
  text-decoration: underline;
}

/* Animations */
@keyframes messageFlash {
  0%, 100% {
    background: var(--bg-secondary);
  }
  50% {
    background: var(--primary);
    transform: scale(1.02);
  }
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.75rem;
  color: white;
  flex-shrink: 0;
  text-transform: uppercase;
}

.message-body {
  flex: 1;
  min-width: 0;
  position: relative;
  padding-right: 1.5rem;
}

.message.own-message .message-body {
  padding-right: 0;
  padding-left: 1.5rem;
}

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

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

.message-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.25rem;
  gap: 0.5rem;
}

.message-nickname {
  font-weight: 600;
  color: var(--primary);
  font-size: 0.8rem;
}

.message.own-message .message-nickname {
  color: rgba(255, 255, 255, 0.9);
}

.message-time {
  font-size: 0.65rem;
  color: var(--light-gray);
  white-space: nowrap;
}

.message-text {
  color: var(--text-primary);
  line-height: 1.4;
  word-wrap: break-word;
  font-size: 0.875rem;
}

.system-message {
  text-align: center;
  padding: 0.5rem 1rem;
  background: var(--bg-tertiary);
  color: var(--primary);
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 500;
  align-self: center;
  max-width: fit-content;
}

/* Input Area */
.input-area {
  padding: 1rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  background: var(--bg-primary);
  border-radius: 0 0 var(--border-radius) var(--border-radius);
}

.input-row {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.input-icons {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}

.mobile-chat-actions {
  display: none;
}

.mobile-chat-action-btn {
  min-height: 44px;
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
  color: var(--text-primary);
  border-radius: 12px;
  padding: 0.75rem 0.5rem;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: var(--transition);
}

.mobile-chat-action-btn:hover {
  background: var(--bg-tertiary);
  border-color: var(--primary);
}

.mobile-chat-action-btn:active {
  transform: scale(0.97);
}

.mobile-overlay-backdrop {
  display: none;
}

.mobile-more-sheet {
  display: none;
}

.mobile-more-sheet-handle {
  width: 42px;
  height: 4px;
  border-radius: 999px;
  background: var(--light-gray);
  margin: 0 auto 0.85rem;
}

.mobile-more-sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.mobile-more-sheet-header h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.mobile-more-sheet-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.mobile-sheet-action-btn {
  min-height: 48px;
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
  color: var(--text-primary);
  border-radius: 14px;
  padding: 0.9rem 0.8rem;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.mobile-sheet-action-btn:hover {
  background: var(--bg-tertiary);
  border-color: var(--primary);
}

.mobile-sheet-action-btn:active {
  transform: scale(0.98);
}

.message-input {
  flex: 1;
  padding: 0.875rem 1rem;
  border: 2px solid var(--border-color);
  border-radius: 20px;
  font-size: 0.9rem;
  transition: var(--transition);
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.message-input:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--bg-primary);
}

.message-input::placeholder {
  color: var(--light-gray);
}

.emoji-btn {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border: 2px solid var(--border-color);
  background: var(--bg-secondary);
  color: var(--text-primary);
  border-radius: 50%;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.emoji-btn:hover {
  background: var(--bg-tertiary);
  border-color: var(--primary);
  transform: scale(1.05);
}

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

.send-btn {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border: none;
  background: var(--primary);
  color: var(--white);
  border-radius: 50%;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  flex-shrink: 0;
}

.send-btn:hover {
  background: var(--primary-dark);
  transform: scale(1.05);
}

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

/* Empty States */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1.5rem;
  text-align: center;
  color: var(--text-secondary);
  height: 100%;
}

.empty-state-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
  opacity: 0.3;
}

.empty-state-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.empty-state-text {
  font-size: 0.9rem;
  line-height: 1.6;
  max-width: 400px;
}

/* Loading Indicator */
.loading-indicator {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg-primary);
  padding: 2rem;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-lg);
  text-align: center;
  z-index: 10000;
}

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

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

.loading-text {
  color: var(--text-primary);
  font-weight: 500;
}

.connection-status {
  position: fixed;
  bottom: calc(1rem + var(--safe-area-bottom));
  right: 1rem;
  padding: 0.5rem 1rem;
  background: var(--bg-primary);
  border-radius: 20px;
  box-shadow: var(--shadow);
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.connection-status.show {
  opacity: 1;
}

.connection-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #28A745;
  animation: pulse 2s infinite;
}

.connection-status.disconnected .connection-dot {
  background: #DC3545;
  animation: none;
}

.connection-status.connecting .connection-dot {
  background: #FFC107;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

/* Floating Action Button */
.fab {
  position: fixed;
  bottom: calc(1.5rem + var(--safe-area-bottom));
  left: 1.5rem;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--secondary);
  color: var(--white);
  border: none;
  font-size: 1.75rem;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  transition: var(--transition);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.fab:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

.fab:active {
  transform: scale(1);
}

.fab.hidden {
  display: none;
}

/* Chat Tabs (Mobile) */
.chat-tabs {
  display: none;
  background: var(--white);
  border-top: 1px solid #E9ECEF;
  padding: 0.5rem 0.5rem calc(0.5rem + var(--safe-area-bottom));
  gap: 0.5rem;
  position: sticky;
  bottom: 0;
  z-index: 100;
}

.chat-tab {
  flex: 1;
  min-height: 44px;
  padding: 0.75rem;
  border: none;
  background: var(--bg-light);
  border-radius: 8px;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  font-size: 1.25rem;
}

.chat-tab .tab-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--gray);
}

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

.chat-tab.active .tab-label {
  color: var(--white);
}

/* Typing Indicator */
.typing-indicator {
  padding: 0.5rem 1rem;
  background: #E9ECEF;
  border-radius: 20px;
  font-size: 0.85rem;
  color: var(--gray);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  max-width: fit-content;
  margin-bottom: 0.75rem;
}

.typing-dots::before {
  content: '●●●';
  animation: typingDots 1.4s infinite;
  letter-spacing: 2px;
}

@keyframes typingDots {
  0%, 20% {
    opacity: 0.2;
  }
  50% {
    opacity: 1;
  }
  100% {
    opacity: 0.2;
  }
}

/* Message Reactions */
.message-reactions {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
  position: relative;
  min-height: 1.8rem;
}

.message.own-message .message-reactions {
  flex-direction: row;
}

.reaction-bar {
  display: flex;
  gap: 0.2rem;
  align-items: center;
  flex-shrink: 0;
}

/* GIF Picker */
.gif-picker-popup {
  position: absolute;
  bottom: calc(100% + 0.5rem);
  right: 90px;
  background: var(--bg-primary);
  border: 2px solid var(--border-color);
  border-radius: 12px;
  padding: 0.75rem;
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  animation: fadeIn 0.2s ease;
  width: 320px;
  max-height: 400px;
  overflow-y: auto;
}

.gif-search-input {
  width: 100%;
  padding: 0.5rem;
  border: 2px solid var(--border-color);
  border-radius: 6px;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.gif-search-input:focus {
  outline: none;
  border-color: var(--primary);
}

.gif-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
}

.gif-item {
  width: 100%;
  height: 120px;
  object-fit: cover;
  border-radius: 6px;
  cursor: pointer;
  transition: var(--transition);
  border: 2px solid transparent;
}

.gif-item:hover {
  transform: scale(1.05);
  border-color: var(--primary);
}

.gif-loading {
  text-align: center;
  padding: 2rem;
  color: var(--text-secondary);
}

/* Mention Autocomplete */
.mention-autocomplete {
  position: absolute;
  bottom: calc(100% + 0.5rem);
  left: 0;
  background: var(--bg-primary);
  border: 2px solid var(--border-color);
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  max-height: 200px;
  overflow-y: auto;
  z-index: 1000;
  animation: fadeIn 0.2s ease;
  min-width: 180px;
}

.mention-item {
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-primary);
}

.mention-item:hover,
.mention-item.selected {
  background: var(--bg-tertiary);
}

.mention-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 600;
  color: white;
}

/* User Presence */
.user-presence {
  font-size: 0.7rem;
  color: var(--light-gray);
  font-style: italic;
}

.user-idle {
  opacity: 0.6;
}

.user-last-seen {
  position: absolute;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  font-size: 0.7rem;
  box-shadow: var(--shadow);
  z-index: 1000;
  white-space: nowrap;
}

/* RTL Support */
[dir="rtl"] {
  direction: rtl;
}

[dir="rtl"] .message {
  text-align: right;
}

[dir="rtl"] .message.own-message {
  flex-direction: row;
}

[dir="rtl"] .message:not(.own-message) {
  flex-direction: row-reverse;
}

[dir="rtl"] .message-reactions {
  flex-direction: row-reverse;
}

[dir="rtl"] .message.own-message .message-reactions {
  flex-direction: row-reverse;
}

[dir="rtl"] .users-panel {
  border-right: none;
  border-left: 1px solid var(--border-color);
}

[dir="rtl"] .message-reply-context {
  border-left: none;
  border-right: 3px solid var(--primary);
}

[dir="rtl"] .input-area {
  flex-direction: row-reverse;
}

.add-reaction-btn {
  min-width: 26px;
  height: 26px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  background: rgba(255, 255, 255, 0.72);
  cursor: pointer;
  border-radius: 999px;
  font-size: 0.82rem;
  line-height: 1;
  transition: var(--transition);
  opacity: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.08);
  backdrop-filter: blur(8px);
}

.message-wrapper:hover .add-reaction-btn {
  opacity: 0.95;
}

.add-reaction-btn:hover {
  background: rgba(255, 255, 255, 0.96);
  opacity: 1;
  transform: translateY(-1px) scale(1.04);
}

.reaction-picker {
  position: absolute;
  bottom: calc(100% + 0.35rem);
  left: 0;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 14px;
  padding: 0.35rem;
  box-shadow: 0 14px 32px rgba(15, 23, 42, 0.16);
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.2rem;
  z-index: 1000;
  animation: fadeIn 0.2s ease;
  width: min(184px, calc(100vw - 2rem));
  backdrop-filter: blur(10px);
}

/* Fallback for messages at top */
.message.own-message .reaction-picker {
  left: auto;
  right: 0;
}

.reaction-picker-btn {
  width: 100%;
  aspect-ratio: 1;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 10px;
  font-size: 1.05rem;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.reaction-picker-btn:hover {
  background: rgba(37, 99, 235, 0.1);
  transform: scale(1.08);
}

/* Emoji Picker Popup */
.emoji-picker-popup {
  position: absolute;
  bottom: calc(100% + 0.5rem);
  right: 50px;
  background: var(--bg-primary);
  border: 2px solid var(--border-color);
  border-radius: 12px;
  padding: 0.75rem;
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  animation: fadeIn 0.2s ease;
  max-width: 280px;
  width: min(280px, calc(100vw - 2rem));
}

.emoji-picker-popup .emoji-category {
  margin-bottom: 0.5rem;
}

.emoji-picker-popup .emoji-category-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
  text-transform: uppercase;
}

.emoji-picker-popup .emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 0.25rem;
}

.emoji-picker-popup .emoji-btn-item {
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 6px;
  font-size: 1.25rem;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.emoji-picker-popup .emoji-btn-item:hover {
  background: var(--bg-tertiary);
  transform: scale(1.15);
}

/* ============================
   New Optimizations CSS
   ============================ */

/* Toast Notifications (optimization #7) */
.toast {
  position: fixed;
  bottom: calc(-100px - var(--safe-area-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-primary);
  color: var(--text-primary);
  padding: 1rem 1.5rem;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-lg);
  z-index: 10000;
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border: 2px solid var(--border-color);
  font-weight: 500;
  min-width: 200px;
  text-align: center;
}

.toast.show {
  bottom: 2rem;
  opacity: 1;
}

.toast.toast-success {
  background: var(--secondary);
  color: white;
  border-color: var(--secondary);
}

.toast.toast-error {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
}

.toast.toast-info {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* Message Status Icons (optimization #21) */
.message-status {
  display: inline-flex;
  align-items: center;
  margin-left: 0.5rem;
  font-size: 0.75rem;
}

.status-icon {
  opacity: 0.7;
}

.status-sending {
  color: var(--gray);
  animation: pulse 1.5s ease-in-out infinite;
}

.status-sent {
  color: var(--secondary);
}

.status-delivered {
  color: var(--primary);
}

.status-error {
  color: var(--danger);
  cursor: pointer;
}

@keyframes pulse {
  0%, 100% {
    opacity: 0.7;
  }
  50% {
    opacity: 0.3;
  }
}

/* Smooth Message Transitions (optimization #22) */
.message {
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.message:hover {
  transform: translateX(2px);
}

.own-message:hover {
  transform: translateX(-2px);
}

/* Loading Skeleton (optimization #20) */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-tertiary) 25%,
    var(--border-color) 50%,
    var(--bg-tertiary) 75%
  );
  background-size: 200% 100%;
  animation: loading 1.5s ease-in-out infinite;
  border-radius: var(--border-radius);
}

@keyframes loading {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.skeleton-message {
  padding: 1rem;
  margin-bottom: 0.75rem;
}

.skeleton-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  margin-right: 0.75rem;
}

.skeleton-text {
  height: 1rem;
  margin-bottom: 0.5rem;
  width: 70%;
}

.skeleton-text-short {
  width: 40%;
}

/* Improved Empty State (optimization #23) */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1.5rem;
  text-align: center;
  min-height: 300px;
  animation: fadeIn 0.5s ease;
}

.empty-state-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
  opacity: 0.5;
  animation: bounce 2s ease-in-out infinite;
}

.empty-state-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.empty-state-text {
  font-size: 0.9rem;
  color: var(--text-secondary);
  max-width: 300px;
}

@keyframes bounce {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-10px);
  }
}

/* Copy Button Animation */
.message-action-btn {
  transition: all 0.2s ease;
}

/* ==========================
   Authentication UI Styles
   ========================== */

.auth-status {
  margin-bottom: 25px;
  padding: 15px;
  background: #f8f9fa;
  border-radius: 8px;
}

.auth-guest {
  text-align: center;
}

.auth-message {
  margin: 0;
  color: #666;
  font-size: 14px;
}

.auth-message a {
  color: var(--primary-color);
  text-decoration: none;
  font-weight: 500;
}

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

.auth-user {
  display: block;
}

.auth-user.hidden {
  display: none;
}

.user-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 15px;
}

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

.user-icon {
  font-size: 32px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: white;
  border-radius: 50%;
}

.user-name-line {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 2px;
}

.user-name {
  font-weight: 600;
  color: #333;
  font-size: 15px;
}

.user-email {
  font-size: 12px;
  color: #666;
}

.premium-badge {
  display: inline-block;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}

.premium-badge.hidden {
  display: none;
}

.user-actions {
  display: flex;
  gap: 10px;
}

.btn-link {
  background: none;
  border: none;
  color: var(--primary-color);
  cursor: pointer;
  font-size: 13px;
  text-decoration: none;
  padding: 5px 10px;
  border-radius: 4px;
  transition: background 0.2s;
}

.btn-link:hover {
  background: rgba(0, 102, 204, 0.1);
}

.input-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 14px;
  color: #666;
}

.nickname-hint {
  font-size: 12px;
  color: #0066cc;
  font-weight: 500;
}

.nickname-hint.hidden {
  display: none;
}

/* Premium Badge in User List */
.user-item {
  position: relative;
}

.user-item.premium::after {
  content: '⭐';
  margin-left: 4px;
  font-size: 10px;
}

/* Room Owner Badge */
.room-info .owner-badge {
  display: inline-block;
  background: #ffd700;
  color: #333;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  margin-left: 8px;
  font-weight: 600;
}

/* Claimed Room Indicator */
.room-info .claimed-badge {
  display: inline-block;
  background: #4CAF50;
  color: white;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  margin-left: 8px;
  font-weight: 600;
}

/* ===========================
   VOICE & VIDEO RECORDING
   =========================== */

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

.recording-modal.hidden {
  display: none;
}

.recording-modal-content {
  background: white;
  border-radius: 16px;
  padding: 32px;
  max-width: 400px;
  width: 90%;
  max-height: min(640px, calc(100dvh - 2rem - var(--safe-area-top) - var(--safe-area-bottom)));
  overflow-y: auto;
  text-align: center;
  animation: slideUp 0.3s ease;
}

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

.recording-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 24px;
}

.recording-icon {
  font-size: 32px;
}

.recording-header h3 {
  margin: 0;
  font-size: 24px;
  color: #333;
}

.recording-body {
  padding: 20px 0;
}

.recording-animation {
  position: relative;
  width: 120px;
  height: 120px;
  margin: 0 auto 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.recording-pulse {
  width: 60px;
  height: 60px;
  background: #f44336;
  border-radius: 50%;
  z-index: 2;
  animation: pulse 1.5s ease-in-out infinite;
}

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

.recording-pulse-ring {
  position: absolute;
  width: 120px;
  height: 120px;
  border: 3px solid #f44336;
  border-radius: 50%;
  animation: pulseRing 1.5s ease-out infinite;
}

@keyframes pulseRing {
  0% {
    transform: scale(0.5);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 0;
  }
}

.recording-timer {
  font-size: 48px;
  font-weight: 700;
  color: #f44336;
  margin-bottom: 8px;
  font-family: 'Courier New', monospace;
}

.recording-limit {
  font-size: 14px;
  color: #666;
  margin-bottom: 24px;
}

.recording-controls {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.btn-danger {
  background: #f44336;
  color: white;
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-danger:hover {
  background: #d32f2f;
}

.btn-secondary {
  background: #757575;
  color: white;
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  width: 100%;
}

.btn-secondary:hover {
  background: #616161;
}

/* Voice Message Display */
.voice-message {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: #e3f2fd;
  border-radius: 12px;
  max-width: 400px;
}

.voice-icon {
  font-size: 24px;
}

.voice-message audio {
  flex: 1;
  height: 32px;
  min-width: 200px;
}

.voice-duration {
  font-size: 12px;
  color: #666;
  font-weight: 600;
}

/* Video Message Display */
.video-message {
  margin: 8px 0;
}

.video-message video {
  display: block;
  border-radius: 12px;
  background: #000;
}

/* Premium Feature Buttons */
.emoji-btn.premium-feature {
  position: relative;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.emoji-btn.premium-feature:hover {
  background: linear-gradient(135deg, #5568d3 0%, #633a8f 100%);
  transform: scale(1.05);
}

.emoji-btn.premium-feature::after {
  content: '⭐';
  position: absolute;
  top: -2px;
  right: -2px;
  font-size: 10px;
}

/* Disable buttons for non-premium users */
.emoji-btn.premium-feature:disabled {
  background: #ccc;
  cursor: not-allowed;
  opacity: 0.6;
}

.emoji-btn.premium-feature:disabled:hover {
  transform: none;
}

/* Mobile Optimizations for Media */
@media (max-width: 768px) {
  .recording-modal-content {
    padding: 24px;
  }
  
  .recording-timer {
    font-size: 40px;
  }
  
  .recording-animation {
    width: 100px;
    height: 100px;
  }
  
  .recording-pulse {
    width: 50px;
    height: 50px;
  }
  
  .recording-pulse-ring {
    width: 100px;
    height: 100px;
  }
  
  .voice-message {
    max-width: 100%;
  }
  
  .voice-message audio {
    min-width: 150px;
  }
  
  .video-message video {
    max-width: 100%;
    height: auto;
  }
  
  .recording-controls {
    flex-direction: column;
  }
  
  .btn-danger, .btn-secondary {
    width: 100%;
  }
}
.room-info .claimed-badge {
  display: inline-block;
  background: #4CAF50;
  color: white;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  margin-left: 8px;
  font-weight: 600;
}

/* Mobile Responsive */
@media (max-width: 768px) {
  .user-card {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .user-actions {
    width: 100%;
    justify-content: flex-end;
  }
  
  .auth-status {
    padding: 12px;
  }
}

}

.message-action-btn:active {
  transform: scale(0.9);
}

/* Better focus states for accessibility */
button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Mobile optimizations */
@media (max-width: 768px) {
  .toast {
    min-width: 80%;
    max-width: 90%;
  }
  
  .empty-state {
    padding: 2rem 1rem;
    min-height: 200px;
  }
  
  .empty-state-icon {
    font-size: 3rem;
  }
}

.reactions-display {
  display: flex;
  flex-wrap: wrap;
  gap: 0.28rem;
}

.reaction-bubble {
  display: inline-flex;
  align-items: center;
  gap: 0.22rem;
  padding: 0.12rem 0.42rem;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 999px;
  font-size: 0.72rem;
  cursor: pointer;
  transition: var(--transition);
  line-height: 1;
}

.reaction-bubble:hover {
  background: rgba(37, 99, 235, 0.08);
  transform: translateY(-1px);
}

.reaction-bubble.user-reacted {
  background: rgba(37, 99, 235, 0.14);
  border-color: rgba(37, 99, 235, 0.35);
}

.reaction-count {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--gray);
}

/* Unread Badge */
.unread-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background: var(--danger);
  color: var(--white);
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.15rem 0.4rem;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

/* ==================== RESPONSIVE DESIGN ==================== */
@media (max-width: 1024px) {
  .chat-windows {
    flex-direction: column;
  }
  
  .chat-window {
    display: none;
  }
  
  .chat-window.active {
    display: flex;
  }
  
  .chat-tabs {
    display: flex;
  }
  
  .fab {
    display: none;
  }
}

@media (max-width: 768px) {
  #chat-screen.active {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }

  .top-bar {
    padding: calc(0.75rem + var(--safe-area-top)) calc(0.85rem + var(--safe-area-right)) 0.75rem calc(0.85rem + var(--safe-area-left));
    gap: 0.75rem;
  }

  .room-info {
    flex: 1;
    gap: 0.5rem;
  }

  .lock-badge,
  .room-contact-link,
  .room-info .owner-badge,
  .room-info .claimed-badge,
  #theme-toggle-btn,
  #sound-toggle-btn,
  #toggle-users-btn,
  #clear-history-btn,
  #download-btn,
  #chatbot-fab,
  .window-header,
  .chat-tabs,
  .fab,
  #chatbot-window {
    display: none !important;
  }

  .top-actions {
    gap: 0.35rem;
    flex-wrap: nowrap;
  }

  #toggle-lock-btn,
  #leave-btn {
    width: 42px;
    height: 42px;
    min-width: 42px;
  }
  
  .room-name {
    font-size: 1rem;
  }

  .main-content {
    flex: 1;
    height: auto;
    min-height: 0;
    overflow: hidden;
  }

  .users-panel {
    position: fixed;
    left: 0.75rem;
    right: 0.75rem;
    bottom: calc(0.75rem + var(--safe-area-bottom));
    top: auto;
    width: auto;
    height: auto;
    max-height: min(60vh, calc(100dvh - 8rem - var(--safe-area-top)));
    border-right: none;
    border: 1px solid var(--border-color);
    border-radius: 18px;
    box-shadow: var(--shadow-lg);
    transform: translateY(calc(100% + 2rem));
    z-index: 320;
  }

  .users-panel.hidden {
    transform: translateY(calc(100% + 2rem));
    left: 0.75rem;
    top: auto;
    height: auto;
  }

  .users-panel.active {
    transform: translateY(0);
  }

  .mobile-overlay-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 300;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }

  .mobile-overlay-backdrop.active {
    display: block;
    opacity: 1;
    pointer-events: auto;
  }
  
  .chat-windows {
    flex: 1;
    min-height: 0;
    padding: 0;
    gap: 0;
    overflow: hidden;
  }

  .chat-window {
    flex: 1;
    min-height: 0;
    border-radius: 0;
    box-shadow: none;
    background: var(--bg-secondary);
    overflow: hidden;
  }

  #room-window {
    display: flex;
  }
  
  .message {
    max-width: 95%;
    padding: 0.4rem 0.6rem;
    font-size: 0.95rem;
  }
  
  .message-avatar {
    width: 28px;
    height: 28px;
    font-size: 0.7rem;
  }
  
  .message-nickname {
    font-size: 0.85rem;
  }
  
  .message-time {
    font-size: 0.75rem;
  }
  
  .message-text {
    font-size: 0.95rem;
  }
  
  .message-actions,
  .message-reactions,
  .reaction-picker,
  .reactions-display,
  .reaction-bar,
  .message-action-btn,
  .add-reaction-btn {
    display: none !important;
  }
  
  .emoji-picker-popup {
    max-width: 240px;
    padding: 0.5rem;
  }
  
  .input-area {
    gap: 0.5rem;
    padding: 0.65rem calc(0.75rem + var(--safe-area-right)) calc(0.75rem + var(--safe-area-bottom)) calc(0.75rem + var(--safe-area-left));
    border-top: 1px solid var(--border-color);
    background: var(--bg-primary);
    border-radius: 0;
    position: sticky;
    bottom: 0;
    z-index: 25;
    box-shadow: 0 -10px 24px rgba(15, 23, 42, 0.08);
  }

  .input-row {
    gap: 0.5rem;
    align-items: stretch;
  }

  .input-icons {
    display: none;
  }

  .mobile-chat-actions {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.5rem;
  }

  .message-input {
    min-height: 52px;
    border-radius: 14px;
  }

  .send-btn {
    width: auto;
    min-width: 72px;
    border-radius: 14px;
    padding: 0 1rem;
    font-size: 0.95rem;
    font-weight: 700;
  }

  .mobile-more-sheet {
    position: fixed;
    left: 0.75rem;
    right: 0.75rem;
    bottom: calc(0.75rem + var(--safe-area-bottom));
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
    padding: 0.85rem 0.85rem 1rem;
    z-index: 340;
    transform: translateY(calc(100% + 2rem));
    transition: transform 0.22s ease;
  }

  .mobile-more-sheet.active {
    display: block;
    transform: translateY(0);
  }
  
  .emoji-picker-popup .emoji-grid {
    grid-template-columns: repeat(6, 1fr);
  }
  
  .emoji-picker-popup .emoji-btn-item {
    width: 36px;
    height: 36px;
    font-size: 1.1rem;
  }

  .reaction-picker {
    gap: 0.35rem;
    padding: 0.5rem;
  }
  
  .fab {
    bottom: 5rem;
    left: 1rem;
    width: 50px;
    height: 50px;
    font-size: 1.5rem;
  }
}

@media (max-width: 480px) {
  .join-box {
    padding: 2rem 1.5rem;
  }
  
  .logo {
    font-size: 3rem;
  }
  
  .join-box h1 {
    font-size: 1.75rem;
  }
  
  .top-bar {
    padding-left: calc(0.7rem + var(--safe-area-left));
    padding-right: calc(0.7rem + var(--safe-area-right));
  }

  .top-actions {
    gap: 0.25rem;
  }

  .main-content {
    min-height: 0;
  }
  
  .messages-area {
    flex: 1;
    padding: 0.75rem 0.75rem 0.5rem;
    min-height: 0;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: auto;
    touch-action: pan-y;
  }
  
  .message-wrapper {
    max-width: 95%;
    gap: 0.35rem;
    align-items: stretch;
  }

  .message-body {
    padding-right: 0.5rem;
  }

  .message.own-message .message-body {
    padding-left: 0.5rem;
  }

  .emoji-picker-popup {
    position: fixed;
    left: 0.75rem;
    right: 0.75rem;
    bottom: calc(5.75rem + var(--safe-area-bottom));
    width: auto;
    max-width: none;
    margin-bottom: 0;
  }

  .emoji-picker-popup {
    padding: 0.75rem;
    max-height: min(280px, calc(100dvh - 8rem - var(--safe-area-bottom)));
    overflow-y: auto;
  }

  .emoji-picker-popup .emoji-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .emoji-picker-popup .emoji-btn-item {
    width: 100%;
    min-height: 40px;
    height: 40px;
  }
  
  .input-area {
    padding-top: 0.5rem;
  }
  
  .message-input {
    font-size: 16px; /* Prevents zoom on iOS */
    padding: 0.75rem 0.875rem;
    min-width: 0; /* Allow input to shrink */
  }
  
  .mobile-chat-actions {
    gap: 0.4rem;
  }

  .mobile-chat-action-btn {
    padding: 0.8rem 0.25rem;
    font-size: 0.72rem;
  }

  .send-btn {
    min-width: 58px;
    padding: 0 0.9rem;
  }
  
  .fab {
    bottom: calc(5.5rem + var(--safe-area-bottom));
    left: 1rem;
  }

  .recording-modal {
    align-items: flex-end;
    padding: 0.75rem;
  }

  .recording-modal-content {
    width: 100%;
    border-radius: 18px 18px 12px 12px;
    padding: 1.25rem 1rem calc(1.25rem + var(--safe-area-bottom));
    max-height: min(560px, calc(100dvh - 1.5rem - var(--safe-area-top)));
  }

  .mobile-more-sheet-actions {
    grid-template-columns: 1fr;
  }

  .recording-header h3 {
    font-size: 1.25rem;
  }

  .recording-animation {
    width: 88px;
    height: 88px;
    margin-bottom: 1rem;
  }

  .recording-pulse-ring {
    width: 88px;
    height: 88px;
  }

  .recording-controls {
    flex-direction: column;
  }

  .recording-controls .btn-danger,
  .recording-controls .btn-secondary {
    width: 100%;
    min-height: 48px;
  }

  #join-footer {
    font-size: 0.8125rem;
    padding-left: calc(0.75rem + var(--safe-area-left));
    padding-right: calc(0.75rem + var(--safe-area-right));
  }
}
