/* Shared responsive foundation. Keep layout fluid before page-specific rules. */
html,
body {
  max-width: 100%;
  min-width: 0;
  overflow-x: clip;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

button,
a,
input,
select,
textarea {
  max-width: 100%;
}

button,
a {
  overflow-wrap: anywhere;
}

/* Flex/grid children must be allowed to shrink instead of widening the page. */
.flex > *,
.inline-flex > *,
[class*="grid"] > * {
  min-width: 0;
}

/* Shared fixed dashboard shell. The side rail owns the desktop offset;
   content itself always fills the remaining width. */
.dashboard-header,
#dashboardSection > nav.neo-nav {
  min-width: 0;
}

.dashboard-header > div,
#dashboardSection > nav.neo-nav > div,
.worker-topbar-actions,
.customer-mobile-actions {
  min-width: 0;
  max-width: 100%;
}

.dashboard-header .font-extrabold,
.dashboard-header .font-extrabold > *,
.worker-topbar-actions > *,
.customer-mobile-actions > * {
  min-width: 0;
}

@media (max-width: 767px) {
  main,
  .customer-dashboard-shell {
    min-width: 0;
    width: 100%;
    max-width: 100%;
    padding-left: max(0.75rem, var(--ss-safe-left, 0px));
    padding-right: max(0.75rem, var(--ss-safe-right, 0px));
  }

  .dashboard-header > div,
  #dashboardSection > nav.neo-nav > div {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    flex-wrap: nowrap;
    align-items: center;
    gap: 0.35rem;
    padding-left: max(0.75rem, var(--ss-safe-left, 0px)) !important;
    padding-right: max(0.75rem, var(--ss-safe-right, 0px)) !important;
  }

  .dashboard-header .font-extrabold {
    min-width: 0;
    max-width: 100%;
    font-size: clamp(1rem, 5vw, 1.35rem);
  }

  .dashboard-header > div > div:first-child {
    padding-inline-start: 0.5rem;
  }

  .dashboard-header .font-extrabold > span:first-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .dashboard-header .font-extrabold span:last-child {
    font-size: clamp(0.72rem, 3vw, 0.9rem);
  }

  .customer-mobile-actions,
  .worker-topbar-actions {
    display: flex;
    flex: 0 1 auto;
    flex-wrap: nowrap;
    justify-content: flex-end;
    gap: 0.25rem;
  }

  .dashboard-header > div > .flex.items-center.gap-2 {
    min-width: 0;
    gap: 0.25rem;
  }

  .customer-mobile-actions .neo-btn,
  .worker-topbar-actions a,
  .worker-topbar-actions button {
    min-height: 2.5rem;
    min-width: 0;
    padding-inline: 0.5rem;
    white-space: normal;
    text-align: center;
  }

  #customerSidebar,
  #workerSidebar {
    min-width: 0;
    max-width: 100%;
  }

  #ordersTab .dashboard-orders-heading,
  .dashboard-orders-heading {
    display: block;
  }

  #ordersTab .dashboard-order-filters,
  .dashboard-order-filters {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    margin-top: 1rem;
  }

  main.customer-dashboard-shell {
    padding-top: 0.75rem !important;
    padding-bottom: calc(6.75rem + var(--ss-safe-bottom, 0px)) !important;
  }

  #ordersTab {
    margin-top: 0 !important;
    padding-top: 0.25rem !important;
  }

  #ordersTab .dashboard-orders-heading {
    margin-bottom: 0.85rem;
  }

  #ordersTab .dashboard-order-filter-field {
    min-width: 0;
    flex: 1 1 auto;
  }

  #ordersTab .order-source-switch {
    display: flex !important;
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  #ordersTab .order-secondary-controls {
    align-items: stretch;
  }

  #ordersTab .order-secondary-switch {
    flex: 1 1 auto;
    min-width: 0;
    overflow: visible;
  }

  #ordersTab .order-secondary-btn {
    flex: 1 1 0;
    min-width: 0;
    gap: 0.15rem;
    padding-inline: 0.2rem;
    font-size: clamp(0.58rem, 2.05vw, 0.72rem);
    white-space: normal;
    line-height: 1.1;
    text-align: center;
  }

  #ordersTab .order-secondary-btn .material-symbols-outlined {
    font-size: 0.9rem;
  }

  #ordersTab .order-source-switch::-webkit-scrollbar {
    display: none;
  }

  #ordersTab .order-source-btn {
    flex: 0 0 auto;
    min-width: 8.25rem;
    width: auto;
    padding-inline: 0.75rem;
    font-size: 0.78rem;
    line-height: 1.15;
    white-space: nowrap;
    overflow-wrap: normal;
    word-break: normal;
  }

  #ordersTab .dashboard-stat-grid {
    min-width: 0;
  }

  .dashboard-order-card,
  .dashboard-work-request-card,
  .customer-card,
  .profile-shell,
  .order-source-panel,
  .history-accordion {
    min-width: 0;
    max-width: 100%;
  }

  .dashboard-order-card button,
  .dashboard-work-request-card button,
  .order-source-panel select {
    max-width: 100%;
    min-width: 0;
  }

  /* Leave the fixed bottom rail clear on small and foldable cover screens. */
  .dashboard-order-card:last-child,
  .dashboard-work-request-card:last-child,
  .tab-content:last-child {
    scroll-margin-bottom: calc(5rem + var(--ss-safe-bottom, 0px));
  }
}

@media (max-width: 420px) {
  .customer-mobile-actions .neo-btn span:last-child,
  .worker-topbar-actions a,
  .worker-topbar-actions button {
    font-size: 0.72rem;
  }

  #ordersTab .dashboard-stat-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  }

  #ordersTab .dashboard-stat {
    min-width: 0;
    min-height: 6rem;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center;
    gap: 0.3rem;
    padding: 0.55rem 0.35rem;
  }

  #ordersTab .dashboard-stat-icon {
    flex: 0 0 1.8rem;
    width: 1.8rem;
    height: 1.8rem;
    border-radius: 0.7rem;
  }

  #ordersTab .dashboard-stat-icon .material-symbols-outlined {
    font-size: 1.1rem;
  }

  #ordersTab .dashboard-stat p:first-child {
    word-break: normal;
    overflow-wrap: normal;
    font-size: 0.6rem;
    line-height: 1.15;
    text-align: center;
  }

  #ordersTab .dashboard-stat p:last-child {
    font-size: 1.1rem;
  }

  #ordersTab .order-source-switch {
    gap: 0.25rem;
  }

  .dashboard-header .customer-mobile-actions .neo-btn {
    width: 2.5rem;
    padding-inline: 0;
    justify-content: center;
  }

  .dashboard-header .customer-mobile-actions .neo-btn span:last-child {
    display: none;
  }

  .dashboard-header .font-extrabold > span:first-child {
    font-size: 1.15rem;
  }

  .dashboard-header .font-extrabold > span:last-child {
    font-size: 0.7rem;
  }
}

/* The primary booking/request switch must fit on Fold cover screens. Keep
   History available, but give it its own full-width row below the two main
   sources instead of forcing all three controls into one cramped row. */
@media (max-width: 480px) {
  #ordersTab .order-source-switch {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: stretch;
    gap: 0.25rem;
    width: 100%;
    min-width: 0;
    padding: 0.25rem;
    overflow: visible;
  }

  #ordersTab .order-source-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    width: 100%;
    flex: 1 1 0;
    gap: 0.2rem;
    padding: 0.4rem 0.3rem;
    font-size: 0.7rem;
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    overflow-wrap: normal;
    word-break: normal;
  }

  #ordersTab #bookingsCountBadge,
  #ordersTab #workRequestsCountBadge {
    flex: 0 0 auto;
    padding-inline: 0.35rem;
    font-size: 0.58rem;
    line-height: 1.1;
  }

  #ordersTab #orderSourceHistoryBtn {
    grid-column: 1 / -1;
  }
}

@media (max-width: 767px) {
  .profile-modal-actions {
    min-width: 0;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .profile-modal-action {
    min-width: 0;
    flex: 1 1 0;
    justify-content: center;
    gap: 0.35rem;
    padding-inline: 0.5rem;
    font-size: clamp(0.78rem, 3.2vw, 1rem) !important;
    line-height: 1.1;
    white-space: nowrap;
    word-break: normal;
    overflow-wrap: normal;
  }

  .profile-modal-action .material-symbols-outlined {
    flex: 0 0 auto;
    font-size: 1.1rem;
  }
}

/* Tablet dashboards have the desktop side rail but not enough room for the
   wide desktop heading/filter row. Stack that row before the copy is forced
   into a narrow column (notably on iPad Mini widths). */
@media (min-width: 768px) and (max-width: 1100px) {
  .customer-dashboard-shell .dashboard-orders-heading {
    display: block !important;
    min-width: 0;
  }

  .customer-dashboard-shell .dashboard-order-filters {
    display: flex;
    width: 100%;
    max-width: none;
    min-width: 0;
    flex: none;
    margin-top: 1.25rem;
    gap: 0.65rem;
  }

  .customer-dashboard-shell .dashboard-order-filter-field {
    min-width: 0;
    flex: 1 1 auto;
  }

  .customer-dashboard-shell .dashboard-order-filters #statusFilter {
    min-width: 0;
  }

  .customer-dashboard-shell .dashboard-order-filters #refreshBtn {
    flex: 0 0 4rem;
  }
}

@media (min-width: 768px) {
  #ordersTab,
  #requestsTab,
  #profileTab,
  #filesTab,
  #analyticsTab,
  #referralsTab,
  #post-requestTab {
    width: 100%;
    max-width: none;
    min-width: 0;
  }
}

/* Preserve a compact, readable three-card summary on phones without changing
   the desktop card layout. High-specificity selectors override page utilities
   and dashboard-local styles while keeping the shared rule reusable. */
@media (max-width: 767px) {
  html body #ordersTab .dashboard-stat-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: stretch;
    gap: 0.5rem;
  }

  html body #ordersTab .dashboard-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    min-width: 0;
    min-height: 6.25rem;
    height: 100%;
    padding: 0.6rem 0.35rem;
    text-align: center;
  }

  html body #ordersTab .dashboard-stat-icon {
    flex: 0 0 1.75rem;
    width: 1.75rem;
    height: 1.75rem;
  }

  html body #ordersTab .dashboard-stat-icon .material-symbols-outlined {
    font-size: 1.1rem;
  }

  html body #ordersTab .dashboard-stat p:first-child {
    display: grid;
    place-items: center;
    width: 100%;
    min-height: 2.3em;
    margin: 0;
    font-size: clamp(0.7rem, 3.1vw, 0.75rem);
    line-height: 1.15;
    text-align: center;
    text-wrap: balance;
    overflow-wrap: normal;
    word-break: normal;
  }

  html body #ordersTab .dashboard-stat p:last-child {
    margin: 0;
    font-size: clamp(1.05rem, 4.5vw, 1.15rem);
    line-height: 1;
    font-variant-numeric: tabular-nums;
  }

  .modal-overlay,
  .login-modal-overlay {
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
}

/* iOS Safari zooms focused controls smaller than 16px. This also applies to
   controls inserted dynamically into booking, auth, and dashboard modals. */
@media (max-width: 1024px) {
  html body :is(
    input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="hidden"]):not([type="button"]):not([type="submit"]):not([type="reset"]):not([type="image"]):not([type="range"]):not([type="color"]),
    textarea,
    select
  ) {
    font-size: 16px;
    scroll-margin-top: calc(4.5rem + env(safe-area-inset-top, 0px));
    scroll-margin-bottom: calc(5.5rem + env(safe-area-inset-bottom, 0px));
  }
}
