/* Popup giỏ hàng sau khi thêm vào giỏ (inc/cart-popup.php, assets/cart-popup.js) */
html.ms-cartpop-lock, html.ms-cartpop-lock body { overflow: hidden; }

/* Hộp giữa màn hình; danh sách dài thì cuộn bên trong hộp. */
.ms-cartpop { position: fixed; inset: 0; z-index: 100000; display: flex; align-items: center; justify-content: center; padding: 16px; }
.ms-cartpop[hidden] { display: none; }
.ms-cartpop *, .ms-cartpop *::before, .ms-cartpop *::after { box-sizing: border-box; }
.ms-cartpop-overlay { position: absolute; inset: 0; background: rgba(0, 0, 0, .5); opacity: 0; transition: opacity .2s ease; }
.ms-cartpop-panel {
	position: relative;
	display: flex;
	flex-direction: column;
	width: 100%;
	max-width: 760px;
	max-height: min(85vh, 760px);
	overflow: hidden;
	border-radius: 16px;
	background: #fff;
	box-shadow: 0 24px 60px rgba(0, 0, 0, .25);
	color: var(--ms-ink, #171717);
	outline: none;
	opacity: 0;
	transform: translateY(12px) scale(.97);
	transition: opacity .2s ease, transform .2s ease;
}
.ms-cartpop.is-open .ms-cartpop-overlay { opacity: 1; }
.ms-cartpop.is-open .ms-cartpop-panel { opacity: 1; transform: none; }
@media (max-width: 549px) {
	.ms-cartpop { padding: 12px; }
	.ms-cartpop-panel { max-height: 90vh; border-radius: 14px; }
}
@media (prefers-reduced-motion: reduce) {
	.ms-cartpop-overlay, .ms-cartpop-panel { transition: none; }
}

.ms-cartpop-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--ms-line, #e5e5e5); }
.ms-cartpop-head h2 { margin: 0; font-size: 18px; font-weight: 900; letter-spacing: -.01em; text-transform: uppercase; }
.ms-cartpop-x { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; margin: 0 -8px 0 0; padding: 0; border: 0; border-radius: 50%; background: none; color: var(--ms-ink, #171717); cursor: pointer; }
.ms-cartpop-x:hover, .ms-cartpop-x:focus-visible { background: #f5f5f5; }

.ms-cartpop-body { display: flex; flex: 1; flex-direction: column; min-height: 0; }
.ms-cartpop-ok { display: flex; align-items: center; gap: 8px; margin: 0; padding: 12px 20px; background: #ecfdf3; color: var(--ms-green, #16a34a); font-size: 14px; font-weight: 700; }
.ms-cartpop-count { margin: 0; padding: 12px 20px 4px; color: var(--ms-muted, #737373); font-size: 13px; }
.ms-cartpop-count strong { color: var(--ms-ink, #171717); }
.ms-cartpop-empty { padding: 40px 20px; color: var(--ms-muted, #737373); text-align: center; }

.ms-cartpop-list { flex: 1; min-height: 0; margin: 0; padding: 4px 20px 8px; overflow-y: auto; overscroll-behavior: contain; list-style: none; }
.ms-cartpop-item { display: flex; gap: 12px; margin: 0; padding: 12px 0; border-bottom: 1px solid #f0f0f0; }
.ms-cartpop-item:last-child { border-bottom: 0; }
.ms-cartpop-item.is-new { margin: 6px -10px; padding: 10px; border: 1px solid var(--ms-accent-200, #fed7aa); border-radius: 12px; background: var(--ms-accent-50, #fff7ed); }
.ms-cartpop-thumb { flex-shrink: 0; width: 64px; height: 64px; overflow: hidden; border: 1px solid var(--ms-line, #e5e5e5); border-radius: 10px; background: #fafafa; }
.ms-cartpop-thumb img { display: block; width: 100%; height: 100%; margin: 0; object-fit: cover; }
.ms-cartpop-info { flex: 1; min-width: 0; }
.ms-cartpop-name { display: -webkit-box; overflow: hidden; color: var(--ms-ink, #171717); font-size: 14px; font-weight: 700; line-height: 1.4; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
a.ms-cartpop-name:hover { color: var(--ms-accent, #f54a00); }
.ms-cartpop-info dl.variation { display: flex; flex-wrap: wrap; gap: 0 6px; margin: 4px 0 0; color: var(--ms-muted, #737373); font-size: 12px; }
.ms-cartpop-info dl.variation dt, .ms-cartpop-info dl.variation dd { margin: 0; padding: 0; font-weight: 400; }
.ms-cartpop-info dl.variation dd p { display: inline; margin: 0; }
.ms-cartpop-price { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-top: 6px; color: var(--ms-muted, #737373); font-size: 13px; }
.ms-cartpop-price strong { color: var(--ms-accent, #f54a00); font-size: 14px; font-weight: 800; }

.ms-cartpop-foot { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 16px 20px; border-top: 1px solid var(--ms-line, #e5e5e5); background: #fafafa; }
.ms-cartpop-total { grid-column: 1 / -1; display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 2px; font-size: 15px; }
.ms-cartpop-foot .ms-cartpop-btn.is-primary { order: 2; } /* Cập nhật giỏ hàng | Thanh toán */
@media (max-width: 549px) {
	.ms-cartpop-foot { grid-template-columns: 1fr; }
}

/* Nút xóa từng sản phẩm */
.ms-cartpop-remove { flex-shrink: 0; align-self: flex-start; display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; margin: -4px -6px 0 0; padding: 0; border: 0; border-radius: 8px; background: none; color: #a3a3a3; cursor: pointer; }
.ms-cartpop-remove:hover, .ms-cartpop-remove:focus-visible { background: #fef2f2; color: #dc2626; }
.ms-cartpop-remove[disabled] { opacity: .5; cursor: wait; }
.ms-cartpop-item.is-removing { opacity: .4; pointer-events: none; transition: opacity .15s; }
.ms-cartpop-error { margin: 0; padding: 10px 20px; background: #fef2f2; color: #b91c1c; font-size: 13px; }
.ms-cartpop-total strong { color: var(--ms-accent, #f54a00); font-size: 20px; font-weight: 900; }
.ms-cartpop-btn { display: flex; align-items: center; justify-content: center; min-height: 46px; padding: 0 16px; border: 1px solid var(--ms-ink, #171717); border-radius: 10px; background: #fff; color: var(--ms-ink, #171717); font-size: 14px; font-weight: 800; letter-spacing: .02em; text-transform: uppercase; }
.ms-cartpop-btn:hover { background: #f5f5f5; color: var(--ms-ink, #171717); }
.ms-cartpop-btn.is-primary { border-color: var(--ms-accent, #f54a00); background: var(--ms-accent, #f54a00); color: #fff; }
.ms-cartpop-btn.is-primary:hover { background: var(--ms-accent-hover, #dc4300); color: #fff; }
.ms-cartpop-continue { margin: 0; padding: 14px 20px; border: 0; border-top: 1px solid var(--ms-line, #e5e5e5); background: #fff; color: var(--ms-text, #525252); font-size: 14px; font-weight: 700; cursor: pointer; }
.ms-cartpop-continue:hover { color: var(--ms-ink, #171717); text-decoration: underline; }
.ms-cartpop-variant { display: block; margin-top: 4px; color: var(--ms-muted, #737373); font-size: 12px; }

/* Đơn giá + ô số lượng (−  n  +) */
.ms-cartpop-unit { margin-top: 4px; color: var(--ms-muted, #737373); font-size: 13px; }
.ms-cartpop-price { align-items: center; margin-top: 8px; }
.ms-cartpop-qty { display: inline-flex; align-items: stretch; height: 34px; overflow: hidden; border: 1px solid #d4d4d4; border-radius: 8px; background: #fff; }
.ms-cartpop-qty input[type="number"] {
	width: 46px;
	height: 100%;
	min-height: 0;
	margin: 0;
	padding: 0 2px;
	border: 0;
	border-right: 1px solid #e5e5e5;
	border-left: 1px solid #e5e5e5;
	border-radius: 0;
	box-shadow: none;
	color: var(--ms-ink, #171717);
	font-size: 14px;
	font-weight: 700;
	text-align: center;
	-moz-appearance: textfield;
}
.ms-cartpop-qty input::-webkit-outer-spin-button, .ms-cartpop-qty input::-webkit-inner-spin-button { margin: 0; -webkit-appearance: none; }
.ms-cartpop-qty input:focus { outline: 2px solid var(--ms-accent, #f54a00); outline-offset: -2px; }
.ms-cartpop-step { width: 32px; height: 100%; min-height: 0; margin: 0; padding: 0; border: 0; background: #fafafa; color: var(--ms-ink, #171717); font-size: 18px; line-height: 1; cursor: pointer; }
.ms-cartpop-step:hover:not([disabled]) { background: #f0f0f0; }
.ms-cartpop-step[disabled] { color: #c4c4c4; cursor: not-allowed; }
.ms-cartpop-qty.is-fixed { opacity: .7; }
.ms-cartpop-item.is-zero .ms-cartpop-info { opacity: .45; } /* số lượng 0 → sẽ xóa khi bấm cập nhật */

/* Ghi chú + 2 nút */
.ms-cartpop-note { grid-column: 1 / -1; display: grid; gap: 6px; margin: 0; font-size: 13px; font-weight: 700; }
.ms-cartpop-note textarea { width: 100%; min-height: 58px; margin: 0; padding: 8px 12px; border: 1px solid #d4d4d4; border-radius: 10px; background: #fff; box-shadow: none; color: var(--ms-ink, #171717); font-size: 14px; font-weight: 400; line-height: 1.5; resize: vertical; }
.ms-cartpop-note textarea:focus { border-color: var(--ms-accent, #f54a00); outline: none; }
.ms-cartpop-foot .ms-cartpop-btn { width: 100%; margin: 0; cursor: pointer; }
button.ms-cartpop-btn { font-family: inherit; }
.ms-cartpop-btn.is-dirty { border-color: var(--ms-accent, #f54a00); background: var(--ms-accent-50, #fff7ed); color: var(--ms-accent, #f54a00); }
.ms-cartpop-panel.is-busy .ms-cartpop-body { opacity: .6; pointer-events: none; transition: opacity .15s; }

/* "Tiếp tục mua sắm" nằm trong popup (cuối cột tóm tắt / dưới thông báo giỏ trống) */
.ms-cartpop-foot .ms-cartpop-continue { grid-column: 1 / -1; padding: 8px 0 0; border: 0; background: none; }
.ms-cartpop-empty p { margin: 0 0 12px; }
.ms-cartpop-empty .ms-cartpop-continue { padding: 10px 16px; border: 1px solid var(--ms-line, #e5e5e5); border-radius: 10px; }
.ms-cartpop-panel { max-height: 90vh; }

/* Desktop: 2 cột – trái danh sách sản phẩm (cao hết popup, cuộn riêng), phải tóm tắt + ghi chú + nút */
@media (min-width: 850px) {
	.ms-cartpop-panel { max-width: 1000px; max-height: min(90vh, 880px); }
	.ms-cartpop-body {
		display: grid;
		grid-template-columns: minmax(0, 1fr) 340px;
		grid-template-rows: auto auto minmax(0, 1fr);
	}
	.ms-cartpop-ok, .ms-cartpop-error { grid-column: 1; grid-row: 1; }
	.ms-cartpop-count { grid-column: 1; grid-row: 2; padding-top: 14px; }
	.ms-cartpop-list { grid-column: 1; grid-row: 3; min-height: 260px; padding: 4px 24px 16px; }
	.ms-cartpop-empty { grid-column: 1 / -1; grid-row: 1 / -1; }
	.ms-cartpop-foot {
		grid-column: 2;
		grid-row: 1 / -1;
		grid-template-columns: 1fr;
		align-content: start;
		gap: 12px;
		padding: 20px;
		overflow-y: auto;
		border-top: 0;
		border-left: 1px solid var(--ms-line, #e5e5e5);
	}
	.ms-cartpop-foot > .ms-cartpop-total { order: 1; padding-bottom: 12px; border-bottom: 1px dashed #d4d4d4; }
	.ms-cartpop-foot > .ms-cartpop-note { order: 2; }
	.ms-cartpop-foot > .ms-cartpop-btn.is-primary { order: 3; }
	.ms-cartpop-foot > [data-ms-cartpop-update] { order: 4; }
	.ms-cartpop-foot > .ms-cartpop-continue { order: 5; }
	.ms-cartpop-note textarea { min-height: 110px; }
	.ms-cartpop-item { gap: 16px; padding: 16px 0; }
	.ms-cartpop-item.is-new { margin: 8px -12px; padding: 14px 12px; }
	.ms-cartpop-thumb { width: 80px; height: 80px; }
	.ms-cartpop-name { font-size: 15px; }
}

/* Điện thoại / máy tính bảng: gọn phần dưới để danh sách sản phẩm có nhiều chỗ nhất */
@media (max-width: 849px) {
	.ms-cartpop { padding: 8px; }
	.ms-cartpop-panel { max-width: 640px; max-height: calc(100vh - 16px); max-height: calc(100dvh - 16px); border-radius: 14px; }
	.ms-cartpop-head { padding: 10px 16px; }
	.ms-cartpop-head h2 { font-size: 16px; }
	.ms-cartpop-ok, .ms-cartpop-error { padding: 8px 16px; font-size: 13px; }
	.ms-cartpop-count { padding: 8px 16px 0; font-size: 12px; }
	.ms-cartpop-list { padding: 0 16px 4px; }
	.ms-cartpop-item { padding: 10px 0; }
	.ms-cartpop-item.is-new { margin: 4px -8px; padding: 8px; }
	.ms-cartpop-foot { grid-template-columns: 1fr 1fr; gap: 8px; padding: 10px 16px 8px; }
	.ms-cartpop-total { margin: 0; font-size: 14px; }
	.ms-cartpop-total strong { font-size: 18px; }
	.ms-cartpop-note { gap: 4px; font-size: 12px; }
	.ms-cartpop-note textarea { min-height: 40px; height: 40px; padding: 8px 12px; resize: none; transition: height .15s; }
	.ms-cartpop-note textarea:focus, .ms-cartpop-note textarea:not(:placeholder-shown) { height: 76px; } /* bấm vào / đã có chữ → mở rộng */
	.ms-cartpop-foot .ms-cartpop-btn { min-height: 44px; padding: 0 8px; font-size: 12.5px; letter-spacing: 0; line-height: 1.2; text-align: center; }
	.ms-cartpop-foot .ms-cartpop-continue { padding: 2px 0 0; font-size: 13px; }
	/* Thứ tự: Tạm tính / Ghi chú / [Cập nhật | Thanh toán] / Tiếp tục mua sắm */
	.ms-cartpop-foot > .ms-cartpop-total { order: 1; }
	.ms-cartpop-foot > .ms-cartpop-note { order: 2; }
	.ms-cartpop-foot > [data-ms-cartpop-update] { order: 3; }
	.ms-cartpop-foot > .ms-cartpop-btn.is-primary { order: 4; }
	.ms-cartpop-foot > .ms-cartpop-continue { order: 5; }
}
