/* ============================================================
   waAPI — Custom Styles  (AdminLTE 4 + WhatsApp Chat UI)
   ============================================================ */

/* ── AdminLTE 4 nav-icon fix (Bootstrap Icons) ───────────── */
.nav-icon {
  margin-right: 8px;
  font-size: 1rem;
  width: 1.25rem;
  text-align: center;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ── General cards / tables ──────────────────────────────── */
.small-box .icon i { font-size: 3.5rem; }
.card { border-radius: 8px; }
.table th {
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
pre { white-space: pre-wrap; word-break: break-word; }

/* ============================================================
   CHAT PAGE — Full-height layout fix for AdminLTE 4
   AdminLTE 4 uses CSS Grid. app-main sits in the 1fr row.
   We override it to flex so chat-wrapper can fill the height.
   ============================================================ */
body.chat-page {
  overflow: hidden;
}

body.chat-page .app-wrapper {
  height: 100vh;
  overflow: hidden;
}

body.chat-page .app-main {
  display: flex !important;
  flex-direction: column;
  overflow: hidden !important;
  padding: 0 !important;
  min-height: 0;
}

body.chat-page .app-footer {
  display: none; /* hide footer on chat page — saves space */
}

/* ── Chat wrapper ────────────────────────────────────────── */
.chat-wrapper {
  display: flex;
  flex: 1;
  min-height: 0;
  background: #f0f2f5;
}

/* ============================================================
   LEFT PANEL — Conversations list
   ============================================================ */
.conv-panel {
  width: 320px;
  min-width: 320px;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-right: 1px solid #e9edef;
  overflow: hidden;
  flex-shrink: 0;
}

/* Panel top-bar */
.conv-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: #f0f2f5;
  border-bottom: 1px solid #e9edef;
  min-height: 52px;
  flex-shrink: 0;
}

.conv-topbar-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: #111b21;
}

.conv-topbar-actions {
  display: flex;
  gap: 4px;
}

.conv-icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: #54656f;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.05rem;
  transition: background 0.15s;
}
.conv-icon-btn:hover { background: #e9edef; color: #111b21; }

/* Search box */
.conv-search {
  padding: 6px 12px 8px;
  background: #fff;
  flex-shrink: 0;
}

.conv-search-inner {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f0f2f5;
  border-radius: 8px;
  padding: 6px 12px;
}

.conv-search-inner i {
  color: #54656f;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.conv-search-inner input {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  font-size: 0.85rem;
  color: #111b21;
}

.conv-search-inner input::placeholder { color: #8696a0; }

/* List */
.conv-list {
  flex: 1;
  overflow-y: auto;
}

/* Each conversation row */
.conv-item {
  display: flex;
  align-items: center;
  padding: 10px 12px 10px 16px;
  cursor: pointer;
  gap: 12px;
  border-bottom: 1px solid rgba(0,0,0,.04);
  transition: background 0.1s;
  position: relative;
}

.conv-item:hover  { background: #f5f6f6; }
.conv-item.active { background: #f0f2f5; }

.conv-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #dfe5e7;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  color: #667781;
  flex-shrink: 0;
  overflow: hidden;
}

.conv-avatar-initials {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #6c757d;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
}

.conv-body {
  flex: 1;
  min-width: 0;
  border-bottom: 1px solid #e9edef;
  padding-bottom: 10px;
}

.conv-item:last-child .conv-body { border-bottom: none; }

.conv-row1 {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 2px;
}

.conv-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: #111b21;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.conv-time {
  font-size: 0.7rem;
  color: #667781;
  flex-shrink: 0;
  padding-left: 6px;
  white-space: nowrap;
}

.conv-row2 {
  display: flex;
  align-items: center;
  gap: 4px;
}

.conv-preview {
  font-size: 0.78rem;
  color: #667781;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.conv-tick {
  font-size: 0.78rem;
  color: #8696a0;
  flex-shrink: 0;
}

/* ============================================================
   WELCOME SCREEN
   ============================================================ */
.chat-welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #f0f2f5;
  color: #667781;
  text-align: center;
  padding: 40px 24px;
  border-left: 1px solid #e9edef;
}

.chat-welcome-icon {
  width: 200px;
  height: 200px;
  border-radius: 50%;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 28px;
  box-shadow: 0 4px 24px rgba(0,0,0,.08);
}

.chat-welcome h4 {
  font-weight: 300;
  font-size: 1.5rem;
  color: #41525d;
  margin-bottom: 8px;
}

.chat-welcome p {
  font-size: 0.85rem;
  color: #667781;
  max-width: 340px;
  line-height: 1.6;
}

/* ============================================================
   RIGHT PANEL — Active Chat
   ============================================================ */
.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* Chat header */
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: #f0f2f5;
  border-bottom: 1px solid #e9edef;
  min-height: 58px;
  flex-shrink: 0;
  z-index: 2;
}

.chat-header-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #dfe5e7;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  color: #667781;
  flex-shrink: 0;
  cursor: pointer;
}

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

.chat-contact-name {
  font-weight: 600;
  font-size: 0.95rem;
  color: #111b21;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-contact-sub {
  font-size: 0.75rem;
  color: #667781;
}

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

/* ── Messages area ──────────────────────────────────────── */
.messages-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  padding: 8px 0 4px;
  /* WhatsApp background */
  background-color: #efeae2;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='400'%3E%3Cdefs%3E%3Cpattern id='p' width='80' height='80' patternUnits='userSpaceOnUse'%3E%3Cpath d='M0 40 Q20 20 40 40 Q60 60 80 40' fill='none' stroke='%23c9b99a' stroke-width='.6' opacity='.25'/%3E%3Cpath d='M0 60 Q20 40 40 60 Q60 80 80 60' fill='none' stroke='%23c9b99a' stroke-width='.6' opacity='.2'/%3E%3C/pattern%3E%3C/defs%3E%3Crect width='400' height='400' fill='url(%23p)'/%3E%3C/svg%3E");
}

/* ── Date separator ──────────────────────────────────────── */
.date-sep {
  display: flex;
  justify-content: center;
  padding: 12px 0 4px;
}

.date-sep span {
  background: rgba(11, 20, 26, .16);
  color: #111b21;
  font-size: 0.72rem;
  font-weight: 500;
  padding: 4px 12px;
  border-radius: 6px;
  box-shadow: 0 1px 2px rgba(0,0,0,.1);
  backdrop-filter: blur(4px);
  background: #fff;
}

/* ── Message bubbles ─────────────────────────────────────── */
.bubble-wrap {
  display: flex;
  padding: 1px 6%;
}

.bubble-wrap-in  { justify-content: flex-start; }
.bubble-wrap-out { justify-content: flex-end; }

.bubble {
  position: relative;
  max-width: 65%;
  min-width: 72px;
  padding: 6px 10px 22px 10px;
  border-radius: 7.5px;
  word-break: break-word;
  font-size: 0.875rem;
  line-height: 1.5;
  box-shadow: 0 1px 2px rgba(0,0,0,.13);
}

/* Inbound — white */
.bubble-in {
  background: #fff;
  border-top-left-radius: 0;
  color: #111b21;
}

/* Outbound — green tint */
.bubble-out {
  background: #d9fdd3;
  border-top-right-radius: 0;
  color: #111b21;
}

/* Tails */
.bubble-in::before {
  content: '';
  position: absolute;
  top: 0; left: -8px;
  width: 0; height: 0;
  border-style: solid;
  border-width: 0 9px 9px 0;
  border-color: transparent #fff transparent transparent;
}

.bubble-out::before {
  content: '';
  position: absolute;
  top: 0; right: -8px;
  width: 0; height: 0;
  border-style: solid;
  border-width: 9px 9px 0 0;
  border-color: #d9fdd3 transparent transparent transparent;
}

/* Time + status — pinned bottom-right of bubble */
.bubble-meta {
  position: absolute;
  bottom: 4px;
  right: 8px;
  display: flex;
  align-items: center;
  gap: 3px;
  white-space: nowrap;
  pointer-events: none;
}

.bubble-time {
  font-size: 0.67rem;
  color: rgba(17,27,33,.5);
  line-height: 1;
}

.bubble-in  .bubble-time { color: rgba(17,27,33,.5); }
.bubble-out .bubble-time { color: rgba(17,27,33,.5); }

.bubble-tick {
  font-size: 0.82rem;
  line-height: 1;
  color: #8696a0;
  display: flex;
  align-items: center;
}

.bubble-tick .bi-check2-all.read-tick { color: #53bdeb; }

/* text padding to clear the meta line */
.bubble-text {
  display: block;
  padding-right: 52px; /* make room for time+tick */
}

/* single-line short messages need min padding */
.bubble-text:only-child { padding-right: 60px; }

/* Media inside bubbles */
.bubble-img {
  max-width: 260px;
  max-height: 260px;
  border-radius: 6px;
  display: block;
  cursor: zoom-in;
  object-fit: cover;
  margin-bottom: 18px; /* room for meta */
}

.bubble-video {
  max-width: 280px;
  border-radius: 6px;
  display: block;
  margin-bottom: 18px;
}

.bubble-audio {
  max-width: 240px;
  display: block;
  margin-bottom: 18px;
  width: 100%;
}

.bubble-doc-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(0,0,0,.04);
  padding: 8px 10px;
  border-radius: 6px;
  text-decoration: none;
  color: #111b21;
  margin-bottom: 18px;
  min-width: 160px;
  max-width: 260px;
}

.bubble-doc-wrap:hover { background: rgba(0,0,0,.08); color: #111b21; }

.bubble-doc-icon {
  font-size: 2rem;
  color: #667781;
  flex-shrink: 0;
}

.bubble-doc-name {
  font-size: 0.82rem;
  word-break: break-word;
  flex: 1;
}

.bubble-caption {
  font-size: 0.82rem;
  color: #111b21;
  margin-top: 4px;
  padding-right: 52px;
}

/* ── Chat input area ─────────────────────────────────────── */
.chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 16px 10px;
  background: #f0f2f5;
  flex-shrink: 0;
  border-top: none;
}

.chat-input-box {
  flex: 1;
  display: flex;
  align-items: flex-end;
  gap: 0;
  background: #fff;
  border-radius: 24px;
  box-shadow: 0 1px 3px rgba(0,0,0,.1);
  padding: 4px 6px 4px 14px;
  min-height: 44px;
}

.chat-input-box textarea {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font-size: 0.9rem;
  background: transparent;
  line-height: 1.5;
  max-height: 130px;
  min-height: 34px;
  padding: 6px 4px;
  color: #111b21;
  align-self: center;
}

.chat-input-box textarea::placeholder { color: #8696a0; }

.btn-attach-inner {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: #54656f;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.15rem;
  flex-shrink: 0;
  transition: color 0.15s;
  align-self: flex-end;
  margin-bottom: 1px;
}

.btn-attach-inner:hover { color: #111b21; }

.btn-send-chat {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: none;
  background: #00a884;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
  box-shadow: 0 2px 6px rgba(0,168,132,.35);
}

.btn-send-chat:hover    { background: #017f65; }
.btn-send-chat:active   { transform: scale(.94); }
.btn-send-chat:disabled { background: #b2dfdb; box-shadow: none; cursor: not-allowed; }

/* ── Lightbox ────────────────────────────────────────────── */
#lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.92);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
}

#lightbox img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 4px;
  box-shadow: 0 8px 40px rgba(0,0,0,.6);
}

#lightbox-close {
  position: absolute;
  top: 16px;
  right: 22px;
  color: #fff;
  font-size: 2.2rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.15s;
}
#lightbox-close:hover { opacity: 1; }

/* ── Toast ───────────────────────────────────────────────── */
.toast-fixed {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9998;
  min-width: 220px;
}

/* ── Thin scrollbars ─────────────────────────────────────── */
.conv-list::-webkit-scrollbar,
.messages-area::-webkit-scrollbar { width: 6px; }
.conv-list::-webkit-scrollbar-thumb,
.messages-area::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,.18);
  border-radius: 3px;
}
.conv-list::-webkit-scrollbar-track,
.messages-area::-webkit-scrollbar-track { background: transparent; }

/* ── Mobile (<= 768px) ───────────────────────────────────── */
@media (max-width: 768px) {
  .conv-panel {
    position: absolute;
    width: 100%;
    max-width: 100%;
    z-index: 10;
    height: 100%;
  }
  .conv-panel.conv-hidden { display: none !important; }
  .chat-welcome           { display: none !important; }
  .bubble                 { max-width: 82%; }
  .bubble-wrap            { padding: 1px 3%; }
}
