/* ---------------------------------------------------------------------------
   WhatsApp Bot Manager - custom styles on top of Bootstrap 5

   Layout: a fixed dark sidebar on large screens, an offcanvas drawer below the
   lg breakpoint, and a scrolling content column next to it.
   --------------------------------------------------------------------------- */

:root {
  --wbm-whatsapp: #25d366;
  --wbm-sidebar-width: 16rem;
  --wbm-sidebar-bg: #0f1418;
  --wbm-sidebar-border: rgba(255, 255, 255, 0.06);
  --wbm-sidebar-muted: rgba(233, 236, 239, 0.62);
}

body {
  -webkit-font-smoothing: antialiased;
}

.min-width-0 {
  min-width: 0;
}

/* ---------------------------------------------------------------------------
   Shell
   --------------------------------------------------------------------------- */

.app-shell {
  min-height: 100vh;
  background-color: var(--bs-body-bg);
}

.app-sidebar {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: var(--wbm-sidebar-width);
  z-index: 1030;
  background-color: var(--wbm-sidebar-bg);
  border-right: 1px solid var(--wbm-sidebar-border);
}

.app-sidebar-inner {
  width: 100%;
  padding: 1rem 0.75rem;
  overflow-y: auto;
}

.app-main {
  margin-left: 0;
}

@media (min-width: 992px) {
  .app-main {
    margin-left: var(--wbm-sidebar-width);
  }
}

.app-topbar {
  background-color: rgba(23, 28, 33, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--wbm-sidebar-border);
  z-index: 1020;
}

.app-topbar-title {
  letter-spacing: 0.01em;
}

.app-content {
  max-width: 100rem;
  width: 100%;
}

.app-footer {
  border-color: var(--wbm-sidebar-border) !important;
}

/* The drawer reuses the sidebar markup, so it needs the same background. */
.app-sidebar-offcanvas {
  width: var(--wbm-sidebar-width);
  background-color: var(--wbm-sidebar-bg);
}

/* ---------------------------------------------------------------------------
   Sidebar contents
   --------------------------------------------------------------------------- */

.app-brand {
  color: var(--bs-body-color);
  padding: 0.25rem 0.5rem 1.25rem;
}

.app-brand-mark {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.65rem;
  background-color: rgba(37, 211, 102, 0.14);
  color: var(--wbm-whatsapp);
  font-size: 1.15rem;
  flex-shrink: 0;
}

.app-brand-name {
  font-weight: 600;
  font-size: 0.95rem;
}

.app-brand-meta {
  font-size: 0.7rem;
  color: var(--wbm-sidebar-muted);
}

.app-nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0.75rem;
  border-radius: 0.6rem;
  color: var(--wbm-sidebar-muted);
  font-size: 0.925rem;
  transition: background-color 0.15s ease-in-out, color 0.15s ease-in-out;
}

.app-nav-link i {
  font-size: 1.05rem;
  width: 1.25rem;
  text-align: center;
}

.app-nav-link:hover,
.app-nav-link:focus-visible {
  background-color: rgba(255, 255, 255, 0.05);
  color: var(--bs-body-color);
}

.app-nav-link.active {
  background-color: rgba(37, 211, 102, 0.14);
  color: #6ff0a4;
  font-weight: 500;
}

.app-sidebar-footer {
  padding: 0.75rem 0.5rem 0.25rem;
  border-top: 1px solid var(--wbm-sidebar-border);
}

.app-session-card {
  background-color: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--wbm-sidebar-border);
  border-radius: 0.6rem;
  padding: 0.6rem 0.7rem;
}

.app-session-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--wbm-sidebar-muted);
}

.app-session-number {
  font-size: 0.8rem;
  font-family: var(--bs-font-monospace);
  margin-top: 0.35rem;
  color: var(--bs-body-color);
}

.app-realtime {
  font-size: 0.75rem;
  color: var(--wbm-sidebar-muted);
  padding: 0 0.25rem;
  transition: color 0.2s ease-in-out;
}

/* ---------------------------------------------------------------------------
   Cards
   --------------------------------------------------------------------------- */

.card {
  border-radius: 0.75rem;
}

.card-header {
  border-bottom-color: var(--wbm-sidebar-border);
}

dl.row dd {
  margin-bottom: 0.5rem;
}

/* Statistics cards: a short entrance, staggered per card, plus a hover lift. */
.stat-card {
  position: relative;
  overflow: hidden;
  animation: stat-card-in 0.45s ease-out both;
  animation-delay: var(--stat-delay, 0ms);
  transition: transform 0.18s ease-out, box-shadow 0.18s ease-out;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 0.75rem 1.5rem rgba(0, 0, 0, 0.28) !important;
}

/* The accent stripe doubles as the status colour of the connection card. */
.stat-card::before {
  content: '';
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background-color: currentColor;
  opacity: 0.85;
}

.stat-card.accent-primary::before { color: var(--bs-primary); }
.stat-card.accent-success::before { color: var(--bs-success); }
.stat-card.accent-info::before { color: var(--bs-info); }
.stat-card.accent-warning::before { color: var(--bs-warning); }
.stat-card.accent-danger::before { color: var(--bs-danger); }

.stat-icon {
  font-size: 1.5rem;
  line-height: 1;
  flex-shrink: 0;
}

.stat-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 600;
  line-height: 1.2;
  transition: color 0.2s ease-in-out;
}

.stat-value-sm {
  font-size: 1rem;
  font-weight: 500;
  line-height: 1.35;
}

.stat-hint {
  font-size: 0.75rem;
  min-height: 1rem;
}

@keyframes stat-card-in {
  from {
    opacity: 0;
    transform: translateY(0.5rem);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .stat-card {
    animation: none;
  }

  .stat-card:hover {
    transform: none;
  }
}

/* ---------------------------------------------------------------------------
   Charts
   --------------------------------------------------------------------------- */

.chart-box {
  position: relative;
  height: 20rem;
}

.chart-box-sm {
  height: 15rem;
}

.chart-box canvas {
  transition: opacity 0.2s ease-in-out;
}

.chart-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  margin: 0;
  padding: 1rem;
  font-size: 0.9rem;
}

/* ---------------------------------------------------------------------------
   Connection screen
   --------------------------------------------------------------------------- */

/* Keeps the QR readable in dark mode: WhatsApp needs a white quiet zone. */
.qr-frame {
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08);
  line-height: 0;
}

.qr-frame img {
  display: block;
  width: 288px;
  height: 288px;
  max-width: 100%;
}

/* The status badge changes colour often, so soften the switch. */
#statusBadge,
.js-status-badge {
  transition: background-color 0.2s ease-in-out;
}

.event-scroll #eventList,
#eventList {
  max-height: 22rem;
  overflow-y: auto;
}

#eventList .badge {
  min-width: 7.5rem;
  text-align: center;
}

/* ---------------------------------------------------------------------------
   Tables
   --------------------------------------------------------------------------- */

.table > thead th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--bs-secondary-color);
  font-weight: 600;
  white-space: nowrap;
}

.table > tbody > tr > td {
  vertical-align: middle;
}

/* ---------------------------------------------------------------------------
   Loading overlay
   --------------------------------------------------------------------------- */

.app-loader {
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  z-index: 2000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 4.5rem;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease-in-out;
}

.app-loader.is-visible {
  opacity: 1;
}

.toast-container {
  z-index: 2100;
}

/* ---------------------------------------------------------------------------
   Accounts: avatars, the sidebar user card and the sign in screen
   --------------------------------------------------------------------------- */

.app-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  background-color: rgba(37, 211, 102, 0.16);
  color: var(--wbm-whatsapp);
  font-weight: 600;
  line-height: 1;
  flex-shrink: 0;
  user-select: none;
}

.app-avatar-sm {
  width: 1.65rem;
  height: 1.65rem;
  font-size: 0.8rem;
}

.app-avatar-lg {
  width: 3.5rem;
  height: 3.5rem;
  font-size: 1.5rem;
}

.app-user-card {
  padding: 0.5rem 0.6rem;
  border-radius: 0.6rem;
  background-color: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--wbm-sidebar-border);
}

.app-user-name {
  font-size: 0.9rem;
  font-weight: 600;
}

.app-user-role {
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  color: var(--wbm-sidebar-muted);
}

.auth-shell {
  background:
    radial-gradient(circle at 15% 15%, rgba(37, 211, 102, 0.14), transparent 45%),
    radial-gradient(circle at 85% 80%, rgba(13, 110, 253, 0.12), transparent 45%),
    var(--wbm-sidebar-bg);
}

.auth-card-wrap {
  max-width: 26rem;
}

.auth-card {
  background-color: rgba(23, 28, 33, 0.94);
  backdrop-filter: blur(6px);
  border-radius: 1rem;
}

.auth-logo {
  width: 3.75rem;
  height: 3.75rem;
  border-radius: 1rem;
  background-color: rgba(37, 211, 102, 0.16);
  color: var(--wbm-whatsapp);
  font-size: 1.85rem;
}

/* ---------------------------------------------------------------------------
   Outbound messages: drag & drop upload
   --------------------------------------------------------------------------- */

.upload-dropzone {
  border: 1px dashed rgba(255, 255, 255, 0.18);
  border-radius: 0.75rem;
  padding: 1.5rem;
  text-align: center;
  cursor: pointer;
  background-color: rgba(255, 255, 255, 0.02);
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.upload-dropzone:hover,
.upload-dropzone:focus {
  border-color: rgba(37, 211, 102, 0.55);
  outline: none;
}

.upload-dropzone.is-dragging {
  border-color: var(--wbm-whatsapp);
  background-color: rgba(37, 211, 102, 0.08);
}

.upload-image-preview {
  max-width: 100%;
  max-height: 220px;
  border-radius: 0.5rem;
  object-fit: contain;
  margin-bottom: 0.75rem;
}

.upload-pdf-preview {
  width: 100%;
  height: 220px;
  border: 0;
  border-radius: 0.5rem;
  margin-bottom: 0.75rem;
  background-color: rgba(0, 0, 0, 0.25);
}

.upload-file-meta {
  font-size: 0.9rem;
  word-break: break-all;
}

#messageTypeTabs .nav-link {
  color: var(--bs-secondary-color);
}

#messageTypeTabs .nav-link.active {
  background-color: rgba(37, 211, 102, 0.18);
  color: var(--wbm-whatsapp);
}

/* ---------------------------------------------------------------------------
   Small screens
   --------------------------------------------------------------------------- */

@media (max-width: 575.98px) {
  .qr-frame img {
    width: 240px;
    height: 240px;
  }

  #eventList .badge {
    min-width: 6rem;
  }

  .stat-value {
    font-size: 1.35rem;
  }

  .chart-box {
    height: 17rem;
  }
}
