/* Desktop category flyout for the cp_sideverticalmenu drawer.
   Registered from the module's hookDisplayHeader (cp_sideverticalmenu.php).
   Gated to fine-pointer desktop so touch/tablet keep the accordion drawer. */

/* The JS rebuilds tiles in shared markup the mobile accordion also renders, so
   the injected image/header must be desktop-only — otherwise they bloat the
   accordion once the DOM has been enhanced. Desktop rules below re-show them. */
#cp_sidevertical_menu_top .mfp-media,
#cp_sidevertical_menu_top .mfp-head { display: none; }

@media (min-width: 992px) and (hover: hover) and (pointer: fine) {

  :root {
    --mfp-col-width: 327px;
    --mfp-tile-w: 172px;
    --mfp-gap: 14px;
    --mfp-pad: 28px;
  }

  #cp_sidevertical_menu_top.slide { overflow: visible; }
  #cp_sidevertical_menu_top.slide #sidevertical_menu {
    max-height: 100vh;
    overflow-y: auto;
  }

  #cp_sidevertical_menu_top.slide #top-menu > li.mfp-li .collapse-icons { display: none !important; }

  /* position:fixed so the containing block is the drawer (it has a transform),
     not the <li> inside the scrolling column.
     Fixed size (width fits ~5 columns, full viewport height) so the panel looks
     the same regardless of child count; !important beats bootstrap-collapse's
     inline height.
     .mfp-li gates this to items the JS prepared, so anything it couldn't parse
     keeps the drawer's native behaviour instead of a raw fixed panel. */
  #cp_sidevertical_menu_top.slide #top-menu > li.mfp-li > .popover.sub-menu {
    display: none;
    position: fixed;
    top: 0;
    left: var(--mfp-col-width);
    width: min(972px, calc(96vw - var(--mfp-col-width)));
    height: 100vh !important;
    overflow-y: auto;
    margin: 0;
    padding: 24px var(--mfp-pad) 28px;
    background: #fff;
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.12);
    z-index: 5;
  }

  /* .mfp-open is JS-driven; :hover keeps it open while the cursor travels. */
  #cp_sidevertical_menu_top.slide #top-menu > li.mfp-li.mfp-open > .popover.sub-menu,
  #cp_sidevertical_menu_top.slide #top-menu > li.mfp-li:hover > .popover.sub-menu {
    display: block !important;
  }

  /* Animate the CONTENT (not the panel) on every reveal: the opaque white panel
     stays put, so a category switch reads as a soft in-place refresh instead of
     an instant swap — and without the see-through flash a panel-opacity fade
     caused (the cursor never leaves the active zone to "see" a close). */
  #cp_sidevertical_menu_top.slide #top-menu > li.mfp-li.mfp-open > .popover.sub-menu > *,
  #cp_sidevertical_menu_top.slide #top-menu > li.mfp-li:hover > .popover.sub-menu > * {
    animation: mfp-content-in .18s ease both;
  }
  @keyframes mfp-content-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
  }
  @media (prefers-reduced-motion: reduce) {
    #cp_sidevertical_menu_top.slide #top-menu > li.mfp-li.mfp-open > .popover.sub-menu > *,
    #cp_sidevertical_menu_top.slide #top-menu > li.mfp-li:hover > .popover.sub-menu > * {
      animation: none;
    }
  }

  /* ---- Header ------------------------------------------------------------- */
  #cp_sidevertical_menu_top.slide .popover.sub-menu .mfp-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 16px;
    margin: 0 0 18px;
    padding-bottom: 14px;
    border-bottom: 1px solid #eee;
  }
  #cp_sidevertical_menu_top.slide .popover.sub-menu .mfp-title {
    font-size: 18px;
    font-weight: 600;
    line-height: 1.2;
    color: #1f1f1f;
    text-transform: none;
  }
  #cp_sidevertical_menu_top.slide .popover.sub-menu .mfp-all {
    flex: 0 0 auto;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    text-decoration: none;
    text-transform: none;
    color: var(--primary-color, #e30613);
  }
  #cp_sidevertical_menu_top.slide .popover.sub-menu .mfp-all:hover { text-decoration: underline; }

  /* Show only direct children; hide the deeper (depth-2) collapse lists. */
  #cp_sidevertical_menu_top.slide #top-menu > li > .popover.sub-menu .collapse {
    display: none !important;
  }

  /* Kill the module's absolute arrow bullet (a::before) inside the tiles. */
  #cp_sidevertical_menu_top.slide #top-menu > li > .popover.sub-menu ul[data-depth="1"] li a::before {
    content: none !important;
  }
  /* The expander is kept in the DOM for mobile, but has no place in the tile. */
  #cp_sidevertical_menu_top.slide #top-menu > li.mfp-li > .popover.sub-menu .pull-xs-right {
    display: none;
  }

  /* Tiles stretch to fill the fixed-size panel: few children → fewer, wider
     tiles filling the row (so tile width varies between categories). */
  #cp_sidevertical_menu_top.slide #top-menu > li > .popover.sub-menu > ul[data-depth="1"] {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(var(--mfp-tile-w), 1fr));
    gap: var(--mfp-gap);
    margin: 0;
    padding: 0;
    list-style: none;
  }
  #cp_sidevertical_menu_top.slide #top-menu > li > .popover.sub-menu > ul[data-depth="1"] > li {
    margin: 0;
    padding: 0;
    list-style: none;
  }

  /* ---- Tile card ---------------------------------------------------------- */
  #cp_sidevertical_menu_top.slide #top-menu > li > .popover.sub-menu > ul[data-depth="1"] > li > a {
    display: flex !important;
    flex-direction: column;
    align-items: stretch;
    height: 100%;
    padding: 12px 12px 14px;
    background: #fff;
    border: 1px solid #ededed;
    border-radius: 6px;
    transition: border-color .15s, box-shadow .15s, transform .12s;
  }
  #cp_sidevertical_menu_top.slide #top-menu > li > .popover.sub-menu > ul[data-depth="1"] > li > a:hover {
    border-color: rgba(227, 6, 19, .35);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  }

  #cp_sidevertical_menu_top.slide .popover.sub-menu .mfp-media {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 104px;
    margin-bottom: 10px;
    overflow: hidden;
  }
  #cp_sidevertical_menu_top.slide .popover.sub-menu .mfp-img {
    max-width: 100%;
    max-height: 96px;
    object-fit: contain;
    display: block;
    transition: transform .22s ease;
  }
  #cp_sidevertical_menu_top.slide #top-menu > li > .popover.sub-menu > ul[data-depth="1"] > li > a:hover .mfp-img {
    transform: scale(1.06);
  }
  #cp_sidevertical_menu_top.slide .popover.sub-menu .mfp-media--empty {
    background: #f7f7f8;
    border-radius: 4px;
  }
  #cp_sidevertical_menu_top.slide .popover.sub-menu .mfp-media--empty::after {
    content: '';
    width: 30px;
    height: 30px;
    opacity: .28;
    background: center / contain no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='3' width='18' height='18' rx='2'/%3E%3Ccircle cx='8.5' cy='8.5' r='1.5'/%3E%3Cpath d='M21 15l-5-5L5 21'/%3E%3C/svg%3E");
  }

  #cp_sidevertical_menu_top.slide .popover.sub-menu .mfp-label {
    display: block;
    min-height: 2.7em;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.35;
    text-align: center;
    color: #333;
    text-transform: none;
    word-break: normal;
    overflow-wrap: break-word;
    hyphens: auto;
    transition: color .15s;
  }
  #cp_sidevertical_menu_top.slide #top-menu > li > .popover.sub-menu > ul[data-depth="1"] > li > a:hover .mfp-label {
    color: var(--primary-color, #e30613);
  }

  /* Non-category entries (CMS pages, custom links) carry no image — center the
     label so they read as a link tile, not a category with a missing photo. */
  #cp_sidevertical_menu_top.slide .popover.sub-menu a.mfp-tile--link {
    justify-content: center;
  }
  #cp_sidevertical_menu_top.slide .popover.sub-menu a.mfp-tile--link .mfp-label {
    min-height: 0;
  }

  /* Theme gives the top item `padding: 6px 0`, so its label hugs the highlight
     frame; widen the box so the text breathes inside the red state. */
  #cp_sidevertical_menu_top.slide #top-menu > li > a {
    padding: 11px 24px;
  }
  #cp_sidevertical_menu_top.slide #top-menu > li.mfp-open > a,
  #cp_sidevertical_menu_top.slide #top-menu > li:hover > a {
    background: var(--primary-color, #e30613);
    color: #fff;
  }
}
