/**
 * WhatsApp Web API Unified WhatsApp Theme Stylesheet
 * Fully Responsive for Desktop, Tablet & Mobile Devices
 */

:root {
  --wa-green: #25D366;
  --wa-dark-green: #128C7E;
  --wa-teal: #075E54;
  --wa-light-green: #e7fce8;
  --wa-bg: #f0f2f5;
  --wa-card-bg: #ffffff;
  --wa-sidebar-bg: #111b21;
  --wa-sidebar-hover: #202c33;
  --wa-border: #e9edef;
  --wa-text-primary: #111b21;
  --wa-text-muted: #667781;
}

/* Base Layout */
html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--wa-bg);
  color: var(--wa-text-primary);
  min-height: 100vh;
  margin: 0;
  display: flex;
}

/* App Structure */
.app-sidebar {
  width: 260px;
  min-height: 100vh;
  background-color: var(--wa-sidebar-bg);
  color: #aebac1;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 1045;
}

.app-main {
  flex: 1;
  min-width: 0; /* prevents flex child overflow */
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: var(--wa-bg);
}

.app-navbar {
  background-color: #ffffff;
  border-bottom: 1px solid var(--wa-border);
  padding: 0.75rem 1.25rem;
  position: sticky;
  top: 0;
  z-index: 1020;
}

.app-content {
  padding: 1.5rem;
  flex: 1;
}

/* Mobile Sidebar Drawer & Backdrop */
.sidebar-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(17, 27, 33, 0.6);
  backdrop-filter: blur(2px);
  z-index: 1040;
  display: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.sidebar-backdrop.show {
  display: block;
  opacity: 1;
}

@media (max-width: 991.98px) {
  .app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    height: 100vh;
    transform: translateX(-100%);
    box-shadow: 0 0 25px rgba(0, 0, 0, 0.5);
  }

  .app-sidebar.show-sidebar {
    transform: translateX(0);
  }

  .app-content {
    padding: 1rem 0.75rem;
  }
}

/* Sidebar Nav Items */
.app-sidebar .nav-link {
  color: #aebac1;
  padding: 0.7rem 1.15rem;
  font-size: 0.92rem;
  border-radius: 8px;
  margin: 2px 10px;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: all 0.2s ease;
  font-weight: 500;
}

.app-sidebar .nav-link:hover {
  background-color: var(--wa-sidebar-hover);
  color: #ffffff;
}

.app-sidebar .nav-link.active {
  background-color: rgba(37, 211, 102, 0.15);
  color: var(--wa-green);
  font-weight: 600;
}

.app-sidebar .nav-link i {
  font-size: 1.15rem;
  width: 20px;
  text-align: center;
}

/* Cards & Components */
.card {
  background-color: #ffffff;
  border: 1px solid var(--wa-border);
  border-radius: 16px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04), 0 6px 16px rgba(17, 27, 33, 0.02);
}

.stat-card {
  border: 1px solid var(--wa-border);
  border-radius: 14px;
  background-color: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.06);
}

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
}

/* Buttons */
.btn-success {
  background-color: var(--wa-green);
  border-color: var(--wa-green);
  color: #ffffff;
  font-weight: 600;
}

.btn-success:hover, .btn-success:focus, .btn-success:active {
  background-color: var(--wa-dark-green) !important;
  border-color: var(--wa-dark-green) !important;
  color: #ffffff !important;
}

.btn-primary {
  background-color: var(--wa-dark-green);
  border-color: var(--wa-dark-green);
  color: #ffffff;
  font-weight: 600;
}

.btn-primary:hover, .btn-primary:focus, .btn-primary:active {
  background-color: var(--wa-teal) !important;
  border-color: var(--wa-teal) !important;
  color: #ffffff !important;
}

/* Form Controls */
.form-control, .form-select {
  background-color: #ffffff;
  border: 1px solid #d1d7db;
  border-radius: 8px;
  color: var(--wa-text-primary);
  font-size: 0.95rem;
}

.form-control:focus, .form-select:focus {
  border-color: var(--wa-green);
  box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.2);
}

/* Horizontally Scrollable Tabs for Mobile */
.nav-pills-mobile {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none; /* Firefox */
  padding-bottom: 2px;
}

.nav-pills-mobile::-webkit-scrollbar {
  display: none; /* Safari and Chrome */
}

.nav-pills-mobile .nav-link {
  white-space: nowrap;
  border-radius: 10px;
  padding: 0.6rem 1.2rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: #54656f;
  background-color: #e9edef;
  margin-right: 8px;
  transition: all 0.2s ease;
}

.nav-pills-mobile .nav-link.active {
  background-color: var(--wa-dark-green);
  color: #ffffff;
}

/* Status Badges */
.badge-status {
  padding: 0.45em 0.75em;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 6px;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.badge-connected {
  background-color: #d1e7dd;
  color: #0f5132;
}

.badge-qr_required {
  background-color: #fff3cd;
  color: #664d03;
}

.badge-initializing {
  background-color: #cff4fc;
  color: #055160;
}

.badge-disconnected, .badge-error {
  background-color: #f8d7da;
  color: #842029;
}

/* QR Code Display */
.qr-scanner-card {
  max-width: 440px;
  margin: 0 auto;
  border-radius: 16px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
  border: 1px solid var(--wa-border);
}

.qr-box-container {
  width: 280px;
  height: 280px;
  max-width: 90vw;
  max-height: 90vw;
  margin: 0 auto;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #ffffff;
  border: 2px dashed #cfd8dc;
  border-radius: 12px;
}

/* WhatsApp Live Chat Layout */
.live-chat-card {
  height: calc(100vh - 180px);
  min-height: 520px;
  border-radius: 16px;
  overflow: hidden;
  background-color: #ffffff;
}

.chat-sidebar {
  width: 340px;
  min-width: 280px;
  background-color: #ffffff;
  border-right: 1px solid var(--wa-border);
  display: flex;
  flex-direction: column;
  height: 100%;
}

.chat-search-box {
  padding: 0.75rem 1rem;
  background-color: #f0f2f5;
  border-bottom: 1px solid var(--wa-border);
}

.chat-list {
  flex: 1;
  overflow-y: auto;
}

.chat-item {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #f2f2f2;
  cursor: pointer;
  transition: background-color 0.15s ease;
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-item:hover {
  background-color: #f5f6f6;
}

.chat-item.active {
  background-color: #e9edef;
}

.chat-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background-color: #dfe5e7;
  color: #54656f;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  flex-shrink: 0;
}

.chat-content-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background-color: #efeae2;
  background-image: radial-gradient(#d1d7db 1px, transparent 1px);
  background-size: 20px 20px;
  height: 100%;
}

.chat-header {
  padding: 0.75rem 1.25rem;
  background-color: #ffffff;
  border-bottom: 1px solid var(--wa-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-bubble {
  max-width: 80%;
  padding: 8px 14px;
  border-radius: 12px;
  position: relative;
  word-wrap: break-word;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.08);
  font-size: 0.92rem;
}

.chat-bubble-in {
  align-self: flex-start;
  background-color: #ffffff;
  border-top-left-radius: 2px;
  color: #111b21;
}

.chat-bubble-out {
  align-self: flex-end;
  background-color: #d9fdd3;
  border-top-right-radius: 2px;
  color: #111b21;
}

.chat-bubble-time {
  font-size: 0.68rem;
  color: #667781;
  margin-top: 4px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
}

.chat-composer {
  padding: 0.75rem 1.25rem;
  background-color: #ffffff;
  border-top: 1px solid var(--wa-border);
}

/* Mobile Live Chat Responsiveness */
@media (max-width: 767.98px) {
  .live-chat-card {
    height: calc(100vh - 140px);
    border-radius: 10px;
    flex-direction: column !important;
  }

  .chat-sidebar {
    width: 100%;
    border-right: none;
  }

  .chat-content-area {
    width: 100%;
  }

  /* When conversation is open on mobile, hide the chat list */
  .chat-mobile-conversation-active .chat-sidebar {
    display: none !important;
  }

  /* When conversation is NOT open on mobile, hide the conversation window */
  .chat-mobile-list-active .chat-content-area {
    display: none !important;
  }

  .chat-bubble {
    max-width: 88%;
  }
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* Code Snippet Box */
.code-box {
  background-color: #1e1e1e;
  color: #d4d4d4;
  border-radius: 8px;
  padding: 1rem;
  font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.88rem;
  overflow-x: auto;
  position: relative;
}

.btn-copy-code {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 0.75rem;
  padding: 2px 8px;
}
