/* ═══════════════════════════════════════════════════════
   FamilyLink — Private Messenger CSS
   ═══════════════════════════════════════════════════════ */

:root {
  /* Color System */
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-tertiary: #1a1a28;
  --bg-surface: #1e1e2e;
  --bg-hover: #252538;
  --bg-active: #2a2a42;
  
  --text-primary: #e8e8f0;
  --text-secondary: #9898b0;
  --text-muted: #686884;
  --text-inverse: #0a0a0f;
  
  --accent-primary: #6366f1;
  --accent-secondary: #8b5cf6;
  --accent-gradient: linear-gradient(135deg, #6366f1, #8b5cf6);
  --accent-glow: rgba(99, 102, 241, 0.3);
  
  --success: #4ade80;
  --danger: #ef4444;
  --warning: #fbbf24;
  
  --msg-sent-bg: linear-gradient(135deg, #4f46e5, #6d5ad8);
  --msg-received-bg: #1e1e2e;
  
  --border-color: rgba(255, 255, 255, 0.06);
  --border-glow: rgba(99, 102, 241, 0.2);
  
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.15);
  
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  
  --sidebar-width: 340px;
  --header-height: 64px;
}

/* ─── Reset & Base ────────────────────────────────────── */

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

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

input, button, textarea {
  font-family: inherit;
  font-size: inherit;
}

a {
  color: var(--accent-primary);
  text-decoration: none;
  transition: color 0.2s;
}
a:hover {
  color: var(--accent-secondary);
}

.hidden { display: none !important; }

.screen {
  display: none;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  overflow: hidden;
}
.screen.active {
  display: flex;
}

/* ─── Scrollbar ───────────────────────────────────────── */

::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ═══════════ AUTH SCREEN ═══════════ */

#auth-screen {
  justify-content: center;
  align-items: center;
  background: var(--bg-primary);
  position: relative;
  overflow: hidden;
}

#auth-screen::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle at 30% 40%, rgba(99, 102, 241, 0.08), transparent 50%),
              radial-gradient(circle at 70% 60%, rgba(139, 92, 246, 0.06), transparent 50%);
  animation: authGlow 15s ease-in-out infinite alternate;
}

@keyframes authGlow {
  0% { transform: translate(0, 0) rotate(0deg); }
  100% { transform: translate(-5%, -5%) rotate(3deg); }
}

.auth-container {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 400px;
  padding: 40px;
  background: rgba(18, 18, 26, 0.8);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg), var(--shadow-glow);
}

.auth-logo {
  text-align: center;
  margin-bottom: 36px;
}

.logo-icon {
  display: inline-flex;
  margin-bottom: 16px;
  animation: logoFloat 3s ease-in-out infinite;
}

@keyframes logoFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.auth-logo h1 {
  font-size: 28px;
  font-weight: 700;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.5px;
}

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

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-group input {
  padding: 12px 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 15px;
  transition: all 0.3s ease;
  outline: none;
}

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

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

.btn {
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.btn-primary {
  background: var(--accent-gradient);
  color: white;
  box-shadow: 0 4px 16px var(--accent-glow);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 24px rgba(99, 102, 241, 0.4);
}

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

.auth-switch {
  text-align: center;
  font-size: 14px;
  color: var(--text-secondary);
}

.form-error {
  padding: 10px 14px;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius-sm);
  color: var(--danger);
  font-size: 13px;
  text-align: center;
}

/* ═══════════ CHAT SCREEN ═══════════ */

#chat-screen {
  flex-direction: row;
  height: 100vh;
}

/* ─── Sidebar ─────────────────────────────────────────── */

.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  padding-top: calc(16px + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--border-color);
  height: calc(var(--header-height) + env(safe-area-inset-top, 0px));
}

.sidebar-user-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-username {
  font-weight: 600;
  font-size: 15px;
}

.sidebar-search {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border-color);
}

.sidebar-search svg {
  color: var(--text-muted);
  flex-shrink: 0;
}

.sidebar-search input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
}
.sidebar-search input::placeholder {
  color: var(--text-muted);
}

.contacts-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.contact-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
}

.contact-item:hover {
  background: var(--bg-hover);
}

.contact-item.active {
  background: var(--bg-active);
  border: 1px solid var(--border-glow);
}

.contact-info {
  flex: 1;
  min-width: 0;
}

.contact-name {
  font-weight: 500;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-last-msg {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.contact-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.contact-time {
  font-size: 11px;
  color: var(--text-muted);
}

.contact-unread {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  background: var(--accent-gradient);
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  color: white;
}

/* ─── Avatar ──────────────────────────────────────────── */

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 16px;
  color: white;
  position: relative;
  flex-shrink: 0;
  background: var(--accent-gradient);
}

.avatar-sm {
  width: 34px;
  height: 34px;
  font-size: 13px;
}

.avatar-lg {
  width: 80px;
  height: 80px;
  font-size: 30px;
}

.avatar-xl {
  width: 120px;
  height: 120px;
  font-size: 44px;
}

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

/* ─── Chat Area ───────────────────────────────────────── */

.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--bg-primary);
  position: relative;
}

.chat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 16px;
  opacity: 0.7;
}

.chat-empty h2 {
  font-size: 22px;
  font-weight: 600;
}

.chat-empty p {
  color: var(--text-secondary);
}

.empty-icon {
  margin-bottom: 12px;
  animation: logoFloat 3s ease-in-out infinite;
}

.chat-active {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* ─── Chat Header ─────────────────────────────────────── */

.chat-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 20px;
  height: var(--header-height);
  min-height: var(--header-height);
  height: calc(var(--header-height) + env(safe-area-inset-top, 0px));
  min-height: calc(var(--header-height) + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  z-index: 50;
  position: relative;
}

.back-btn {
  display: none;
}

.chat-header-info {
  flex: 1;
}

.chat-header-info h3 {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.2;
}

.status-text {
  font-size: 12px;
  color: var(--text-muted);
  transition: color 0.3s;
}

.status-text.online {
  color: var(--success);
}

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

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

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

/* ─── Messages ────────────────────────────────────────── */

.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.messages-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: auto;
}

.message {
  max-width: 70%;
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  position: relative;
  animation: msgSlideIn 0.3s ease;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

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

.message.sent {
  align-self: flex-end;
  background: var(--msg-sent-bg);
  color: white;
  border-bottom-right-radius: 4px;
}

.message.received {
  align-self: flex-start;
  background: var(--msg-received-bg);
  border: 1px solid var(--border-color);
  border-bottom-left-radius: 4px;
}

.message-content {
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.message-time {
  font-size: 11px;
  margin-top: 4px;
  opacity: 0.6;
  text-align: right;
}

.message.received .message-time {
  color: var(--text-muted);
}

.message-date-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px 0 8px;
}

.message-date-divider span {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-tertiary);
  padding: 4px 14px;
  border-radius: 12px;
}

/* Typing Indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
  background: var(--msg-received-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  border-bottom-left-radius: 4px;
  width: fit-content;
  align-self: flex-start;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite;
}

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

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

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

/* ─── Message Input ───────────────────────────────────── */

.message-input-area {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 14px 20px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
}

.message-input-wrapper {
  flex: 1;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 4px 4px 4px 16px;
  display: flex;
  align-items: flex-end;
  transition: border-color 0.3s;
}

.message-input-wrapper:focus-within {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

#message-input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 14px;
  padding: 8px 0;
  resize: none;
  outline: none;
  max-height: 120px;
  line-height: 1.4;
}

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

.send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: var(--accent-gradient);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
  flex-shrink: 0;
  box-shadow: 0 2px 8px var(--accent-glow);
}

.send-btn:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.4);
}

.send-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ═══════════ CALL OVERLAY ═══════════ */

.call-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.3s ease;
}

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

.call-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  width: 100%;
  position: relative;
}

.call-videos {
  position: absolute;
  inset: 0;
}

.call-videos video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.call-videos .local-video {
  position: absolute;
  bottom: 120px;
  right: 20px;
  width: 160px;
  height: 120px;
  border-radius: var(--radius-md);
  border: 2px solid rgba(255, 255, 255, 0.2);
  z-index: 2;
  object-fit: cover;
}

.call-avatar-display {
  position: relative;
  z-index: 1;
  margin-bottom: 24px;
}

.call-avatar-ring {
  padding: 8px;
  border-radius: 50%;
  border: 3px solid var(--accent-primary);
  animation: callPulse 2s ease-in-out infinite;
}

@keyframes callPulse {
  0%, 100% { box-shadow: 0 0 0 0 var(--accent-glow); }
  50% { box-shadow: 0 0 0 20px transparent; }
}

.call-status {
  position: relative;
  z-index: 1;
  font-size: 16px;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.call-name {
  position: relative;
  z-index: 1;
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 60px;
}

.call-controls {
  position: absolute;
  bottom: 48px;
  display: flex;
  gap: 24px;
  z-index: 10;
}

.call-control-btn {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  background: var(--bg-surface);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.call-control-btn:hover {
  background: var(--bg-hover);
  transform: scale(1.05);
}

.call-control-btn.active {
  background: var(--danger);
  color: white;
}

.call-control-btn.end-call {
  background: var(--danger);
  color: white;
  width: 70px;
  height: 70px;
}

.call-control-btn.end-call:hover {
  background: #dc2626;
}

/* ═══════════ INCOMING CALL ═══════════ */

.incoming-call {
  position: fixed;
  inset: 0;
  z-index: 1100;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(20px);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.3s ease;
}

.incoming-call-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  position: relative;
}

.incoming-call-pulse {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -80%);
  width: 200px;
  height: 200px;
  border-radius: 50%;
  background: var(--accent-glow);
  animation: incomingPulse 2s ease-in-out infinite;
}

@keyframes incomingPulse {
  0%, 100% { transform: translate(-50%, -80%) scale(0.8); opacity: 0.3; }
  50% { transform: translate(-50%, -80%) scale(1.2); opacity: 0; }
}

.incoming-call-card h3 {
  font-size: 24px;
  font-weight: 700;
  position: relative;
}

.incoming-call-card p {
  color: var(--text-secondary);
  font-size: 15px;
  position: relative;
}

.incoming-call-actions {
  display: flex;
  gap: 48px;
  margin-top: 32px;
  position: relative;
}

.call-action-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.call-action-btn.reject {
  background: var(--danger);
}

.call-action-btn.accept {
  background: var(--success);
  animation: acceptPulse 1.5s ease-in-out infinite;
}

@keyframes acceptPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.4); }
  50% { box-shadow: 0 0 0 12px transparent; }
}

.call-action-btn:hover {
  transform: scale(1.1);
}

/* ═══════════ RESPONSIVE ═══════════ */
@media (max-width: 768px) {
  .sidebar {
    width: 100%;
    z-index: 100;
  }
  
  .sidebar.collapsed {
    display: none !important;
  }
  
  .back-btn {
    display: flex;
  }
  
  .chat-header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 200;
  }

  .messages-container {
    padding-top: calc(var(--header-height) + env(safe-area-inset-top, 0px) + 10px);
  }
  
  .chat-area {
    width: 100%;
  }

  .message {
    max-width: 85%;
  }

  .call-videos .local-video {
    width: 120px;
    height: 90px;
    bottom: 140px;
    right: 12px;
  }

  .auth-container {
    margin: 20px;
    padding: 28px;
  }
}

@media (max-width: 480px) {
  .auth-container {
    padding: 24px 20px;
    border-radius: var(--radius-lg);
  }
  
  .call-controls {
    gap: 16px;
  }
  
  .call-control-btn {
    width: 52px;
    height: 52px;
  }
  
  .call-control-btn.end-call {
    width: 60px;
    height: 60px;
  }
}

/* ═══════════ UTILITY ANIMATIONS ═══════════ */

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

.shake {
  animation: shake 0.4s ease;
}

/* Load spinner for messages */
.loading-spinner {
  display: flex;
  justify-content: center;
  padding: 20px;
}

.loading-spinner::after {
  content: '';
  width: 28px;
  height: 28px;
  border: 3px solid var(--border-color);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Notification badge */
.notification-badge {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 900;
  padding: 12px 20px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideDown 0.3s ease, fadeOut 0.3s ease 3s forwards;
  cursor: pointer;
}

@keyframes slideDown {
  from { transform: translateY(-100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes fadeOut {
  to { opacity: 0; transform: translateY(-20px); pointer-events: none; }
}

/* Version Labeling */
.version-tag {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 24px;
  opacity: 0.5;
}

.sidebar-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border-color);
  text-align: center;
}

.version-text {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  opacity: 0.6;
}
