/* ==========================================================================
   Gujarati Samaj New Zealand — Responsive rules
   --------------------------------------------------------------------------
   Breakpoints (desktop-first, max-width):
     1279.98px  Laptop        — tighter navigation spacing
     1179.98px  Nav collapse  — desktop nav → hamburger menu
     1023.98px  Tablet (land) — footer & grids reflow
      767.98px  Tablet (port) — single-column hero, smaller header
      479.98px  Mobile        — compact brand, stacked footer
   ========================================================================== */

/* ---- Laptop (≤1279px) ---------------------------------------------------- */
@media (max-width: 1279.98px) {
  .primary-nav__link {
    padding-inline: 0.625rem;
  }

  .primary-nav__link::after {
    left: 0.625rem;
    right: 0.625rem;
  }

  .site-header__actions {
    gap: var(--space-3);
  }

  .brand__name {
    font-size: 1.25rem;
  }
}

/* ---- Navigation collapse (≤1179px) -------------------------------------- */
@media (max-width: 1179.98px) {
  :root {
    --header-height: 76px;
    --logo-height: 56px;
  }

  .topbar,
  .primary-nav {
    display: none;
  }

  .nav-toggle {
    display: inline-flex;
  }

  [data-layout="header"] {
    min-height: var(--header-height);
  }
}

/* ---- Tablet landscape (≤1023px) ----------------------------------------- */
@media (max-width: 1023.98px) {
  .grid--3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .footer-main {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-10) var(--space-8);
  }

  .page-hero--with-media .page-hero__inner {
    gap: var(--space-8);
  }
}

/* ---- Tablet portrait (≤767px) ------------------------------------------- */
@media (max-width: 767.98px) {
  :root {
    --gutter: 20px;
    --header-height: 68px;
    --logo-height: 48px;
  }

  .brand {
    gap: var(--space-2);
  }

  .brand__name {
    font-size: 1.125rem;
  }

  .brand__region {
    font-size: 0.6875rem;
    letter-spacing: 0.2em;
  }

  .page-hero--with-media .page-hero__inner,
  .grid--2 {
    grid-template-columns: minmax(0, 1fr);
  }

  .page-hero::before {
    width: 300px;
    height: 300px;
    top: -140px;
    right: -150px;
    border-width: 24px;
  }

  .media-placeholder {
    aspect-ratio: 16 / 9;
  }

  .section-header {
    margin-bottom: var(--space-8);
  }

  .notice {
    padding: var(--space-4);
  }

  .type-specimen {
    padding: var(--space-5);
  }

  .back-to-top {
    right: var(--space-4);
    bottom: var(--space-4);
  }
}

/* ---- Mobile (≤599px): header CTA moves into the menu ------------------- */
@media (max-width: 599.98px) {
  .site-header__cta {
    display: none;
  }

  .grid--3 {
    grid-template-columns: minmax(0, 1fr);
  }

  .footer-main {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-8);
    padding-block: var(--space-12) var(--space-10);
  }

  .footer-bottom__inner {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* ---- Small mobile (≤479px) ---------------------------------------------- */
@media (max-width: 479.98px) {
  :root {
    --gutter: 16px;
  }

  .nav-toggle__label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
  }

  .nav-toggle {
    padding-inline: var(--space-3);
  }

  .btn-group .btn {
    flex: 1 1 100%;
  }

  .mobile-menu__panel {
    width: min(400px, 92vw);
  }
}

/* ==========================================================================
   Content components & Home page (same breakpoints as above)
   ========================================================================== */

/* ---- Tablet landscape (≤1023px) ----------------------------------------- */
@media (max-width: 1023.98px) {
  .grid--4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .split {
    grid-template-columns: minmax(0, 1fr);
  }

  .split--reverse .split__media {
    order: 0;
  }

  .split__media {
    max-width: 720px;
  }

  /* Keep the decorative ring inside the page gutter (no horizontal scroll) */
  .split__media--ring::before {
    right: -3%;
  }

  .split--reverse .split__media--ring::before {
    right: -3%;
    left: auto;
  }

  .event-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .event-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .lightbox {
    padding: var(--space-16) var(--space-6) var(--space-20);
  }

  .lightbox__prev,
  .lightbox__next {
    top: auto;
    bottom: var(--space-4);
    transform: none;
  }

  .lightbox__prev {
    left: calc(50% - 56px);
  }

  .lightbox__next {
    right: calc(50% - 56px);
  }

  .lightbox__img {
    max-height: calc(100vh - 13rem);
  }
}

/* ---- Tablet portrait (≤767px) ------------------------------------------- */
@media (max-width: 767.98px) {
  .home-hero {
    min-height: 520px;
    padding-block: var(--space-16);
  }

  .home-hero::before {
    background: rgba(43, 43, 43, 0.72);
  }

  .event-feature {
    grid-template-columns: minmax(0, 1fr);
  }

  .event-feature__media img {
    min-height: 0;
    aspect-ratio: 4 / 3;
  }

  .event-feature__body {
    padding: var(--space-6);
  }

  .event-list {
    grid-template-columns: minmax(0, 1fr);
  }

  .gallery-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-3);
  }

  .gallery-subheading {
    margin-top: var(--space-10);
  }

  .split__media--ring::before {
    border-width: 16px;
  }

  .split__badge {
    left: var(--space-4);
    padding: var(--space-3) var(--space-4);
  }

  .credits__list {
    columns: 1;
  }
}

/* ---- Mobile (≤599px) ---------------------------------------------------- */
@media (max-width: 599.98px) {
  .grid--4 {
    grid-template-columns: minmax(0, 1fr);
  }

  .icon-card {
    padding: var(--space-6) var(--space-5);
  }

  .section-header__action {
    width: 100%;
  }

  .section-header__action .btn {
    width: 100%;
  }

  .lightbox {
    padding: var(--space-16) var(--space-3) var(--space-20);
  }
}

/* ---- Small mobile (≤479px) ---------------------------------------------- */
@media (max-width: 479.98px) {
  .home-hero__title {
    font-size: 2.25rem;
  }

  .split__badge-value {
    font-size: var(--text-md);
  }
}

/* ==========================================================================
   Inner-page components (About page onwards) — same breakpoints as above
   ========================================================================== */

@media (max-width: 1023.98px) {
  .gallery-item--captioned .gallery-item__overlay {
    padding: var(--space-12) var(--space-4) var(--space-4);
  }
}

@media (max-width: 767.98px) {
  .page-hero.page-hero--image::before {
    background: rgba(43, 43, 43, 0.74);
  }

  /* Community grid: 2 columns — featured full width, two squares, wide */
  .gallery-grid--community {
    aspect-ratio: auto;
    grid-template-rows: none;
    grid-auto-rows: calc((100vw - (var(--gutter) * 2) - var(--space-3)) / 2);
  }

  .statement {
    padding-left: var(--space-4);
  }
}

@media (max-width: 479.98px) {
  .gallery-item__text {
    display: none;
  }

  .gallery-item--featured .gallery-item__text,
  .gallery-item--wide .gallery-item__text {
    display: block;
  }

  .gallery-item__title {
    font-size: var(--text-md);
  }
}

/* ==========================================================================
   Membership page components — same breakpoints as above
   ========================================================================== */

@media (max-width: 1023.98px) {
  .plan-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .plan-grid > :last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }

  .steps {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-10) var(--space-6);
  }

  .steps__item:not(:last-child)::after {
    display: none;
  }

  .form-layout,
  .faq-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .faq-layout__intro {
    position: static;
  }
}

@media (max-width: 599.98px) {
  .plan-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .plan-card {
    padding: var(--space-6) var(--space-5);
  }

  /* Steps become a vertical timeline */
  .steps {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-8);
  }

  .steps__item {
    display: grid;
    grid-template-columns: 56px minmax(0, 1fr);
    column-gap: var(--space-5);
    padding-inline: 0;
    text-align: left;
  }

  .steps__number {
    grid-row: span 2;
    margin-bottom: 0;
  }

  .steps__title {
    align-self: end;
    margin-top: var(--space-1);
  }

  .steps__item:not(:last-child)::after {
    display: block;
    top: 70px;
    bottom: calc(var(--space-8) * -1 + 14px);
    left: 27px;
    width: 0;
    border-top: 0;
    border-left: 2px dashed var(--color-border-strong);
  }

  .steps__notice {
    margin-top: var(--space-10);
  }

  .form__grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .form__actions .btn {
    flex: 1 1 100%;
  }

  .accordion__trigger {
    padding: var(--space-4) var(--space-5);
    font-size: var(--text-md);
  }

  .accordion__content {
    padding: 0 var(--space-5) var(--space-5);
  }
}

@media (max-width: 379.98px) {
  .choice-group {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* ==========================================================================
   Contact page components — same breakpoints as above
   ========================================================================== */

@media (max-width: 1023.98px) {
  .location-layout {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 599.98px) {
  .map-frame {
    aspect-ratio: 4 / 5;
    min-height: 0;
  }

  .map-placeholder {
    padding: var(--space-4);
  }

  .map-placeholder__card {
    padding: var(--space-5) var(--space-4) var(--space-4);
  }
}

/* ==========================================================================
   News page components — same breakpoints as above
   ========================================================================== */

@media (max-width: 1023.98px) {
  .news-feature {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 599.98px) {
  .news-filter {
    justify-content: flex-start;
    gap: var(--space-2);
  }

  .news-filter__btn {
    min-height: 40px;
    padding: 0.375rem 0.625rem 0.375rem 0.875rem;
    font-size: var(--text-sm);
  }

  .news-results {
    text-align: left;
  }

  .news-modal {
    width: calc(100% - (var(--space-3) * 2));
    max-height: calc(100vh - (var(--space-3) * 2));
    max-height: calc(100dvh - (var(--space-3) * 2));
  }

  .news-modal__actions .btn {
    width: 100%;
  }

  .newsletter-form__row {
    flex-direction: column;
    align-items: stretch;
  }

  .newsletter-form__row .btn {
    width: 100%;
  }
}

/* ==========================================================================
   Photos & Videos page components — same breakpoints as above
   ========================================================================== */

@media (max-width: 1023.98px) {
  .gallery-grid--page {
    --cols: 3;
  }
}

@media (max-width: 767.98px) {
  .gallery-grid--page {
    --cols: 2;
    --gap: var(--space-3);
    grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
    gap: var(--gap);
  }

  .gallery-grid--page .gallery-item__overlay {
    padding: var(--space-8) var(--space-3) var(--space-3);
  }

  .gallery-grid--page .gallery-item__overlay svg {
    display: none;
  }
}

@media (max-width: 479.98px) {
  .gallery-tabs {
    width: 100%;
  }

  .gallery-tabs__tab {
    flex: 1 1 0;
    min-width: 0;
    padding-inline: var(--space-3);
    font-size: var(--text-sm);
  }

  .gallery-tabs__tab svg {
    display: none;
  }

  .gallery-grid--page .gallery-item__title {
    font-size: var(--text-sm);
  }
}

/* 3-column tablet mosaic: one tall tile shows as a square so the 27 cells
   fill complete rows (no gaps at the end of the grid) */
@media (min-width: 768px) and (max-width: 1023.98px) {
  .gallery-grid--page .gallery-item--square-md {
    grid-row: auto;
  }
}

/* ==========================================================================
   Sub-Committees page components — same breakpoints as above
   ========================================================================== */

@media (max-width: 1023.98px) {
  .media-collage {
    max-width: 720px;
  }
}

@media (max-width: 767.98px) {
  .media-collage::before {
    top: -4%;
    left: 0;
    border-width: 14px;
  }
}

@media (max-width: 599.98px) {
  .committee-modal {
    width: calc(100% - (var(--space-3) * 2));
  }

  .committee-modal__header {
    align-items: flex-start;
    gap: var(--space-4);
  }

  .committee-modal__icon {
    width: 52px;
    height: 52px;
  }

  .committee-modal__icon svg {
    width: 26px;
    height: 26px;
  }

  .media-collage__inset {
    border-width: 4px;
  }
}

/* ==========================================================================
   Accounts page components — same breakpoints as above
   ========================================================================== */

@media (max-width: 1023.98px) {
  .accounts-status {
    max-width: 720px;
  }
}

@media (max-width: 767.98px) {
  .doc-item {
    grid-template-columns: auto minmax(0, 1fr);
    align-items: start;
    gap: var(--space-4) var(--space-5);
    padding: var(--space-5);
  }

  .doc-item__icon {
    width: 52px;
    height: 62px;
  }

  .doc-item__icon svg {
    width: 24px;
    height: 24px;
  }

  .doc-item__actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
    padding-top: var(--space-4);
    border-top: 1px solid var(--color-border);
  }

  .pdf-frame {
    aspect-ratio: 3 / 4;
    min-height: 0;
  }
}

@media (max-width: 479.98px) {
  .doc-item__actions {
    flex-direction: column;
    align-items: stretch;
  }

  .doc-item__actions > .btn,
  .doc-download,
  .doc-download .btn {
    width: 100%;
  }
}

/* ==========================================================================
   Constitution page components — same breakpoints as above
   ========================================================================== */

@media (max-width: 1023.98px) {
  .const-about {
    max-width: 720px;
  }

  .preview-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-6);
  }
}

@media (max-width: 767.98px) {
  .const-doc {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-6);
  }

  .const-doc__cover {
    padding: var(--space-6);
  }

  .doc-cover {
    max-width: 150px;
  }

  .pdf-frame--viewer {
    aspect-ratio: auto;
    height: clamp(420px, 70vh, 640px);
  }
}

@media (max-width: 479.98px) {
  .const-doc__actions,
  .preview-info__actions {
    flex-direction: column;
    align-items: stretch;
  }

  .const-doc__actions .doc-download,
  .preview-info__actions .doc-download,
  .const-doc__actions .btn,
  .preview-info__actions .btn {
    width: 100%;
  }
}

/* ==========================================================================
   Activity wing detail pages — same breakpoints as above
   ========================================================================== */

/* Other wings: below 1024px switch to compact horizontal rows
   (thumbnail + title) in 2 columns; an odd last item spans both */
@media (max-width: 1023.98px) {
  .wing-links {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-3);
  }

  .wing-links > li:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }

  .wing-link {
    flex-direction: row;
    align-items: center;
  }

  .wing-link:hover {
    transform: none;
  }

  .wing-link__media {
    flex: 0 0 112px;
    align-self: stretch;
    aspect-ratio: auto;
    min-height: 84px;
  }

  .wing-link__body {
    padding: var(--space-3) var(--space-5);
  }
}

@media (max-width: 599.98px) {
  .wing-links {
    grid-template-columns: minmax(0, 1fr);
  }

  .wing-link__media {
    flex-basis: 96px;
  }
}


/* ==========================================================================
   Final audit fix — Constitution document cover label (mobile)
   At < 768px the cover shrinks to 150px, which left "CONSTITUTION" (18px)
   wider than its 80px text box and clipped by the cover's overflow.
   ========================================================================== */
@media (max-width: 767.98px) {
  .doc-cover__label {
    font-size: var(--text-xs);
    letter-spacing: 0;
  }
}


/* ==========================================================================
   Fix — horizontal overflow from the decorative ring (Activity Wing pages)
   --------------------------------------------------------------------------
   When .split__media--ring is the last item of a normal (non-reversed) split,
   the image sits in the right column and its ring (right: -7%) points out
   towards the viewport edge. Between 1024px and ~1300px the gap between the
   image and the viewport edge is only the container gutter (or a little
   more), so the ring reached 3-15px past it once a classic scrollbar took its
   width. The image edge is always at least one gutter inside the viewport,
   so capping the offset at the gutter keeps the ring on-screen. At 1320px
   and wider the original -7% fits, so the desktop design is unchanged.
   ========================================================================== */
@media (min-width: 1024px) and (max-width: 1319.98px) {
  .split:not(.split--reverse) > .split__media--ring:last-child::before {
    right: max(-7%, calc(var(--gutter) * -1));
  }
}

/* Same cause in the stacked layout (< 1024px): the existing right: -3% on a
   720px-wide image (21.6px) is more than the 20px gutter used below 768px,
   so the ring overshot by about 1px at 740-767px. Capping at the gutter
   changes nothing wherever -3% already fits. */
@media (max-width: 1023.98px) {
  .split__media--ring::before,
  .split--reverse .split__media--ring::before {
    right: max(-3%, calc(var(--gutter) * -1));
  }
}
