/* Keep directory controls inside the viewport on narrow phones. */
.pagination {
  max-width: 100%;
  flex-wrap: wrap;
  row-gap: 8px;
}

.mobile-filter-apply { display: none; }

/* Fluid cards at tablet widths, including the 521–545px range. */
@media (min-width: 521px) and (max-width: 850px) {
  .cards {
    width: 100%;
    min-width: 0;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  }
  .card { width: 100%; min-width: 0; }
  .avatar { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .directory-layout { position: relative; }

  .directory.filters-open aside {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 12;
    display: flex;
    flex-direction: column;
    width: 100%;
    margin-top: 0;
    max-height: min(62vh, 520px);
    max-height: min(62svh, 520px);
    padding: 12px;
    border: 1px solid rgba(204, 213, 223, .8);
    border-radius: 10px;
    background: rgba(255, 255, 255, .96);
    box-shadow: 0 14px 32px rgba(32, 45, 53, .2);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
    overflow: hidden;
  }

  .mobile-filter-scroll {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .mobile-filter-apply {
    position: relative;
    z-index: 1;
    display: block;
    flex: 0 0 auto;
    width: 100%;
    min-height: 48px;
    margin-top: 8px;
    padding: 10px 14px;
    border: 0;
    border-radius: 8px;
    background: #f9a839;
    color: #26343d;
    font: 700 14px 'Noto Serif Bengali', serif;
    cursor: pointer;
  }

  .filters label {
    min-height: 48px;
    padding: 10px 6px;
    gap: 14px;
    font-size: 15px;
    line-height: 1.35;
  }

  .filters input { width: 24px; height: 24px; flex: 0 0 24px; }

  .filters {
    scrollbar-width: auto;
    scrollbar-color: #91a4ad #edf2f4;
  }

  .filters::-webkit-scrollbar { width: 10px; }
  .filters::-webkit-scrollbar-track { border-radius: 8px; background: #edf2f4; }
  .filters::-webkit-scrollbar-thumb {
    min-height: 44px;
    border: 2px solid #edf2f4;
    border-radius: 8px;
    background: #91a4ad;
  }
}

@media (max-width: 520px) {
  .profile-update-callout a {
    display: flex;
    align-self: stretch;
    box-sizing: border-box;
    width: 100%;
    min-height: 44px;
    justify-content: center;
  }
}

@media (max-width: 340px) {
  .cards { grid-template-columns: minmax(0, 1fr); }
  .card { width: 100%; }
  .avatar { width: 100%; }
  .card h3 { font-size: 15px; }
  .chip { font-size: 12px; }
}

/* Prevent iOS Safari from zooming the page when these fields receive focus. */
#search,
.contact-request-form input,
.contact-request-form textarea {
  font-size: 16px;
}

#search { font: 16px 'Noto Serif Bengali', serif; }

/* Keep search reachable below the header while browsing the directory. */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
}

#search {
  position: sticky;
  top: 64px;
  z-index: 9;
  display: block;
  border: 1px solid rgba(204, 213, 223, .82);
  background: rgba(240, 245, 250, .84);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  box-shadow: 0 6px 18px rgba(39, 51, 60, .08);
}

/* Keep the close control visible while the profile dialog itself scrolls. */
.profile-modal {
  display: flex;
  flex-direction: column;
  height: min(760px, calc(100vh - 32px));
  height: min(760px, calc(100dvh - 32px));
  overflow: hidden;
}

.profile-modal:not([open]) { display: none; }
.profile-modal[open] { display: flex; }

.profile-modal > .profile-close {
  position: relative;
  z-index: 5;
  flex: 0 0 42px;
  align-self: flex-end;
  margin: 10px 10px -52px auto;
}

.profile-modal > #profileContent {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 600px) {
  .profile-modal {
    position: fixed;
    inset: 0;
    width: 100vw;
    max-width: none;
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    margin: 0;
    border: 0;
    border-radius: 0;
  }

  .profile-modal > .profile-close {
    margin-top: calc(10px + env(safe-area-inset-top, 0px));
    margin-right: calc(10px + env(safe-area-inset-right, 0px));
  }
}

@media (max-width: 420px) {
  .request-dialog {
    width: calc(100vw - 24px);
    max-width: none;
    max-height: calc(100vh - 24px);
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
  }

  .contact-request-form { padding: 16px; }

  .contact-request-form input:not([type="hidden"]),
  .contact-request-form textarea {
    font: 16px Arial, sans-serif;
    min-height: 44px;
  }

  .contact-request-form textarea { min-height: 104px; }
}

@media (max-width: 850px) {
  .contact-request-form input:not([type="hidden"]),
  .contact-request-form textarea {
    min-height: 44px;
    font: 16px Arial, sans-serif;
  }

  .request-submit { min-height: 48px; }
}

.request-submit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 48px;
  transition: transform .18s ease, box-shadow .18s ease, background-color .18s ease;
}

.request-submit:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 7px 16px rgba(183, 112, 18, .22);
}

.request-submit:active:not(:disabled) { transform: scale(.98); }
.request-submit:focus-visible { outline: 3px solid #e6a13a80; outline-offset: 3px; }
.request-submit .submit-icon { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.request-submit .submit-check { display: none; }
.request-submit.is-sending .submit-arrow { animation: submit-arrow-pulse .6s ease-in-out infinite alternate; }
.request-submit.is-success { background: #f9a839; color: #24313a; box-shadow: 0 0 0 3px #f9a83955; animation: submit-success .35s ease-out both; }
.request-submit.is-success .submit-arrow { display: none; }
.request-submit.is-success .submit-check { display: block; animation: submit-check-in .3s ease-out both; }
.request-submit.is-error { animation: submit-error .35s ease-in-out; }

@keyframes submit-arrow-pulse { to { transform: translateX(4px); } }
@keyframes submit-success { 50% { transform: scale(1.025); } }
@keyframes submit-check-in { from { opacity: 0; transform: scale(.5); } to { opacity: 1; transform: scale(1); } }
@keyframes submit-error { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

@media (prefers-reduced-motion: reduce) {
  .request-submit,
  .request-submit.is-success,
  .request-submit.is-error,
  .request-submit.is-sending .submit-arrow,
  .request-submit.is-success .submit-check { animation: none; transition: none; }
}
