/* ===================================================== */
/* "More" sidebar dropdown menu (replaces old slide panel) */
/* ===================================================== */

.sidebar-more-dropdown {
  width: 100%;
}

.sidebar-more-dropdown .sidebar__nav-item.dropdown-toggle {
  cursor: pointer;
  width: 100%;
}

/* Hide Bootstrap's default caret arrow - the "..." icon is enough */
.sidebar-more-dropdown .dropdown-toggle::after {
  display: none !important;
}

/* Base menu: kept rendered (display:block) at all times instead of relying
   on Bootstrap's display:none <-> block toggle, so the slide transform can
   actually transition. Popper still handles vertical placement; the closed
   state is invisible and non-interactive via visibility/pointer-events.
   Opacity is always 1 - only the slide (transform) animates, so the menu
   never passes through a translucent state that shows the page underneath. */
.sidebar-more-dropdown .dropdown-menu.sidebar-more-menu {
  display: block !important;
  margin-bottom: 8px !important;
  left: 75px !important;
  opacity: 1;
  visibility: hidden;
  pointer-events: none;
  transform: translateX(-16px) !important;
  transition: transform 0.22s ease, visibility 0s linear 0.22s;
}

/* Slide out to the left, overlapping the sidebar and main page */
.sidebar-more-dropdown .dropdown-menu.sidebar-more-menu.show {
  visibility: visible;
  pointer-events: auto;
  transform: translateX(0) !important;
  transition: transform 0.22s ease, visibility 0s linear 0s;
}

/* On mobile the off-canvas sidebar sits very close to the screen's left edge,
   so Popper's calculated position pushes part of the menu off-screen and it
   gets clipped. Force it to anchor flush against its own toggle instead,
   with a slightly smaller left overlap than desktop. */
@media (max-width: 1024px) {
  .sidebar-more-dropdown .dropdown-menu.sidebar-more-menu {
    position: absolute !important;
    inset: auto !important;
    top: auto !important;
    bottom: 100% !important;
    left: 45px !important;
    right: auto !important;
    margin: 0 0 8px 0 !important;
    max-width: calc(100vw - 32px) !important;
  }
}

/* The off-canvas mobile sidebar itself needs overflow-x:hidden for its own
   nav scrolling (see _left.scss), but that also clips this dropdown as it
   slides out past the sidebar's right edge. JS toggles this class on
   .left-sb-container for the lifetime of the dropdown being open. */
@media (max-width: 1024px) {
  .left-sb-container.sidebar-more-menu-open {
    overflow: visible !important;
  }
}

/* Belt-and-braces stacking fix for mobile: the open menu slides upward and
   visually covers the Home/Notifications/Search/etc. nav-item group above
   it. That group sits earlier in the DOM so it should already paint below
   the dropdown, but a tap that lands right as the menu is closing (e.g. a
   dropdown-item's own click both navigates AND triggers Bootstrap's
   outside-click handler) can otherwise land on the now-hidden dropdown's
   old position and be picked up by whatever nav item is underneath it.
   Explicitly raising the dropdown's own stacking order and disabling
   pointer-events on the nav group behind it for the lifetime of
   "sidebar-more-menu-open" (same class/timing as the overflow fix above)
   makes that impossible regardless of timing. */
@media (max-width: 1024px) {
  .sidebar-more-dropdown {
    position: relative;
    z-index: 1601;
  }

  .left-sb-container.sidebar-more-menu-open .sidebar__nav > *:not(.sidebar__nav-group_toggle) {
    pointer-events: none !important;
  }
}

/* Kill the tap-highlight / click-flash on sidebar/dropdown items, on every
   viewport. Bootstrap's reboot already zeroes -webkit-tap-highlight-color on
   <body>, but that doesn't reliably inherit through elements using
   transform/will-change for their slide animations (both .left-sb-container
   and this dropdown do), so the browser's default blue flash was leaking
   back in. Tapping/clicking these just navigates to a new page, so no tap
   feedback colour is needed. */
.left-sb-container,
.left-sb-container a,
.left-sb-container button,
.left-sb-container .sidebar__nav-item,
.left-sb-container .dropdown-toggle,
.left-sb-container .dropdown-item,
.left-sb-container .form-switch,
.left-sb-container input {
  -webkit-tap-highlight-color: transparent !important;
}

/* Flicker row specifically: the checkbox is the one interactive element in
   the sidebar dropdown that isn't an <a>/<button>/.dropdown-item, so it
   wasn't covered by the tap-highlight fix above, and Bootstrap's own
   .form-check-input:focus / :checked states also pull in the primary
   (blue) colour via border/box-shadow. Neutralise all of it - the toggle's
   own on/off styling already communicates state, no focus ring needed. */
#ds-flicker-toggle-item,
#ds-flicker-toggle-item .form-switch,
#ds-flicker-toggle-item input,
#ds-flicker-switch {
  -webkit-tap-highlight-color: transparent !important;
}

#ds-flicker-toggle-item:hover,
#ds-flicker-toggle-item:focus,
#ds-flicker-toggle-item:focus-visible,
#ds-flicker-toggle-item:active {
  /* Was "transparent", and neither this rule nor the generic one below
     covered :hover at all - so on mouse-over this row fell straight
     through to Bootstrap's own default .dropdown-item:hover (light grey
     background, dark text - see css-libs.css), which is bright against
     the dark theme and makes the text unreadable. Matches the same
     hover/active colour every other row in this menu uses. */
  background: var(--cl-event-hover-bg) !important;
  outline: none !important;
  box-shadow: none !important;
}

#ds-flicker-switch:focus,
#ds-flicker-switch:focus-visible,
#ds-flicker-switch:active {
  outline: none !important;
  box-shadow: none !important;
}

/* Base text/icon colour for the Flicker row. It's a <div class="dropdown-
   item">, not an <a class="dropdown-item"> - the theme's base colour rule
   for dropdown items (_dropdowns.scss) only targets the anchor version, so
   this row was falling back to Bootstrap's default dark grey text, which
   is invisible against the dark theme's background (every other row here
   is an <a> and already gets themed correctly). */
#ds-flicker-toggle-item,
#ds-flicker-toggle-item span.flex-item {
  color: var(--cl-primary-text-color) !important;
}
#ds-flicker-toggle-item span.flex-item.dropdown-item-icon svg path {
  fill: var(--cl-primary-text-color) !important;
}

.sidebar-more-menu .dropdown-item {
  display: flex !important;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  outline: none;
}

/* Our theme's base dropdown-item override (_dropdowns.scss) only re-colours
   :hover, :active and .active on the "a.dropdown-item" selector specifically
   - it never touched the browser's separate :focus state, and it doesn't
   match a plain <div class="dropdown-item"> (e.g. the Flicker row) at all
   since there's no "a." in front of it. Both gaps fall straight through to
   Bootstrap's own default (blue $primary background + white text on
   .active/:active, per _dropdown.scss), which is what was showing through
   as a blue flash. Covered here for every item, div or anchor alike. */
.sidebar-more-menu .dropdown-item:hover,
.sidebar-more-menu .dropdown-item:focus,
.sidebar-more-menu .dropdown-item:focus-visible,
.sidebar-more-menu .dropdown-item:active,
.sidebar-more-menu .dropdown-item.active {
  background: var(--cl-event-hover-bg) !important;
  outline: none !important;
  box-shadow: none !important;
}

.sidebar-more-menu .dropdown-item:not(.sidebar-more-menu__logout):hover,
.sidebar-more-menu .dropdown-item:not(.sidebar-more-menu__logout):focus,
.sidebar-more-menu .dropdown-item:not(.sidebar-more-menu__logout):focus-visible,
.sidebar-more-menu .dropdown-item:not(.sidebar-more-menu__logout):active,
.sidebar-more-menu .dropdown-item:not(.sidebar-more-menu__logout).active {
  color: var(--cl-primary-text-color) !important;
}

.sidebar-more-menu .dropdown-item span.flex-item:not(.dropdown-item-icon) {
  flex: 1;
  overflow: hidden;
  line-height: 1;
  white-space: normal;
}

.sidebar-more-menu .dropdown-item span.flex-item.dropdown-item-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  margin-right: 8px;
  line-height: 1.2;
}

.sidebar-more-menu .dropdown-item span.flex-item.dropdown-item-icon svg {
  width: 100%;
  height: 100%;
  opacity: 1;
}

.sidebar-more-menu .dropdown-item span.flex-item.dropdown-item-icon svg path {
  fill: var(--cl-primary-text-color);
}

/* Logout item - danger colour, matching the reference design */
.sidebar-more-menu .dropdown-item.sidebar-more-menu__logout,
.sidebar-more-menu .dropdown-item.sidebar-more-menu__logout span.flex-item {
  color: var(--cl-danger-color);
}

.sidebar-more-menu .dropdown-item.sidebar-more-menu__logout span.flex-item.dropdown-item-icon svg path {
  fill: var(--cl-danger-color);
}

.sidebar-more-menu .dropdown-item.sidebar-more-menu__logout span.flex-item.dropdown-item-icon svg {
  opacity: 1;
}

/* ===================================================== */
/* Larger tap targets on mobile - left sidebar + popout menu */
/* ===================================================== */

/* Small phones make the default 50px-tall / 15px rows and 20px dropdown
   icons hard to hit accurately. Desktop is untouched - scoped to the same
   mobile breakpoint used elsewhere in this file. */
@media (max-width: 1024px) {
  /* Left sidebar nav rows: Home, Notifications, Search, Messages, More... */
  .left-sb-container .sidebar__nav-item {
    height: 60px;
  }

  .left-sb-container .sidebar__nav-item span.icon svg,
  .left-sb-container .sidebar__nav-item span.icon.avatar {
    width: 28px;
    height: 28px;
  }

  .left-sb-container .sidebar__nav-item span.text {
    margin-left: 14px;
  }

  .left-sb-container .sidebar__nav-item span.text > a {
    font-size: 18px;
    line-height: 22px;
  }

  .left-sb-container .sidebar__nav-item span.text span.info-indicators {
    font-size: 12px;
    line-height: 20px;
    min-width: 22px;
  }

  /* Popout "More" menu rows: Wallet, Advertising, Flicker, Bookmarks... */
  .sidebar-more-menu .dropdown-item {
    padding: 16px 20px !important;
    min-height: 56px;
    font-size: 17px !important;
    line-height: 20px !important;
  }

  .sidebar-more-menu .dropdown-item span.flex-item.dropdown-item-icon {
    width: 26px;
    height: 26px;
    margin-right: 14px;
  }

  /* Flicker's own switch: bigger track/thumb so the actual tappable
     control (only the checkbox itself reacts to a tap, not the row) is
     easier to hit precisely. */
  #ds-flicker-switch {
    width: 44px;
    height: 24px;
  }
}

/* ===================================================== */
/* Popout menu vertical positioning fix - mobile          */
/* ===================================================== */

/* The rows above were made taller/bigger-font for easier tapping, which
   grew the popout menu's total height. Since it was anchored with
   bottom: 100% (i.e. it grows UPWARD from its toggle, which sits low in
   the sidebar), a taller menu now pushes its top edge above the visible
   screen - part of it, including some of its own options, was rendering
   off-screen and unreachable.
   Fix: anchor it as a fixed element pinned near the bottom of the
   viewport instead of relative to the toggle, and cap its height with
   its own scroll - this guarantees the whole menu (and every option in
   it) always sits fully within the visible screen, regardless of how
   tall it grows. */
@media (max-width: 1024px) {
  .sidebar-more-dropdown .dropdown-menu.sidebar-more-menu {
    position: fixed !important;
    top: auto !important;
    bottom: max(12px, env(safe-area-inset-bottom, 12px)) !important;
    left: 12px !important;
    right: 12px !important;
    margin: 0 !important;
    max-width: calc(100vw - 24px) !important;
    max-height: min(72vh, calc(100vh - 24px)) !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }
}
