/**
 * Wasan Elite Beauty — layout polish
 * Fixes sidebar scroll (flex overflow), viewport precision (dvh + safe-area),
 * and smooth/reliable navigation scrolling without structural regressions.
 */

/* ── Viewport / shell precision ─────────────────────────────── */
html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html,
body {
  min-height: 100%;
  min-height: 100dvh;
}

body {
  overflow-x: hidden;
}

#root {
  min-height: 100%;
  min-height: 100dvh;
}

.layout {
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
  max-width: 100%;
  overflow-x: clip;
}

.main-content {
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 100%;
  min-width: 0;
  overflow-x: clip;
  box-sizing: border-box;
}

.page-content {
  min-width: 0;
  box-sizing: border-box;
}

/* ── Sidebar: fixed height shell so nav can scroll ──────────── */
.sidebar {
  top: 0;
  bottom: 0;
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  min-height: 0 !important;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-inline-end: env(safe-area-inset-right, 0px);
}

.sidebar-header,
.sidebar-footer {
  flex: 0 0 auto;
}

/* Critical: min-height:0 lets flex child shrink and activate overflow */
.sidebar-nav {
  flex: 1 1 auto;
  min-height: 0;
  max-height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  scrollbar-gutter: stable;
  padding-inline-end: 4px;
  touch-action: pan-y;
}

/* ── Custom scrollbar (Firefox + Chromium) ──────────────────── */
.sidebar-nav {
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--gold) 55%, transparent) transparent;
}

.sidebar-nav::-webkit-scrollbar {
  width: 6px;
}

.sidebar-nav::-webkit-scrollbar-track {
  background: transparent;
  margin-block: 8px;
}

.sidebar-nav::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--gold) 45%, transparent);
  border-radius: 999px;
  border: 1px solid transparent;
  background-clip: padding-box;
  transition: background 0.2s ease;
}

.sidebar-nav:hover::-webkit-scrollbar-thumb,
.sidebar-nav:focus-within::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--gold) 75%, transparent);
}

.sidebar-nav::-webkit-scrollbar-thumb:active {
  background: var(--gold);
}

/* Fallback when color-mix unsupported */
@supports not (background: color-mix(in srgb, #d4af37 50%, transparent)) {
  .sidebar-nav {
    scrollbar-color: #d4af378c transparent;
  }

  .sidebar-nav::-webkit-scrollbar-thumb {
    background: #d4af3773;
  }

  .sidebar-nav:hover::-webkit-scrollbar-thumb,
  .sidebar-nav:focus-within::-webkit-scrollbar-thumb {
    background: #d4af37bf;
  }
}

/* Keep nav items from causing horizontal jitter while scrolling */
.sidebar-nav .nav-item {
  flex-shrink: 0;
  max-width: 100%;
  box-sizing: border-box;
}

/* ── Responsive precision ───────────────────────────────────── */
@media (max-width: 1100px) {
  :root {
    --sidebar-width: 240px;
  }
}

@media (max-width: 768px) {
  :root {
    --sidebar-width: min(280px, 86vw);
  }

  .sidebar {
    height: 100%;
    max-height: 100%;
    /* fill fixed inset via top/bottom already set */
  }

  .page-content {
    padding: 16px;
  }
}

@media (max-width: 480px) {
  .page-content {
    padding: 12px;
  }
}

/* Prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
  .sidebar-nav {
    scroll-behavior: auto;
  }

  .sidebar-nav .nav-item {
    transition: none;
  }
}
