/* =============================================
   Blucript Responsive Overrides
   Target: 768px minimum (tablet)
   ============================================= */

/* ---- Prevent horizontal scrollbar globally ---- */
html, body {
  overflow-x: hidden;
}
.nk-app-root {
  overflow-x: hidden;
}

/* ============================================
   SECTION 1: Sidebar & Navigation
   ============================================ */

/* Hamburger menu button in header (visible below 1200px) */
.nk-header-hamburger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  font-size: 24px;
  color: #526484;
  border-radius: 4px;
  transition: color 0.2s;
  text-decoration: none;
}
.nk-header-hamburger:hover {
  color: #4782C4;
  text-decoration: none;
}
.nk-header-menu-toggle {
  margin-right: 12px;
  flex-shrink: 0;
}

/* At <=1199px: sidebar goes off-canvas, content takes full width */
@media (max-width: 1199.98px) {
  .has-sidebar .nk-wrap {
    padding-left: 0 !important;
  }
  .menu-expanded .nk-content {
    margin-left: 0 !important;
  }
  /* Sidebar: hidden by default, slides in when toggled */
  .nk-sidebar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    height: 100vh !important;
    width: 250px !important;
    z-index: 1030 !important;
    transform: translateX(-100%) !important;
    transition: transform 0.3s ease;
    background: #fff;
  }
  /* JS adds toggle-active to the toggle and nk-sidebar-active to the sidebar when clicked */
  .nk-sidebar.nk-sidebar-active.nk-sidebar-mobile {
    transform: translateX(0) !important;
  }
  /* Also handle the case when JS toggles via nav-shown on body */
  .nav-shown .nk-sidebar {
    transform: translateX(0) !important;
  }
  /* Overlay behind sidebar when open */
  .nk-sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 1029;
  }
}

/* ============================================
   SECTION 2: Header
   ============================================ */
@media (max-width: 991.98px) {
  .nk-header-wrap {
    flex-wrap: nowrap;
  }
  .nk-header-wrap .nk-header-search-container {
    flex: 1;
    min-width: 0;
    overflow: hidden;
  }
  .nk-header-wrap .nk-header-tools {
    flex-shrink: 0;
  }
  .nk-header-search-container h5 {
    font-size: 14px !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

@media (max-width: 767.98px) {
  .user-toggle .user-info {
    max-width: 160px;
    overflow: hidden;
  }
  .nk-header .nk-quick-nav > li {
    padding: 0 4px;
  }
}

/* ============================================
   SECTION 3: Global Table Responsiveness
   ============================================ */
@media (max-width: 991.98px) {
  /* Make tables horizontally scrollable */
  .nk-tb-list {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Override hardcoded column widths from inline styles */
  .table th[style*="width"],
  .table td[style*="width"],
  .datatable-init th[style*="width"],
  .datatable-init td[style*="width"],
  .datatable-init-export th[style*="width"],
  .datatable-init-export td[style*="width"] {
    width: auto !important;
    min-width: 80px !important;
  }

  /* DataTables: scroll only the table area, keep pagination/controls static */
  .dataTables_wrapper {
    overflow: visible !important;
  }
  /* DataTables scrollX: ensure scroll container works properly */
  .dataTables_wrapper .dataTables_scroll {
    overflow: visible !important;
  }
  .dataTables_wrapper .dataTables_scrollHead,
  .dataTables_wrapper .dataTables_scrollBody {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }
  /* Fallback: if datatable-wrap is used without scrollX */
  .dataTables_wrapper .datatable-wrap {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }
  /* Also handle cases where table is direct child or inside scroll wrapper */
  .dataTables_wrapper > .dataTables_scroll,
  .dataTables_wrapper > table,
  .dataTables_wrapper > .table-responsive {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }
  .dataTables_wrapper .dataTables_info,
  .dataTables_wrapper .dataTables_paginate,
  .dataTables_wrapper .dataTables_length,
  .dataTables_wrapper .dataTables_filter {
    overflow: visible !important;
    width: 100% !important;
  }
}

/* ============================================
   SECTION 4: Negative Margin Overrides
   ============================================ */
@media (max-width: 1199.98px) {
  div[style*="margin-left: -21px"],
  div[style*="margin-left: -22%"],
  div[style*="margin-left: -20px"],
  div[style*="margin-left: -25px"],
  div[style*="margin-left: -18px"],
  div[style*="margin-left: -40%"],
  div[style*="margin-left: -10px"],
  div[style*="margin-left:-20px"],
  div[style*="margin-left:-25px"],
  div[style*="margin-left:-10px"] {
    margin-left: 0 !important;
  }
}

/* ============================================
   SECTION 5: Dashboard Card Reflow
   ============================================ */
@media (max-width: 991.98px) {
  .col-xxl {
    flex: 0 0 50% !important;
    max-width: 50% !important;
  }
}
@media (max-width: 767.98px) {
  .col-xxl {
    flex: 0 0 100% !important;
    max-width: 100% !important;
  }
}

/* ============================================
   SECTION 6: Chat Page
   ============================================ */
@media (max-width: 991.98px) {
  .chat-input-container {
    max-width: 100% !important;
  }
  .whatsapp-chat1 {
    max-width: 100% !important;
  }
  .emoji-picker,
  .emoji-picker2,
  .emoji-picker3 {
    left: 0 !important;
    right: auto !important;
    max-width: 350px !important;
    width: calc(100vw - 40px) !important;
  }
  .nk-chat-aside {
    width: 100% !important;
    max-width: 100% !important;
  }
}

/* Chat aside toggle on tablet */
@media (max-width: 1199.98px) {
  .nk-chat-body {
    min-width: 0 !important;
  }
}

/* ============================================
   SECTION 7: Form Elements
   ============================================ */
@media (max-width: 991.98px) {
  select[style*="width: 150px"],
  select[style*="width: 206px"],
  .form-control-wrap[style*="width: 206px"] {
    width: 100% !important;
  }
  .swal2-popup {
    width: 90vw !important;
    max-width: 500px !important;
  }
}

/* ============================================
   SECTION 8: Contact List Filter Row
   ============================================ */
@media (max-width: 991.98px) {
  .contact-filter-row .col-2,
  .filter-row .col-2 {
    flex: 0 0 33.333% !important;
    max-width: 33.333% !important;
    margin-bottom: 8px;
  }
}
@media (max-width: 767.98px) {
  .contact-filter-row .col-2,
  .filter-row .col-2 {
    flex: 0 0 50% !important;
    max-width: 50% !important;
  }
}

/* ============================================
   SECTION 9: Automation Button Widths
   ============================================ */
@media (max-width: 991.98px) {
  button[style*="min-width: 280px"],
  button[style*="min-width: 250px"] {
    min-width: unset !important;
    width: 100% !important;
  }
}

/* ============================================
   SECTION 10: Appointment Calendar
   ============================================ */
@media (max-width: 991.98px) {
  .fc .fc-toolbar {
    flex-direction: column !important;
    gap: 8px;
  }
  .fc .fc-toolbar-title {
    font-size: 1rem !important;
  }
  .fc .fc-button {
    padding: 4px 8px !important;
    font-size: 0.8rem !important;
  }
}

/* ============================================
   SECTION 11: Flow Details
   ============================================ */
@media (max-width: 991.98px) {
  div[style*="max-width: 1280px"],
  div[style*="max-width: 800px"] {
    max-width: 100% !important;
  }
}

/* ============================================
   SECTION 12: Template Emoji Grid
   ============================================ */
@media (max-width: 991.98px) {
  div[style*="grid-template-columns: repeat(8"] {
    grid-template-columns: repeat(6, 1fr) !important;
    width: 260px !important;
  }
}

/* ============================================
   SECTION 13: Page Action Buttons
   ============================================ */
@media (max-width: 767.98px) {
  .nk-block-head-content .text-end,
  .nk-block-head-content .text-md-end {
    text-align: left !important;
    margin-top: 8px;
  }
  .nk-block-head-content .btn {
    margin-bottom: 4px;
  }
}

/* ============================================
   SECTION 14: Auth Pages
   ============================================ */
@media (max-width: 767.98px) {
  .nk-block.nk-block-middle {
    margin-top: 40px !important;
  }
  .nk-split-content {
    padding: 20px !important;
  }
}

/* ============================================
   SECTION 15: Settings Pages
   ============================================ */
@media (max-width: 991.98px) {
  .card-aside {
    width: 100% !important;
    max-width: 100% !important;
  }
  .card-aside-wrap {
    flex-direction: column !important;
  }
  .card-content {
    width: 100% !important;
  }
}

/* ============================================
   SECTION 16: Modal Dialogs
   ============================================ */
@media (max-width: 767.98px) {
  .modal-dialog {
    margin: 10px !important;
    max-width: calc(100vw - 20px) !important;
  }
  .modal-lg,
  .modal-xl {
    max-width: calc(100vw - 20px) !important;
  }
}

/* ============================================
   SECTION 17: DataTable Controls
   ============================================ */
@media (max-width: 991.98px) {
  .dataTables_wrapper .dataTables_length,
  .dataTables_wrapper .dataTables_filter {
    text-align: left !important;
    margin-bottom: 8px;
  }
  .dataTables_wrapper .dataTables_info,
  .dataTables_wrapper .dataTables_paginate {
    text-align: center !important;
    margin-top: 8px;
  }
  .dataTables_wrapper .dataTables_paginate .paginate_button {
    padding: 4px 8px !important;
  }
}

/* ============================================
   SECTION 18: Back Button Link Fix
   ============================================ */
@media (max-width: 991.98px) {
  .back-button-link + .ql-menu-link {
    margin-left: 0 !important;
    float: none !important;
  }
}

/* ============================================
   SECTION 19: Broadcast & Template Previews
   ============================================ */
@media (max-width: 991.98px) {
  .referral-card {
    max-width: 100% !important;
  }
  div[style*="min-width: 320px"] {
    min-width: unset !important;
    width: 100% !important;
  }
  div[style*="min-width: 250px"] {
    min-width: unset !important;
  }
}

/* ============================================
   SECTION 20: Tooltip / Popup Positioning
   ============================================ */
@media (max-width: 991.98px) {
  .appointment-popup,
  .booking-popup,
  .tooltip-custom {
    min-width: unset !important;
    max-width: calc(100vw - 30px) !important;
    left: 15px !important;
    right: 15px !important;
  }
}
