/* ============================================================================
   AliothPress — Components
   
   All structural UI elements for the public-facing site:
   header, navigation, mobile sidebar, footer, cards, buttons, 
   language switcher, post meta, pagination.
   ============================================================================ */


/* ============================================================================
   1. HEADER
   ============================================================================ */

/* Fixed header: anchor jumps (/#section, :target, scrollIntoView) must land
   BELOW the sticky bar, not underneath it. scroll-padding on the root covers
   every scroll mechanism; the extra 16px is breathing room. */
html {
  scroll-padding-top: calc(var(--ap-header-height) + 16px);
  /* Reserve space for the scrollbar even on short pages. Without this,
     navigating between a page WITH a scrollbar and one WITHOUT shifts the
     whole centered layout (header/nav included) horizontally by the
     scrollbar width — the menu appears to "jump" on page transitions.
     Also keeps the layout stable when the mobile sidebar locks body
     scrolling. Overlay scrollbars (macOS/mobile) have zero width, so no
     gutter is reserved there; unsupported browsers simply ignore this. */
  scrollbar-gutter: stable;
}

/* Fallback for browsers without scrollbar-gutter support (e.g. Safari < 18.2
   with "always show scroll bars" enabled): keep the scrollbar permanently
   visible so the centered layout never shifts between short and long pages.
   Browsers that DO support scrollbar-gutter skip this block entirely. */
@supports not (scrollbar-gutter: stable) {
  html {
    overflow-y: scroll;
  }
}

/* Full-bleed page-builder blocks (.ap-section--full, .ap-slideshow--full,
   .ap-ticker) are sized with 100vw, which INCLUDES the classic scrollbar
   width. With the gutter reserved above, those blocks overhang the content
   area by ~half the scrollbar width and can trigger a small horizontal
   scrollbar on Windows/Linux. `clip` trims that overhang without creating
   a scroll container, so `position: sticky` on the header keeps working
   (unlike `overflow-x: hidden`). Unsupported browsers ignore it. */
body {
  overflow-x: clip;
}

.ap-header {
  background: var(--ap-header-bg);
  color: var(--ap-header-text);
  height: var(--ap-header-height);
  position: sticky;
  top: 0;
  z-index: var(--ap-z-sticky);
  transition: box-shadow var(--ap-transition-normal);
}

.ap-header.is-scrolled {
  box-shadow: var(--ap-shadow-lg);
}

/* iOS/iPadOS (targeted via -webkit-touch-callout, which only WebKit on
   Apple touch devices supports): position: sticky on the header proved
   unreliable there, so these devices get a plain fixed header — immune to
   any ancestor overflow/clip quirks, so the global `overflow-x: clip` on
   body stays untouched. The body is padded by the header height to keep
   content from sliding underneath. Desktop and Android browsers fail the
   @supports check and are untouched. */
@supports (-webkit-touch-callout: none) {
  body {
    padding-top: var(--ap-header-height);
  }

  .ap-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
  }

  /* Owner logged in: the admin bar is its own fixed 36px strip at the very
     top and already moves the header down with `top: 36px`; the body then
     needs both offsets. The bar's stylesheet is inlined in the template
     and loads after this file, so !important is needed to win the
     equal-specificity cascade against its `padding-top: 36px`. */
  html:has(.ap-admin-bar) body {
    padding-top: calc(var(--ap-header-height) + 36px) !important;
  }
}

.ap-header__inner {
  /* Mobile (< 768px): plain flex. Only two items are visible (logo +
     right section) — the desktop nav is display:none — so space-between
     is safe here and there is nothing in the middle to shift. */
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
  gap: var(--ap-space-6);
  max-width: none;
}

@media (min-width: 1024px) {
  /* Desktop (matches the .ap-nav breakpoint in responsive.css): grid with
     symmetric flexible side columns — the nav (middle
     column) is positioned independently of the LOGO and RIGHT-SECTION
     widths. With `flex + space-between`, any width change in a sibling
     (logo image/text finishing to render, language switcher, etc.)
     shifted the nav horizontally on load.
     grid-column is set EXPLICITLY on each child: with auto-placement,
     any hidden/missing sibling (e.g. the nav) would let the next item
     slide into the middle column and land in the center of the header. */
  .ap-header__inner {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
  }

  .ap-header__inner > .ap-logo {
    grid-column: 1;
    justify-self: start;
    min-width: 0;
  }

  .ap-header__inner > .ap-nav {
    grid-column: 2;
    justify-self: center;
  }

  .ap-header__inner > .ap-header__right {
    grid-column: 3;
    justify-self: end;
    min-width: 0;
  }
}

/* Logo */
.ap-logo {
  display: flex;
  align-items: center;
  gap: var(--ap-space-3);
  text-decoration: none;
  color: var(--ap-header-text);
  font-family: var(--ap-font-heading);
  font-size: var(--ap-text-xl);
  font-weight: var(--ap-font-weight-bold);
  white-space: nowrap;
  flex-shrink: 0;
}

.ap-logo:hover {
  color: var(--ap-header-text);
  opacity: 0.9;
}

.ap-logo img {
  max-height: 36px;
  width: auto;
}

@media (max-width: 768px) {
  .ap-logo img {
    max-height: 28px;
  }
}

/* Desktop navigation */
.ap-nav {
  display: flex;
  align-items: center;
  gap: var(--ap-space-1);
}

.ap-nav__link {
  display: inline-flex;
  align-items: center;
  padding: var(--ap-space-2) var(--ap-space-3);
  color: var(--ap-header-link);
  text-decoration: none;
  font-size: var(--ap-text-sm);
  font-weight: var(--ap-font-weight-medium);
  border-radius: var(--ap-radius-md);
  transition: color var(--ap-transition-fast), 
              background-color var(--ap-transition-fast);
  white-space: nowrap;
}

.ap-nav__link:hover,
.ap-nav__link:focus-visible {
  color: var(--ap-header-link-hover);
  background: rgba(255, 255, 255, 0.1);
}

/* Header right section: language + hamburger */
.ap-header__right {
  display: flex;
  align-items: center;
  gap: var(--ap-space-2);
}


/* ============================================================================
   2. LANGUAGE SWITCHER (compact dropdown in header)
   ============================================================================ */

.ap-lang {
  position: relative;
}

.ap-lang__trigger {
  display: inline-flex;
  align-items: center;
  gap: var(--ap-space-1);
  padding: var(--ap-space-1) var(--ap-space-2);
  color: var(--ap-header-link);
  font-size: var(--ap-text-xs);
  font-weight: var(--ap-font-weight-medium);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--ap-radius-sm);
  cursor: pointer;
  transition: all var(--ap-transition-fast);
  background: transparent;
}

.ap-lang__trigger:hover {
  color: var(--ap-header-link-hover);
  border-color: rgba(255, 255, 255, 0.4);
  background: rgba(255, 255, 255, 0.05);
}

.ap-lang__arrow {
  width: 10px;
  height: 10px;
  transition: transform var(--ap-transition-fast);
}

.ap-lang.is-open .ap-lang__arrow {
  transform: rotate(180deg);
}

.ap-lang__dropdown {
  position: absolute;
  top: calc(100% + var(--ap-space-2));
  right: 0;
  min-width: 140px;
  background: var(--ap-color-white);
  border: var(--ap-border-width) solid var(--ap-color-border);
  border-radius: var(--ap-radius-md);
  box-shadow: var(--ap-shadow-lg);
  padding: var(--ap-space-1);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity var(--ap-transition-fast),
              visibility var(--ap-transition-fast),
              transform var(--ap-transition-fast);
  z-index: var(--ap-z-dropdown);
}

.ap-lang.is-open .ap-lang__dropdown {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.ap-lang__option {
  display: block;
  width: 100%;
  padding: var(--ap-space-2) var(--ap-space-3);
  color: var(--ap-color-text);
  font-size: var(--ap-text-sm);
  text-decoration: none;
  border-radius: var(--ap-radius-sm);
  transition: background var(--ap-transition-fast);
}

.ap-lang__option:hover {
  background: var(--ap-color-surface);
  color: var(--ap-color-text);
}

.ap-lang__option.is-active {
  color: var(--ap-color-primary);
  font-weight: var(--ap-font-weight-semibold);
  background: var(--ap-color-primary-subtle);
}


/* ============================================================================
   3. MOBILE HAMBURGER BUTTON
   ============================================================================ */

.ap-hamburger {
  display: none; /* shown via responsive.css */
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  cursor: pointer;
  background: transparent;
  border: none;
  border-radius: var(--ap-radius-md);
  transition: background var(--ap-transition-fast);
}

.ap-hamburger:hover {
  background: rgba(255, 255, 255, 0.1);
}

.ap-hamburger__line {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--ap-header-text);
  border-radius: 1px;
  transition: transform var(--ap-transition-normal),
              opacity var(--ap-transition-normal);
}

.ap-hamburger__line + .ap-hamburger__line {
  margin-top: 5px;
}

/* Animate to X when open */
.ap-hamburger.is-open .ap-hamburger__line:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.ap-hamburger.is-open .ap-hamburger__line:nth-child(2) {
  opacity: 0;
}

.ap-hamburger.is-open .ap-hamburger__line:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}


/* ============================================================================
   4. MOBILE SIDEBAR
   ============================================================================ */

.ap-sidebar-overlay {
  position: fixed;
  inset: 0;
  background: transparent;
  z-index: var(--ap-z-overlay);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--ap-transition-normal),
              visibility var(--ap-transition-normal);
}

.ap-sidebar-overlay.is-visible {
  opacity: 1;
  visibility: visible;
}

.ap-sidebar {
  position: fixed;
  top: var(--ap-header-height);
  right: 0;
  width: 240px;
  height: auto;
  max-height: calc(100dvh - var(--ap-header-height));
  background: var(--ap-color-bg);
  z-index: var(--ap-z-modal);
  transform: translateY(-8px);
  opacity: 0;
  visibility: hidden;
  transition: transform var(--ap-transition-normal) cubic-bezier(0.4, 0, 0.2, 1),
              opacity var(--ap-transition-normal),
              visibility var(--ap-transition-normal);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  border-radius: 0 0 0 var(--ap-radius-lg);
  box-shadow: var(--ap-shadow-xl);
}

.ap-sidebar.is-open {
  transform: translateY(0);
  opacity: 1;
  visibility: visible;
}

.ap-sidebar__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--ap-space-3) var(--ap-space-4);
  border-bottom: var(--ap-border-width) solid var(--ap-color-border);
  flex-shrink: 0;
}

.ap-sidebar__title {
  font-family: var(--ap-font-heading);
  font-size: var(--ap-text-xs);
  font-weight: var(--ap-font-weight-semibold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ap-color-text-muted);
}

.ap-sidebar__close {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--ap-radius-md);
  color: var(--ap-color-text-muted);
  transition: color var(--ap-transition-fast);
}

.ap-sidebar__close:hover {
  color: var(--ap-color-text);
}

.ap-sidebar__nav {
  padding: var(--ap-space-2) 0 var(--ap-space-3);
}

.ap-sidebar__link {
  display: block;
  padding: var(--ap-space-2) var(--ap-space-4);
  color: var(--ap-color-text-secondary);
  font-size: var(--ap-text-sm);
  font-weight: var(--ap-font-weight-medium);
  text-decoration: none;
  border-inline-start: 2px solid transparent;
  transition: color var(--ap-transition-fast),
              border-color var(--ap-transition-fast);
}

.ap-sidebar__link:hover {
  color: var(--ap-color-primary);
  border-inline-start-color: var(--ap-color-primary);
}

.ap-sidebar__footer {
  padding: var(--ap-space-4) var(--ap-space-5);
  border-top: var(--ap-border-width) solid var(--ap-color-border);
  flex-shrink: 0;
}

.ap-sidebar__section-title {
  padding: var(--ap-space-4) var(--ap-space-5) var(--ap-space-2);
  font-size: var(--ap-text-xs);
  font-weight: var(--ap-font-weight-semibold);
  color: var(--ap-color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.ap-sidebar__langs {
  display: flex;
  flex-wrap: wrap;
  gap: var(--ap-space-2);
  padding: var(--ap-space-2) var(--ap-space-5) var(--ap-space-4);
}

.ap-sidebar__lang-link {
  display: inline-flex;
  align-items: center;
  padding: var(--ap-space-1) var(--ap-space-3);
  font-size: var(--ap-text-sm);
  color: var(--ap-color-text-secondary);
  border: var(--ap-border-width) solid var(--ap-color-border);
  border-radius: var(--ap-radius-full);
  text-decoration: none;
  transition: all var(--ap-transition-fast);
}

.ap-sidebar__lang-link:hover {
  border-color: var(--ap-color-primary);
  color: var(--ap-color-primary);
}

.ap-sidebar__lang-link.is-active {
  background: var(--ap-color-primary);
  border-color: var(--ap-color-primary);
  color: var(--ap-color-white);
  font-weight: var(--ap-font-weight-medium);
}


/* ============================================================================
   5. MAIN CONTENT AREA
   ============================================================================ */

.ap-main {
  min-height: 60vh;
  padding: var(--ap-space-12) 0;
}


/* ============================================================================
   6. FOOTER
   ============================================================================ */

.ap-footer {
  background: var(--ap-footer-bg);
  color: var(--ap-footer-text);
  border-top: var(--ap-border-width) solid var(--ap-footer-border);
  padding: var(--ap-space-12) 0 var(--ap-space-8);
}

.ap-footer__inner {
  text-align: center;
  max-width: none;
}

/* Copyright & license */
.ap-footer__copyright {
  font-size: var(--ap-text-sm);
  margin-bottom: var(--ap-space-2);
}

.ap-footer__license {
  font-size: var(--ap-text-sm);
  color: var(--ap-color-text-muted);
  margin-bottom: var(--ap-space-6);
}

/* Social icons */
.ap-footer__socials {
  display: flex;
  justify-content: center;
  gap: var(--ap-space-3);
  margin-bottom: var(--ap-space-6);
}

.ap-social-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--ap-radius-full);
  background: var(--ap-color-surface-alt);
  color: var(--ap-color-text-secondary);
  transition: background var(--ap-transition-fast),
              color var(--ap-transition-fast),
              transform var(--ap-transition-fast);
}

.ap-social-icon:hover {
  transform: translateY(-2px);
}

.ap-social-icon svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* Additional content block */
.ap-footer__additional {
  font-size: var(--ap-text-sm);
  color: var(--ap-color-text-secondary);
  margin-bottom: var(--ap-space-6);
}

/* Footer menu */
.ap-footer__nav {
  padding-top: var(--ap-space-5);
  border-top: var(--ap-border-width) solid var(--ap-color-border);
}

.ap-footer__nav a {
  color: var(--ap-footer-link);
  text-decoration: none;
  font-size: var(--ap-text-sm);
  margin: 0 var(--ap-space-3);
  transition: color var(--ap-transition-fast);
}

.ap-footer__nav a:hover {
  color: var(--ap-footer-link-hover);
}

.ap-footer__nav-sep {
  color: var(--ap-color-text-muted);
  font-size: var(--ap-text-xs);
}

/* "Powered by" footer line — only shown for non-licensed installs.
   Uses --ap-footer-text (not text-muted) for adequate contrast per WCAG AA.
   No opacity — dimming is achieved via the color token alone, which the
   theme designer has already balanced against the footer background. */
.ap-footer__powered {
  margin-top: var(--ap-space-4);
  font-size: var(--ap-text-sm);
  color: var(--ap-footer-text);
}

.ap-footer__powered a {
  color: var(--ap-footer-link);
  text-decoration: underline;
}

.ap-footer__powered a:hover {
  color: var(--ap-footer-link-hover);
}


/* ============================================================================
   PUBLIC PAGE UTILITIES — shared across tag, category, 404, message, hub pages
   Moved out of inline styles to keep markup clean, reduce HTML payload,
   and give theme designers a single place to override presentation.
   ============================================================================ */

/* Empty-state block: "no content / no posts / no categories" */
.ap-empty-state {
  text-align: center;
  padding: var(--ap-space-16) 0;
  color: var(--ap-color-text-muted);
}
.ap-empty-state__hint {
  margin-top: var(--ap-space-3);
}

/* Page header variants */
.ap-page__header--centered {
  text-align: center;
  padding-top: var(--ap-space-10);
}
.ap-page__header--top {
  padding-top: var(--ap-space-10);
}
.ap-page__subtitle {
  color: var(--ap-color-text-secondary);
  margin-top: var(--ap-space-3);
}
.ap-page__meta--spaced {
  margin-bottom: var(--ap-space-3);
}

/* Narrow container for tag/category post lists */
.ap-post-list--narrow {
  max-width: var(--ap-container-narrow);
  margin-inline: auto;
}

/* Hub grid for /categories and /tags index pages */
.ap-hub-grid {
  max-width: var(--ap-container-narrow);
  margin-inline: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: var(--ap-space-5);
  padding: var(--ap-space-8) 0;
}
.ap-hub-card {
  display: block;
  padding: var(--ap-space-5) var(--ap-space-6);
  border: 1px solid var(--ap-color-border);
  border-radius: var(--ap-radius-lg);
  text-decoration: none;
  color: var(--ap-color-text);
  transition: all 0.2s ease;
}
.ap-hub-card__name {
  font-size: var(--ap-text-lg);
  font-weight: 600;
  font-family: var(--ap-font-heading);
  display: block;
}
.ap-hub-card__count {
  font-size: var(--ap-text-sm);
  color: var(--ap-color-text-secondary);
  margin-top: var(--ap-space-1);
  display: block;
}

/* 404 page */
.ap-404 {
  text-align: center;
  padding: var(--ap-space-24) 0;
}
.ap-404__code {
  font-size: 4.5rem;
  color: var(--ap-color-text-muted);
  font-family: var(--ap-font-heading);
}
.ap-404__title {
  margin: var(--ap-space-5) 0;
  color: var(--ap-color-text);
}
.ap-404__description {
  color: var(--ap-color-text-secondary);
  margin-bottom: var(--ap-space-8);
}

/* Simple message page (e.g. post-subscription confirmation) */
.ap-message-page {
  text-align: center;
  padding: var(--ap-space-24) 0;
}
.ap-message-page__title {
  font-size: 2rem;
  color: var(--ap-color-text);
  font-family: var(--ap-font-heading);
  margin: 0 0 var(--ap-space-5);
}
.ap-message-page__body {
  color: var(--ap-color-text-secondary);
  margin-bottom: var(--ap-space-8);
}

/* Home page */
.ap-home__header {
  text-align: center;
  padding: var(--ap-space-16) 0 var(--ap-space-10);
}
.ap-home__tagline {
  font-size: var(--ap-text-xl);
  color: var(--ap-color-text-secondary);
  margin-top: var(--ap-space-4);
}
.ap-home__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
  gap: var(--ap-space-8);
}

/* Post card — grid variant (home page) and image handling */
.ap-post-card--grid {
  border-bottom: none;
}
.ap-post-card__image-wrap {
  border-radius: var(--ap-radius-lg);
  overflow: hidden;
  margin-bottom: var(--ap-space-4);
}
.ap-post-card__image {
  width: 100%;
  height: 200px;
  object-fit: cover;
  display: block;
}

/* Inherit-color link used in post meta (category link) */
.ap-link-plain {
  color: inherit;
  text-decoration: none;
}


/* ============================================================================
   7. POST CARD (for blog listing)
   ============================================================================ */

.ap-post-card {
  padding: var(--ap-space-6) 0;
  border-bottom: var(--ap-border-width) solid var(--ap-color-border);
}

.ap-post-card:last-child {
  border-bottom: none;
}

.ap-post-card__title {
  font-family: var(--ap-font-heading);
  font-size: var(--ap-text-2xl);
  font-weight: var(--ap-font-weight-bold);
  line-height: var(--ap-leading-tight);
  margin-bottom: var(--ap-space-2);
}

.ap-post-card__title a {
  color: var(--ap-color-text);
  text-decoration: none;
  transition: color var(--ap-transition-fast);
}

.ap-post-card__title a:hover {
  color: var(--ap-color-primary);
}

.ap-post-card__meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--ap-space-3);
  font-size: var(--ap-text-sm);
  color: var(--ap-color-text-muted);
  margin-bottom: var(--ap-space-3);
}

.ap-post-card__excerpt {
  font-size: var(--ap-text-base);
  color: var(--ap-color-text-secondary);
  line-height: var(--ap-leading-normal);
}

.ap-post-card__read-more {
  display: inline-flex;
  align-items: center;
  gap: var(--ap-space-1);
  margin-top: var(--ap-space-3);
  font-size: var(--ap-text-sm);
  font-weight: var(--ap-font-weight-medium);
  color: var(--ap-color-primary);
  text-decoration: none;
}

.ap-post-card__read-more:hover {
  color: var(--ap-color-primary-hover);
}

.ap-post-card__read-more svg {
  width: 16px;
  height: 16px;
  transition: transform var(--ap-transition-fast);
}

.ap-post-card__read-more:hover svg {
  transform: translateX(3px);
}

/* RTL: flip read-more arrow direction and hover */
[dir="rtl"] .ap-post-card__read-more svg {
  transform: scaleX(-1);
}
[dir="rtl"] .ap-post-card__read-more:hover svg {
  transform: scaleX(-1) translateX(3px);
}


/* ============================================================================
   8. ARTICLE PAGE (single post/page view)
   ============================================================================ */

.ap-article {
  max-width: var(--ap-container-narrow);
  margin-inline: auto;
}

.ap-article__header {
  text-align: center;
  margin-bottom: var(--ap-space-8);
}

.ap-article__title {
  font-family: var(--ap-font-heading);
  font-size: var(--ap-text-4xl);
  font-weight: var(--ap-font-weight-bold);
  line-height: var(--ap-leading-tight);
  margin-bottom: var(--ap-space-4);
}

.ap-article__meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--ap-space-4);
  font-size: var(--ap-text-sm);
  color: var(--ap-color-text-muted);
}

.ap-article__featured-img {
  margin-bottom: var(--ap-space-8);
  border-radius: var(--ap-radius-lg);
  overflow: hidden;
}

.ap-article__featured-img img {
  width: 100%;
  height: auto;
  display: block;
}

.ap-article__featured-img figcaption {
  text-align: center;
  font-size: var(--ap-text-sm);
  color: var(--ap-color-text-muted);
  margin-top: var(--ap-space-2);
}

.ap-article__tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--ap-space-2);
  margin-top: var(--ap-space-10);
  padding-top: var(--ap-space-6);
  border-top: var(--ap-border-width) solid var(--ap-color-border);
}

.ap-tag {
  display: inline-flex;
  align-items: center;
  padding: var(--ap-space-1) var(--ap-space-3);
  font-size: var(--ap-text-xs);
  font-weight: var(--ap-font-weight-medium);
  color: var(--ap-color-primary);
  background: var(--ap-color-primary-subtle);
  border-radius: var(--ap-radius-full);
  text-decoration: none;
  transition: background var(--ap-transition-fast);
}

.ap-tag:hover {
  background: var(--ap-color-primary-light);
  color: var(--ap-color-primary);
}


/* ============================================================================
   9. PAGINATION
   ============================================================================ */

.ap-pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: var(--ap-space-2);
  padding: var(--ap-space-10) 0 var(--ap-space-4);
}

.ap-pagination a,
.ap-pagination span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  padding: 0 var(--ap-space-3);
  font-size: var(--ap-text-sm);
  border-radius: var(--ap-radius-md);
  text-decoration: none;
  transition: all var(--ap-transition-fast);
}

.ap-pagination a {
  color: var(--ap-color-text-secondary);
  border: var(--ap-border-width) solid var(--ap-color-border);
}

.ap-pagination a:hover {
  color: var(--ap-color-primary);
  border-color: var(--ap-color-primary);
  background: var(--ap-color-primary-subtle);
}

.ap-pagination .is-current {
  background: var(--ap-color-primary);
  color: var(--ap-color-white);
  border: var(--ap-border-width) solid var(--ap-color-primary);
  font-weight: var(--ap-font-weight-semibold);
}

.ap-pagination svg {
  width: 16px;
  height: 16px;
}

/* RTL: flip pagination arrows */
[dir="rtl"] .ap-pagination svg {
  transform: scaleX(-1);
}


/* ============================================================================
   10. THEME TOGGLE (dark/light switcher)
   ============================================================================ */

.ap-theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--ap-radius-full);
  color: var(--ap-header-link);
  cursor: pointer;
  transition: background var(--ap-transition-fast),
              color var(--ap-transition-fast);
  background: transparent;
  border: none;
  padding: 0;
  flex-shrink: 0;
}

.ap-theme-toggle:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--ap-header-link-hover);
}

/* Dark mode (default): show sun, hide moon */
.ap-theme-toggle__sun  { display: block; }
.ap-theme-toggle__moon { display: none; }

/* Light mode: show moon, hide sun */
.light-theme .ap-theme-toggle__sun  { display: none; }
.light-theme .ap-theme-toggle__moon { display: block; }

.light-theme .ap-theme-toggle {
  color: var(--ap-header-link);
}

.light-theme .ap-theme-toggle:hover {
  background: rgba(0, 0, 0, 0.06);
  color: var(--ap-header-link-hover);
}


/* ============================================================================
   11. BUTTONS
   ============================================================================ */

.ap-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--ap-space-2);
  padding: var(--ap-space-2) var(--ap-space-4);
  font-family: var(--ap-font-body);
  font-size: var(--ap-text-sm);
  font-weight: var(--ap-font-weight-medium);
  line-height: var(--ap-leading-tight);
  border-radius: var(--ap-radius-md);
  border: var(--ap-border-width) solid transparent;
  cursor: pointer;
  transition: all var(--ap-transition-fast);
  text-decoration: none;
  white-space: nowrap;
}

/* Sizes */
.ap-btn--sm {
  padding: var(--ap-space-1) var(--ap-space-3);
  font-size: var(--ap-text-sm);
}

.ap-btn--md {
  padding: var(--ap-space-2) var(--ap-space-5);
  font-size: var(--ap-text-base);
}

.ap-btn--lg {
  padding: var(--ap-space-3) var(--ap-space-6);
  font-size: var(--ap-text-lg);
}

.ap-btn--primary {
  background: var(--ap-color-primary);
  color: var(--ap-color-text-inverse);
}

.ap-btn--primary:hover {
  background: var(--ap-color-primary-hover);
  color: var(--ap-color-text-inverse);
}

.ap-btn--outline {
  background: transparent;
  color: var(--ap-color-primary);
  border-color: var(--ap-color-primary);
}

.ap-btn--outline:hover {
  background: var(--ap-color-primary);
  color: var(--ap-color-text-inverse);
}

.ap-btn--ghost {
  background: transparent;
  color: var(--ap-color-text-secondary);
}

.ap-btn--ghost:hover {
  background: var(--ap-color-surface);
  color: var(--ap-color-text);
}


/* ============================================================================
   DROPDOWN NAVIGATION — Multi-level menu support
   
   All values use CSS custom properties — themes work automatically.
   ============================================================================ */

.ap-nav__item {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.ap-nav__link--parent {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}

.ap-nav__dropdown-arrow {
  transition: transform 0.2s ease;
  opacity: 0.7;
  flex-shrink: 0;
}

.ap-nav__link--parent[aria-expanded="true"] .ap-nav__dropdown-arrow {
  transform: rotate(180deg);
}

.ap-nav__dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(-4px);
  min-width: 160px;
  background: var(--ap-header-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--ap-color-border);
  border-radius: var(--ap-radius-md);
  box-shadow: var(--ap-shadow-lg);
  padding: 4px 0;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s;
  z-index: var(--ap-z-dropdown);
}

.ap-nav__dropdown.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

.ap-nav__dropdown::before {
  content: '';
  position: absolute;
  top: -10px;
  left: 0;
  right: 0;
  height: 10px;
}

.ap-nav__dropdown-item {
  display: block;
  padding: 6px 14px;
  color: var(--ap-header-link);
  text-decoration: none;
  font-size: var(--ap-text-sm);
  white-space: nowrap;
  transition: background var(--ap-transition-fast), color var(--ap-transition-fast);
}

.ap-nav__dropdown-item:hover,
.ap-nav__dropdown-item:focus-visible {
  background: var(--ap-color-primary-subtle);
  color: var(--ap-header-link-hover);
}

/* ── Long dropdowns: multi-column on desktop ──────────────────────────────
   Classes are set server-side in base.html from the number of children:
   8+ → 2 columns, 16+ → 3 columns. Items flow top-to-bottom, then wrap to
   the next column. Mobile is untouched — the sidebar accordion is separate
   markup and stays vertical and scrollable. Only theme variables are used,
   so all themes and light/dark pick this up unchanged. */

.ap-nav__dropdown--cols-2,
.ap-nav__dropdown--cols-3 {
  column-gap: 0;
  padding-block: var(--ap-space-2);
  max-width: calc(100vw - 32px);
}

.ap-nav__dropdown--cols-2 { column-count: 2; width: 400px; }
.ap-nav__dropdown--cols-3 { column-count: 3; width: 580px; }

/* In multi-column mode long labels wrap instead of overflowing the column,
   and no item or subitem may be split across a column break. */
.ap-nav__dropdown--cols-2 .ap-nav__dropdown-item,
.ap-nav__dropdown--cols-3 .ap-nav__dropdown-item {
  white-space: normal;
  overflow-wrap: break-word;
  break-inside: avoid;
}

/* A child together with its inline grandchildren; never split by a column
   break. The sub-list is hidden until hover/tap opens it, expanding BELOW
   the parent and pushing the following items down — the same accordion
   behaviour as the mobile sidebar. */
.ap-nav__group {
  break-inside: avoid;
}

.ap-nav__group-sub {
  display: none;
}

.ap-nav__group-sub.is-open {
  display: block;
}

.ap-nav__dropdown-item--parent[aria-expanded="true"] .ap-nav__dropdown-arrow {
  transform: rotate(180deg);
}

.ap-nav__dropdown-item--sub {
  padding-inline-start: calc(14px + var(--ap-space-4));
  font-size: var(--ap-text-xs);
  color: var(--ap-color-text-muted);
}

/* Edge pinning for wide dropdowns (set by the edge-detection JS in
   base.html): near a viewport edge the centered position is replaced by
   pinning to the corresponding edge of the trigger item. */
.ap-nav__dropdown--pin-end {
  left: auto;
  right: 0;
  transform: translateY(-4px);
}

.ap-nav__dropdown--pin-start {
  left: 0;
  right: auto;
  transform: translateY(-4px);
}

.ap-nav__dropdown--pin-end.is-open,
.ap-nav__dropdown--pin-start.is-open {
  transform: translateY(0);
}

/* ── Sidebar split rows: label navigates, arrow toggles ──────────────────
   A parent item is a flex row — the label is a normal link, the chevron is
   a separate toggle button, so items with children are reachable by tap. */
.ap-sidebar__row {
  display: flex;
  align-items: center;
}

.ap-sidebar__row .ap-sidebar__link,
.ap-sidebar__row .ap-sidebar__submenu-item {
  flex: 1;
  min-width: 0;
}

.ap-sidebar__toggle {
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  padding: var(--ap-space-3) var(--ap-space-4);
  color: var(--ap-color-text);
}

.ap-sidebar__row--sub .ap-sidebar__toggle {
  padding-block: var(--ap-space-1);
  color: var(--ap-color-text-muted);
}

.ap-sidebar__toggle.is-open .ap-sidebar__submenu-arrow {
  transform: rotate(180deg);
}

/* ── Mobile sidebar submenus ── */

.ap-sidebar__link--parent {
  background: none;
  border: none;
  width: 100%;
  text-align: start;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font: inherit;
  padding: var(--ap-space-3) var(--ap-space-5);
  color: var(--ap-color-text);
}

.ap-sidebar__submenu-arrow {
  transition: transform 0.2s ease;
  flex-shrink: 0;
  opacity: 0.6;
}

.ap-sidebar__link--parent.is-open .ap-sidebar__submenu-arrow {
  transform: rotate(180deg);
}

.ap-sidebar__submenu {
  padding-block: var(--ap-space-1);
  padding-inline: var(--ap-space-4) 0;
  border-inline-start: 1px solid var(--ap-color-border);
  margin-block: 0 var(--ap-space-1);
  margin-inline: var(--ap-space-4) 0;
}

.ap-sidebar__submenu-item {
  display: block;
  padding: var(--ap-space-1) var(--ap-space-3);
  color: var(--ap-color-text-muted);
  text-decoration: none;
  font-size: var(--ap-text-xs);
  font-weight: var(--ap-font-weight-medium);
  letter-spacing: 0.01em;
  transition: color var(--ap-transition-fast);
}

.ap-sidebar__submenu-item:hover {
  color: var(--ap-color-primary);
}

/* ── Second-level submenus (grandchildren), 2.3.4 ─────────────────────────
   Desktop: a side flyout attached to a dropdown item. Mobile sidebar: one
   more accordion tier. Uses ONLY theme variables — every bundled theme and
   any custom theme built on the same variables picks these up unchanged. */
.ap-nav__subitem {
  position: relative;
}

.ap-nav__dropdown-item--parent {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--ap-space-2);
}

.ap-nav__flyout-arrow {
  flex-shrink: 0;
  opacity: 0.6;
}

.ap-nav__flyout {
  position: absolute;
  top: calc(-1 * var(--ap-space-1));
  left: 100%;
  margin-left: 2px;
  min-width: 160px;
  background: var(--ap-header-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--ap-color-border);
  border-radius: var(--ap-radius-md);
  box-shadow: var(--ap-shadow-lg);
  padding: 4px 0;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateX(-4px);
  transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s;
  z-index: var(--ap-z-dropdown);
}

.ap-nav__flyout.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateX(0);
}

/* Near the right viewport edge the flyout flips to the left side (set by
   the edge-detection JS in base.html). */
.ap-nav__flyout--left {
  left: auto;
  right: 100%;
  margin-left: 0;
  margin-right: 2px;
  transform: translateX(4px);
}

.ap-nav__flyout--left.is-open {
  transform: translateX(0);
}

/* Mobile sidebar, third tier: same accordion pattern, one more indent. */
.ap-sidebar__sublink--parent {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: var(--ap-space-1) var(--ap-space-3);
  background: none;
  border: none;
  color: var(--ap-color-text-muted);
  font-size: var(--ap-text-xs);
  font-weight: var(--ap-font-weight-medium);
  letter-spacing: 0.01em;
  text-align: start;
  cursor: pointer;
  transition: color var(--ap-transition-fast);
}

.ap-sidebar__sublink--parent:hover {
  color: var(--ap-color-primary);
}

.ap-sidebar__subsubmenu {
  padding-inline: var(--ap-space-3) 0;
  margin-inline: var(--ap-space-3) 0;
}


/* ============================================================================
   RTL SUPPORT — Arabic, Hebrew
   ============================================================================ */

/* Language dropdown: open from left side */
[dir="rtl"] .ap-lang__dropdown {
  right: auto;
  left: 0;
}

/* Mobile sidebar: slide from left */
[dir="rtl"] .ap-sidebar {
  right: auto;
  left: 0;
}

/* ── FAQ Accordion (AEO) ── */
.ap-faq {
  margin-top: var(--ap-space-8);
}

.ap-faq__title {
  font-family: var(--ap-font-heading);
  font-size: var(--ap-text-xl);
  font-weight: var(--ap-font-weight-bold);
  color: var(--ap-color-text);
  margin-bottom: var(--ap-space-4);
}

.ap-faq__items {
  border: var(--ap-border-width) solid var(--ap-color-border);
  border-radius: var(--ap-radius-lg);
  overflow: hidden;
}

.ap-faq__item {
  border-bottom: var(--ap-border-width) solid var(--ap-color-border);
}

.ap-faq__item:last-child {
  border-bottom: none;
}

.ap-faq__question {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--ap-space-4) var(--ap-space-5);
  font-family: var(--ap-font-body);
  font-weight: var(--ap-font-weight-semibold);
  font-size: var(--ap-text-base);
  cursor: pointer;
  color: var(--ap-color-text);
  background: var(--ap-color-surface);
  transition: background var(--ap-transition-fast);
  list-style: none;
}

.ap-faq__question::-webkit-details-marker {
  display: none;
}

.ap-faq__question::after {
  content: '';
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--ap-color-text-muted);
  border-bottom: 2px solid var(--ap-color-text-muted);
  transform: rotate(45deg);
  transition: transform var(--ap-transition-fast);
  flex-shrink: 0;
  margin-left: var(--ap-space-3);
}

.ap-faq__item[open] .ap-faq__question::after {
  transform: rotate(-135deg);
}

.ap-faq__question:hover {
  background: var(--ap-color-primary-subtle);
}

.ap-faq__answer {
  padding: var(--ap-space-4) var(--ap-space-5);
  color: var(--ap-color-text-secondary);
}

/* RTL: flip chevron margin */
[dir="rtl"] .ap-faq__question::after {
  margin-left: 0;
  margin-right: var(--ap-space-3);
}
