/* ============================================
   Fair Winds Plumbing - layout.css
   Header, footer, container, section grids
   ============================================ */

.container {
  width: 100%;
  max-width: var(--max);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

section { padding-block: clamp(3.5rem, 7vw, 6rem); }

/* ---------- Header ---------- */
.site-header {
  position: fixed;                         /* fixed so overflow strategies can't break it */
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  background: rgba(24, 63, 89, 0.97);     /* deep navy - lighthouse trim */
  border-bottom: 2px solid rgba(184, 134, 63, 0.30);  /* brass rule */
}
/* Desktop-only backdrop-filter.
   On mobile the .site-nav drawer is a position:fixed descendant; per CSS spec,
   backdrop-filter on its ancestor makes that ancestor the drawer's containing
   block, collapsing the drawer to header height. Keep blur off when the drawer
   is in play. */
@media (min-width: 901px) {
  .site-header {
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
  }
}
.site-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  padding-block: 1rem;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--cream);                     /* cream on navy header */
  background: none;
}
.brand:hover { background: none; color: var(--cream); }
.brand__mark {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border-radius: var(--radius-sm);
  background: var(--cream);                /* cream to match logo's native background */
  color: var(--sage);
  flex-shrink: 0;
  overflow: hidden;
  border: 1px solid rgba(184, 134, 63, 0.4);
}
.brand__mark img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.site-nav { display: flex; align-items: center; gap: 1.8rem; }
.site-nav__list {
  display: flex;
  gap: 1.6rem;
  list-style: none;
  margin: 0;
}
.site-nav__list a {
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: rgba(244, 239, 228, 0.75);        /* muted cream on navy */
  background: none;
  padding: 0.4rem 0;
  position: relative;
}
.site-nav__list a:hover,
.site-nav__list a[aria-current="page"] {
  color: var(--cream);
  background-image: linear-gradient(var(--bronze), var(--bronze));
  background-size: 100% 2px;
  background-repeat: no-repeat;
  background-position: 0 100%;
}

.nav-toggle {
  display: none;
  width: 44px; height: 44px;
  position: relative;
  align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--cream);                     /* cream icon on navy header */
  border: 2px solid rgba(244, 239, 228, 0.35);
}
.nav-toggle__bar {
  position: absolute;
  left: 50%;
  width: 22px;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
  transform-origin: center;
  transform: translateX(-50%);
  transition: transform var(--dur-sm, 220ms) var(--ease-rugged-inout, var(--ease)),
              opacity var(--dur-sm, 220ms) var(--ease-rugged-inout, var(--ease)),
              top var(--dur-sm, 220ms) var(--ease-rugged-inout, var(--ease));
}
.nav-toggle__bar--top { top: 13px; }
.nav-toggle__bar--mid { top: 21px; }
.nav-toggle__bar--bot { top: 29px; }
.nav-toggle[aria-expanded="true"] .nav-toggle__bar--top {
  top: 21px;
  transform: translateX(-50%) rotate(45deg);
}
.nav-toggle[aria-expanded="true"] .nav-toggle__bar--mid { opacity: 0; }
.nav-toggle[aria-expanded="true"] .nav-toggle__bar--bot {
  top: 21px;
  transform: translateX(-50%) rotate(-45deg);
}

@media (max-width: 900px) {
  :root { --header-h: 64px; }            /* shorter mobile header - keep body padding accurate */
  /* Shrink the brand on mobile so the header doesn't wrap */
  .brand { font-size: 1.1rem; gap: 0.5rem; }
  .brand__mark { width: 38px; height: 38px; }
  .site-header__inner { gap: 0.75rem; padding-block: 0.75rem; }

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

  /* Full-screen mobile drawer, solid navy background */
  .site-nav {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100dvh;                         /* dynamic viewport height */
    background: #183F59;                    /* solid navy - no transparency, no var() in case it fails to resolve */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 5rem 1.5rem 2rem;
    gap: 0;
    transform: translateX(100%);
    transition: transform 0.3s var(--ease);
    z-index: 45;                            /* above page, below header (50) */
    visibility: hidden;
    opacity: 0;
  }
  .site-nav[data-open="true"] {
    transform: translateX(0);
    visibility: visible;
    opacity: 1;
  }
  .site-nav__list {
    flex-direction: column;
    gap: 0;
    width: 100%;
    max-width: 320px;
    align-items: stretch;
    padding: 0;
  }
  .site-nav__list li {
    border-bottom: 1px solid rgba(184, 134, 63, 0.2);
  }
  .site-nav__list li:last-child { border-bottom: 0; }
  .site-nav__list a {
    font-size: 1.3rem;
    font-family: var(--font-display);
    font-weight: 500;
    letter-spacing: 0;
    text-transform: none;
    color: var(--cream);
    padding: 1.1rem 0;
    display: block;
    width: 100%;
    text-align: center;
    min-height: 56px;
    background: none;
  }
  .site-nav__list a:hover,
  .site-nav__list a[aria-current="page"] {
    color: var(--bronze-soft);
    background: none;
  }

  /* Lock body scroll when drawer is open */
  body:has(.site-nav[data-open="true"]) {
    overflow: hidden;
  }
}

/* ---------- Footer ---------- */
.site-footer {
  margin-top: 0;                           /* wave divider handles spacing */
  background: var(--navy);                 /* deep navy - lighthouse plaque */
  color: var(--cream);
  padding-block: 4rem 2rem;
  position: relative;
}
/* Wave divider is an inline SVG .divider-wave above the footer - no pseudo needed */
.site-footer a {
  color: var(--bronze-soft);
  background: none;
}
/* Allow long email addresses to wrap inside footer links — prefer the <wbr> after "@" over mid-word breaks */
.site-footer .break-email {
  word-break: normal;
  overflow-wrap: break-word;
  hyphens: none;
}
.site-footer a:hover { color: var(--cream); background: none; }

.site-footer__grid {
  display: grid;
  grid-template-columns: 1.5fr 1fr 1fr 1fr;
  gap: 2.5rem;
  margin-bottom: 3rem;
}
@media (max-width: 900px) {
  .site-footer__grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
  .site-footer__grid { grid-template-columns: 1fr; }
}
.site-footer h4 {
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.20em;
  color: var(--bronze-soft);              /* lighter brass on dark surface */
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid rgba(201, 154, 85, 0.28);  /* brass rule */
}
.site-footer ul { list-style: none; }
.site-footer li + li { margin-top: 0.55rem; }
.site-footer__brand p {
  margin-top: 1rem;
  color: rgba(244, 239, 228, 0.68);
  max-width: 32ch;
}
.site-footer__bottom {
  border-top: 1px solid rgba(244, 239, 228, 0.12);
  padding-top: 1.6rem;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  font-size: 0.85rem;
  color: rgba(244, 239, 228, 0.50);
}

/* ---------- Generic grid utility ---------- */
.grid {
  display: grid;
  gap: 1.5rem;
}
.grid--2 { grid-template-columns: repeat(2, 1fr); }
.grid--3 { grid-template-columns: repeat(3, 1fr); }
.grid--auto { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }

/* Centre orphan cards on the last row of a 3-up grid.
   Uses a 6-column track so two leftover items can sit in the middle four columns. */
.grid--3.grid--centre-orphans {
  grid-template-columns: repeat(6, 1fr);
}
.grid--3.grid--centre-orphans > * {
  grid-column: span 2;
}
/* Exactly 5 items: 4th becomes the first orphan on row 2 → start at column 2 */
.grid--3.grid--centre-orphans > :nth-child(3n+1):nth-last-child(2) {
  grid-column: 2 / span 2;
}
/* Exactly 5 items: 5th is the last orphan → starts at column 4 */
.grid--3.grid--centre-orphans > :nth-child(3n+2):last-child {
  grid-column: 4 / span 2;
}
/* Exactly one orphan (e.g. 4 items): centre it in columns 3–4 */
.grid--3.grid--centre-orphans > :nth-child(3n+1):last-child {
  grid-column: 3 / span 2;
}

@media (max-width: 900px) {
  .grid--3 { grid-template-columns: 1fr 1fr; }
  .grid--3.grid--centre-orphans { grid-template-columns: repeat(4, 1fr); }
  .grid--3.grid--centre-orphans > * { grid-column: span 2; }
  /* In a 2-up layout, a single trailing orphan centres in the middle two columns */
  .grid--3.grid--centre-orphans > :nth-child(2n+1):last-child {
    grid-column: 2 / span 2;
  }
  /* Reset the 3-up specific orphan rules so they don't fight the 2-up layout */
  .grid--3.grid--centre-orphans > :nth-child(3n+1):nth-last-child(2),
  .grid--3.grid--centre-orphans > :nth-child(3n+2):last-child {
    grid-column: span 2;
  }
}
@media (max-width: 680px) {
  .grid--2, .grid--3 { grid-template-columns: 1fr; }
  .grid--3.grid--centre-orphans { grid-template-columns: 1fr; }
  .grid--3.grid--centre-orphans > *,
  .grid--3.grid--centre-orphans > :nth-child(3n+1):nth-last-child(2),
  .grid--3.grid--centre-orphans > :nth-child(3n+2):last-child,
  .grid--3.grid--centre-orphans > :nth-child(3n+1):last-child,
  .grid--3.grid--centre-orphans > :nth-child(2n+1):last-child {
    grid-column: 1 / -1;
  }
}
