/* RESET & GLOBAL */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(135deg, #f0f1f1, #392053);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  transition: background 0.3s;
}

body.dark-mode {
  background: #000000;
  background: linear-gradient(135deg, #000000, #1a1a1a);
}

#app {
  width: 100%;
  max-width: 1000px;
  height: 90vh;
  background: rgb(255, 255, 255);
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: background 0.3s, color 0.3s;
}

body.dark-mode #app {
  background: #000000;
  color: #e0e0e0;
  border: 1px solid #333;
}

/* LOGIN SCREEN */
#loginScreen {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 200%;
  padding-top: 20%;
  padding-bottom: 100%;
}

#loginScreen h1 {
  margin-bottom: 30px;
  font-size: 2.5em;
  color: #000000;
}

body.dark-mode #loginScreen h1 {
  color: #9f7aea;
}

#loginScreen input {
  width: 100%;
  max-width: 400px;
  padding: 15px 20px;
  font-size: 16px;
  border: 2px solid #ddd;
  border-radius: 12px;
  margin-bottom: 20px;
  transition: all 0.3s;
}

body.dark-mode #loginScreen input {
  background: #1a1a1a;
  border-color: #333;
  color: #e0e0e0;
}

#loginScreen input:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102,126,234,0.1);
}

body.dark-mode #loginScreen input:focus {
  border-color: #9f7aea;
  box-shadow: 0 0 0 3px rgba(159,122,234,0.2);
}

#loginScreen button {
  padding: 15px 40px;
  font-size: 18px;
  background: linear-gradient(135deg, #d12f23, #e4561d);
  color: white;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

#loginScreen button:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 20px rgba(102,126,234,0.3);
}

/* CHAT UI */
#chatUI {
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
}

/* NAVIGATION TABS */
/* NAVIGATION TABS */
.chat-navigation {
  position: absolute;
  top: 10px;
  left: 15%;     /* ← CHANGED from 'right' to 'left' */
  display: flex;
  gap: 10px;
  z-index: 100;
}

.nav-btn {
  padding:10px 20px 10px 20px;
  font-size: 16px;
  border-radius: 20px;
  border: 1px solid #f5f1f1;
  background: rgba(0, 52, 70, 0.95);
  cursor: pointer;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
  font-weight: 600;
  text-decoration: none;
  color: #ffeded;
}
.nav-btn a{
  text-decoration: none;
  color: white;
}

.nav-btn:hover {
  background: #207575;
  color: white;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(102,126,234,0.3);
}

body.dark-mode .nav-btn {
  background: rgba(0,0,0,0.8);
  border-color: #444;
  color: rgb(223, 218, 218);
}

body.dark-mode .nav-btn:hover {
  background: #246d1b;
  color: white;
}

/* MAIN CHAT */
#mainChat {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* HEADER */
#header {
  background: linear-gradient(135deg, #4b0101, #021447);
  color: rgb(253, 248, 248);
  padding: 8px 5px;
  display: grid;
  grid-column-start:  3;
  grid-template-rows: repeat(4, auto);
  direction: rtl;
}

body.dark-mode #header {
  background: linear-gradient(135deg, #1a1a1a, #2d2d2d);
  border-bottom: 1px solid #333;
}

#status {
  font-size: 14px;
  font-weight: 500;
}

#headerButtons {
  display: flex;
  gap: 10px;
}

#headerButtons button {
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  background: rgba(255,255,255,0.2);
  color: white;
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 14px;
}

#headerButtons button:hover {
  background: rgba(255,255,255,0.3);
  transform: translateY(-1px);
}

/* CHAT BOX */
#chatBox {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background-image: url(backgr.webp);
  transition: background 0.3s;
  display: flex;
  flex-direction: column;
}

body.dark-mode #chatBox {
  background: #000000;
}

.msg {
  padding: 12px 16px;
  border-radius: 12px;
  margin-bottom: 10px;
  max-width: 70%;
  position: relative;
  transition: all 0.3s ease;
  word-wrap: break-word;
  animation: fadeIn 0.3s ease;
}

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

.msg.mine {
  background: linear-gradient(135deg, #a4eb6a, #9ce658);
  color: rgb(0, 0, 0);
  margin-left: auto;
  border-bottom-right-radius: 4px;
  font-weight: 500;
  font-size: 16px;
}

body.dark-mode .msg.mine {
  background: linear-gradient(135deg, rgb(136, 24, 24), #740f0f);
  color: white;
}

.msg.other {
  background: rgb(239, 242, 243);
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  font-size: 15px;
}

body.dark-mode .msg.other {
  background: #0b3f42;
  color: #e0e0e0;
  border: 1px solid #333;
}

/* SYSTEM MESSAGES - CENTERED WITH BORDER */
.msg.system {
  background: rgba(8, 0, 0, 0.1);
  color: #000000;
  max-width: 60%;
  height: 50px;
  margin: 10px auto;
  padding: 1px;
  text-align: center;
  border-radius: 8px;
  border: 1px solid #e0e0e0;
  font-style: italic;
}

body.dark-mode .msg.system {
  background: rgba(255,255,255,0.05);
  color: #888;
  border-color: #333;
}

.msg-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.msg-text {
  line-height: 1.4;
}

.msg-info {
  font-size: 11px;
  opacity: 0.8;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* READ RECEIPTS - BLUR EFFECT */
/* READ RECEIPTS - BLUR EFFECT */
.read-receipt {
  font-size: 8px;
  opacity: 0.6;
  margin-top: 2px;
  filter: blur(0.3px);
  font-style: italic;
  color: #666;    /* ← ADDED for light mode */
}

body.dark-mode .read-receipt {
  opacity: 0.5;
  color: #888;    /* ← CHANGE this for dark mode */
}


/* INPUT AREA */
#inputArea {
  display: flex;
  gap: 10px;
  padding: 20px;
  border-top: 1px solid #e0e0e0;
  background: white;
  transition: background 0.3s;
  align-items: flex-end;
}

body.dark-mode #inputArea {
  background: #000000;
  border-top-color: #333;
}

#chatMsg {
  flex: 1;
  padding: 12px 16px;
  border-radius: 12px;
  border: 2px solid #ddd;
  resize: none;
  transition: all 0.3s;
  font-size: 16px;
  min-height: 44px;
  max-height: 120px;
}

body.dark-mode #chatMsg {
  background: #1a1a1a;
  border-color: #333;
  color: #e0e0e0;
}

#chatMsg:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102,126,234,0.1);
}

body.dark-mode #chatMsg:focus {
  border-color: #9f7aea;
  box-shadow: 0 0 0 3px rgba(159,122,234,0.2);
}

#sendBtn {
  padding: 12px 24px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, #006331, #764ba2);
  color: white;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.3s ease;
  min-height: 44px;
}

#sendBtn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(102,126,234,0.4);
}

body.dark-mode #sendBtn {
  background: linear-gradient(135deg, #2da75c, #62be73);
}

/* TYPING INDICATOR */
#typingIndicator {
  font-style: italic;
  color: #666;
  padding: 10px 20px;
  display: none;
  font-size: 13px;
}

body.dark-mode #typingIndicator {
  color: #888;
}

/* REACTIONS */
.reactions {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.reaction {
  background: rgba(255,255,255,0.8);
  padding: 2px 6px;
  border-radius: 12px;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid #ddd;
}

body.dark-mode .reaction {
  background: rgba(0,0,0,0.6);
  border-color: #444;
  color: #e0e0e0;
}

.reaction:hover {
  transform: scale(1.1);
}

.reaction.active {
  background: #667eea;
  color: white;
}

body.dark-mode .reaction.active {
  background: #9f7aea;
}

.add-reaction {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 11px;
  opacity: 0.6;
  transition: opacity 0.2s;
}

.add-reaction:hover {
  opacity: 1;
}

.reaction-picker {
  display: flex;
  gap: 4px;
  background: white;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 4px;
  position: absolute;
  bottom: 100%;
  margin-bottom: 4px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

body.dark-mode .reaction-picker {
  background: #2d2d2d;
  border-color: #444;
}

.reaction-picker span {
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  transition: background 0.2s;
}

.reaction-picker span:hover {
  background: #f0f0f0;
}

body.dark-mode .reaction-picker span:hover {
  background: #444;
}

/* NEW MESSAGE BUTTON */
.new-message-btn {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, #2ba060, #c6d6c9);
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 25px;
  cursor: pointer;
  z-index: 1000;
  box-shadow: 0 4px 20px rgba(102,126,234,0.4);
  font-weight: bold;
  font-size: 14px;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
}

body.dark-mode .new-message-btn {
  background: linear-gradient(135deg, #9f7aea, #805ad5);
}

.new-message-btn:hover {
  transform: translateX(-50%) translateY(-2px);
  box-shadow: 0 6px 25px rgba(102,126,234,0.6);
}

/* MESSAGE HIGHLIGHT */
.highlight-message {
  animation: highlight-pulse 2s ease-in-out;
  border-left: 3px solid #667eea !important;
}

body.dark-mode .highlight-message {
  border-left: 3px solid #9f7aea !important;
}

@keyframes highlight-pulse {
  0%, 100% { background-color: transparent; }
  50% { background-color: rgba(102,126,234,0.1); }
}

body.dark-mode .highlight-message {
  animation: highlight-pulse-dark 2s ease-in-out;
}

@keyframes highlight-pulse-dark {
  0%, 100% { background-color: transparent; }
  50% { background-color: rgba(159,122,234,0.2); }
}

/* SCROLLBAR */
#chatBox::-webkit-scrollbar {
  width: 8px;
}

#chatBox::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 4px;
}

body.dark-mode #chatBox::-webkit-scrollbar-track {
  background: #1a1a1a;
}

#chatBox::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 4px;
}

#chatBox::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

body.dark-mode #chatBox::-webkit-scrollbar-thumb {
  background: #333;
}

body.dark-mode #chatBox::-webkit-scrollbar-thumb:hover {
  background: #444;
}

/* ONLINE USERS */
.online-dot {
  color: #28a745;
  font-size: 16px;
  margin-right: 8px;
  animation: blink 2s infinite;
}

@keyframes blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0.6; }
}

.current-user {
  font-weight: bold;
  color: #667eea;
}

body.dark-mode .current-user {
  color: #9f7aea;
}

/* RESPONSIVE DESIGN - MOBILE OPTIMIZED */
@media (max-width: 768px) {
  body {
    padding: 0;
  }
  
  #app {
    position: sticky;
    max-width: 100%;           /* Full width */
    border-radius: 0;          /* No rounded corners */
    height: calc(100vh - 30px); /* Full height minus bottom margin */
    margin: 0 0 30px 0;        /* Pushes element up 20px from the bottom */
    padding: 0;                /* Optional, depends on content */
    box-shadow: none;          /* Remove shadow */
    overflow-y: auto;          /* Scroll if content overflows */
  }
  
  .chat-navigation {
    top: 5px;
    right: 5px;
  }
  
  .nav-btn {
    padding:10px 20px 10px 20px;
    font-size: 12px;
  }
  
  #header {
    padding: 15px;
  }
  
  #chatBox {
    padding: 15px 10px;
  }
  
  .msg {
    max-width: 85%;
    padding: 10px 12px;
  }
  
  .msg.system {
    max-width: 80%;
    font-size: 12px;
  }
  
  #inputArea {
    padding: 15px;
    gap: 8px;
    position: sticky;
    bottom: 4px;               /* Stick 4px above the bottom */

  }
  
  #chatMsg {
    padding: 10px 12px;
    font-size: 20px; /* Better for mobile keyboards */
    min-height: 48px; /* Better touch target */
  }
  
  #sendBtn {
    padding: 10px 20px;
    min-height: 48px;
    font-size: 14px;
  }
  
  .new-message-btn {
    bottom: 70px;
    padding: 10px 20px;
    font-size: 13px;
  }
  
  /* Ensure input area is always visible on mobile */
  #inputArea {
    position: sticky;
    bottom: 4px;
    background: inherit;
    border-top: 1px solid #e0e0e0;
  }
  
  body.dark-mode #inputArea {
    border-top-color: #333;
  }
  
  /* Better touch targets for reactions */
  .reaction {
    padding: 4px 8px;
    font-size: 12px;
  }
  
  .msg-info {
  font-size: 12px;    /* ← CHANGED from 11px to 12px */
  opacity: 0.8;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
}

/* Extra small devices */
@media (max-width: 480px) {
  #loginScreen {
  padding-top: 20%;
  padding-bottom: 100%;  }
  
  #loginScreen h1 {
    font-size: 2em;
    text-align: center;
  }
  
  .msg {
    max-width: 90%;
  }
  
  .msg.system {
    max-width: 85%;
  }
  
  .chat-navigation {
    top: 2px;
    right: 2px;
  }
  
  .nav-btn {
      padding:10px 20px 10px 20px;

    font-size: 11px;
  }
}

/* Landscape mode optimization */
@media (max-height: 500px) and (orientation: landscape) {
  #app {
    position: sticky;
    max-width: 100%;           /* Full width */
    border-radius: 0;          /* No rounded corners */
    height: calc(100vh - 0); /* Full height minus bottom margin */
    margin: 0 0 0 0;        /* Pushes element up 20px from the bottom */
    padding: 0;                /* Optional, depends on content */
    box-shadow: none;          /* Remove shadow */
    overflow-y: auto; 
  }
  
  #chatBox {
    padding: 10px;
  }
  
  .msg {
    margin-bottom: 5px;
    padding: 8px 10px;
  }
  
  #inputArea {
    padding: 10px;
    position: sticky;
    bottom: 0;
  }
}

/* High DPI screens */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .msg {
    border: 0.5px solid transparent;
  }
  
  body.dark-mode .msg.other {
    border-width: 0.5px;
  }
}

/* Reduced motion for accessibility */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}