/*
 * The admin sidebar (views/partials/sidebar.ejs, behaviour in js/sidebar.js),
 * on top of the WowDash rules in style.css. Loaded after it, so a selector of
 * the same weight here wins.
 *
 * The one rule the rest follows: a single row is solid brand colour, and it is
 * the page you are on. The theme also painted an open section's header solid,
 * so an expanded section and the current page looked alike and two rows were
 * lit at once.
 */

/* Logo, search, then the list in whatever height is left, so the search box
   stays put however far down the list has been scrolled. */
.sidebar {
  display: flex;
  flex-direction: column;
}

/* The theme's 1400px width all the way down. At 220px (1200-1399px, every
   1280 and 1366 laptop) and in the 250px drawer, most section names broke
   over two lines. */
@media (max-width: 1649.98px) {
  .sidebar {
    width: 17.1875rem;
  }
}

@media (min-width: 1200px) and (max-width: 1399.98px) {
  .dashboard-main {
    margin-inline-start: 17.1875rem;
  }
}

.sidebar-menu-area {
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
  padding-block: 0.25rem 1rem;
}

/* --- Find a screen ------------------------------------------------------- */

.sidebar-search {
  position: relative;
  flex: none;
  padding: 0.75rem 1rem 0.5rem;
  border-inline-end: 1px solid var(--neutral-200);
}

.sidebar-search input {
  width: 100%;
  height: 2.375rem;
  padding-inline: 2.25rem 0.75rem;
  font-size: 0.875rem;
  color: var(--text-primary-light);
  background-color: var(--neutral-50);
  border: 1px solid var(--neutral-200);
  border-radius: 8px;
  outline: none;
  transition: border-color 0.15s, background-color 0.15s, box-shadow 0.15s;
}

.sidebar-search input::placeholder {
  color: var(--text-secondary-light);
}

.sidebar-search input:focus {
  background-color: var(--white);
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--primary-50);
}

.sidebar-search-icon {
  position: absolute;
  inset-inline-start: 1.75rem;
  /* the input's centre: top padding + half its height */
  top: 1.9375rem;
  transform: translateY(-50%);
  font-size: 1rem;
  color: var(--text-secondary-light);
  pointer-events: none;
}

.sidebar-search-empty {
  margin: 0;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  color: var(--text-secondary-light);
}

/* While filtering, every section with a match is open at once — the accordion
   only ever shows one — and the rest of the list is out of the way. */
.sidebar-menu .is-filtered-out {
  display: none !important;
}

.sidebar-menu.is-filtering li.dropdown > .sidebar-submenu {
  display: block !important;
}

.sidebar-menu.is-filtering li.dropdown > a::after {
  transform: translateY(-50%) rotate(90deg);
}

/* --- Rows ---------------------------------------------------------------- */

/* The theme spaced a dropdown 0.5rem from the row above and a plain link not at
   all, so the list ran in an uneven rhythm. */
.sidebar-menu > li + li,
.sidebar-menu li.dropdown {
  margin-block-start: 0.125rem;
}

.sidebar-menu li a {
  padding: 0.5rem 0.75rem;
  transition: background-color 0.15s, color 0.15s;
}

.sidebar-menu li a:not(.active-page):hover {
  background-color: var(--neutral-100);
}

.sidebar-menu li a:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: -2px;
}

/* An open section is just open: its header keeps the ordinary row colours, and
   only the section holding the current page has its name in brand colour. */
.sidebar-menu li.dropdown.open > a,
.sidebar-menu li.dropdown.dropdown-open > a {
  background-color: transparent;
  color: var(--text-primary-light);
}

.sidebar-menu li.dropdown.open > a:hover,
.sidebar-menu li.dropdown.dropdown-open > a:hover {
  color: var(--brand);
}

.sidebar-menu li.dropdown.has-active-page > a {
  color: var(--brand);
  font-weight: 600;
}

/* Room for the arrow, which is positioned over the row rather than beside the
   name: a long name used to run underneath it. */
.sidebar-menu li.dropdown > a {
  padding-inline-end: 2rem;
}

.sidebar-menu li.dropdown > a::after {
  transition: transform 0.2s;
}

/* Open as rendered. The theme only showed a section's items for `open`; the
   server now renders the current page's section `dropdown-open`, the class the
   toggle itself uses, so the two can no longer disagree. */
.sidebar-menu li.dropdown.dropdown-open > .sidebar-submenu {
  display: block;
}

/* A section's items hang off a guide line under its icon, instead of a bullet
   apiece. */
.sidebar-menu .sidebar-submenu {
  margin-block: 0.125rem 0.375rem;
  margin-inline-start: 1.3125rem;
  padding-block-start: 0;
  padding-inline-start: 0.625rem;
  border-inline-start: 1px solid var(--neutral-200);
}

.sidebar-menu .sidebar-submenu li + li {
  margin-block-start: 0.125rem;
}

.sidebar-menu .sidebar-submenu li a {
  padding: 0.375rem 0.75rem;
}

.sidebar-menu .sidebar-submenu li.active-page a {
  background-color: var(--brand);
  color: #fff;
}

/* --- Headings over the blocks of sections -------------------------------- */

.sidebar-menu .sidebar-menu-heading {
  margin-block: 1.125rem 0.375rem;
  padding-inline: 0.75rem;
  font-size: 0.6875rem;
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--neutral-500);
}

/* --- The drawer below 1200px --------------------------------------------- */

/* The dimmed backdrop behind the open drawer. The theme sized it to the body,
   so on a page shorter than the window the bottom of the screen stayed bright.
   Fixed in both states, so it does not jump while it slides away. */
body::after {
  position: fixed;
}

/* The drawer and its backdrop on Bootstrap's off-canvas layers (backdrop 1040,
   panel 1045): over everything on the page, under dialogs, date pickers and
   toasts. The theme left them at 3 and 2, the same as or below things inside the
   page — the sticky sideways scroller under a wide table (tableScroll.css, 3), the
   dashboard's ⓘ (3), the action bars of the wallpaper and social-media screens —
   and those came later in the page, so they were drawn over the open drawer. Also
   lifts a folded sidebar opened out by the pointer over the same things. */
.sidebar {
  z-index: 1045;
}

body::after {
  z-index: 1040;
}

/* --- Folded down to icons ------------------------------------------------- */

.sidebar.active:not(:hover) .sidebar-search {
  display: none;
}

/* Hovering opens the folded sidebar out to full width; the theme brings the
   headings back as inline-block there, which squeezes their margins. */
.sidebar.active:hover .sidebar-menu li.sidebar-menu-heading {
  display: block;
}

/* With the labels hidden a heading would be blank, so each block is set off by
   a rule instead. */
.sidebar.active:not(:hover) .sidebar-menu li.sidebar-menu-heading {
  display: block;
  height: 1px;
  margin: 0.625rem 0.75rem;
  padding: 0;
  overflow: hidden;
  font-size: 0;
  background-color: var(--neutral-200);
}

/* The current page's section is closed while folded, so its icon is what says
   where you are. */
.sidebar.active:not(:hover) .sidebar-menu li.dropdown.has-active-page > a {
  background-color: var(--brand);
  color: #fff;
}

/* --- Pinning and arranging (js/sidebarArrange.js) ------------------------ */

/* Colours come from adminModern.css's sidebar palette, with the theme's own as
   the fallback for a page that does not load it. */

/* The search box shares its row with the switch into arranging. */
.sidebar-search {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.sidebar-search input {
  flex: 1 1 auto;
  min-width: 0;
}

.sidebar-search input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.sidebar-arrange-toggle {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.375rem;
  height: 2.375rem;
  padding: 0;
  font-size: 1.125rem;
  line-height: 1;
  color: var(--hk-sidebar-muted, var(--text-secondary-light));
  background-color: var(--hk-sidebar-field, var(--neutral-50));
  border: 1px solid var(--hk-sidebar-field-line, var(--neutral-200));
  border-radius: 8px;
  transition: color 0.15s, background-color 0.15s, border-color 0.15s;
}

.sidebar-arrange-toggle:hover {
  color: var(--hk-sidebar-strong, var(--brand));
}

.sidebar-arrange-toggle[aria-pressed="true"] {
  color: var(--hk-active-ink, #fff);
  background-color: var(--hk-active-bg, var(--brand));
  border-color: transparent;
}

.sidebar-arrange-toggle:focus-visible,
.sidebar-pin:focus-visible,
.sidebar-grip:focus-visible,
.sidebar-arrange-actions button:focus-visible {
  outline: 2px solid var(--hk-sidebar-muted, var(--brand));
  outline-offset: 1px;
}

/* A module's row holds its pin, so the pin can sit over it. */
.sidebar-menu > li.sidebar-module {
  position: relative;
}

/* A module's name stays on one line. The pin takes room at the end of the row
   only while the pointer is on that row, and there the name gives way to an
   ellipsis instead of breaking onto a second line: "Donation Management" and
   "Song Management" just fit beside a section's arrow, and no more. */
.sidebar-menu > li.sidebar-module > a > span {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* The row's own link or its pin, not the open section's screens under it. */
.sidebar-menu > li.sidebar-module:has(> a:hover, > .sidebar-pin:hover, > .sidebar-pin:focus-visible) > a {
  padding-inline-end: 2.25rem;
}

.sidebar-menu > li.sidebar-module.dropdown:has(> a:hover, > .sidebar-pin:hover, > .sidebar-pin:focus-visible) > a {
  padding-inline-end: 3.5rem;
}

/* Top-aligned to the module's own link rather than centred on the <li>, which
   also holds an open section's screens. */
.sidebar-pin {
  position: absolute;
  inset-block-start: 0.375rem;
  inset-inline-end: 0.375rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  font-size: 0.9375rem;
  line-height: 1;
  color: var(--hk-sidebar-muted, var(--text-secondary-light));
  background: transparent;
  border: 0;
  border-radius: 6px;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, background-color 0.15s;
}

/* Just inside the section's arrow. */
.sidebar-menu > li.sidebar-module.dropdown > .sidebar-pin {
  inset-inline-end: 1.875rem;
  width: 1.5rem;
}

.sidebar-menu > li.sidebar-module > a:hover ~ .sidebar-pin,
.sidebar-pin:hover,
.sidebar-pin:focus-visible,
.sidebar.is-arranging .sidebar-pin {
  opacity: 1;
}

.sidebar-pin:hover {
  color: var(--hk-sidebar-strong, var(--brand));
  background-color: var(--hk-sidebar-hover, var(--neutral-100));
}

/* Arranging, every pin shows, so every row keeps its room, and a long name
   wraps rather than hiding behind an ellipsis while you decide where it goes. */
.sidebar.is-arranging .sidebar-menu > li.sidebar-module > a {
  padding-inline-end: 2.25rem;
}

.sidebar.is-arranging .sidebar-menu > li.sidebar-module.dropdown > a {
  padding-inline-end: 3.5rem;
}

.sidebar.is-arranging .sidebar-menu > li.sidebar-module > a > span {
  white-space: normal;
}

/* On the current page's pill, in the pill's own ink. */
.sidebar-menu > li > a.active-page ~ .sidebar-pin,
.sidebar-menu > li > a.active-page ~ .sidebar-pin:hover {
  color: var(--hk-active-ink, #fff);
}

.sidebar-menu > li > a.active-page ~ .sidebar-pin:hover {
  background-color: rgba(0, 0, 0, 0.08);
}

/* A block with nothing left in it (every module pinned, or Pinned with none). */
.sidebar-menu > li.is-empty {
  display: none !important;
}

/* Folded to icons there is no room for either control. */
.sidebar.active:not(:hover) .sidebar-pin,
.sidebar.active:not(:hover) .sidebar-grip,
.sidebar.active:not(:hover) .sidebar-arrange-toggle {
  display: none;
}

/* Arranging: a handle at the start of every row. */
.sidebar.is-arranging .sidebar-menu {
  user-select: none;
  -webkit-user-select: none;
}

.sidebar.is-arranging .sidebar-menu a {
  -webkit-user-drag: none;
}

.sidebar.is-arranging .sidebar-menu li > a:not([role="button"]) {
  cursor: grab;
}

.sidebar.is-arranging .sidebar-menu > li.sidebar-module > a,
.sidebar.is-arranging .sidebar-submenu > li > a,
.sidebar.is-arranging .sidebar-menu > li[data-heading] {
  padding-inline-start: 1.75rem;
}

.sidebar.is-arranging .sidebar-submenu > li,
.sidebar.is-arranging .sidebar-menu > li[data-heading] {
  position: relative;
}

.sidebar-grip {
  position: absolute;
  inset-block-start: 0.375rem;
  inset-inline-start: 0.125rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.75rem;
  padding: 0;
  font-size: 1rem;
  line-height: 1;
  letter-spacing: 0;
  color: var(--hk-sidebar-muted, var(--text-secondary-light));
  background: transparent;
  border: 0;
  border-radius: 6px;
  cursor: grab;
  /* A finger on the handle drags the row instead of scrolling the list. */
  touch-action: none;
}

.sidebar-grip:hover {
  color: var(--hk-sidebar-strong, var(--brand));
  background-color: var(--hk-sidebar-hover, var(--neutral-100));
}

/* On the current page's pill, in the pill's own ink, or it vanishes into it. */
.sidebar-menu li > a.active-page ~ .sidebar-grip,
.sidebar-menu li > a.active-page ~ .sidebar-grip:hover {
  color: var(--hk-active-ink, #fff);
}

.sidebar-menu li > a.active-page ~ .sidebar-grip:hover {
  background-color: rgba(0, 0, 0, 0.08);
}

.sidebar-submenu .sidebar-grip {
  inset-block-start: 0.1875rem;
  height: 1.625rem;
}

.sidebar-menu > li[data-heading] > .sidebar-grip {
  inset-block-start: 50%;
  height: 1.5rem;
  transform: translateY(-50%);
}

/* The rows being carried: lifted off the list, on the sidebar's own colour so
   the rows they pass over do not show through. */
.sidebar-menu li.is-dragging {
  position: relative;
  z-index: 5;
  border-radius: 10px;
  background-color: var(--hk-sidebar, var(--white));
  background-image: linear-gradient(var(--hk-sidebar-hover, transparent), var(--hk-sidebar-hover, transparent));
  box-shadow: 0 10px 24px rgba(8, 20, 60, 0.28), 0 0 0 1px var(--hk-sidebar-line, var(--neutral-200));
}

.sidebar.is-dragging-active,
.sidebar.is-dragging-active * {
  cursor: grabbing !important;
}

/* Where a row landed after a move or a pin. */
@keyframes sidebar-row-moved {
  from {
    background-color: var(--hk-sidebar-hover, var(--neutral-100));
    box-shadow: inset 0 0 0 1px var(--hk-sidebar-line, var(--neutral-200));
  }
  to {
    background-color: transparent;
    box-shadow: inset 0 0 0 1px transparent;
  }
}

.sidebar-menu li.is-just-moved > a:not(.active-page),
.sidebar-menu > li.is-just-moved[data-heading] {
  animation: sidebar-row-moved 1.2s ease-out;
}

@media (prefers-reduced-motion: reduce) {
  .sidebar-menu li.is-just-moved > a:not(.active-page),
  .sidebar-menu > li.is-just-moved[data-heading] {
    animation: none;
  }
}

/* Under the list while arranging: how, and the way out. */
.sidebar-arrange-bar {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  padding: 0.75rem 1rem 1rem;
  border-block-start: 1px solid var(--hk-sidebar-line, var(--neutral-200));
}

.sidebar-arrange-bar[hidden] {
  display: none;
}

.sidebar-arrange-hint {
  margin: 0;
  font-size: 0.75rem;
  line-height: 1.45;
  color: var(--hk-sidebar-muted, var(--text-secondary-light));
}

.sidebar-arrange-actions {
  display: flex;
  gap: 0.5rem;
}

.sidebar-arrange-actions button {
  flex: 1 1 0;
  height: 2.25rem;
  padding: 0 0.75rem;
  font-size: 0.8125rem;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: 8px;
  transition: color 0.15s, background-color 0.15s, border-color 0.15s, filter 0.15s;
}

.sidebar-arrange-reset {
  color: var(--hk-sidebar-ink, var(--text-primary-light));
  background-color: transparent;
  border-color: var(--hk-sidebar-field-line, var(--neutral-200)) !important;
}

.sidebar-arrange-reset:hover {
  color: var(--hk-sidebar-strong, var(--brand));
  background-color: var(--hk-sidebar-hover, var(--neutral-100));
}

.sidebar-arrange-done {
  color: var(--hk-active-ink, #fff);
  background-color: var(--hk-active-bg, var(--brand));
}

.sidebar-arrange-done:hover {
  filter: brightness(0.95);
}
