/* ═══════════════════════════════════════════
   WhatsApp Web Clone — CSS
   ═══════════════════════════════════════════ */

:root {
  --wa-dark-green: #00a884;
  --wa-light-green: #d9fdd3;
  --wa-teal: #008069;
  --wa-header-bg: #202c33;
  --wa-panel-bg: #111b21;
  --wa-chat-bg: #0b141a;
  --wa-sidebar-bg: #111b21;
  --wa-input-bg: #2a3942;
  --wa-hover-bg: #202c33;
  --wa-active-bg: #2a3942;
  --wa-border: #222d34;
  --wa-text-primary: #e9edef;
  --wa-text-secondary: #8696a0;
  --wa-bubble-outgoing: #005c4b;
  --wa-bubble-incoming: #202c33;
  --wa-icon: #aebac1;
  --wa-search-bg: #202c33;
  --wa-typing-indicator: #00a884;
  --wa-unread-badge: #00a884;
}

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

body {
  font-family: 'Segoe UI', Helvetica, Arial, sans-serif;
  background: #222e35;
  color: var(--wa-text-primary);
  height: 100vh;
  overflow: hidden;
}

.app-container {
  display: flex;
  height: 100vh;
  max-width: 100%;
  margin: 0 auto;
  background: var(--wa-chat-bg);
}

/* ─── SIDEBAR ─── */
.sidebar {
  width: 440px;
  min-width: 340px;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--wa-border);
  background: var(--wa-sidebar-bg);
}

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

.sidebar-header .user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--wa-input-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--wa-icon);
  font-size: 20px;
}

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

.icon-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: none;
  color: var(--wa-icon);
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  transition: background 0.2s;
}
.icon-btn:hover { background: rgba(255,255,255,0.05); }

/* Search */
.search-container {
  padding: 8px 12px;
  background: var(--wa-sidebar-bg);
  border-bottom: 1px solid var(--wa-border);
}

.search-box {
  display: flex;
  align-items: center;
  background: var(--wa-search-bg);
  border-radius: 8px;
  padding: 0 12px;
  height: 36px;
}

.search-box svg { color: var(--wa-text-secondary); flex-shrink: 0; }

.search-box input {
  flex: 1;
  border: none;
  background: none;
  color: var(--wa-text-primary);
  padding: 0 12px;
  font-size: 14px;
  outline: none;
}
.search-box input::placeholder { color: var(--wa-text-secondary); }

/* Contact List */
.contact-list {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}

.contact-list::-webkit-scrollbar { width: 6px; }
.contact-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }

.contact-item {
  display: flex;
  align-items: center;
  padding: 10px 16px;
  cursor: pointer;
  transition: background 0.15s;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}
.contact-item:hover { background: var(--wa-hover-bg); }
.contact-item.active { background: var(--wa-active-bg); }

.contact-avatar {
  width: 49px;
  height: 49px;
  border-radius: 50%;
  background: #2a3942;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--wa-icon);
  font-size: 22px;
  flex-shrink: 0;
  margin-right: 14px;
  position: relative;
}

.contact-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.contact-top-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

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

.contact-time {
  font-size: 12px;
  color: var(--wa-text-secondary);
  flex-shrink: 0;
  margin-left: 6px;
}
.contact-time.unread { color: var(--wa-unread-badge); }

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

.contact-preview {
  font-size: 13.5px;
  color: var(--wa-text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

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

/* ─── CHAT PANEL ─── */
.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--wa-chat-bg);
  position: relative;
}

/* Empty state */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--wa-text-secondary);
  gap: 16px;
}

.empty-state svg { width: 320px; opacity: 0.15; }
.empty-state h2 { font-weight: 300; font-size: 28px; color: var(--wa-text-primary); }
.empty-state p { font-size: 14px; max-width: 500px; text-align: center; line-height: 1.6; }

/* Chat header */
.chat-header {
  display: flex;
  align-items: center;
  padding: 10px 16px;
  height: 60px;
  background: var(--wa-header-bg);
  border-bottom: 1px solid var(--wa-border);
}

.chat-header .contact-avatar { margin-right: 14px; width: 40px; height: 40px; font-size: 18px; }

.chat-header-info { flex: 1; }
.chat-header-info .name { font-size: 16px; font-weight: 400; }
.chat-header-info .phone { font-size: 13px; color: var(--wa-text-secondary); }

.chat-header-actions { display: flex; gap: 4px; }

/* Messages area */
.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px 60px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
  background-image: url("data:image/svg+xml,%3Csvg width='200' height='200' xmlns='http://www.w3.org/2000/svg'%3E%3Cdefs%3E%3Cpattern id='p' width='40' height='40' patternUnits='userSpaceOnUse'%3E%3Ccircle cx='20' cy='20' r='1' fill='rgba(255,255,255,0.015)'/%3E%3C/pattern%3E%3C/defs%3E%3Crect width='200' height='200' fill='url(%23p)'/%3E%3C/svg%3E");
}

.messages-area::-webkit-scrollbar { width: 6px; }
.messages-area::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }

.date-divider {
  text-align: center;
  margin: 12px 0;
}
.date-divider span {
  background: #182229;
  color: var(--wa-text-secondary);
  padding: 5px 12px;
  border-radius: 8px;
  font-size: 12.5px;
  box-shadow: 0 1px 1px rgba(0,0,0,0.1);
}

.message-row {
  display: flex;
  margin-bottom: 1px;
}
.message-row.outgoing { justify-content: flex-end; }
.message-row.incoming { justify-content: flex-start; }

.message-bubble {
  max-width: 65%;
  padding: 6px 8px 8px 9px;
  border-radius: 8px;
  position: relative;
  word-wrap: break-word;
  line-height: 1.35;
  font-size: 14.2px;
  box-shadow: 0 1px 0.5px rgba(0,0,0,0.13);
}

.message-row.outgoing .message-bubble {
  background: var(--wa-bubble-outgoing);
  border-top-right-radius: 0;
}
.message-row.incoming .message-bubble {
  background: var(--wa-bubble-incoming);
  border-top-left-radius: 0;
}

/* First message in a group gets the tail */
.message-row.outgoing.first-in-group .message-bubble { border-top-right-radius: 0; }
.message-row.incoming.first-in-group .message-bubble { border-top-left-radius: 0; }

.message-text {
  margin-right: 58px;
  white-space: pre-wrap;
}

.message-image {
  max-width: 330px;
  border-radius: 6px;
  margin-bottom: 4px;
  cursor: pointer;
}
.message-image img {
  width: 100%;
  border-radius: 6px;
  display: block;
}

.message-caption {
  margin-top: 4px;
  margin-right: 58px;
}

.message-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  float: right;
  margin-top: 2px;
  margin-left: 8px;
  position: relative;
  top: 5px;
}

.message-time {
  font-size: 11px;
  color: rgba(255,255,255,0.45);
}

.message-status {
  font-size: 16px;
  line-height: 1;
}
.message-status.sent { color: rgba(255,255,255,0.4); }
.message-status.delivered { color: rgba(255,255,255,0.4); }
.message-status.read { color: #53bdeb; }

/* ─── INPUT AREA ─── */
.input-area {
  display: flex;
  align-items: flex-end;
  padding: 8px 16px;
  background: var(--wa-header-bg);
  gap: 8px;
  border-top: 1px solid var(--wa-border);
}

.input-area .icon-btn { flex-shrink: 0; }

.message-input-wrapper {
  flex: 1;
  background: var(--wa-input-bg);
  border-radius: 8px;
  padding: 9px 12px;
  display: flex;
  align-items: flex-end;
}

.message-input {
  flex: 1;
  border: none;
  background: none;
  color: var(--wa-text-primary);
  font-size: 15px;
  resize: none;
  outline: none;
  max-height: 120px;
  line-height: 1.4;
  font-family: inherit;
}
.message-input::placeholder { color: var(--wa-text-secondary); }

.send-btn {
  width: 42px;
  height: 42px;
  border: none;
  background: none;
  color: var(--wa-icon);
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
  transition: color 0.2s;
}
.send-btn:hover { color: var(--wa-dark-green); }

/* Image preview */
.image-preview-bar {
  display: none;
  align-items: center;
  padding: 8px 16px;
  background: var(--wa-header-bg);
  border-top: 1px solid var(--wa-border);
  gap: 12px;
}
.image-preview-bar.visible { display: flex; }

.image-preview-bar img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 8px;
}

.image-preview-bar .preview-info {
  flex: 1;
  color: var(--wa-text-secondary);
  font-size: 13px;
}

.image-preview-bar .remove-btn {
  color: #ef4444;
  cursor: pointer;
  font-size: 22px;
  background: none;
  border: none;
  padding: 4px;
}

/* ─── NEW CHAT MODAL ─── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 100;
  justify-content: center;
  align-items: center;
}
.modal-overlay.active { display: flex; }

.modal {
  background: var(--wa-panel-bg);
  border-radius: 12px;
  padding: 24px;
  width: 420px;
  max-width: 90vw;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

.modal h3 {
  font-size: 18px;
  font-weight: 500;
  margin-bottom: 20px;
  color: var(--wa-text-primary);
}

.modal-input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--wa-border);
  border-radius: 8px;
  background: var(--wa-input-bg);
  color: var(--wa-text-primary);
  font-size: 15px;
  outline: none;
  margin-bottom: 12px;
}
.modal-input:focus { border-color: var(--wa-dark-green); }
.modal-input::placeholder { color: var(--wa-text-secondary); }

.modal-hint {
  font-size: 13px;
  color: var(--wa-text-secondary);
  margin-bottom: 20px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.btn {
  padding: 10px 24px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-primary {
  background: var(--wa-dark-green);
  color: white;
}
.btn-primary:hover { background: #00c49a; }
.btn-secondary {
  background: var(--wa-input-bg);
  color: var(--wa-text-primary);
}
.btn-secondary:hover { background: var(--wa-hover-bg); }

/* ─── IMAGE VIEWER OVERLAY ─── */
.image-viewer {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.9);
  z-index: 200;
  justify-content: center;
  align-items: center;
  cursor: pointer;
}
.image-viewer.active { display: flex; }
.image-viewer img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 4px;
}

/* ─── TOASTS ─── */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  padding: 12px 20px;
  border-radius: 8px;
  color: white;
  font-size: 14px;
  animation: slideIn 0.3s ease;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.toast.error { background: #dc3545; }
.toast.success { background: var(--wa-dark-green); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ─── RESPONSIVE ─── */
@media (max-width: 768px) {
  .sidebar { width: 100%; max-width: 100%; }
  .chat-panel { display: none; position: absolute; inset: 0; z-index: 50; }
  .chat-panel.active { display: flex; }
  .messages-area { padding: 12px 16px; }
  .message-bubble { max-width: 85%; }
  .back-btn { display: flex !important; }
}
@media (min-width: 769px) {
  .back-btn { display: none !important; }
}
