/* ==========================================================================
   COMPONENT: Navigation
   Desktop: utility bar + main bar with dropdowns.
   Mobile (<= 1100px): compact bar + off-canvas panel.
   ========================================================================== */

.site-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--nav-background-color);
  color: var(--text-on-dark);

  a {
    text-decoration: none;
  }

  /* Utility bar */
  .nav-utility {
    background: color-mix(in srgb, var(--nav-background-color) 70%, black);
    font-size: 0.85rem;
    color: var(--text-on-dark-muted);

    .container {
      display: flex;
      justify-content: space-between;
      align-items: center;
      gap: 20px;
      min-height: 38px;
    }

    ul {
      display: flex;
      gap: 24px;
      margin: 0;
      padding: 0;
      list-style: none;
    }

    li {
      display: inline-flex;
      align-items: center;
      gap: 8px;
    }

    i {
      color: var(--primary-color);
    }

    a:hover {
      color: var(--primary-color);
    }
  }

  /* Main bar */
  .nav-main .container {
    position: relative;
    display: flex;
    align-items: center;
    gap: 24px;
    min-height: 84px;
  }

  .nav-logo {
    flex: 0 0 auto;

    img {
      width: 210px;
      height: auto;
    }
  }

  .nav-links {
    display: flex;
    align-items: center;
    gap: 4px;
    margin: 0 auto 0 0;
    padding: 0;
    list-style: none;

    > li {
      position: relative;
    }

    > li > a,
    > li > button {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      padding: 10px 12px;
      font: 600 0.97rem var(--font-body);
      white-space: nowrap;
      color: var(--text-on-dark);
      background: none;
      border: 0;
      border-radius: var(--radius);
      cursor: pointer;

      &:hover,
      &[aria-current="page"] {
        color: var(--primary-color);
      }

      i {
        font-size: 0.7rem;
        transition: transform 0.2s ease;
      }
    }

    > li:hover > button i,
    > li:focus-within > button i {
      transform: rotate(180deg);
    }
  }

  .nav-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    min-width: 250px;
    margin: 0;
    padding: 10px;
    list-style: none;
    background: white;
    border-radius: var(--radius-lg);
    border-top: 4px solid var(--primary-color);
    box-shadow: var(--shadow);
    opacity: 0;
    visibility: hidden;
    transform: translateY(8px);
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;

    /* Hover bridge so the menu does not close in the gap */
    &::before {
      content: "";
      position: absolute;
      inset: -14px 0 auto;
      height: 14px;
    }

    a {
      display: block;
      padding: 10px 14px;
      color: var(--secondary-color);
      font-weight: 600;
      border-radius: var(--radius);

      &:hover {
        background: var(--primary-soft);
      }
    }
  }

  .nav-links > li:hover .nav-dropdown,
  .nav-links > li:focus-within .nav-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
  }

  /* Services mega panel (spans the nav width) */
  .nav-links > li.nav-item-mega {
    position: static;
  }

  .nav-mega {
    position: absolute;
    top: calc(100% - 6px);
    left: var(--gutter);
    right: var(--gutter);
    display: grid;
    grid-template-columns: 1.6fr 1fr 1fr;
    grid-template-rows: auto 1fr;
    gap: 0;
    margin: 0;
    padding: 0;
    list-style: none;
    color: var(--secondary-color);
    background: white;
    border-radius: var(--radius-lg);
    border-top: 4px solid var(--primary-color);
    box-shadow: var(--shadow);
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(8px);
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;

    &::before {
      content: "";
      position: absolute;
      inset: -20px 0 auto;
      height: 20px;
    }

    ul {
      margin: 0;
      padding: 0;
      list-style: none;
    }
  }

  .nav-links > li.nav-item-mega:hover .nav-mega,
  .nav-links > li.nav-item-mega:focus-within .nav-mega {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
  }

  .nav-mega-col {
    padding: 28px;

    + .nav-mega-col {
      border-left: 1px solid var(--border-color);
    }
  }

  /* Roofing and Siding fill both rows; Pole Barn sits above View All Services */
  .nav-mega-col:not(.nav-mega-side) {
    grid-row: 1 / span 2;
  }

  .nav-mega-side {
    grid-column: 3;
  }

  .nav-mega-side:not(.nav-mega-foot) {
    padding-bottom: 0;
  }

  .nav-mega-foot {
    display: flex;
    align-items: flex-end;
    padding-top: 0;

    .nav-mega-all {
      flex: 1;
    }
  }

  .nav-mega-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
    padding-bottom: 12px;
    font-family: var(--font-heading);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--secondary-color);
    border-bottom: 2px solid var(--primary-color);

    i {
      display: grid;
      place-items: center;
      width: 34px;
      height: 34px;
      font-size: 1rem;
      color: var(--secondary-color);
      background: var(--primary-soft);
      border-radius: 50%;
    }

    &:hover {
      color: var(--primary-strong);
    }
  }

  .nav-mega-list {
    a {
      display: block;
      padding: 7px 10px;
      margin-inline: -10px;
      font-size: 0.95rem;
      font-weight: 500;
      color: var(--secondary-color);
      border-radius: var(--radius);

      &:hover {
        color: var(--secondary-color);
        background: var(--primary-soft);
      }
    }
  }

  .nav-mega-list-2col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: 24px;
  }

  .nav-mega-side {
    background: var(--surface-color);

    p {
      margin: 0;
      font-size: 0.93rem;
      color: var(--text-muted);
    }
  }

  .nav-mega-all {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 24px;
    padding: 12px 16px;
    font-weight: 700;
    color: var(--text-on-dark);
    background: var(--secondary-color);
    border-radius: var(--radius);

    &:hover {
      color: var(--primary-color);
    }
  }

  .nav-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    white-space: nowrap;
  }

  .nav-phone {
    display: flex;
    align-items: center;
    gap: 10px;
    line-height: 1.2;

    i {
      display: grid;
      place-items: center;
      width: 40px;
      height: 40px;
      border-radius: 50%;
      background: color-mix(in srgb, var(--primary-color) 18%, transparent);
      color: var(--primary-color);
    }

    small {
      display: block;
      font-size: 0.75rem;
      color: var(--text-on-dark-muted);
    }

    strong {
      font-size: 1.02rem;
    }

    &:hover strong {
      color: var(--primary-color);
    }
  }

  /* Mobile toggle (hidden on desktop) */
  .nav-toggle {
    display: none;
    margin-left: auto;
    width: 48px;
    height: 48px;
    font-size: 1.6rem;
    color: var(--text-on-dark);
    background: color-mix(in srgb, white 8%, transparent);
    border: 0;
    border-radius: var(--radius);
    cursor: pointer;
  }

  .nav-mobile-call {
    display: none;
  }
}

/* Off-canvas panel */
.nav-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgb(0 0 0 / 0.6);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s;

  &.is-open {
    opacity: 1;
    visibility: visible;
  }
}

.nav-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 210;
  width: min(360px, 88vw);
  padding: 20px 24px 32px;
  overflow-y: auto;
  background: var(--nav-background-color);
  color: var(--text-on-dark);
  transform: translateX(100%);
  transition: transform 0.3s ease;

  &.is-open {
    transform: translateX(0);
  }

  .nav-panel-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;

    img {
      width: 170px;
    }
  }

  .nav-close {
    width: 44px;
    height: 44px;
    font-size: 1.5rem;
    color: var(--text-on-dark);
    background: color-mix(in srgb, white 8%, transparent);
    border: 0;
    border-radius: var(--radius);
    cursor: pointer;
  }

  ul {
    margin: 0;
    padding: 0;
    list-style: none;
  }

  > ul > li {
    border-bottom: 1px solid var(--border-on-dark);
  }

  /* Menu links only; the buttons in .btn-row keep their own button styles */
  ul a,
  .nav-panel-sub-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 14px 0;
    font: 600 1.05rem var(--font-body);
    color: var(--text-on-dark);
    text-decoration: none;
    background: none;
    border: 0;
    cursor: pointer;
  }

  .nav-panel-sub {
    display: none;
    padding: 0 0 10px 14px;
    border-left: 2px solid var(--primary-color);

    a {
      padding: 8px 0;
      font-size: 0.97rem;
      color: var(--text-on-dark-muted);
    }
  }

  li.is-expanded > .nav-panel-sub {
    display: block;
  }

  li.is-expanded > .nav-panel-sub-toggle i,
  li.is-expanded > .nav-panel-row .nav-panel-sub-toggle i {
    transform: rotate(180deg);
  }

  .nav-panel-sub-toggle i {
    transition: transform 0.2s ease;
  }

  /* Category row: link on the left, expand button on the right */
  .nav-panel-row {
    display: flex;
    align-items: center;

    a {
      flex: 1;
      color: var(--text-on-dark);
    }

    .nav-panel-sub-toggle {
      justify-content: center;
      width: 44px;
      flex: 0 0 44px;
      color: var(--primary-color);
    }
  }

  .nav-panel-sub .nav-panel-sub {
    margin: 2px 0 8px;
    border-left-color: var(--border-on-dark);

    a {
      font-size: 0.92rem;
    }
  }

  .btn-row {
    margin-top: 24px;
    flex-direction: column;
  }
}

body.nav-locked {
  overflow: hidden;
}

@media (max-width: 1360px) {
  .site-nav .nav-phone span {
    display: none;
  }
}

@media (max-width: 1100px) {
  .site-nav {
    .nav-utility,
    .nav-links,
    .nav-actions {
      display: none;
    }

    .nav-main .container {
      min-height: 72px;
      gap: 12px;
    }

    .nav-logo img {
      width: 180px;
    }

    .nav-toggle {
      display: grid;
      place-items: center;
    }

    .nav-mobile-call {
      display: grid;
      place-items: center;
      margin-left: auto;
      width: 48px;
      height: 48px;
      font-size: 1.3rem;
      color: var(--secondary-color);
      background: var(--primary-color);
      border-radius: var(--radius);

      + .nav-toggle {
        margin-left: 0;
      }
    }
  }
}
