/* ==========================================================================
   Byteproc WhatsApp SaaS — Production Theme
   Modern, Clean, Enterprise Grade Styling
   ========================================================================== */

:root {
  --primary: #075e54;
  --primary-light: #0b1e1b;
  --wa-green: #25d366;
  --wa-dark-green: #128c7e;
  --wa-teal: #075e54;
  --wa-accent: #10b981;
  --wa-accent-soft: rgba(16, 185, 129, 0.12);
  --wa-bubble-in: #ffffff;
  --wa-bubble-out: #dcf8c6;
  --wa-chat-bg: #efeae2;
  --surface: #ffffff;
  --bg-main: #f8fafc;
  --border-color: #e2e8f0;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px -2px rgba(0, 0, 0, 0.06), 0 2px 6px -1px rgba(0, 0, 0, 0.03);
  --shadow-lg: 0 10px 25px -3px rgba(0, 0, 0, 0.08), 0 4px 10px -2px rgba(0, 0, 0, 0.03);
  --sidebar-width: 260px;

  /* WhatsApp Brand Sidebar Variables */
  --sidebar-bg: #0b1e1b;
  --sidebar-brand-bg: #071614;
  --sidebar-border: rgba(255, 255, 255, 0.07);
  --sidebar-text: #9bb4ab;
  --sidebar-text-muted: #5e7b72;
  --sidebar-text-active: #25d366;
  --sidebar-active-bg: rgba(37, 211, 102, 0.12);
  --sidebar-active-border: #25d366;
  --sidebar-hover-bg: rgba(255, 255, 255, 0.06);
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-main);
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  letter-spacing: -0.01em;
}

/* --------------------------------------------------------------------------
   Layout Structure
   -------------------------------------------------------------------------- */
.app-wrapper {
  display: flex;
  min-height: 100vh;
}

.app-sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: #f1f5f9;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 1040;
  transition: transform 0.25s ease-in-out;
  border-right: 1px solid var(--sidebar-border);
}

.app-main {
  flex-grow: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left 0.25s ease-in-out;
  min-width: 0;
  max-width: 100%;
}

.app-navbar {
  height: 64px;
  background: #ffffff;
  border-bottom: 1px solid var(--border-color);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 1030;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.03);
}

.app-content {
  padding: 1.75rem 2rem;
  flex-grow: 1;
  min-width: 0;
  max-width: 100%;
}

.app-footer {
  padding: 1.25rem 2rem;
  border-top: 1px solid var(--border-color);
  background: #ffffff;
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* --------------------------------------------------------------------------
   Sidebar Components
   -------------------------------------------------------------------------- */
.sidebar-brand {
  height: 64px;
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  background: var(--sidebar-brand-bg);
  border-bottom: 1px solid var(--sidebar-border);
  font-weight: 700;
  font-size: 1.125rem;
  color: #ffffff;
  text-decoration: none;
  gap: 0.75rem;
}

.sidebar-brand .brand-badge {
  background: linear-gradient(135deg, #25d366 0%, #128c7e 100%);
  color: white;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  box-shadow: 0 4px 10px rgba(37, 211, 102, 0.3);
}

.sidebar-menu {
  list-style: none;
  padding: 1rem 0.75rem;
  margin: 0;
  flex-grow: 1;
  overflow-y: auto;
}

.menu-header {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--sidebar-text-muted);
  padding: 0.75rem 0.85rem 0.35rem;
}

.menu-item {
  margin-bottom: 0.25rem;
}

.menu-link {
  display: flex;
  align-items: center;
  padding: 0.65rem 0.85rem;
  color: var(--sidebar-text);
  text-decoration: none;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.15s ease-in-out;
  gap: 0.75rem;
}

.menu-link i {
  font-size: 1.15rem;
  transition: transform 0.15s ease, color 0.15s ease;
  color: #799a8f;
}

.menu-link:hover {
  background: var(--sidebar-hover-bg);
  color: #ffffff;
}

.menu-link:hover i {
  color: #ffffff;
  transform: translateX(2px);
}

.menu-link.active {
  background: linear-gradient(90deg, rgba(37, 211, 102, 0.14) 0%, rgba(37, 211, 102, 0.04) 100%);
  color: var(--sidebar-text-active);
  border-left: 3px solid var(--sidebar-active-border);
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  font-weight: 600;
}

.menu-link.active i {
  color: var(--sidebar-text-active);
}

.menu-link .badge {
  margin-left: auto;
  font-size: 0.72rem;
  padding: 0.25rem 0.5rem;
  border-radius: 9999px;
}

/* Sidebar Upgrade Card (WhatsApp Brand Accents) */
.sidebar-upgrade-card {
  padding: 0.85rem 1rem;
  border-radius: var(--radius-md);
  background: linear-gradient(145deg, rgba(37, 211, 102, 0.12) 0%, rgba(7, 94, 84, 0.35) 100%);
  border: 1px solid rgba(37, 211, 102, 0.22);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  position: relative;
  overflow: hidden;
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
}

.sidebar-upgrade-card::before {
  content: '';
  position: absolute;
  top: -15px;
  right: -15px;
  width: 60px;
  height: 60px;
  background: radial-gradient(circle, rgba(37, 211, 102, 0.25) 0%, transparent 70%);
  border-radius: 50%;
  pointer-events: none;
}

.sidebar-upgrade-card .badge-pro {
  background: #25d366;
  color: #075e54;
  font-weight: 700;
  font-size: 0.65rem;
  letter-spacing: 0.06em;
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
}

.sidebar-upgrade-card .btn-upgrade {
  background: #25d366;
  color: #075e54;
  font-size: 0.78rem;
  font-weight: 700;
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: none;
  transition: all 0.2s ease-in-out;
  text-decoration: none;
}

.sidebar-upgrade-card .btn-upgrade:hover {
  background: #2ee672;
  color: #054c44;
  box-shadow: 0 4px 12px rgba(37, 211, 102, 0.4);
  transform: translateY(-1px);
}

.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--sidebar-border);
  background: rgba(0, 0, 0, 0.25);
  color: #cbd5e1;
}

.sidebar-footer .text-muted {
  color: #94a3b8 !important;
}

.wa-status-pill {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.25);
  color: #34d399;
  border-radius: var(--radius-full);
  padding: 0.35rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
}

.wa-status-dot {
  width: 8px;
  height: 8px;
  background: #10b981;
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.3);
  animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

/* --------------------------------------------------------------------------
   Cards, Metrics & Enterprise Surface
   -------------------------------------------------------------------------- */
.card-modern {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.card-modern:hover {
  border-color: #cbd5e1;
}

.metric-card {
  padding: 1.25rem 1.5rem;
  border-radius: var(--radius-md);
  background: #ffffff;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.metric-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

/* --------------------------------------------------------------------------
   Modern Dashboard Suite (Connected & Disconnected UI)
   -------------------------------------------------------------------------- */
.btn-wa-broadcast {
  background: #00875a;
  color: #ffffff !important;
  font-weight: 600;
  border-radius: var(--radius-sm);
  padding: 0.55rem 1.15rem;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  border: none;
  transition: all 0.15s ease-in-out;
}
.btn-wa-broadcast:hover {
  background: #00734c;
  color: #ffffff !important;
  box-shadow: 0 4px 14px rgba(0, 135, 90, 0.28);
  transform: translateY(-1px);
}

.dashboard-hero-unconnected {
  background: linear-gradient(135deg, #fff5f5 0%, #fff0f0 100%);
  border: 1px solid #fee2e2;
  border-radius: var(--radius-lg);
  padding: 2.25rem 2rem;
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.04);
}

.phone-illustration-box {
  width: 120px;
  height: 160px;
  background: #ffffff;
  border: 3px solid #1e293b;
  border-radius: 22px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.08);
}
.phone-illustration-box::before {
  content: '';
  position: absolute;
  top: 8px;
  width: 36px;
  height: 4px;
  background: #1e293b;
  border-radius: 2px;
}
.phone-wa-badge {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #25d366;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.65rem;
  box-shadow: 0 4px 12px rgba(37, 211, 102, 0.35);
}
.phone-prohibition-badge {
  position: absolute;
  bottom: 12px;
  right: -10px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #ef4444;
  color: #ffffff;
  border: 2px solid #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  box-shadow: 0 4px 10px rgba(239, 68, 68, 0.4);
}

.dashboard-kpi-card {
  background: #ffffff;
  border: 1px solid #eef2f6;
  border-radius: 14px;
  padding: 1.15rem 1.25rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  position: relative;
  text-decoration: none;
  color: inherit;
  display: block;
}
.dashboard-kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px -4px rgba(0, 0, 0, 0.06);
  color: inherit;
}
.dashboard-kpi-card .kpi-icon-box {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  flex-shrink: 0;
}
.dashboard-kpi-card .kpi-title {
  font-size: 0.825rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 0.15rem;
}
.dashboard-kpi-card .kpi-value {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.2;
}

.dashboard-card {
  background: #ffffff;
  border: 1px solid #eef2f6;
  border-radius: 14px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
  height: 100%;
  display: flex;
  flex-direction: column;
}

.quick-action-card {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 0.85rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-decoration: none;
  color: inherit;
  transition: all 0.15s ease-in-out;
}
.quick-action-card:hover {
  border-color: #00875a;
  background: #fcfdfd;
  box-shadow: 0 4px 12px rgba(0, 135, 90, 0.08);
  transform: translateY(-1px);
  color: inherit;
}
.quick-action-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  flex-shrink: 0;
}

.chat-attention-row {
  padding: 0.75rem 0.5rem;
  border-bottom: 1px solid #f1f5f9;
  transition: background 0.15s ease;
}
.chat-attention-row:last-child {
  border-bottom: none;
}
.chat-attention-row:hover {
  background: #f8fafc;
  border-radius: 8px;
}

.metric-card-compact {
  padding: 0.85rem 1.15rem;
}

.metric-card-compact .metric-title {
  font-size: 0.75rem;
  margin-bottom: 0.2rem;
}

.metric-card-compact .metric-value {
  font-size: 1.5rem;
}

.metric-card-compact .metric-icon-box {
  width: 40px;
  height: 40px;
  font-size: 1.25rem;
}

.metric-title {
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.metric-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.2;
}

.metric-icon-box {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.metric-icon-green { background: #dcfce7; color: #16a34a; }
.metric-icon-blue { background: #e0f2fe; color: #0284c7; }
.metric-icon-purple { background: #f3e8ff; color: #9333ea; }
.metric-icon-amber { background: #fef3c7; color: #d97706; }

/* --------------------------------------------------------------------------
   Modern Form Controls
   -------------------------------------------------------------------------- */
.form-control, .form-select {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.85rem;
  font-size: 0.9rem;
  color: var(--text-main);
  background-color: #ffffff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-control:focus, .form-select:focus {
  border-color: #10b981;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15);
  outline: none;
}

.form-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: #334155;
  margin-bottom: 0.4rem;
}

.btn-wa {
  background-color: #10b981;
  border-color: #10b981;
  color: #ffffff;
  font-weight: 600;
  border-radius: var(--radius-sm);
  padding: 0.55rem 1.15rem;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  transition: all 0.15s ease-in-out;
}

.btn-wa:hover, .btn-wa:focus {
  background-color: #059669;
  border-color: #059669;
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.btn-outline-wa {
  color: #10b981;
  border-color: #10b981;
  font-weight: 600;
  border-radius: var(--radius-sm);
}

.btn-outline-wa:hover {
  background-color: #10b981;
  color: #ffffff;
}

.btn-wa-light {
  background-color: #e8f8f2;
  border: 1px solid #c6f0e0;
  color: #00875a;
  font-weight: 600;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease-in-out;
}

.btn-wa-light:hover, .btn-wa-light:focus {
  background-color: #d1f2e4;
  border-color: #a3e6cb;
  color: #006644;
}

/* --------------------------------------------------------------------------
   DataTables Modern Styling Overrides
   -------------------------------------------------------------------------- */
.table-modern {
  width: 100% !important;
  border-collapse: separate;
  border-spacing: 0;
}

.table-modern thead th {
  background: #f8fafc;
  color: #475569;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
}

.table-modern tbody td {
  padding: 0.9rem 1.25rem;
  font-size: 0.875rem;
  vertical-align: middle;
  border-bottom: 1px solid #f1f5f9;
  white-space: nowrap;
}

.table-modern tbody td:nth-child(4) {
  white-space: normal;
  max-width: 340px;
}

.table-modern tbody tr:hover td {
  background-color: #f8fafc;
}

.table-compact thead th {
  padding: 0.55rem 0.85rem !important;
  font-size: 0.74rem !important;
}

.table-compact tbody td {
  padding: 0.45rem 0.85rem !important;
  font-size: 0.82rem !important;
}

.dataTables_wrapper .dataTables_filter input {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.75rem;
  font-size: 0.875rem;
  margin-left: 0.5rem;
}

.dataTables_wrapper .dataTables_filter input:focus {
  border-color: #10b981;
  outline: none;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15);
}

.dataTables_wrapper .dataTables_paginate .paginate_button.current {
  background: #10b981 !important;
  color: white !important;
  border: 1px solid #10b981 !important;
  border-radius: var(--radius-sm);
}

/* --------------------------------------------------------------------------
   Badges & Statuses
   -------------------------------------------------------------------------- */
.badge-status {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.badge-status.sent { background: #e2e8f0; color: #475569; }
.badge-status.delivered { background: #dbeafe; color: #1d4ed8; }
.badge-status.read { background: #dcfce7; color: #15803d; }
.badge-status.failed { background: #fee2e2; color: #b91c1c; }
.badge-status.inbound { background: #ede9fe; color: #6d28d9; }
.badge-status.outbound { background: #e0f2fe; color: #0369a1; }

.badge-cat-marketing {
  background-color: #f3e8ff !important;
  color: #7e22ce !important;
  border: 1px solid #d8b4fe !important;
}

.badge-cat-utility {
  background-color: #e0f2fe !important;
  color: #0369a1 !important;
  border: 1px solid #bae6fd !important;
}

.badge-cat-auth {
  background-color: #fef3c7 !important;
  color: #b45309 !important;
  border: 1px solid #fde68a !important;
}

/* --------------------------------------------------------------------------
   WhatsApp Chat Screen (Enterprise Messenger UI - Fullscreen Fit)
   -------------------------------------------------------------------------- */
body.page-chat {
  height: 100vh !important;
  height: 100dvh !important;
  max-height: 100vh !important;
  max-height: 100dvh !important;
  overflow: hidden !important;
}

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

body.page-chat .app-main,
.app-main-chat {
  height: 100vh !important;
  height: 100dvh !important;
  max-height: 100vh !important;
  max-height: 100dvh !important;
  min-height: 0 !important;
  overflow: hidden !important;
  display: flex !important;
  flex-direction: column !important;
}

body.page-chat .app-navbar {
  flex-shrink: 0 !important;
}

body.page-chat .app-content,
.app-content-chat {
  padding: 0 !important;
  margin: 0 !important;
  flex: 1 1 0% !important;
  min-height: 0 !important;
  height: auto !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
}

body.page-chat .app-footer {
  display: none !important;
}

.chat-container {
  display: flex;
  flex: 1 1 0%;
  min-height: 0;
  height: 100%;
  background: #ffffff;
  border: none;
  border-radius: 0;
  overflow: hidden;
  box-shadow: none;
  margin: 0;
}

.chat-sidebar {
  width: 360px;
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  background: #ffffff;
  flex-shrink: 0;
  height: 100%;
  overflow: hidden;
}

.chat-sidebar-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  background: #fafafa;
}

.chat-search-box {
  position: relative;
}

.chat-search-box i {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}

.chat-search-box input {
  padding-left: 2.25rem;
  background: #ffffff;
}

.chat-contacts-list {
  flex: 1 1 0%;
  min-height: 0;
  overflow-y: auto;
  list-style: none;
  padding: 0;
  margin: 0;
}

.chat-contact-item {
  display: flex;
  align-items: center;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid #f1f5f9;
  cursor: pointer;
  transition: background 0.15s ease;
  gap: 0.85rem;
}

.chat-contact-item:hover {
  background: #f8fafc;
}

.chat-contact-item.active {
  background: #f0fdf4;
  border-left: 3px solid #10b981;
}

.avatar-ring {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #475569;
  flex-shrink: 0;
  position: relative;
}

.avatar-ring.online::after {
  content: '';
  position: absolute;
  bottom: 0;
  right: 0;
  width: 12px;
  height: 12px;
  background: #22c55e;
  border: 2px solid white;
  border-radius: 50%;
}

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

.chat-contact-name {
  font-size: 0.925rem;
  font-weight: 600;
  color: var(--text-main);
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.15rem;
}

.chat-contact-time {
  font-size: 0.725rem;
  color: var(--text-muted);
  font-weight: 400;
}

.chat-contact-snippet {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  min-width: 0;
}

.chat-contact-snippet .snippet-text {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Active Chat Main Area */
.chat-main {
  flex: 1 1 0%;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--wa-chat-bg);
  background-image: radial-gradient(#d3cbbe 1px, transparent 1px);
  background-size: 24px 24px;
  position: relative;
  overflow: hidden;
}

.chat-header {
  height: 64px;
  background: #ffffff;
  border-bottom: 1px solid var(--border-color);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.chat-messages-area,
.chat-body {
  flex: 1 1 0%;
  min-height: 0;
  padding: 1.25rem 1.5rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.chat-date-pill {
  align-self: center;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(4px);
  color: #64748b;
  font-size: 0.725rem;
  font-weight: 600;
  padding: 0.3rem 0.85rem;
  border-radius: var(--radius-full);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  margin: 0.5rem auto;
}

.bubble {
  width: fit-content;
  max-width: 65%;
  min-width: 80px;
  padding: 0.6rem 0.85rem;
  border-radius: 8px;
  position: relative;
  font-size: 0.9rem;
  line-height: 1.4;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.08);
  word-break: break-word;
}

.bubble.inbound {
  align-self: flex-start;
  margin-right: auto;
  background: var(--wa-bubble-in);
  border-top-left-radius: 2px;
}

.bubble.outbound {
  align-self: flex-end;
  margin-left: auto;
  background: var(--wa-bubble-out);
  border-top-right-radius: 2px;
}

.bubble-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.35rem;
  margin-top: 0.25rem;
  font-size: 0.7rem;
  color: #64748b;
}

.tick-sent { color: #94a3b8; }
.tick-delivered { color: #64748b; }
.tick-read { color: #0284c7; }

/* Template Card inside bubble */
.template-card-preview {
  background: #ffffff;
  border-radius: 6px;
  border: 1px solid rgba(0,0,0,0.06);
  padding: 0.75rem;
  margin-top: 0.35rem;
}

.template-badge {
  font-size: 0.68rem;
  text-transform: uppercase;
  font-weight: 700;
  background: #ede9fe;
  color: #6d28d9;
  padding: 0.2rem 0.45rem;
  border-radius: 4px;
  margin-bottom: 0.35rem;
  display: inline-block;
}

.chat-input-bar {
  background: #ffffff;
  border-top: 1px solid var(--border-color);
  padding: 0.85rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.chat-input-bar .form-control {
  border-radius: var(--radius-full);
  padding: 0.65rem 1.25rem;
}

/* --------------------------------------------------------------------------
   Auth Screen Specifics
   -------------------------------------------------------------------------- */
.auth-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
  padding: 1.5rem;
}

.auth-card {
  width: 100%;
  max-width: 440px;
  background: #ffffff;
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
  padding: 2.25rem;
}

.auth-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-bottom: 1.75rem;
}

.auth-brand-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.35);
}

/* --------------------------------------------------------------------------
   SweetAlert2 Custom Styling Adjustments
   -------------------------------------------------------------------------- */
.swal2-popup {
  border-radius: var(--radius-md) !important;
  font-family: inherit !important;
  padding: 1.75rem !important;
}

.swal2-title {
  font-size: 1.25rem !important;
  font-weight: 700 !important;
  color: var(--text-main) !important;
}

.swal2-html-container {
  font-size: 0.925rem !important;
  color: var(--text-muted) !important;
}

/* Sidebar mobile backdrop overlay */
.sidebar-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(2px);
  z-index: 1035;
  display: none;
  opacity: 0;
  transition: opacity 0.25s ease-in-out;
}

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

/* Responsive adjustments */
@media (max-width: 991.98px) {
  .app-sidebar {
    transform: translateX(-100%);
    box-shadow: 0 0 25px rgba(0,0,0,0.5);
  }
  .app-sidebar.show {
    transform: translateX(0);
  }
  .app-main {
    margin-left: 0;
    width: 100% !important;
    max-width: 100vw !important;
    overflow-x: hidden !important;
  }
  .app-content {
    padding: 1.25rem 1rem;
    width: 100% !important;
    max-width: 100% !important;
  }
  body:not(.page-chat) .app-main {
    padding-bottom: 64px; /* Space for mobile bottom bar */
  }
}

@media (max-width: 575.98px) {
  .app-navbar {
    height: 56px;
    padding: 0 0.85rem;
  }
  .app-content {
    padding: 1rem 0.75rem;
  }
  .app-footer {
    padding: 1rem 0.75rem;
    font-size: 0.8rem;
    text-align: center;
  }
}

@media (max-width: 767.98px) {
  /* Hide navbar and top bar on mobile when active chat thread is open for native app-like fullscreen chat */
  body.page-chat.chat-thread-open .app-navbar {
    display: none !important;
  }
  body.page-chat.chat-thread-open .inbox-top-bar {
    display: none !important;
  }

  /* Inbox Top Bar on Phone */
  .inbox-top-bar {
    padding: 0.65rem 0.85rem !important;
    gap: 0.5rem !important;
    flex-direction: column !important;
    align-items: stretch !important;
  }
  .inbox-top-row {
    width: 100%;
    max-width: 100% !important;
  }
  .inbox-main-title {
    font-size: 1.25rem !important;
  }
  .inbox-status-filters {
    width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
  }
  .inbox-status-filters::-webkit-scrollbar {
    display: none;
  }
  .inbox-search-actions {
    width: 100%;
  }
  .inbox-search-wrapper {
    width: 100% !important;
  }

  .chat-container {
    height: 100% !important;
    position: relative;
    overflow: hidden;
  }

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

  .chat-contact-item {
    padding: 0.75rem 1rem !important;
  }
  .chat-contact-item:active {
    background: #f1f5f9 !important;
  }

  .chat-main {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1040;
    background: #ffffff;
    height: 100vh !important;
    height: 100dvh !important;
    flex-direction: column;
  }

  .chat-main.mobile-active {
    display: flex !important;
  }

  .chat-header {
    height: 58px !important;
    padding: 0 0.75rem !important;
    flex-shrink: 0;
  }

  .chat-back-btn {
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50% !important;
  }

  .active-contact-title {
    max-width: 120px !important;
  }

  .chat-header-icon-btn {
    width: 34px !important;
    height: 34px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 0 !important;
  }

  .chat-messages-area {
    padding: 0.75rem 0.5rem !important;
  }

  .bubble {
    max-width: 88% !important;
    font-size: 0.85rem !important;
  }

  .chat-input-bar {
    padding: 0.5rem 0.65rem !important;
    padding-bottom: max(0.5rem, env(safe-area-inset-bottom, 0.5rem)) !important;
    gap: 0.35rem !important;
  }

  .chat-input-bar .form-control {
    font-size: 16px !important; /* Prevents auto zoom in iOS Safari */
    padding: 0.5rem 0.85rem !important;
  }

  .composer-icon-btn {
    width: 36px !important;
    height: 36px !important;
    padding: 0 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    border: none !important;
    background: #f1f5f9 !important;
  }

  .composer-send-btn {
    width: 38px !important;
    height: 38px !important;
    border-radius: 50% !important;
    padding: 0 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  .chat-crm-drawer {
    position: fixed !important;
    top: 0;
    right: 0;
    bottom: 0;
    height: 100vh !important;
    height: 100dvh !important;
    width: 88vw !important;
    max-width: 330px !important;
    z-index: 1050 !important;
    box-shadow: -5px 0 25px rgba(0, 0, 0, 0.25) !important;
    transform: translateX(100%);
    transition: transform 0.25s ease-in-out;
  }

  .chat-crm-drawer.show {
    transform: translateX(0) !important;
  }

  .chat-crm-backdrop {
    display: block !important;
    position: fixed !important;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(15, 23, 42, 0.45) !important;
    backdrop-filter: blur(2px);
    z-index: 1045 !important;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease-in-out;
  }

  .chat-crm-backdrop.show {
    opacity: 1 !important;
    pointer-events: auto !important;
  }
}

/* --------------------------------------------------------------------------
   Upgraded 3-Panel Inbox & Messenger Architecture (Reference: media_1790662709556.jpg)
   -------------------------------------------------------------------------- */
.inbox-top-bar {
  background: #ffffff;
  border-bottom: 1px solid var(--border-color);
  padding: 0.65rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  gap: 1rem;
}

.btn-filter-pill {
  border-radius: var(--radius-full);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.25rem 0.65rem;
  border: 1px solid #e2e8f0;
  background: #ffffff;
  color: #475569;
  display: inline-flex;
  align-items: center;
  transition: all 0.15s ease;
  cursor: pointer;
}
.btn-filter-pill:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
  color: #1e293b;
}
.btn-filter-pill.active {
  background: #dcfce7;
  border-color: #86efac;
  color: #16a34a;
}
.btn-filter-pill .badge {
  font-size: 0.68rem;
  padding: 0.15rem 0.4rem;
  border-radius: 9999px;
}

/* Chat Sidebar Sub-Tabs (All / Unread / Groups) */
.chat-sidebar-tabs {
  display: flex;
  padding: 0.5rem 0.85rem;
  gap: 0.5rem;
  border-bottom: 1px solid #f1f5f9;
  background: #ffffff;
}
.chat-tab-pill {
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-full);
  color: #64748b;
  text-decoration: none;
  background: #f1f5f9;
  transition: all 0.15s ease;
  cursor: pointer;
}
.chat-tab-pill:hover {
  background: #e2e8f0;
  color: #1e293b;
}
.chat-tab-pill.active {
  background: #dcfce7;
  color: #16a34a;
}

/* Panel 3: Right CRM Details Drawer */
.chat-crm-drawer {
  width: 310px;
  background: #ffffff;
  border-left: 1px solid var(--border-color);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow-y: auto;
  transition: transform 0.25s ease-in-out;
}

@media (max-width: 1199.98px) {
  .chat-crm-drawer {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 25;
    box-shadow: -5px 0 25px rgba(0, 0, 0, 0.15);
    transform: translateX(100%);
  }
  .chat-crm-drawer.show {
    transform: translateX(0);
  }
  .chat-crm-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(15, 23, 42, 0.35);
    backdrop-filter: blur(2px);
    z-index: 24;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease-in-out;
  }
  .chat-crm-backdrop.show {
    opacity: 1;
    pointer-events: auto;
  }
}

.inbox-search-wrapper {
  width: 250px;
}
.chat-crm-backdrop {
  display: none;
}

.crm-nav-tabs {
  display: flex;
  border-bottom: 1px solid #f1f5f9;
  padding: 0 1rem;
}
.crm-nav-link {
  padding: 0.65rem 0.85rem;
  font-size: 0.825rem;
  font-weight: 600;
  color: #64748b;
  text-decoration: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
}
.crm-nav-link:hover {
  color: #1e293b;
}
.crm-nav-link.active {
  color: #00875a;
  border-bottom-color: #00875a;
}

.badge-tag {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}
.badge-tag.tag-blue {
  background: #e0f2fe;
  color: #0284c7;
}
.badge-tag.tag-purple {
  background: #f3e8ff;
  color: #9333ea;
}
.badge-tag.tag-green {
  background: #dcfce7;
  color: #16a34a;
}

/* Audio Waveform Voice Note Card */
.chat-audio-card {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 210px;
}
.audio-waveform {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 24px;
}
.audio-waveform .bar {
  width: 2.5px;
  background: #64748b;
  border-radius: 2px;
}

/* --------------------------------------------------------------------------
   Mobile Phone UI & Touch UX Enhancements
   -------------------------------------------------------------------------- */
html, body {
  -webkit-tap-highlight-color: transparent;
}
button, a, input, select, textarea {
  touch-action: manipulation;
}

/* Mobile Bottom Navigation Bar (Phone-First Sticky Bar) */
.mobile-bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: #ffffff;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 1030;
  box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.06);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 0.68rem;
  font-weight: 500;
  padding: 0.35rem 0.2rem;
  gap: 0.15rem;
  transition: all 0.15s ease;
  user-select: none;
}

.bottom-nav-item i {
  font-size: 1.15rem;
  line-height: 1;
}

.bottom-nav-item:hover,
.bottom-nav-item:focus {
  color: #00875a;
}

.bottom-nav-item.active {
  color: #00875a;
  font-weight: 700;
}

.bottom-nav-item.active i {
  color: #00875a;
}

/* Hide mobile bottom nav on chat view and print */
body.page-chat .mobile-bottom-nav,
@media print {
  .mobile-bottom-nav {
    display: none !important;
  }
}

/* Mobile Dashboard Enhancements (<= 575.98px) */
@media (max-width: 575.98px) {
  .dashboard-header-title {
    font-size: 1.4rem !important;
    line-height: 1.25;
  }

  .dashboard-hero-unconnected {
    padding: 1.35rem 1rem !important;
    border-radius: var(--radius-md) !important;
  }

  .phone-illustration-box {
    width: 90px !important;
    height: 120px !important;
    border-radius: 16px !important;
  }
  .phone-illustration-box::before {
    width: 28px !important;
    height: 3px !important;
    top: 6px !important;
  }
  .phone-wa-badge {
    width: 38px !important;
    height: 38px !important;
    font-size: 1.25rem !important;
  }
  .phone-prohibition-badge {
    width: 22px !important;
    height: 22px !important;
    font-size: 0.85rem !important;
    bottom: -6px !important;
    right: -6px !important;
  }

  /* 2x2 Grid for KPI Cards on Phone */
  .dashboard-kpi-card {
    padding: 0.85rem 0.75rem !important;
    border-radius: 12px !important;
  }
  .dashboard-kpi-card .kpi-icon-box {
    width: 36px !important;
    height: 36px !important;
    font-size: 1.15rem !important;
    border-radius: 10px !important;
  }
  .dashboard-kpi-card .kpi-title {
    font-size: 0.72rem !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .dashboard-kpi-card .kpi-value {
    font-size: 1.35rem !important;
  }

  /* Quick action cards on phone */
  .quick-action-card {
    padding: 0.75rem 0.65rem !important;
  }
  .quick-action-icon {
    width: 34px !important;
    height: 34px !important;
    font-size: 1.05rem !important;
    border-radius: 8px !important;
  }
  .quick-action-card .fw-bold {
    font-size: 0.825rem !important;
  }

  /* Chat Attention Row on Phone */
  .chat-attention-row {
    padding: 0.65rem 0.35rem !important;
  }
  
  .dashboard-card {
    padding: 1rem 0.85rem !important;
    border-radius: 12px !important;
  }

  /* Mobile Contacts List optimizations */
  .mobile-contact-card {
    padding: 0.75rem !important;
  }

  /* Mobile Templates List optimizations */
  .mobile-template-card {
    padding: 0.85rem !important;
  }

  /* Mobile Campaigns List optimizations */
  .mobile-campaign-card {
    padding: 0.85rem !important;
  }

  /* Mobile Recurring Campaigns List optimizations */
  .mobile-recurring-card {
    padding: 0.85rem !important;
  }

  /* Mobile Flows List optimizations */
  .mobile-flow-card {
    padding: 0.85rem !important;
  }
}

/* Mobile Contacts CRM Cards */
.mobile-contact-card {
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  border: 1px solid #e2e8f0 !important;
}

.mobile-contact-card:hover {
  border-color: #cbd5e1 !important;
}

.mobile-contact-card:active {
  background-color: #fafbfc;
}

/* Mobile Flows Cards */
.mobile-flow-card {
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  border: 1px solid #e2e8f0 !important;
}

.mobile-flow-card:hover {
  border-color: #cbd5e1 !important;
}

.mobile-flow-card:active {
  background-color: #fafbfc;
}

/* Mobile Templates CRM Cards */
.mobile-template-card {
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  border: 1px solid #e2e8f0 !important;
}

.mobile-template-card:hover {
  border-color: #cbd5e1 !important;
}

.mobile-template-card:active {
  background-color: #fafbfc;
}

/* Mobile Campaigns Cards */
.mobile-campaign-card {
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  border: 1px solid #e2e8f0 !important;
}

.mobile-campaign-card:hover {
  border-color: #cbd5e1 !important;
}

.mobile-campaign-card:active {
  background-color: #fafbfc;
}

/* Mobile Recurring Campaigns Cards */
.mobile-recurring-card {
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  border: 1px solid #e2e8f0 !important;
}

.mobile-recurring-card:hover {
  border-color: #cbd5e1 !important;
}

.mobile-recurring-card:active {
  background-color: #fafbfc;
}

/* Recurring Sends Responsive Header Actions */
.recurring-header-actions {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}

@media (max-width: 575.98px) {
  .recurring-header-actions {
    flex-direction: column !important;
    width: 100% !important;
    align-items: stretch !important;
  }
  .recurring-header-actions .btn-group,
  .recurring-header-actions .btn-wa {
    width: 100% !important;
  }
}

/* Flex item min-width reset utility */
.min-w-0 {
  min-width: 0 !important;
}

/* WhatsApp Display Name Preview Responsive Utilities */
@media (max-width: 575.98px) {
  .whatsapp-preview-shell {
    max-width: 100% !important;
  }
  .whatsapp-preview-header-name {
    max-width: 110px !important;
  }
}

/* ==========================================================================
   Modern Modal & Dialog Backdrop (Prevents Background Bleed & Double Buttons)
   ========================================================================== */
.modal-backdrop {
  background-color: #0b1320 !important;
}

.modal-backdrop.show {
  opacity: 0.8 !important;
  backdrop-filter: blur(8px) !important;
  -webkit-backdrop-filter: blur(8px) !important;
}

@media (max-width: 575.98px) {
  .modal-dialog {
    margin: 0.75rem auto !important;
    max-width: calc(100% - 1.25rem) !important;
  }
}

/* ==========================================================================
   Responsive Sizing & Width Utilities (Bootstrap 5 Responsive Extension)
   Fixes buttons & containers expanding to 100% on desktop when w-100 is combined
   with responsive breakpoints (e.g. w-100 w-sm-auto, w-100 w-md-auto).
   ========================================================================== */
@media (min-width: 576px) {
  .w-sm-auto { width: auto !important; }
  .w-sm-25   { width: 25% !important; }
  .w-sm-50   { width: 50% !important; }
  .w-sm-75   { width: 75% !important; }
  .w-sm-100  { width: 100% !important; }
}

@media (min-width: 768px) {
  .w-md-auto { width: auto !important; }
  .w-md-25   { width: 25% !important; }
  .w-md-50   { width: 50% !important; }
  .w-md-75   { width: 75% !important; }
  .w-md-100  { width: 100% !important; }
}

@media (min-width: 992px) {
  .w-lg-auto { width: auto !important; }
  .w-lg-25   { width: 25% !important; }
  .w-lg-50   { width: 50% !important; }
  .w-lg-75   { width: 75% !important; }
  .w-lg-100  { width: 100% !important; }
}

@media (min-width: 1200px) {
  .w-xl-auto { width: auto !important; }
  .w-xl-25   { width: 25% !important; }
  .w-xl-50   { width: 50% !important; }
  .w-xl-75   { width: 75% !important; }
  .w-xl-100  { width: 100% !important; }
}

