/* ===== Messenger Page Specific Styles ===== */

/* Messenger page body */
.messenger-page {
  overflow: hidden;
}

/* Messenger Container */
.messenger-container {
  position: fixed;
  top: var(--navbar-height);
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
}

/* Screens */
.screen {
  display: none;
  height: 100%;
  width: 100%;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

/* Login Screen */
#login-screen {
  justify-content: center;
  align-items: center;
  background: linear-gradient(135deg, var(--color-bg-alt) 0%, var(--color-bg) 100%);
}

.login-container {
  background: white;
  padding: 40px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  text-align: center;
  max-width: 90%;
  width: 360px;
}

.login-container h1 {
  color: var(--color-text);
  margin-bottom: 10px;
  font-size: 28px;
  font-weight: 700;
}

.login-container p {
  color: var(--color-text-light);
  margin-bottom: 24px;
}

#username-input {
  width: 100%;
  padding: 14px 16px;
  font-size: 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  margin-bottom: 16px;
  outline: none;
  transition: border-color var(--transition);
}

#username-input:focus {
  border-color: var(--color-primary);
}

#join-btn {
  width: 100%;
  padding: 14px;
  font-size: 16px;
  font-weight: 600;
  background: var(--color-primary);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition);
}

#join-btn:hover {
  background: var(--color-primary-dark);
}

#join-btn:active {
  transform: scale(0.98);
}

/* Chat Screen */
#chat-screen {
  background: var(--color-bg-alt);
}

/* Header */
.app-header {
  background: var(--color-primary);
  color: white;
  padding: 12px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}

.app-header h1 {
  font-size: 18px;
  font-weight: 600;
}

.header-info {
  font-size: 14px;
  opacity: 0.9;
}

/* Main Content */
.main-content {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

/* Users Sidebar */
.users-sidebar {
  width: 280px;
  background: white;
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sidebar-header h2 {
  font-size: 18px;
  color: var(--color-text);
}

.close-btn {
  display: none;
  background: none;
  border: none;
  font-size: 28px;
  cursor: pointer;
  color: var(--color-text-light);
}

#users-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
}

#users-list li {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--color-border);
  cursor: pointer;
  transition: background var(--transition);
}

#users-list li:hover {
  background: var(--color-bg-alt);
}

#users-list li.current-user {
  background: #dbeafe;
}

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

.user-avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 600;
  font-size: 16px;
}

.user-name {
  font-weight: 500;
  color: var(--color-text);
}

.online-indicator {
  width: 10px;
  height: 10px;
  border-radius: var(--radius-full);
  background: var(--color-success);
}

.call-user-btn {
  background: var(--color-success);
  border: none;
  border-radius: var(--radius-full);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform var(--transition), background var(--transition);
}

.call-user-btn:hover {
  background: #059669;
  transform: scale(1.1);
}

.call-user-btn svg {
  width: 20px;
  height: 20px;
  fill: white;
}

/* Chat Area */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #f1f5f9;
  min-width: 0;
}

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

.message {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  position: relative;
  word-wrap: break-word;
}

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

.message.outgoing .message-time {
  color: rgba(255, 255, 255, 0.7);
}

.message.incoming {
  background: white;
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-sm);
}

.message.system {
  background: #fef3c7;
  color: #92400e;
  align-self: center;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: var(--radius-full);
}

.message-sender {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-primary);
  margin-bottom: 4px;
}

.message-text {
  font-size: 15px;
  line-height: 1.4;
}

.message-time {
  font-size: 11px;
  color: var(--color-text-muted);
  text-align: right;
  margin-top: 4px;
}

/* Message Input */
.message-input-container {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  background: white;
  gap: 8px;
  border-top: 1px solid var(--color-border);
}

#message-input {
  flex: 1;
  padding: 12px 16px;
  font-size: 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  outline: none;
  transition: border-color var(--transition);
}

#message-input:focus {
  border-color: var(--color-primary);
}

.icon-btn {
  background: none;
  border: none;
  padding: 10px;
  cursor: pointer;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
  color: var(--color-text-light);
}

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

.send-btn {
  background: var(--color-primary);
  color: white;
}

.send-btn:hover {
  background: var(--color-primary-dark);
}

/* Video Modal */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.95);
  z-index: 2000;
  justify-content: center;
  align-items: center;
}

.modal.active {
  display: flex;
}

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

#remote-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #1e293b;
}

#local-video {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 120px;
  height: 160px;
  border-radius: var(--radius-md);
  object-fit: cover;
  border: 3px solid white;
  background: #334155;
}

.call-info {
  position: absolute;
  top: 20px;
  left: 20px;
  color: white;
  font-size: 16px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.call-controls {
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 20px;
}

.control-btn {
  width: 60px;
  height: 60px;
  border-radius: var(--radius-full);
  border: none;
  background: rgba(255, 255, 255, 0.2);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), transform var(--transition);
  backdrop-filter: blur(8px);
}

.control-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.1);
}

.control-btn.muted {
  background: var(--color-error);
}

.end-call-btn {
  background: var(--color-error);
}

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

/* Incoming Call Modal */
.incoming-call-container {
  background: white;
  padding: 40px;
  border-radius: var(--radius-lg);
  text-align: center;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.02); }
}

.caller-avatar {
  width: 100px;
  height: 100px;
  margin: 0 auto 20px;
  background: var(--color-primary);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
}

.caller-avatar svg {
  fill: white;
}

.incoming-call-container h2 {
  font-size: 24px;
  color: var(--color-text);
  margin-bottom: 8px;
}

.incoming-call-container p {
  color: var(--color-text-light);
  margin-bottom: 30px;
}

.incoming-call-actions {
  display: flex;
  justify-content: center;
  gap: 40px;
}

.call-action-btn {
  width: 70px;
  height: 70px;
  border-radius: var(--radius-full);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--transition);
}

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

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

.call-action-btn.accept {
  background: var(--color-success);
}

.call-action-btn svg {
  fill: white;
}

/* Mobile Responsive */
@media (max-width: 768px) {
  .users-sidebar {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
  }

  .users-sidebar.open {
    transform: translateX(0);
  }

  .close-btn {
    display: block;
  }

  #show-users-btn {
    display: flex;
  }

  .message {
    max-width: 85%;
  }

  #local-video {
    width: 90px;
    height: 120px;
    top: 10px;
    right: 10px;
  }

  .call-controls {
    bottom: 30px;
    gap: 15px;
  }

  .control-btn {
    width: 50px;
    height: 50px;
  }
}

@media (min-width: 769px) {
  #show-users-btn {
    display: none;
  }
}

/* Safe area for notched devices */
@supports (padding: max(0px)) {
  .message-input-container {
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }

  .call-controls {
    bottom: max(40px, calc(env(safe-area-inset-bottom) + 20px));
  }
}

/* Scrollbar styling */
.messages::-webkit-scrollbar,
#users-list::-webkit-scrollbar {
  width: 6px;
}

.messages::-webkit-scrollbar-track,
#users-list::-webkit-scrollbar-track {
  background: transparent;
}

.messages::-webkit-scrollbar-thumb,
#users-list::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 3px;
}

.messages::-webkit-scrollbar-thumb:hover,
#users-list::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.3);
}
