/* ============================================================
   Hybrid Engine — Pure CSS Design System
   Premium Dark Mode + Glassmorphism + Smooth Animations
   ============================================================ */

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

/* ── Variables ── */
:root {
  --bg:          #0a0a0f;
  --bg2:         #111118;
  --bg3:         #1a1a28;
  --glass:       rgba(255,255,255,0.05);
  --glass-border:rgba(255,255,255,0.10);
  --primary:     #6366f1;
  --primary2:    #8b5cf6;
  --accent:      #06b6d4;
  --danger:      #ef4444;
  --success:     #22c55e;
  --text:        #f1f5f9;
  --text2:       #94a3b8;
  --text3:       #475569;
  --online:      #22c55e;
  --radius:      14px;
  --radius-sm:   8px;
  --shadow:      0 8px 32px rgba(0,0,0,0.5);
  --transition:  0.2s cubic-bezier(0.4,0,0.2,1);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; font-family: 'Inter', system-ui, sans-serif; background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
button { font-family: inherit; cursor: pointer; border: none; outline: none; }
input { font-family: inherit; outline: none; border: none; background: none; }
a { text-decoration: none; color: inherit; }

/* ── App Shell ── */
#app { height: 100vh; display: flex; flex-direction: column; }

/* ── VIEWS (single-page routing) ── */
.view { display: none; flex: 1; overflow: hidden; }
.view.active { display: flex; }

/* ============================================================
   AUTH VIEW
   ============================================================ */
#view-auth {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: radial-gradient(ellipse at top left, rgba(99,102,241,0.15) 0%, transparent 60%),
              radial-gradient(ellipse at bottom right, rgba(139,92,246,0.12) 0%, transparent 60%),
              var(--bg);
  overflow-y: auto;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: 24px;
  padding: 36px 32px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
  animation: slideUp 0.4s ease both;
}

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

.auth-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 28px;
}

.auth-logo-icon {
  width: 72px; height: 72px;
  background: linear-gradient(135deg, var(--primary), var(--primary2));
  border-radius: 20px;
  display: flex; align-items: center; justify-content: center;
  font-size: 32px;
  box-shadow: 0 8px 32px rgba(99,102,241,0.4);
  margin-bottom: 12px;
}

.auth-logo h1 { font-size: 24px; font-weight: 800; letter-spacing: -0.5px; }
.auth-logo p { color: var(--text2); font-size: 13px; margin-top: 4px; }

/* Auth tabs */
.auth-tabs {
  display: flex;
  background: rgba(255,255,255,0.04);
  border-radius: var(--radius-sm);
  padding: 4px;
  margin-bottom: 24px;
}

.auth-tab {
  flex: 1; padding: 9px;
  border-radius: calc(var(--radius-sm) - 2px);
  font-size: 14px; font-weight: 600;
  color: var(--text2);
  background: none;
  transition: var(--transition);
}

.auth-tab.active {
  background: linear-gradient(135deg, var(--primary), var(--primary2));
  color: #fff;
  box-shadow: 0 2px 12px rgba(99,102,241,0.35);
}

/* Input field */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--text2); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px; }

.input-wrap {
  display: flex; align-items: center; gap: 10px;
  background: rgba(255,255,255,0.06);
  border: 1.5px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  transition: var(--transition);
}
.input-wrap:focus-within { border-color: var(--primary); background: rgba(99,102,241,0.08); }
.input-wrap .icon { font-size: 16px; opacity: 0.5; flex-shrink: 0; }
.input-wrap input { flex: 1; height: 44px; font-size: 15px; color: var(--text); }
.input-wrap input::placeholder { color: var(--text3); }
.input-wrap .eye-btn { background: none; font-size: 16px; opacity: 0.5; padding: 4px; }
.field .err { color: var(--danger); font-size: 12px; margin-top: 4px; }

/* Auth submit button */
.btn-primary {
  width: 100%; padding: 14px;
  background: linear-gradient(135deg, var(--primary), var(--primary2));
  color: #fff; font-size: 15px; font-weight: 700;
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 20px rgba(99,102,241,0.35);
  transition: var(--transition);
  margin-top: 6px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 24px rgba(99,102,241,0.45); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.6; cursor: default; transform: none; }

/* ============================================================
   MAIN LAYOUT
   ============================================================ */
#view-main {
  flex-direction: row;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
  width: 320px;
  flex-shrink: 0;
  background: var(--bg2);
  border-right: 1px solid var(--glass-border);
  display: flex;
  flex-direction: column;
  height: 100%;
}

.sidebar-header {
  padding: 16px 16px 12px;
  display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid var(--glass-border);
  flex-shrink: 0;
}

.sidebar-title {
  flex: 1;
  font-size: 17px; font-weight: 700;
}

.icon-btn {
  width: 36px; height: 36px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  color: var(--text2);
  cursor: pointer;
  transition: var(--transition);
}
.icon-btn:hover { background: rgba(255,255,255,0.1); color: var(--text); }

/* Search bar */
.search-bar {
  padding: 10px 16px;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.search-input-wrap {
  display: flex; align-items: center; gap: 8px;
  background: rgba(255,255,255,0.06);
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0 12px;
  transition: var(--transition);
}
.search-input-wrap:focus-within { border-color: var(--primary); }
.search-input-wrap span { font-size: 16px; opacity: 0.5; }
.search-input-wrap input { height: 38px; flex: 1; font-size: 14px; color: var(--text); }
.search-input-wrap input::placeholder { color: var(--text3); }

/* User list */
.user-list { flex: 1; overflow-y: auto; padding: 8px 8px; }
.user-list::-webkit-scrollbar { width: 4px; }
.user-list::-webkit-scrollbar-track { background: transparent; }
.user-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

.user-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  position: relative;
}
.user-item:hover { background: var(--glass); }
.user-item.active { background: rgba(99,102,241,0.15); }

.avatar {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary2));
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 700; color: #fff;
  flex-shrink: 0;
  position: relative;
}
.avatar.sm { width: 36px; height: 36px; font-size: 13px; }
.avatar .online-dot {
  position: absolute; bottom: 1px; right: 1px;
  width: 11px; height: 11px;
  background: var(--online);
  border-radius: 50%;
  border: 2px solid var(--bg2);
}

.user-item-info { flex: 1; min-width: 0; }
.user-item-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-item-sub { font-size: 12px; color: var(--text2); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* sidebar tabs */
.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--glass-border);
  flex-shrink: 0;
}
.sidebar-tab {
  flex: 1; padding: 10px 8px;
  font-size: 12px; font-weight: 600;
  color: var(--text2);
  background: none;
  border-bottom: 2px solid transparent;
  transition: var(--transition);
}
.sidebar-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ── Chat Area ── */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--bg);
  position: relative;
}

/* Empty / No user selected */
.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text2);
  gap: 12px;
  font-size: 15px;
}
.chat-empty .big-icon { font-size: 64px; opacity: 0.3; }

/* Chat header */
.chat-header {
  padding: 16px 24px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}
.mobile-back-btn {
  display: none;
  background: transparent;
  border: none;
  color: var(--text1);
  font-size: 24px;
  cursor: pointer;
  padding: 0 8px 0 0;
}
.mobile-back-btn:hover { color: var(--primary); }
.chat-header-info { flex: 1; }
.chat-header-name { font-size: 15px; font-weight: 700; }
.chat-header-status { font-size: 12px; color: var(--text2); margin-top: 2px; }
.chat-header-actions { display: flex; gap: 8px; }

.call-btn {
  width: 38px; height: 38px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; color: var(--text2);
  cursor: pointer;
  transition: var(--transition);
}
.call-btn:hover { background: rgba(99,102,241,0.2); color: var(--primary); border-color: var(--primary); }
.call-btn.video:hover { background: rgba(6,182,212,0.15); color: var(--accent); border-color: var(--accent); }

/* Messages */
.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.messages-area::-webkit-scrollbar { width: 4px; }
.messages-area::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 2px; }

.msg-row { display: flex; align-items: flex-end; gap: 8px; }
.msg-row.me { flex-direction: row-reverse; }

.msg-bubble {
  max-width: 70%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
  animation: popIn 0.15s ease both;
}
@keyframes popIn {
  from { opacity: 0; transform: scale(0.95); }
  to   { opacity: 1; transform: scale(1); }
}

.msg-bubble.them {
  background: var(--bg3);
  color: var(--text);
  border-bottom-left-radius: 4px;
}
.msg-bubble.me {
  background: linear-gradient(135deg, var(--primary), var(--primary2));
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg-time {
  font-size: 11px;
  color: var(--text3);
  text-align: right;
  margin-top: 4px;
}
.msg-link {
  color: #a0c0ff;
  text-decoration: underline;
}
.msg-link:hover {
  color: #fff;
}
.msg-sys-container {
  display: flex;
  justify-content: center;
  width: 100%;
  margin: 12px 0;
}
.msg-sys {
  font-size: 11px;
  color: var(--text2);
  background: var(--bg2);
  padding: 6px 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}
.msg-date-divider { text-align: center; color: var(--text3); font-size: 11px; padding: 8px 0; }

/* Message input */
.chat-input-area {
  padding: 12px 20px;
  background: var(--bg2);
  border-top: 1px solid var(--glass-border);
  display: flex; align-items: center; gap: 10px;
  flex-shrink: 0;
}

.msg-input-wrap {
  flex: 1;
  display: flex; align-items: center; gap: 8px;
  background: var(--bg3);
  border: 1.5px solid var(--glass-border);
  border-radius: 22px;
  padding: 0 16px;
  transition: var(--transition);
}
.msg-input-wrap:focus-within { border-color: var(--primary); }
.msg-input-wrap input { flex: 1; height: 44px; font-size: 14px; color: var(--text); }
.msg-input-wrap input::placeholder { color: var(--text3); }

.send-btn {
  width: 44px; height: 44px;
  background: linear-gradient(135deg, var(--primary), var(--primary2));
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  transition: var(--transition);
  box-shadow: 0 4px 16px rgba(99,102,241,0.4);
}
.send-btn:hover { transform: scale(1.05); }
.send-btn:active { transform: scale(0.96); }

/* ============================================================
   PROFILE PANEL
   ============================================================ */
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--glass-border);
  display: flex; align-items: center; gap: 10px;
  flex-shrink: 0;
}
.my-profile-name { flex: 1; font-size: 14px; font-weight: 600; }
.my-profile-sub { font-size: 11px; color: var(--text2); }

/* ============================================================
   MODAL BASE
   ============================================================ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease;
}
.modal-overlay.show { opacity: 1; pointer-events: all; }

.modal-box {
  background: var(--bg2);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  padding: 28px 24px;
  width: 90%;
  max-width: 380px;
  transform: scale(0.95);
  transition: transform 0.2s ease;
  box-shadow: 0 24px 64px rgba(0,0,0,0.6);
}
.modal-overlay.show .modal-box { transform: scale(1); }

.modal-title { font-size: 18px; font-weight: 700; margin-bottom: 20px; }

/* ============================================================
   INCOMING CALL MODAL
   ============================================================ */
#modal-incoming-call .modal-box {
  text-align: center;
  max-width: 340px;
}
.incoming-call-avatar {
  width: 80px; height: 80px;
  background: linear-gradient(135deg, var(--primary), var(--primary2));
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 32px; font-weight: 700; color: #fff;
  margin: 0 auto 16px;
  animation: ringPulse 1.2s ease-in-out infinite;
  box-shadow: 0 0 0 0 rgba(99,102,241,0.5);
}
@keyframes ringPulse {
  0%   { box-shadow: 0 0 0 0 rgba(99,102,241,0.5); }
  70%  { box-shadow: 0 0 0 20px rgba(99,102,241,0); }
  100% { box-shadow: 0 0 0 0 rgba(99,102,241,0); }
}
.incoming-call-name { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.incoming-call-type { color: var(--text2); font-size: 14px; margin-bottom: 28px; }
.incoming-call-btns { display: flex; justify-content: center; gap: 32px; }
.call-action-btn {
  width: 64px; height: 64px; border-radius: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; font-size: 24px; cursor: pointer;
  transition: var(--transition);
}
.call-action-btn span { font-size: 11px; font-weight: 600; }
.call-action-btn.accept { background: var(--success); box-shadow: 0 4px 20px rgba(34,197,94,0.4); }
.call-action-btn.reject { background: var(--danger); box-shadow: 0 4px 20px rgba(239,68,68,0.4); }
.call-action-btn:hover { transform: scale(1.08); }

/* ============================================================
   CALL VIEW (Full-screen)
   ============================================================ */
#view-call {
  position: fixed; inset: 0;
  background: #050508;
  z-index: 200;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
#view-call.active { display: flex; }

.call-remote-video {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  background: #111;
}
.call-local-video {
  position: absolute; bottom: 96px; right: 20px;
  width: 120px; height: 160px;
  border-radius: 12px;
  object-fit: cover;
  background: #1a1a2e;
  border: 2px solid rgba(255,255,255,0.15);
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}

.call-overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: space-between;
  padding: 60px 24px 36px;
}

.call-info { text-align: center; }
.call-caller-name { font-size: 28px; font-weight: 800; text-shadow: 0 2px 8px rgba(0,0,0,0.6); }
.call-status { color: rgba(255,255,255,0.6); font-size: 14px; margin-top: 6px; }
.call-timer { color: rgba(255,255,255,0.8); font-size: 18px; font-weight: 600; margin-top: 4px; }

.call-controls {
  display: flex; gap: 20px; align-items: center;
}
.call-ctrl-btn {
  width: 56px; height: 56px; border-radius: 50%;
  background: rgba(255,255,255,0.15);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.2);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; font-size: 20px; color: #fff; cursor: pointer;
  transition: var(--transition);
}
.call-ctrl-btn span { font-size: 10px; font-weight: 600; }
.call-ctrl-btn:hover { background: rgba(255,255,255,0.25); }
.call-ctrl-btn.active { background: var(--primary); border-color: var(--primary); }
.call-ctrl-btn.end-call {
  width: 68px; height: 68px; font-size: 24px;
  background: var(--danger);
  border-color: var(--danger);
  box-shadow: 0 4px 24px rgba(239,68,68,0.5);
}

/* ============================================================
   PROFILE MODAL
   ============================================================ */
.avatar-picker {
  width: 72px; height: 72px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary2));
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; font-weight: 700; color: #fff;
  margin: 0 auto 20px;
}

/* ============================================================
   TOAST NOTIFICATION
   ============================================================ */
#toast-container {
  position: fixed;
  bottom: 24px; right: 24px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 999;
}
.toast {
  padding: 12px 18px;
  background: var(--bg3);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  box-shadow: var(--shadow);
  animation: toastIn 0.25s ease both;
  max-width: 320px;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--danger); }
.toast.info    { border-left: 3px solid var(--primary); }

/* ============================================================
   LOADING SPINNER
   ============================================================ */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =========================================================
   Mobile Responsiveness
========================================================= */
@media (max-width: 700px) {
  .mobile-back-btn { display: block; }
  
  .sidebar { width: 100%; position: absolute; z-index: 10; transition: transform 0.3s ease; }
  .sidebar.hidden { transform: translateX(-100%); }
  
  .chat-area { width: 100%; position: absolute; z-index: 5; }
  
  .call-local-video { width: 90px; height: 120px; }
}

/* ── Empty state placeholder ── */
.no-chats {
  text-align: center;
  padding: 40px 16px;
  color: var(--text3);
}
.no-chats .icon { font-size: 48px; margin-bottom: 12px; }
.no-chats p { font-size: 13px; line-height: 1.6; }
