/* EverLastERP - Comprehensive Responsive UI Audit Fixes */
/* Goal: consistent layout + no horizontal overflow + usable tables/modals/forms across breakpoints */
/* NOTE: This file is intentionally "late-loaded" to override earlier mobile styles when needed. */

/* =========================
   Global safety (all sizes)
   ========================= */
html, body {
  max-width: 100%;
  overflow-x: hidden;
}

img, video, canvas, svg {
  max-width: 100%;
  height: auto;
}

/* Prevent long tokens (IDs/emails/URLs) from breaking layouts */
pre, code, kbd, samp,
.text-break,
.text-wrap,
p, span, div, td, th, a, small {
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* Ensure Bootstrap-like containers never exceed viewport */
.container, .container-fluid, .content-wrapper, #content-wrapper, .page-wrapper {
  max-width: 100%;
}

/* =========================
   Tables (all sizes)
   ========================= */
/* Make sure any "wide" table is scrollable without forcing body horizontal scroll */
.table-responsive,
.table-wrapper,
.table-container,
div[class*="table"],
.card-body .table-responsive {
  width: 100% !important;
  max-width: 100% !important;
  overflow-x: auto !important;
  overflow-y: visible !important;
  -webkit-overflow-scrolling: touch !important;
}

/* Prevent sticky header overlap issues */
.table thead th,
table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
}

/* Avoid accidental clipping of action buttons inside table cells */
.table td, .table th,
table td, table th {
  overflow: visible;
}

/* =========================
   Modals (all sizes)
   ========================= */
.modal-dialog {
  max-width: min(920px, calc(100% - 1rem));
}

/* Make modal content scrollable on small viewports */
.modal-content {
  max-height: 92vh;
}

.modal-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* =========================
   Dropdowns / Popovers
   ========================= */
.dropdown-menu {
  max-width: calc(100vw - 2rem);
}

/* =========================
   Breakpoints
   ========================= */

/* ---- <= 991.98px (tablet & below) ---- */
@media (max-width: 991.98px) {
  /* Ensure main content never gets a fixed left margin on mobile */
  .content-wrapper,
  #content-wrapper {
    margin-left: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  /* Avoid nested containers causing horizontal overflow */
  .container, .container-fluid {
    padding-left: 0.75rem !important;
    padding-right: 0.75rem !important;
  }

  /* Cards should not overflow */
  .card, .employee-card, .dashboard-card {
    max-width: 100% !important;
  }

  /* Button groups should wrap instead of overflowing */
  .btn-group,
  .d-flex.gap-1,
  .d-flex.gap-2,
  .d-flex.flex-wrap {
    flex-wrap: wrap !important;
  }

  /* Make modal fit small screens comfortably */
  .modal-dialog {
    margin: 0.5rem !important;
    width: calc(100% - 1rem) !important;
    max-width: calc(100% - 1rem) !important;
  }

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

  /* Prevent page-wide horizontal scroll caused by wide charts/containers */
  .chart-container,
  .chart-container-enhanced,
  .chart-wrapper {
    max-width: 100% !important;
    overflow-x: auto;
  }
}

/* ---- <= 768px (small tablets/phones) ---- */
@media (max-width: 768px) {
  /* Forms: keep iOS from zooming inputs */
  input, select, textarea, .form-control, .form-select {
    font-size: 16px !important;
  }

  /* Input-groups: stack nicely on small screens (currency+amount, icons+input, etc.) */
  .input-group {
    flex-wrap: wrap !important;
  }
  .input-group > .form-select,
  .input-group > .form-control,
  .input-group > .input-group-text,
  .input-group > .btn {
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 0.5rem !important;
  }

  /* Tables: ensure scroll container has some breathing room if templates use negative margins */
  .table-responsive {
    margin-left: 0 !important;
    margin-right: 0 !important;
  }
}

/* ---- <= 576px (phones) ---- */
@media (max-width: 576px) {
  /* Stack common header action rows */
  .content-header,
  .content-header-actions,
  .card-tools {
    width: 100% !important;
  }

  /* Make sure inline action clusters don't exceed width */
  .action-buttons,
  .table tbody td .d-flex,
  .table tbody td .btn-group {
    width: 100%;
  }
}

/* ---- Landscape handling ---- */
@media (max-width: 991.98px) and (orientation: landscape) {
  .modal-content {
    max-height: 85vh;
  }
}

