/* ТЕМА INGRIAFARM — премиум-слой модалки мини-корзины (if-cartm__*).
   Каркас и легаси-классы (b-popup, cart-prev-*) живут в modals.css —
   здесь поверх: сцена обложки (градиент, лапки, «дышащий» кот, волна на
   стыке), глубина (blur-бэкдроп, слоёные тени), иерархия строк и футера,
   вход с пружиной и stagger строк. Язык темы: оранжевый — рамки и акценты,
   маскот без наклонов, Montserrat. Тёмная тема и reduced-motion учтены. */

/* --- Бэкдроп: тёплое стекло ---------------------------------------------- */
#body .b-overlay.if-cartm {
  background: rgba(26, 15, 4, 0.42);
  -webkit-backdrop-filter: blur(7px) saturate(1.15);
  backdrop-filter: blur(7px) saturate(1.15);
  animation: if-cartm-veil 0.28s ease-out both;
}
@keyframes if-cartm-veil {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* --- Карточка модалки: пружинный вход, слоёная тень ---------------------- */
#body .b-overlay.if-cartm .b-popup {
  max-width: 700px;
  /* Потолок по вьюпорту: на ландшафте телефона фикс-486px была бы выше
     экрана (панель обрезалась бы); при высоком экране = прежние 486px */
  height: min(486px, calc(100dvh - 40px));
  padding: 18px 18px 18px 252px;
  border-radius: 26px;
  border: 1px solid rgba(243, 155, 43, 0.22);
  box-shadow:
    0 34px 90px rgba(30, 16, 2, 0.38),
    0 4px 14px rgba(30, 16, 2, 0.12);
  animation: if-cartm-in 0.5s cubic-bezier(0.2, 1.25, 0.36, 1) both;
  overflow: hidden; /* волна обложки не вылезает за скругление */
}
@keyframes if-cartm-in {
  from { opacity: 0; transform: translateY(18px) scale(0.94); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@media (max-width: 610px) {
  #body .b-overlay.if-cartm .b-popup { padding: 18px; height: auto; min-height: 420px; }
}

/* Крестик: круглый чип, поворот на hover */
#body .if-cartm .b-popup__edit {
  width: 34px;
  height: 34px;
  right: 14px;
  top: 14px;
  border-radius: 50%;
  border: 1.5px solid rgba(4, 0, 0, 0.14);
  background: rgba(255, 255, 255, 0.9);
  transition: transform 0.25s ease, border-color 0.2s ease, opacity 0.2s ease;
  z-index: 3;
}
#body .if-cartm .b-popup__edit:hover {
  opacity: 1;
  border-color: #F39B2B;
  transform: rotate(90deg);
}
.theme-dark #body .if-cartm .b-popup__edit {
  background: rgba(34, 30, 26, 0.9);
  border-color: rgba(255, 255, 255, 0.2);
}

/* --- Обложка-сцена -------------------------------------------------------- */
/* Градиент рассвета + россыпь лапок + блик; кот у кромки «дышит». */
#body .if-cartm .modal-content__cover {
  width: 234px;
  min-width: 234px;
  border-radius: 0; /* скругляет overflow родителя */
  background: linear-gradient(168deg, #FFC061 0%, #F5A032 52%, #E8891A 100%);
}
/* Логотип из modals.css (::before c support-logo) оставляем — приподнимем */
#body .if-cartm .modal-content__cover::before {
  left: 26px;
  top: 30px;
  filter: drop-shadow(0 2px 6px rgba(120, 60, 0, 0.35));
}
/* Подпись под логотипом */
.if-cartm__cover-sub {
  position: absolute;
  left: 27px;
  top: 80px;
  z-index: 1;
  max-width: 180px;
  font: 600 10px/1.5 'Montserrat', sans-serif;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.8);
}
/* Мягкий световой блик сверху */
.if-cartm__cover-glow {
  position: absolute;
  inset: 0;
  background: radial-gradient(120% 55% at 30% -8%, rgba(255, 255, 255, 0.38), rgba(255, 255, 255, 0) 60%);
  pointer-events: none;
}
/* Россыпь лапок: фирменная лапа прелоадера, редкий тайл, лёгкий поворот */
.if-cartm__cover-paws {
  position: absolute;
  inset: -30px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Cg fill='%23FFFFFF'%3E%3Cellipse cx='32' cy='43' rx='14' ry='11'/%3E%3Cellipse cx='13' cy='27' rx='6' ry='8' transform='rotate(-22 13 27)'/%3E%3Cellipse cx='25' cy='18' rx='6' ry='8' transform='rotate(-7 25 18)'/%3E%3Cellipse cx='39' cy='18' rx='6' ry='8' transform='rotate(7 39 18)'/%3E%3Cellipse cx='51' cy='27' rx='6' ry='8' transform='rotate(22 51 27)'/%3E%3C/g%3E%3C/svg%3E") 0 0 / 44px 44px repeat;
  opacity: 0.07;
  transform: rotate(-10deg);
  pointer-events: none;
}
/* Кот: у нижней кромки, контактная тень, спокойное «дыхание» без наклонов */
#body .if-cartm .modal-content__cover-logo {
  position: relative;
  z-index: 1;
}
#body .if-cartm .modal-content__cover-logo img {
  filter: drop-shadow(0 16px 22px rgba(110, 55, 0, 0.38));
  transform-origin: 50% 100%;
  animation: if-cartm-breath 4.6s ease-in-out infinite alternate;
}
@keyframes if-cartm-breath {
  from { transform: scale(1); }
  to { transform: scale(1.014); }
}
/* Волна на стыке обложки и контента — фирменный переход темы (вертикальная
   сестра if-hero__topwave): гребень «бумаги» наезжает на оранжевый. */
.if-cartm__cover-wave {
  position: absolute;
  top: 0;
  bottom: 0;
  right: -1px;
  width: 26px;
  background: repeat-y right center / 100% 620px url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 60 620' preserveAspectRatio='none'%3E%3Cpath d='M60,0 L60,620 L30,620 C8,560 52,470 30,400 C10,335 50,240 30,160 C14,95 48,55 30,0 Z' fill='%23FFFFFF'/%3E%3C/svg%3E");
  pointer-events: none;
}
.theme-dark .if-cartm__cover-wave {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 60 620' preserveAspectRatio='none'%3E%3Cpath d='M60,0 L60,620 L30,620 C8,560 52,470 30,400 C10,335 50,240 30,160 C14,95 48,55 30,0 Z' fill='%23222222'/%3E%3C/svg%3E");
}

/* --- Шапка: заголовок + чип-счётчик -------------------------------------- */
#body .if-cartm .b-popup__head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 12px;
}
#body .if-cartm .b-popup__title {
  flex: 0 1 auto;
  font: 800 20px/1.2 'Montserrat', sans-serif;
}
.if-cartm__count[hidden] { display: none; } /* display ниже перебил бы атрибут hidden */
.if-cartm__count {
  display: inline-block;
  padding: 4px 10px;
  border: 1.5px solid rgba(243, 155, 43, 0.55);
  border-radius: 10px;
  font: 700 12px/1 'Montserrat', sans-serif;
  color: #b25e00;
  white-space: nowrap;
}
.theme-dark .if-cartm__count { color: #f6b96b; }

/* --- Список: маски по краям, строки с иерархией --------------------------- */
#body .if-cartm .cart-prev-products {
  padding: 6px 8px 6px 2px;
  -webkit-mask-image: linear-gradient(180deg, transparent 0, #000 14px, #000 calc(100% - 14px), transparent 100%);
  mask-image: linear-gradient(180deg, transparent 0, #000 14px, #000 calc(100% - 14px), transparent 100%);
}
#body .if-cartm .cart-prev-product-item {
  padding: 11px 8px;
  border-radius: 14px;
  background: transparent; /* серые карточки легаси спорят с пунктиром между строками */
  transition: background-color 0.18s ease;
}
#body .if-cartm .cart-prev-product-item:hover { background: #FFF6E9; }
.theme-dark #body .if-cartm .cart-prev-product-item:hover { background: rgba(255, 255, 255, 0.05); }
/* Тонкий пунктир между строками */
#body .if-cartm .cart-prev-product-item + .cart-prev-product-item {
  position: relative;
  margin-top: 2px;
}
#body .if-cartm .cart-prev-product-item + .cart-prev-product-item::before {
  content: '';
  position: absolute;
  left: 10px;
  right: 10px;
  top: -1px;
  border-top: 1px dashed rgba(4, 0, 0, 0.12);
}
.theme-dark #body .if-cartm .cart-prev-product-item + .cart-prev-product-item::before {
  border-top-color: rgba(255, 255, 255, 0.14);
}
/* Картинка в кремовой рамке */
#body .if-cartm .cart-prev-product-item-img {
  width: 54px;
  height: 54px;
  padding: 6px;
  border-radius: 12px;
  background: #FFF3E1;
  object-fit: contain;
}
.theme-dark #body .if-cartm .cart-prev-product-item-img { background: rgba(255, 255, 255, 0.08); }
/* Название: две строки вместо жёсткого nowrap-обрезания (theme-extra) */
#body .if-cartm .cart-prev-product-item-name a {
  font-weight: 600;
  white-space: normal;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
#body .if-cartm .cart-prev-product-item-name a:hover { color: #E8891A; }
#body .if-cartm .cart-prev-product-item-unit { opacity: 0.6; }
/* Сумма строки — табличные цифры, не прыгает при пересчёте */
#body .if-cartm .cart-prev-product-item-price-value {
  font: 800 15px/1 'Montserrat', sans-serif;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
/* Крестик строки: тихий, оживает на hover */
#body .if-cartm .cart-prev-product-item-remove-btn {
  opacity: 0.35;
  transition: opacity 0.15s ease;
}
#body .if-cartm .cart-prev-product-item:hover .cart-prev-product-item-remove-btn { opacity: 0.8; }
#body .if-cartm .cart-prev-product-item-remove-btn:hover { opacity: 1; }

/* Stagger строк при открытии (класс is-opening вешает JS на 700мс) */
.if-cartm.is-opening .cart-prev-product-item {
  animation: if-cartm-row 0.38s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.if-cartm.is-opening .cart-prev-product-item:nth-child(2) { animation-delay: 0.05s; }
.if-cartm.is-opening .cart-prev-product-item:nth-child(3) { animation-delay: 0.1s; }
.if-cartm.is-opening .cart-prev-product-item:nth-child(4) { animation-delay: 0.15s; }
.if-cartm.is-opening .cart-prev-product-item:nth-child(5) { animation-delay: 0.2s; }
.if-cartm.is-opening .cart-prev-product-item:nth-child(n+6) { animation-delay: 0.25s; }
@keyframes if-cartm-row {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- Пустое состояние ----------------------------------------------------- */
.if-cartm__empty {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
}
.if-cartm__empty-paw {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  margin-bottom: 6px;
  border: 1.5px dashed rgba(243, 155, 43, 0.7);
  border-radius: 18px;
  color: #F39B2B;
}
.if-cartm__empty-paw svg { width: 30px; height: 30px; }
.if-cartm__empty b { font: 800 17px/1.2 'Montserrat', sans-serif; }
.if-cartm__empty span { font-size: 13px; opacity: 0.6; max-width: 260px; }

/* --- Футер: итог + кнопка ------------------------------------------------- */
#body .if-cartm .cart-prev-bottom {
  align-items: flex-end;
  gap: 14px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed rgba(4, 0, 0, 0.14);
}
.theme-dark #body .if-cartm .cart-prev-bottom { border-top-color: rgba(255, 255, 255, 0.16); }
#body .if-cartm .cart-prev-total {
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
}
#body .if-cartm .cart-prev-total-label {
  font: 700 11px/1 'Montserrat', sans-serif;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.55;
}
#body .if-cartm .cart-prev-total-value {
  font: 800 27px/1 'Montserrat', sans-serif;
  font-variant-numeric: tabular-nums;
  transition: transform 0.18s ease;
}
/* «Тик» суммы при пересчёте (класс вешает JS на мгновение) */
#body .if-cartm .cart-prev-total-value.is-pop { transform: scale(1.12); }

/* Кнопка: градиент, тень-подсветка, стрелка едет, блик на hover */
#body .if-cartm .modal__footer-btn {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 15px 24px;
  border-radius: 15px;
  position: relative;
  overflow: hidden;
  background: linear-gradient(150deg, #F8AC3F, #EE8E14);
  box-shadow: 0 10px 24px rgba(238, 142, 20, 0.42);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
#body .if-cartm .modal__footer-btn:not(:disabled):hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 30px rgba(238, 142, 20, 0.5);
}
#body .if-cartm .modal__footer-btn:disabled { opacity: 0.55; box-shadow: none; }
#body .if-cartm .modal__footer-btn .if-cartm__btn-arrow {
  display: inline-flex;
  transition: transform 0.2s ease;
}
#body .if-cartm .modal__footer-btn:not(:disabled):hover .if-cartm__btn-arrow { transform: translateX(4px); }
/* Блик-проблеск */
#body .if-cartm .modal__footer-btn::after {
  content: '';
  position: absolute;
  top: -20%;
  bottom: -20%;
  left: -35%;
  width: 26%;
  background: linear-gradient(105deg, transparent, rgba(255, 255, 255, 0.5), transparent);
  transform: skewX(-18deg);
  transition: left 0.5s ease;
  pointer-events: none;
}
#body .if-cartm .modal__footer-btn:not(:disabled):hover::after { left: 120%; }

/* --- Реплика кота: комикс-бабл над головой -------------------------------- */
.if-cartm__bubble {
  position: absolute;
  left: 50%;
  bottom: 226px;
  transform: translateX(-38%);
  z-index: 2;
  padding: 8px 14px;
  border-radius: 14px 14px 14px 4px;
  background: #fff;
  color: #181411;
  font: 800 14px/1 'Montserrat', sans-serif;
  box-shadow: 0 6px 16px rgba(110, 55, 0, 0.28);
  animation: if-cartm-bubble 0.35s cubic-bezier(0.2, 1.4, 0.4, 1) both;
  pointer-events: none;
  white-space: nowrap;
}
.if-cartm__bubble[hidden] { display: none; }
/* Хвостик к коту */
.if-cartm__bubble::after {
  content: '';
  position: absolute;
  left: 12px;
  bottom: -7px;
  border: 6px solid transparent;
  border-top-color: #fff;
  border-left-color: #fff;
}
@keyframes if-cartm-bubble {
  from { opacity: 0; transform: translateX(-38%) translateY(8px) scale(0.7); }
  to { opacity: 1; transform: translateX(-38%) translateY(0) scale(1); }
}
.if-cartm__bubble.is-leaving { opacity: 0; transition: opacity 0.25s ease; }

/* --- Бейдж остатка в строке ------------------------------------------------ */
.if-cartm__stock {
  display: block;
  margin-top: 3px;
  font: 700 11px/1.2 'Montserrat', sans-serif;
  color: #b25e00;
}
.theme-dark .if-cartm__stock { color: #f6b96b; }

/* --- Промокод в модалке ---------------------------------------------------- */
.if-cartm__promo { margin-top: 12px; }
.if-cartm__promo-link {
  font: 700 12.5px/1 'Montserrat', sans-serif;
  color: #b25e00;
  cursor: pointer;
  text-decoration: underline dashed;
  text-underline-offset: 3px;
}
.theme-dark .if-cartm__promo-link { color: #f6b96b; }
.if-cartm__promo-form { display: flex; gap: 8px; }
.if-cartm__promo-form[hidden] { display: none; }
.if-cartm__promo-input {
  flex: 1;
  min-width: 0;
  height: 38px;
  padding: 0 12px;
  border: 1px solid rgba(4, 0, 0, 0.2);
  border-radius: 10px;
  background: transparent;
  font: 600 13px/1 'Montserrat', sans-serif;
  color: inherit;
}
.if-cartm__promo-input:focus { outline: none; border-color: #F39B2B; }
.theme-dark .if-cartm__promo-input { border-color: rgba(255, 255, 255, 0.22); }
.if-cartm__promo-btn {
  padding: 0 16px;
  height: 38px;
  border: 1.5px solid #F39B2B;
  border-radius: 10px;
  font: 700 12.5px/1 'Montserrat', sans-serif;
  color: #b25e00;
  cursor: pointer;
  transition: background-color 0.15s ease;
}
.if-cartm__promo-btn:hover { background: rgba(243, 155, 43, 0.12); }
.theme-dark .if-cartm__promo-btn { color: #f6b96b; }
.if-cartm__promo-applied {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px dashed #F39B2B;
  border-radius: 10px;
  font: 800 12.5px/1 'Montserrat', sans-serif;
  letter-spacing: 0.05em;
}
.if-cartm__promo-applied[hidden] { display: none; }
.if-cartm__promo-value { color: #2e9e5b; }
.if-cartm__promo-remove {
  margin-left: auto;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  color: inherit;
  opacity: 0.5;
  cursor: pointer;
}
.if-cartm__promo-remove:hover { opacity: 1; }
.if-cartm__promo-err {
  margin: 7px 0 0;
  font: 600 12px/1.4 'Montserrat', sans-serif;
  color: #d64545;
}
.theme-dark .if-cartm__promo-err { color: #e06666; }

/* --- Спиннер кнопки оплаты (общий: модалка и /cart) ------------------------ */
.if-btn-loading { position: relative; pointer-events: none; }
.if-btn-loading > * { visibility: hidden; }
.if-btn-loading::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  border: 2.5px solid rgba(24, 20, 17, 0.25);
  border-top-color: #181411;
  border-radius: 50%;
  animation: if-btn-spin 0.7s linear infinite;
}
@keyframes if-btn-spin { to { transform: rotate(360deg); } }

/* --- Reduced motion ------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  #body .b-overlay.if-cartm,
  #body .b-overlay.if-cartm .b-popup,
  .if-cartm.is-opening .cart-prev-product-item { animation: none; }
  #body .if-cartm .modal-content__cover-logo img { animation: none; }
}
