/* ==========================================================
   カート cart.php

   進行状況・見出し・枠・金額・ボタンは、確認画面と共通の
   style_confirm.css を使います。このファイルには、カートだけの
   指定を置きます。（色の変数 --cf-* も style_confirm.css で定義）

   構成
     1. メッセージ・空のカート
     2. 商品の一覧
     3. 数量入力・削除
     4. 在庫不足・更新中の表示
     5. 金額欄
     6. モーダル（削除の確認・エラー）
     7. 幅が狭い時の表示（900px以下）
========================================================== */


/* ==========================================================
   1. メッセージ・空のカート
========================================================== */
.cart-alert {
  margin: 0 0 16px;
  padding: 12px 16px;
  border: 1px solid var(--cf-shu);
  border-left-width: 4px;
  border-radius: 6px;
  background: #fff;
  color: var(--cf-shu);
  font-weight: bold;
}

.cart-empty {
  padding: 40px 20px;
  border: 1px solid var(--cf-line);
  border-radius: 6px;
  background: var(--cf-paper);
  text-align: center;
}

.cart-empty p {
  margin: 0 0 20px;
  font-size: 17px;
}

.cart-empty-link {
  display: inline-block;
  padding: 12px 32px;
  border: 2px solid var(--cf-gold);
  border-radius: 8px;
  background: var(--cf-green);
  color: #fff;
  font-weight: bold;
  letter-spacing: 0.08em;
  text-decoration: none;
}

.cart-empty-link:hover {
  background: var(--cf-green-ink);
}


/* ==========================================================
   2. 商品の一覧
========================================================== */

/* 見出し行と商品行で、同じ列幅を使う
   （画像 / 商品名 / 単価 / 数量 / 小計） */
.cart-head,
.cart-item {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) 6.5em 9.5em 6.5em;
  align-items: center;
  gap: 6px 16px;
}

.cart-head {
  padding-bottom: 8px;
  border-bottom: 1px solid var(--cf-line);
  font-size: 13px;
  color: var(--cf-sub);
}

.cart-head-product {
  grid-column: 1 / 3;
}

.cart-head-price,
.cart-head-subtotal {
  text-align: right;
}

.cart-head-qty {
  text-align: center;
}

.cart-item {
  position: relative;
  padding: 14px 0;
  border-bottom: 1px dashed var(--cf-line);
}

.cart-item:last-child {
  padding-bottom: 0;
  border-bottom: none;
}

.cart-img {
  width: 72px;
  height: 72px;
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--cf-line);
  border-radius: 4px;
}

.cart-item-code {
  font-size: 13px;
  color: var(--cf-sub);
}

.cart-item-name {
  font-size: 17px;
  font-weight: bold;
  line-height: 1.5;
}

.cart-item-option {
  font-size: 14px;
  color: var(--cf-green);
}

/* 単価（数量変更の時、JSが中の span を書き換える） */
.cart-price {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.cart-price .price-original {
  display: block;
  font-size: 13px;
  color: #9a9186;
  text-decoration: line-through;
}

.cart-price .price-discount {
  font-size: 16px;
  font-weight: bold;
  color: var(--cf-shu);
}

.cart-price .price-normal {
  font-size: 16px;
}

.cart-subtotal {
  font-size: 18px;
  font-weight: bold;
  text-align: right;
  font-variant-numeric: tabular-nums;
}


/* ==========================================================
   3. 数量入力・削除
========================================================== */
.cart-quantity .qty-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin: 0;
}

.cart-quantity-box {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* style.css の .qty-control を、カート用に少し小さくする */
.cart-quantity .qty-control {
  border-color: #b9ae9b;
  border-radius: 6px;
}

.cart-quantity .qty-control:focus-within {
  border-color: var(--cf-green);
  outline: 2px solid var(--cf-gold);
  outline-offset: 1px;
}

.cart-quantity .qty-control input[type="number"] {
  width: 44px;
  height: 36px;
  padding: 0;
  font-family: inherit;
  font-size: 16px; /* 16px未満だと、iPhoneで入力時に画面が拡大される */
  outline: none;
}

.cart-quantity .qty-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  background: var(--cf-paper);
  color: var(--cf-green);
  font-size: 18px;
  line-height: 36px;
  cursor: pointer;
}

.cart-quantity .qty-btn:hover {
  background: #efe9dc;
}

.qty-unit {
  font-size: 14px;
  color: var(--cf-sub);
}

/* 削除（文字だけのボタン） */
.remove-btn {
  padding: 2px 4px;
  border: none;
  background: none;
  color: var(--cf-shu);
  font-family: inherit;
  font-size: 13px;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.remove-btn:hover {
  color: #7d2118;
}

.remove-btn:focus-visible,
.cart-quantity .qty-btn:focus-visible,
.cart-empty-link:focus-visible {
  outline: 3px solid var(--cf-gold);
  outline-offset: 2px;
}


/* ==========================================================
   4. 在庫不足・更新中の表示
========================================================== */

/* 在庫不足の商品（ページ表示時にPHPが付ける） */
.cart-item.stock-error-item,
/* 在庫不足の商品（購入手続きへ進む時にJSが付ける） */
.cart-item.stock-ng {
  margin: 0 -10px;
  padding: 14px 10px;
  border: 1px solid var(--cf-shu);
  border-radius: 6px;
  background: #fff;
}

.cart-item.stock-ng .cart-subtotal {
  color: var(--cf-shu);
}

/* 商品名の下に出す注意書き */
.stock-warning-note {
  margin-top: 2px;
  font-size: 13px;
  font-weight: bold;
  color: var(--cf-shu);
}

/* JSが商品行の先頭に差し込むエラー */
.stock-error {
  grid-column: 1 / -1;
  font-size: 14px;
  font-weight: bold;
  color: var(--cf-shu);
}

/* 数量の更新中 */
.cart-item.is-loading {
  pointer-events: none;
}

.cart-item.is-loading::after {
  content: "更新中…";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(252, 250, 245, 0.75);
  font-weight: bold;
  color: var(--cf-green-ink);
}


/* ==========================================================
   5. 金額欄
========================================================== */

/* 「あと◯円で送料無料」 */
.free-shipping-message {
  margin: 0 0 14px;
  padding: 8px 12px;
  border-left: 3px solid var(--cf-gold);
  background: var(--cf-paper);
  font-size: 14px;
  color: var(--cf-green-ink);
}

.cart-bill-note {
  margin: -12px 0 18px;
  font-size: 13px;
  text-align: right;
  color: var(--cf-sub);
}


/* ==========================================================
   6. モーダル（削除の確認・エラー）
========================================================== */
.cart-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 9999;
}

.cart-modal.show {
  opacity: 1;
  pointer-events: auto;
}

.cart-modal-content {
  width: 90%;
  max-width: 360px;
  padding: 24px 20px 20px;
  box-sizing: border-box;
  border-top: 4px double #d4a017;
  border-radius: 0 0 8px 8px;
  background: #fff;
  text-align: center;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}

.cart-modal-message {
  margin: 0 0 18px;
  font-size: 16px;
  line-height: 1.7;
}

.cart-modal-buttons {
  display: flex;
  justify-content: center;
  gap: 12px;
}

.modal-btn {
  padding: 10px 24px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-family: inherit;
  font-size: 15px;
  text-decoration: none;
  cursor: pointer;
}

.modal-btn.confirm {
  background: #234d30;
  color: #fff;
}

.modal-btn.confirm:hover {
  background: #1a3c24;
}

.modal-btn.cancel,
.modal-btn.view-cart {
  border-color: #b9ae9b;
  background: #fff;
  color: #2e2a26;
}

.modal-btn.cancel:hover,
.modal-btn.view-cart:hover {
  background: #fcfaf5;
}


/* ==========================================================
   7. 幅が狭い時の表示（900px以下）
   サイドメニューが横にある分、商品の欄は画面より狭くなるので、
   早めに縦積みへ切り替える
========================================================== */
@media (max-width: 900px) {

  .cart-head {
    display: none;
  }

  /* 1段目：画像と商品名 / 2段目：単価・数量・小計 */
  .cart-item {
    grid-template-columns: 56px minmax(0, 1fr) auto;
    gap: 8px 12px;
  }

  .cart-head + .cart-item {
    padding-top: 0;
  }

  .cart-img {
    width: 56px;
    height: 56px;
  }

  .cart-body {
    grid-column: 2 / 4;
  }

  .cart-price {
    grid-column: 1 / 2;
    text-align: left;
  }

  .cart-quantity {
    grid-column: 2 / 3;
  }

  .cart-quantity .qty-form {
    flex-direction: row;
    gap: 10px;
  }

  .cart-subtotal {
    grid-column: 3 / 4;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cart-modal {
    transition: none;
  }
}