/* The cart (js/cart.js): count on the header's bag, the second part of the «brow», and the panel. */

/* ───────────── header bag ───────────── */
.icon-btn--bag { position: relative; }
.bag__count {
  position: absolute;
  top: -4px;
  right: -4px;
  display: none;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--color-bg-accent);
  color: var(--color-text-primary);
  font: 700 11px / 18px var(--font-ui);
  text-align: center;
}
.header.has-cart .bag__count { display: block; }
/* phones and tablets have no bag in the header until there is something to show */
@media (max-width: 1099px) { .header.has-cart .icon-btn--bag { display: grid; } }

/* ───────────── the «brow»: «Меню» | cart ─────────────
   The second button on the brow's shape. While the header is down (it has its own bag) it slides
   away and the shape narrows; it comes back when the header goes. */
.brow-cart {
  position: absolute;
  top: 0;
  left: var(--menu-w, 106px);
  display: none;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 100%;
  padding: 0 18px 2px 14px;
  font: 700 13px / 1 var(--font-ui);
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: left var(--glide), translate var(--glide), opacity .3s ease .14s;
}
.topbar.has-cart .brow-cart { display: flex; }
.topbar.is-open .brow-cart { opacity: 0; translate: 16px 0; pointer-events: none; transition: left var(--glide), translate var(--glide), opacity .16s ease; }
.brow-cart svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.brow-cart b { min-width: 1ch; color: var(--color-bg-accent); }
.brow-cart:focus-visible { outline: 2px solid var(--color-bg-accent); outline-offset: -4px; border-radius: 999px; }
.brow-cart::before { content: ""; position: absolute; top: 9px; bottom: 11px; left: 0; width: 1px; background: rgb(251 247 239 / .22); }
.brow-cart.is-bump svg { animation: cart-bump .5s cubic-bezier(.23, 1, .32, 1); }
.icon-btn--bag.is-bump { animation: bag-bump .55s cubic-bezier(.23, 1, .32, 1); }
@keyframes bag-bump { 40% { scale: 1.22; background-color: var(--color-bg-accent); } }
/* the piece in flight (js/cart.js moves it); it passes over the brow and the price bar */
.fly { position: fixed; z-index: 1000; top: 0; left: 0; width: 76px; height: 76px; margin: -38px 0 0 -38px; overflow: hidden; border: 2px solid var(--color-bg-accent); border-radius: 50%; background: #fff; pointer-events: none; will-change: transform; }
.fly img { position: absolute; inset: 8px; width: calc(100% - 16px); height: calc(100% - 16px); object-fit: contain; }
@keyframes cart-bump { 40% { scale: 1.45; rotate: -8deg; } }
@media (max-width: 767px) {
  .brow-cart { gap: 7px; padding: 0 16px 2px 13px; font-size: 15px; }
  .brow-cart svg { width: 19px; height: 19px; }
  .brow-cart::before { top: 13px; bottom: 15px; }
}

/* ───────────── the panel ───────────── */
.cart {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(440px, 100%);
  max-width: 100%;
  height: 100%;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--color-text-primary);
  overflow: clip; /* not «hidden»: focusing a button of the panel while it is outside must not scroll it in */
}
.cart::backdrop { background: rgb(20 18 15 / 0); }
.cart.is-in::backdrop { background: rgb(20 18 15 / .4); }
.cart__panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 24px 24px max(24px, env(safe-area-inset-bottom));
  border-radius: 28px 0 0 28px;
  background: #fff;
  transform: translate3d(100%, 0, 0);
}
.cart.is-in .cart__panel { transform: translate3d(0, 0, 0); }
.cart__head { display: flex; align-items: center; justify-content: space-between; }
.cart__title { margin: 0; font: 500 30px / 1.1 var(--font-display); letter-spacing: -.02em; }
.cart__close { width: 44px; height: 44px; border-radius: 50%; background: var(--color-bg-page); font-size: 24px; line-height: 1; }
.cart__list { flex: 1; min-height: 0; margin: 20px -8px 0 0; padding-right: 8px; overflow-y: auto; overscroll-behavior: contain; }
.cart__item { display: flex; gap: 14px; padding: 14px 0; border-top: 1px solid rgb(28 27 25 / .1); }
.cart__photo { display: grid; flex: none; place-items: center; width: 88px; height: 88px; border-radius: 18px; background: #fff; }
.cart__photo img { max-width: 84px; max-height: 84px; object-fit: contain; }
.cart__name a { color: inherit; }
@media (hover: hover) { .cart__name a:hover { text-decoration: underline; text-decoration-color: var(--color-bg-accent); text-decoration-thickness: 2px; text-underline-offset: 3px; } }
.cart__info { flex: 1; min-width: 0; }
.cart__name { font: 600 15px / 1.3 var(--font-ui); }
.cart__sub { margin-top: 2px; color: var(--color-text-secondary); font-size: 13px; }
.cart__price { margin-top: 6px; font: 700 16px / 1.2 var(--font-ui); }
.cart__price small { color: var(--color-text-secondary); font-size: 12px; font-weight: 500; }
.cart__row { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }
.cart__qty { display: inline-flex; align-items: center; gap: 4px; padding: 2px; border-radius: 999px; background: var(--color-bg-page); }
.cart__qty button { width: 32px; height: 32px; border-radius: 50%; font-size: 18px; line-height: 1; }
.cart__qty b { min-width: 24px; font-size: 14px; text-align: center; }
.cart__remove { color: var(--color-text-secondary); font-size: 13px; text-decoration: underline; text-underline-offset: 3px; }
.cart__foot { padding-top: 16px; border-top: 1px solid rgb(28 27 25 / .1); }
.cart__total { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; font-size: 14px; color: var(--color-text-secondary); }
.cart__total strong { font: 700 24px / 1.2 var(--font-ui); color: var(--color-text-primary); }
.cart__btn { display: flex; align-items: center; justify-content: center; width: 100%; min-height: 52px; padding: 0 24px; border-radius: 999px; background: var(--color-bg-strong); color: var(--color-text-inverse); font: 600 15px / 1 var(--font-ui); }
.cart__btn--light { background: var(--color-bg-page); color: var(--color-text-primary); }
.cart__checkout, .cart__form .cart__btn[type="submit"] { background: var(--color-bg-accent); color: var(--color-text-primary); }
.cart__form, .cart__done, .cart__empty { display: none; flex-direction: column; gap: 12px; margin-top: 24px; }
.cart__note { color: var(--color-text-secondary); font-size: 14px; line-height: 1.5; }
.cart__field { width: 100%; height: 56px; padding: 0 20px; border: 1px solid transparent; border-radius: 999px; background: var(--color-bg-page); color: inherit; font: 500 16px var(--font-ui); }
.cart__field:focus-visible { border-color: var(--color-bg-strong); outline: 0; }
.cart__error { min-height: 18px; color: #b3261e; font-size: 13px; }
.cart__done strong { font: 500 28px / 1.1 var(--font-display); }
.cart.is-empty[data-step="list"] .cart__empty { display: flex; }
.cart.is-empty[data-step="list"] :is(.cart__list, .cart__foot) { display: none; }
.cart[data-step="form"] :is(.cart__list, .cart__foot) { display: none; }
.cart[data-step="form"] .cart__form { display: flex; }
.cart[data-step="done"] :is(.cart__list, .cart__foot) { display: none; }
.cart[data-step="done"] .cart__done { display: flex; }
html.cart-open { overflow: hidden; }

/* The panel glides in softly: slow to start, long to settle; it leaves a little quicker.
   What is in it follows, one piece after another. */
@media (prefers-reduced-motion: no-preference) {
  .cart::backdrop { transition: background-color .5s ease; }
  .cart.is-in::backdrop { transition: background-color .7s ease; }
  .cart__panel { transition: transform .5s cubic-bezier(.45, 0, .25, 1); will-change: transform; }
  .cart.is-in .cart__panel { transition: transform .8s cubic-bezier(.4, 0, .1, 1); }
  .cart.is-entering :is(.cart__head, .cart__item, .cart__foot, .cart__empty) { animation: cart-piece .7s cubic-bezier(.16, 1, .3, 1) backwards; }
  .cart.is-entering .cart__head { animation-delay: .22s; }
  .cart.is-entering .cart__item { animation-delay: calc(.28s + var(--i, 0) * .07s); }
  .cart.is-entering :is(.cart__foot, .cart__empty) { animation-delay: .36s; }
  @keyframes cart-piece { from { opacity: 0; translate: 28px 0; } }
}
@media (max-width: 767px) { .cart__panel { padding-inline: 20px; border-radius: 0; } }
@media (prefers-reduced-motion: reduce) { .brow-cart { transition: none !important; } .brow-cart.is-bump svg, .icon-btn--bag.is-bump { animation: none; } }
