:root {
  /* WhatsApp style variables */
  --header-height: 44px;
  --input-height: 56px;
  --bubble-radius: 8px;
  --max-message-width: 80%;
  --reply-indicator-color: #25D366;
  --whatsapp-green: #128C7E;
  --whatsapp-light: #e6e6e6;
  --whatsapp-dark: #0b141a;
  --safe-area-top: env(safe-area-inset-top, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);

  /* Terminal dark mode variables */
  --terminal-bg: #0a0a0a;
  --terminal-fg: #e0e0e0;
  --terminal-green: #e0e0e0;
  --terminal-blue: #5D8BF4;
  --terminal-light-gray: #555;
}

/* Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  position: fixed;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}

/* WhatsApp Light Mode */
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--whatsapp-light);
  color: #333;
  display: flex;
  flex-direction: column;
}

/* Terminal Dark Mode */
body.dark {
  font-family: 'Courier New', monospace;
  background-color: var(--terminal-bg) !important;
  color: var(--terminal-fg);
}

/* Header - Consistent for both modes */
header {
  height: calc(var(--header-height) + var(--safe-area-top));
  background-color: var(--whatsapp-green);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  position: sticky;
  top: 0;
  z-index: 1000;
  padding-top: var(--safe-area-top);
}

body.dark header {
  background-color: #111;
  border-bottom: 1px solid #333;
}

.header-content {
  display: flex;
  align-items: center;
  width: 100%;
  height: var(--header-height);
}

.header-content i {
  font-size: 20px;
  margin-right: 12px;
  color: white;
}

body.dark .header-content i {
  color: var(--terminal-green);
}

.header-content span {
  font-size: 18px;
  font-weight: 500;
  flex-grow: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

body.dark .header-content span {
  color: var(--terminal-green);
  font-family: 'Courier New', monospace;
}

.header-buttons {
  display: flex;
  gap: 8px;
}

.header-btn {
  background: transparent;
  border: none;
  color: white;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  cursor: pointer;
}

body.dark .header-btn {
  color: var(--terminal-light-gray);
}

/* Chat Container */
.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-top: var(--safe-area-top);
  padding-bottom: var(--safe-area-bottom);
}

.messages-container {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 8px 0;
  display: flex;
  flex-direction: column;
}

/* WhatsApp Message Style */
.message {
  max-width: var(--max-message-width);
  margin: 4px 12px 8px;
  padding: 8px 12px;
  border-radius: var(--bubble-radius);
  background: #fff;
  word-wrap: break-word;
  position: relative;
  align-self: flex-start;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.08);
}

.message.you {
  background: #d9fdd3;
  align-self: flex-end;
}

.message .meta {
  font-size: 12px;
  color: #667781;
  margin-bottom: 4px;
  display: flex;
  justify-content: space-between;
}

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

/* Light mode reply box */
.message-reply {
  background: #f1f1f1;
  border-left: 3px solid var(--whatsapp-green);
  padding: 6px 10px;
  margin-bottom: 8px;
  border-radius: 4px;
}

.reply-sender {
  color: var(--whatsapp-green);
  font-weight: bold;
  margin-right: 6px;
}

.reply-text {
  color: #555;
}

/* Terminal Message Style */
body.dark .message {
  background: transparent;
  max-width: 100%;
  margin: 6px 12px;
  padding: 0;
  border-radius: 0;
  box-shadow: none;
  align-self: flex-start;
  font-family: 'Courier New', monospace;
}

body.dark .message .meta {
  display: flex;
  align-items: baseline;
  margin-bottom: 2px;
  color: #888;
  font-size: 0.9em;
}

body.dark .message .meta strong {
  color: #5D8BF4;
  margin-right: 8px;
}

body.dark .message.you .meta strong {
  color: #e0e0e0;
}

body.dark .message .text {
  margin-left: 20px;
  font-size: 14px;
  line-height: 1.5;
  color: #e0e0e0;
  white-space: pre-wrap;
}

body.dark .message.you .text {
  color: #e0e0e0;
}

/* Terminal-style reply in dark mode */
body.dark .message-reply {
  background: #111;
  border-left: 2px solid #e0e0e0;
  padding: 4px 8px;
  margin-bottom: 8px;
  font-family: 'Courier New', monospace;
}

body.dark .reply-sender {
  color: #5D8BF4;
  font-weight: bold;
  margin-right: 6px;
}

body.dark .reply-text {
  color: #aaa;
}

/* Input Area - Fixed for both modes */
.input-container {
  position: sticky;
  bottom: 0;
  background: #f0f2f5;
  z-index: 1000;
  border-top: 1px solid #e6e6e6;
  padding: 12px;
  padding-bottom: calc(12px + var(--safe-area-bottom));
}

body.dark .input-container {
  background: #111;
  border-top: 1px solid #333;
}

.input-form {
  display: flex;
  align-items: center;
  background: #fff;
  border-radius: 24px;
  padding: 8px 16px;
  width: 100%;
}

body.dark .input-form {
  background: #111;
  border-radius: 0;
  padding: 8px 12px;
  border-top: 1px solid #333;
}

.input-form input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  padding: 8px 0;
  font-size: 16px;
  color: #333;
}

body.dark .input-form input {
  color: #e0e0e0;
  font-family: 'Courier New', monospace;
}

body.dark .input-form::before {
  content: ">";
  color: var(--terminal-green);
  margin-right: 8px;
  font-weight: bold;
}

.input-form input::placeholder {
  color: #999;
}

body.dark .input-form input::placeholder {
  color: var(--terminal-light-gray);
}

.send-btn {
  background: transparent;
  border: none;
  color: var(--whatsapp-green);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  cursor: pointer;
  margin-left: 8px;
}

body.dark .send-btn {
  color: var(--terminal-green);
}

/* Reply Preview */
.reply-preview {
  background: #f1f1f1;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  margin-bottom: 8px;
  border-radius: 8px;
}

body.dark .reply-preview {
  background: #111;
  border-top: 1px solid #333;
  border-radius: 0;
  padding: 8px 12px;
}

.reply-content {
  flex: 1;
  display: flex;
  align-items: center;
}

body.dark .reply-content::before {
  content: ">";
  color: var(--terminal-green);
  margin-right: 8px;
  font-weight: bold;
}

.reply-line {
  width: 4px;
  height: 36px;
  background: var(--reply-indicator-color);
  border-radius: 2px;
  margin-right: 10px;
}

body.dark .reply-line {
  background: var(--terminal-green);
}

.reply-details {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.reply-label {
  font-size: 12px;
  color: #666;
  margin-bottom: 2px;
}

body.dark .reply-label {
  color: var(--terminal-light-gray);
}

#reply-text {
  font-size: 14px;
  color: #333;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

body.dark #reply-text {
  color: #aaa;
}

#reply-user {
  font-weight: bold;
}

body.dark #reply-user {
  color: #5D8BF4;
}

.btn-close {
  background: transparent;
  border: none;
  color: #666;
  width: 32px;
  height: 32px;
  font-size: 18px;
  cursor: pointer;
}

body.dark .btn-close {
  color: var(--terminal-light-gray);
}



.message-status {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin-top: 2px;
  font-size: 11px;
  color: #667781;
  gap: 4px;
}

body.dark .message-status {
  margin-left: 20px;
  color: var(--terminal-light-gray);
  justify-content: flex-start;
}

.seen-icon {
  color: var(--whatsapp-green);
}

body.dark .seen-icon {
  color: var(--terminal-green);
}

.seen-users {
  font-size: 10px;
  color: #999;
  max-width: 120px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

body.dark .seen-users {
  color: var(--terminal-light-gray);
}

/* Typing Indicator */
.typing-indicator {
  max-width: var(--max-message-width);
  margin: 4px 12px 8px;
  padding: 10px 14px;
  border-radius: var(--bubble-radius);
  background: #fff;
  display: flex;
  align-items: center;
  align-self: flex-start;
}

body.dark .typing-indicator {
  background: transparent;
  color: var(--terminal-light-gray);
  font-style: italic;
  padding: 4px 12px;
  margin: 8px 12px;
}

.typing-indicator .dots {
  display: flex;
  margin-right: 8px;
}

.typing-indicator .dot {
  width: 8px;
  height: 8px;
  background: #999;
  border-radius: 50%;
  margin: 0 2px;
  animation: bounce 1.4s infinite ease-in-out both;
}

body.dark .typing-indicator .dots {
  display: none;
}

body.dark .typing-indicator::before {
  content: "$";
  color: var(--terminal-green);
  margin-right: 8px;
  font-weight: bold;
}

.typing-indicator .typing-text {
  color: #666;
  font-size: 14px;
}

body.dark .typing-indicator .typing-text {
  color: var(--terminal-light-gray);
}

/* Swipe to Reply */
.message {
  transition: transform 0.2s ease;
  touch-action: pan-y;
}

/* iOS specific fixes */
@supports (-webkit-touch-callout: none) {
  body {
    padding-bottom: var(--safe-area-bottom);
  }

  .input-container {
    padding-bottom: calc(12px + var(--safe-area-bottom));
  }

  .chat-container {
    padding-bottom: 0;
  }
}

/* ===== DARK MODE MESSAGE FIXES ===== */
body.dark .message {
  background: transparent;
  max-width: 100%;
  margin: 4px 12px;
  padding: 0;
  border-radius: 0;
  box-shadow: none;
  font-family: 'Courier New', monospace;
  word-break: break-word;
}

body.dark .message.system {
  color: #888;
  font-style: italic;
  margin-left: 0;
  padding-left: 0;
}

body.dark .message-content {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  line-height: 1.4;
}

body.dark .message .meta {
  display: inline-flex;
  align-items: baseline;
  color: #888;
  font-size: 0.9em;
  white-space: nowrap;
}

body.dark .message .meta strong {
  color: #5D8BF4;
}

body.dark .message.you .meta strong {
  color: #e0e0e0;
}

body.dark .message .text {
  display: inline;
  color: #e0e0e0;
  margin-left: 4px;
  word-break: break-word;
  flex: 1;
  min-width: 0;
}

body.dark .message.you .text {
  color: #e0e0e0;
}

body.dark .message.you .meta::before {
  content: "> ";
  color: #e0e0e0;
}

body.dark .message:not(.you) .meta::before {
  content: "$ ";
  color: #5D8BF4;
}

body.dark .message.system .meta::before {
  content: "";
}

body.dark .message-status {
  display: inline-flex;
  margin-left: 8px;
  color: #666;
  font-size: 0.8em;
  align-items: center;
}

body.dark .seen-icon {
  color: #e0e0e0;
  margin-right: 4px;
}

body.dark .seen-users {
  color: #666;
  font-style: italic;
}

/* WhatsApp-like UI */
.chat-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

header {
  background: #075e54;
  color: white;
  display: flex;
  align-items: center;
  z-index: 100;
}

.messages-container {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 60px;
}

.input-container {
  background: #f0f0f0;
  padding: 5px 10px;
  display: flex;
  align-items: center;
}




.call-controls {
  display: flex;
  justify-content: center;
  gap: 20px;
  padding: 15px;
  background: rgba(0, 0, 0, 0.5);
}

.call-controls button {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: none;
  background: #333;
  color: white;
  font-size: 18px;
}

/* Input box fixes */
#msg {
  flex: 1;
  border-radius: 20px;
  border: none;
  padding: 8px 15px;
  margin: 0 10px;
  outline: none;
}

.control-btn {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  color: white;
  border: none;
  cursor: pointer;
}

.control-btn:hover {
  background: rgba(0, 0, 0, 0.7);
}

/* Calling UI */
.calling-ui {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: white;
}

.calling-spinner {
  border: 5px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top: 5px solid white;
  width: 50px;
  height: 50px;
  animation: spin 1s linear infinite;
  margin: 0 auto 20px;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

/* Call Ended Alert */
.call-ended-alert {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.alert-content {
  background: white;
  padding: 20px;
  border-radius: 8px;
  text-align: center;
  max-width: 300px;
}


.control-btn {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: none;
  margin: 0 10px;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.audio-btn {
  background: #4CAF50;
  color: white;
}



.end-btn {
  background: #F44336;
  color: white;
}

/* Calling UI */
.calling-ui {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: white;
}

.calling-spinner {
  width: 50px;
  height: 50px;
  border: 5px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: white;
  animation: spin 1s ease-in-out infinite;
  margin-bottom: 20px;
}

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

/* Call ended alert */
.call-ended-alert {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.alert-content {
  background: white;
  padding: 20px;
  border-radius: 8px;
  max-width: 80%;
  text-align: center;
}

/* Audio call specific */
.audio-call-active {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: white;
}

.audio-user {
  font-size: 24px;
  margin-bottom: 30px;
}

.audio-controls {
  display: flex;
}

.fas.fa-paper-plane {
  position: static !important;
  background: none !important;
  padding: 0 !important;
  border-radius: 0 !important;
  box-shadow: none !important;
}
/* Video Call Container Styles */
#video-call-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #000;
  z-index: 2000;
  display: none;
  flex-direction: column;
}

#video-call-container:not(.d-none) {
  display: flex !important;
}

/* Video Grid Layout */
.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 10px;
  padding: 10px;
  width: 100%;
  height: calc(100% - 80px); /* Space for controls */
  overflow-y: auto;
}

/* Video Container Styles */
.video-container {
  position: relative;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  aspect-ratio: 4/3;
}

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

/* Local Video Specific Styles */
.local-video-container {
  order: -1; /* Ensure local video appears first in grid */
}

.local-video-container video {
  transform: scaleX(-1); /* Mirror effect for self-view */
}

/* User Label Styles */
.video-user-label {
  position: absolute;
  bottom: 5px;
  left: 5px;
  color: #fff;
  background: rgba(0, 0, 0, 0.5);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  z-index: 2;
}

/* Video Controls */
.video-controls {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 15px;
  padding: 15px;
  background: rgba(0, 0, 0, 0);
  z-index: 1001;
}

.video-controls button {
  border: none;
  border-radius: 50%;
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

.video-controls button:hover {
  transform: scale(1.1);
}

.video-controls button i {
  font-size: 20px;
}

/* Control Button Specific Styles */
.control-btn.end-btn {
  background-color: #f44336;
  color: white;
}

.control-btn.audio-btn {
  background-color: #2196F3;
  color: white;
}

.control-btn.video-btn {
  background-color: #4CAF50;
  color: white;
}

.control-btn.flip-btn {
  background-color: #FFC107;
  color: black;
}

/* Audio-only Call Styles */
.audio-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #f0f0f0;
  border-radius: 8px;
  padding: 20px;
}

.audio-icon {
  font-size: 24px;
  margin-bottom: 10px;
}

/* Play Button for Video Issues */
.video-play-btn {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0, 0, 0, 0.7);
  color: white;
  border: none;
  border-radius: 50%;
  width: 50px;
  height: 50px;
  font-size: 20px;
  cursor: pointer;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Calling UI Styles */
.calling-ui {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: white;
}

.calling-spinner {
  width: 50px;
  height: 50px;
  border: 5px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: white;
  animation: spin 1s ease-in-out infinite;
  margin-bottom: 20px;
}

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

.calling-text {
  font-size: 18px;
  margin-bottom: 20px;
}

/* Call Ended Alert */
.call-ended-alert {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 3000;
}

.alert-content {
  background: white;
  padding: 20px;
  border-radius: 8px;
  max-width: 80%;
  text-align: center;
}

.dark .alert-content {
  background: #333;
  color: white;
}

/* Responsive Adjustments */
@media (max-width: 768px) {
  .video-grid {
    grid-template-columns: 1fr;
  }
  
  .video-container {
    aspect-ratio: 16/9;
  }
  
  .video-controls button {
    width: 50px;
    height: 50px;
  }
  
  .video-controls button i {
    font-size: 18px;
  }
}
.video-grid.full-screen {
  display: block;
  height: 100%;
  padding: 0;
}
.remote-fullscreen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}
.small-video {
  position: absolute;
  top: 20px;
  left: 20px;
  width: 120px;
  height: 160px;
  z-index: 2;
  border: 2px solid #fff;
  border-radius: 8px;
  box-shadow: 0 2px 5px rgba(0,0,0,0.3);
}
.small-video video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.small-video .video-user-label {
  font-size: 10px;
  padding: 2px 4px;
}
@media (max-width: 768px) {
  .small-video {
    width: 100px;
    height: 133px;
  }
}
.edit {
  border: none;
  color: #075e54;
  background: transparent;
}
/* Sticky Header Fix for iOS Keyboard */
#room-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  transition: all 0.3s ease;
}
.keyboard-active #room-header {
  position: fixed;
  width: 100%;
  background: inherit;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
.keyboard-active .chat-container {
  padding-top: 60px; /* Adjust based on header height */
}

/* Swipe Messages */
.message {
  transition: transform 0.3s ease;
  touch-action: pan-y;
}
.message.you {
  transform-origin: right;
}
.message.other {
  transform-origin: left;
}
.message.swiping {
  transition: none;
}

/* Reply Message Display */
.message-replied {
  background: rgba(0, 150, 255, 0.1);
  border-left: 3px solid #4CAF50;
  margin-bottom: 5px;
  padding-left: 8px;
}
.dark .message-replied {
  background: rgba(0, 100, 0, 0.2);
}
.message-reply-container {
  display: flex;
  flex-direction: column;
  border-left: 3px solid #4CAF50;
  padding-left: 8px;
  margin-bottom: 5px;
  cursor: pointer;
}
.reply-sender {
  font-weight: bold;
  color: #4CAF50;
  font-size: 0.8em;
}
.reply-text {
  color: #555;
  font-size: 0.9em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dark .reply-text {
  color: #ccc;
}

/* Input Container Fix */
#chat-form-container {
  position: sticky;
  bottom: 0;
  background: inherit;
  padding: 10px 0;
  z-index: 900;
}
.keyboard-active #chat-form-container {
  position: fixed;
  width: 100%;
  padding-bottom: env(safe-area-inset-bottom);
}

/* Video Call UI Adjustments */
.video-call-active {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2000;
  background: #000;
}
.keyboard-active .video-call-active {
  bottom: 0;
}

/* Swipe Feedback */
.swipe-feedback {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.7;
}
.swipe-feedback.left {
  left: 0;
  background: linear-gradient(to right, rgba(76, 175, 80, 0.3), transparent);
}
.swipe-feedback.right {
  right: 0;
  background: linear-gradient(to left, rgba(33, 150, 243, 0.3), transparent);
}
.swipe-feedback i {
  font-size: 24px;
  color: white;
}

@media (max-width: 768px) {
  .keyboard-active #room-header {
    padding-top: env(safe-area-inset-top);
  }
  .keyboard-active .chat-container {
    padding-top: calc(60px + env(safe-area-inset-top));
  }
}