/* ============================================
   Punjab Roots Realty — WhatsApp CRM Styles
   Conversation list + Chat panel + Messaging
   ============================================ */

/* ======== STATUS BAR ======== */
.wac-status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, rgba(37,211,102,0.08), rgba(37,211,102,0.02));
  border: 1px solid rgba(37,211,102,0.15);
  gap: 12px;
  flex-wrap: wrap;
}
.wac-status-bar.disconnected {
  background: linear-gradient(135deg, rgba(239,68,68,0.06), rgba(239,68,68,0.02));
  border-color: rgba(239,68,68,0.15);
}
.wac-status-left {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--clr-text-primary);
}
.wac-status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.wac-status-dot.online {
  background: #25D366;
  box-shadow: 0 0 8px rgba(37,211,102,0.5);
  animation: wacPulse 2s ease-in-out infinite;
}
.wac-status-dot.offline {
  background: #EF4444;
  box-shadow: 0 0 6px rgba(239,68,68,0.3);
}
@keyframes wacPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(1.2); }
}
.wac-status-phone {
  font-size: 11px;
  color: var(--clr-text-muted);
  font-family: monospace;
  background: var(--clr-bg-tertiary);
  padding: 2px 8px;
  border-radius: 4px;
}
.wac-status-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ======== MAIN LAYOUT ======== */
.wac-main {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 0;
  height: calc(100vh - 340px);
  min-height: 500px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--clr-border);
  background: var(--clr-bg-card);
  box-shadow: 0 4px 24px rgba(0,0,0,0.06);
}

/* ======== SIDEBAR (Conversation List) ======== */
.wac-sidebar {
  border-right: 1px solid var(--clr-border);
  display: flex;
  flex-direction: column;
  background: var(--clr-bg-secondary);
  min-height: 0;
  height: 100%;
}

.wac-sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--clr-border);
  background: var(--clr-bg-card);
}

.wac-search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--clr-bg-tertiary);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  transition: border-color 0.2s;
}
.wac-search:focus-within {
  border-color: #25D366;
  box-shadow: 0 0 0 3px rgba(37,211,102,0.1);
}
.wac-search .material-icons-round {
  font-size: 18px;
  color: var(--clr-text-muted);
}
.wac-search input {
  border: none;
  background: transparent;
  font-size: 13px;
  color: var(--clr-text-primary);
  width: 100%;
  outline: none;
  font-family: 'Inter', sans-serif;
}

.wac-filters {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.wac-filter-select {
  flex: 1;
  padding: 6px 8px;
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-sm);
  background: var(--clr-bg-card);
  color: var(--clr-text-primary);
  font-size: 11px;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  outline: none;
}
.wac-filter-select:focus {
  border-color: #25D366;
}

/* ======== CONVERSATION LIST ======== */
.wac-convo-list {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
}
.wac-convo-list::-webkit-scrollbar { width: 4px; }
.wac-convo-list::-webkit-scrollbar-thumb { background: var(--clr-border); border-radius: 4px; }

.wac-convo-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  cursor: pointer;
  border-bottom: 1px solid rgba(0,0,0,0.04);
  transition: background 0.15s;
  position: relative;
}
.wac-convo-item:hover {
  background: rgba(37,211,102,0.04);
}
.wac-convo-item.active {
  background: rgba(37,211,102,0.1);
  border-left: 3px solid #25D366;
}
.wac-convo-item.unread {
  background: rgba(37,211,102,0.05);
}

.wac-convo-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
  font-family: 'Outfit', sans-serif;
}

.wac-convo-info {
  flex: 1;
  min-width: 0;
}
.wac-convo-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 3px;
}
.wac-convo-name {
  font-weight: 600;
  font-size: 13px;
  color: var(--clr-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wac-convo-item.unread .wac-convo-name {
  font-weight: 700;
}
.wac-convo-time {
  font-size: 11px;
  color: var(--clr-text-muted);
  white-space: nowrap;
  margin-left: 8px;
}
.wac-convo-item.unread .wac-convo-time {
  color: #25D366;
  font-weight: 600;
}

.wac-convo-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.wac-convo-preview {
  font-size: 12px;
  color: var(--clr-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  line-height: 1.4;
}
.wac-convo-item.unread .wac-convo-preview {
  color: var(--clr-text-secondary);
  font-weight: 500;
}
.wac-convo-badge {
  background: #25D366;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  border-radius: 12px;
  padding: 2px 7px;
  min-width: 18px;
  text-align: center;
  flex-shrink: 0;
  margin-left: 8px;
}

.wac-project-tag {
  display: inline-block;
  margin-top: 4px;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(37,211,102,0.1);
  color: #1a8c46;
  letter-spacing: 0.3px;
}

/* Status Badges */
.wac-status-badge {
  display: inline-block;
  margin-top: 3px;
  margin-left: 4px;
  font-size: 9px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 8px;
  letter-spacing: 0.2px;
}
.wac-status-interested { background: rgba(245,158,11,0.12); color: #D97706; }
.wac-status-not_interested { background: rgba(239,68,68,0.1); color: #DC2626; }
.wac-status-hot_lead { background: rgba(234,179,8,0.12); color: #B45309; }
.wac-status-follow_up { background: rgba(59,130,246,0.1); color: #2563EB; }
.wac-status-replied { background: rgba(99,102,241,0.1); color: #4F46E5; }
.wac-status-converted { background: rgba(34,197,94,0.1); color: #16A34A; }

/* Status Selector in Chat Header */
.wac-status-select {
  padding: 5px 8px;
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-sm);
  background: var(--clr-bg-card);
  color: var(--clr-text-primary);
  font-size: 11px;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  outline: none;
  max-width: 150px;
}
.wac-status-select:focus {
  border-color: #25D366;
}

.wac-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  gap: 8px;
}
.wac-empty p {
  font-size: 13px;
  color: var(--clr-text-muted);
}

.wac-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
}
.wac-loading p {
  font-size: 13px;
  color: var(--clr-text-muted);
}

/* ======== CHAT PANEL ======== */
.wac-chat-panel {
  display: flex;
  flex-direction: column;
  background: var(--clr-bg-card);
  position: relative;
  min-height: 0;
  height: 100%;
}

.wac-chat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  padding: 40px;
  gap: 12px;
}
.wac-chat-empty h3 {
  font-size: 18px;
  color: var(--clr-text-primary);
  font-weight: 600;
}
.wac-chat-empty p {
  font-size: 13px;
  color: var(--clr-text-muted);
  max-width: 300px;
}

/* Chat Header */
.wac-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--clr-border);
  background: var(--clr-bg-card);
  gap: 12px;
  flex-wrap: wrap;
}
.wac-chat-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.wac-back-btn {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--clr-text-muted);
  padding: 4px;
}
.wac-chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
}
.wac-chat-contact h4 {
  font-size: 14px;
  font-weight: 600;
  color: var(--clr-text-primary);
  margin: 0;
}
.wac-chat-phone {
  font-size: 11px;
  color: var(--clr-text-muted);
}

.wac-chat-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}
.wac-tag-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 12px;
  background: linear-gradient(135deg, #25D366, #128C7E);
  color: #fff;
}
.wac-chat-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.wac-tag-select {
  padding: 5px 8px;
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-sm);
  background: var(--clr-bg-card);
  color: var(--clr-text-primary);
  font-size: 11px;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  outline: none;
  max-width: 150px;
}
.wac-action-btn {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--clr-border);
  background: var(--clr-bg-card);
  color: var(--clr-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.wac-action-btn:hover {
  background: rgba(37,211,102,0.08);
  color: #25D366;
  border-color: #25D366;
}
.wac-action-btn .material-icons-round {
  font-size: 18px;
}

/* Chat Messages Container */
.wac-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background:
    linear-gradient(rgba(37,211,102,0.02), transparent),
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 20px,
      rgba(0,0,0,0.008) 20px,
      rgba(0,0,0,0.008) 21px
    );
  display: flex;
  flex-direction: column;
  gap: 6px;
  scrollbar-width: thin;
}
.wac-chat-messages::-webkit-scrollbar { width: 4px; }
.wac-chat-messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.1); border-radius: 4px; }

/* Message Bubbles */
.wac-msg {
  display: flex;
  max-width: 75%;
  animation: wacMsgIn 0.2s ease-out;
}
@keyframes wacMsgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.wac-msg.incoming {
  align-self: flex-start;
}
.wac-msg.outgoing {
  align-self: flex-end;
}

.wac-msg-bubble {
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.5;
  position: relative;
  word-wrap: break-word;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

.wac-msg.incoming .wac-msg-bubble {
  background: #fff;
  border: 1px solid rgba(0,0,0,0.06);
  border-top-left-radius: 4px;
  color: var(--clr-text-primary);
}
.wac-msg.outgoing .wac-msg-bubble {
  background: linear-gradient(135deg, #DCF8C6, #C5E8B0);
  border-top-right-radius: 4px;
  color: #1a1a2e;
}

.wac-msg-text {
  white-space: pre-wrap;
}

.wac-msg-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 4px;
}
.wac-msg-time {
  font-size: 10px;
  color: rgba(0,0,0,0.4);
}
.wac-msg-status {
  font-size: 12px;
  color: rgba(0,0,0,0.3);
}
.wac-msg-status.delivered {
  color: rgba(0,0,0,0.4);
}
.wac-msg-status.read {
  color: #53bdeb;
}
.wac-msg-status.failed {
  color: #EF4444;
}

/* Chat Input Area */
.wac-chat-input-area {
  padding: 12px 20px;
  border-top: 1px solid var(--clr-border);
  background: var(--clr-bg-card);
}
.wac-chat-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--clr-bg-tertiary);
  border: 1px solid var(--clr-border);
  border-radius: 24px;
  padding: 6px 6px 6px 18px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.wac-chat-input-wrap:focus-within {
  border-color: #25D366;
  box-shadow: 0 0 0 3px rgba(37,211,102,0.1);
}
.wac-message-input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 13px;
  color: var(--clr-text-primary);
  outline: none;
  resize: none;
  font-family: 'Inter', sans-serif;
  line-height: 1.4;
  max-height: 120px;
  padding: 6px 0;
}
.wac-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #25D366;
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.1s;
  flex-shrink: 0;
}
.wac-send-btn:hover {
  background: #1da851;
  transform: scale(1.05);
}
.wac-send-btn:active {
  transform: scale(0.95);
}
.wac-send-btn .material-icons-round {
  font-size: 20px;
}

.wac-chat-input-hint {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 6px;
  font-size: 10px;
  color: var(--clr-text-muted);
  padding-left: 4px;
}

.wac-chat-input-disabled {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px;
  color: var(--clr-text-muted);
  font-size: 13px;
  background: var(--clr-bg-tertiary);
  border-radius: var(--radius-md);
}
.wac-chat-input-disabled a {
  color: #25D366;
  font-weight: 600;
}

/* ======== KEYWORD SETTINGS ======== */
.wac-keywords-section {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--clr-border);
}
.wac-keyword-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}
.wac-keyword-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--clr-bg-tertiary);
  border-radius: var(--radius-sm);
  border: 1px solid var(--clr-border);
}
.wac-keyword-text {
  flex: 1;
  font-size: 13px;
  font-weight: 600;
  color: var(--clr-text-primary);
}
.wac-keyword-project {
  font-size: 11px;
  color: var(--clr-text-muted);
  background: rgba(37,211,102,0.1);
  padding: 2px 8px;
  border-radius: 8px;
}
.wac-keyword-remove {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--clr-text-muted);
  padding: 2px;
  display: flex;
  align-items: center;
}
.wac-keyword-remove:hover {
  color: var(--clr-danger);
}
.wac-keyword-add {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.wac-keyword-add input,
.wac-keyword-add select {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-sm);
  background: var(--clr-bg-card);
  color: var(--clr-text-primary);
  font-size: 12px;
  font-family: 'Inter', sans-serif;
  outline: none;
}
.wac-keyword-add input:focus,
.wac-keyword-add select:focus {
  border-color: #25D366;
}

/* ======== RESPONSIVE ======== */
@media (max-width: 768px) {
  .wac-main {
    /* minmax(0,1fr) lets the single track shrink to the container width;
       a bare 1fr resolves to the list's min-content (~540px) and gets clipped. */
    grid-template-columns: minmax(0, 1fr);
    height: calc(100vh - 250px);
    min-height: 420px;
  }
  .wac-sidebar {
    border-right: none;
    min-width: 0;
    max-width: 100%;
  }
  /* On phones the chat opens as a full-screen overlay above everything
     (escapes the .wac-main overflow:hidden because it's position:fixed). */
  .wac-chat-panel {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 2000;
    height: 100%;
  }
  .wac-chat-panel.active {
    display: flex;
  }
  .wac-back-btn {
    display: flex;
  }
  .wac-status-bar {
    flex-direction: column;
    align-items: flex-start;
  }
  .wac-chat-header {
    flex-wrap: nowrap;
    overflow-x: auto;
  }
  .wac-chat-actions {
    flex-wrap: wrap;
  }
}

/* ======== DATE DIVIDERS ======== */
.wac-date-divider {
  display: flex;
  justify-content: center;
  margin: 16px 0;
  width: 100%;
}
.wac-date-divider span {
  background: var(--clr-bg-tertiary, #EDF2F7);
  color: var(--clr-text-secondary, #4A5568);
  font-size: 11px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: var(--radius-sm, 6px);
  box-shadow: var(--shadow-sm, 0 1px 3px rgba(0, 0, 0, 0.06));
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

/* ============ WhatsApp Media (images / video / voice / docs) ============ */
.wac-attach-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: transparent;
  color: #54656f;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s;
  flex-shrink: 0;
}
.wac-attach-btn:hover {
  background: rgba(37, 211, 102, 0.12);
  color: #25D366;
}
.wac-attach-btn .material-icons-round {
  font-size: 22px;
}

.wac-media-img {
  max-width: 240px;
  max-height: 280px;
  border-radius: 10px;
  display: block;
  cursor: pointer;
  object-fit: cover;
  background: rgba(0, 0, 0, 0.04);
}
.wac-media-video {
  max-width: 260px;
  max-height: 300px;
  border-radius: 10px;
  display: block;
  background: #000;
}
.wac-media-audio {
  width: 240px;
  max-width: 100%;
  display: block;
}
.wac-media-doc {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.05);
  color: var(--text-primary, #1f2937);
  text-decoration: none;
  max-width: 240px;
}
.wac-media-doc:hover { background: rgba(0, 0, 0, 0.09); }
.wac-media-doc .material-icons-round { color: #25D366; font-size: 26px; flex-shrink: 0; }
.wac-media-doc span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.85rem;
}
.wac-media-pending {
  padding: 16px 18px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.04);
  color: #54656f;
  font-size: 0.85rem;
  font-style: italic;
}
.wac-msg-ai {
  font-size: 0.65rem;
  font-weight: 700;
  color: #2E7D32;
  background: rgba(46, 125, 50, 0.12);
  border-radius: 4px;
  padding: 1px 5px;
  margin-right: 4px;
  letter-spacing: 0.3px;
}
/* caption sits directly under the media inside the same bubble */
.wac-msg-bubble .wac-media-img + .wac-msg-text,
.wac-msg-bubble .wac-media-video + .wac-msg-text,
.wac-msg-bubble .wac-media-doc + .wac-msg-text {
  margin-top: 6px;
}
