/* Primary nav + mega menus */

#top_menu {
  flex-wrap: wrap;
  align-items: center;
}

#top_menu_collapse .navbar-nav {
  align-items: center;
}

.sagco-nav-rfq-link {
  background-color: #9d1631 !important;
  color: #fff !important;
  font-weight: 600;
  border-radius: 0.2rem;
  padding-left: 1rem !important;
  padding-right: 1rem !important;
  margin-top: 0.35rem;
  margin-bottom: 0.35rem;
}

.sagco-nav-rfq-link:hover,
.sagco-nav-rfq-link:focus {
  background-color: #7f1228 !important;
  color: #fff !important;
}

/* Bootstrap's .navbar-toggler-icon styles were trimmed from frontend.css —
   draw the hamburger bars directly on the (empty) toggler button.
   WHITE bars: the navbar header is navy, navy bars were invisible. */
.navbar-toggler {
  position: relative;
  width: 2.75rem;
  height: 2.5rem;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  transition: background-color 0.2s ease;
}

.navbar-toggler:hover {
  background: rgba(255, 255, 255, 0.16);
}

.navbar-toggler::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 1.5rem;
  height: 1.25rem;
  transform: translate(-50%, -50%);
  background:
    linear-gradient(#fff, #fff) 0 0 / 100% 2px no-repeat,
    linear-gradient(#fff, #fff) 0 50% / 100% 2px no-repeat,
    linear-gradient(#fff, #fff) 0 100% / 100% 2px no-repeat;
}

/* Mobile nav backdrop (element is injected by site.js) */
.sagco-nav-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1060;
  background: rgba(15, 23, 42, 0.45);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.28s ease, visibility 0.28s;
}

.sagco-nav-backdrop.sagco-open {
  opacity: 1;
  visibility: visible;
}

body.sagco-nav-open {
  overflow: hidden;
}

/* #wrapwrap is the real scroll container (Odoo gives html/body
   overflow:hidden), so lock it too — otherwise the page keeps
   scrolling behind the open sidebar. */
body.sagco-nav-open #wrapwrap {
  overflow: hidden;
}

.sagco-nav-close {
  display: none;
}

/* The trimmed frontend.css has no .dropdown-menu{display:none}/.show rules,
   so the mega menu must manage its own visibility. */
.sagco-mega-dropdown .sagco-mega-menu {
  display: none;
}

.sagco-mega-dropdown .sagco-mega-menu.show {
  display: block;
}

.sagco-mega-inner {
  padding: 1rem;
}

.sagco-mega-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

@media (min-width: 768px) {
  .sagco-mega-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (min-width: 992px) {
  .sagco-nav-rfq-item {
    margin-left: auto !important;
  }

  .sagco-mega-dropdown {
    position: static !important;
  }

  .sagco-mega-dropdown .sagco-mega-menu {
    position: absolute;
    top: 100%;
    width: 100%;
    left: 0;
    right: 0;
    margin-top: 0;
    border-radius: 0;
    border-top: 3px solid #1b2958;
    padding-top: 0.5rem;
    padding-bottom: 0.75rem;
  }

  /* The theme caps dropdowns at 60/70vh with overflow-y:auto (frontend.css,
     site-fixes.css) — mega menus must grow to fit their cards, no scrollbar. */
  #top .nav-item.dropdown.sagco-mega-dropdown .sagco-mega-menu {
    max-height: none;
    overflow: visible;
  }

  .sagco-mega-inner {
    max-width: 1140px;
    margin-left: auto;
    margin-right: auto;
    padding-left: 1.5rem;
    padding-right: 1.5rem;
  }

  .sagco-mega-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.85rem 1rem;
  }
}

.sagco-mega-card {
  display: flex;
  flex-direction: column;
  height: 100%;
  text-decoration: none !important;
  color: #1b2958;
  background: #fff;
  border: 1px solid #e8ecf1;
  border-radius: 0.35rem;
  overflow: hidden;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.sagco-mega-card:hover,
.sagco-mega-card:focus {
  color: #1b2958;
  text-decoration: none !important;
  box-shadow: 0 0.35rem 1rem rgba(27, 41, 88, 0.12);
  transform: translateY(-2px);
}

/* frontend.css underlines nav links via ID-scoped rules — suppress inside mega menus.
   #top_menu_collapse variant covers the sidebar once reparented to <body>. */
#top .sagco-mega-card,
#top .sagco-mega-card *,
#top .sagco-mega-see-all,
#top_menu_collapse .sagco-mega-card,
#top_menu_collapse .sagco-mega-card *,
#top_menu_collapse .sagco-mega-see-all {
  text-decoration: none !important;
}

.sagco-mega-card.active {
  border-color: #1b2958;
  box-shadow: 0 0 0 1px #1b2958;
}

.sagco-mega-card-img-wrap {
  display: block;
  aspect-ratio: 16 / 10;
  overflow: hidden;
  background: #dde4ee;
}

.sagco-mega-card-img-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Wrapper is invisible until the desktop horizontal layout needs it —
   keeps the mobile flat list identical to before. */
.sagco-mega-card-body {
  display: contents;
}

.sagco-mega-card-title {
  display: block;
  font-size: 0.875rem;
  font-weight: 700;
  line-height: 1.3;
  padding: 0.55rem 0.65rem 0.15rem;
}

.sagco-mega-card-meta {
  display: block;
  font-size: 0.75rem;
  color: #6c757d;
  padding: 0 0.65rem 0.55rem;
}

.sagco-mega-footer {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid #e8ecf1;
  text-align: center;
}

.sagco-mega-see-all {
  background-color: #1b2958;
  border-color: #1b2958;
  border-radius: 0;
  font-weight: 700;
  padding: 0.5rem 2rem;
}

.sagco-mega-see-all:hover {
  background-color: #152044;
  border-color: #152044;
}

@media (max-width: 991.98px) {
  /* Mobile nav: off-canvas sidebar sliding in from the right.
     site.js toggles .sagco-open; .show is kept as a fallback in case
     Bootstrap's collapse handler ever reaches the element. */
  #top_menu_collapse {
    display: block;
    position: fixed;
    top: 0;
    bottom: 0;
    right: 0;
    left: auto;
    width: min(320px, 85vw);
    z-index: 1065;
    background: #fff;
    overflow-y: auto;
    padding: 3rem 0 2rem;
    transform: translateX(105%);
    visibility: hidden;
    transition: transform 0.28s ease, visibility 0.28s;
    box-shadow: -0.5rem 0 2rem rgba(15, 23, 42, 0.18);
  }

  #top_menu_collapse.sagco-open,
  #top_menu_collapse.show {
    transform: translateX(0);
    visibility: visible;
  }

  #top_menu {
    width: 100%;
  }

  #top_menu .nav-link {
    padding: 0.8rem 1.25rem;
  }

  .sagco-nav-rfq-link {
    margin: 0.75rem 1.25rem 0;
    text-align: center;
  }

  /* Sticky so the X stays pinned while the nav list scrolls */
  .sagco-nav-close {
    display: flex;
    align-items: center;
    justify-content: center;
    position: sticky;
    top: 0.4rem;
    z-index: 5;
    margin-inline-start: auto;
    margin-inline-end: 0.6rem;
    margin-top: -1.6rem;
    width: 2.3rem;
    height: 2.3rem;
    font-size: 1.6rem;
    line-height: 1;
    color: #fff;
    background: #1b2958;
    border: 0;
    border-radius: 50%;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.25);
    cursor: pointer;
  }

  .sagco-nav-close:hover {
    background: #9d1631;
  }

  /* Mega submenus inside the sidebar: flat indented text list, no images.
     Unscoped — the collapse is reparented to <body> on mobile. */
  .sagco-mega-dropdown .dropdown-menu {
    position: static !important;
    float: none;
    width: 100%;
    max-height: none;
    overflow: visible;
    box-shadow: none;
    border: 0;
    padding: 0 0 0.25rem;
  }

  .sagco-mega-inner {
    padding: 0;
  }

  .sagco-mega-grid {
    grid-template-columns: 1fr;
    gap: 0;
    margin: 0 1.25rem;
    border-left: 2px solid #e8ecf1;
  }

  .sagco-mega-card {
    border: 0;
    border-radius: 0;
    height: auto;
  }

  .sagco-mega-card:hover,
  .sagco-mega-card:focus {
    box-shadow: none;
    transform: none;
  }

  .sagco-mega-card-img-wrap {
    display: none;
  }

  .sagco-mega-card-title {
    font-size: 0.95rem;
    padding: 0.45rem 0.75rem;
  }

  .sagco-mega-card-link {
    display: none;
  }

  .sagco-mega-card-meta {
    padding: 0 0.75rem 0.45rem;
  }

  .sagco-mega-footer {
    margin: 0.25rem 1.25rem 0;
    padding-top: 0.5rem;
    border-top: 0;
    text-align: left;
  }
}

/* ================= Desktop: horizontal 2-column mega cards =================
   Must come LAST — same specificity as the base rules above. */
@media (min-width: 992px) {
  .sagco-mega-card {
    flex-direction: row;
    align-items: stretch;
  }

  .sagco-mega-card-img-wrap {
    flex: 0 0 118px;
    width: 118px;
    aspect-ratio: auto;
    min-height: 104px;
    align-self: stretch;
  }

  .sagco-mega-card-body {
    display: flex;
    flex: 1 1 auto;
    min-width: 0;
    flex-direction: column;
    justify-content: center;
    padding: 0.65rem 0.9rem;
  }

  .sagco-mega-card-title {
    padding: 0;
    font-size: 0.95rem;
  }

  .sagco-mega-card-meta {
    padding: 0;
    margin-top: 0.1rem;
  }

  .sagco-mega-card-link {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 0.4rem;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #9d1631;
  }

  .sagco-mega-card-link::after {
    content: "";
    width: 0.4rem;
    height: 0.4rem;
    border-top: 2px solid currentColor;
    border-inline-end: 2px solid currentColor;
    transform: rotate(45deg);
    transition: transform 0.2s ease;
  }

  .sagco-mega-card:hover .sagco-mega-card-link::after,
  .sagco-mega-card:focus .sagco-mega-card-link::after {
    transform: rotate(45deg) translate(1px, -1px);
  }
}
