/* Self-contained navigation sidebar. No dependencies; see README.md.
   Theme it from the host page with --sb-accent, --sb-panel, --sb-text, --sb-font.
   Without them it falls back to the host's --accent, --color-panel,
   --color-text-primary and --font-subtitle, then to built-in defaults. */

.sidebar,
.sidebar-toggle {
  --_accent: var(--sb-accent, var(--accent, #c983d7));
  --_panel: var(--sb-panel, var(--color-panel, #222226));
  --_text: var(--sb-text, var(--color-text-primary, #ffffff));
  --_font: var(--sb-font, var(--font-subtitle, "DM Sans", system-ui, sans-serif));
  --_ease: cubic-bezier(0.4, 0, 0.2, 1);
  --_ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  position: fixed;
  left: 0;
  top: 50%;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1.7rem;
  transform: translateY(-50%);
  animation: sidebar-enter 0.6s var(--_ease-out) both;
}

.sidebar *,
.sidebar *::before,
.sidebar *::after {
  box-sizing: border-box;
}

.sidebar-set {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.sidebar-btn {
  display: flex;
  align-items: stretch;
  width: max-content;
  height: 48px;
  padding: 0;
  border: 1px solid color-mix(in srgb, var(--_accent) 50%, transparent);
  border-left: 0;
  border-radius: 0 14px 14px 0;
  background: var(--_panel);
  color: var(--_text);
  text-decoration: none;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
  overflow: hidden;
  transition:
    background 0.35s var(--_ease),
    border-color 0.35s var(--_ease),
    box-shadow 0.35s var(--_ease),
    color 0.35s var(--_ease);
}

.sidebar-btn:hover,
.sidebar-btn:focus-visible {
  background: color-mix(in srgb, var(--_accent) 22%, var(--_panel));
  border-color: color-mix(in srgb, var(--_accent) 72%, white);
  box-shadow: 8px 8px 22px rgba(0, 0, 0, 0.32);
}

.sidebar-btn:active {
  background: color-mix(in srgb, var(--_accent) 38%, var(--_panel));
}

.sidebar-btn:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--_accent) 65%, white);
  outline-offset: 3px;
}

.sidebar-icon {
  display: grid;
  place-items: center;
  width: 48px;
  flex: none;
}

.sidebar-icon img {
  width: 30px;
  height: 30px;
  object-fit: contain;
  background: transparent;
}

.sidebar-fallback {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: #6e6e74;
}

.sidebar-slide {
  display: grid;
  grid-template-columns: 0fr;
  min-width: 0;
  transition: grid-template-columns 0.46s var(--_ease-out);
}

.sidebar-btn:hover .sidebar-slide,
.sidebar-btn:focus-visible .sidebar-slide {
  grid-template-columns: 1fr;
}

.sidebar-name {
  display: flex;
  align-items: center;
  overflow: hidden;
  min-width: 0;
}

.sidebar-label {
  display: block;
  padding: 0 0.95rem 0 0.2rem;
  font-family: var(--_font);
  font-size: 0.95rem;
  font-weight: 500;
  line-height: 1;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.sidebar-btn[aria-current="page"] {
  background: color-mix(in srgb, var(--_accent) 28%, var(--_panel));
  border-color: color-mix(in srgb, var(--_accent) 78%, white);
  box-shadow: inset -3px 0 0 var(--_accent), 0 4px 20px rgba(0, 0, 0, 0.2);
}

.sidebar-btn[aria-current="page"]::after {
  content: "";
  width: 18px;
  flex: none;
  transition: width 0.46s var(--_ease-out);
}

.sidebar-btn[aria-current="page"]:hover,
.sidebar-btn[aria-current="page"]:focus-visible {
  box-shadow: inset -3px 0 0 var(--_accent), 8px 8px 22px rgba(0, 0, 0, 0.32);
}

.sidebar-btn[aria-current="page"]:hover::after,
.sidebar-btn[aria-current="page"]:focus-visible::after {
  width: 0;
}

.sidebar-toggle {
  display: none;
}

@media (max-width: 600px) {
  .sidebar {
    translate: -100% 0;
    transition: translate 0.4s var(--_ease-out);
  }

  .sidebar.is-open {
    translate: 0 0;
  }

  .sidebar-toggle {
    display: grid;
    place-items: center;
    position: fixed;
    left: 0;
    top: calc(50% - var(--_nav-h, 0px) / 2 - 4.5rem - 56px);
    z-index: 31;
    width: 22px;
    height: 56px;
    padding: 0;
    border: 1px solid color-mix(in srgb, var(--_accent) 50%, transparent);
    border-left: 0;
    border-radius: 0 12px 12px 0;
    background: var(--_panel);
    color: var(--_text);
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    transition: background 0.35s var(--_ease), border-color 0.35s var(--_ease);
  }

  .sidebar-toggle:hover,
  .sidebar-toggle:focus-visible {
    background: color-mix(in srgb, var(--_accent) 22%, var(--_panel));
    border-color: color-mix(in srgb, var(--_accent) 72%, white);
  }

  .sidebar-toggle:focus-visible {
    outline: 2px solid color-mix(in srgb, var(--_accent) 65%, white);
    outline-offset: 2px;
  }

  .sidebar-arrow {
    width: 8px;
    height: 8px;
    margin-left: -3px;
    border-right: 2px solid currentColor;
    border-top: 2px solid currentColor;
    transform: rotate(45deg);
    transition: transform 0.4s var(--_ease-out);
  }

  .sidebar-toggle[aria-expanded="true"] .sidebar-arrow {
    margin-left: 3px;
    transform: rotate(-135deg);
  }
}

@keyframes sidebar-enter {
  from {
    opacity: 0;
    transform: translate(-16px, -50%);
  }
  to {
    opacity: 1;
    transform: translateY(-50%);
  }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar,
  .sidebar * {
    animation-duration: 0.01ms !important;
    animation-delay: 0s !important;
    transition-duration: 0.01ms !important;
  }

  .sidebar-btn:hover,
  .sidebar-btn:active {
    transform: none;
  }
}
