/* ═══════════════════════════════════════════
   Django Chat App — Main Stylesheet
   Design: Dark luxury with emerald accents
   ═══════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@300;400;500;600&family=Syne:wght@700;800&display=swap');

/* ── CSS Variables ── */
:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #111118;
  --bg-tertiary: #1a1a24;
  --bg-card: #16161f;
  --bg-hover: #1e1e2a;
  --accent: #10b981;
  --accent-dim: #059669;
  --accent-glow: rgba(16, 185, 129, 0.15);
  --text-primary: #f0f0f5;
  --text-secondary: #8888a0;
  --text-muted: #4a4a60;
  --border: rgba(255,255,255,0.06);
  --border-accent: rgba(16, 185, 129, 0.3);
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --radius: 14px;
  --radius-sm: 8px;
  --radius-full: 999px;
  --font-body: 'DM Sans', sans-serif;
  --font-display: 'Syne', sans-serif;
  --sidebar-w: 320px;
  --transition: 0.2s cubic-bezier(0.4,0,0.2,1);
}

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

html, body {
  min-height: 100dvh;
  height: auto;
  margin: 0;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; border: none; outline: none; }
input, textarea { font-family: inherit; outline: none; border: none; }

/* ═══════════════════════════════════════════
   AUTH PAGES (Login / Register)
   ═══════════════════════════════════════════ */

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  background-image:
    radial-gradient(ellipse 60% 50% at 50% -10%, rgba(16,185,129,0.12) 0%, transparent 70%),
    radial-gradient(ellipse 40% 30% at 80% 80%, rgba(16,185,129,0.06) 0%, transparent 60%);
  padding: 24px;
}

.auth-box {
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 48px 40px;
  box-shadow: var(--shadow), 0 0 0 1px rgba(16,185,129,0.05) inset;
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 32px;
}

.auth-logo .logo-icon {
  width: 40px;
  height: 40px;
  background: var(--accent);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.auth-logo .logo-text {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.auth-title {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 800;
  margin-bottom: 6px;
  letter-spacing: -0.5px;
}

.auth-subtitle {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 32px;
}

/* Form Elements */
.form-group {
  margin-bottom: 18px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.form-input {
  width: 100%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  color: var(--text-primary);
  font-size: 15px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.form-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

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

.form-errors {
  margin-bottom: 16px;
}

.error-item {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.2);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 13px;
  color: #f87171;
  margin-bottom: 6px;
}

.btn-primary {
  width: 100%;
  background: var(--accent);
  color: #000;
  font-weight: 600;
  font-size: 15px;
  padding: 12px;
  border-radius: var(--radius-sm);
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
  margin-top: 8px;
  letter-spacing: 0.01em;
}

.btn-primary:hover {
  background: #34d399;
  box-shadow: 0 4px 20px rgba(16,185,129,0.3);
  transform: translateY(-1px);
}

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

.auth-footer {
  text-align: center;
  margin-top: 24px;
  font-size: 14px;
  color: var(--text-secondary);
}

.auth-footer a {
  color: var(--accent);
  font-weight: 500;
}

.auth-footer a:hover {
  color: #34d399;
}

/* Django messages */
.django-messages {
  margin-bottom: 16px;
}

.alert {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 8px;
}

.alert-success { background: rgba(16,185,129,0.1); border: 1px solid rgba(16,185,129,0.2); color: #6ee7b7; }
.alert-error   { background: rgba(239,68,68,0.1);  border: 1px solid rgba(239,68,68,0.2);  color: #f87171; }
.alert-warning { background: rgba(245,158,11,0.1); border: 1px solid rgba(245,158,11,0.2); color: #fcd34d; }


/* ═══════════════════════════════════════════
   MAIN APP LAYOUT (Dashboard + Chat)
   ═══════════════════════════════════════════ */

.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.sidebar-header {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.app-brand {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 8px;
  letter-spacing: -0.3px;
}

.brand-dot {
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  display: inline-block;
}

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

.icon-btn {
  width: 34px;
  height: 34px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 16px;
  transition: background var(--transition), color var(--transition);
  text-decoration: none;
  border: 1px solid var(--border);
}

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

.search-box {
  position: relative;
}

.search-box input {
  width: 100%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 8px 14px 8px 36px;
  color: var(--text-primary);
  font-size: 14px;
  transition: border-color var(--transition);
}

.search-box input:focus {
  border-color: var(--accent);
}

.search-box input::placeholder { color: var(--text-muted); }

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 14px;
  pointer-events: none;
}

/* ── Current User Strip ── */
.current-user-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-tertiary);
  flex-shrink: 0;
}

.current-user-strip .avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: #000;
  flex-shrink: 0;
}

.current-user-strip .user-info { flex: 1; overflow: hidden; }
.current-user-strip .username  { font-size: 14px; font-weight: 600; }
.current-user-strip .status    { font-size: 12px; color: var(--accent); }

/* ── User List ── */
.users-label {
  padding: 14px 20px 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  flex-shrink: 0;
}

.user-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}

.user-list::-webkit-scrollbar { width: 4px; }
.user-list::-webkit-scrollbar-track { background: transparent; }
.user-list::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 2px; }

.user-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  cursor: pointer;
  transition: background var(--transition);
  text-decoration: none;
  color: inherit;
  position: relative;
}

.user-item:hover { background: var(--bg-hover); }
.user-item.active { background: var(--bg-hover); border-left: 2px solid var(--accent); }

.avatar-wrap {
  position: relative;
  flex-shrink: 0;
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  color: #000;
  text-transform: uppercase;
}

.online-dot {
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 10px;
  height: 10px;
  background: var(--accent);
  border: 2px solid var(--bg-secondary);
  border-radius: 50%;
}

.user-meta { flex: 1; overflow: hidden; }

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

.user-preview {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

.user-time {
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
  align-self: flex-start;
  margin-top: 2px;
}

.unread-badge {
  background: var(--accent);
  color: #000;
  font-size: 11px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

/* ── Main Content ── */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-primary);
}

/* ── Empty State ── */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--text-muted);
  padding: 40px;
  text-align: center;
}

.empty-icon {
  font-size: 64px;
  opacity: 0.3;
  filter: grayscale(1);
}

.empty-state h2 {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 800;
  color: var(--text-secondary);
}

.empty-state p {
  font-size: 14px;
  max-width: 280px;
}

/* ── Chat Header ── */
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
}

.chat-header .avatar { width: 40px; height: 40px; font-size: 15px; }

.chat-header-info { flex: 1; }
.chat-header-info .name { font-size: 15px; font-weight: 600; }
.chat-header-info .status { font-size: 12px; color: var(--text-muted); }
.chat-header-info .status.online { color: var(--accent); }

.chat-header-actions { display: flex; gap: 6px; }

/* ── Messages Area ── */
.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  padding-bottom: 100px; 
  display: flex;
  flex-direction: column;
  gap: 6px;
  background-image:
    radial-gradient(ellipse 40% 30% at 20% 80%, rgba(16,185,129,0.03) 0%, transparent 70%);
}

.messages-area::-webkit-scrollbar { width: 4px; }
.messages-area::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 2px; }

.msg-day-divider {
  text-align: center;
  margin: 12px 0;
}

.msg-day-divider span {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-tertiary);
  padding: 4px 12px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
}

.message-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 70%;
  animation: msgIn 0.2s ease-out;
}

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

.message-row.sent {
  margin-left: auto;
  flex-direction: row-reverse;
}

.message-row.received { margin-right: auto; }

.msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #000;
  flex-shrink: 0;
}

.message-bubble {
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.5;
  position: relative;
  max-width: 100%;
  word-wrap: break-word;
}

.sent .message-bubble {
  background: var(--accent);
  color: #000;
  border-bottom-right-radius: 4px;
}

.received .message-bubble {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.msg-time {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 3px;
  padding: 0 2px;
  text-align: right;
}

.message-row.received .msg-time { text-align: left; }

/* ── Message Input ── */
.message-input-area {
  position: fixed;
  bottom: 0;
  right: 0;
  left: 0;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
  z-index: 100;
}

/* Desktop View: Adjust the input area to stay out of the sidebar */
@media (min-width: 769px) {
  .message-input-area {
    /* Set this to your actual sidebar width */
    left: 320px; 
  }
}

.input-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 6px 6px 6px 18px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.input-row:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.message-input {
  flex: 1;
  background: transparent;
  color: var(--text-primary);
  font-size: 15px;
  border: none;
  resize: none;
  max-height: 120px;
  line-height: 1.5;
}

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

.send-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent);
  color: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  transition: background var(--transition), transform var(--transition);
}

.send-btn:hover { background: #34d399; transform: scale(1.05); }
.send-btn:active { transform: scale(0.95); }

/* ── Typing Indicator ── */
.typing-indicator {
  display: none;
  align-items: center;
  gap: 6px;
  padding: 4px 0 8px 8px;
  font-size: 12px;
  color: var(--text-muted);
}

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

.typing-dots span {
  width: 4px;
  height: 4px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typing 1.2s infinite;
}

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

@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30%            { transform: translateY(-4px); opacity: 1; }
}

/* ── Connection Status Toast ── */
.connection-toast {
  position: fixed;
  top: 20px;
  right: 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: var(--shadow);
  z-index: 1000;
  animation: slideIn 0.3s ease-out;
  transition: opacity 0.3s;
}

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

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

.toast-dot.connected    { background: var(--accent); }
.toast-dot.disconnected { background: #ef4444; }
.toast-dot.connecting   { background: #f59e0b; animation: pulse 1s infinite; }

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

/* ── Profile Page ── */
.profile-page {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

.profile-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  max-width: 400px;
  width: 100%;
  text-align: center;
}

.profile-avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  font-weight: 800;
  color: #000;
  margin: 0 auto 16px;
}

.profile-name {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 800;
  margin-bottom: 4px;
}

.profile-username {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 20px;
}

.profile-stats {
  display: flex;
  gap: 1px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  margin-bottom: 24px;
}

.stat-item {
  flex: 1;
  background: var(--bg-tertiary);
  padding: 14px 10px;
  text-align: center;
}

.stat-value {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 800;
  color: var(--accent);
}

.stat-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.btn-outline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all var(--transition);
  text-decoration: none;
}

.btn-outline:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-glow);
}

/* ── Responsive ── */
@media (max-width: 640px) {
  .sidebar {
    width: 100%;
    position: absolute;
    z-index: 10;
    transform: translateX(0);
    transition: transform var(--transition);
  }

  .sidebar.hidden {
    transform: translateX(-100%);
  }

  .main-content {
    width: 100%;
  }
}

 /* back button -start*/
/* Base style - Hidden by default */
.mobile-back-btn {
  display: none;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  padding: 8px 14px;
  border-radius: 40px;
  text-decoration: none;
  color: #ffffff;
  font-size: 15px;
  font-weight: 500;
  transition: all 0.2s ease;
  border: 0.5px solid rgba(255, 255, 255, 0.15);
}

.mobile-back-btn:active {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(0.96);
}


@media (max-width: 768px) {
  .mobile-back-btn {
    display: inline-flex;
    position: sticky;
    top: 12px;
    left: 12px;
    z-index: 100;
    margin: 2px 0 8px 8px;
  }
}
/* back button -end*/

/* Mobile Logic */
@media (max-width: 768px) {
  /* Hide the main chat content by default on mobile */
  .main-content {
    display: none;
    width: 100%;
  }

  /* When the body has the 'chat-open' class, show chat and hide sidebar */
  body.chat-open .main-content {
    display: flex;
  }
  body.chat-open .sidebar {
    display: none;
  }

  .sidebar {
    width: 100%; /* Sidebar takes full width on mobile list view */
  }
}