/* ── Lemmy's Rankings: episode-article pop-in workbench sidebar ────────────
   Loaded only by the episode pages (/rankings/<episode>/). The zone index at
   /rankings/ keeps its normal permanent sidebar like every other zone page.

   The workbench nav lives in the page markup as static, crawlable links. With
   JavaScript it is parked off-canvas behind a vertical "WORKBENCH" tab pinned
   to the left edge, so it never eats into the article column until it is asked
   for. Without JavaScript the same markup renders as a normal static block at
   the top of the page and every link still works.

   The panel styles itself completely (background, border, shadow, cards) rather
   than inheriting them: episode pages run on operator.css only, so the drawer
   would otherwise inherit operator-yellow links and mono body text. Shared chrome
   (.sidebar, .sidebar__nav-card) is explicitly overridden per the brand rules —
   no fill, border, or shadow is ever inherited.                                  */

.rankings-sidebar-toggle,
.rankings-sidebar-scrim,
.rankings-sidebar-head {
  display: none;
}

/* ── Panel components ────────────────────────────────────────────────────── */
.rankings-sidebar {
  display: flex;
  flex-direction: column;
  color: #292928;
  background: #f7f7f4;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 16px;
  line-height: 1.35;
  gap: 18px;
}

.rankings-sidebar .sidebar__brand-block {
  margin-bottom: 4px;
  padding-bottom: 14px;
  border-bottom: 1px solid #dedcd5;
}

.rankings-sidebar .brand {
  display: block;
  width: min(160px, 100%);
}

.rankings-sidebar .brand__logo {
  display: block;
  width: 100%;
  height: auto;
}

.rankings-sidebar .sidebar__group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  margin-bottom: 18px;
}

.rankings-sidebar .sidebar__group-label {
  display: block;
  margin-bottom: 4px;
  color: #8e8c85;
  font-family: "Courier New", Courier, monospace;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.rankings-sidebar .sidebar__nav-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid #dcd8cc;
  border-radius: 2px;
  background: #ffffff;
  color: #292928;
  font-family: "Courier New", Courier, monospace;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-decoration: none;
  text-transform: uppercase;
  transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease, transform 140ms ease, box-shadow 140ms ease;
}

.rankings-sidebar .sidebar__nav-card:hover,
.rankings-sidebar .sidebar__nav-card:focus-visible {
  border-color: #11100d;
  background: #faf9f5;
  color: #11100d;
  text-decoration: none;
  transform: translateX(2px);
  box-shadow: 2px 2px 0 rgb(17 16 13 / 0.08);
}

.rankings-sidebar .sidebar__nav-card.is-active,
.rankings-sidebar .sidebar__nav-card[aria-current="page"] {
  border-color: #11100d;
  background: #11100d;
  color: #ffffff;
  box-shadow: none;
  transform: none;
}

.rankings-sidebar .sidebar__nav-card-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.rankings-sidebar .sidebar__nav-card-badge {
  margin-left: 8px;
  color: #85837d;
  font-family: "Courier New", Courier, monospace;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
  flex-shrink: 0;
}

.rankings-sidebar .sidebar__nav-card.is-active .sidebar__nav-card-badge {
  color: #e6cb3b;
}

.rankings-sidebar .sidebar__nav-card-arrow {
  margin-left: 8px;
  color: #85837d;
  font-size: 13px;
  flex-shrink: 0;
  transition: transform 140ms ease, color 140ms ease;
}

.rankings-sidebar .sidebar__nav-card:hover .sidebar__nav-card-arrow {
  color: #11100d;
  transform: translateX(2px);
}

.rankings-sidebar .sidebar__nav-card.is-active .sidebar__nav-card-arrow {
  color: #ffffff;
}

.rankings-sidebar .sidebar__nav-card--drawer {
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 6px;
  min-height: 48px;
  padding: 8px 12px;
  border-color: #c8c4b6;
  background: #f3efe4;
  text-align: center;
}

.rankings-sidebar .sidebar__nav-card--drawer:hover {
  border-color: #11100d;
  background: #ede8dc;
}

.rankings-sidebar .sidebar__drawer-handle {
  display: block;
  width: 46px;
  height: 4px;
  border-radius: 2px;
  background: #c8c4b6;
  transition: background-color 140ms ease;
}

.rankings-sidebar .sidebar__nav-card--drawer:hover .sidebar__drawer-handle {
  background: #11100d;
}

/* ── No-JS fallback ─────────────────────────────────────────────────────── */
body:not(.rankings-sidebar-ready) .rankings-sidebar {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: 100%;
  max-width: none;
  height: auto;
  min-height: 0;
  padding: 20px 20px 28px;
  border-right: 0;
  border-bottom: 1px solid #dedcd5;
  background: #f7f7f4;
}

/* ── JS ready: off-canvas drawer + edge tab ─────────────────────────────── */
/* Stacking sits above the sticky .op-header (z-index 100) and below
   modals/toasts (>=140). */
body.rankings-sidebar-ready .rankings-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 130;
  display: flex;
  flex-direction: column;
  width: clamp(260px, 22vw, 320px);
  height: 100svh;
  padding: 20px 20px 32px;
  border-right: 1px solid #d8d4c7;
  border-bottom: 0;
  background: #f7f7f4;
  box-shadow: 18px 0 44px rgba(17, 16, 13, 0.28);
  overflow-y: auto;
  transform: translateX(calc(-100% - 6px));
  transition: transform 220ms ease;
}

body.rankings-sidebar-ready.rankings-sidebar-is-open .rankings-sidebar {
  transform: translateX(0);
}

/* The panel header and its close button are drawer-only: without JavaScript
   they would be dead controls, so they stay hidden. */
body.rankings-sidebar-ready .rankings-sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid #dedcd5;
}

.rankings-sidebar-head__label {
  color: #8e8c85;
  font-family: "Courier New", Courier, monospace;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.rankings-sidebar-close {
  display: inline-flex;
  width: 34px;
  height: 34px;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid #d8d4c7;
  border-radius: 2px;
  background: #ffffff;
  color: #292928;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  transition: border-color 140ms ease, background-color 140ms ease, color 140ms ease;
}

.rankings-sidebar-close:hover,
.rankings-sidebar-close:focus-visible {
  border-color: #11100d;
  background: #11100d;
  color: #f7f4ea;
}

/* Edge tab */
body.rankings-sidebar-ready .rankings-sidebar-toggle {
  position: fixed;
  left: 0;
  top: 50%;
  z-index: 119;
  display: flex;
  width: 34px;
  min-height: 128px;
  align-items: center;
  justify-content: center;
  padding: 14px 0;
  border: 1px solid #11100d;
  border-left: 0;
  border-radius: 0 4px 4px 0;
  background: #11100d;
  color: #f7f4ea;
  font-family: Arial, Helvetica, sans-serif;
  box-shadow: 3px 3px 0 rgba(17, 16, 13, 0.18);
  cursor: pointer;
  transform: translateY(-50%);
  transition: background-color 140ms ease, color 140ms ease;
}

body.rankings-sidebar-ready .rankings-sidebar-toggle:hover,
body.rankings-sidebar-ready .rankings-sidebar-toggle:focus-visible {
  background: #f4df35;
  color: #11100d;
}

body.rankings-sidebar-ready.rankings-sidebar-is-open .rankings-sidebar-toggle {
  display: none;
}

.rankings-sidebar-toggle__label {
  font-family: "Courier New", Courier, monospace;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.16em;
  line-height: 1;
  text-transform: uppercase;
  writing-mode: vertical-rl;
}

.rankings-sidebar-toggle__hint {
  position: absolute;
  left: 0;
  bottom: -18px;
  width: 34px;
  color: #85837d;
  font-family: "Courier New", Courier, monospace;
  font-size: 9px;
  letter-spacing: 0.12em;
  text-align: center;
}

/* Scrim */
body.rankings-sidebar-ready .rankings-sidebar-scrim {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: block;
  border: 0;
  padding: 0;
  background: rgba(17, 16, 13, 0.34);
  cursor: pointer;
}

/* Must out-specify the rule above, otherwise the closed scrim stays displayed
   and swallows every click on the tab and the page. */
body.rankings-sidebar-ready .rankings-sidebar-scrim[hidden] {
  display: none;
}

/* ── The shared stylesheet collapses .sidebar into a top bar at <=1023px and
   hides .sidebar__group with !important. The rankings drawer stays vertical at
   every width, so that is undone here. ──────────────────────────────────── */
@media (max-width: 1023px) {
  .rankings-sidebar .sidebar__group,
  .rankings-sidebar .category-nav {
    display: flex !important;
    flex-direction: column;
    gap: 6px;
    /* Flex items default to min-content width; the nowrap card labels would push
       the panel wider than the viewport without this. */
    min-width: 0;
    margin-bottom: 18px;
  }

  .rankings-sidebar .sidebar__brand-block {
    display: block !important;
  }

  body.rankings-sidebar-ready .rankings-sidebar {
    width: min(300px, 84vw);
    padding: 16px 14px 28px;
  }

  body.rankings-sidebar-ready .rankings-sidebar-toggle {
    top: auto;
    bottom: 16px;
    min-height: 116px;
    transform: none;
  }

  body:not(.rankings-sidebar-ready) .rankings-sidebar {
    width: 100vw;
    max-width: 100vw;
    padding: 16px 14px 24px;
  }
}

@media (prefers-reduced-motion: reduce) {
  body.rankings-sidebar-ready .rankings-sidebar,
  body.rankings-sidebar-ready .rankings-sidebar-toggle,
  .rankings-sidebar-close,
  .rankings-sidebar .sidebar__nav-card {
    transition: none;
  }
}