/* ============================================================================
 * out_source responsive layer
 * ----------------------------------------------------------------------------
 * Shared by every page in /out_source (logins + contract / patient / referring-doctor
 * dashboards). Loaded LAST in <head> so it refines each page's own <style> and Bootstrap.
 * Goals: no horizontal scroll from 320px phones up to 4K, fluid type and spacing, touch-sized
 * controls, tables/modals that always fit, and safe-area support (notches, home bars).
 * Breakpoints follow the main homepage: 480 / 768 / 1100 / 1400 / 1920 / 2560.
 * ========================================================================== */

/* ---------- 1. Base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* Fluid root size: 14px on small phones -> ~16px laptops -> ~18px 1440p -> ~21px 4K. */
  font-size: clamp(14px, 13px + .2vw, 22px);
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 100%;
  overflow-x: hidden;
  overflow-wrap: break-word; /* only breaks a word when it would otherwise overflow */
  /* Keep content clear of notches / rounded corners / home indicator. */
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

img,
svg,
video,
canvas,
iframe {
  max-width: 100%;
}

/* Images without an explicit height keep their aspect ratio; sized logos are left alone. */
img:not([height]),
video {
  height: auto;
}

/* ---------- 2. Layout containers: grow with the screen instead of stopping at 1320px ---------- */
.container,
.container-fluid {
  width: 100%;
  padding-left: clamp(12px, 3vw, 32px);
  padding-right: clamp(12px, 3vw, 32px);
}

@media (min-width: 1400px) {
  .container { max-width: min(1320px, 92vw); }
}

@media (min-width: 1920px) {
  .container { max-width: min(1640px, 88vw); }
}

@media (min-width: 2560px) {
  .container { max-width: min(2100px, 84vw); }
}

/* Full-width dashboards stay readable on ultra-wide monitors. */
.container-fluid {
  max-width: 2400px;
  margin-left: auto;
  margin-right: auto;
}

.row {
  --bs-gutter-x: clamp(.75rem, 1.5vw, 1.5rem);
}

/* ---------- 3. Navbar ---------- */
.navbar {
  padding-top: max(.5rem, env(safe-area-inset-top));
}

.navbar-brand {
  min-width: 0;
  max-width: 100%;
  white-space: normal;
  display: inline-flex;
  align-items: center;
  gap: .5rem;
}

.navbar-brand span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.navbar-toggler {
  min-width: 44px;
  min-height: 44px;
}

/* Keep the toggler on the brand's row: the brand shrinks (and truncates) instead of pushing it down. */
@media (max-width: 991.98px) {
  .navbar-brand {
    flex: 1 1 0;
    max-width: calc(100% - 56px);
  }
}

.navbar .nav-link {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: .4rem;
}

@media (max-width: 991.98px) {
  .navbar-collapse {
    max-height: calc(100dvh - 4.5rem);
    overflow-y: auto;
  }
}

/* Portal header bar (patient / referring-doctor dashboards): wraps instead of squeezing the buttons. */
.header-section .container > .d-flex {
  flex-wrap: wrap;
  gap: .75rem;
}

.header-section .btn {
  white-space: nowrap;
}

/* ---------- 4. Cards, grids and stat blocks ---------- */
.card,
.contract-info-card,
.filter-card,
.summary-card,
.order-card,
.dashboard-header {
  max-width: 100%;
}

.summary-stats {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr));
}

.order-header,
.test-item,
.payment-item,
.print-buttons,
.filter-buttons {
  flex-wrap: wrap;
  gap: .5rem;
}

.filter-btn {
  min-width: min(100%, 120px);
}

.order-card:hover {
  transform: none; /* hover lift jumps around on touch and causes scroll jitter */
}

/* Filter rows built from .col-auto: each control takes the full width on phones. */
@media (max-width: 575.98px) {
  .row.align-items-end > .col-auto,
  .row.g-2 > .col-auto {
    flex: 1 1 100%;
    width: 100%;
  }

  .row.align-items-end > .col.ms-auto {
    flex: 1 1 100%;
  }
}

/* ---------- 5. Tables never widen the page: they scroll inside their own box ---------- */
.table-responsive,
.card table,
.order-card table,
.container table,
.container-fluid table {
  max-width: 100%;
}

/* On phones a wide table scrolls sideways inside its own box instead of stretching the page. */
@media (max-width: 767.98px) {
  .container table:not(.no-scroll),
  .container-fluid table:not(.no-scroll) {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* ---------- 6. Forms and buttons: touch sized, no iOS zoom-on-focus ---------- */
.btn,
.form-control,
.form-select,
.input-group-text {
  min-height: 40px;
}

.btn {
  white-space: normal;
}

.input-group {
  flex-wrap: nowrap;
}

@media (max-width: 767.98px) {
  input,
  select,
  textarea,
  .form-control,
  .form-select {
    font-size: 16px; /* below 16px iOS Safari zooms the page on focus */
  }

  .btn,
  .form-control,
  .form-select {
    min-height: 44px;
  }
}

/* ---------- 7. Modals always fit the viewport ---------- */
.modal-dialog {
  max-width: min(var(--bs-modal-width, 500px), calc(100vw - 1rem));
  margin-left: auto;
  margin-right: auto;
}

.modal-dialog-scrollable .modal-content,
.modal-content {
  max-height: calc(100dvh - 1rem);
}

.modal-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 575.98px) {
  .modal-dialog {
    margin: .5rem auto;
  }
}

/* ---------- 8. Fixed app-promotion banner (contracts dashboard) ---------- */
.app-promotion-banner {
  max-width: min(280px, calc(100vw - 20px));
  left: max(20px, env(safe-area-inset-left));
  bottom: max(20px, env(safe-area-inset-bottom));
}

@media (max-width: 575.98px) {
  .app-promotion-banner {
    left: max(10px, env(safe-area-inset-left));
    right: max(10px, env(safe-area-inset-right));
    max-width: none;
  }
}

/* Short landscape phones: a fixed banner would cover the page, so let it scroll with the content. */
@media (max-height: 520px) {
  .app-promotion-banner {
    position: static;
    margin: 1rem auto;
  }

  body {
    margin-bottom: 0 !important;
  }
}

/* ---------- 9. Login pages ---------- */
.main-container,
.page-canvas {
  min-height: 100vh;
  min-height: 100dvh;
}

/* sales_login: the form column had a 360px minimum, wider than a 320px phone. */
.shell {
  grid-template-columns: minmax(0, 420px) minmax(0, 1fr);
}

@media (max-width: 1099px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
    width: 100%;
  }
}

.login-card,
.login-container {
  max-width: 100%;
}

@media (min-width: 1920px) {
  .shell { max-width: 1560px; }
}

@media (min-width: 2560px) {
  .shell { max-width: 2000px; }
}

/* ---------- 10. Small phones ---------- */
@media (max-width: 479.98px) {
  h1, .h1 { font-size: clamp(1.4rem, 7vw, 1.75rem); }
  h2, .h2 { font-size: clamp(1.25rem, 6vw, 1.5rem); }
  h4, h5 { font-size: 1.05rem; }

  .contract-info-card,
  .filter-card,
  .summary-card,
  .order-card {
    padding: 12px;
  }

  .text-end {
    text-align: start !important; /* right-aligned blocks stack under their heading on phones */
  }
}

/* ---------- 11. Short landscape screens (phones on their side, small laptops) ---------- */
@media (max-height: 520px) and (orientation: landscape) {
  .navbar { padding-top: .25rem; padding-bottom: .25rem; }
  .dashboard-header { padding-top: 12px; padding-bottom: 12px; margin-bottom: 14px; }
  .main-container,
  .page-canvas { align-items: flex-start; }
}

/* ---------- 12. Accessibility ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}
