/**
 * app.css - WhatsApp Web Replica Stylesheet
 * High fidelity styling matching WhatsApp Web 2026 UI
 */

:root {
  --wa-green: #00a884;
  --wa-green-dark: #008069;
  --wa-teal: #128c7e;
  --wa-blue-tick: #53bdeb;
  --wa-gray-tick: #8696a0;
  
  /* Dark mode by default */
  --bg-app: #111b21;
  --bg-sidebar: #111b21;
  --bg-header: #202c33;
  --bg-chat: #0b141a;
  --bg-input: #202c33;
  --bg-input-inner: #2a3942;
  --bg-bubble-out: #005c4b;
  --bg-bubble-in: #202c33;
  --bg-active-chat: #2a3942;
  --bg-hover-chat: #202c33;
  --border-color: #222d34;
  --text-primary: #e9edef;
  --text-secondary: #8696a0;
  --text-muted: #667781;
  --shadow-color: rgba(0, 0, 0, 0.3);
  --modal-bg: #222e35;
}

[data-theme="light"] {
  --bg-app: #f0f2f5;
  --bg-sidebar: #ffffff;
  --bg-header: #f0f2f5;
  --bg-chat: #efeae2;
  --bg-input: #f0f2f5;
  --bg-input-inner: #ffffff;
  --bg-bubble-out: #d9fdd3;
  --bg-bubble-in: #ffffff;
  --bg-active-chat: #f0f2f5;
  --bg-hover-chat: #f5f6f6;
  --border-color: #e9edef;
  --text-primary: #111b21;
  --text-secondary: #667781;
  --text-muted: #8696a0;
  --shadow-color: rgba(0, 0, 0, 0.1);
  --modal-bg: #ffffff;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-app);
  color: var(--text-primary);
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-thumb {
  background: rgba(134, 150, 160, 0.3);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(134, 150, 160, 0.5);
}

/* App Container */
.app-container {
  display: flex;
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
}

/* Left Sidebar */
.sidebar {
  width: 420px;
  min-width: 340px;
  max-width: 500px;
  height: 100%;
  border-right: 1px solid var(--border-color);
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 10;
  transition: transform 0.25s ease;
}

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

.user-profile-trigger {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  background: #2a3942;
  position: relative;
}

.avatar-wrapper {
  position: relative;
  display: inline-block;
}

.online-dot {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 11px;
  height: 11px;
  background: #25d366;
  border: 2px solid var(--bg-header);
  border-radius: 50%;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
}

.badge-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 8px;
  height: 8px;
  background: var(--wa-green);
  border-radius: 50%;
}

/* Sidebar Navigation Tabs */
.sidebar-tabs {
  display: flex;
  align-items: center;
  background: var(--bg-sidebar);
  padding: 8px 12px 4px 12px;
  gap: 6px;
  overflow-x: auto;
}

.tab-btn {
  padding: 6px 14px;
  background: var(--bg-header);
  color: var(--text-secondary);
  border: none;
  border-radius: 18px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
}

.tab-btn.active {
  background: rgba(0, 168, 132, 0.2);
  color: var(--wa-green);
  font-weight: 600;
}

/* Search Bar */
.search-container {
  padding: 8px 12px;
  background: var(--bg-sidebar);
}

.search-box {
  display: flex;
  align-items: center;
  background: var(--bg-header);
  border-radius: 8px;
  padding: 6px 12px;
  gap: 10px;
  border: 1px solid transparent;
}

.search-box:focus-within {
  border-color: var(--wa-green);
}

.search-box input {
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 14px;
  width: 100%;
}

.search-box input::placeholder {
  color: var(--text-muted);
}

/* Chat List */
.chat-list {
  flex: 1;
  overflow-y: auto;
  list-style: none;
}

.chat-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-color);
  transition: background 0.15s;
  position: relative;
}

.chat-item:hover {
  background: var(--bg-hover-chat);
}

.chat-item.active {
  background: var(--bg-active-chat);
}

.chat-item-avatar {
  margin-right: 14px;
  position: relative;
}

.chat-item-content {
  flex: 1;
  min-width: 0;
}

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

.chat-item-name {
  font-size: 16px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item-time {
  font-size: 12px;
  color: var(--text-muted);
}

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

.chat-item-snippet {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 4px;
}

.unread-badge {
  background: var(--wa-green);
  color: #111b21;
  font-size: 11px;
  font-weight: bold;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
}

/* Main Chat Area */
.main-chat {
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--bg-chat);
  position: relative;
}

/* Placeholder when no chat selected */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  padding: 32px;
  background: var(--bg-header);
  border-bottom: 6px solid var(--wa-green);
}

.empty-state-icon {
  font-size: 72px;
  margin-bottom: 24px;
  color: var(--wa-green);
}

.empty-state h1 {
  font-size: 32px;
  font-weight: 300;
  color: var(--text-primary);
  margin-bottom: 12px;
}

.empty-state p {
  color: var(--text-secondary);
  font-size: 14px;
  max-width: 500px;
  line-height: 1.6;
}

.empty-state .security-badge {
  margin-top: 40px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 13px;
}

/* Active Chat View */
.chat-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
}

.chat-header {
  height: 60px;
  background: var(--bg-header);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-color);
  z-index: 5;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  flex: 1;
  min-width: 0;
}

.chat-header-text {
  min-width: 0;
}

.chat-header-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-header-subtitle {
  font-size: 12px;
  color: var(--wa-green);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Chat Messages Container with Authentic Wallpaper Pattern */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px 50px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background-color: var(--bg-chat);
  background-image: radial-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px);
  background-size: 20px 20px;
  position: relative;
}

.date-divider {
  align-self: center;
  background: var(--bg-header);
  color: var(--text-secondary);
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 8px;
  margin: 12px 0;
  box-shadow: 0 1px 2px var(--shadow-color);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.encryption-notice {
  align-self: center;
  background: rgba(254, 230, 0, 0.1);
  color: #f7a600;
  font-size: 12px;
  padding: 8px 16px;
  border-radius: 8px;
  max-width: 480px;
  text-align: center;
  margin-bottom: 12px;
  line-height: 1.4;
}

/* Message Bubbles */
.message-bubble {
  max-width: 65%;
  min-width: 90px;
  padding: 8px 12px 6px 12px;
  border-radius: 8px;
  position: relative;
  font-size: 14.2px;
  line-height: 1.45;
  word-wrap: break-word;
  box-shadow: 0 1px 2px var(--shadow-color);
  display: flex;
  flex-direction: column;
}

.message-bubble.incoming {
  align-self: flex-start;
  background: var(--bg-bubble-in);
  color: var(--text-primary);
  border-top-left-radius: 0;
}

.message-bubble.outgoing {
  align-self: flex-end;
  background: var(--bg-bubble-out);
  color: var(--text-primary);
  border-top-right-radius: 0;
}

.sender-name-label {
  font-size: 12.5px;
  font-weight: 600;
  color: #ff8b3d;
  margin-bottom: 3px;
}

.message-reply-preview {
  background: rgba(0, 0, 0, 0.2);
  border-left: 4px solid var(--wa-green);
  border-radius: 4px;
  padding: 4px 8px;
  margin-bottom: 6px;
  font-size: 12px;
  cursor: pointer;
}

.message-text {
  white-space: pre-wrap;
  margin-bottom: 2px;
}

.message-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  user-select: none;
}

.message-bubble.outgoing .message-meta {
  color: rgba(255, 255, 255, 0.6);
}

.tick-icon {
  font-size: 13px;
  line-height: 1;
}

.tick-icon.blue {
  color: var(--wa-blue-tick) !important;
}

/* Voice Note Component */
.voicenote-player {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 2px;
  min-width: 260px;
}

.voicenote-play-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--wa-green);
  color: #ffffff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.voicenote-wave-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.voicenote-wave-bars {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 24px;
}

.wave-bar {
  flex: 1;
  background: rgba(255, 255, 255, 0.4);
  border-radius: 2px;
  transition: height 0.1s, background 0.1s;
}

.wave-bar.played {
  background: var(--wa-green);
}

.voicenote-timing {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-secondary);
}

.voicenote-speed {
  background: rgba(255, 255, 255, 0.12);
  border: none;
  color: var(--text-primary);
  border-radius: 12px;
  padding: 2px 6px;
  font-size: 11px;
  cursor: pointer;
  font-weight: bold;
}

/* Media Messages (Photo / Video / Document) */
.media-image-preview {
  max-width: 320px;
  max-height: 320px;
  border-radius: 6px;
  cursor: pointer;
  object-fit: cover;
  margin-bottom: 4px;
}

.media-document-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(0, 0, 0, 0.15);
  padding: 10px 14px;
  border-radius: 6px;
  cursor: pointer;
  margin-bottom: 4px;
}

.document-icon {
  font-size: 28px;
}

.document-details {
  flex: 1;
}

.document-filename {
  font-weight: 500;
  font-size: 14px;
}

.document-filesize {
  font-size: 11px;
  color: var(--text-muted);
}

/* Reactions */
.reaction-pill {
  position: absolute;
  bottom: -10px;
  right: 10px;
  background: var(--bg-header);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 2px 6px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  box-shadow: 0 1px 3px var(--shadow-color);
}

/* Message Hover Actions */
.message-actions-trigger {
  position: absolute;
  top: 4px;
  right: 4px;
  opacity: 0;
  background: var(--bg-header);
  border: none;
  color: var(--text-secondary);
  border-radius: 50%;
  width: 24px;
  height: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s;
}

.message-bubble:hover .message-actions-trigger {
  opacity: 1;
}

/* Input Bar */
.chat-input-bar {
  background: var(--bg-input);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
  z-index: 5;
}

.input-field-wrapper {
  flex: 1;
  background: var(--bg-input-inner);
  border-radius: 8px;
  padding: 9px 14px;
  display: flex;
  align-items: center;
}

.chat-textarea {
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 15px;
  resize: none;
  max-height: 100px;
  line-height: 1.4;
  font-family: inherit;
}

.chat-textarea::placeholder {
  color: var(--text-muted);
}

/* Voice Note Live Recording Bar */
.recording-bar {
  display: none;
  flex: 1;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-input-inner);
  border-radius: 8px;
  padding: 8px 16px;
}

.recording-timer-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.record-pulse-dot {
  width: 12px;
  height: 12px;
  background: #ff3b30;
  border-radius: 50%;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.3); opacity: 0.6; }
  100% { transform: scale(1); opacity: 1; }
}

.recording-time {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-primary);
}

.recording-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Attachment Menu */
.attachment-popover {
  position: absolute;
  bottom: 70px;
  left: 60px;
  background: var(--bg-header);
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  display: none;
  flex-direction: column;
  gap: 12px;
  z-index: 20;
}

.attachment-item {
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  padding: 6px 12px;
  border-radius: 8px;
  transition: background 0.15s;
}

.attachment-item:hover {
  background: rgba(255, 255, 255, 0.08);
}

.attachment-icon-circle {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: #ffffff;
}

/* Emoji Picker Popover */
.emoji-popover {
  position: absolute;
  bottom: 70px;
  left: 16px;
  width: 320px;
  height: 280px;
  background: var(--bg-header);
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  display: none;
  flex-direction: column;
  z-index: 20;
  overflow: hidden;
}

.emoji-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
  padding: 12px;
  overflow-y: auto;
}

.emoji-btn {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  transition: transform 0.1s;
}

.emoji-btn:hover {
  transform: scale(1.25);
  background: rgba(255, 255, 255, 0.1);
}

/* Modals & Overlays */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}

.modal-content {
  background: var(--modal-bg);
  border-radius: 12px;
  width: 90%;
  max-width: 520px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-header {
  height: 56px;
  background: var(--bg-header);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid var(--border-color);
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  max-height: 75vh;
}

/* WhatsApp Calling Interface */
.call-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: #0f1c24;
  z-index: 200;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 40px 20px;
}

.call-header-info {
  text-align: center;
}

.call-contact-name {
  font-size: 26px;
  font-weight: 600;
  color: #ffffff;
  margin-top: 14px;
}

.call-status-label {
  font-size: 15px;
  color: #8696a0;
  margin-top: 6px;
}

.call-avatar-pulse {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  border: 4px solid var(--wa-green);
  box-shadow: 0 0 20px rgba(0, 168, 132, 0.6);
  animation: pulseCall 1.8s infinite;
}

@keyframes pulseCall {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(0, 168, 132, 0.7); }
  70% { transform: scale(1.05); box-shadow: 0 0 0 25px rgba(0, 168, 132, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(0, 168, 132, 0); }
}

.video-call-streams {
  width: 100%;
  height: 60%;
  display: none;
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  background: #000000;
}

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

.local-video {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 140px;
  height: 190px;
  border-radius: 8px;
  object-fit: cover;
  border: 2px solid #ffffff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.call-controls-bar {
  display: flex;
  align-items: center;
  gap: 24px;
  background: rgba(32, 44, 51, 0.85);
  padding: 12px 28px;
  border-radius: 36px;
  backdrop-filter: blur(8px);
}

.call-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: #ffffff;
  transition: transform 0.1s;
}

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

.call-btn.hangup {
  background: #ea4335;
}

.call-btn.control {
  background: rgba(255, 255, 255, 0.15);
}

/* Device Login Screen Overlay */
.auth-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: #111b21;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
}

.auth-card {
  background: #202c33;
  border-radius: 16px;
  padding: 36px;
  width: 90%;
  max-width: 500px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  text-align: center;
}

.auth-qr-frame {
  background: #ffffff;
  padding: 16px;
  border-radius: 12px;
  display: inline-block;
  margin: 20px 0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.btn-primary {
  background: var(--wa-green);
  color: #111b21;
  font-weight: 600;
  border: none;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 15px;
  cursor: pointer;
  width: 100%;
  margin-top: 12px;
  transition: background 0.15s;
}

.btn-primary:hover {
  background: #00bf96;
}

.btn-secondary {
  background: transparent;
  color: var(--wa-green);
  border: 1px solid var(--wa-green);
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  width: 100%;
  margin-top: 10px;
}

/* Quick User Pickers on Login */
.quick-users-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
  justify-content: center;
}

.quick-user-chip {
  background: #2a3942;
  border: 1px solid #3b4a54;
  color: #e9edef;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}

.quick-user-chip:hover {
  background: var(--wa-green);
  color: #111b21;
}

/* Stories / Status Viewer */
.status-viewer-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: #000000;
  z-index: 250;
  display: none;
  flex-direction: column;
}

.status-progress-bar {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  width: 100%;
}

.status-progress-segment {
  flex: 1;
  height: 3px;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 2px;
  overflow: hidden;
}

.status-progress-fill {
  height: 100%;
  background: #ffffff;
  width: 0%;
  transition: width 0.1s linear;
}

.status-content-display {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  font-size: 28px;
  color: #ffffff;
  text-align: center;
}

/* Mobile responsive */
@media (max-width: 768px) {
  .sidebar {
    width: 100%;
    max-width: 100%;
  }
  .main-chat {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 20;
  }
  .main-chat.mobile-active {
    display: flex;
  }
  .messages-container {
    padding: 12px 14px;
  }
  .message-bubble {
    max-width: 85%;
  }
}
