/* Design System System-wide Variables */
:root {
  --font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --bg-color: #060913;
  --glass-bg: rgba(15, 22, 38, 0.65);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  --primary-color: #97cf30; /* Custom Accent Green */
  --whatsapp-green: #97cf30;
  --text-main: #f5f5f7;
  --text-muted: #8e8e93;
  --bubble-incoming: rgba(30, 41, 59, 0.7);
  --bubble-outgoing: rgba(151, 207, 48, 0.2);
  --border-radius-lg: 20px;
  --border-radius-md: 14px;
  --border-radius-sm: 8px;
}

/* Base Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-color);
  color: var(--text-main);
  height: 100vh;
  overflow: hidden;
  position: relative;
}

/* Background Glowing Blobs */
.blob {
  position: absolute;
  width: 500px;
  height: 500px;
  border-radius: 50%;
  filter: blur(120px);
  z-index: 0;
  opacity: 0.15;
  pointer-events: none;
  animation: float 20s infinite alternate;
}

.blob-green {
  background-color: var(--whatsapp-green);
  top: -10%;
  left: -10%;
}

.blob-purple {
  background-color: #af52de; /* Apple Purple */
  bottom: -10%;
  right: -10%;
  animation-delay: -10s;
}

@keyframes float {
  0% { transform: translate(0, 0) scale(1); }
  100% { transform: translate(80px, 50px) scale(1.1); }
}

/* LOGIN LAYOUT */
.login-body {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  width: 100vw;
}

.login-container {
  z-index: 10;
  width: 100%;
  max-width: 420px;
  padding: 20px;
}

.login-card {
  background: var(--glass-bg);
  backdrop-filter: blur(25px);
  -webkit-backdrop-filter: blur(25px);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  border-radius: var(--border-radius-lg);
  padding: 40px 30px;
  text-align: center;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.login-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 40px 0 rgba(0, 0, 0, 0.45);
}

.login-header {
  margin-bottom: 30px;
}

.app-logo {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  width: 80px;
  height: 80px;
  border-radius: 22px;
  background: linear-gradient(135deg, var(--whatsapp-green), #60851e);
  color: white;
  box-shadow: 0 8px 16px rgba(151, 207, 48, 0.3);
  margin-bottom: 20px;
}

.login-header h1 {
  font-size: 1.8rem;
  font-weight: 700;
  margin-bottom: 8px;
  letter-spacing: -0.5px;
}

.login-header p {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.input-group {
  margin-bottom: 20px;
}

.input-group input {
  width: 100%;
  padding: 16px 20px;
  border-radius: var(--border-radius-md);
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.05);
  color: white;
  font-family: var(--font-family);
  font-size: 1rem;
  text-align: center;
  transition: border-color 0.2s, background-color 0.2s;
}

.input-group input:focus {
  outline: none;
  border-color: var(--primary-color);
  background: rgba(255, 255, 255, 0.08);
}

.btn-submit {
  width: 100%;
  padding: 16px;
  border-radius: var(--border-radius-md);
  border: none;
  background: linear-gradient(135deg, var(--primary-color), #60851e);
  color: white;
  font-family: var(--font-family);
  font-weight: 600;
  font-size: 1rem;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(151, 207, 48, 0.3);
  transition: transform 0.1s active, opacity 0.2s;
}

.btn-submit:hover {
  opacity: 0.9;
}

.btn-submit:active {
  transform: scale(0.98);
}

.error-msg {
  color: #ff453a; /* Apple Red */
  font-size: 0.85rem;
  margin-top: 15px;
  font-weight: 500;
}

/* APP MAIN LAYOUT */
.app-container {
  display: flex;
  height: 100vh;
  width: 100vw;
  z-index: 10;
  position: relative;
  background: rgba(11, 15, 25, 0.3);
}

/* Sidebar Styling */
.sidebar {
  width: 350px;
  border-right: 1px solid var(--glass-border);
  background: var(--glass-bg);
  backdrop-filter: blur(25px);
  -webkit-backdrop-filter: blur(25px);
  display: flex;
  flex-direction: column;
  height: 100%;
}

.sidebar-header {
  padding: 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

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

.profile-info h2 {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--primary-color);
  color: white;
  display: flex;
  justify-content: center;
  align-items: center;
  font-weight: 600;
  font-size: 1.1rem;
}

.btn-icon {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 50%;
  width: 38px;
  height: 38px;
  color: var(--text-main);
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition: background-color 0.2s;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.1);
}

.search-box {
  padding: 0 20px 20px 20px;
}

.search-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.search-input-wrapper svg {
  position: absolute;
  left: 15px;
  color: var(--text-muted);
}

.search-input-wrapper input {
  width: 100%;
  padding: 12px 16px 12px 42px;
  border-radius: var(--border-radius-md);
  border: 1px solid rgba(255, 255, 255, 0.05);
  background: rgba(255, 255, 255, 0.05);
  color: white;
  font-family: var(--font-family);
  font-size: 0.9rem;
  transition: background-color 0.2s;
}

.search-input-wrapper input:focus {
  outline: none;
  background: rgba(255, 255, 255, 0.08);
}

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

/* Scrollbar customizations */
.chat-list::-webkit-scrollbar,
.messages-area::-webkit-scrollbar,
.modal-body::-webkit-scrollbar {
  width: 6px;
}

.chat-list::-webkit-scrollbar-thumb,
.messages-area::-webkit-scrollbar-thumb,
.modal-body::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

/* Chat Card */
.chat-card {
  padding: 16px;
  border-radius: var(--border-radius-md);
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.2s;
  margin-bottom: 4px;
}

.chat-card:hover {
  background: rgba(255, 255, 255, 0.04);
}

.chat-card.active {
  background: rgba(255, 255, 255, 0.08);
}

.chat-card-info {
  flex: 1;
  min-width: 0; /* Enables text overflow truncation */
}

.chat-card-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}

.chat-card-header h3 {
  font-size: 0.98rem;
  font-weight: 600;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

.chat-time {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.chat-card-preview {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-card-preview p {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  flex: 1;
}

/* Badges on Chat Cards */
.badge-status {
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 6px;
  font-weight: 600;
  margin-left: 8px;
}

.badge-status-edited {
  background: rgba(0, 122, 255, 0.2);
  color: #30b0ff;
}

.badge-status-deleted {
  background: rgba(255, 69, 58, 0.2);
  color: #ff453a;
}

/* CHAT WINDOW STYLING */
.chat-window {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: rgba(11, 15, 25, 0.5);
  height: 100%;
}

.welcome-screen {
  display: flex;
  justify-content: center;
  align-items: center;
  flex: 1;
  padding: 40px;
  text-align: center;
}

.welcome-card {
  max-width: 480px;
}

.welcome-icon {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-muted);
  margin-bottom: 24px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.welcome-card h3 {
  font-size: 1.6rem;
  font-weight: 700;
  margin-bottom: 12px;
  letter-spacing: -0.4px;
}

.welcome-card p {
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1.5;
  margin-bottom: 30px;
}

.btn-pwa-install {
  padding: 12px 24px;
  border-radius: var(--border-radius-md);
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.05);
  color: white;
  font-family: var(--font-family);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background-color 0.2s;
}

.btn-pwa-install:hover {
  background: rgba(255, 255, 255, 0.1);
}

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

.chat-header {
  padding: 18px 24px;
  background: var(--glass-bg);
  backdrop-filter: blur(25px);
  -webkit-backdrop-filter: blur(25px);
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
  gap: 16px;
  z-index: 10;
}

.active-contact-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.active-contact-info h3 {
  font-size: 1.05rem;
  font-weight: 600;
}

.active-contact-info p {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* Messages area with Whatsapp wallpaper feel */
.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background-image: radial-gradient(rgba(255,255,255,0.015) 1px, transparent 0);
  background-size: 24px 24px;
}

/* Message Bubble Wrappers */
.message-row {
  display: flex;
  width: 100%;
  margin-bottom: 4px;
}

.message-row-incoming {
  justify-content: flex-start;
}

.message-row-outgoing {
  justify-content: flex-end;
}

/* Message Bubble cards */
.message-bubble {
  max-width: 65%;
  padding: 12px 16px;
  border-radius: 16px;
  position: relative;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.message-row-incoming .message-bubble {
  background: var(--bubble-incoming);
  border-top-left-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.03);
}

.message-row-outgoing .message-bubble {
  background: var(--bubble-outgoing);
  border-top-right-radius: 4px;
  border: 1px solid rgba(151, 207, 48, 0.25);
}

/* Message Content */
.message-sender {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--primary-color);
  margin-bottom: 2px;
}

.message-row-outgoing .message-sender {
  display: none; /* Hide our own name in our bubbles */
}

.message-text {
  font-size: 0.95rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.message-footer {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.message-time {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* Message status indicators */
.message-status-badge {
  font-size: 0.68rem;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 4px;
  text-transform: uppercase;
}

.badge-edit {
  background: rgba(151, 207, 48, 0.15);
  color: var(--whatsapp-green);
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
}

.badge-edit:hover {
  opacity: 0.85;
}

.badge-edit:active {
  transform: scale(0.95);
}

.badge-delete {
  background: rgba(255, 69, 58, 0.15);
  color: #ff453a;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
}

.badge-delete:hover {
  opacity: 0.85;
}

.badge-delete:active {
  transform: scale(0.95);
}

/* Media styling inside chat bubbles */
.media-attachment {
  margin-top: 4px;
  border-radius: var(--border-radius-sm);
  overflow: hidden;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  flex-direction: column;
}

.media-image {
  max-width: 100%;
  max-height: 250px;
  object-fit: cover;
  cursor: zoom-in;
}

.media-audio {
  padding: 8px;
  width: 100%;
  min-width: 200px;
}

.media-document {
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
}

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

.doc-info p {
  font-size: 0.85rem;
  font-weight: 600;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

.doc-info span {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.btn-download-doc {
  color: var(--primary-color);
}

/* MODAL / OVERLAY FOR EDIT HISTORY */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 100;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

.modal-card {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  border-radius: var(--border-radius-lg);
  width: 100%;
  max-width: 500px;
  display: flex;
  flex-direction: column;
  max-height: 80vh;
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  font-size: 1.15rem;
  font-weight: 700;
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
}

/* Timeline Revisions Design */
.timeline {
  position: relative;
  padding-left: 24px;
}

.timeline::before {
  content: '';
  position: absolute;
  left: 7px;
  top: 6px;
  bottom: 6px;
  width: 2px;
  background: rgba(255, 255, 255, 0.1);
}

.timeline-item {
  position: relative;
  margin-bottom: 24px;
}

.timeline-item:last-child {
  margin-bottom: 0;
}

.timeline-dot {
  position: absolute;
  left: -24px;
  top: 4px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--bg-color);
  border: 3px solid var(--primary-color);
}

.timeline-item-deleted .timeline-dot {
  border-color: #ff453a;
}

.timeline-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
}

.timeline-status {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
}

.timeline-time {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.timeline-content {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: var(--border-radius-md);
  padding: 12px 16px;
  font-size: 0.92rem;
  line-height: 1.4;
  white-space: pre-wrap;
}

/* Loading Spinners */
.loading-spinner-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  gap: 12px;
  color: var(--text-muted);
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(255, 255, 255, 0.08);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* MOBILE AND RESPONSIVENESS */
.mobile-only {
  display: none;
}

@media (max-width: 768px) {
  .mobile-only {
    display: block;
  }
  
  .sidebar {
    width: 100vw;
    position: absolute;
    left: 0;
    top: 0;
    z-index: 20;
    transition: transform 0.3s ease;
  }

  .app-container.chat-active .sidebar {
    transform: translateX(-100%);
  }

  .chat-window {
    width: 100vw;
    position: absolute;
    left: 0;
    top: 0;
    z-index: 10;
  }

  .message-bubble {
    max-width: 85%;
  }
}

/* NEW CLASSES FOR EDITED & DELETED MESSAGE STATES AND INLINE TIMELINE */
.message-bubble.is-edited {
  background: rgba(151, 207, 48, 0.08);
  border-left: 3px solid var(--whatsapp-green);
  box-shadow: 0 4px 12px rgba(151, 207, 48, 0.15);
}

.message-row-outgoing .message-bubble.is-edited {
  background: rgba(151, 207, 48, 0.22);
}

.message-bubble.is-deleted {
  background: rgba(255, 69, 58, 0.08);
  border-left: 3px solid #ff453a;
  box-shadow: 0 4px 12px rgba(255, 69, 58, 0.1);
  border-top-right-radius: 16px;
}

.message-row-outgoing .message-bubble.is-deleted {
  background: rgba(255, 69, 58, 0.12);
  border-top-right-radius: 16px;
}

.message-deleted-header {
  color: #ff453a;
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
  letter-spacing: -0.2px;
}

.message-deleted-header svg {
  color: #ff453a;
}

.message-text.is-deleted {
  text-decoration: line-through;
  opacity: 0.5;
  font-style: italic;
}

.media-attachment.media-is-deleted {
  opacity: 0.4;
  filter: grayscale(80%) blur(0.5px);
  pointer-events: none;
}

/* History Drawer Styles */
.history-drawer {
  margin-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: 8px;
  overflow: hidden;
}

.drawer-inner {
  padding: 4px 0 2px 0;
}

.drawer-title {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.drawer-item {
  background: rgba(0, 0, 0, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: 10px;
  padding: 8px 12px;
  margin-bottom: 6px;
  font-size: 0.85rem;
}

.drawer-item:last-child {
  margin-bottom: 0;
}

.drawer-item-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
  align-items: center;
}

.drawer-item-label {
  font-weight: 600;
  color: var(--whatsapp-green);
  font-size: 0.75rem;
}

.drawer-item-time {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.drawer-item-content {
  white-space: pre-wrap;
  word-break: break-word;
  color: rgba(255, 255, 255, 0.9);
  line-height: 1.35;
}

.drawer-media-preview {
  margin-top: 6px;
  font-size: 0.72rem;
}

.drawer-media-preview a {
  color: var(--whatsapp-green);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-weight: 500;
}

.drawer-media-preview a:hover {
  text-decoration: underline;
}
