/* ==========================================================================
   NEENANDBIA — Top-Layer Drawers (Menu, Search, Shopping Bag)
   Built with native modal <dialog>, scroll-snap swipe, & overscroll containment
   ========================================================================== */

dialog.nb-drawer {
  --drawer-width: min(440px, 88dvw);
  --drawer-backdrop: 0;

  inset: 0;
  width: auto;
  height: auto;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  background: transparent;
  border: 0;
  overflow: visible;
  overscroll-behavior: contain;
}

dialog.nb-drawer:not([open]) {
  display: none;
}

dialog.nb-drawer::backdrop {
  background: var(--color-surface-base);
  opacity: calc(var(--drawer-backdrop) * 0.55);
  overflow: hidden;
  overscroll-behavior: contain;
}

/* Fallback transition when scroll-driven animations aren't used */
.nb-drawer-scroller {
  position: relative;
  display: grid;
  width: 100%;
  height: 100svh;
  overflow-x: scroll;
  overflow-y: hidden;
  overscroll-behavior: none;
  scrollbar-width: none;
  scroll-snap-type: x mandatory;
}

.nb-drawer-scroller::-webkit-scrollbar {
  display: none;
}

@media (prefers-reduced-motion: no-preference) {
  .nb-drawer-scroller {
    scroll-behavior: smooth;
  }
}

/* LEFT DRAWER (Menu) */
.nb-drawer--left .nb-drawer-scroller {
  grid-template-columns: var(--drawer-width) 100%;
}

.nb-drawer--left .nb-drawer-sheet {
  grid-column: 1;
  scroll-snap-align: start;
}

.nb-drawer--left .nb-drawer-spacer {
  grid-column: 2;
  scroll-snap-align: end;
  scroll-initial-target: nearest;
}

/* RIGHT DRAWER (Search & Shopping Bag) */
.nb-drawer--right {
  --drawer-width: min(460px, 90dvw);
}

.nb-drawer--right .nb-drawer-scroller {
  grid-template-columns: 100% var(--drawer-width);
}

.nb-drawer--right .nb-drawer-spacer {
  grid-column: 1;
  scroll-snap-align: start;
  scroll-initial-target: nearest;
}

.nb-drawer--right .nb-drawer-sheet {
  grid-column: 2;
  scroll-snap-align: end;
}

/* Scroll-driven backdrop opacity sync (gated behind @supports) */
@supports (animation-timeline: scroll()) {
  @property --drawer-backdrop {
    syntax: '<number>';
    inherits: true;
    initial-value: 0;
  }

  .nb-drawer {
    timeline-scope: --drawer-fade;
    animation-timeline: --drawer-fade;
  }

  .nb-drawer-scroller {
    scroll-timeline: --drawer-fade x;
  }

  .nb-drawer--left {
    animation: nb-drawer-fade-left linear both;
    animation-timeline: --drawer-fade;
  }

  .nb-drawer--right {
    animation: nb-drawer-fade-right linear both;
    animation-timeline: --drawer-fade;
  }

  @keyframes nb-drawer-fade-left {
    0% { --drawer-backdrop: 1; }
    100% { --drawer-backdrop: 0; }
  }

  @keyframes nb-drawer-fade-right {
    0% { --drawer-backdrop: 0; }
    100% { --drawer-backdrop: 1; }
  }
}

/* Drawer Sheet Container */
.nb-drawer-sheet {
  display: flex;
  flex-direction: column;
  height: 100svh;
  background: var(--color-surface-page);
  color: var(--color-text-primary);
  overflow-y: auto;
  overscroll-behavior-y: contain;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
}

.nb-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-8) var(--space-9);
  border-bottom: 1px solid var(--color-border-subtle);
  flex-shrink: 0;
}

.nb-drawer-header--borderless {
  border-bottom: none;
  padding-bottom: var(--space-4);
}

.nb-drawer-title {
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-medium);
  letter-spacing: var(--letter-spacing-wider);
  text-transform: uppercase;
  margin: 0;
  color: var(--color-text-primary);
}

.nb-drawer-brand {
  font-size: clamp(20px, 2vw, 25px);
  font-weight: var(--font-weight-bold);
  letter-spacing: var(--letter-spacing-brand);
  text-transform: uppercase;
  color: var(--color-text-primary);
  text-decoration: none;
  line-height: 1;
}

.nb-drawer-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  min-height: 36px;
  padding: var(--space-4);
  background: transparent;
  border: 0;
  color: var(--color-text-primary);
  cursor: pointer;
  transition: opacity var(--motion-duration-instant) ease;
}

.nb-drawer-close:hover {
  opacity: 0.6;
}

.nb-drawer-close:focus-visible {
  outline: 2px solid var(--color-focus-ring);
  outline-offset: 2px;
}

.nb-drawer-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: var(--space-6) var(--space-9);
}

/* ---- MENU DRAWER SPECIFICS ---- */
.nb-menu-tabs {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  padding: 0 var(--space-9) var(--space-6);
  border-bottom: 1px solid var(--color-border-subtle);
}

.nb-menu-tab {
  position: relative;
  background: transparent;
  border: 0;
  padding: var(--space-4) 0;
  font-family: inherit;
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  letter-spacing: var(--letter-spacing-wide);
  text-transform: uppercase;
  color: var(--color-text-secondary);
  cursor: pointer;
}

.nb-menu-tab[aria-selected="true"] {
  color: var(--color-text-primary);
  font-weight: var(--font-weight-semibold);
}

.nb-menu-tab[aria-selected="true"]::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  border-block-end: 2px solid var(--color-text-primary);
}

.nb-menu-tab:focus-visible {
  outline: 2px solid var(--color-focus-ring);
  outline-offset: 4px;
}

.nb-menu-list {
  list-style: none;
  margin: 0;
  padding: var(--space-6) 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.nb-menu-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) 0;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-base);
  letter-spacing: var(--letter-spacing-wide);
  text-transform: uppercase;
  color: var(--color-text-inverse);
  text-decoration: none;
  transition: opacity var(--motion-duration-instant) ease, transform var(--motion-duration-instant) ease;
}

.nb-menu-link:hover {
  opacity: 0.65;
  transform: translateX(4px);
}

.nb-menu-link--highlight {
  font-weight: var(--font-weight-bold);
  color: var(--color-text-primary);
}

.nb-menu-footer {
  padding: var(--space-6) var(--space-9);
  border-top: 1px solid var(--color-border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-5);
  flex-shrink: 0;
}

.nb-menu-account-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-4);
  background: transparent;
  border: 0;
  padding: var(--space-4) 0;
  font-family: inherit;
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  letter-spacing: var(--letter-spacing-wide);
  text-transform: uppercase;
  color: var(--color-text-primary);
  cursor: pointer;
}

.nb-menu-account-btn:hover {
  opacity: 0.7;
}

.nb-region-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-4);
  background: transparent;
  border: 0;
  font-family: inherit;
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  letter-spacing: var(--letter-spacing-wide);
  text-transform: uppercase;
  color: var(--color-text-secondary);
  cursor: pointer;
  padding: var(--space-4);
}

.nb-region-btn:hover {
  color: var(--color-text-primary);
}

/* ---- SEARCH DRAWER SPECIFICS ---- */
.nb-search-bar-wrap {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-7) var(--space-8);
  border-bottom: 1px solid var(--color-border-subtle);
  flex-shrink: 0;
}

.nb-search-input-box {
  position: relative;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
}

.nb-search-input {
  width: 100%;
  height: 40px;
  padding: 0 38px 0 var(--space-6);
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: var(--font-size-sm);
  color: var(--color-text-primary);
  background: var(--color-surface-page);
}

.nb-search-input:focus {
  outline: 2px solid var(--color-focus-ring);
  outline-offset: -1px;
  border-color: var(--color-text-primary);
}

.nb-search-input-icon {
  position: absolute;
  right: 12px;
  color: var(--color-text-secondary);
  pointer-events: none;
  display: inline-flex;
}

.nb-search-section-title {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-primary);
  margin: var(--space-6) 0 var(--space-5);
}

.nb-search-suggestions {
  list-style: none;
  margin: 0 0 var(--space-8);
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.nb-search-suggestion-btn {
  background: transparent;
  border: 0;
  padding: var(--space-2) 0;
  font-family: inherit;
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  cursor: pointer;
  text-align: left;
  transition: color var(--motion-duration-instant) ease;
}

.nb-search-suggestion-btn:hover {
  color: var(--color-text-primary);
  text-decoration: underline;
}

.nb-search-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-6);
  padding-bottom: var(--space-8);
}

.nb-search-card {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}

.nb-search-card-img-wrap {
  aspect-ratio: 3 / 4;
  background: var(--color-surface-card);
  overflow: hidden;
  margin-bottom: var(--space-4);
}

.nb-search-card-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform var(--motion-duration-fast) var(--motion-ease-standard);
}

.nb-search-card:hover .nb-search-card-img {
  transform: scale(1.03);
}

.nb-search-card-title {
  font-size: 11px;
  font-weight: var(--font-weight-medium);
  letter-spacing: var(--letter-spacing-tight);
  text-transform: uppercase;
  line-height: 1.35;
  color: var(--color-text-primary);
  margin: 0 0 var(--space-2);
}

.nb-search-card-price {
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
  margin: 0;
}

.nb-search-empty {
  padding: var(--space-10) 0;
  text-align: center;
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
}

/* ---- SHOPPING BAG / CART DRAWER SPECIFICS ---- */
.nb-cart-items {
  display: flex;
  flex-direction: column;
  gap: var(--space-7);
}

.nb-cart-empty {
  padding: var(--space-11) var(--space-6);
  text-align: center;
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
}

.nb-cart-item {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: var(--space-6);
  padding-bottom: var(--space-7);
  border-bottom: 1px solid var(--color-border-subtle);
}

.nb-cart-item-img {
  width: 88px;
  height: 112px;
  object-fit: cover;
  background: var(--color-surface-card);
  display: block;
}

.nb-cart-item-info {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.nb-cart-item-title {
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  letter-spacing: var(--letter-spacing-tight);
  text-transform: uppercase;
  color: var(--color-text-primary);
  margin: 0;
  line-height: 1.4;
}

.nb-cart-item-meta {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  margin: 0;
}

.nb-cart-item-price {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-primary);
  margin: var(--space-1) 0;
}

.nb-cart-item-stock {
  font-size: 11px;
  font-weight: var(--font-weight-medium);
  color: var(--color-text-success);
  margin: 0 0 var(--space-3);
}

.nb-cart-qty-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-5);
  margin-top: var(--space-2);
}

.nb-cart-qty-controls {
  display: inline-flex;
  align-items: center;
  gap: var(--space-5);
}

.nb-qty-btn {
  width: 26px;
  height: 26px;
  border-radius: var(--radius-pill);
  border: 0;
  background: var(--color-surface-base);
  color: var(--color-text-tertiary);
  font-size: 14px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: opacity var(--motion-duration-instant) ease;
}

.nb-qty-btn:hover {
  opacity: 0.78;
}

.nb-qty-val {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  min-width: 18px;
  text-align: center;
}

.nb-cart-item-actions {
  display: flex;
  align-items: center;
  gap: var(--space-5);
}

.nb-cart-icon-btn {
  background: transparent;
  border: 0;
  padding: var(--space-2);
  color: var(--color-text-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.nb-cart-icon-btn:hover {
  color: var(--color-text-primary);
}

.nb-cart-footer {
  padding: var(--space-7) var(--space-8) var(--space-8);
  border-top: 1px solid var(--color-border-subtle);
  background: var(--color-surface-page);
  flex-shrink: 0;
}

.nb-cart-subtotal-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-6);
}

.nb-cart-subtotal-label {
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-medium);
  letter-spacing: var(--letter-spacing-wide);
  text-transform: uppercase;
}

.nb-cart-subtotal-value {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
}

.nb-cart-btn-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.nb-btn-dark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 44px;
  padding: 0 var(--space-6);
  background: var(--color-text-inverse);
  color: var(--color-text-tertiary);
  border: 1px solid var(--color-text-inverse);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  letter-spacing: var(--letter-spacing-wider);
  text-transform: uppercase;
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--motion-duration-instant) ease, opacity var(--motion-duration-instant) ease;
}

.nb-btn-dark:hover {
  background: var(--color-surface-base);
}

.nb-btn-dark:focus-visible {
  outline: 2px solid var(--color-focus-ring);
  outline-offset: 2px;
}

@media (max-width: 640px) {
  dialog.nb-drawer {
    --drawer-width: min(340px, 86dvw);
  }
  .nb-drawer--right {
    --drawer-width: min(360px, 92dvw);
  }
  .nb-drawer-header {
    padding: var(--space-6) var(--space-7);
  }
  .nb-drawer-brand {
    font-size: 18px;
    letter-spacing: 0.2em;
  }
  .nb-drawer-body {
    padding: var(--space-5) var(--space-7);
  }
  .nb-menu-tabs {
    padding: 0 var(--space-7) var(--space-4);
    gap: var(--space-6);
  }
  .nb-menu-footer {
    padding: var(--space-5) var(--space-7);
    flex-wrap: wrap;
  }
  .nb-search-bar-wrap {
    padding: var(--space-5) var(--space-6);
  }
  .nb-cart-footer {
    padding: var(--space-6) var(--space-7);
  }
}
