﻿/* Business Method ERP — mobile/tablet responsive overrides (after NobleUI) */
/* Breakpoints: phone ~375–575, tablet 576–991, desktop 992+ */

html {
  -webkit-text-size-adjust: 100%;
}

body {
  overflow-x: hidden;
}

/* Avoid page-level horizontal scroll; tables scroll inside wrappers */
.page-wrapper,
.main-wrapper {
  overflow-x: hidden !important;
  max-width: 100vw;
}

.page-content {
  overflow-x: hidden !important;
  max-width: 100% !important;
  box-sizing: border-box;
}

.page-content > .row {
  max-width: 100%;
}

/* Intentional horizontal scroll only for tables */
.table-responsive {
  display: block;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Soften fixed table layout on small screens so columns can scroll */
@media (max-width: 991.98px) {
  .page-content table.bm-gap-equal,
  .page-content .bm-equal-table {
    table-layout: auto !important;
    min-width: 640px;
  }

  .page-content .table th,
  .page-content .table td {
    padding: 0.65rem 0.75rem !important;
  }

  .page-content .table th.bm-col-edit,
  .page-content .table td.bm-col-edit {
    min-width: 3.5rem;
  }
}

/* KPI tiles: 2-up on phones when using col-md auto columns */
@media (max-width: 767.98px) {
  .bm-kpi > .col-md {
    flex: 0 0 50%;
    max-width: 50%;
  }

  .bm-kpi .card {
    min-height: 0;
  }

  .bm-kpi h3 {
    font-size: 1.25rem;
  }

  .bm-kpi h5 {
    font-size: 1rem;
  }
}

@media (max-width: 399.98px) {
  .bm-kpi > .col-md,
  .bm-kpi > .col-6 {
    flex: 0 0 100%;
    max-width: 100%;
  }
}

/* Charts fill container and shrink with viewport */
.bm-chart-wrap {
  width: 100% !important;
  max-width: 100%;
  min-height: 220px;
  overflow: hidden;
}

.bm-chart-wrap .apexcharts-canvas,
.bm-chart-wrap > div {
  max-width: 100% !important;
}

@media (max-width: 575.98px) {
  .bm-chart-wrap {
    min-height: 200px;
  }
}

/* Add / filter forms: stack on small screens, no fixed widths */
.bm-add-form.form-inline,
.form-inline.bm-add-form {
  align-items: stretch;
}

.bm-add-form .bm-add-field label {
  display: block;
  font-size: 0.75rem;
  margin-bottom: 0.15rem;
  color: #8f9bb3;
}

@media (max-width: 767.98px) {
  .bm-add-form.form-inline,
  form.form-inline.flex-wrap {
    display: flex !important;
    flex-direction: column;
    align-items: stretch !important;
    width: 100%;
  }

  .bm-add-form .bm-add-field,
  .bm-add-form .form-group,
  form.form-inline .form-group.bm-add-field {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    margin-right: 0 !important;
    margin-bottom: 0.65rem !important;
  }

  .bm-add-form .form-control,
  .bm-add-form select.form-control,
  .bm-add-form input.form-control,
  .bm-add-form textarea.form-control,
  form.form-inline .form-control {
    width: 100% !important;
    max-width: 100% !important;
    min-height: 40px;
  }

  .bm-add-form .bm-add-submit,
  .bm-add-form button[type="submit"] {
    width: 100%;
    min-height: 42px;
    margin-bottom: 0 !important;
  }

  /* Filter bars (finance) */
  .card-body > form.form-inline:not(.bm-add-form) {
    display: flex !important;
    flex-wrap: wrap;
    width: 100%;
  }

  .card-body > form.form-inline:not(.bm-add-form) .form-control,
  .card-body > form.form-inline:not(.bm-add-form) select {
    flex: 1 1 100%;
    width: 100% !important;
    max-width: 100%;
    margin-right: 0 !important;
    margin-bottom: 0.5rem !important;
    min-height: 40px;
  }

  .card-body > form.form-inline:not(.bm-add-form) .btn {
    width: 100%;
    min-height: 40px;
  }
}

/* Modals fit viewport */
@media (max-width: 575.98px) {
  .modal-dialog {
    margin: 0.5rem;
    max-width: calc(100vw - 1rem);
  }

  .modal-content {
    max-height: calc(100vh - 1rem);
    overflow-y: auto;
  }

  .modal-footer {
    flex-wrap: wrap;
    gap: 0.35rem;
  }

  .modal-footer .btn {
    min-height: 40px;
  }
}

/* Page header / actions */
.bm-page-header {
  gap: 0.5rem;
}

@media (max-width: 575.98px) {
  .bm-page-header {
    flex-direction: column;
    align-items: flex-start !important;
  }

  .bm-page-header h4 {
    font-size: 1.25rem;
  }

  .page-content {
    padding-left: 12px !important;
    padding-right: 12px !important;
    padding-top: 12px !important;
  }
}

/* Touch-friendly controls */
@media (max-width: 991.98px) {
  .btn-sm {
    min-height: 36px;
    padding: 0.35rem 0.65rem;
  }

  .bm-edit-btn {
    min-width: 36px;
    min-height: 36px;
    padding: 6px;
  }

  .form-control-sm {
    min-height: 38px;
    font-size: 16px; /* reduces iOS zoom on focus */
  }

  input[type="date"].form-control-sm {
    min-height: 40px;
  }

  /* Support action buttons wrap */
  td.text-nowrap form.d-inline {
    display: inline-block;
    margin: 0.15rem 0.15rem 0.15rem 0;
  }

  td.text-nowrap .btn {
    margin-bottom: 0.15rem;
  }
}

/* Mobile top bar — open sidebar when off-canvas */
.bm-mobile-topbar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 970;
  align-items: center;
  justify-content: flex-start;
  min-height: 52px;
  padding: 0.5rem 0.75rem;
  margin: 0 -15px 0.75rem;
  background: #0c1427;
  border-bottom: 1px solid #172340;
}

.bm-mobile-topbar .bm-mobile-brand {
  font-weight: 700;
  color: #eef4ff;
  font-size: 1rem;
  text-decoration: none;
  letter-spacing: -0.02em;
}

.bm-mobile-topbar .bm-mobile-brand span {
  color: #727cf5;
  font-weight: 400;
}

.bm-mobile-topbar .sidebar-toggler {
  cursor: pointer;
  width: 22px;
  padding: 10px 4px;
  margin: -6px 0.75rem -6px 0;
  flex-shrink: 0;
}

.bm-mobile-topbar .sidebar-toggler span {
  display: block;
  width: 100%;
  border-radius: 3px;
  height: 2px;
  background: #9fa2ab;
  position: relative;
}

.bm-mobile-topbar .sidebar-toggler span + span {
  margin-top: 5px;
}

@media (max-width: 991.98px) {
  .bm-mobile-topbar {
    display: flex;
  }

  /* Ensure off-canvas sidebar can open above content */
  .sidebar {
    transition: margin .2s ease, visibility .2s ease;
  }

  .sidebar-open .sidebar {
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.35);
  }

  /* Folded desktop rules must not shrink mobile off-canvas width */
  body.sidebar-folded .sidebar,
  .sidebar-folded .sidebar {
    width: 240px !important;
  }

  body.sidebar-folded .sidebar .link-title,
  .sidebar-folded .sidebar .link-title {
    display: inline !important;
    width: auto !important;
    opacity: 1 !important;
    visibility: visible !important;
  }

  body.sidebar-folded .sidebar .sidebar-body .nav .nav-item .nav-link {
    justify-content: flex-start;
    padding-left: 25px;
    padding-right: 25px;
  }

  /* Collapsed icons on desktop stay clickable; on mobile full labels when open */
  .sidebar .nav-link {
    min-height: 44px;
    align-items: center;
  }
}

/* Footer search doesn't blow out width */
.footer {
  padding-left: 0.75rem !important;
  padding-right: 0.75rem !important;
  gap: 0.5rem;
}

.footer .bm-footer-search,
.footer .search-form {
  width: 100%;
  max-width: 100%;
}

.footer .bm-footer-search .form-control {
  min-height: 40px;
  font-size: 16px;
}

@media (min-width: 768px) {
  .footer .bm-footer-search,
  .footer .search-form {
    max-width: 280px;
  }
}

/* Amount / nowrap cells: allow scroll via table wrapper, don't force page wide */
@media (max-width: 991.98px) {
  .bm-amount {
    font-size: 0.95rem;
  }
}

/* Card body padding on very small screens */
@media (max-width: 575.98px) {
  .bm-dense .card-body {
    padding: 0.9rem 0.85rem;
  }

  .card .card-title {
    font-size: 0.95rem;
  }
}


/* Extra: support action cell wrap on phones */
@media (max-width: 575.98px) {
  .table td.text-nowrap {
    white-space: normal;
  }
  .table td.text-nowrap .btn {
    display: inline-block;
  }
}

/* Extra: sticky mobile topbar offset */
@media (max-width: 991.98px) {
  .bm-mobile-topbar {
    margin-left: -12px;
    margin-right: -12px;
    padding-left: 12px;
    padding-right: 12px;
  }
}
