/* ===========================================================================
   Tresneria mobile dock
   - iOS/base keeps the proven sticky placement.
   - Android fixed placement and pixel-locking remain in bottom-nav.js.
   - Five stable destinations; product action floats above the dock.
   ========================================================================== */

:root {
  --bar-max: 860px;
  --bar-h: 64px;
  --cta-h: 52px;
  --cta-gap: 8px;
  --nav-extra-pad: 0px;
  --glass-bg: rgba(255, 255, 255, 0.82);
  --glass-stroke: rgba(255, 255, 255, 0.76);
  --ink: #111;
  --ink-dim: #5b5b60;
  --active-bg: rgba(17, 17, 17, 0.08);
  --attention: #b38b09;
}

/* Desktop is opt-out by default, including any bottom padding side effects. */
.ios-glass-tabbar {
  display: none;
}

@media (max-width: 767px) {
  body {
    padding-bottom: calc(
      var(--bar-h) + var(--nav-extra-pad) + max(24px, env(safe-area-inset-bottom, 0px))
    );
  }

  body.has-bottom-product-cta {
    --nav-extra-pad: calc(var(--cta-h) + var(--cta-gap));
  }

  .ios-glass-tabbar {
    position: sticky;
    bottom: 2px;
    z-index: 9999;
    box-sizing: border-box;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    align-items: center;
    gap: 2px;
    width: calc(100% - 16px);
    max-width: var(--bar-max);
    height: var(--bar-h);
    margin-right: auto;
    margin-bottom: calc(env(safe-area-inset-bottom, 0px) + 2px);
    margin-left: auto;
    isolation: isolate;
    overflow: visible;
    backface-visibility: hidden;
    background: transparent !important;
    border: 0 !important;
    box-shadow: none !important;
  }

  .ios-glass-tabbar::before {
    position: absolute;
    z-index: -1;
    inset: -6px;
    content: "";
    background: var(--glass-bg);
    border: 1px solid var(--glass-stroke);
    border-radius: 20px;
    box-shadow:
      0 10px 28px rgba(0, 0, 0, 0.14),
      inset 0 1px 0 rgba(255, 255, 255, 0.72);
    backdrop-filter: saturate(165%) blur(6px);
    -webkit-backdrop-filter: saturate(165%) blur(6px);
  }

  .ios-glass-tabbar .tab {
    position: relative;
    min-width: 0;
    height: var(--bar-h);
    color: var(--ink-dim);
    font: 500 10.5px/1.1 ui-sans-serif, system-ui, -apple-system, "SF Pro", Inter, Roboto, "Segoe UI", sans-serif;
    text-decoration: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    transition: color 0.22s ease, transform 0.15s ease;
    -webkit-tap-highlight-color: transparent;
  }

  .ios-glass-tabbar .tab:active {
    transform: translateY(1px) scale(0.98);
  }

  .ios-glass-tabbar .tab:focus-visible {
    z-index: 2;
    outline: 2px solid var(--ink);
    outline-offset: -4px;
    border-radius: 14px;
  }

  .ios-glass-tabbar .nav-icon-shell {
    position: relative;
    width: 34px;
    height: 32px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    transition:
      background-color 0.22s ease,
      box-shadow 0.22s ease,
      transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
  }

  .ios-glass-tabbar .tab svg {
    width: 22px;
    height: 22px;
    display: block;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  .ios-glass-tabbar .nav-label {
    overflow: hidden;
    max-width: 100%;
    padding: 0 2px;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: font-weight 0.22s ease, color 0.22s ease;
  }

  .ios-glass-tabbar .tab.is-active {
    color: var(--ink);
  }

  .ios-glass-tabbar .tab.is-active .nav-icon-shell {
    background: var(--active-bg);
    box-shadow: inset 0 0 0 1px rgba(17, 17, 17, 0.035);
    transform: translateY(-1px);
  }

  .ios-glass-tabbar .tab.is-active .nav-label {
    font-weight: 650;
  }

  /* Cart badge lives on the icon instead of guessing a five-column offset. */
  .ios-glass-tabbar .badge,
  .ios-glass-tabbar [data-cart-count] {
    position: absolute;
    top: -3px;
    right: -7px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    color: #fff;
    font: 700 10px/16px ui-sans-serif, system-ui, sans-serif;
    text-align: center;
    background: #ff3b30;
    border: 1px solid rgba(255, 255, 255, 0.9);
    border-radius: 999px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.28);
  }

  .ios-glass-tabbar [data-cart-count][data-count="0"] {
    display: none;
  }

  /* One ripple is generated from pointerdown; click no longer duplicates it. */
  .tap-ripple {
    position: absolute;
    inset: 0;
    overflow: hidden;
    border-radius: 14px;
    pointer-events: none;
  }

  .tap-ripple > span {
    position: absolute;
    width: 12px;
    height: 12px;
    background: rgba(255, 255, 255, 0.72);
    border-radius: 999px;
    transform: translate(-50%, -50%) scale(0);
    animation: tresneria-nav-ripple 0.5s ease-out forwards;
    mix-blend-mode: soft-light;
  }

  /* Product CTA is visually separate but anchored to the proven bar geometry. */
  .ios-glass-tabbar .product-action {
    position: absolute;
    right: 0;
    bottom: calc(var(--bar-h) + var(--cta-gap));
    left: 0;
    box-sizing: border-box;
    width: 100%;
    height: var(--cta-h);
    margin: 0;
    padding: 0 18px;
    color: #fff;
    font-family: ui-sans-serif, system-ui, -apple-system, "SF Pro", Inter, Roboto, "Segoe UI", sans-serif;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(17, 17, 17, 0.84);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 18px;
    box-shadow:
      0 10px 24px rgba(0, 0, 0, 0.22),
      inset 0 1px 0 rgba(255, 255, 255, 0.12);
    opacity: 0;
    transform: translateY(10px) scale(0.985);
    pointer-events: none;
    transition:
      opacity 0.22s ease-out,
      transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1),
      background-color 0.2s ease;
    backdrop-filter: saturate(150%) blur(10px);
    -webkit-backdrop-filter: saturate(150%) blur(10px);
    -webkit-tap-highlight-color: transparent;
  }

  .ios-glass-tabbar.has-product-action .product-action {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
  }

  .ios-glass-tabbar .product-action:active {
    background: rgba(17, 17, 17, 0.92);
    transform: translateY(1px) scale(0.99);
  }

  .ios-glass-tabbar .product-action:focus-visible {
    outline: 2px solid #fff;
    outline-offset: -4px;
  }

  .ios-glass-tabbar .product-action.is-loading {
    cursor: progress;
    opacity: 0.78;
  }

  .ios-glass-tabbar .product-action.is-select-option {
    justify-content: center;
  }

  .ios-glass-tabbar .action-label {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.02em;
  }

  .ios-glass-tabbar .action-price {
    font-size: 15px;
    font-weight: 650;
    line-height: 1;
  }

  /* Feed: stacked card lift. Ranks: cup lift plus a single quiet glint. */
  .ios-glass-tabbar .feed-card,
  .ios-glass-tabbar .rank-cup,
  .ios-glass-tabbar .rank-glint {
    transform-box: fill-box;
    transform-origin: center;
  }

  .ios-glass-tabbar .rank-glint {
    fill: var(--attention);
    stroke: none;
    opacity: 0.36;
  }

  .ios-glass-tabbar [data-tab="feed"].is-nav-animated .feed-card--back {
    animation: tresneria-feed-card-rise 0.68s cubic-bezier(0.2, 0.8, 0.2, 1);
  }

  .ios-glass-tabbar [data-tab="feed"].is-nav-animated .feed-card--front {
    animation: tresneria-feed-card-pulse 0.68s ease-out;
  }

  .ios-glass-tabbar [data-tab="ranks"].is-nav-animated .rank-cup {
    animation: tresneria-rank-lift 0.7s cubic-bezier(0.2, 0.8, 0.2, 1);
  }

  .ios-glass-tabbar [data-tab="ranks"].is-nav-animated .rank-glint {
    animation: tresneria-rank-glint 0.7s ease-out;
  }
}

@keyframes tresneria-nav-ripple {
  to {
    opacity: 0;
    transform: translate(-50%, -50%) scale(9);
  }
}

@keyframes tresneria-feed-card-rise {
  0%, 100% { transform: translateY(0); }
  42% { transform: translateY(-2.5px); }
}

@keyframes tresneria-feed-card-pulse {
  0%, 100% { opacity: 1; }
  48% { opacity: 0.58; }
}

@keyframes tresneria-rank-lift {
  0%, 100% { transform: translateY(0) scale(1); }
  42% { transform: translateY(-2px) scale(1.04); }
}

@keyframes tresneria-rank-glint {
  0%, 22%, 100% { opacity: 0.28; transform: scale(0.75) rotate(0deg); }
  58% { opacity: 1; transform: scale(1.18) rotate(18deg); }
}

@supports not ((backdrop-filter: blur(6px)) or (-webkit-backdrop-filter: blur(6px))) {
  @media (max-width: 767px) {
    .ios-glass-tabbar::before {
      background: rgba(248, 248, 250, 0.98);
      backdrop-filter: none;
      -webkit-backdrop-filter: none;
    }

    .ios-glass-tabbar .product-action {
      background: rgba(17, 17, 17, 0.96);
      backdrop-filter: none;
      -webkit-backdrop-filter: none;
    }
  }
}

@media (max-width: 360px) {
  .ios-glass-tabbar .tab {
    font-size: 10px;
  }

  .ios-glass-tabbar .nav-icon-shell {
    width: 31px;
  }

  .ios-glass-tabbar .tab svg {
    width: 21px;
    height: 21px;
  }

  .ios-glass-tabbar .product-action {
    padding-right: 15px;
    padding-left: 15px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ios-glass-tabbar,
  .ios-glass-tabbar *,
  .ios-glass-tabbar *::before,
  .ios-glass-tabbar *::after {
    scroll-behavior: auto !important;
    animation: none !important;
    transition: none !important;
  }
}
