/**
 * kakao-aside-menu web component styles
 * Light-DOM custom element: a hidden slide-in menu whose open button pushes
 * the whole <body> aside and slides the panel into the freed space.
 *
 * Theming: every --kakao-aside-* property in the settings block below can be
 * set on the element or any ancestor. The defaults live in that block:
 * change them on construction.html.
 *
 * The component is light DOM (like <kakao-button>): this file must be loaded,
 * because the push effect styles the page <body> itself. While a menu is open
 * the component sets data-kakao-aside-open="left|right" on <html> and the
 * --kakao-aside-push custom property with the panel width.
 */

kakao-aside-menu {
  /* @kakao-settings:start prefix=--kakao-aside- (written by construction.html, edit there) */
  --_width: var(--kakao-aside-width, 280px);
  --_bg: var(--kakao-aside-bg, var(--kakao-color-raised, #ffffff));
  --_color: var(--kakao-aside-color, var(--kakao-color-text, #18181b));
  --_accent: var(--kakao-aside-accent, var(--kakao-color-primary, #4f46e5));
  --_subtle: var(--kakao-aside-subtle, var(--kakao-color-subtle, #f0f0f1));
  --_subtle-strong: var(--kakao-aside-subtle-strong, var(--kakao-color-subtle-strong, #e6e6e8));
  --_focus: var(--kakao-aside-focus, var(--kakao-color-focus, #2563eb));
  --_radius: var(--kakao-aside-radius, var(--kakao-radius-md, 10px));
  --_duration: var(--kakao-aside-duration, var(--kakao-motion-duration, 320ms));
  --_easing: var(--kakao-aside-easing, cubic-bezier(0.22, 1, 0.36, 1));
  --_z-index: var(--kakao-aside-z-index, 40);
  --_shadow: var(--kakao-aside-shadow, none);
  --_open-size: var(--kakao-aside-open-size, 40px);
  --_open-icon: var(--kakao-aside-open-icon, 20px);
  --_open-bg: var(--kakao-aside-open-bg, transparent);
  --_open-color: var(--kakao-aside-open-color, var(--kakao-color-text, #18181b));
  --_open-hover-bg: var(--kakao-aside-open-hover-bg, var(--kakao-color-subtle, #f0f0f1));
  --_open-active-bg: var(--kakao-aside-open-active-bg, var(--kakao-color-subtle-strong, #e6e6e8));
  --_head-padding: var(--kakao-aside-head-padding, 0.875rem 1rem);
  --_title-size: var(--kakao-aside-title-size, 1rem);
  --_title-weight: var(--kakao-aside-title-weight, 600);
  --_close-size: var(--kakao-aside-close-size, 34px);
  --_close-icon: var(--kakao-aside-close-icon, 16px);
  --_content-padding: var(--kakao-aside-content-padding, 0.5rem 0.75rem 1.25rem);
  /* @kakao-settings:end */
  display: inline-block;
}

/* Until the script has built the panel, the raw content (e.g. a <nav> of plain
   links) would show inline in the page: keep it out of sight and out of the flow. */
kakao-aside-menu:not(:defined) > * {
  display: none;
}

/* Setting up the persistent breakpoint (load, reconnect, new value): no slide. */
kakao-aside-menu[data-instant] .kakao-aside-panel {
  transition: none;
}

/* ---------------------------------------------------------------------------
 * The page push: while a menu is open the body slides away by the panel
 * width. The transition makes the push follow the panel, not snap. While
 * a menu is open html clips horizontal overflow, so the document cannot be
 * scrolled sideways and the viewport keeps its exact size (the fixed panel
 * is unaffected by the push).
 * ------------------------------------------------------------------------- */

html[data-kakao-aside-open] {
  overflow-x: hidden;
}

/* width: 100% keeps the body exactly one viewport wide while it slides:
   with the default auto width a margin would make the body narrower and
   its content reflow (squash). This way the content only moves. */
/* These live on <html>/<body>, outside the element: they read the public names,
   because the --_ aliases only exist on <kakao-aside-menu> itself. */
html[data-kakao-aside-open] body {
  width: 100%;
  margin-left: var(--kakao-aside-push, 280px);
  transition: margin-left var(--kakao-aside-duration, 320ms) var(--kakao-aside-easing, cubic-bezier(0.22, 1, 0.36, 1));
}

html[data-kakao-aside-open='right'] body {
  width: 100%;
  margin-left: calc(-1 * var(--kakao-aside-push, 280px));
  transition: margin-left var(--kakao-aside-duration, 320ms) var(--kakao-aside-easing, cubic-bezier(0.22, 1, 0.36, 1));
}

/* Pages can override the push timing by setting --kakao-aside-duration. */

/* ---------------------------------------------------------------------------
 * Open (hamburger) button. Stays visible where the element is placed.
 * ------------------------------------------------------------------------- */

.kakao-aside-open {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--_open-size);
  height: var(--_open-size);
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--_radius);
  background: var(--_open-bg);
  color: var(--_open-color);
  cursor: pointer;
}

.kakao-aside-open[hidden] {
  display: none;
}

/* Persistent (wide viewport): a normal sidebar - nothing to open or close.
   The page is not pushed, so the panel just sits beside the unchanged
   layout: no html data-kakao-aside-open, no body margin. */
kakao-aside-menu[data-persistent] .kakao-aside-open,
kakao-aside-menu[data-persistent] .kakao-aside-close {
  display: none;
}

.kakao-aside-open svg {
  width: var(--_open-icon);
  height: var(--_open-icon);
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  transition: transform var(--_duration) var(--_easing);
}

.kakao-aside-open:hover {
  background: var(--_open-hover-bg);
}

.kakao-aside-open:active {
  background: var(--_open-active-bg);
}

.kakao-aside-open:focus-visible {
  outline: 2px solid var(--_focus);
  outline-offset: 2px;
}

kakao-aside-menu[open] .kakao-aside-open svg {
  transform: rotate(180deg);
}

/* ---------------------------------------------------------------------------
 * Panel: fixed to one side, slides in over the freed space. Hidden means
 * hidden: no box, no events, no tab stops.
 * ------------------------------------------------------------------------- */

.kakao-aside-panel {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: var(--_width);
  max-width: 100vw;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  background: var(--_bg);
  color: var(--_color);
  box-shadow: var(--_shadow);
  transform: translateX(-100%);
  visibility: hidden;
  z-index: var(--_z-index);
  transition:
    transform var(--_duration) var(--_easing),
    visibility 0s linear var(--_duration);
}

.kakao-aside-panel[data-position='right'] {
  left: auto;
  right: 0;
  transform: translateX(100%);
}

kakao-aside-menu[open] .kakao-aside-panel,
kakao-aside-menu[data-persistent] .kakao-aside-panel {
  transform: translateX(0);
  visibility: visible;
  transition:
    transform var(--_duration) var(--_easing);
}

/* ---------------------------------------------------------------------------
 * Header: title on the left, close button on the right.
 * ------------------------------------------------------------------------- */

.kakao-aside-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: var(--_head-padding);
}

/* Menu on the left: the close button sits in the top-left corner (the title
   moves right); on the right side of the screen it stays in the top-right. */
.kakao-aside-panel[data-position='left'] .kakao-aside-head {
  flex-direction: row-reverse;
}

.kakao-aside-title {
  font-size: var(--_title-size);
  font-weight: var(--_title-weight);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.kakao-aside-close {
  flex: 0 0 auto;
}

/* The close control is a <kakao-button variant="ghost" size="sm">
   (button.js + button.css must be loaded): shaped into a perfect circle
   here. */
.kakao-aside-close .kakao-button-inner {
  width: var(--_close-size);
  height: var(--_close-size);
  padding: 0;
  justify-content: center;
  border-radius: 50%;
  font-size: var(--_close-icon);
}

/* ---------------------------------------------------------------------------
 * Content area. Whatever the page puts inside the element lands here via
 * the slot; it scrolls when taller than the viewport.
 * ------------------------------------------------------------------------- */

.kakao-aside-content {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: var(--_content-padding);
}

/* Opinionated link styling inside the menu; override via the slot markup. */
.kakao-aside-content nav a {
  display: block;
  padding: 0.5rem 0.625rem;
  border-radius: var(--_radius);
  color: var(--_color);
  text-decoration: none;
  font-size: 0.95rem;
}

.kakao-aside-content nav a:hover,
.kakao-aside-content nav a:focus-visible {
  background: var(--_subtle);
}

.kakao-aside-content nav a:focus-visible {
  outline: 2px solid var(--_focus);
  outline-offset: -2px;
}

/* ---------------------------------------------------------------------------
 * Built-in nav list (list-data): a vertical list of full-width buttons above
 * the slotted content.
 * ------------------------------------------------------------------------- */

.kakao-aside-navlist {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0 0 0.75rem;
}

.kakao-aside-navlist[hidden] {
  display: none;
}

.kakao-aside-navitem {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0.5rem 0.625rem;
  border: 0;
  border-radius: var(--_radius);
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 0.95rem;
  text-align: left;
  cursor: pointer;
}

.kakao-aside-navitem:hover {
  background: var(--_subtle);
}

.kakao-aside-navitem:focus-visible {
  outline: 2px solid var(--_focus);
  outline-offset: -2px;
}

.kakao-aside-navitem[aria-current='true'] {
  background: color-mix(in srgb, var(--_accent) 12%, transparent);
  color: var(--_accent);
  font-weight: 600;
}

.kakao-aside-navitem:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  background: none;
}

/* Reduced motion: everything snaps into place. */
@media (prefers-reduced-motion: reduce) {
  html[data-kakao-aside-open] body,
  html[data-kakao-aside-open='right'] body {
    transition: none;
  }
  .kakao-aside-panel,
  kakao-aside-menu[open] .kakao-aside-panel {
    transition: none;
  }
  .kakao-aside-open svg {
    transition: none;
  }
}
