/* Product detail: phone first, photo first, fixed actions within thumb reach. */
.modal.product-detail-modal {
  height: 100vh; height: 100dvh; max-height: none; margin: 0; padding: 0;
  display: flex; flex-direction: column; overflow: hidden;
  border: 0; border-radius: 0; animation: none;
}
.product-detail-modal::before { display: none; }
.product-detail-modal .product-detail-head {
  position: static; flex-shrink: 0; margin: 0;
  padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--border); min-height: 72px;
}
.product-detail-head > div { min-width: 0; }
.product-detail-title { flex: 1; }
.product-header-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.product-detail-head .product-header-button { display: grid; place-items: center; width: 48px; height: 48px; padding: 0; border: 1px solid var(--border); border-radius: 14px; background: var(--bg); color: var(--text); cursor: pointer; }
.product-detail-head .product-header-delete { color: var(--danger); }
.product-header-button .icon { width: 21px; height: 21px; }
.product-detail-head .product-header-button:disabled { background: #303037; border-color: #303037; color: #bdbdc4; cursor: not-allowed; }
.product-detail-head .product-header-button:active:not(:disabled) { background: var(--primary-soft); }
@media (hover: hover) { .product-detail-head .product-header-button:hover:not(:disabled) { background: var(--primary-soft); } }
.product-detail-head h2 { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; font-size: 18px; margin-top: 3px !important; }
.product-detail-head .eyebrow { display: block; font-size: 9px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.product-detail-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 12px max(16px, env(safe-area-inset-right)) 20px max(16px, env(safe-area-inset-left)); }
.product-detail-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; }
#productGallery { min-width: 0; }
.product-detail-info { min-width: 0; }
.product-summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 16px 0; border-top: 1px solid var(--border); }
.product-summary > div { display: grid; gap: 3px; }
.product-summary .price { font-size: 23px; }
.product-summary .price small { font-size: 13px; font-weight: 400; color: var(--muted); }
.product-detail-actions { flex-shrink: 0; padding: 10px max(12px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); border-top: 1px solid var(--border); background: var(--card); }
.product-detail-actions .quick-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin: 0; }
.product-detail-actions .btn { min-height: 48px; padding: 10px 4px; font-size: 13px; }
.product-detail-actions .btn:only-child { grid-column: 1 / -1; }
.product-detail-back { padding: 0; }

.product-gallery { min-width: 0; }
.photo-angle { border-radius: 0; border: 0; border-top: 1px solid var(--border); min-height: 44px; font-size: 12px; padding: 8px 4px; }
.gallery-frame, .gallery-empty {
  width: min(100%, calc((100vh - 328px) * .8));
  width: min(100%, calc((100dvh - 328px) * .8));
  aspect-ratio: 4 / 5; margin: 0 auto; position: relative;
  overflow: hidden; border-radius: 20px; background: var(--bg);
  border: 1px solid var(--border); box-shadow: var(--shadow);
}
.gallery-viewport { display: flex; width: 100%; height: 100%; overflow-x: auto; overflow-y: hidden; scroll-snap-type: x mandatory; scroll-snap-stop: always; scrollbar-width: none; overscroll-behavior-x: contain; }
.gallery-viewport::-webkit-scrollbar, .gallery-thumb-row::-webkit-scrollbar { display: none; }
.gallery-photo { flex: 0 0 100%; width: 100%; height: 100%; position: relative; padding: 0; border: 0; background: var(--bg); color: var(--muted); scroll-snap-align: center; cursor: zoom-in; }
.gallery-photo img { width: 100%; height: 100%; display: block; object-fit: contain; }
.gallery-photo:focus-visible { outline-offset: -4px; }
.gallery-counter, .gallery-open-hint { position: absolute; top: 12px; z-index: 1; color: #fff; background: rgba(22, 22, 27, .68); border-radius: 999px; padding: 6px 10px; font-size: 11px; pointer-events: none; }
.gallery-counter { right: 12px; font-variant-numeric: tabular-nums; min-width: 40px; text-align: center; }
.gallery-open-hint { left: 12px; }
.gallery-dots { position: absolute; bottom: 4px; left: 50%; transform: translateX(-50%); display: flex; }
.gallery-dots button { display: grid; place-items: center; width: 44px; height: 44px; padding: 0; background: none; border: 0; cursor: pointer; }
.gallery-dots button::after { content: ''; width: 7px; height: 7px; border-radius: 50%; background: rgba(255, 255, 255, .78); box-shadow: 0 0 0 1px rgba(0, 0, 0, .4); }
.gallery-dots button[aria-pressed="true"]::after { width: 18px; border-radius: 5px; background: var(--primary); box-shadow: 0 0 0 1px #fff; }
.gallery-thumb-row { position: relative; display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; overscroll-behavior-x: contain; margin-top: 10px; padding: 2px; }
.gallery-thumb { flex: 0 0 76px; width: 76px; min-height: 104px; padding: 4px; border: 2px solid transparent; border-radius: 12px; background: var(--bg); color: var(--muted); cursor: pointer; }
.gallery-thumb[aria-pressed="true"] { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-dark); }
.gallery-thumb-image { display: block; position: relative; aspect-ratio: 4 / 5; overflow: hidden; border-radius: 7px; }
.gallery-thumb-image img { width: 100%; height: 100%; display: block; object-fit: cover; }
.gallery-thumb-label { display: block; margin-top: 4px; font-size: 10px; font-weight: 600; white-space: nowrap; }
.gallery-description { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 4px; margin-top: 6px; font-size: 10px; color: var(--muted); line-height: 1.6; }
.gallery-fallback { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; flex-direction: column; gap: 10px; color: var(--muted); font-size: 13px; padding: 16px; }
[data-image-state="error"] > img { visibility: hidden; }
[data-image-state="error"] > .gallery-fallback { display: flex; }
[data-image-state="loading"] > img { opacity: 0; }
[data-image-state="loading"]::before { content: ''; position: absolute; inset: 0; background: linear-gradient(110deg, var(--bg) 25%, var(--primary-soft) 45%, var(--bg) 65%); background-size: 240% 100%; animation: gallery-shimmer 1.6s ease infinite; pointer-events: none; }
.gallery-thumb-image .gallery-fallback { padding: 4px; }
.gallery-thumb-image .gallery-fallback svg { width: 24px; height: 24px; }
.gallery-thumb-image .gallery-fallback span { display: none; }
.gallery-empty { display: flex; justify-content: center; align-items: center; flex-direction: column; gap: 8px; text-align: center; padding: 24px; color: var(--muted); }
.gallery-empty > .gallery-fallback { position: static; display: flex; }
.gallery-empty > .gallery-fallback span { display: none; }
.gallery-empty strong { font-size: 15px; color: var(--text); }
.gallery-empty > span { font-size: 12px; }
@keyframes gallery-shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* Fixed fullscreen viewer. Zoom gestures are scoped to its image stage. */
.photo-viewer { --bg: #17171c; --primary-soft: #292931; --muted: #b7b7c1; position: fixed; inset: 0; z-index: 220; background: #17171c; color: #f6f6fa; display: flex; flex-direction: column; padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
.photo-viewer:focus { outline: none; }
.viewer-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-shrink: 0; padding: calc(10px + env(safe-area-inset-top)) 16px 10px; }
.viewer-header > div { display: grid; gap: 4px; min-width: 0; }
.viewer-header strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.viewer-caption { color: #b7b7c1; font-size: 12px; }
.viewer-stage { position: relative; flex: 1; min-height: 0; overflow: hidden; display: flex; align-items: center; justify-content: center; touch-action: none; user-select: none; cursor: zoom-in; }
.viewer-stage img { flex: 0 0 auto; max-width: 100%; max-height: 100%; width: auto; height: auto; transform-origin: center; will-change: transform; object-fit: contain; }
.viewer-stage.is-zoomed { cursor: grab; }
.viewer-stage .gallery-fallback { padding-bottom: 72px; }
.viewer-retry { display: none; position: absolute; top: calc(50% + 40px); left: 50%; transform: translateX(-50%); min-height: 48px; border: 1px solid #53535e; border-radius: 12px; padding: 10px 16px; background: #292931; color: #fff; cursor: pointer; }
.viewer-stage[data-image-state="error"] .viewer-retry { display: block; }
.viewer-help { flex-shrink: 0; padding: 10px 16px; text-align: center; color: #b7b7c1; font-size: 11px; }
.viewer-controls { flex-shrink: 0; display: grid; grid-template-columns: 48px minmax(0, 1fr) minmax(0, 1fr) 48px; gap: 8px; padding: 8px 12px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid #32323b; }
.viewer-icon-button, .viewer-zoom, .viewer-close-bottom { min-width: 48px; min-height: 48px; border: 1px solid #44444e; border-radius: 14px; color: #f6f6fa; background: #292931; cursor: pointer; padding: 8px; font-size: 13px; }
.viewer-icon-button { font-size: 28px; flex-shrink: 0; width: 48px; height: 48px; }
.viewer-close-bottom { background: #f1e8ed; border-color: #f1e8ed; color: #30252d; font-weight: 600; }
.viewer-controls button:disabled { opacity: .35; cursor: default; }
@media (prefers-reduced-motion: reduce) { [data-image-state="loading"]::before { animation: none; } }
@media (min-width: 901px) {
  .product-detail-back { padding: 24px; }
  .modal.product-detail-modal { max-width: 1060px; height: min(840px, calc(100vh - 48px)); height: min(840px, calc(100dvh - 48px)); border: 1px solid var(--border); border-radius: 24px; margin: auto; }
  .product-detail-modal .product-detail-head { padding: 14px 24px; }
  .product-detail-body { padding: 20px 24px; }
  .product-detail-layout { grid-template-columns: minmax(0, 380px) minmax(0, 1fr); gap: 28px; align-items: start; }
  #productGallery { position: sticky; top: 0; }
  .gallery-frame, .gallery-empty { width: 100%; }
  .product-summary { padding-top: 0; border-top: 0; }
  .product-detail-actions { padding: 12px 24px; }
  .product-detail-actions .quick-actions { max-width: 500px; margin-left: auto; }
  .viewer-controls { grid-template-columns: 48px 160px 160px 48px; justify-content: center; }
}
