/*
 * Cart drawer (desktop right panel) and add-to-cart sheet (mobile).
 * Markup: inc/cart-drawer.php. Behaviour: assets/cart-drawer.js.
 */

.chf-drawer {
  position: fixed;
  inset: 0;
  z-index: 100010;
  font-family: var(--font-body, 'Plus Jakarta Sans', system-ui, sans-serif);
  color: var(--chf-blue-ink, #0F2747);
}

.chf-drawer[hidden] { display: none; }

html.chf-drawer-lock { overflow: hidden; }

.chf-drawer-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 39, 71, .48);
  opacity: 0;
  transition: opacity .28s ease;
}

.chf-drawer.is-open .chf-drawer-overlay { opacity: 1; }

/* ── Desktop: right-hand panel ─────────────────────────────────────────── */

.chf-drawer-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(430px, 100vw);
  background: #fff;
  box-shadow: -12px 0 40px rgba(15, 39, 71, .18);
  transform: translateX(100%);
  transition: transform .3s cubic-bezier(.32, .72, 0, 1);
  display: flex;
  flex-direction: column;
  outline: none;
}

.chf-drawer.is-open[data-mode="panel"] .chf-drawer-panel { transform: none; }

.chf-drawer[data-mode="sheet"] .chf-drawer-panel { display: none; }

.chf-drawer-inner {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.chf-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 24px;
  border-bottom: 1px solid #E8EDF3;
}

.chf-drawer .chf-drawer-title {
  margin: 0;
  font-family: var(--font-display, 'Manrope', sans-serif);
  font-size: 20px;
  font-weight: 800;
  line-height: 1.2;
  color: inherit;
}

.chf-drawer-count {
  font-size: 13px;
  font-weight: 600;
  color: #718096;
}

.chf-drawer .chf-drawer-close {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: #F4F6F9;
  color: inherit;
  cursor: pointer;
  transition: background .15s ease;
}

.chf-drawer .chf-drawer-close:hover { background: #E8EDF3; }

.chf-drawer-close:focus-visible,
.chf-drawer-btn:focus-visible,
.chf-drawer-qty button:focus-visible,
.chf-drawer-remove:focus-visible {
  outline: 2px solid var(--chf-blue, #1B4F8C);
  outline-offset: 2px;
}

.chf-drawer-items {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 4px 24px;
}

.chf-drawer-item {
  position: relative;
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 14px;
  padding: 18px 0;
  border-bottom: 1px solid #EEF2F6;
}

.chf-drawer-item:last-child { border-bottom: 0; }

.chf-drawer-item--child {
  grid-template-columns: 48px minmax(0, 1fr);
  margin-left: 28px;
  padding: 12px 0;
}

.chf-drawer-item-img {
  aspect-ratio: 1;
  border: 1px solid #E8EDF3;
  border-radius: 10px;
  background: #fff;
  overflow: hidden;
}

.chf-drawer-item-img img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  margin: 0;
}

.chf-drawer-item-body { min-width: 0; }

.chf-drawer .chf-drawer-item-name {
  display: block;
  padding-right: 32px;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.35;
  color: inherit;
  text-decoration: none;
}

.chf-drawer a.chf-drawer-item-name:hover { color: var(--chf-blue, #1B4F8C); }

.chf-drawer-item-meta {
  margin-top: 2px;
  font-size: 12px;
  color: #718096;
}

.chf-drawer-item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
}

.chf-drawer-item-total {
  font-size: 15px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.chf-drawer-included {
  font-size: 12px;
  font-weight: 700;
  color: #2F855A;
}

.chf-drawer-qty {
  display: inline-flex;
  align-items: center;
  border: 1px solid #D9E1EA;
  border-radius: 10px;
  overflow: hidden;
}

.chf-drawer .chf-drawer-qty button {
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: #fff;
  color: inherit;
  font-size: 18px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  box-shadow: none;
}

.chf-drawer .chf-drawer-qty button:hover:not(:disabled) { background: #F4F6F9; }
.chf-drawer .chf-drawer-qty button:disabled { color: #CBD5E0; cursor: not-allowed; }

.chf-drawer-qty-n {
  min-width: 32px;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.chf-drawer .chf-drawer-remove {
  position: absolute;
  top: 14px;
  right: -6px;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #A0AEC0;
  cursor: pointer;
  box-shadow: none;
}

.chf-drawer .chf-drawer-remove:hover { background: #FDECEC; color: var(--sale, #E53E3E); }

.chf-drawer-foot {
  padding: 18px 24px calc(20px + env(safe-area-inset-bottom));
  border-top: 1px solid #E8EDF3;
  background: #fff;
  box-shadow: 0 -8px 24px rgba(15, 39, 71, .05);
}

.chf-drawer-line {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 6px;
  font-size: 14px;
  color: #4A5568;
  font-variant-numeric: tabular-nums;
}

.chf-drawer-line--saving { color: #2F855A; font-weight: 600; }

.chf-drawer-line--total {
  margin: 4px 0 0;
  font-size: 17px;
  font-weight: 800;
  color: inherit;
}

.chf-drawer .chf-drawer-note {
  margin: 4px 0 14px;
  font-size: 12px;
  color: #718096;
}

.chf-drawer .chf-drawer-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  min-height: 50px;
  padding: 0 20px;
  border: 1.5px solid transparent;
  border-radius: 12px;
  box-sizing: border-box;
  font-family: inherit;
  font-size: 15px;
  font-weight: 800;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}

.chf-drawer .chf-drawer-btn + .chf-drawer-btn { margin-top: 10px; }

.chf-drawer .chf-drawer-btn--primary {
  background: var(--chf-orange, #E87722);
  color: #fff;
  box-shadow: 0 6px 16px rgba(232, 119, 34, .28);
}

.chf-drawer .chf-drawer-btn--primary:hover { background: #D56A18; color: #fff; }

.chf-drawer .chf-drawer-btn--ghost {
  background: #fff;
  border-color: #CBD5E0;
  color: var(--chf-blue-ink, #0F2747);
}

.chf-drawer .chf-drawer-btn--ghost:hover { border-color: var(--chf-blue, #1B4F8C); color: var(--chf-blue, #1B4F8C); }

.chf-drawer-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 40px 32px;
  text-align: center;
  color: #A0AEC0;
}

.chf-drawer .chf-drawer-empty p {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: #4A5568;
}

.chf-drawer-empty .chf-drawer-btn { max-width: 240px; }

/* Busy veil while the cart is being read or changed. */
.chf-drawer-busy {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, .6);
}

.chf-drawer.is-busy .chf-drawer-busy { display: flex; }

.chf-drawer-busy span {
  width: 34px;
  height: 34px;
  border: 3px solid #E2E8F0;
  border-top-color: var(--chf-blue, #1B4F8C);
  border-radius: 50%;
  animation: chf-drawer-spin .7s linear infinite;
}

@keyframes chf-drawer-spin { to { transform: rotate(360deg); } }

/* ── Mobile: "Added to cart" bottom sheet ──────────────────────────────── */

.chf-sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: none;
  padding: 10px 20px calc(20px + env(safe-area-inset-bottom));
  background: #fff;
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -12px 40px rgba(15, 39, 71, .2);
  transform: translateY(100%);
  transition: transform .32s cubic-bezier(.32, .72, 0, 1);
  outline: none;
}

.chf-drawer[data-mode="sheet"] .chf-sheet { display: block; }
.chf-drawer.is-open[data-mode="sheet"] .chf-sheet { transform: none; }

.chf-sheet-handle {
  display: block;
  width: 40px;
  height: 4px;
  margin: 0 auto 10px;
  border-radius: 4px;
  background: #D9E1EA;
}

.chf-sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.chf-sheet-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 800;
}

.chf-sheet-title svg { color: #2F855A; }

.chf-sheet-item {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  padding: 16px 0 18px;
}

.chf-drawer .chf-sheet-item .chf-drawer-item-name { padding-right: 0; font-size: 15px; }

.chf-sheet-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin-top: 6px;
  font-size: 14px;
  color: #4A5568;
}

.chf-sheet-meta .amount { font-weight: 800; color: var(--chf-blue-ink, #0F2747); }
.chf-sheet-meta del { opacity: .6; }
.chf-sheet-meta del .amount { font-weight: 500; }
.chf-sheet-meta ins { text-decoration: none; }

.chf-sheet-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.chf-drawer .chf-sheet-actions .chf-drawer-btn + .chf-drawer-btn { margin-top: 0; }

/* On phones the full cart panel, if opened, takes the whole width. */
@media (max-width: 768px) {
  .chf-drawer-panel { width: 100vw; }
  .chf-drawer-head { padding: 16px 20px; }
  .chf-drawer-items { padding: 4px 20px; }
  .chf-drawer-foot { padding-left: 20px; padding-right: 20px; }
}

/* ── Error toast ───────────────────────────────────────────────────────── */

.chf-toast {
  position: fixed;
  left: 50%;
  bottom: 96px;
  z-index: 100020;
  max-width: min(440px, calc(100vw - 32px));
  padding: 14px 18px;
  border-radius: 12px;
  background: #0F2747;
  color: #fff;
  font-family: var(--font-body, 'Plus Jakarta Sans', system-ui, sans-serif);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  box-shadow: 0 12px 32px rgba(15, 39, 71, .3);
  transform: translateX(-50%);
}

.chf-toast[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) {
  .chf-drawer-overlay,
  .chf-drawer-panel,
  .chf-sheet { transition: none; }
}
