/* ============================================================
   Layout — navigation, sidebars, containers, grids
   ============================================================ */

/* ── CONTAINER ─────────────────────────────────── */
.container {
  max-width: var(--container-xl);
  margin: 0 auto;
  padding: 0 var(--s-6);
}
.container--sm  { max-width: var(--container-sm); }
.container--md  { max-width: var(--container-md); }
.container--lg  { max-width: var(--container-lg); }
.container--xl  { max-width: var(--container-xl); }
.container--2xl { max-width: var(--container-2xl); }

/* ── MAIN NAV ──────────────────────────────────── */
.nav {
  position: sticky;
  top: 0;
  left: 0;
  right: 0;
  z-index: var(--z-sticky);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem var(--s-6);
  background: rgba(245, 240, 232, 0.97);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  min-height: var(--nav-height);
}
.nav.is-scrolled {
  box-shadow: var(--shadow-sm);
}

.nav-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--ink);
  font-family: var(--font-kaiti);
  font-size: 1.2rem;
  font-weight: 400;
  text-decoration: none;
  letter-spacing: 0.06em;
}
.nav-brand-en {
  display: block;
  font-family: var(--font-body);
  font-size: 0.56rem;
  letter-spacing: 0.25em;
  font-weight: 400;
  color: var(--stone);
  text-transform: uppercase;
  margin-top: 2px;
}
.nav-brand-mark {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  display: block;
}
.nav-brand-text {
  display: inline-flex;
  flex-direction: column;
  line-height: 1.1;
}

.nav-menu {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}
.nav-link {
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: 300;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--stone);
  transition: color var(--dur-fast) var(--ease-out);
  cursor: pointer;
  background: none;
  border: none;
  padding: 0.5rem 0;
  text-decoration: none;
}
.nav-link:hover,
.nav-link.is-active {
  color: var(--ink);
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: var(--s-3);
}

.nav-toggle {
  display: none;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--ink);
  cursor: pointer;
}
.nav-toggle-icon,
.nav-toggle-icon::before,
.nav-toggle-icon::after {
  display: block;
  width: 20px;
  height: 2px;
  background: currentColor;
  position: relative;
  transition: transform var(--dur-base) var(--ease-out);
}
.nav-toggle-icon::before,
.nav-toggle-icon::after {
  content: "";
  position: absolute;
  left: 0;
}
.nav-toggle-icon::before { top: -6px; }
.nav-toggle-icon::after  { top: 6px; }

/* Morph to X when open */
.nav.is-open .nav-toggle-icon { background: transparent; }
.nav.is-open .nav-toggle-icon::before { transform: translateY(6px) rotate(45deg); }
.nav.is-open .nav-toggle-icon::after  { transform: translateY(-6px) rotate(-45deg); }

/* Mobile nav — drop-down sheet from the top */
@media (max-width: 768px) {
  .nav-toggle { display: flex; }
  .nav {
    /* allow the menu to overflow below the nav bar */
    position: relative;
  }
  .nav-menu {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--cream);
    flex-direction: column;
    align-items: stretch;
    padding: var(--s-4) var(--s-5);
    gap: 0;
    border-top: 1px solid var(--border);
    box-shadow: 0 8px 20px rgba(26, 22, 18, 0.08);
    z-index: 200;
    /* Hidden by default — smooth slide */
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: max-height var(--dur-base) var(--ease-out),
                opacity var(--dur-base) var(--ease-out),
                padding var(--dur-base) var(--ease-out);
    pointer-events: none;
  }
  .nav.is-open .nav-menu {
    max-height: calc(100vh - var(--nav-height));
    opacity: 1;
    pointer-events: auto;
    padding: var(--s-4) var(--s-5);
    overflow-y: auto;
  }
  .nav-menu > li {
    width: 100%;
    border-bottom: 1px solid var(--border);
  }
  .nav-menu > li:last-child { border-bottom: none; }
  .nav-link {
    display: block;
    font-size: var(--text-base);
    padding: var(--s-3) 0;
    width: 100%;
  }

  /* Mobile dropdown (Home → About/Services/Contact) expands inline */
  .nav-dropdown-menu {
    position: static !important;
    opacity: 1 !important;
    visibility: visible !important;
    transform: none !important;
    box-shadow: none !important;
    border: none !important;
    padding: 0 0 var(--s-3) var(--s-4) !important;
    margin: 0 !important;
    background: transparent !important;
  }
  .nav-caret { display: none; }

  /* Language switcher + cart badge alignment */
  .nav-menu .lang-switcher,
  .nav-menu #nav-cart,
  .nav-menu #nav-auth-slot { padding: var(--s-3) 0; }
}

/* ── PORTAL LAYOUT (two-column with sidebar) ─── */
.portal-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: calc(100vh - var(--nav-height));
}

.sidebar {
  background: var(--ink);
  color: rgba(245, 240, 232, 0.7);
  padding: var(--s-6) var(--s-3);
  position: sticky;
  top: var(--nav-height);
  height: calc(100vh - var(--nav-height));
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}

.sidebar-user {
  text-align: center;
  padding: var(--s-4) var(--s-3);
  margin-bottom: var(--s-3);
  border-bottom: 1px solid rgba(245, 240, 232, 0.1);
}
.sidebar-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--washi);
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 1.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto var(--s-2);
}
.sidebar-name {
  font-family: var(--font-zh);
  font-size: var(--text-base);
  color: var(--washi);
  margin-bottom: 2px;
}
.sidebar-sub {
  font-family: var(--font-body);
  font-size: 0.6rem;
  letter-spacing: 0.15em;
  color: rgba(245, 240, 232, 0.5);
}

.sidebar-section {
  padding: var(--s-3) var(--s-3) var(--s-1);
}
.sidebar-label {
  font-family: var(--font-body);
  font-size: 0.54rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: rgba(245, 240, 232, 0.35);
}
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.7rem 1rem;
  background: none;
  border: none;
  border-radius: var(--r-md);
  font-family: var(--font-body);
  font-size: var(--text-xs);
  letter-spacing: 0.08em;
  color: rgba(245, 240, 232, 0.55);
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease-out);
  text-align: left;
  text-decoration: none;
}
.sidebar-link:hover {
  background: rgba(245, 240, 232, 0.06);
  color: var(--washi);
}
.sidebar-link.is-active {
  background: rgba(184, 150, 90, 0.15);
  color: var(--gold);
}
.sidebar-link-icon {
  font-size: 1rem;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}
.sidebar-link-label {
  flex: 1;
}
.sidebar-link-badge {
  background: var(--red-seal);
  color: var(--washi);
  font-size: 0.6rem;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  padding: 0 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.sidebar-divider {
  height: 1px;
  background: rgba(245, 240, 232, 0.1);
  margin: var(--s-3) var(--s-3);
}

/* Main content area */
.main {
  padding: var(--s-8) var(--s-6);
  min-width: 0; /* allow shrinking */
}

.page-header {
  margin-bottom: var(--s-6);
  padding-bottom: var(--s-4);
  border-bottom: 1px solid var(--border);
}
.page-header-label {
  font-family: var(--font-body);
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-widest);
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: var(--s-2);
}
.page-title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: var(--text-3xl);
  line-height: 1.2;
  margin-bottom: var(--s-1);
}
.page-subtitle {
  font-family: var(--font-zh);
  font-size: var(--text-lg);
  color: var(--stone);
  font-weight: 300;
}

/* ──────────────────────────────────────────────────────────────
   Mobile: sidebar becomes a slide-in drawer with a hamburger toggle
   and a backdrop. Menu items stay full-width with labels visible —
   no more horizontal squeeze of 14 links jammed into one bottom bar.
   ────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .portal-layout {
    grid-template-columns: 1fr;
  }
  /* Hidden by default; slides in from the left when .is-open is set. */
  .sidebar {
    position: fixed;
    /* Cover from the very top of the viewport down. Previously top
       was set to nav-height, which on mobile (where .nav uses
       position:relative and scrolls away) left a thin transparent
       gap above the drawer that read as a black bar against the
       page background. */
    top: 0;
    bottom: 0;
    left: 0;
    width: 82vw;
    max-width: 320px;
    /* Use 100dvh (dynamic viewport height) so URL-bar collapse on
       mobile browsers doesn't make the drawer taller than the
       visible area. Falls back to 100vh on older browsers. */
    height: 100vh;
    height: 100dvh;
    padding: var(--s-5) var(--s-3);
    /* Extra top padding for the device safe-area / status bar, and
       extra bottom padding so the last item (Sign Out) clears any
       home-indicator overlay and stays scrollable into view. */
    padding-top: calc(var(--s-5) + env(safe-area-inset-top, 0px));
    padding-bottom: calc(var(--s-8) + env(safe-area-inset-bottom, 0px));
    gap: var(--s-1);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    overflow-x: hidden;
    z-index: 1200;
    transform: translateX(-100%);
    transition: transform 220ms cubic-bezier(.4, 0, .2, 1);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.25);
    scrollbar-width: thin;
  }
  .sidebar.is-open {
    transform: translateX(0);
  }

  /* Full user card + section labels stay visible in the drawer */
  .sidebar-user {
    display: block;
    padding: var(--s-3) var(--s-2) var(--s-4);
  }
  .sidebar-section {
    display: block;
    padding: var(--s-3) var(--s-2) var(--s-1);
  }
  .sidebar-divider {
    display: block;
  }

  /* Menu items get proper size & readable labels */
  .sidebar-link {
    flex-direction: row;
    gap: 0.75rem;
    padding: 0.85rem 0.85rem;
    min-width: 0;
    font-size: 0.8rem;
    text-align: left;
    white-space: normal;
    letter-spacing: 0.04em;
    line-height: 1.3;
  }
  .sidebar-link-icon {
    font-size: 1.2rem;
    width: 24px;
  }
  .sidebar-link-label {
    font-size: 0.8rem;
    letter-spacing: 0.04em;
  }

  /* Backdrop shown when drawer is open */
  .sidebar-backdrop {
    display: none;
    position: fixed;
    /* Cover the whole viewport including the nav row, matching the
       drawer's top:0 — otherwise a sliver of the page nav stayed
       visible above the dim layer. */
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1100;
    opacity: 0;
    transition: opacity 220ms ease;
  }
  /* (Earlier: body:has(.sidebar.is-open) .nav { z-index: 1 } —
     removed because :has() was suspected of triggering an extra
     stacking-context paint that showed as a thin dark line at the
     top of the viewport on desktop. Drawer z-index 1200 + backdrop
     z-index 1100 already overlay the nav z-index of 100.) */
  .sidebar-backdrop.is-visible {
    display: block;
    opacity: 1;
  }

  /* Hamburger toggle button (injected into top-nav by portal-menu.js) */
  .portal-menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    background: none;
    color: var(--ink);
    cursor: pointer;
    padding: 0;
    margin-right: 4px;
    position: relative;
  }
  .portal-menu-btn svg { width: 22px; height: 22px; }
  .portal-menu-btn-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    min-width: 9px;
    height: 9px;
    background: var(--red-seal);
    border-radius: 50%;
    display: none;
  }
  .portal-menu-btn-badge.is-visible { display: block; }

  .main {
    padding: var(--s-4);
    padding-bottom: var(--s-5);
  }
}

/* Hamburger + backdrop only appear on mobile */
@media (min-width: 769px) {
  .portal-menu-btn,
  .sidebar-backdrop {
    display: none !important;
  }
  /* Sign Out + Language toggle live in the top nav on desktop, so
     hide their sidebar duplicates. They stay visible on mobile
     where the top nav collapses behind a hamburger. */
  .sidebar-mobile-only {
    display: none !important;
  }
}

/* ── SECTION ───────────────────────────────────── */
.section {
  padding: var(--s-16) 0;
}
.section--sm { padding: var(--s-8) 0; }
.section--lg { padding: var(--s-24) 0; }

.section-header {
  text-align: center;
  margin-bottom: var(--s-8);
}
.section-label {
  font-family: var(--font-body);
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-widest);
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: var(--s-2);
}
.section-title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: var(--text-3xl);
}

/* ── STATS GRID ────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--s-3);
}
.stat-card {
  background: var(--washi);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--s-5);
  text-align: center;
}
.stat-number {
  font-family: var(--font-display);
  font-size: var(--text-3xl);
  font-weight: 400;
  color: var(--ink);
  line-height: 1;
}
.stat-label {
  font-family: var(--font-body);
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--stone);
  margin-top: var(--s-2);
}

/* ── FOOTER ────────────────────────────────────── */
.footer {
  background: var(--ink);
  color: rgba(245, 240, 232, 0.7);
  padding: var(--s-12) var(--s-6) var(--s-6);
  margin-top: var(--s-16);
}
.footer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--s-8);
  max-width: var(--container-xl);
  margin: 0 auto var(--s-8);
}
.footer-heading {
  font-family: var(--font-body);
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: var(--s-4);
}
.footer-links {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}
.footer-link {
  color: rgba(245, 240, 232, 0.65);
  font-size: var(--text-sm);
  text-decoration: none;
  transition: color var(--dur-fast) var(--ease-out);
}
.footer-link:hover {
  color: var(--gold);
}
.footer-bottom {
  max-width: var(--container-xl);
  margin: 0 auto;
  padding-top: var(--s-6);
  border-top: 1px solid rgba(245, 240, 232, 0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: var(--text-xs);
  color: rgba(245, 240, 232, 0.5);
  flex-wrap: wrap;
  gap: var(--s-3);
}

/* ── EMERGENCY / DISCLAIMER BANNER ─────────────── */
.emergency-banner {
  background: rgba(192, 57, 43, 0.08);
  border-left: 4px solid var(--red-seal);
  padding: var(--s-4) var(--s-6);
  border-radius: var(--r-md);
  margin: var(--s-6) 0;
}
.emergency-banner-title {
  font-weight: 500;
  color: var(--red-seal);
  font-size: var(--text-sm);
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
  margin-bottom: var(--s-1);
}
.emergency-banner-text {
  font-size: var(--text-sm);
  color: var(--stone);
  line-height: var(--leading-relaxed);
}
