/* ============================================
   أنماط تطبيق الدردشة الفورية
   تصميم حديث مع Glassmorphism
   ============================================ */

/* ============ شاشة تسجيل الدخول ============ */
.chat-login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--bg);
  position: relative;
  overflow: hidden;
}
.chat-login::before {
  content: '';
  position: absolute;
  width: 500px; height: 500px;
  background: radial-gradient(circle, rgba(0,255,136,.08), transparent 70%);
  top: -100px; right: -100px;
  border-radius: 50%;
  animation: float-bg 8s ease-in-out infinite alternate;
}
.chat-login::after {
  content: '';
  position: absolute;
  width: 400px; height: 400px;
  background: radial-gradient(circle, rgba(56,189,248,.06), transparent 70%);
  bottom: -80px; left: -80px;
  border-radius: 50%;
  animation: float-bg 10s ease-in-out infinite alternate-reverse;
}
@keyframes float-bg {
  0% { transform: translate(0, 0) scale(1); }
  100% { transform: translate(30px, -20px) scale(1.1); }
}

.chat-login-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 50px 40px;
  max-width: 440px;
  width: 100%;
  text-align: center;
  position: relative;
  z-index: 1;
  backdrop-filter: blur(20px);
  box-shadow: 0 25px 60px rgba(0,0,0,.4);
  animation: fadeUp .6s ease;
}
.chat-login-icon {
  font-size: 4rem;
  margin-bottom: 15px;
  animation: bounce-in .8s ease;
}
@keyframes bounce-in {
  0% { transform: scale(0); }
  50% { transform: scale(1.3); }
  100% { transform: scale(1); }
}
.chat-login-card h1 {
  font-size: 1.8rem;
  font-weight: 900;
  margin-bottom: 8px;
  background: linear-gradient(135deg, var(--primary), #38bdf8);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.chat-login-card p {
  color: var(--text-2);
  margin-bottom: 30px;
  font-size: .95rem;
}
.chat-login-form {
  text-align: right;
}
.form-field {
  margin-bottom: 20px;
}
.form-field label {
  display: block;
  font-weight: 700;
  margin-bottom: 8px;
  font-size: .9rem;
  color: var(--text-2);
}
.form-field input {
  width: 100%;
  padding: 14px 18px;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: var(--bg-3);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  transition: .3s;
}
.form-field input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(0,255,136,.1);
}
.color-picker {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}
.color-opt {
  width: 36px; height: 36px;
  border-radius: 50%;
  cursor: pointer;
  transition: .3s;
  border: 3px solid transparent;
  position: relative;
}
.color-opt:hover {
  transform: scale(1.15);
}
.color-opt.selected {
  border-color: var(--text);
  box-shadow: 0 0 12px rgba(0,0,0,.3);
}
.color-opt.selected::after {
  content: '✓';
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  color: #000;
  font-weight: 900;
  font-size: .85rem;
}

.chat-login-btn {
  width: 100%;
  padding: 15px;
  border-radius: 12px;
  border: none;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: var(--on-primary);
  font-family: var(--font);
  font-size: 1.1rem;
  font-weight: 900;
  cursor: pointer;
  transition: .3s;
  margin-top: 10px;
}
.chat-login-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 30px rgba(0,255,136,.3);
}
.chat-login-btn:active {
  transform: translateY(0);
}
.back-link {
  display: inline-block;
  margin-top: 25px;
  color: var(--text-3);
  font-size: .9rem;
  transition: .2s;
}
.back-link:hover {
  color: var(--primary);
}

/* ============ تطبيق الدردشة ============ */
.chat-app {
  display: flex;
  height: calc(100vh - 80px);
  overflow: hidden;
}

/* ============ الشريط الجانبي ============ */
.chat-sidebar {
  width: 280px;
  background: var(--bg-2);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform .3s ease;
}
.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.sidebar-header h3 {
  font-size: 1.1rem;
  font-weight: 900;
}
.sidebar-close {
  display: none;
  background: none;
  border: none;
  color: var(--text-2);
  font-size: 1.3rem;
  cursor: pointer;
}
.rooms-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
}
.room-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 12px;
  cursor: pointer;
  transition: .25s;
  margin-bottom: 4px;
  position: relative;
}
.room-item:hover {
  background: var(--bg-3);
}
.room-item.active {
  background: rgba(0,255,136,.08);
  border: 1px solid rgba(0,255,136,.2);
}
.room-item .room-emoji {
  font-size: 1.5rem;
  flex-shrink: 0;
}
.room-item .room-details {
  flex: 1;
  min-width: 0;
}
.room-item .room-title {
  font-weight: 700;
  font-size: .95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.room-item.active .room-title {
  color: var(--primary);
}
.room-item .room-meta {
  font-size: .78rem;
  color: var(--text-3);
  margin-top: 2px;
}
.room-badge {
  background: var(--primary);
  color: var(--on-primary);
  font-size: .7rem;
  font-weight: 900;
  padding: 2px 7px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
}
.sidebar-footer {
  padding: 15px 20px;
  border-top: 1px solid var(--border);
}
.online-count {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .85rem;
  color: var(--text-2);
}
.pulse-dot {
  width: 10px; height: 10px;
  background: #22c55e;
  border-radius: 50%;
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(34,197,94,.4); }
  50% { box-shadow: 0 0 0 8px rgba(34,197,94,0); }
}

/* ============ المنطقة الرئيسية ============ */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
}
.chat-header {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 15px 24px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.4rem;
  cursor: pointer;
}
.room-info {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
}
.room-icon {
  font-size: 1.8rem;
}
.room-info h2 {
  font-size: 1.15rem;
  font-weight: 900;
  margin: 0;
}
.room-desc {
  font-size: .8rem;
  color: var(--text-3);
}
.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
.online-users {
  display: flex;
  direction: ltr;
}
.online-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: .7rem;
  color: #000;
  margin-right: -8px;
  border: 2px solid var(--bg-2);
  transition: .2s;
}
.online-avatar:hover {
  transform: translateY(-3px);
  z-index: 1;
}
.sound-toggle, .logout-btn {
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text-2);
  width: 38px; height: 38px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 1rem;
  transition: .2s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sound-toggle:hover, .logout-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* ============ منطقة الرسائل ============ */
.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  position: relative;
  scroll-behavior: smooth;
}
.messages-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 100%;
  justify-content: flex-end;
}

/* رسالة واحدة */
.msg {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  animation: msg-in .3s ease;
  max-width: 85%;
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
.msg-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: .85rem;
  color: #000;
  flex-shrink: 0;
}
.msg-content {
  flex: 1;
  min-width: 0;
}
.msg-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 4px;
}
.msg-author {
  font-weight: 900;
  font-size: .9rem;
}
.msg-time {
  font-size: .72rem;
  color: var(--text-3);
}
.msg-text {
  background: var(--bg-2);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 4px 16px 16px 16px;
  font-size: .95rem;
  line-height: 1.7;
  word-wrap: break-word;
  overflow-wrap: break-word;
}
.msg.own {
  flex-direction: row-reverse;
  margin-right: auto;
  margin-left: 0;
}
.msg.own .msg-header {
  flex-direction: row-reverse;
}
.msg.own .msg-text {
  background: rgba(0,255,136,.08);
  border-color: rgba(0,255,136,.15);
  border-radius: 16px 4px 16px 16px;
}

/* رسالة نظام */
.msg-system {
  text-align: center;
  color: var(--text-3);
  font-size: .8rem;
  padding: 8px;
  opacity: .7;
}
.msg-system span {
  background: var(--bg-2);
  padding: 4px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
}

/* فاصل التاريخ */
.date-separator {
  text-align: center;
  margin: 16px 0;
  position: relative;
}
.date-separator::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 0; right: 0;
  height: 1px;
  background: var(--border);
}
.date-separator span {
  background: var(--bg);
  padding: 4px 16px;
  font-size: .78rem;
  color: var(--text-3);
  position: relative;
  z-index: 1;
}

/* زر التمرير للأسفل */
.scroll-bottom {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--primary);
  color: var(--on-primary);
  width: 44px; height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.2rem;
  box-shadow: 0 5px 20px rgba(0,0,0,.3);
  transition: .3s;
  opacity: 0;
  pointer-events: none;
}
.scroll-bottom.visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  pointer-events: auto;
}
.scroll-bottom:hover {
  transform: translateX(-50%) translateY(-4px);
}

/* ============ حقل الإرسال ============ */
.chat-input-area {
  padding: 0 24px 20px;
  flex-shrink: 0;
  position: relative;
}
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  font-size: .82rem;
  color: var(--text-3);
}
.typing-dots {
  display: flex;
  gap: 3px;
}
.typing-dots i {
  width: 6px; height: 6px;
  background: var(--text-3);
  border-radius: 50%;
  display: block;
  animation: typing-bounce .6s ease-in-out infinite;
}
.typing-dots i:nth-child(2) { animation-delay: .15s; }
.typing-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes typing-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

.chat-form {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-2);
  border: 2px solid var(--border);
  border-radius: 16px;
  padding: 6px 10px 6px 6px;
  transition: .3s;
}
.chat-form:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(0,255,136,.08);
}
.emoji-btn {
  font-size: 1.4rem;
  cursor: pointer;
  transition: .2s;
  flex-shrink: 0;
  padding: 6px;
  border-radius: 8px;
}
.emoji-btn:hover {
  background: var(--bg-3);
  transform: scale(1.1);
}
.chat-form input {
  flex: 1;
  padding: 10px 8px;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  outline: none;
}
.chat-form input::placeholder {
  color: var(--text-3);
}
.chat-form button[type="submit"] {
  background: var(--primary);
  color: var(--on-primary);
  border: none;
  width: 42px; height: 42px;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: .25s;
  flex-shrink: 0;
}
.chat-form button[type="submit"]:hover {
  background: var(--primary-2);
  transform: scale(1.05);
}
.chat-form button[type="submit"]:active {
  transform: scale(0.95);
}

/* ============ لوحة الإيموجي ============ */
.emoji-panel {
  position: absolute;
  bottom: 80px;
  right: 24px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px;
  width: 320px;
  max-height: 250px;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0,0,0,.4);
  z-index: 10;
  animation: fadeUp .2s ease;
}
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
}
.emoji-grid span {
  font-size: 1.4rem;
  padding: 6px;
  text-align: center;
  cursor: pointer;
  border-radius: 8px;
  transition: .15s;
}
.emoji-grid span:hover {
  background: var(--bg-3);
  transform: scale(1.2);
}

/* ============ رسالة فارغة ============ */
.empty-chat {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-3);
  gap: 12px;
}
.empty-chat .empty-icon {
  font-size: 4rem;
  opacity: .5;
  animation: bounce-in .8s ease;
}
.empty-chat p {
  font-size: 1.1rem;
}

/* ============ Scrollbar مخصص ============ */
.messages-area::-webkit-scrollbar,
.rooms-list::-webkit-scrollbar,
.emoji-panel::-webkit-scrollbar {
  width: 6px;
}
.messages-area::-webkit-scrollbar-track,
.rooms-list::-webkit-scrollbar-track,
.emoji-panel::-webkit-scrollbar-track {
  background: transparent;
}
.messages-area::-webkit-scrollbar-thumb,
.rooms-list::-webkit-scrollbar-thumb,
.emoji-panel::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 10px;
}
.messages-area::-webkit-scrollbar-thumb:hover,
.rooms-list::-webkit-scrollbar-thumb:hover {
  background: var(--text-3);
}

/* ============ استجابة ============ */
@media (max-width: 768px) {
  .chat-sidebar {
    position: fixed;
    top: 80px;
    right: 0;
    bottom: 0;
    z-index: 50;
    transform: translateX(100%);
    box-shadow: -5px 0 30px rgba(0,0,0,.3);
  }
  .chat-sidebar.open {
    transform: translateX(0);
  }
  .sidebar-toggle,
  .sidebar-close {
    display: block;
  }
  .chat-login-card {
    padding: 35px 25px;
  }
  .msg {
    max-width: 95%;
  }
  .emoji-panel {
    width: calc(100% - 48px);
    right: 24px;
    left: 24px;
  }
  .online-users {
    display: none;
  }
}
