*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: linear-gradient(135deg, #141e30, #243b55);
  color: #111827;
}

a {
  color: #2563eb;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: rgba(15, 23, 42, 0.9);
  color: #e5e7eb;
  border-radius: 1rem;
  padding: 2rem 2.25rem 2.5rem;
  box-shadow: 0 20px 35px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(14px);
}

.auth-card h1 {
  margin: 0;
  font-size: 1.5rem;
  text-align: center;
}

.auth-card h2 {
  margin: 0.75rem 0 1.5rem;
  font-size: 1.125rem;
  text-align: center;
  color: #9ca3af;
}

label {
  display: block;
  font-size: 0.875rem;
  margin-bottom: 0.9rem;
}

label input {
  margin-top: 0.3rem;
}

input[type="text"],
input[type="password"],
textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border-radius: 0.5rem;
  border: 1px solid #4b5563;
  background: rgba(15, 23, 42, 0.85);
  color: #e5e7eb;
  font-size: 0.95rem;
}

input:focus,
textarea:focus {
  outline: 2px solid #3b82f6;
  outline-offset: 0;
  border-color: transparent;
}

.btn-primary,
.btn-secondary {
  border: none;
  border-radius: 999px;
  padding: 0.6rem 1.2rem;
  font-size: 0.95rem;
  cursor: pointer;
  font-weight: 500;
}

.btn-primary {
  background: linear-gradient(135deg, #3b82f6, #06b6d4);
  color: white;
  box-shadow: 0 10px 20px rgba(37, 99, 235, 0.45);
}

.btn-primary:hover {
  filter: brightness(1.05);
}

.btn-secondary {
  background: transparent;
  border: 1px solid rgba(148, 163, 184, 0.6);
  color: #e5e7eb;
}

.btn-secondary:hover {
  background: rgba(148, 163, 184, 0.18);
}

.auth-footer {
  margin-top: 1rem;
  font-size: 0.875rem;
  text-align: center;
  color: #9ca3af;
}

.alert {
  padding: 0.6rem 0.9rem;
  border-radius: 0.5rem;
  font-size: 0.85rem;
  margin-bottom: 0.9rem;
}

.alert-error {
  background: rgba(248, 113, 113, 0.12);
  border: 1px solid rgba(248, 113, 113, 0.6);
  color: #fecaca;
}

/* Chat layout */
.chat-body {
  min-height: 100vh;
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: 0.75rem;
}

.chat-app {
  flex: 1;
  max-width: 900px;
  background: #0b1120;
  color: #e5e7eb;
  border-radius: 1.25rem;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 22px 45px rgba(0, 0, 0, 0.5);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.2rem;
  border-bottom: 1px solid rgba(30, 64, 175, 0.9);
  background: radial-gradient(circle at top left, rgba(59, 130, 246, 0.2), transparent),
    radial-gradient(circle at top right, rgba(56, 189, 248, 0.12), transparent),
    #020617;
}

.chat-title {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.chat-logo {
  font-size: 1.5rem;
}

.chat-app-name {
  font-weight: 600;
  font-size: 1.05rem;
}

.chat-subtitle {
  font-size: 0.8rem;
  color: #9ca3af;
}

.chat-user {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.9rem;
}

.chat-username {
  padding: 0.2rem 0.7rem;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(148, 163, 184, 0.4);
}

.chat-main {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

.chat-messages-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-messages {
  flex: 1;
  padding: 0.9rem 0.9rem 0.4rem;
  overflow-y: auto;
  background:
    radial-gradient(circle at 0% 0%, rgba(56, 189, 248, 0.1), transparent 55%),
    radial-gradient(circle at 100% 0%, rgba(59, 130, 246, 0.13), transparent 55%),
    radial-gradient(circle at 0% 100%, rgba(16, 185, 129, 0.08), transparent 45%),
    #020617;
}

.message-row {
  display: flex;
  margin-bottom: 0.45rem;
}

.message-row.mine {
  justify-content: flex-end;
}

.message-row.theirs {
  justify-content: flex-start;
}

.message-bubble {
  max-width: 80%;
  padding: 0.55rem 0.75rem 0.55rem;
  border-radius: 1rem;
  font-size: 0.9rem;
  background: rgba(15, 23, 42, 0.96);
  border: 1px solid rgba(30, 64, 175, 0.7);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.45);
}

.message-row.mine .message-bubble {
  background: linear-gradient(135deg, #2563eb, #22c55e);
  border-color: transparent;
  color: #eff6ff;
}

.message-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.72rem;
  margin-bottom: 0.18rem;
  opacity: 0.82;
}

.message-text {
  white-space: pre-wrap;
  word-wrap: break-word;
}

.message-image {
  margin-top: 0.25rem;
}

.message-image img {
  max-width: 220px;
  border-radius: 0.85rem;
  display: block;
  border: 1px solid rgba(148, 163, 184, 0.6);
}

.message-file {
  margin-top: 0.25rem;
}

.message-file .file-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.7rem;
  background: rgba(59, 130, 246, 0.15);
  border-radius: 0.5rem;
  border: 1px solid rgba(59, 130, 246, 0.4);
  color: #93c5fd;
  text-decoration: none;
  font-size: 0.85rem;
}

.message-file .file-link:hover {
  background: rgba(59, 130, 246, 0.25);
  text-decoration: none;
}

.message-voice {
  margin-top: 0.25rem;
}

.message-voice audio {
  width: 100%;
  max-width: 250px;
  height: 32px;
  outline: none;
}

.message-voice audio::-webkit-media-controls-panel {
  background-color: rgba(15, 23, 42, 0.95);
}

.message-time {
  margin-left: 0.5rem;
}

.chat-input-area {
  padding: 0.55rem 0.85rem 0.7rem;
  border-top: 1px solid rgba(15, 23, 42, 0.9);
  background: linear-gradient(to top, #020617, rgba(15, 23, 42, 0.9));
  position: relative;
}

.toggle-sidebar-btn {
  position: absolute;
  left: 0.85rem;
  top: 0.55rem;
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.6);
  background: rgba(15, 23, 42, 0.9);
  color: #e5e7eb;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.toggle-sidebar-btn:hover {
  background: rgba(148, 163, 184, 0.18);
}

.chat-form {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  margin-left: 48px;
}

.chat-textarea {
  min-height: 42px;
  max-height: 120px;
  resize: none;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid rgba(55, 65, 81, 0.9);
  color: #e5e7eb;
  border-radius: 999px;
  padding: 0.55rem 0.9rem;
}

.file-input-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.6);
  font-size: 1.1rem;
  cursor: pointer;
  background: rgba(15, 23, 42, 0.9);
}

.file-input-label input[type="file"] {
  display: none;
}

.send-button {
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding-inline: 1.1rem;
}

/* Emoji picker */
.emoji-picker-wrapper {
  position: relative;
  margin-left: 48px;
  margin-bottom: 0.5rem;
}

.emoji-btn {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.6);
  background: rgba(15, 23, 42, 0.9);
  color: #e5e7eb;
  font-size: 1.1rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.emoji-btn:hover {
  background: rgba(148, 163, 184, 0.18);
}

.emoji-picker {
  position: absolute;
  bottom: 48px;
  left: 0;
  width: 320px;
  max-height: 300px;
  background: rgba(15, 23, 42, 0.98);
  border: 1px solid rgba(30, 64, 175, 0.7);
  border-radius: 0.75rem;
  padding: 0.75rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
  z-index: 1000;
  display: none;
  overflow-y: auto;
}

.emoji-picker.show {
  display: block;
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 0.25rem;
}

.emoji-item {
  background: transparent;
  border: none;
  border-radius: 0.4rem;
  padding: 0.4rem;
  font-size: 1.3rem;
  cursor: pointer;
  transition: background 0.15s;
}

.emoji-item:hover {
  background: rgba(59, 130, 246, 0.2);
}

/* Voice button */
.voice-btn {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.6);
  background: rgba(15, 23, 42, 0.9);
  color: #e5e7eb;
  font-size: 1.1rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  user-select: none;
}

.voice-btn:hover {
  background: rgba(148, 163, 184, 0.18);
}

.voice-btn.recording {
  background: rgba(239, 68, 68, 0.3);
  border-color: rgba(239, 68, 68, 0.6);
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* Users sidebar */
.users-sidebar {
  width: 0;
  background: rgba(15, 23, 42, 0.95);
  border-left: 1px solid rgba(30, 64, 175, 0.7);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.3s ease;
}

.users-sidebar.show {
  width: 250px;
}

.users-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid rgba(30, 64, 175, 0.5);
}

.users-header h3 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: #e5e7eb;
}

.users-header .toggle-sidebar {
  background: transparent;
  border: none;
  color: #9ca3af;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.users-header .toggle-sidebar:hover {
  color: #e5e7eb;
}

.users-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
}

.user-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.75rem;
  border-radius: 0.5rem;
  margin-bottom: 0.25rem;
  font-size: 0.9rem;
}

.user-item:hover {
  background: rgba(59, 130, 246, 0.1);
}

.user-status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #6b7280;
  flex-shrink: 0;
}

.user-item.online .user-status {
  background: #22c55e;
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.6);
}

.user-name {
  color: #e5e7eb;
  flex: 1;
}

@media (max-width: 640px) {
  .chat-app {
    border-radius: 1rem;
  }
  .message-bubble {
    max-width: 88%;
  }
  .chat-form {
    margin-left: 0;
  }
  .emoji-picker-wrapper {
    margin-left: 0;
  }
  .toggle-sidebar-btn {
    position: static;
    margin-bottom: 0.5rem;
  }
  .users-sidebar.show {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 200px;
    z-index: 100;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.5);
  }
  .emoji-picker {
    width: 280px;
    max-height: 250px;
  }
  .emoji-grid {
    grid-template-columns: repeat(7, 1fr);
  }
}

