/**
 * AIO ERP Mobile Responsive Improvements
 * Critical fixes for mobile/tablet responsiveness
 */

/* ============================================
   1. SIDEBAR MOBILE RESPONSIVENESS
   ============================================ */

@media (max-width: 1023.98px) {
  /* Hide sidebar off-screen by default.
     Boundary is 1023.98px (not 991px) to match the sidebar's Tailwind `lg`
     (1024px) reveal point — otherwise 992–1023px had neither the static
     sidebar nor the mobile toggle (dead zone). */
  .side-bar {
    position: fixed !important;
    left: 0;
    top: 0;
    height: 100dvh !important;
    max-height: 100dvh !important;
    z-index: 1030;
    transform: translateX(-100%);
    transition: transform 0.3s ease-in-out;
    background-color: var(--bg-surface, #fff);
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.15);
    overflow-y: auto;
    overflow-x: hidden;
    width: min(260px, 86vw) !important;
    -webkit-overflow-scrolling: touch;
  }

  /* Show when existing app handler adds small-view-side-active.
     Two-class specificity (0-2-0) beats bundle-foundation.css's single-class
     z-index: 1001 !important even though that file loads later. */
  .side-bar.small-view-side-active {
    transform: translateX(0) !important;
    z-index: 1150 !important;
  }

  /* Ensure the business switch button has a proper tap target on mobile (≥44×44) */
  .app-sidebar-switch-btn {
    min-width: 44px !important;
    min-height: 44px !important;
    width: 44px !important;
    height: 44px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  .app-premium-main,
  .content-wrapper,
  .main-content {
    margin-left: 0 !important;
    width: 100% !important;
  }

  #mobile-sidebar-toggle {
    display: inline-flex !important;
  }
}

@media (min-width: 1024px) {
  #mobile-sidebar-toggle {
    display: none !important;
  }
}

/* ============================================
   2. SELECT2 DROPDOWN WIDTH FIX
   ============================================ */

/* Allow Select2 JS to set the natural container-matched width;
   only clamp to prevent viewport overflow. */
.select2-container--open .select2-dropdown {
  max-width: calc(100vw - 20px) !important;
  max-height: 300px;
  overflow-y: auto;
  box-sizing: border-box !important;
}

@media (max-width: 991px) {
  .select2-container--open .select2-dropdown {
    /* Do NOT set width: auto — that shrinks the dropdown below its container width.
       Let Select2 JS set width to match container; only cap max-width. */
    min-width: unset !important;
    max-width: calc(100vw - 20px) !important;
    right: auto !important;
    box-sizing: border-box !important;
  }

  .select2-container {
    max-width: 100% !important;
  }
}

@media (max-width: 576px) {
  .select2-container--open .select2-dropdown {
    max-width: calc(100vw - 16px) !important;
  }

  .select2-container {
    width: 100% !important;
  }
}

/* ============================================
   2b. ACTION DROPDOWN — MOBILE SCROLL FIX
   ============================================ */

@media (max-width: 991px) {
  /* Limit tall dropdowns so the page stays scrollable behind them.
     JS in responsive-mobile.js dynamically clamps position:fixed menus. */
  .dropdown-menu {
    max-height: 65vh !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }
}

/* ============================================
   3. FORM LAYOUT RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
  .form-group.col-md-4,
  .form-group.col-md-6,
  .form-group.col-md-3,
  .form-group.col-md-12 {
    flex: 0 0 100% !important;
    max-width: 100% !important;
    margin-bottom: var(--space-3, 12px);
  }

  .form-control,
  .select2-container,
  input[type='text'],
  input[type='email'],
  input[type='number'],
  input[type='date'],
  textarea,
  select {
    width: 100% !important;
    max-width: 100% !important;
  }
}

/* ============================================
   4. DATATABLE MOBILE
   ============================================ */

@media (max-width: 768px) {
  .dataTables_wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  table.dataTable {
    min-width: 600px;
    font-size: 13px;
  }

  table.dataTable .btn-group .btn,
  table.dataTable .btn-sm {
    padding: 4px 6px;
    font-size: 11px;
  }
}

/* ============================================
   5. MODAL MOBILE
   ============================================ */

@media (max-width: 576px) {
  .modal-dialog {
    margin: var(--space-2, 8px);
    max-width: calc(100% - 16px);
  }

  .modal-dialog.modal-lg,
  .modal-dialog.modal-xl {
    max-width: calc(100% - 16px);
  }

  .modal-footer {
    flex-wrap: wrap;
    gap: 8px;
  }

  .modal-footer .btn {
    flex: 1 1 auto;
    min-width: 100px;
  }
}

@media (max-width: 991px) {
  /* Prevent tables inside modals from blowing past modal boundaries */
  .modal .table-responsive,
  .modal-body .table-responsive {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    max-width: 100% !important;
  }

  /* Override bundle-foundation.css `.view_modal .table:not(.no-border) { overflow: hidden !important }`
     That rule has specificity 0-3-0. We use 0-3-1 (3 classes + element type) to beat it.
     The tables inside view_modal need overflow-x: auto to enable horizontal scroll. */
  .view_modal .modal-body table.table,
  .modal-body table.table-bordered,
  .modal-body table.table-striped {
    display: block !important;
    overflow-x: auto !important;
    overflow-y: visible !important;
    -webkit-overflow-scrolling: touch !important;
    max-width: 100% !important;
    width: 100% !important;
  }

  /* Restore normal table layout inside the scroll wrapper */
  .view_modal .modal-body table.table thead,
  .view_modal .modal-body table.table tbody,
  .view_modal .modal-body table.table tfoot,
  .modal-body table.table-bordered thead,
  .modal-body table.table-bordered tbody,
  .modal-body table.table-bordered tfoot {
    display: table !important;
    width: 100% !important;
  }
}

/* ============================================
   6. TOUCH TARGETS
   ============================================ */

@media (max-width: 768px) {
  .form-control,
  .select2-container .select2-selection {
    min-height: 44px;
    font-size: 16px; /* Prevents auto-zoom on iOS */
  }

  .form-group label {
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 500;
  }
}

/* ============================================
   7. HEADER MOBILE
   ============================================ */

@media (max-width: 768px) {
  .navbar,
  .top-nav {
    padding: var(--space-2, 8px) var(--space-3, 12px);
  }
}

/* ============================================
   8. SPACING ADJUSTMENTS
   ============================================ */

@media (max-width: 768px) {
  .content,
  .container-fluid {
    padding: var(--space-3, 12px);
  }

  .card,
  .box,
  .widget {
    margin-bottom: var(--space-3, 12px);
  }
}

/* ============================================
   9. DATERANGEPICKER MOBILE
   ============================================ */

@media (max-width: 767px) {
  /* Fix to viewport so the picker is always fully visible regardless of
     where the trigger input sits in the document. */
  .daterangepicker {
    position: fixed !important;
    top: 10px !important;
    left: 8px !important;
    right: 8px !important;
    bottom: auto !important;
    width: calc(100vw - 16px) !important;
    max-width: calc(100vw - 16px) !important;
    max-height: calc(100vh - 20px) !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    z-index: var(--z-picker, 1310) !important;
  }

  /* Hide second calendar — single calendar sufficient on small screens */
  .daterangepicker .drp-calendar.right {
    display: none !important;
  }

  /* Full-width single calendar */
  .daterangepicker .drp-calendar.left {
    border: 0 !important;
    padding: var(--space-2, 8px) !important;
    max-width: 100% !important;
    width: 100% !important;
    float: none !important;
    clear: both !important;
  }

  /* Presets list full-width */
  .daterangepicker .ranges {
    float: none !important;
    width: 100% !important;
    border-bottom: 1px solid var(--border-color, #e2e8f0);
  }

  .daterangepicker.show-calendar .ranges {
    margin: 0 !important;
    border-bottom: 1px solid var(--border-color, #e2e8f0) !important;
  }

  /* Calendar table fills available width */
  .daterangepicker .drp-calendar.left .calendar-table {
    width: 100% !important;
    padding: 0 !important;
  }

  .daterangepicker .drp-calendar.left .calendar-table table {
    width: 100% !important;
  }

  /* Action buttons row */
  .daterangepicker .drp-buttons {
    padding: var(--space-2, 8px) var(--space-3, 12px) !important;
    display: flex !important;
    justify-content: flex-end !important;
    gap: 8px !important;
  }

  .daterangepicker .drp-buttons .btn {
    flex: 0 0 auto !important;
  }
}

/* ============================================
   10. DATATABLE SPINNER — PREMIUM REDESIGN
   ============================================ */

/* Remove the card/container box and centre in the viewport (not the wrapper).
   position: fixed ensures visibility regardless of wrapper height.
   Specificity 0-3-2 beats bundle-shadcn.css's 0-3-1 selector. */
html body.premium-ui .dataTables_wrapper .dataTables_processing,
html body .dataTables_wrapper .dataTables_processing {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  padding: 0 !important;
  display: flex;
  align-items: center !important;
  justify-content: center !important;
  width: 64px !important;
  height: 64px !important;
  position: fixed !important;
  top: 50vh !important;
  left: 50vw !important;
  transform: translate(-50%, -50%) !important;
  margin: 0 !important;
  z-index: 9998 !important;
}

/* Premium dual-arc spinner with brand colors */
.table-spinner {
  width: 44px !important;
  height: 44px !important;
  border-width: 3px !important;
  border-style: solid !important;
  /* Dim track */
  border-color: rgba(30, 58, 111, 0.12) !important;
  /* Leading arc: brand navy */
  border-left-color: #1E3A6F !important;
  /* Trailing accent: brand orange */
  border-top-color: #fca424 !important;
  border-radius: 50% !important;
  animation: aio-spin-outer 0.72s cubic-bezier(0.5, 0.15, 0.5, 0.85) infinite !important;
  position: relative !important;
  display: block !important;
  margin: 0 auto !important;
}

/* Inner counter-rotating accent ring */
.table-spinner::after {
  content: '';
  position: absolute;
  inset: 7px;
  border-radius: 50%;
  border: 2px solid transparent;
  border-top-color: rgba(30, 58, 111, 0.35);
  border-bottom-color: rgba(252, 164, 36, 0.35);
  animation: aio-spin-inner 1.1s cubic-bezier(0.5, 0.15, 0.5, 0.85) infinite reverse;
}

@keyframes aio-spin-outer {
  to { transform: rotate(360deg); }
}

@keyframes aio-spin-inner {
  to { transform: rotate(360deg); }
}

/* Hide spinner when table has loaded data (tbody > tr visible) */
.dataTables_wrapper:has(tbody tr:not(.odd):not(.even)) .dataTables_processing {
  display: none !important;
}

/* ============================================
   11. GENERIC PREMIUM SPINNER — REUSABLE
   ============================================ */

/* Generic premium spinner that can be used anywhere in the app */
.aio-spinner {
  width: 44px !important;
  height: 44px !important;
  border-width: 3px !important;
  border-style: solid !important;
  /* Dim track */
  border-color: rgba(30, 58, 111, 0.12) !important;
  /* Leading arc: brand navy */
  border-left-color: #1E3A6F !important;
  /* Trailing accent: brand orange */
  border-top-color: #fca424 !important;
  border-radius: 50% !important;
  animation: aio-spin-outer 0.72s cubic-bezier(0.5, 0.15, 0.5, 0.85) infinite !important;
  position: relative !important;
  display: inline-block !important;
}

/* Inner counter-rotating accent ring */
.aio-spinner::after {
  content: '';
  position: absolute;
  inset: 7px;
  border-radius: 50%;
  border: 2px solid transparent;
  border-top-color: rgba(30, 58, 111, 0.35);
  border-bottom-color: rgba(252, 164, 36, 0.35);
  animation: aio-spin-inner 1.1s cubic-bezier(0.5, 0.15, 0.5, 0.85) infinite reverse;
}

/* Smaller inline variant (for buttons and inline text) */
.aio-spinner.aio-spinner-sm {
  width: 20px !important;
  height: 20px !important;
  border-width: 2px !important;
}

.aio-spinner.aio-spinner-sm::after {
  inset: 4px;
  border-width: 1px !important;
}

/* Centered loading message wrapper */
.aio-loading-message {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
}

.aio-loading-message .aio-spinner {
  flex-shrink: 0;
}

/* ============================================
   12. P0 DEVICE UX (2026-07-16 re-audit)
   - WCAG 2.5.5 touch targets on shared chrome
   - safe-area for notched iPhones / home indicators
   ============================================ */

/* Prevent whole-page horizontal scroll from chrome/padding (do NOT pad html —
   that expands scrollWidth on iOS and causes sideways swipe). */
html, body {
  max-width: 100%;
  overflow-x: clip;
}
body.premium-ui,
body {
  overflow-x: clip;
}

body.premium-ui .app-header,
.app-header,
.main-header {
  padding-top: max(0px, env(safe-area-inset-top, 0px));
  padding-left: max(0px, env(safe-area-inset-left, 0px));
  padding-right: max(0px, env(safe-area-inset-right, 0px));
}

/* tw-dw-btn uses display:inline-flex !important which beats Bootstrap .hide.
   Sell create/edit toggle Add Payment via .hide — force it to win everywhere. */
button.tw-dw-btn.hide,
a.tw-dw-btn.hide,
#add_payment_btn.hide,
#add_payment_btn[hidden] {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

/* Desktop / large tablet landscape: no artificial bottom gap in the
   admin sidebar. Mobile browser chrome is handled only under the media
   query below — the previous global max(96px, …) made a huge empty strip
   after the last menu item on desktop. */
body.premium-ui aside.side-bar,
.side-bar {
  padding-top: max(0px, env(safe-area-inset-top, 0px));
  padding-bottom: max(0px, env(safe-area-inset-bottom, 0px));
  padding-left: max(0px, env(safe-area-inset-left, 0px));
  height: 100dvh !important;
  max-height: 100dvh !important;
  box-sizing: border-box !important;
}
body.premium-ui aside.side-bar .sidebar,
.side-bar .sidebar,
body.premium-ui aside.side-bar .sidebar-menu,
.side-bar .sidebar-menu {
  padding-bottom: max(8px, env(safe-area-inset-bottom, 0px));
}

/* Phone / tablet portrait only: leave room so last menu items stay above
   Safari/Chrome bottom URL chrome (not covered by safe-area-inset alone). */
@media (max-width: 1023.98px) {
  body.premium-ui aside.side-bar,
  .side-bar {
    padding-bottom: max(56px, calc(env(safe-area-inset-bottom, 0px) + 40px));
  }
  body.premium-ui aside.side-bar .sidebar,
  .side-bar .sidebar,
  body.premium-ui aside.side-bar .sidebar-menu,
  .side-bar .sidebar-menu {
    padding-bottom: max(16px, env(safe-area-inset-bottom, 0px));
  }
}

.main-footer,
body.premium-ui .main-footer {
  padding-bottom: max(8px, env(safe-area-inset-bottom, 0px));
  padding-left: max(0px, env(safe-area-inset-left, 0px));
  padding-right: max(0px, env(safe-area-inset-right, 0px));
}

/* Header / chrome touch targets (≥44×44) on phone + tablet portrait.
   CRITICAL: do NOT set display:…!important here — it overrides Tailwind
   tw-hidden / md:tw-inline-flex and forces calendar/calc/quick-add/etc.
   back onto small screens (real-phone report 2026-07-17). Size only the
   already-visible controls. */
@media (max-width: 1023.98px) {
  body.premium-ui .app-header .app-header-btn,
  body.premium-ui .app-header .app-header-action.app-header-btn,
  body.premium-ui .app-header button.app-header-btn,
  body.premium-ui .app-header a.app-header-btn,
  .app-header .app-header-btn,
  .app-header #theme-toggle,
  .app-header #mobile_search_btn,
  .app-header #universal_search_toggle,
  #mobile-sidebar-toggle,
  #theme-toggle,
  #mobile_search_btn,
  #universal_search_toggle {
    min-width: 44px !important;
    min-height: 44px !important;
    width: auto !important;
    height: auto !important;
    /* no display:!important — preserves responsive hide classes */
    align-items: center !important;
    justify-content: center !important;
    padding: 10px !important;
    box-sizing: border-box !important;
  }

  /* Icon-only header controls that were ~31×31 */
  body.premium-ui .app-header .app-header-btn svg,
  body.premium-ui .app-header .app-header-btn i {
    flex-shrink: 0;
  }

  /* Promo / subscription CTAs in chrome (e.g. Start Free Trial) — size only */
  body.premium-ui .app-header a:not(.app-header-btn),
  .app-header .btn,
  .app-header .tw-dw-btn,
  .navbar-custom-menu > .nav > li > a,
  .main-header .navbar .nav > li > a {
    min-height: 44px !important;
    align-items: center !important;
    padding-top: 10px !important;
    padding-bottom: 10px !important;
    box-sizing: border-box !important;
  }

  /* Phone: keep only critical header actions (menu, POS icon, theme, bell, profile).
     Hide secondary chrome so icons stop crowding the bar. */
  body.premium-ui .app-header-action--quick-add,
  body.premium-ui .app-header-action--calendar,
  body.premium-ui .app-header-action--calculator,
  body.premium-ui .app-header-action--date,
  body.premium-ui .app-header-action--repair,
  .app-header-action--quick-add,
  .app-header-action--calendar,
  .app-header-action--calculator,
  .app-header-action--date,
  .app-header-action--repair {
    display: none !important;
  }

  body.premium-ui .app-header-action--pos .app-header-btn-label,
  .app-header-action--pos .app-header-btn-label,
  body.premium-ui .app-header-profile-name,
  .app-header-profile-name {
    display: none !important;
  }

  body.premium-ui .app-header-actions,
  .app-header-actions {
    gap: 0.25rem !important;
    max-width: 100%;
    overflow: hidden;
  }

  body.premium-ui .app-header-row,
  .app-header-row {
    flex-wrap: nowrap !important;
    gap: 0.35rem !important;
  }

  /* Sidebar menu rows — better fat-finger hit area */
  body.premium-ui aside.side-bar .sidebar-menu > li > a,
  .side-bar .sidebar-menu > li > a {
    min-height: 44px !important;
    display: flex !important;
    align-items: center !important;
  }

  /* Pagination & small table action buttons */
  .dataTables_wrapper .dataTables_paginate .paginate_button {
    min-width: 44px !important;
    min-height: 44px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  table.dataTable .btn-group .btn,
  table.dataTable .btn-sm,
  table.dataTable .tw-dw-btn-xs,
  table.dataTable .tw-dw-btn-sm {
    min-height: 36px !important; /* denser tables; still larger than 11px-padded 22px hits */
    min-width: 36px !important;
    padding: 8px 10px !important;
  }
}

/* Prefer reduced motion: no transform slide animation fights */
@media (max-width: 1023.98px) and (prefers-reduced-motion: reduce) {
  .side-bar {
    transition: none !important;
  }
}

/* P0.1 — denser UI controls that failed live measure after header fix */
@media (max-width: 1023.98px) {
  .tw-dw-btn-sm,
  .tw-dw-btn-xs,
  .btn-sm,
  .btn-xs {
    min-height: 44px !important;
    min-width: 44px !important;
    padding-top: 10px !important;
    padding-bottom: 10px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    box-sizing: border-box !important;
  }

  button.insight-toggle,
  .insight-toggle {
    min-height: 44px !important;
    min-width: 44px !important;
    padding: 10px 12px !important;
    display: inline-flex !important;
    align-items: center !important;
    box-sizing: border-box !important;
  }

  .insight-clickable,
  span.insight-clickable[role="button"],
  #insight-drawer-close,
  .insight-drawer__close {
    min-width: 44px !important;
    min-height: 44px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    box-sizing: border-box !important;
  }

  /* Stack brand / product switcher controls in header if present.
     No display:!important — keep Tailwind visibility. */
  body.premium-ui .app-header summary,
  .app-header summary {
    min-height: 44px !important;
    min-width: 44px !important;
    align-items: center !important;
  }
}

@media (max-width: 1023.98px) {
  .inv-bucket-badge[role="button"],
  span.sd-badge[role="button"],
  .sd-badge[role="button"] {
    min-height: 44px !important;
    min-width: 44px !important;
    padding: 10px 12px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    box-sizing: border-box !important;
  }
}

/* ============================================
   12b. UI consistency Phase 1 (2026-07-17)
   Close residual chrome targets from mobile audit:
   Filters accordion, list toolbars, trial/promo CTAs.
   Intentional residual: dense DT row actions stay ~36px (above).
   ============================================ */
@media (max-width: 1023.98px) {
  /* Filters panel collapse control (components.filters — was ~15–30px) */
  body.premium-ui .premium-panel--filters .box-header,
  .premium-panel--filters .box-header,
  div[id^="accordion_"] > .box-header {
    min-height: 44px !important;
    display: flex !important;
    align-items: center !important;
    box-sizing: border-box !important;
  }

  body.premium-ui .premium-panel--filters .box-title,
  .premium-panel--filters .box-title,
  div[id^="accordion_"] > .box-header .box-title {
    width: 100%;
    margin: 0 !important;
    display: flex !important;
    align-items: center !important;
  }

  body.premium-ui .premium-panel--filters .box-title a,
  .premium-panel--filters .box-title a,
  div[id^="accordion_"] > .box-header .box-title a,
  div[id^="accordion_"] > .box-header a[data-toggle="collapse"] {
    min-height: 44px !important;
    width: 100% !important;
    display: flex !important;
    align-items: center !important;
    gap: 8px;
    padding: 10px 12px !important;
    box-sizing: border-box !important;
    text-decoration: none;
  }

  body.premium-ui .premium-panel--filters .box-title a:focus-visible,
  .premium-panel--filters .box-title a:focus-visible,
  div[id^="accordion_"] > .box-header a[data-toggle="collapse"]:focus-visible {
    outline: 2px solid var(--focus-ring, #3595f6);
    outline-offset: 2px;
  }

  /* List / widget toolbars: Add, Print, Export, premium-action-btn */
  .box-tools .tw-dw-btn,
  .box-tools .btn,
  .box-tools .premium-action-btn,
  .box-tools summary,
  .box-tools > a,
  .box-header .box-tools a.btn,
  .box-header .box-tools button,
  .content-header .btn,
  .content-header .tw-dw-btn,
  .content-header a.btn,
  .aio-page-heading + .btn,
  .aio-page-heading .btn,
  .aio-page-heading .tw-dw-btn,
  .premium-action-btn,
  summary.premium-action-btn,
  details.tw-dw-dropdown > summary.tw-dw-btn,
  details.tw-dw-dropdown > summary.premium-action-btn {
    min-height: 44px !important;
    min-width: 44px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding-top: 10px !important;
    padding-bottom: 10px !important;
    box-sizing: border-box !important;
  }

  /* Default (non-xs) Daisy-style buttons in content */
  .content-wrapper .tw-dw-btn:not(.tw-dw-btn-xs):not(.tw-dw-btn-sm),
  .content .tw-dw-btn:not(.tw-dw-btn-xs):not(.tw-dw-btn-sm) {
    min-height: 44px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    box-sizing: border-box !important;
  }

  /* Superadmin / subscription promo CTAs (e.g. Start Free Trial) */
  a[href*="subscription"] .btn,
  a[href*="subscription"].btn,
  a[href*="subscription"].tw-dw-btn,
  a[href*="pricing"].btn,
  a[href*="pricing"].tw-dw-btn,
  .subscription-cta,
  .package-subscribe-btn,
  .btn-subscribe,
  body.premium-ui .app-header a[href*="subscription"],
  body.premium-ui .app-header a[href*="pricing"] {
    min-height: 44px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 10px 14px !important;
    box-sizing: border-box !important;
  }

  /* Page sub-nav / contact-style tabs — touch row height */
  .nav-tabs-custom > .nav-tabs > li > a,
  .nav-tabs > li > a {
    min-height: 44px !important;
    display: flex !important;
    align-items: center !important;
    box-sizing: border-box !important;
  }

  /* Header notification bell + profile summary (if not covered by .app-header-btn) */
  body.premium-ui .app-header-notifications button,
  body.premium-ui .app-header-notifications a,
  body.premium-ui .app-header details > summary,
  .app-header details > summary {
    min-height: 44px !important;
    min-width: 44px !important;
    align-items: center !important;
    justify-content: center !important;
    box-sizing: border-box !important;
  }

  /* iOS Safari: inputs/selects < 16px font trigger auto-zoom on focus.
     Cover single + multi Select2, daterange fields, and picker internals. */
  .select2-container .select2-selection--single,
  .select2-container .select2-selection--multiple,
  .select2-container .select2-selection__rendered,
  .select2-container .select2-selection__choice,
  .select2-container .select2-search--dropdown .select2-search__field,
  .select2-container .select2-search--inline .select2-search__field,
  .select2-container--default .select2-selection--multiple .select2-search__field,
  .form-control,
  input.form-control,
  select.form-control,
  textarea.form-control,
  .datepicker,
  .daterange-picker,
  input.daterange-picker,
  input.daterange,
  input[data-toggle="daterangepicker"],
  .daterangepicker input,
  .daterangepicker select,
  .daterangepicker .calendar-table,
  .daterangepicker td,
  .daterangepicker th,
  .daterangepicker .ranges li,
  input[type="text"],
  input[type="search"],
  input[type="number"],
  input[type="email"],
  input[type="tel"],
  input[type="password"],
  input[type="date"] {
    font-size: 16px !important;
  }

  .select2-container .select2-selection--single {
    min-height: 44px !important;
    display: flex !important;
    align-items: center !important;
  }

  .select2-container .select2-selection--multiple {
    min-height: 44px !important;
    padding: 6px 8px !important;
  }

  .select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: 1.25 !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
  }

  .select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 100% !important;
    top: 0 !important;
  }

  /* Larger hit area for Select2; reduces “must tap twice” misses */
  .select2-container {
    min-height: 44px;
    max-width: 100% !important;
  }
  .select2-container .select2-selection {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  /* Partial sideways scroll: cap common dense layout offenders */
  .content-wrapper,
  .content,
  .app-premium-main,
  .box,
  .aio-card,
  .premium-panel,
  .table-responsive,
  .dataTables_wrapper {
    max-width: 100%;
  }
  .row {
    max-width: 100%;
  }
  .content-wrapper .row {
    margin-left: 0 !important;
    margin-right: 0 !important;
  }
  /* keep bootstrap columns from overflowing when gutters were assumed */
  .content-wrapper [class*="col-"] {
    min-width: 0;
  }

  /* Dropdown items inside open menus: keep usable taps without blowing closed layout */
  .premium-dropdown-menu a[role="menuitem"],
  .premium-dropdown-menu .premium-dropdown-item,
  .app-header .premium-dropdown-menu a {
    min-height: 44px !important;
    display: flex !important;
    align-items: center !important;
    box-sizing: border-box !important;
  }

  /*
   * DataTables export toolbar (Print / Colvis / CSV / …)
   * aio-shell forces min-height:0 + padding:3px 10px with higher specificity than
   * .tw-dw-btn-xs — re-assert touch size with equal-or-higher selector weight.
   */
  body.premium-ui .dataTables_wrapper {
    --aio-dt-control-height: 44px;
  }

  body.premium-ui .dataTables_wrapper .dt-buttons .btn,
  body.premium-ui .dataTables_wrapper .dt-buttons .dt-button,
  body.premium-ui .dataTables_wrapper .buttons-print,
  body.premium-ui .dataTables_wrapper .buttons-csv,
  body.premium-ui .dataTables_wrapper .buttons-excel,
  body.premium-ui .dataTables_wrapper .buttons-pdf,
  body.premium-ui .dataTables_wrapper .buttons-copy,
  body.premium-ui .dataTables_wrapper .buttons-colvis,
  body.premium-ui .dataTables_wrapper .dt-buttons a.tw-dw-btn,
  body.premium-ui .dataTables_wrapper .dt-buttons a.tw-dw-btn-xs,
  body.premium-ui .dataTables_wrapper .dt-buttons button.tw-dw-btn {
    min-height: 44px !important;
    height: auto !important;
    padding: 10px 12px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    box-sizing: border-box !important;
    line-height: 1.25 !important;
  }

  /* CMS / marketing trial CTA on home (tw-dw-btn-lg was collapsing to ~26px) */
  a.tw-dw-btn.tw-dw-btn-lg,
  a.tw-dw-btn-lg,
  .content-wrapper a.tw-dw-btn-lg,
  .content a.tw-dw-btn-lg,
  body.premium-ui a.tw-dw-btn.tw-dw-btn-primary.tw-dw-btn-lg {
    min-height: 44px !important;
    height: auto !important;
    padding: 12px 18px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    box-sizing: border-box !important;
    line-height: 1.3 !important;
  }
}

/* ============================================
   13. P2 POS phone density (re-audit residual)
   ============================================ */
@media (max-width: 767.98px) {
  /* Stack POS layout; allow cart table to scroll instead of crushing columns */
  .pos-express-btn {
    min-height: 48px !important;
    font-size: 16px !important;
  }

  #pos_table {
    min-width: 0 !important;
  }

  #pos_table th,
  #pos_table td {
    min-width: 0 !important;
    white-space: nowrap;
  }

  .pos-total,
  .pos-total-row {
    font-size: 1.05rem !important;
  }

  /* Product suggestion grid: 2 columns on phones */
  .product_list,
  .product_box,
  .eq-height-row {
    max-width: 100%;
  }

  .product_box {
    min-height: 0 !important;
  }

  /* Payment buttons full-width for thumb reach */
  .payment-buttons .btn,
  .pos-form-actions .btn,
  .pos-form-actions .tw-dw-btn {
    min-height: 48px !important;
    width: 100%;
    margin-bottom: 8px;
  }
}

@media (min-width: 768px) and (max-width: 1023.98px) {
  /* iPad portrait POS: keep two-pane but ensure touch targets */
  .pos-express-btn {
    min-height: 44px !important;
  }
}

/* ============================================
   NAV BACK LINKS — mobile only
   Use class `aio-nav-back` on list/parent "Back" links.
   Desktop users use sidebar/breadcrumb; mobile needs an explicit back.
   Do NOT use on auth, install wizards, form Previous, or Cancel.
   ============================================ */
.aio-nav-back {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
}

@media (min-width: 768px) {
  .aio-nav-back {
    display: none !important;
  }
  /* When the back link is the only child of a paragraph wrapper, hide the wrapper too */
  p:has(> a.aio-nav-back:only-child),
  p:has(> .aio-nav-back:only-child) {
    display: none !important;
  }
}

@media (max-width: 767.98px) {
  .aio-nav-back {
    display: inline-flex !important;
    min-height: 44px;
    align-items: center;
  }
}

/* Contact show — per-tab filter toolbar + mobile More tabs */
.contact-show-page .contact-tab-toolbar {
  margin-bottom: var(--space-3, 12px);
  padding-bottom: var(--space-2, 8px);
  border-bottom: 1px solid var(--border-color, #e2e8f0);
}
.contact-show-page .contact-show-link-dates {
  margin-bottom: var(--space-2, 8px);
}
.contact-show-page .contact-tabs-more > a {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
}
.contact-show-page .contact-tabs-more-menu {
  max-height: 70vh;
  overflow-y: auto;
  z-index: var(--z-dropdown, 1300);
}
.contact-show-page .contact-tabs-more-menu > li > a {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 0.5em;
  white-space: normal;
}
/* When more-mode is on, secondary strip items are hidden by JS; ensure More is visible */
body.contact-show-more-tabs .contact-show-page .contact-tabs-more {
  display: list-item !important;
}
@media (min-width: 768px) {
  body.contact-show-more-tabs .contact-show-page .contact-tabs-more {
    display: none !important;
  }
  body.contact-show-more-tabs .contact-show-page #contact_show_main_tabs > li.contact-tab-secondary {
    display: list-item !important;
  }
}

