/* ══════════════════════════════════════════════════════════════
   LTD.KIM Drawer / Offcanvas Sidebar
   Owns: #shop-aside, .shop-aside, #drawer-categories, #drawer-filters
   Keep drawer layout here, not in style.css.
   ══════════════════════════════════════════════════════════════ */

/* Hidden by default. header.js injects the aside on every page. */
.shop-aside[data-mode="offcanvas"] {
  display: none;
}

/* Backdrop element injected by header.js. */
.aside-backdrop {
  position: fixed;
  inset: 0;
  z-index: 9998;
  background: rgba(0, 0, 0, .62);
}

/* Hidden attribute must always win. */
.aside-backdrop[hidden] {
  display: none !important;
}

/* Open state. */
body.aside-open {
  overflow: hidden;
}

/* Panel: full viewport height, flex column. */
body.aside-open #shop-aside,
body.aside-open .shop-aside[data-mode="offcanvas"] {
  display: flex !important;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(320px, 88vw);
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  z-index: 9999;

  flex-direction: column;
  min-height: 0;
  overflow: hidden;

  padding: 0;
  margin: 0;
  box-sizing: border-box;

  color: var(--text);
  background: var(--bg-base);
  border-right: 1px solid var(--line);
  box-shadow: 6px 0 30px rgba(0, 0, 0, .72);
}

/* Pearl mode panel. */
[data-theme="pearl"] body.aside-open #shop-aside,
[data-theme="pearl"] body.aside-open .shop-aside[data-mode="offcanvas"] {
  background: var(--bg-surface);
  box-shadow: 6px 0 30px rgba(0, 0, 0, .18);
}

/* Header: fixed-height top area. */
.shop-aside .aside-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;

  padding: calc(.8rem + env(safe-area-inset-top)) .95rem .75rem;
  border-bottom: 1px solid var(--line);
  background: inherit;
}

/* Wordmark. */
.aside-wordmark {
  display: inline-flex;
  align-items: baseline;
  gap: .04rem;
  min-width: 0;

  font-family: var(--font-serif);
  font-size: 1rem;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--gold);
  white-space: nowrap;
}

.aside-wordmark-dot {
  color: var(--text);
}

.aside-wordmark-sub {
  display: inline-block;
  margin-left: .65rem;
  font-family: var(--font-sans);
  font-size: .58rem;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--text-faint);
}

/* Close button inherits base .aside-close from style.css. */
.shop-aside .aside-close {
  flex: 0 0 auto;
}

/* Base section behavior.
   Important: sections do NOT grow by default. Categories grows later. */
.shop-aside .aside-section {
  flex: 0 0 auto;
  min-height: 0;
  padding: .55rem .95rem;
  border-bottom: 1px solid var(--line);
}

/* Section titles. */
.shop-aside .aside-section-title {
  margin: 0 0 .45rem;
  font-size: .62rem;
  line-height: 1.2;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--text-faint);
  font-weight: 600;
}

/* Visual order:
   header -> language -> currency -> filters -> categories
   Categories is last and fills remaining viewport height. */
.shop-aside .aside-head {
  order: 1;
}

.shop-aside .aside-section:has(#drawer-lang) {
  order: 2;
}

.shop-aside .aside-section:has(#drawer-currency) {
  order: 3;
}

.shop-aside .aside-section:has(#drawer-filters) {
  order: 4;
}

.shop-aside .aside-section:has(#drawer-categories) {
  order: 5;
}

/* Language/currency compact inline rows. */
.shop-aside .aside-section:has(> .aside-select) {
  padding: .45rem .95rem;
}

.shop-aside .aside-section:has(> .aside-select) > .aside-section-title {
  display: inline-block;
  width: 4.8rem;
  margin: 0;
  vertical-align: middle;
  font-size: .58rem;
  letter-spacing: .2em;
}

.shop-aside .aside-select {
  display: inline-block;
  width: calc(100% - 5.2rem);
  min-height: 34px;
  vertical-align: middle;

  border: 0;
  border-bottom: 1px solid var(--line-strong);
  border-radius: 0;
  background: transparent;
  color: var(--text);

  padding: .2rem 1.4rem .2rem .15rem;
  font-size: .82rem;
  outline: none;
}

.shop-aside .aside-select:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* Filters:
   Keep filters bounded so they cannot steal the entire drawer height.
   If filters are empty, this stays compact. */
.shop-aside .aside-section:has(#drawer-filters) {
  flex: 0 0 auto;
  min-height: 0;
  max-height: 30vh;
  max-height: 30dvh;
  overflow: hidden;
}

#drawer-filters {
  min-height: 0;
  max-height: calc(30vh - 2.4rem);
  max-height: calc(30dvh - 2.4rem);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;

  display: flex;
  flex-direction: column;
  gap: .35rem;
}

/* Categories:
   This is the section that should consume the remaining sidebar height. */
.shop-aside .aside-section:has(#drawer-categories) {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;

  display: flex;
  flex-direction: column;

  padding-bottom: 0;
  margin-bottom: 0;
  border-bottom: 0;
}

.shop-aside .aside-section:has(#drawer-categories) > .aside-section-title {
  flex: 0 0 auto;
  margin-bottom: .45rem;
}

/* The category list fills the remaining section height and scrolls internally. */
#drawer-categories {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;

  padding-bottom: calc(1rem + env(safe-area-inset-bottom));
  margin-bottom: 0;
}

/* Generic category/filter row styling. */
#drawer-categories a,
#drawer-categories button,
#drawer-filters a,
#drawer-filters button,
.filter-cat-list a,
.filter-cat-list button {
  min-height: 38px;
}

/* If existing category tree uses lists, normalize spacing. */
#drawer-categories ul,
#drawer-filters ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

/* Avoid children forcing flex overflow. */
#shop-aside *,
#drawer-categories *,
#drawer-filters * {
  min-width: 0;
}

/* Mobile touch comfort. */
@media (max-width: 860px), (hover: none) {
  body.aside-open #shop-aside,
  body.aside-open .shop-aside[data-mode="offcanvas"] {
    width: min(340px, 90vw);
  }

  .shop-aside .aside-section {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .shop-aside .aside-select {
    font-size: 16px;
  }

  #drawer-categories a,
  #drawer-categories button,
  #drawer-filters a,
  #drawer-filters button,
  .filter-cat-list a,
  .filter-cat-list button {
    min-height: 44px;
  }
}

/* Narrow screens. */
@media (max-width: 420px) {
  body.aside-open #shop-aside,
  body.aside-open .shop-aside[data-mode="offcanvas"] {
    width: min(330px, 94vw);
  }

  .aside-wordmark {
    font-size: .95rem;
    letter-spacing: .15em;
  }

  .aside-wordmark-sub {
    display: none;
  }

  .shop-aside .aside-section:has(> .aside-select) > .aside-section-title {
    width: 4.4rem;
  }

  .shop-aside .aside-select {
    width: calc(100% - 4.8rem);
  }
}

/* Fallback for browsers without :has().
   The DOM order generated by header.js is:
   head, language, currency, categories, filters.
   Without :has(), keep drawer usable: whole panel scrolls.
   Modern Chrome/Safari/Firefox use the enhanced rules above. */
@supports not selector(:has(*)) {
  body.aside-open #shop-aside,
  body.aside-open .shop-aside[data-mode="offcanvas"] {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .shop-aside .aside-section {
    flex: 0 0 auto;
  }

  #drawer-categories,
  #drawer-filters {
    max-height: none;
    overflow: visible;
  }
}

/* Print never shows drawer. */
@media print {
  .shop-aside,
  .aside-backdrop {
    display: none !important;
  }
}

/* ══════════════════════════════════════════════════════════════
   SHARED CATEGORY TREE IN DRAWER
   The same lazy tree used by /categories.html.
   ══════════════════════════════════════════════════════════════ */

#drawer-categories .cat-tree {
  list-style: none;
  margin: 0;
  padding: 0;
}

#drawer-categories .cat-node {
  list-style: none;
  margin: 0;
  padding: 0;
}

#drawer-categories .cat-row {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) auto;
  align-items: center;
  gap: .35rem;
  min-height: 38px;
  border-bottom: 1px solid rgba(212,175,55,.08);
}

#drawer-categories .cat-toggle,
#drawer-categories .cat-toggle-spacer {
  width: 32px;
  height: 32px;
}

#drawer-categories .cat-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: transparent;
  color: var(--gold);
  font-size: 1rem;
  line-height: 1;
  border-radius: var(--radius);
}

#drawer-categories .cat-toggle:hover {
  background: rgba(212,175,55,.08);
}

#drawer-categories .cat-link {
  display: block;
  min-width: 0;
  padding: .5rem 0;
  color: var(--text);
  font-size: .86rem;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#drawer-categories .cat-link:hover {
  color: var(--gold);
}

#drawer-categories .cat-count {
  min-width: 1.65rem;
  padding: .08rem .38rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text-faint);
  font-size: .66rem;
  line-height: 1.35;
  text-align: center;
}

#drawer-categories .cat-children {
  list-style: none;
  margin: 0;
  padding: 0 0 0 .9rem;
  border-left: 1px solid rgba(212,175,55,.12);
}

#drawer-categories .cat-children[hidden] {
  display: none !important;
}

#drawer-categories .cat-children .cat-link {
  font-size: .82rem;
  color: var(--text-dim);
}

#drawer-categories .loading,
#drawer-categories .error {
  padding: .85rem 0;
  color: var(--text-faint);
  font-size: .85rem;
  line-height: 1.5;
}

@media (max-width: 860px), (hover: none) {
  #drawer-categories .cat-row {
    min-height: 44px;
  }

  #drawer-categories .cat-toggle,
  #drawer-categories .cat-toggle-spacer {
    width: 40px;
    height: 40px;
  }

  #drawer-categories .cat-link {
    padding: .65rem 0;
    font-size: .9rem;
  }
}

