* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary: #25D366;
  --primary-dark: #1da851;
  --secondary: #128C7E;
  --bg-main: #0b141a;
  --bg-chat: #0d1418;
  --bg-message: #1f2c33;
  --bg-message-own: #005c4b;
  --text-primary: #e9edef;
  --text-secondary: #8696a0;
  --border: #2a3942;
  --danger: #f15c6d;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: var(--bg-main);
  color: var(--text-primary);
  line-height: 1.6;
}

.container {
  max-width: 900px;
  margin: 0 auto;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-chat);
}

/* Welcome Screen */
.password-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.welcome-card {
  background: var(--bg-message);
  padding: 3rem 2rem;
  border-radius: 16px;
  text-align: center;
  max-width: 450px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

.icon {
  font-size: 4rem;
  margin-bottom: 1rem;
}

.welcome-card h2 {
  margin-bottom: 1rem;
  font-size: 1.8rem;
}

.welcome-card p {
  color: var(--text-secondary);
  margin-bottom: 2rem;
}

.btn {
  padding: 0.9rem 2rem;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.3s;
  font-weight: 600;
}

.btn-primary {
  background: var(--primary);
  color: white;
  width: 100%;
}

.btn-primary:hover {
  background: var(--primary-dark);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(37, 211, 102, 0.4);
}

.btn-primary:disabled {
  background: var(--border);
  cursor: not-allowed;
  transform: none;
}

.btn-secondary {
  background: var(--secondary);
  color: white;
  width: 100%;
  margin-top: 0.5rem;
}

.btn-secondary:hover {
  background: #0f6d61;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(18, 140, 126, 0.4);
}

.btn-secondary:disabled {
  background: var(--border);
  cursor: not-allowed;
  transform: none;
}

.divider {
  margin: 1.5rem 0;
  color: var(--text-secondary);
  position: relative;
}

.divider::before,
.divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 40%;
  height: 1px;
  background: var(--border);
}

.divider::before { left: 0; }
.divider::after { right: 0; }

.info-text {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

/* Chat Screen */
.chat-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.chat-header {
  background: var(--bg-message);
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}

.chat-header::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--primary), transparent);
  animation: shimmer 3s infinite;
}

@keyframes shimmer {
  0% { left: -100%; }
  100% { left: 100%; }
}

.room-info {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.room-info h3 {
  font-size: 1rem;
  margin-bottom: 0;
  font-weight: 500;
  animation: bounce 2s ease-in-out infinite;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

.clock-container {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.2rem;
}

.clock {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--primary);
  font-family: 'Courier New', monospace;
  letter-spacing: 2px;
  text-shadow: 0 0 10px rgba(37, 211, 102, 0.3);
  animation: glow 2s ease-in-out infinite;
}

@keyframes glow {
  0%, 100% { text-shadow: 0 0 10px rgba(37, 211, 102, 0.3); }
  50% { text-shadow: 0 0 20px rgba(37, 211, 102, 0.6); }
}

.date {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 400;
}

.header-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  position: relative;
}

.floating-emoji {
  font-size: 1.5rem;
  animation: float 3s ease-in-out infinite;
  margin-right: 0.5rem;
}

@keyframes float {
  0%, 100% { 
    transform: translateY(0) rotate(0deg);
  }
  25% { 
    transform: translateY(-10px) rotate(5deg);
  }
  50% { 
    transform: translateY(0) rotate(0deg);
  }
  75% { 
    transform: translateY(-5px) rotate(-5deg);
  }
}

.room-id {
  display: none;
}

.header-actions {
  display: flex;
  gap: 0.5rem;
}

.btn-icon {
  background: transparent;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 50%;
  transition: background 0.2s;
}

.btn-icon:hover {
  background: rgba(255,255,255,0.1);
}

/* Search Bar */
.search-bar {
  background: var(--bg-message);
  padding: 0.8rem 1rem;
  display: flex;
  gap: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.search-bar input {
  flex: 1;
  background: var(--bg-chat);
  border: 1px solid var(--border);
  padding: 0.6rem 1rem;
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 0.95rem;
}

.search-bar input:focus {
  outline: none;
  border-color: var(--primary);
}

#closeSearchBtn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0 0.5rem;
}

/* Messages */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  background: var(--bg-chat);
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.messages-container::-webkit-scrollbar {
  width: 6px;
}

.messages-container::-webkit-scrollbar-track {
  background: var(--bg-chat);
}

.messages-container::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  color: var(--text-secondary);
  gap: 1rem;
}

.loading p {
  margin-top: 1rem;
  font-size: 0.95rem;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.message {
  max-width: 70%;
  padding: 0.7rem 1rem;
  border-radius: 8px;
  background: var(--bg-message);
  align-self: flex-start;
  position: relative;
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message.own {
  background: var(--bg-message-own);
  align-self: flex-end;
}

.message-content {
  word-wrap: break-word;
  margin-bottom: 0.3rem;
  white-space: pre-wrap;
}

.message-file {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.5rem;
  background: rgba(0,0,0,0.2);
  border-radius: 6px;
  margin-bottom: 0.3rem;
}

.file-icon {
  font-size: 2rem;
}

.file-info {
  flex: 1;
  min-width: 0;
}

.file-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-size {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.file-actions {
  display: flex;
  gap: 0.3rem;
}

.file-actions a,
.file-actions button {
  padding: 0.4rem 0.8rem;
  background: var(--primary);
  color: white;
  text-decoration: none;
  border: none;
  border-radius: 4px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.2s;
}

.file-actions a:hover,
.file-actions button:hover {
  background: var(--primary-dark);
}

.file-actions .share-btn {
  background: var(--secondary);
  padding: 0.4rem 0.6rem;
  font-size: 1rem;
}

.file-actions .share-btn:hover {
  background: #1976D2;
}

.message-time {
  font-size: 0.75rem;
  color: var(--text-secondary);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.delete-btn {
  background: transparent;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  transition: background 0.2s;
}

.delete-btn:hover {
  background: rgba(241, 92, 109, 0.2);
}

.empty-state {
  text-align: center;
  padding: 3rem 2rem;
  color: var(--text-secondary);
}

.empty-state .icon {
  font-size: 3rem;
  margin-bottom: 1rem;
}

/* Input Container */
.input-container {
  background: var(--bg-message);
  padding: 1rem 1.5rem;
  display: flex;
  gap: 0.8rem;
  align-items: center;
  border-top: 1px solid var(--border);
}

#messageInput {
  flex: 1;
  background: var(--bg-chat);
  border: 1px solid var(--border);
  padding: 0.8rem 1rem;
  border-radius: 24px;
  color: var(--text-primary);
  font-size: 0.95rem;
}

#messageInput:focus {
  outline: none;
  border-color: var(--primary);
}

.btn-send {
  background: var(--primary);
  border: none;
  width: 45px;
  height: 45px;
  border-radius: 50%;
  color: white;
  font-size: 1.2rem;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-send:hover {
  background: var(--primary-dark);
  transform: scale(1.05);
}

.btn-send:disabled {
  background: var(--border);
  cursor: not-allowed;
  transform: scale(1);
}

/* Upload Progress */
.upload-progress {
  background: var(--bg-message);
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
}

.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--bg-chat);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 0.5rem;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  transition: width 0.3s;
  border-radius: 4px;
}

.progress-text {
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-align: center;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-message);
  color: var(--text-primary);
  padding: 1rem 1.5rem;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  opacity: 0;
  transition: all 0.3s;
  z-index: 1000;
  max-width: 90%;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Password Form */
#passwordForm,
#createPasswordForm {
  width: 100%;
}

#passwordForm input,
#createPasswordForm input {
  width: 100%;
  background: var(--bg-chat);
  border: 1px solid var(--border);
  padding: 0.8rem 1rem;
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 0.95rem;
  margin-bottom: 1rem;
}

#passwordForm input:focus,
#createPasswordForm input:focus {
  outline: none;
  border-color: var(--primary);
}

.error-text {
  color: var(--danger);
  font-size: 0.9rem;
  margin-top: 1rem;
  padding: 0.5rem;
  background: rgba(241, 92, 109, 0.1);
  border-radius: 4px;
}

/* Responsive */
@media (max-width: 768px) {
  .container {
    max-width: 100%;
  }

  .message {
    max-width: 85%;
  }

  .welcome-card {
    padding: 2rem 1.5rem;
  }

  .header h1 {
    font-size: 1.5rem;
  }
}


/* Shake animation for wrong password */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-10px); }
  20%, 40%, 60%, 80% { transform: translateX(10px); }
}
