/* Сброс и базовая типографика */
*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, sans-serif;
  background: #f5f5f7;
  color: #222;
}

/* Обертка приложения */
.app {
  max-width: 1120px;
  margin: 0 auto;
  padding: 12px 12px 24px;
}

/* Шапка */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 16px;
}

.app-logo {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.app-subtitle {
  font-size: 13px;
  color: #666;
  margin-top: 2px;
}

.app-header-right {
  display: flex;
  align-items: center;
}

.cart-header {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  background: #ffffff;
  box-shadow: 0 2px 4px rgba(15, 23, 42, 0.05);
  font-size: 13px;
}

.cart-header-label {
  font-weight: 500;
}

.cart-header-count {
  color: #555;
}

.cart-header-total {
  font-weight: 600;
}

/* Основная часть: каталог + корзина */
.app-main {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.catalog-section,
.cart-section {
  background: transparent;
}

/* На широких экранах делим на две колонки */
@media (min-width: 900px) {
  .app-main {
    flex-direction: row;
    align-items: flex-start;
  }

  .catalog-section {
    flex: 2;
  }

  .cart-section {
    flex: 1;
    min-width: 280px;
  }
}

/* Заголовки секций */
.section-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 10px;
}

/* Сетка каталога: строго 2 карточки в ряд на десктопе, 1 на мобильных */
.catalog-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

@media (max-width: 640px) {
  .catalog-grid {
    grid-template-columns: 1fr;
  }
}

/* Карточка товара */
.product-card {
  background: #ffffff;
  border-radius: 14px;
  padding: 10px;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.05);
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* Блок картинки с соотношением сторон */
.product-image-wrapper {
  width: 100%;
  padding-top: 68%;
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  background: #f1f5f9;
  margin-bottom: 8px;
}

.product-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.product-image-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: #888;
}

/* Контент карточки */
.product-content {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.product-title-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 6px;
}

.product-title {
  font-size: 14px;
  font-weight: 600;
  margin: 0;
}

.product-price-block {
  text-align: right;
  white-space: nowrap;
}

.product-price {
  display: block;
  font-size: 14px;
  font-weight: 700;
  color: #111827;
}

.product-old-price {
  display: block;
  font-size: 11px;
  color: #9ca3af;
  text-decoration: line-through;
}

/* Описание в карточке — укоротим, чтобы карточка не раздувалась */
.product-description {
  font-size: 12px;
  color: #555;
  margin: 0;
  max-height: 3.2em; /* примерно 2 строки */
  overflow: hidden;
}

/* Кнопки карточки */
.product-actions {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 6px;
}

.btn {
  border: none;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease,
    transform 0.05s ease;
  white-space: nowrap;
}

.btn-primary {
  background: #22c55e;
  color: #ffffff;
  font-weight: 600;
}

.btn-primary:hover {
  background: #16a34a;
  box-shadow: 0 2px 6px rgba(34, 197, 94, 0.3);
  transform: translateY(-1px);
}

.btn-outline {
  background: #f9fafb;
  color: #111827;
  border: 1px solid #e5e7eb;
}

.btn-outline:hover {
  background: #eef2ff;
}

/* Корзина */
.cart-box {
  background: #ffffff;
  border-radius: 14px;
  padding: 10px;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.05);
  margin-bottom: 10px;
}

.cart-items {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
}

.cart-item-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px 8px;
  border-radius: 10px;
  background: #f9fafb;
}

.cart-item-main {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.cart-item-name {
  font-weight: 500;
}

.cart-item-price {
  font-weight: 600;
}

.cart-item-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-qty,
.btn-remove {
  border: none;
  border-radius: 999px;
  font-size: 13px;
  padding: 2px 8px;
  cursor: pointer;
}

.btn-qty {
  background: #e5e7eb;
}

.btn-qty:hover {
  background: #d1d5db;
}

.btn-remove {
  background: #fee2e2;
  color: #b91c1c;
}

.btn-remove:hover {
  background: #fecaca;
}

.cart-item-qty {
  min-width: 18px;
  text-align: center;
}

/* Форма оформления заказа */
.checkout-form {
  background: #ffffff;
  border-radius: 14px;
  padding: 10px;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.05);
  font-size: 13px;
}

.checkout-title {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 8px 0;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-bottom: 8px;
}

.form-group label {
  font-size: 12px;
  color: #4b5563;
}

.form-group input,
.form-group textarea {
  border-radius: 8px;
  border: 1px solid #e5e7eb;
  padding: 6px 8px;
  font-family: inherit;
  font-size: 13px;
  resize: vertical;
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: #22c55e;
  box-shadow: 0 0 0 1px rgba(34, 197, 94, 0.2);
}

.checkout-submit {
  width: 100%;
  margin-top: 6px;
}

.checkout-hint {
  margin-top: 6px;
  font-size: 11px;
  color: #6b7280;
}

/* Модалки */
.modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal.open {
  display: flex;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}

.modal-dialog {
  position: relative;
  z-index: 51;
  background: #ffffff;
  border-radius: 16px;
  padding: 12px;
  max-width: 520px;
  width: calc(100% - 24px);
  max-height: calc(100% - 24px);
  overflow-y: auto;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.25);
}

.modal-close-btn {
  position: absolute;
  top: 6px;
  right: 8px;
  border: none;
  background: transparent;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

/* Контент модалки товара */
.modal-product {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

@media (min-width: 640px) {
  .modal-product {
    flex-direction: row;
  }
}

.modal-product-image-wrapper {
  flex: 1;
  min-width: 180px;
  max-width: 230px;
  border-radius: 12px;
  overflow: hidden;
  background: #f1f5f9;
}

.modal-product-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.modal-product-info {
  flex: 2;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal-product-info h2 {
  font-size: 16px;
  margin: 0;
}

.modal-product-prices {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.product-description-full {
  font-size: 13px;
  color: #4b5563;
  white-space: pre-line;
}
