/* ============================================================
   css/cart.css — корзина, страница оплаты и результат оплаты.
   Подключается на cart.html, checkout.html и payment-result.html, плюс
   .cart-link (иконка в шапке) — на страницах воронки.
   Токены и кнопки переиспользуются из main.css / components.css.
   ============================================================ */

/* ---- Иконка корзины в шапке ------------------------------- */
.cart-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  position: relative;
  white-space: nowrap;
}
.cart-link[hidden] { display: none; }
.cart-link__icon { width: 18px; height: 18px; flex: none; }
.cart-link__count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--brand-red-cta);
  color: var(--brand-white);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
}
.cart-link__count[hidden] { display: none; }
/* В узкой шапке подпись прячем — остаётся иконка со счётчиком. */
@media (max-width: 560px) {
  .cart-link__label { display: none; }
}

/* ---- Каркас страницы -------------------------------------- */
.cart-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  gap: var(--gap);
  align-items: start;
}
@media (max-width: 900px) {
  .cart-layout { grid-template-columns: minmax(0, 1fr); }
}

.cart-panel {
  background: var(--brand-white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  min-width: 0;                 /* без этого длинные названия распирают grid */
}
@media (max-width: 480px) {
  .cart-panel { padding: 18px 16px; border-radius: var(--radius-sm); }
}

.cart-panel__title {
  margin: 0 0 18px;
  font-size: 22px;
  color: var(--brand-dark);
}

/* ---- Список позиций --------------------------------------- */
.cart-list { list-style: none; margin: 0; padding: 0; }

.cart-row {
  padding: 18px 0;
  border-bottom: 1px solid var(--border);
  min-width: 0;
}
.cart-row:first-child { padding-top: 0; }
.cart-row:last-child { border-bottom: none; padding-bottom: 0; }

.cart-row__head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  justify-content: space-between;
}
.cart-row__title {
  margin: 0;
  font-size: 17px;
  line-height: 1.35;
  color: var(--brand-dark);
  /* Длинные названия услуг переносятся, а не ломают вёрстку. */
  overflow-wrap: anywhere;
  min-width: 0;
}
.cart-row__remove {
  flex: none;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: transparent;
  color: var(--text-m);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  transition: background .18s, color .18s, border-color .18s;
}
.cart-row__remove:hover {
  background: var(--brand-red-cta);
  border-color: var(--brand-red-cta);
  color: var(--brand-white);
}
.cart-row__single { margin: 8px 0 0; color: var(--text-m); font-size: 14px; }

/* ---- Переключатель месяц / год ---------------------------- */
.cart-period {
  border: none;
  margin: 14px 0 0;
  padding: 0;
  min-width: 0;
}
.cart-period__legend {
  padding: 0;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--text-m);
}
.cart-period__opt {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 10px;
  padding: 11px 14px;
  margin-bottom: 8px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color .18s, background .18s;
}
.cart-period__opt:last-child { margin-bottom: 0; }
.cart-period__opt:hover { border-color: var(--brand-blue); }
.cart-period__opt:has(input:checked) {
  border-color: var(--brand-blue);
  background: rgba(var(--brand-cyan-rgb), .07);
}
.cart-period__opt:focus-within { outline: 2px solid var(--brand-blue); outline-offset: 2px; }
.cart-period__opt input { flex: none; width: 18px; height: 18px; accent-color: var(--brand-blue); }
.cart-period__text {
  font-size: 15px;
  color: var(--brand-dark);
  min-width: 0;
  overflow-wrap: anywhere;
}
.cart-period__price { white-space: nowrap; }
.cart-period__saving {
  margin-left: auto;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(67, 217, 124, .16);
  color: #1E7A45;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
@media (max-width: 420px) {
  /* На узком экране «выгода» уходит на свою строку, а не сжимает цену. */
  .cart-period__saving { margin-left: 28px; }
}

/* ---- Воздух вокруг кнопки покупки на карточке тарифа (tarify.html) ----
   Обе ступени стека CTA задаются здесь одним значением 14px, чтобы блок
   «выбор периода → купить → заявка» дышал одинаково.

   1) Переключатель месяц/год и кнопка покупки стояли вплотную: у .cart-period
      есть только верхний margin, а у кнопки — никакого.
   2) Ссылка «Получить консультацию» попадает под
      .tarif-card > a.btn { margin-top: auto } из components.css. Прижать её
      к низу карточки это правило уже не может: всё свободное место забирает
      .tarif-list { flex-grow: 1 }, поэтому auto схлопывается в 0.

   Низ карточки не съезжает — за выравнивание отвечает flex-grow списка,
   а не эти margin'ы. */
.tarif-cart > .cart-period + .btn { margin-top: 14px; }
.tarif-card > .tarif-cart + .btn { margin-top: 14px; }

.cart-row__foot { margin-top: 12px; display: flex; justify-content: flex-end; }
.cart-row__amount { font-size: 19px; font-weight: 700; color: var(--brand-dark); white-space: nowrap; }

/* ---- Итог -------------------------------------------------- */
.cart-summary { margin-top: 20px; padding-top: 18px; border-top: 2px solid var(--border); }
.cart-summary__line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.cart-summary__label { font-size: 16px; color: var(--text-m); }
.cart-summary__total { font-size: 26px; font-weight: 800; color: var(--brand-dark); white-space: nowrap; }
.cart-summary__saving {
  margin: 10px 0 0;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: rgba(67, 217, 124, .12);
  color: #1E7A45;
  font-size: 14px;
  font-weight: 600;
}
.cart-summary__saving[hidden] { display: none; }
.cart-summary__note { margin: 14px 0 0; font-size: 13px; color: var(--text-m); }

/* ---- Пустая корзина ---------------------------------------- */
.cart-empty { text-align: center; padding: 28px 0; }
.cart-empty[hidden] { display: none; }
.cart-empty__title { margin: 0 0 10px; font-size: 20px; color: var(--brand-dark); }
.cart-empty__text { margin: 0 0 20px; color: var(--text-m); }

/* ---- Форма оформления -------------------------------------- */
.checkout-form[hidden] { display: none; }
.checkout-error {
  margin: 0 0 16px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: rgba(233, 75, 75, .1);
  border: 1px solid rgba(233, 75, 75, .35);
  color: #A32222;
  font-size: 14px;
}
.checkout-error[hidden] { display: none; }
.checkout-legal { margin: 14px 0 0; font-size: 12px; line-height: 1.5; color: var(--text-m); }

/* ---- Страница результата оплаты ---------------------------- */
.payment-result { text-align: center; max-width: 620px; margin: 0 auto; }
.payment-result__icon {
  width: 64px; height: 64px; margin: 0 auto 20px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(var(--brand-cyan-rgb), .14);
}
.payment-result[data-state="succeeded"] .payment-result__icon { background: rgba(67, 217, 124, .18); }
.payment-result[data-state="canceled"] .payment-result__icon { background: rgba(233, 75, 75, .14); }
.payment-result__title { margin: 0 0 12px; font-size: 26px; color: var(--brand-dark); }
.payment-result__text { margin: 0 0 18px; color: var(--text-m); line-height: 1.6; }
.payment-result__amount { margin: 0 0 22px; font-weight: 700; color: var(--brand-dark); }
.payment-result__amount[hidden] { display: none; }
.payment-result__actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }
.payment-result__actions [hidden] { display: none; }

.payment-spinner {
  width: 28px; height: 28px;
  border: 3px solid rgba(var(--brand-blue-rgb), .25);
  border-top-color: var(--brand-blue);
  border-radius: 50%;
  animation: payment-spin .9s linear infinite;
}
.payment-spinner[hidden] { display: none; }
@keyframes payment-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .payment-spinner { animation-duration: 2.4s; }
}

/* ---- Страница оплаты (checkout.html) ----------------------- */
.checkout-title { margin: 0 0 10px; }
.checkout-lead { margin: 0 0 28px; max-width: 60ch; }

.order-list { list-style: none; margin: 0 0 4px; padding: 0; }
.order-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "name amount" "period amount";
  gap: 2px 14px;
  align-items: baseline;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.order-item:first-child { padding-top: 0; }
.order-item:last-child { border-bottom: none; }
.order-item__name {
  grid-area: name;
  font-size: 16px;
  font-weight: 600;
  color: var(--brand-dark);
  overflow-wrap: anywhere;      /* длинные названия услуг не рвут сетку */
  min-width: 0;
}
.order-item__period { grid-area: period; font-size: 13px; color: var(--text-m); }
.order-item__amount {
  grid-area: amount;
  align-self: center;
  font-size: 17px;
  font-weight: 700;
  color: var(--brand-dark);
  white-space: nowrap;
}

.checkout-seller {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  line-height: 1.7;
  color: var(--text-m);
}
.checkout-seller h3 { margin: 0 0 8px; font-size: 14px; color: var(--brand-dark); }
.checkout-seller p { margin: 0 0 8px; }
.checkout-seller p:last-child { margin-bottom: 0; }

.checkout-status {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 16px;
  color: var(--text-m);
  font-size: 15px;
}
.checkout-status[hidden] { display: none; }

.checkout-retry { display: flex; flex-wrap: wrap; gap: 12px; margin: 0 0 18px; }
.checkout-retry[hidden] { display: none; }

/* Виджет ЮKassa рендерит внутрь свой iframe. Задаём только ширину и отступ:
   собственную высоту он подбирает сам, фиксировать её нельзя. */
.checkout-widget { margin: 0 0 18px; min-width: 0; }
.checkout-widget[hidden] { display: none; }
.checkout-widget #payment-form { width: 100%; min-width: 0; }
.checkout-widget iframe { max-width: 100%; border: 0; }

.checkout-legal { margin: 0; font-size: 12px; line-height: 1.6; color: var(--text-m); }

/* Заметка вместо снятого блока оплаты (режим контролируемой эксплуатации,
   js/checkout-mode.js). Показывается в карточке вместо кнопки «В корзину». */
.cart-restricted-note {
  margin: .6rem 0 .8rem;
  padding: .6rem .8rem;
  border-radius: 8px;
  background: #f5f7fa;
  color: #4a5568;
  font-size: .9rem;
  line-height: 1.45;
}
