/* ============================================
   InfluenceHub – Responsive layout audit
   - Guarantees no horizontal overflow at
     320px, 480px, 768px, 1024px and 1440px.
   - Keeps modals scrollable on short viewports.
   - Ensures the bulk action bar never covers
     page content (adds bottom padding to <main>
     while the bar is visible).
   - Ensures the mobile menu opens/closes cleanly
     and does not overflow horizontally.
   - Dark mode, prefers-reduced-motion and
     forced-colors support.
   ============================================ */

/* ---------- Global: prevent horizontal overflow ---------- */

html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

/* Long unbreakable strings (URLs, emails) must wrap instead of
   forcing a horizontal scrollbar. */
body {
  overflow-wrap: break-word;
  word-wrap: break-word;
}

/* Media elements never exceed their container. */
img,
svg,
video,
canvas {
  max-width: 100%;
  height: auto;
}

/* ---------- Header: keep the fixed bar inside the viewport ---------- */

#site-header {
  max-width: 100vw;
}

#site-header > div {
  max-width: 100%;
}

/* ---------- Mobile menu: never overflow horizontally ---------- */

#mobile-menu {
  max-width: 100vw;
  overflow-x: hidden;
}

#mobile-menu .mobile-menu-inner {
  max-width: 100%;
  overflow-x: hidden;
}

#mobile-menu a,
#mobile-menu button {
  max-width: 100%;
  overflow-wrap: break-word;
}

/* ---------- Catalog grid: allow cards to shrink ---------- */

#influencers-grid {
  min-width: 0;
}

#influencers-grid > * {
  min-width: 0;
}

/* ---------- Filters panel: selects and inputs shrink ---------- */

#filters-panel,
#filters-panel > div {
  min-width: 0;
}

#filters-panel select,
#filters-panel input {
  min-width: 0;
  max-width: 100%;
}

/* ---------- Active filters bar: wrap instead of overflow ---------- */

#active-filters,
.active-filters-inner,
.active-filters-list {
  min-width: 0;
  max-width: 100%;
}

.active-filters-list {
  flex-wrap: wrap;
}

/* ---------- Tabs: wrap on narrow screens ---------- */

#inbox-tabs,
#sent-tabs {
  max-width: 100%;
}

/* ---------- Bulk action bar: never cover content ---------- */

/* When the bar is visible, add bottom padding to <main> so the last
   section (FAQ / footer) is never hidden behind the fixed bar. The
   bar is ~72px tall on mobile and ~64px on desktop. */
body.bulk-bar-visible main {
  padding-bottom: 6rem;
}

@media (min-width: 640px) {
  body.bulk-bar-visible main {
    padding-bottom: 5.5rem;
  }
}

/* The bar itself must never exceed the viewport width. */
#bulk-action-bar {
  max-width: 100vw;
  overflow-x: hidden;
}

#bulk-action-bar > div {
  max-width: 100%;
  min-width: 0;
}

#bulk-action-bar > div > * {
  min-width: 0;
}

/* On very narrow screens, stack the bulk bar contents so the
   "Siųsti užklausas" button does not overflow. */
@media (max-width: 380px) {
  #bulk-action-bar > div {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  #bulk-action-bar #bulk-send,
  #bulk-action-bar [data-bulk-send] {
    width: 100%;
    margin-left: 0;
    justify-content: center;
  }
}

/* ---------- Modals: scrollable on short viewports ---------- */

/* Every modal panel already has max-height + overflow-y from
   modal-a11y-audit.css. Re-assert here so this file is the single
   source of truth for responsive modal behaviour. */
#auth-modal .auth-panel,
#profile-modal .auth-panel,
#profile-form-modal .auth-panel,
#request-modal .auth-panel,
#birthday-modal .auth-panel,
#confirm-modal .confirm-modal-panel {
  max-height: calc(100vh - 2rem);
  max-height: calc(100dvh - 2rem);
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Modal inner scroll areas (forms, profile body) must also scroll. */
#profile-modal-body,
#profile-form,
#request-form,
#birthday-form {
  max-height: calc(100vh - 12rem);
  max-height: calc(100dvh - 12rem);
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* ---------- 320px: extra-tight adjustments ---------- */

@media (max-width: 360px) {
  /* Header: shrink the logo text so it fits next to the controls. */
  #site-header .font-display {
    font-size: 1rem;
  }

  /* Hero heading: reduce size so it does not overflow. */
  .hero-bg h1 {
    font-size: 1.875rem;
    line-height: 1.15;
  }

  /* Category grid: single column on the narrowest screens. */
  #kategorijos .grid {
    grid-template-columns: 1fr;
  }

  /* Modals: tighter padding so content fits. */
  #auth-modal .auth-panel,
  #profile-modal .auth-panel,
  #profile-form-modal .auth-panel,
  #request-modal .auth-panel,
  #birthday-modal .auth-panel,
  #confirm-modal .confirm-modal-panel {
    max-height: calc(100vh - 0.5rem);
    max-height: calc(100dvh - 0.5rem);
    border-radius: 1rem;
  }

  #profile-modal-body,
  #profile-form,
  #request-form,
  #birthday-form {
    max-height: calc(100vh - 10rem);
    max-height: calc(100dvh - 10rem);
  }

  /* Bulk bar: full-width send button. */
  #bulk-action-bar #bulk-send,
  #bulk-action-bar [data-bulk-send] {
    width: 100%;
    margin-left: 0;
    justify-content: center;
  }
}

/* ---------- 480px: keep two-column category grid ---------- */

@media (min-width: 361px) and (max-width: 480px) {
  #kategorijos .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* ---------- 768px: tablet adjustments ---------- */

@media (min-width: 768px) and (max-width: 1023px) {
  /* Catalog grid: two columns on tablets. */
  #influencers-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* ---------- 1024px+: desktop adjustments ---------- */

@media (min-width: 1024px) {
  /* Bulk bar: keep it centered and not full-width. */
  #bulk-action-bar > div {
    max-width: 48rem;
  }
}

/* ---------- 1440px: cap content width ---------- */

@media (min-width: 1440px) {
  /* The max-w-7xl container already caps at 80rem (1280px); add a
     little breathing room so the layout does not feel cramped. */
  #site-header > div,
  main > section > div,
  footer > div {
    max-width: 80rem;
  }
}

/* ---------- Mobile menu open state ---------- */

/* The mobile menu is toggled by app.js via the .is-open class and
   the aria-expanded attribute. Ensure it is hidden by default and
   only shown when open, with no horizontal overflow. */
#mobile-menu {
  display: none;
}

#mobile-menu.is-open {
  display: block;
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  #mobile-menu,
  #bulk-action-bar,
  #bulk-action-bar > div {
    transition: none !important;
    animation: none !important;
    transform: none !important;
  }
}

/* ---------- Forced colors (Windows High Contrast) ---------- */

@media (forced-colors: active) {
  #mobile-menu {
    border-top: 1px solid CanvasText;
    background: Canvas;
    color: CanvasText;
  }

  #bulk-action-bar > div {
    border: 1px solid CanvasText;
    background: Canvas;
    color: CanvasText;
  }
}
