/*
   * Nav escritorio solo desde 1120px (lg). Por debajo: hamburguesa + panel —
   * evita solapamientos en iPad vertical y tablets estrechas.
   */
  .topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    width: 100%;
    box-sizing: border-box;
    background: #ffffff;
    padding-top: env(safe-area-inset-top, 0);
    padding-bottom: 0;
    border-bottom: 1px solid transparent;
    transition: background 0.3s ease, border-color 0.3s ease, color 0.3s ease;
  }

  /* Blur en pseudo: no compone el mismo stacking context que el flex interno (mejor en Safari iOS). */
  .topbar.topbar--scrolled:not(.topbar--light)::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
  }

  .topbar--scrolled {
    background: #ffffff;
    border-bottom-color: #E8E3D9;
  }

  /* Home sobre hero: transparente y elementos blancos */
  .topbar.topbar--light {
    background: transparent;
    border-bottom-color: transparent;
  }

  .topbar--light .topbar__nav-link,
  .topbar--light .topbar__icon,
  .topbar--light .topbar__lang-link {
    color: #fff;
  }

  .topbar--light .topbar__nav-link:hover,
  .topbar--light .topbar__icon:hover,
  .topbar--light .topbar__lang-link:hover {
    color: #FF8C00;
  }

  .topbar--light .topbar__lang-active,
  .topbar--light .topbar__lang-sep {
    color: rgba(255, 255, 255, 0.6);
  }

  .topbar--light .topbar__logo-img {
    filter: brightness(0) invert(1);
  }

  /* Mismo criterio que la galería (/obras): ancho completo + solo var(--px) desde el viewport.
     Sin max-width centrado: en pantallas > --max-w el inner centrado desalineaba el logo respecto a los filtros. */
  .topbar__inner {
    position: relative;
    z-index: 1;
    box-sizing: border-box;
    width: 100%;
    max-width: none;
    margin-left: 0;
    margin-right: 0;
    padding-left: max(env(safe-area-inset-left, 0px), var(--px, 2rem));
    padding-right: max(env(safe-area-inset-right, 0px), var(--px, 2rem));
    /* Margen respecto al borde del header (el safe-area ya va en .topbar).
       padding vertical simétrico: si top ≠ bottom, el centro de la caja (usado por nav/logo absolute)
       no coincide con el centro del área flex de .topbar__actions. */
    padding-top: calc(1.5rem + 20px);
    padding-bottom: 1.5rem;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    min-height: 4.35rem;
    gap: 1rem;
  }

  /* Móvil: mismo criterio que laterales — max(safe-area, --px); el safe-area superior no se duplica en .topbar */
  @media (max-width: 1119px) {
    .topbar {
      padding-top: 0;
    }

    .topbar__inner {
      padding-top: max(env(safe-area-inset-top, 0px), var(--px, 2rem));
      padding-bottom: max(env(safe-area-inset-bottom, 0px), var(--px, 2rem));
      /* Columna central acotada: el logo no puede invadir lupa ni hamburguesa */
      grid-template-columns: minmax(0, 1fr) minmax(0, min(42vw, 7.75rem)) minmax(0, 1fr);
      column-gap: 0.35rem;
      row-gap: 0.35rem;
    }

    .topbar__hamburger {
      justify-self: start;
      align-self: center;
      position: relative;
      z-index: 1;
      width: max-content;
      max-width: 100%;
      min-width: 0;
    }

    .topbar__logo {
      justify-self: stretch;
      align-self: center;
      position: relative;
      z-index: 0;
      min-width: 0;
      max-width: 100%;
      width: 100%;
      display: flex;
      justify-content: center;
      align-items: center;
      overflow: hidden;
    }

    .topbar__logo-img {
      max-width: 100%;
      height: 40px;
      width: auto;
      object-fit: contain;
    }

    /* Búsqueda → cuenta → carrito; sin huecos extra entre iconos */
    .topbar__actions {
      justify-self: end;
      align-self: center;
      display: flex;
      flex-direction: row;
      flex-wrap: nowrap;
      align-items: center;
      justify-content: flex-end;
      gap: 2px;
      width: max-content;
      max-width: 100%;
      min-width: 0;
      margin: 0;
      padding: 0;
      flex-shrink: 0;
      position: relative;
      z-index: 1;
    }
  }

  @media (min-width: 1120px) {
    /*
      Nav y logo en absolute respecto a .topbar__inner → misma altura visual que .topbar__actions
      (antes el nav usaba .topbar y quedaba desfasado respecto a la franja del inner).
      Logo: --mad-logo-left en el inner (JS).
    */
    .topbar__inner {
      position: relative;
      /* Grid 1fr auto 1fr: logo centrado en su columna izquierda (entre el borde y el
         nav) — 100% CSS, sin JS. El nav (auto) queda centrado entre las dos columnas 1fr. */
      display: grid;
      grid-template-columns: 1fr auto 1fr;
      align-items: center;
      min-height: 4.85rem;
      /* Con grid + align-items:center el padding es simétrico (antes era asimétrico
         para compensar el centrado absoluto top:50%). */
      padding-top: 1.5rem;
      padding-bottom: 1.5rem;
    }

    .topbar__hamburger,
    .topbar__logo,
    .topbar__nav,
    .topbar__actions {
      grid-column: unset;
    }

    .topbar__logo {
      justify-self: center;
      position: static;
      transform: none;
      z-index: 2;
    }

    .topbar__nav {
      position: static;
      justify-self: center;
      transform: none;
      z-index: 1;
      width: max-content;
      max-width: 100%;
    }

    /* Mismo criterio vertical que nav/logo: centro del .topbar__inner (padding box), pese a padding top/bottom distinto */
    .topbar__actions {
      position: static;
      justify-self: end;
      transform: none;
      z-index: 2;
      flex-direction: row;
      flex-wrap: nowrap;
      gap: 1.5rem;
      width: auto;
      max-width: none;
    }
  }

  /* Hamburger - visible solo móvil; primera columna del grid móvil */
  .topbar__hamburger {
    justify-self: start;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
    width: auto;
    min-width: 2.25rem;
    padding: 0;
    background: none;
    border: none;
    cursor: pointer;
    transition: transform 0.2s;
    color: #2d0b3d;
  }

  .topbar__hamburger-label {
    font-family: 'Google Sans', sans-serif;
    font-weight: 700;
    font-size: 0.65rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    line-height: 1;
    color: inherit;
  }

  .topbar__hamburger-bars {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    width: 2.25rem;
    height: 1.125rem;
    flex-shrink: 0;
  }

  .topbar--light .topbar__hamburger {
    color: #fff;
  }

  @media (min-width: 1120px) {
    .topbar__hamburger {
      display: none;
    }
  }

  .topbar__hamburger-line {
    display: block;
    width: 100%;
    height: 3px;
    border-radius: 1px;
    background: currentColor;
    transition: transform 0.3s ease, opacity 0.3s ease;
  }

  body.topbar-mobile-open .topbar__hamburger-bars .topbar__hamburger-line:nth-child(1) {
    transform: translateY(0.5625rem) rotate(45deg);
  }

  body.topbar-mobile-open .topbar__hamburger-bars .topbar__hamburger-line:nth-child(2) {
    opacity: 0;
  }

  body.topbar-mobile-open .topbar__hamburger-bars .topbar__hamburger-line:nth-child(3) {
    transform: translateY(-0.5625rem) rotate(-45deg);
  }

  /* Logo: columna central en móvil (justify-self); desktop usa absolute + --mad-logo-left */
  .topbar__logo {
    justify-self: center;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    transition: opacity 0.25s ease;
  }

  .topbar__logo:hover {
    opacity: 0.85;
  }

  .topbar__logo-img {
    height: 40px;
    width: auto;
    max-width: min(40vw, 10.5rem);
    object-fit: contain;
    display: block;
  }

  @media (min-width: 1120px) {
    .topbar__logo-img {
      height: 48px;
      max-width: none;
    }
  }

  /* Nav links - oculto en móvil */
  .topbar__nav {
    display: none;
    align-items: center;
    gap: clamp(0.75rem, 1.25vw, 1.25rem);
    flex-wrap: nowrap;
    white-space: nowrap;
    min-width: 0;
  }

  @media (min-width: 1120px) {
    .topbar__nav {
      display: flex;
      justify-content: center;
      align-items: center;
      gap: clamp(1.15rem, 2vw, 2rem);
    }
  }

  .topbar__nav-link {
    font-family: 'Google Sans', sans-serif;
    font-weight: 700;
    font-size: clamp(0.96rem, 1.08vw, 1.14rem);
    letter-spacing: 0.09em;
    color: #2D0B3D;
    text-transform: uppercase;
    transition: color 0.3s ease;
    white-space: nowrap;
    flex-shrink: 0;
  }

  @media (min-width: 1120px) {
    .topbar__nav-link {
      line-height: 1;
      display: inline-flex;
      align-items: center;
    }
  }

  .topbar__nav-link:hover {
    color: #FF8C00;
  }

  /* Actions: search, cuenta, carrito - visibles en móvil y desktop */
  .topbar__actions {
    justify-self: end;
    display: flex;
    align-items: center;
    gap: 1.5rem;
  }

  .topbar__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #2D0B3D;
    transition: color 0.3s ease, transform 0.2s ease;
  }

  .topbar__icon:hover {
    color: #FF8C00;
  }

  .topbar__icon:active {
    transform: scale(0.95);
  }

  .topbar__icon--search {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
  }

  .topbar__icon--cart {
    overflow: visible;
  }

  .topbar__cart-icon-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    flex-shrink: 0;
  }

  .topbar__cart-badge {
    display: none;
    box-sizing: border-box;
    position: absolute;
    top: -6px;
    right: -8px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    align-items: center;
    justify-content: center;
    background: #ff8c00;
    color: #fff;
    font-family: 'Montserrat', system-ui, sans-serif;
    font-size: 0.65rem;
    font-weight: 600;
    border-radius: 50%;
    line-height: 1;
    z-index: 1;
  }

  .topbar__cart-badge[data-visible='1'] {
    display: flex;
  }

  /* Pequeño "pop" al actualizar el contador tras agregar una obra */
  .topbar__cart-badge.is-bump {
    animation: madBadgePop 0.35s ease;
  }
  @keyframes madBadgePop {
    0%   { transform: scale(1); }
    40%  { transform: scale(1.35); }
    100% { transform: scale(1); }
  }
  @media (prefers-reduced-motion: reduce) {
    .topbar__cart-badge.is-bump { animation: none; }
  }

  /* Language switcher - desktop only */
  .topbar__lang-wrap {
    display: none;
  }

  @media (min-width: 1120px) {
    .topbar__lang-wrap {
      display: inline-flex;
      align-items: center;
      gap: 0.35rem;
    }

    .topbar__lang-inner {
      display: inline-flex;
      align-items: center;
      gap: 0.35rem;
    }

    .topbar__lang-link--desktop {
      font-family: 'Google Sans', sans-serif;
      font-weight: 600;
      font-size: 0.85rem;
      letter-spacing: 0.1em;
      text-transform: uppercase;
      color: #2D0B3D;
      text-decoration: none;
      transition: color 0.2s ease;
    }

    .topbar__lang-link--desktop:hover {
      color: #E07B39;
    }

    .topbar__lang-active {
      font-family: 'Google Sans', sans-serif;
      font-weight: 600;
      font-size: 0.85rem;
      letter-spacing: 0.1em;
      text-transform: uppercase;
      color: rgba(45, 11, 61, 0.5);
    }

    .topbar__lang-sep {
      font-size: 0.8rem;
      color: rgba(45, 11, 61, 0.4);
    }
  }

  /* Panel lateral móvil */
  .topbar__mobile-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1998;
    /* Misma lectura visual que `.search-overlay__glass` al abrir búsqueda */
    background: rgba(18, 18, 18, 0.45);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
  }

  @media (min-width: 1120px) {
    .topbar__mobile-overlay,
    .topbar__mobile-panel {
      display: none !important;
    }
  }

  .topbar__mobile-overlay[aria-hidden="false"] {
    display: block;
    opacity: 1;
    visibility: visible;
  }

  .topbar__mobile-panel {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    max-width: 85vw;
    z-index: 1999;
    border-right: 1px solid rgba(255, 255, 255, 0.12);
    transform: translateX(-100%) translateZ(0);
    -webkit-transform: translateX(-100%) translateZ(0);
    transition: transform 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    overflow: hidden;
    isolation: isolate;
    display: flex;
    flex-direction: column;
  }

  .topbar__mobile-panel[aria-hidden='false'] {
    transform: translateX(0) translateZ(0);
    -webkit-transform: translateX(0) translateZ(0);
  }

  /* Idéntico a `.search-overlay__glass` (SearchOverlay.astro): antes era cristal blanco + enlaces blancos (sin contraste). */
  .topbar__mobile-panel-glass {
    position: absolute;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background: rgba(18, 18, 18, 0.45);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
  }

  .topbar__mobile-panel-scroll {
    position: relative;
    z-index: 1;
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    /* Mismo margen izq/der: un solo valor para ambos lados + safe-area simétrico */
    padding-top: calc(5.5rem + env(safe-area-inset-top, 0px));
    padding-bottom: max(2rem, env(safe-area-inset-bottom, 0px));
    padding-inline: max(1.5rem, env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px));
    scrollbar-width: thin;
    display: flex;
    flex-direction: column;
  }

  .topbar__mobile-panel-scroll::-webkit-scrollbar {
    width: 6px;
  }

  .topbar__mobile-panel-scroll::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.22);
    border-radius: 3px;
  }

  .topbar__mobile-nav {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
    flex: 1;
    text-align: left;
  }

  .topbar__mobile-lang {
    margin-top: auto;
    padding-top: 2rem;
    border-top: 1px solid rgba(255, 255, 255, 0.14);
  }

  .topbar__lang-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    text-align: center;
    text-decoration: none;
    width: 100%;
    min-height: 44px;
    padding: 0.75rem 0;
    font-family: 'Google Sans', sans-serif;
    font-weight: 600;
    font-size: 0.9rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: #fff;
    background: none;
    border: 1px solid rgba(255, 255, 255, 0.5);
    cursor: pointer;
    transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
  }

  .topbar__lang-btn:hover {
    color: #f8b478;
    border-color: #f8b478;
  }

  .topbar__mobile-link {
    font-family: 'Google Sans', sans-serif;
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.95);
    min-height: 44px;
    padding: 0.75rem 0;
    transition: color 0.2s ease;
    text-decoration: none;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.5rem;
    text-align: left;
    width: 100%;
  }

  .topbar__mobile-link:hover {
    color: #f8b478;
  }

  /* Móvil: hit area compacta, sin márgenes entre iconos; badge del carrito sin solapar al de cuenta */
  @media (max-width: 1119px) {
    .topbar__hamburger {
      min-height: 44px;
      padding: 0;
      margin: 0;
      box-sizing: border-box;
      justify-content: center;
    }

    .topbar__hamburger-bars {
      align-self: center;
    }

    .topbar__actions {
      gap: 2px;
    }

    /* :not(cart): el carrito no puede llevar max-height o el badge queda mal anclado */
    .topbar__actions .topbar__icon:not(.topbar__icon--cart),
    .topbar__actions .topbar__icon--search {
      flex: 0 0 auto;
      min-width: 36px;
      min-height: 36px;
      max-width: 36px;
      max-height: 36px;
      margin: 0;
      padding: 0;
      box-sizing: border-box;
      overflow: visible;
    }

    .topbar__actions .topbar__icon--cart {
      flex: 0 0 auto;
      min-width: 36px;
      min-height: 36px;
      max-width: 36px;
      margin: 0;
      padding: 0;
      box-sizing: border-box;
      overflow: visible;
    }

    .topbar__actions .topbar__icon--cart .topbar__cart-icon-wrap {
      width: 18px;
      height: 18px;
    }

    .topbar__actions .topbar__icon svg,
    .topbar__actions .topbar__icon--search svg {
      width: 18px;
      height: 18px;
    }
  }
