/* ==========================================================================
   Heritage Cabinetry — styles
   All colours and fonts flow from the CSS variables below. The theme
   switcher (theme-switcher.js) overrides these live so the team can dial in
   the final palette + fonts before shipping. Bake the chosen values back
   into :root here, then remove the switcher, before handing to the client.
   ========================================================================== */

:root {
  /* ---- Palette (design tags: light / mid / dark + accent) --------------- */
  --color-light: #f5f1ed;   /* light colour — page background            */
  --color-mid:   #bfb5af;   /* mid colour   — panels, header             */
  --color-dark:  #252422;   /* dark colour  — footer, dark cards, text   */
  --color-accent:#a63c06;   /* accent       — links, buttons, highlights */

  /* Derived text colours */
  --text-on-light: #2b2724;
  --text-on-dark:  #f5f1ed;
  --text-muted:    #6f665f;

  /* ---- Typography ------------------------------------------------------- */
  --font-header: 'Playfair Display', Georgia, serif;   /* headings          */
  --font-body:   'Source Sans 3', system-ui, sans-serif; /* body copy       */
  --font-menu:   'Source Sans 3', system-ui, sans-serif; /* nav / menu      */

  /* ---- Layout ----------------------------------------------------------- */
  --maxw: 1200px;
  --gap: clamp(1rem, 3vw, 2.5rem);
  --radius: 4px;
  --header-h: 104px;
  --header-h-scrolled: 66px;
  --shadow: 0 10px 30px rgba(20, 18, 16, 0.18);
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--color-light);
  color: var(--text-on-light);
  font-family: var(--font-body);
  font-size: 1.05rem;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  /* Sticky footer: on screens taller than the content, main stretches and
     the footer stays at the true bottom — no page-background strip below it. */
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

main { flex: 1 0 auto; display: flex; flex-direction: column; }
main > :last-child { flex: 1 0 auto; }

h1, h2, h3, h4 {
  font-family: var(--font-header);
  line-height: 1.1;
  font-weight: 700;
  margin: 0 0 0.5em;
}

h1 { font-size: clamp(2.1rem, 5vw, 3.4rem); }
h2 { font-size: clamp(1.7rem, 3.5vw, 2.6rem); }
h3 { font-size: clamp(1.3rem, 2.5vw, 1.8rem); }

a { color: var(--color-accent); text-decoration: none; }
a:hover { text-decoration: underline; }

img { display: block; max-width: 100%; }

.container {
  max-width: var(--maxw);
  margin-inline: auto;
  padding-inline: var(--gap);
}

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

/* Section background variants matching the wireframe tags */
.bg-light { background: var(--color-light); color: var(--text-on-light); }
.bg-mid   { background: var(--color-mid);   color: var(--text-on-light); }
.bg-dark  { background: var(--color-dark);  color: var(--text-on-dark); }
.bg-dark a { color: #e8a06f; }

/* --------------------------------------------------------------------------
   Buttons / links
   -------------------------------------------------------------------------- */
.btn {
  display: inline-block;
  text-align: center;
  font-family: var(--font-menu);
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-size: 0.95rem;
  padding: 0.72em 1.5em;
  border: 2px solid var(--color-accent);
  border-radius: var(--radius);
  background: var(--color-accent);
  color: #fff;
  cursor: pointer;
  transition: background 0.2s var(--ease), color 0.2s var(--ease), transform 0.2s var(--ease);
}
.btn:hover { background: transparent; color: var(--color-accent); text-decoration: none; transform: translateY(-2px); }
.btn-ghost { background: transparent; color: var(--color-accent); }
.btn-ghost:hover { background: var(--color-accent); color: #fff; }
/* Keep solid buttons bright white on dark sections (the .bg-dark link tint
   would otherwise out-rank .btn and dim the label). */
.bg-dark a.btn { color: #fff; }
.bg-dark a.btn:hover { background: transparent; border-color: #fff; color: #fff; }
.bg-dark .btn-ghost { background: transparent; color: var(--text-on-dark); border-color: var(--text-on-dark); }
.bg-dark .btn-ghost:hover { background: var(--text-on-dark); color: var(--color-dark); }

.eyebrow {
  font-family: var(--font-menu);
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--color-accent);
  margin-bottom: 0.75rem;
}

/* --------------------------------------------------------------------------
   Header — sticky, shrinks on scroll, logo centred between the nav groups
   -------------------------------------------------------------------------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--color-mid);
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  transition: background 0.3s var(--ease), box-shadow 0.3s var(--ease);
}
.site-header.scrolled { box-shadow: var(--shadow); }

.nav {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: var(--gap);
  height: var(--header-h);
  transition: height 0.3s var(--ease);
}
.site-header.scrolled .nav { height: var(--header-h-scrolled); }

/* On desktop the menu wrapper is transparent to the grid so the two link
   groups sit either side of the centred logo. */
.nav-menu { display: contents; }
.brand { grid-column: 2; grid-row: 1; }
.nav-group { display: flex; gap: clamp(1rem, 2.5vw, 2.4rem); font-family: var(--font-menu); }
.nav-group.left { grid-column: 1; grid-row: 1; }
.nav-group.right { grid-column: 3; grid-row: 1; justify-content: flex-end; }

.nav a {
  color: var(--text-on-light);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.3em 0;
  position: relative;
}
.nav a::after {
  content: "";
  position: absolute;
  left: 0; bottom: -2px;
  width: 0; height: 2px;
  background: var(--color-accent);
  transition: width 0.25s var(--ease);
}
.nav a:hover { text-decoration: none; }
.nav a:hover::after, .nav a.active::after { width: 100%; }

.brand { display: flex; justify-content: center; }
.brand img {
  height: 68px;
  transition: height 0.3s var(--ease);
}
.site-header.scrolled .brand img { height: 42px; }

/* Mobile nav toggle */
.nav-toggle { display: none; }

/* --------------------------------------------------------------------------
   Hero — fogged / shaded scrolling photos behind the tagline
   -------------------------------------------------------------------------- */
.hero {
  position: relative;
  min-height: 78vh;
  display: grid;
  place-items: center;
  text-align: center;
  overflow: hidden;
  color: var(--text-on-dark);
}
.hero__slides { position: absolute; inset: 0; z-index: 0; }
.hero__slide {
  position: absolute; inset: 0;
  background-size: cover;
  background-position: center;
  opacity: 0;
  transition: opacity 1.6s ease-in-out;
  transform: scale(1.05);
}
.hero__slide.is-active { opacity: 1; }
.hero::after {   /* fog / shade overlay */
  content: "";
  position: absolute; inset: 0; z-index: 1;
  background: linear-gradient(180deg, rgba(37,36,34,0.55), rgba(37,36,34,0.35) 40%, rgba(37,36,34,0.7));
}
.hero__inner { position: relative; z-index: 2; padding: var(--gap); }
.hero__inner h1 { color: #fff; text-shadow: 0 2px 20px rgba(0,0,0,0.4); }
.hero__inner p { font-size: 1.2rem; max-width: 40ch; margin-inline: auto; }

/* --------------------------------------------------------------------------
   Alternating feature cards (Home) — photo panel + text panel
   -------------------------------------------------------------------------- */
.features { display: grid; gap: 0; }
.feature {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: stretch;
  min-height: 420px;
}
.feature__media {
  background-size: cover;
  background-position: center;
  min-height: 320px;
}
.feature__body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(2rem, 5vw, 4.5rem);
}
.feature__body p { max-width: 46ch; }
.feature__body .btn { align-self: flex-start; margin-top: 1rem; }

/* --------------------------------------------------------------------------
   Generic content blocks
   -------------------------------------------------------------------------- */
.lead { font-size: 1.25rem;}
.center { text-align: center; margin-inline: auto; }
.stack > * + * { margin-top: 1rem; }

/* About */
.about-grid {
  display: grid;
  grid-template-columns: 0.9fr 1.1fr;
  gap: clamp(1.5rem, 4vw, 3.5rem);
  align-items: center;
}
.about-grid img { width: 100%; height: 100%; object-fit: cover; border-radius: var(--radius); box-shadow: var(--shadow); aspect-ratio: 4/5; }

/* Services process steps. The text column is slightly wider than the photo
   column, so the photo/text seam sits off-centre and alternates side to side
   down the page instead of forming one straight line. */
.process { display: grid; gap: 0; }
.step {
  display: grid;
  grid-template-columns: 1fr 1.18fr;
  min-height: 360px;
  align-items: stretch;
}
.step:nth-child(odd) { grid-template-columns: 1.18fr 1fr; }
.step:nth-child(odd) .step__media { order: 2; }
.step__media { background-size: cover; background-position: center; min-height: 260px; }
.step__body { display: flex; flex-direction: column; justify-content: center; padding: clamp(2rem, 5vw, 4rem); }
.step__body p { max-width: 56ch; }
/* Wireframe lockup: circled number beside the title, text starting left. */
.step__head { display: flex; align-items: center; gap: 1.1rem; margin-bottom: 0.9rem; }
.step__head h3 { margin: 0; }
.step__num {
  flex: 0 0 auto;
  font-family: var(--font-header);
  font-size: 1.7rem;
  line-height: 1;
  /* Playfair defaults to old-style figures where 3/4/5 dip below the
     baseline; lining figures keep every digit the same height so all five
     circles centre identically. */
  font-variant-numeric: lining-nums;
  width: 3rem; height: 3rem;
  display: grid; place-items: center;
  padding-bottom: 0.14em; /* optical centring within the line box */
  border: 2px solid currentColor;
  border-radius: 50%;
  opacity: 0.85;
}

.projects .lead { max-width: none; }
.project-list {
  list-style: none;
  padding: 0;
  margin: 1.75rem 0 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.85rem 2.5rem;
  max-width: 960px;
  font-size: 1.15rem;
}
.project-list li { position: relative; padding-left: 1.5rem; }
.project-list li::before { content: "▸"; position: absolute; left: 0; color: var(--color-accent); }

/* --------------------------------------------------------------------------
   Gallery
   -------------------------------------------------------------------------- */
/* Category tiles on the dark band. CSS grid (not flex) so full rows always
   fill the container width exactly while resizing — no basis/min-width
   rounding gaps. Only the final short row keeps tile-sized, centred items.
   The nth-child centring rules below assume the five albums defined in
   server.py; revisit them if that count ever changes. */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr); /* >=1168px: all five on one row */
  align-content: start; /* when stretched by the sticky footer on tall screens,
                           keep rows packed — spare height stays dark below */
  gap: 3px;
  background: var(--color-dark);
  padding: 0 3px 3rem;
}
.gallery-cat {
  position: relative;
  aspect-ratio: 4/3;
  overflow: hidden;
  display: grid;
  place-items: center;
  text-align: center;
  color: #fff;
}
@media (max-width: 1167px) {
  /* 3 per row (3 + 2): tiles span two of six tracks; the leftover pair is
     centred by starting tile 4 one track in. */
  .gallery-grid { grid-template-columns: repeat(6, 1fr); }
  .gallery-cat { grid-column: span 2; }
  .gallery-cat:nth-child(4) { grid-column: 2 / span 2; }
}
@media (max-width: 768px) {
  /* 2 per row (2 + 2 + 1): the final odd tile is centred the same way. */
  .gallery-grid { grid-template-columns: repeat(4, 1fr); }
  .gallery-cat:nth-child(4) { grid-column: auto / span 2; }
  .gallery-cat:nth-child(5) { grid-column: 2 / span 2; }
}
@media (max-width: 520px) {
  /* Phones: single full-width column. */
  .gallery-grid { grid-template-columns: 1fr; }
  .gallery-cat, .gallery-cat:nth-child(4), .gallery-cat:nth-child(5) { grid-column: auto; }
}
.gallery-cat img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  transition: transform 0.6s var(--ease), filter 0.6s var(--ease);
  filter: brightness(0.55) saturate(0.9);
}
.gallery-cat:hover img { transform: scale(1.06); filter: brightness(0.4); }
.gallery-cat__label { position: relative; z-index: 2; padding: 1rem; }
.gallery-cat__label h3 { color: #fff; margin: 0; }
.gallery-cat:hover { text-decoration: none; }

/* Album grid — every tile the same scale (cropped to fill), no white gaps */
.album-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 4px;
}
.album-grid img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 2px;
  display: block;
}

/* --------------------------------------------------------------------------
   Contact
   -------------------------------------------------------------------------- */
/* 3-column contact layout (wireframe): map | fields | message + send.
   Columns are top-aligned with natural heights — no stretching, so the map
   is sized purely by its aspect ratio and nothing overflows. */
.contact-layout {
  display: grid;
  grid-template-columns: 1.1fr 1fr 1fr;
  gap: clamp(1.5rem, 4vw, 2.5rem);
  align-items: start;
  margin-top: 2.5rem;
}
.contact-fields { display: grid; gap: 1rem; }
.contact-message { display: grid; gap: 0.85rem; }
.contact-message .field textarea { min-height: 210px; }
.contact-message .btn { justify-self: stretch; }
/* On desktop, size the message box so the column fills out to match the
   fields column, with the full-width Send button closing the row. */
@media (min-width: 861px) {
  .contact-message .field textarea { min-height: 330px; }
}

.map-wrap { position: relative; }
.map-embed {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 5;
  min-height: 320px;
  border: 0;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  background: var(--color-mid);
}
/* Clear the map's drop shadow before the caption starts. */
.map-caption { margin: 1.1rem 0 0; font-size: 0.85rem; }
.map-caption a { color: var(--color-accent); }
.map-fallback {
  display: grid; place-items: center; text-align: center;
  padding: 2rem; aspect-ratio: 4/5; min-height: 340px;
  border-radius: var(--radius); background: var(--color-mid); color: var(--text-on-light);
}
/* The card is a JS-revealed last resort; keep it truly hidden until then
   (the display:grid above would otherwise override the hidden attribute). */
.map-fallback[hidden] { display: none; }

.field { display: grid; gap: 0.35rem; }
.field label { font-family: var(--font-menu); font-weight: 600; font-size: 0.85rem; letter-spacing: 0.04em; text-transform: uppercase; }
.field input, .field select, .field textarea {
  font: inherit;
  padding: 0.75em 0.9em;
  border: 1.5px solid rgba(0,0,0,0.18);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text-on-light);
}
/* Custom select chevron with breathing room, matching the text inputs. */
.field select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 2.8em;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%236f665f' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 1em center;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(166, 60, 6, 0.15);
}
.field textarea { min-height: 130px; resize: vertical; }
.field .error { color: #b3261e; font-size: 0.85rem; min-height: 1em; }
.honeypot { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

.form-status { font-weight: 600; }
.form-status.ok { color: #2e7d32; }
.form-status.err { color: #b3261e; }

/* --------------------------------------------------------------------------
   Footer
   -------------------------------------------------------------------------- */
.site-footer { background: var(--color-dark); color: var(--text-on-dark); padding-block: 3rem; }
.footer-grid {
  display: grid;
  grid-template-columns: auto 1fr 1fr auto;
  gap: clamp(1.5rem, 4vw, 3rem);
  align-items: center;
}
.footer-grid img { height: 66px; }
.footer-contact, .footer-hours { list-style: none; margin: 0; padding: 0; font-size: 0.95rem; }
/* Contact and Hours share the same row rhythm so the two titled columns
   line up row-for-row. */
.footer-contact li { display: flex; gap: 0.6rem; margin-bottom: 0.4rem; }
.footer-contact li:last-child { margin-bottom: 0; }
.footer-contact a { color: var(--text-on-dark); }
.footer-hours { display: grid; grid-template-columns: auto auto; gap: 0.4rem 1.2rem; }
.footer-hours dt { font-weight: 600; }
.footer-hours dd { margin: 0; } /* drop the browser's default 40px indent */
.footer-title { font-family: var(--font-menu); text-transform: uppercase; letter-spacing: 0.14em; font-size: 0.75rem; opacity: 0.7; margin-bottom: 0.6rem; }

/* Floating back-to-top */
.to-top {
  position: fixed;
  right: 1.5rem; bottom: 1.5rem;
  z-index: 90;
  display: inline-flex; align-items: center; gap: 0.5rem;
  padding: 0.7em 1em;
  background: var(--color-dark);
  color: var(--text-on-dark);
  border-radius: 999px;
  box-shadow: var(--shadow);
  font-family: var(--font-menu); font-size: 0.8rem; letter-spacing: 0.06em; text-transform: uppercase;
  opacity: 0; visibility: hidden; transform: translateY(12px);
  transition: opacity 0.3s var(--ease), transform 0.3s var(--ease), visibility 0.3s;
}
.to-top.show { opacity: 1; visibility: visible; transform: translateY(0); }
.to-top:hover { text-decoration: none; background: var(--color-accent); }
.to-top svg { width: 16px; height: 16px; }

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 860px) {
  .feature, .step, .about-grid, .contact-layout, .footer-grid { grid-template-columns: 1fr; }
  .step:nth-child(odd) { grid-template-columns: 1fr; }
  .feature__media, .step__media { min-height: 260px; }
  /* When stacked, always show text then photo — the hero slideshow leads
     straight into "Why Choose…", and no two photos ever touch. */
  .feature__body { order: -1; }
  .step:nth-child(odd) .step__media { order: 0; }
  .project-list { grid-template-columns: 1fr 1fr; }
  .footer-grid { text-align: left; justify-items: start; }

  /* Mobile nav: logo left, hamburger right, dropdown panel below the header.
     The panel is display:none when closed so it can never peek or overlap. */
  :root { --header-h: 76px; --header-h-scrolled: 60px; }
  .nav { display: flex; align-items: center; justify-content: space-between; position: relative; }
  .brand img { height: 48px; }
  .site-header.scrolled .brand img { height: 40px; }
  .nav-toggle {
    display: inline-flex; flex-direction: column; gap: 5px;
    background: none; border: 0; cursor: pointer; padding: 0.6rem;
  }
  .nav-toggle span { width: 24px; height: 2px; background: var(--text-on-light); transition: transform 0.2s var(--ease), opacity 0.2s; }
  .nav.open .nav-toggle span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
  .nav.open .nav-toggle span:nth-child(2) { opacity: 0; }
  .nav.open .nav-toggle span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

  .nav-menu {
    display: none;
    position: absolute;
    top: 100%; left: 0; right: 0;
    background: var(--color-mid);
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow: var(--shadow);
    padding: 0.5rem var(--gap) 1rem;
  }
  .nav.open .nav-menu { display: block; }
  .nav-group { display: block; }
  .nav-group a { display: block; padding: 0.85rem 0; border-bottom: 1px solid rgba(0, 0, 0, 0.07); }
  .nav-group.right a:last-child { border-bottom: 0; }
}

@media (max-width: 520px) {
  .project-list { grid-template-columns: 1fr; }
}
