/**
 * @file
 * Functional mobile drawer foundation for Tierfreundeskreis.de.
 *
 * The existing Menu-Block-based navigation is reused inside the drawer.
 * Final visual design and detailed spacing are handled in a later phase.
 */

/* --------------------------------------------------------------------------
 * Desktop state
 * -------------------------------------------------------------------------- */

.tfk-mobile-drawer__header,
.tfk-mobile-quicklinks {
  display: none;
}

/*
 * The TFK hamburger is controlled entirely by this project component.
 * It is hidden on desktop and enabled below the mobile breakpoint.
 */
.header--custom-header .tfk-mobile-drawer__toggle {
  display: none;
}

.tfk-mobile-drawer__overlay[hidden] {
  display: none !important;
}

/* --------------------------------------------------------------------------
 * Mobile state
 * -------------------------------------------------------------------------- */

@media (max-width: 991.98px) {
  body.tfk-mobile-drawer-is-open {
    overflow: hidden;
  }

  .header--custom-header .tfk-mobile-drawer__toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .tfk-navigation-shell {
    position: fixed;
    z-index: 1000001;
    top: 0;
    bottom: 0;
    left: 0;

    display: flex;
    flex-direction: column;

    width: min(88vw, 24rem);
    max-width: 100%;
    min-height: 100vh;

    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;

    color: var(--mag-text-primary);
    background: var(--mag-bg-default);
    border-right: 1px solid var(--mag-border);
    box-shadow: 0.75rem 0 2rem rgba(0, 0, 0, 0.22);

    visibility: hidden;
    pointer-events: none;

    transform: translateX(-100%);
    transition:
      transform 220ms ease,
      visibility 220ms ease;
  }

  .header--custom-header.is-mobile-drawer-open
    .tfk-navigation-shell {
    visibility: visible;
    pointer-events: auto;
    transform: translateX(0);
  }

  /* ------------------------------------------------------------------------
   * Drawer header
   * ------------------------------------------------------------------------ */

  .tfk-mobile-drawer__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: 0 0 auto;

    min-height: 4rem;
    padding: 0.75rem 1rem;

    border-bottom: 1px solid var(--mag-divider);
  }

  .tfk-mobile-drawer__title {
    margin: 0;
    color: var(--mag-headline);
    font-family: var(--tfk-font-heading);
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 1.2;
  }

  .tfk-mobile-drawer__close {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    width: 2.75rem;
    height: 2.75rem;
    padding: 0;

    color: var(--mag-text-primary);
    background: transparent;
    border: 0;
    border-radius: 0.25rem;

    font-size: 1.25rem;
  }

  .tfk-mobile-drawer__close:hover,
  .tfk-mobile-drawer__close:focus-visible {
    color: var(--mag-headline);
    background: var(--mag-navigation-bg-hover);
  }

  .tfk-mobile-drawer__close:focus-visible,
  .tfk-mobile-drawer__toggle:focus-visible {
    outline: 2px solid var(--mag-primary);
    outline-offset: 2px;
  }

  /* ------------------------------------------------------------------------
   * Main navigation inside the drawer
   * ------------------------------------------------------------------------ */

  .tfk-navigation-shell .tfk-navigation-desktop {
    display: block;
    flex: 0 0 auto;

    min-width: 0;
    margin: 0;
  }

  .tfk-navigation-shell .region,
  .tfk-navigation-shell .block,
  .tfk-navigation-shell nav {
    margin: 0;
    padding: 0;
  }

  .tfk-navigation-shell .tfk-menu__list {
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .tfk-navigation-shell .tfk-menu__list--root {
    display: block;
    width: 100%;
  }

  .tfk-navigation-shell .tfk-menu__item {
    display: block;
    width: 100%;
    margin: 0;
    padding: 0;
  }

  .tfk-navigation-shell .tfk-menu__item--level-0 {
    border-bottom: 1px solid var(--mag-divider);
  }

  .tfk-navigation-shell .tfk-menu__entry {
    display: flex;
    align-items: stretch;
    width: 100%;
  }

  .tfk-navigation-shell .tfk-menu__link--level-0 {
    display: flex;
    align-items: center;
    flex: 1 1 auto;

    min-width: 0;
    min-height: 3.25rem;
    padding: 0.8rem 1rem;

    color: #474747;
    font-size: 1.125rem;
    font-weight: 400;
    line-height: 1.3;
    text-align: left;
    text-decoration: none;
  }

  .themag-dark
    .tfk-navigation-shell
    .tfk-menu__link--level-0 {
    color: var(--mag-navigation-color);
  }

  .tfk-navigation-shell .tfk-menu__link--level-0:hover,
  .tfk-navigation-shell .tfk-menu__link--level-0:focus-visible,
  .tfk-navigation-shell .tfk-menu__link--level-0.is-active {
    color: var(--mag-navigation-color-hover);
    background: var(--mag-navigation-bg-hover);
  }

  .tfk-navigation-shell .tfk-menu__toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 3.5rem;

    width: 3.5rem;
    min-height: 3.25rem;
    padding: 0;

    color: var(--mag-navigation-color);
    background: transparent;
    border: 0;
    border-left: 1px solid var(--mag-divider);
  }

  .tfk-navigation-shell .tfk-menu__toggle:hover,
  .tfk-navigation-shell .tfk-menu__toggle:focus-visible,
  .tfk-navigation-shell
    .tfk-menu__toggle[aria-expanded="true"] {
    color: var(--mag-navigation-color-hover);
    background: var(--mag-navigation-bg-hover);
  }

  .tfk-navigation-shell .tfk-menu__toggle:focus-visible,
  .tfk-navigation-shell .tfk-menu__link:focus-visible {
    outline: 2px solid var(--mag-primary);
    outline-offset: -2px;
  }

  .tfk-navigation-shell .tfk-menu__toggle-icon {
    display: block;

    width: 0.5rem;
    height: 0.5rem;

    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;

    transform: translateY(-0.1rem) rotate(45deg);
    transform-origin: center;

    transition: transform 160ms ease;
  }

  .tfk-navigation-shell
    .tfk-menu__toggle[aria-expanded="true"]
    .tfk-menu__toggle-icon {
    transform: translateY(0.1rem) rotate(225deg);
  }

  /* ------------------------------------------------------------------------
   * Mobile submenu
   * ------------------------------------------------------------------------ */

  .tfk-navigation-shell .tfk-menu__submenu {
    position: static;

    display: block;
    width: 100%;
    min-width: 0;
    max-width: none;

    margin: 0;
    padding: 0.25rem 0;

    color: var(--mag-navigation-color);
    background: var(--mag-bg-grey-light);
    border: 0;
    border-top: 1px solid var(--mag-divider);
    border-radius: 0;
    box-shadow: none;
  }

  .tfk-navigation-shell .tfk-menu__submenu[hidden] {
    display: none !important;
  }

  .tfk-navigation-shell
    .tfk-menu__item--level-1
    > .tfk-menu__entry {
    display: block;
    width: 100%;
  }

  .tfk-navigation-shell .tfk-menu__link--level-1 {
    display: block;
    width: 100%;
    padding: 0.65rem 1rem 0.65rem 1.5rem;

    color: var(--mag-navigation-color);
    font-size: 0.95rem;
    font-weight: 400;
    line-height: 1.35;
    text-align: left;
    text-decoration: none;
    white-space: normal;
  }

  .tfk-navigation-shell
    .tfk-menu__item--level-1:hover
    > .tfk-menu__entry
    > .tfk-menu__link--level-1,
  .tfk-navigation-shell
    a.tfk-menu__link--level-1:focus-visible,
  .tfk-navigation-shell
    a.tfk-menu__link--level-1.is-active {
    color: var(--mag-navigation-color-hover);
    background: var(--mag-navigation-bg-hover);
  }

  /* ------------------------------------------------------------------------
   * Mobile quicklinks
   * ------------------------------------------------------------------------ */

  .tfk-mobile-quicklinks {
    display: block;
    flex: 0 0 auto;

    margin-top: auto;
    padding: 1rem;

    border-top: 1px solid var(--mag-divider);
    background: var(--mag-bg-grey-light);
  }

  .tfk-mobile-quicklinks__title {
    margin: 0 0 0.75rem;

    color: var(--mag-headline);
    font-size: 0.9rem;
    font-weight: 700;
    line-height: 1.25;
  }

  .tfk-mobile-quicklinks .region,
  .tfk-mobile-quicklinks .block,
  .tfk-mobile-quicklinks nav {
    margin: 0;
    padding: 0;
  }

  .tfk-mobile-quicklinks .block__title {
    display: none;
  }

  .tfk-mobile-quicklinks ul.menu {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;

    margin: 0;
    padding: 0;

    list-style: none;
  }

  .tfk-mobile-quicklinks ul.menu > li {
    margin: 0;
    padding: 0;
  }

  .tfk-mobile-quicklinks ul.menu a,
  .tfk-mobile-quicklinks ul.menu .nolink {
    display: block;
    padding: 0.5rem 0.7rem;

    color: var(--mag-navigation-color);
    background: var(--mag-bg-default);
    border: 1px solid var(--mag-border);
    border-radius: 999px;

    font-size: 0.85rem;
    font-weight: 400;
    line-height: 1.25;
    text-decoration: none;
  }

  .tfk-mobile-quicklinks ul.menu a:hover,
  .tfk-mobile-quicklinks ul.menu a:focus-visible {
    color: var(--mag-navigation-color-hover);
    background: var(--mag-navigation-bg-hover);
  }

  /* ------------------------------------------------------------------------
   * Overlay
   * ------------------------------------------------------------------------ */

  .tfk-mobile-drawer__overlay {
    position: fixed;
    z-index: 1000000;

    inset: 0;

    display: block;

    background: rgba(0, 0, 0, 0.52);
  }
}

/* --------------------------------------------------------------------------
 * Reduced motion
 * -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .tfk-navigation-shell,
  .tfk-navigation-shell .tfk-menu__toggle-icon {
    transition: none;
  }
}