/* Mobile-first responsive fixes for TradeCRM */

html,
body {
  overflow-x: hidden;
}

/* Dashboard page scope */
#dashboardPage {
  max-width: 100%;
}

/* Keep chart canvases from causing overflow */
#dashboardPage canvas {
  display: block;
  max-width: 100%;
}

.dropdown-item.active, .dropdown-item:active {
	background-color: #35A4A8 !important;
}

/* Reduce some paddings on small screens */
@media (max-width: 991.98px) {
  main.p-4 {
    padding: 1rem;
  }
}

/* KPI/action headers should wrap instead of overflowing */
@media (max-width: 575.98px) {
  #dashboardPage .card-header .d-flex {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  #dashboardPage #dashboardFollowups>div.d-flex {
    flex-wrap: wrap;
    row-gap: 0.5rem;
  }

  #dashboardPage .table-responsive {
    -webkit-overflow-scrolling: touch;
  }
}

/* Fine-tuning for slightly larger phones */
@media (min-width: 576px) and (max-width: 767.98px) {
  #dashboardPage .card-header .d-flex {
    gap: 0.75rem;
  }
}

/* Tablet tweaks */
@media (min-width: 768px) {
  #dashboardPage .card-header .d-flex {
    flex-direction: row;
    align-items: center;
    gap: 1rem;
  }
}

/* Mobile sidebar toggle (Bootstrap collapse is not used) */
@media (max-width: 991.98px) {

  /* Sidebar becomes a fixed off-canvas panel */
  .crm-sidebar {
    position: fixed;
    top: 60px;
    left: 0px;
    border-radius: 8px;
    height: calc(100vh - 70px);
    transform: translateX(-100%);
    transition: transform 0.22s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1051;
    max-width: 90vw;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .crm-sidebar.open {
    transform: translateX(0);
  }

  /* Backdrop fades in behind the sidebar */
  .crm-sidebar-backdrop {
    display: block;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
    z-index: 1050;
  }

  .crm-sidebar-backdrop.show {
    opacity: 1;
    pointer-events: auto;
  }

  /* The sidebar nav uses an inline height; ensure it fits within the off-canvas panel */
  .crm-sidebar .navbar-nav {
    height: auto !important;
  }
}

/* Mobile header search (always visible input with icon) */
@media (max-width: 991.98px) {
  .mobile-search-static {
    min-width: 0;
  }

  .mobile-search-input-wrapper {
    position: relative;
    flex: 1;
    min-width: 0;
    max-width: 220px;
  }

  .mobile-search-input-wrapper .form-control {
    border-radius: 20px;
    height: 40px;
    padding-left: 2.25rem;
    /* space for icon */
    padding-right: 1rem;
    background: #F1F5F9;
  }

  .mobile-search-input-wrapper .mobile-search-icon {
    position: absolute;
    left: 0.9rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--crm-secondary);
    opacity: 0.9;
    pointer-events: none;
  }
}

/* Layout stability at larger breakpoints */
@media (min-width: 992px) {
  .crm-sidebar {
    transform: none;
  }

  /* Optional desktop collapse (hamburger can hide/show sidebar) */
  .crm-sidebar.desktop-collapsed {
    width: 0;
    min-width: 0 !important;
    /* overrides inline min-width */
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
  }
}

/* Small extra spacing for xl screens */
@media (min-width: 1200px) {
  #dashboardPage .card-body {
    word-break: break-word;
  }
}

/* ------------------------------------------------------------
   Dashboard mobile replication (<= 768px and <= 576px)
   ------------------------------------------------------------ */
@media (max-width: 768px) {
  /* Leave space for the fixed bottom nav */
  #dashboardPage {
    padding-bottom: 92px;
  }

  #profilePage {
    padding-bottom: 92px;
  }

  #usersIndexPage,
  #usersCreatePage,
  #usersEditPage,
  #tradeMansIndexPage {
    padding-bottom: 22px;
  }

  /* Match screenshot: only show meta/google lead cards + recent lists */
  #dashboardPage .dashboard-mobile-hide {
    display: none;
  }

  #dashboardPage .dashboard-mobile-sidebar {
    display: none;
  }

  /* Tighter spacing for mobile */
  #dashboardPage .row.g-4 {
    --bs-gutter-x: 0.75rem;
    --bs-gutter-y: 0.75rem;
  }

  /* KPI + lead cards spacing */
  #dashboardPage .card-body.p-4 {
    padding: 1rem !important;
  }

  #dashboardPage .card-body.p-4.py-3,
  #dashboardPage .card-body.p-4.py-3 {
    padding: 0.95rem !important;
  }

  #dashboardPage .card-header.p-3 {
    padding: 0.85rem !important;
  }

  /* Hide "View All" buttons to match the compact mobile cards */
  #dashboardPage a.single-border-core-theme {
    display: none;
  }

  /* Charts: prevent overflow + keep a compact height */
  #dashboardPage .card-body {
    overflow: hidden;
  }

  #dashboardPage #leadsChart,
  #dashboardPage #revenueChart {
    height: 100px !important;
  }

  /* Mobile bottom navigation */
  #mobileBottomNav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 0 0.75rem 0.75rem;
    z-index: 3000;
  }

  #mobileBottomNav .mobile-bottom-nav-inner {
    background: #15233f;
    border-radius: 1.1rem;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.18);
    padding: 0.45rem 0.45rem;
    display: flex;
    gap: 0.25rem;
  }

  #mobileBottomNav .mobile-bottom-nav-item {
    flex: 1;
    text-decoration: none;
    color: rgba(255, 255, 255, 0.7);
    border-radius: 0.9rem;
    padding: 0.55rem 0.25rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.2rem;
    font-size: 0.78rem;
    font-weight: 600;
    outline: none;
  }

  #mobileBottomNav .mobile-bottom-nav-item:focus-visible {
    box-shadow: 0 0 0 3px rgba(53, 164, 168, 0.35);
  }

  #mobileBottomNav .mobile-bottom-nav-item i {
    font-size: 1.2rem;
    line-height: 1;
  }

  #mobileBottomNav .mobile-bottom-nav-item.active {
    background: rgba(53, 164, 168, 0.16);
    color: #35A4A8;
  }
}

@media (max-width: 576px) {
  .crm-hide-title-on-mobile {
    display: none;
  }

  .crm-hide-breadcrumb-title-on-mobile {
    display: none;
  }

  #dashboardPage .card-body.p-4 {
    padding: 0.9rem !important;
  }

  #dashboardPage .card-header.p-3 {
    padding: 0.75rem !important;
  }

  #dashboardPage h2#stat-tradesmen,
  #dashboardPage h2#stat-leads,
  #dashboardPage h2#stat-active-jobs,
  #dashboardPage h2#stat-revenue {
    font-size: 1.25rem;
  }

  #mobileBottomNav {
    padding: 0 0.6rem 0.65rem;
  }

  #mobileBottomNav .mobile-bottom-nav-item {
    font-size: 0.74rem;
  }

  #dashboardPage #leadsChart,
  #dashboardPage #revenueChart {
    height: 92px !important;
  }
}
