/* ============================================================
   CATEGORY NAVIGATION — department bar, mega menu, mobile drawer
   Markup: Views/Shared/Components/CategoryNav/*  ·  Behaviour: js/category-nav.js
   Classes are prefixed cn- so the older .category-* / .mobile-category-* rules don't apply.
   ============================================================ */

:root {
  --cn-green-900: #0f5c28;
  --cn-green-700: #1d8a43;
  --cn-green-100: #e9f7ee;
  --cn-green-50: #f5fcf7;
  --cn-ink: #13241b;
  --cn-text: #2b3a32;
  --cn-muted: #5f6d66;
  --cn-border: #e3ebe6;
  --cn-radius: 14px;
  --cn-focus: 0 0 0 3px rgba(29, 138, 67, 0.3);
}

/* ---------- Department bar (desktop) ---------- */

/* No z-index on .category-navbar: that would create a stacking context and trap the mobile drawer
   (which lives inside it) beneath the sticky header. The mega menu sets its own z-index. */

.cn-bar {
  position: relative;
  align-items: center;
  gap: 0.75rem;
  min-height: 56px;
}

.cn-all-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  height: 40px;
  padding: 0 0.95rem;
  border: 0;
  border-radius: 10px;
  background: var(--cn-green-700);
  color: #fff;
  font-family: "Manrope", sans-serif;
  font-weight: 800;
  font-size: 0.92rem;
  transition: background-color 0.15s ease;
}

.cn-all-btn:hover,
.cn-all-btn[aria-expanded="true"] {
  background: var(--cn-green-900);
}

.cn-all-btn:focus-visible {
  outline: none;
  box-shadow: var(--cn-focus);
}

.cn-caret {
  font-size: 0.75rem;
  transition: transform 0.2s ease;
}

.cn-all-btn[aria-expanded="true"] .cn-caret {
  transform: rotate(180deg);
}

.cn-departments {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
}

.cn-dept-list {
  display: flex;
  gap: 0.25rem;
  margin: 0;
  padding: 0 0.25rem;
  list-style: none;
  overflow-x: auto;
  scroll-behavior: smooth;
  scrollbar-width: none;
  /* Fade the edge that has more content */
  mask-image: linear-gradient(90deg, transparent 0, #000 var(--cn-fade-start, 0px), #000 calc(100% - var(--cn-fade-end, 0px)), transparent 100%);
}

.cn-dept-list::-webkit-scrollbar {
  display: none;
}

.cn-dept-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  height: 38px;
  padding: 0 0.85rem;
  border-radius: 999px;
  color: var(--cn-text);
  font-weight: 700;
  font-size: 0.9rem;
  white-space: nowrap;
  text-decoration: none;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.cn-dept-link:hover {
  background: var(--cn-green-50);
  color: var(--cn-green-900);
}

.cn-dept-link.is-active {
  background: var(--cn-green-100);
  color: var(--cn-green-900);
}

.cn-dept-link:focus-visible,
.cn-rail-link:focus-visible,
.cn-aisle:focus-visible,
.cn-shelves a:focus-visible,
.cn-see-all:focus-visible,
.cn-row:focus-visible,
.cn-back:focus-visible,
.cn-scroll:focus-visible {
  outline: none;
  box-shadow: var(--cn-focus);
}

.cn-scroll {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--cn-border);
  border-radius: 50%;
  background: #fff;
  color: var(--cn-text);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
}

.cn-scroll:hover {
  border-color: var(--cn-green-700);
  color: var(--cn-green-900);
}

.cn-badge {
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  background: #fff1d6;
  color: #8a5500;
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

/* ---------- Mega menu ---------- */

.cn-mega {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  right: 0;
  z-index: 1035;
  border: 1px solid var(--cn-border);
  border-radius: 0 0 var(--cn-radius) var(--cn-radius);
  background: #fff;
  box-shadow: 0 24px 48px rgba(16, 40, 24, 0.14);
  animation: cn-drop 0.16s ease-out;
}

@keyframes cn-drop {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.cn-mega-inner {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  height: min(560px, 70vh);
}

.cn-rail {
  margin: 0;
  padding: 0.6rem;
  list-style: none;
  overflow-y: auto;
  border-right: 1px solid var(--cn-border);
  background: #fafcfb;
  border-radius: 0 0 0 var(--cn-radius);
  scrollbar-width: thin;
}

.cn-rail-group {
  display: flex;
  margin: 0.6rem 0.5rem 0.3rem;
}

.cn-rail-group:first-child { margin-top: 0.2rem; }

.cn-rail-group a {
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--cn-muted);
  text-decoration: none;
}

.cn-rail-group a:hover { color: var(--cn-green-700); }

.cn-rail-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.5rem 0.6rem;
  border-radius: 10px;
  color: var(--cn-text);
  font-weight: 700;
  font-size: 0.9rem;
  text-decoration: none;
}

.cn-rail-icon {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--cn-green-100);
  color: var(--cn-green-700);
}

.cn-rail-label {
  flex: 1 1 auto;
  min-width: 0;
}

.cn-rail-arrow {
  font-size: 0.75rem;
  color: var(--cn-muted);
  opacity: 0;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.cn-rail-link:hover,
.cn-rail-link.is-current {
  background: #fff;
  color: var(--cn-green-900);
  box-shadow: 0 1px 3px rgba(16, 40, 24, 0.08);
}

.cn-rail-link.is-current .cn-rail-arrow,
.cn-rail-link:hover .cn-rail-arrow {
  opacity: 1;
  transform: translateX(2px);
}

.cn-rail-link.is-current .cn-rail-icon {
  background: var(--cn-green-700);
  color: #fff;
}

.cn-panes {
  min-width: 0;
  overflow-y: auto;
  padding: 1.1rem 1.4rem 1.4rem;
  scrollbar-width: thin;
}

.cn-pane-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 0.75rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--cn-border);
}

.cn-pane-title {
  margin: 0;
  font-family: "Manrope", sans-serif;
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--cn-ink);
}

.cn-see-all {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  border-radius: 6px;
  color: var(--cn-green-700);
  font-weight: 700;
  font-size: 0.88rem;
  text-decoration: none;
  white-space: nowrap;
}

.cn-see-all:hover { text-decoration: underline; }

.cn-columns {
  columns: 3 200px;
  column-gap: 1.75rem;
}

.cn-col {
  break-inside: avoid;
  margin-bottom: 1.15rem;
}

.cn-aisle {
  display: inline-block;
  margin-bottom: 0.35rem;
  border-radius: 6px;
  color: var(--cn-ink);
  font-family: "Manrope", sans-serif;
  font-weight: 800;
  font-size: 0.92rem;
  text-decoration: none;
}

.cn-aisle:hover,
.cn-aisle.is-active { color: var(--cn-green-700); }

.cn-shelves {
  margin: 0;
  padding: 0;
  list-style: none;
}

.cn-shelves a {
  display: inline-block;
  padding: 0.18rem 0;
  border-radius: 4px;
  color: var(--cn-muted);
  font-size: 0.86rem;
  text-decoration: none;
}

.cn-shelves a:hover,
.cn-shelves a.is-active {
  color: var(--cn-green-700);
}

.cn-shelves a.is-active { font-weight: 700; }

.cn-pane-empty {
  color: var(--cn-muted);
}

.cn-pane-empty a {
  color: var(--cn-green-700);
  font-weight: 700;
}

/* ---------- Mobile drawer ---------- */

.cn-drawer {
  --bs-offcanvas-width: min(360px, 88vw);
  display: flex;
  flex-direction: column;
  background: #fff;
}

.cn-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.1rem 0.75rem;
}

.cn-drawer-title {
  margin: 0;
  font-family: "Manrope", sans-serif;
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--cn-ink);
}

.cn-drawer-tools {
  display: grid;
  gap: 0.6rem;
  padding: 0 1.1rem 0.75rem;
  border-bottom: 1px solid var(--cn-border);
}

.cn-drawer-tools .mobile-offcanvas-delivery {
  margin: 0;
}

.cn-search {
  position: relative;
  display: block;
  margin: 0;
}

.cn-search .bi {
  position: absolute;
  left: 0.8rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--cn-muted);
}

.cn-search input {
  width: 100%;
  height: 42px;
  padding: 0 0.8rem 0 2.2rem;
  border: 1.5px solid var(--cn-border);
  border-radius: 10px;
  font-size: 0.92rem;
}

.cn-search input:focus {
  outline: none;
  border-color: var(--cn-green-700);
  box-shadow: var(--cn-focus);
}

.cn-search-results {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0.5rem 0.6rem 1rem;
}

.cn-search-results ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.cn-search-result {
  display: block;
  padding: 0.6rem 0.7rem;
  border-radius: 10px;
  color: var(--cn-ink);
  text-decoration: none;
}

.cn-search-result:hover,
.cn-search-result:focus-visible {
  background: var(--cn-green-50);
  outline: none;
}

.cn-search-result strong { display: block; font-weight: 700; }
.cn-search-result mark { padding: 0; background: #fff1b8; color: inherit; }
.cn-search-result small { color: var(--cn-muted); font-size: 0.76rem; }

.cn-search-empty {
  padding: 1rem 0.7rem;
  color: var(--cn-muted);
  font-size: 0.9rem;
}

.cn-panels {
  position: relative;
  flex: 1 1 auto;
  overflow: hidden;
}

.cn-panel {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  padding: 0.5rem 0.6rem 1.25rem;
  background: #fff;
  transition: transform 0.24s ease, opacity 0.24s ease;
}

.cn-panel[hidden] { display: none; }

/* JS adds these for the slide animation */
.cn-panel.is-entering-forward { transform: translateX(100%); }
.cn-panel.is-entering-back { transform: translateX(-30%); opacity: 0; }

.cn-panel-group {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 0.75rem 0.6rem 0.3rem;
}

.cn-panel-group h3 {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--cn-muted);
}

.cn-panel-group a {
  color: var(--cn-green-700);
  font-weight: 700;
  font-size: 0.8rem;
  text-decoration: none;
}

.cn-panel-head {
  position: sticky;
  top: -0.5rem;
  z-index: 1;
  margin: -0.5rem -0.6rem 0.4rem;
  padding: 0.6rem 1rem 0.65rem;
  background: #fff;
  border-bottom: 1px solid var(--cn-border);
}

.cn-back {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0 0 0.15rem -0.35rem;
  padding: 0.25rem 0.35rem;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--cn-green-700);
  font-weight: 700;
  font-size: 0.84rem;
}

.cn-back:hover { background: var(--cn-green-50); }

.cn-panel-title {
  margin: 0;
  font-family: "Manrope", sans-serif;
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--cn-ink);
  outline: none;
}

.cn-rows {
  margin: 0;
  padding: 0;
  list-style: none;
}

.cn-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  min-height: 48px;
  padding: 0.45rem 0.6rem;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--cn-text);
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  text-align: left;
  text-decoration: none;
}

.cn-row:hover,
.cn-row:active {
  background: var(--cn-green-50);
  color: var(--cn-green-900);
}

.cn-row.is-active {
  color: var(--cn-green-900);
  font-weight: 800;
}

.cn-row.is-active .cn-row-icon {
  background: var(--cn-green-700);
  color: #fff;
}

.cn-row-icon {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--cn-green-100);
  color: var(--cn-green-700);
  font-size: 1rem;
}

.cn-row-label {
  flex: 1 1 auto;
  min-width: 0;
}

.cn-row-arrow {
  flex: 0 0 auto;
  color: var(--cn-muted);
  font-size: 0.85rem;
}

.cn-row--all {
  margin-bottom: 0.25rem;
  color: var(--cn-green-700);
  font-weight: 800;
}

.cn-row--all .cn-row-arrow { color: var(--cn-green-700); }

/* Loading / error states while the drawer panels are fetched */
.cn-loading {
  padding: 0.75rem 0.9rem;
}

.cn-skeleton-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  height: 48px;
}

.cn-skeleton-icon,
.cn-skeleton-text {
  border-radius: 10px;
  background: linear-gradient(90deg, #eef4f0 25%, #f7faf8 50%, #eef4f0 75%);
  background-size: 200% 100%;
  animation: cn-shimmer 1.2s infinite linear;
}

.cn-skeleton-icon { width: 36px; height: 36px; flex: 0 0 auto; }
.cn-skeleton-text { height: 12px; flex: 0 1 60%; }
.cn-skeleton-row:nth-child(2n) .cn-skeleton-text { flex-basis: 45%; }

@keyframes cn-shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

.cn-load-error {
  padding: 1.5rem 1.1rem;
  text-align: center;
  color: var(--cn-muted);
}

.cn-load-error p { margin-bottom: 0.75rem; }

.cn-retry {
  display: block;
  margin: 0 auto 0.6rem;
  padding: 0.5rem 1.1rem;
  border: 0;
  border-radius: 10px;
  background: var(--cn-green-700);
  color: #fff;
  font-weight: 700;
}

.cn-load-error a {
  color: var(--cn-green-700);
  font-weight: 700;
}

@media (prefers-reduced-motion: reduce) {
  .cn-skeleton-icon, .cn-skeleton-text { animation: none; }
  .cn-mega { animation: none; }
  .cn-panel, .cn-caret, .cn-rail-arrow { transition: none; }
  .cn-dept-list { scroll-behavior: auto; }
}
