/* Custom variables for colors and sizes */
:root {
  --bg-color: #080b11;
  --panel-bg: rgba(18, 24, 38, 0.65);
  --panel-border: rgba(255, 255, 255, 0.06);
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --primary-color: #6366f1;
  --primary-glow: rgba(99, 102, 241, 0.15);
  --accent-color: #10b981;
  --accent-glow: rgba(16, 185, 129, 0.15);
  --danger-color: #ef4444;
  --danger-glow: rgba(239, 68, 68, 0.15);
  --msg-self-bg: rgba(99, 102, 241, 0.2);
  --msg-other-bg: rgba(255, 255, 255, 0.04);
  --border-radius: 16px;
  --font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  --sidebar-width: 280px;
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-color);
  color: var(--text-primary);
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  position: relative;
}

/* Ambient glow background blobs */
.bg-glow {
  position: absolute;
  width: 500px;
  height: 500px;
  border-radius: 50%;
  filter: blur(120px);
  z-index: -1;
  opacity: 0.4;
  pointer-events: none;
}

.bg-glow-1 {
  background: radial-gradient(circle, var(--primary-color) 0%, transparent 70%);
  top: -10%;
  left: -10%;
  animation: float 20s ease-in-out infinite alternate;
}

.bg-glow-2 {
  background: radial-gradient(circle, #ec4899 0%, transparent 70%);
  bottom: -10%;
  right: -10%;
  animation: float 20s ease-in-out infinite alternate-reverse;
}

@keyframes float {
  0% { transform: translate(0, 0) scale(1); }
  100% { transform: translate(50px, 30px) scale(1.1); }
}

/* Common Card/Panel Glassmorphism */
.card {
  background: var(--panel-bg);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--panel-border);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* Join Container */
#join-container {
  width: 100%;
  max-width: 480px;
  padding: 2.5rem;
  margin: 1.5rem;
}

.card-header {
  text-align: center;
  margin-bottom: 2.5rem;
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.logo-icon {
  color: var(--primary-color);
  filter: drop-shadow(0 0 8px var(--primary-glow));
}

.logo h1, .logo h2 {
  font-size: 1.8rem;
  font-weight: 700;
  background: linear-gradient(135deg, #fff 0%, var(--text-secondary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.5px;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.5;
}

/* Form Styles */
.form-group {
  margin-bottom: 1.5rem;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

input[type="text"] {
  width: 100%;
  padding: 0.875rem 1.25rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: 1rem;
  transition: all 0.3s ease;
  outline: none;
}

input[type="text"]:focus {
  border-color: var(--primary-color);
  background: rgba(255, 255, 255, 0.06);
  box-shadow: 0 0 0 4px var(--primary-glow);
}

.input-with-button {
  display: flex;
  gap: 0.5rem;
}

.input-with-button input {
  flex-grow: 1;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.875rem 1.5rem;
  font-family: var(--font-family);
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  outline: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary-color) 0%, #4f46e5 100%);
  color: #fff;
  box-shadow: 0 4px 14px 0 var(--primary-glow);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px 0 rgba(99, 102, 241, 0.3);
}

.btn-danger {
  background: linear-gradient(135deg, var(--danger-color) 0%, #dc2626 100%);
  color: #fff;
  box-shadow: 0 4px 14px 0 var(--danger-glow);
}

.btn-danger:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px 0 rgba(239, 68, 68, 0.3);
}

.btn-block {
  width: 100%;
}

#randomize-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  color: var(--text-secondary);
  padding: 0 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}

#randomize-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
  border-color: var(--primary-color);
}

/* Chat Layout */
.chat-app {
  width: 90vw;
  max-width: 1100px;
  height: 85vh;
  display: flex;
}

/* Sidebar */
.chat-sidebar {
  width: var(--sidebar-width);
  border-right: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  background: rgba(10, 15, 28, 0.4);
}

.sidebar-header {
  padding: 1.5rem;
  border-bottom: 1px solid var(--panel-border);
}

.sidebar-header .logo h2 {
  font-size: 1.3rem;
}

.sidebar-section {
  padding: 1.5rem;
  border-bottom: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.sidebar-section.flex-grow {
  flex-grow: 1;
  overflow-y: auto;
}

.section-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-secondary);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.badge {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  padding: 0.15rem 0.5rem;
  border-radius: 20px;
  font-size: 0.7rem;
}

.room-badge-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
}

.room-badge {
  font-weight: 600;
  color: var(--primary-color);
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s ease;
}

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

/* User List */
.users-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.users-list li {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem;
  border-radius: 8px;
  font-size: 0.9rem;
  color: var(--text-primary);
  transition: background-color 0.2s ease;
}

.users-list li:hover {
  background-color: rgba(255, 255, 255, 0.03);
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #a78bfa 0%, var(--primary-color) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.75rem;
  color: #fff;
}

.sidebar-footer {
  padding: 1.5rem;
}

/* Main Chat Pane */
.chat-main {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  background: rgba(12, 17, 30, 0.25);
  position: relative;
}

/* Chat Header */
.chat-header {
  padding: 1.5rem;
  border-bottom: 1px solid var(--panel-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-header-info h3 {
  font-size: 1.15rem;
  font-weight: 600;
}

.chat-header-info .subtitle {
  font-size: 0.8rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(16, 185, 129, 0.08);
  border: 1px solid rgba(16, 185, 129, 0.15);
  padding: 0.35rem 0.75rem;
  border-radius: 20px;
}

.status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--accent-color);
  box-shadow: 0 0 8px var(--accent-color);
}

.status-text {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent-color);
}

/* Message Feed */
.chat-messages {
  flex-grow: 1;
  padding: 1.5rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  scroll-behavior: smooth;
}

/* Custom Scrollbar for messages and sidebar */
.chat-messages::-webkit-scrollbar,
.sidebar-section.flex-grow::-webkit-scrollbar {
  width: 6px;
}

.chat-messages::-webkit-scrollbar-track,
.sidebar-section.flex-grow::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb,
.sidebar-section.flex-grow::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 20px;
}

.chat-messages::-webkit-scrollbar-thumb:hover,
.sidebar-section.flex-grow::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* Message Bubble */
.message {
  display: flex;
  flex-direction: column;
  max-width: 75%;
  animation: messageSlideIn 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

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

.message-self {
  align-self: flex-end;
}

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

.message-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
  padding: 0 0.25rem;
}

.message-info .msg-user {
  font-size: 0.8rem;
  font-weight: 600;
}

.message-info .msg-time {
  font-size: 0.7rem;
  color: var(--text-secondary);
}

.message-text {
  padding: 0.8rem 1.1rem;
  border-radius: 16px;
  line-height: 1.5;
  font-size: 0.95rem;
  word-break: break-word;
}

.message-self .message-text {
  background: var(--msg-self-bg);
  border: 1px solid rgba(99, 102, 241, 0.15);
  border-bottom-right-radius: 4px;
  color: #fff;
}

.message-other .message-text {
  background: var(--msg-other-bg);
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-bottom-left-radius: 4px;
}

/* System Message styling */
.message-system {
  align-self: center;
  max-width: 90%;
  animation: fadeIn 0.4s ease;
}

.message-system .message-text {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.04);
  color: var(--text-secondary);
  font-size: 0.8rem;
  padding: 0.4rem 1rem;
  border-radius: 30px;
  text-align: center;
}

/* Reactions Bar */
.reactions-bar {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem 1.5rem;
  border-top: 1px solid rgba(255, 255, 255, 0.03);
  background: rgba(255, 255, 255, 0.01);
}

.reaction-pill {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 20px;
  padding: 0.25rem 0.6rem;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.reaction-pill:hover {
  background: rgba(99, 102, 241, 0.15);
  border-color: var(--primary-color);
  transform: scale(1.1);
}

.reaction-pill:active {
  transform: scale(0.95);
}

/* Typing Indicator */
.typing-indicator {
  padding: 0.5rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

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

.dots span {
  width: 6px;
  height: 6px;
  background-color: var(--text-secondary);
  border-radius: 50%;
  animation: bounce 1.3s infinite ease-in-out;
}

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

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

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

/* Message Input Form */
.chat-form {
  padding: 1.25rem 1.5rem 1.5rem;
  border-top: 1px solid var(--panel-border);
}

.input-container {
  display: flex;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  overflow: hidden;
  padding: 0.25rem;
  transition: all 0.3s ease;
}

.input-container:focus-within {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 4px var(--primary-glow);
  background: rgba(255, 255, 255, 0.05);
}

.input-container input {
  flex-grow: 1;
  background: transparent;
  border: none;
  padding: 0.75rem 1rem;
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: 0.95rem;
  outline: none;
}

.btn-send {
  background: var(--primary-color);
  color: #fff;
  border-radius: 10px;
  padding: 0 1.25rem;
  transition: background-color 0.2s ease, transform 0.1s ease;
}

.btn-send:hover {
  background: #4f46e5;
}

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

/* Utilities */
.hidden {
  display: none !important;
}

.fade-in {
  animation: fadeIn 0.4s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .chat-app {
    width: 100vw;
    height: 100vh;
    border-radius: 0;
    border: none;
  }
  
  .chat-sidebar {
    display: none; /* In production, we'd add a toggle. But for simplicty, keep layout tight */
  }

  #join-container {
    padding: 1.5rem;
  }
}
