/* ────────────────────────────────────────────────────────────────────────────
   Product dialog — single geometry source for the bounded product modal.

   The dialog card (`.pdg-dialog`) is rendered by `product_dialog.html` and is
   shared verbatim by:
     • the host page `/producto/<pk>/` (server-rendered, already open), and
     • the lazy fragment `?fragment=dialog` injected by `product-dialog.js`
       into a single overlay on catalog/home/materials.

   Themes only contribute color/type tokens (--bg-1, --line, --brand, --muted,
   --font-display, --cta, --price...); geometry lives here and nowhere else.
   ──────────────────────────────────────────────────────────────────────────── */

.pdg-overlay {
  position: fixed;
  inset: 0;
  z-index: 240;
  padding: clamp(12px, 2.5vw, 24px);
}
.pdg-overlay[hidden] { display: none; }
.pdg-overlay-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 8, 15, .62);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.pdg-overlay-body {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
}
body.pdg-open { overflow: hidden; }

/* `hidden` always wins inside the dialog (overrides any `display` utility on
   img / zoom / thumbs / review messages). */
.pdg-dialog [hidden] { display: none !important; }

/* Bounded card: never a fullscreen bottom sheet. The shell only defines the
   outer bounds (width / height / margin / rounding); the two-column layout
   lives on `.pdg-grid`, which is the direct gallery/info wrapper. */
.pdg-dialog {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: min(1000px, 100%);
  max-width: 100%;
  max-height: 84dvh;
  margin: 0;
  border-radius: 22px;
  border: 1px solid color-mix(in oklab, var(--brand) 22%, var(--line));
  background: var(--bg-1);
  box-shadow: 0 28px 100px rgba(0, 0, 0, .5);
  overflow: hidden;
}

/* Direct gallery/info grid wrapper: owns the columns and the inner scroll. */
.pdg-grid {
  display: grid;
  grid-template-columns: minmax(260px, 1.05fr) minmax(0, .95fr);
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.pdg-close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 30;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: color-mix(in oklab, var(--bg-1) 88%, transparent);
  color: var(--text);
  cursor: pointer;
  display: grid;
  place-items: center;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.pdg-close:hover { background: var(--bg-2); }

/* ── Gallery ── */
.pdg-gallery { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg-2); }
.pdg-image-open { position: absolute; inset: 0; display: grid; place-items: center; width: 100%; height: 100%; min-width: 0; min-height: 0; padding: 0; border: 0; background: transparent; cursor: zoom-in; }
.pdg-image-open:focus-visible { outline: 3px solid var(--brand); outline-offset: -3px; }
.pdg-media {
  position: relative;
  aspect-ratio: 1;
  width: 100%;
  min-width: 0;
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.pdg-media img {
  position: absolute;
  inset: 0;
  margin: auto;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 10px;
  max-width: 100%;
  max-height: 100%;
  display: block;
}
.pdg-media .sf-image-zoom-btn { top: 12px; right: 12px; }
.pdg-media .pdg-media-empty {
  font-size: 4rem;
  color: var(--muted);
  opacity: .35;
}
.pdg-thumbs { display: flex; gap: 8px; overflow-x: auto; padding: 0 12px 12px; }
.pdg-thumbs[hidden] { display: none; }
.pdg-thumb {
  width: 56px;
  height: 56px;
  flex: 0 0 auto;
  border: 2px solid transparent;
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-1);
  padding: 0;
  cursor: pointer;
  opacity: .8;
}
.pdg-thumb.active { border-color: var(--brand); opacity: 1; }
.pdg-thumb img { width: 100%; height: 100%; object-fit: contain; padding: 3px; display: block; }

/* Gallery effect animations (fade / focus / stack). */
.pdg-gallery.gallery-effect-fade .pdg-media img.gallery-frame-swap { animation: pdg-gallery-fade .26s ease; }
.pdg-gallery.gallery-effect-focus .pdg-media img {
  object-fit: contain;
  padding: 20px;
  background: radial-gradient(circle at 50% 44%, color-mix(in oklab, var(--brand) 12%, transparent), transparent 56%);
}
.pdg-gallery.gallery-effect-focus .pdg-media img.gallery-frame-swap { animation: pdg-gallery-focus .28s ease; }
.pdg-gallery.gallery-effect-stack .pdg-media img {
  object-fit: contain !important;
  padding: 2px;
  width: 88%;
  height: 82%;
  border-radius: 20px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .26);
}
@keyframes pdg-gallery-fade { from { opacity: .2; } to { opacity: 1; } }
@keyframes pdg-gallery-focus { from { opacity: .45; transform: scale(.96); } to { opacity: 1; transform: scale(1); } }
@media (prefers-reduced-motion: reduce) {
  .pdg-gallery .pdg-media img.gallery-frame-swap { animation: none; }
}

/* ── Info column ── */
.pdg-info { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.pdg-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 24px 26px 12px;
}
.pdg-cat {
  display: inline-flex;
  margin-bottom: 8px;
  padding: 4px 9px;
  border-radius: 999px;
  background: color-mix(in oklab, var(--brand) 14%, transparent);
  color: var(--brand);
  font-size: .72rem;
  font-weight: 800;
}
.pdg-cat[hidden] { display: none; }
.pdg-brand { color: var(--muted); font-size: .78rem; font-weight: 700; margin-bottom: 4px; }
.pdg-rating { color: var(--price, var(--cta)); font-size: .82rem; font-weight: 800; margin-bottom: 8px; }
.pdg-title {
  margin: 0 0 10px;
  font-family: var(--font-display, 'Space Grotesk', sans-serif);
  font-size: clamp(1.3rem, 2.4vw, 1.9rem);
  line-height: 1.15;
  color: var(--text);
}
.pdg-desc { margin: 0 0 14px; color: var(--muted); line-height: 1.55; font-size: .9rem; }
.pdg-spec {
  display: grid;
  gap: 6px;
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: 12px;
  background: color-mix(in oklab, var(--text) 4%, transparent);
  border: 1px solid var(--line);
}
.pdg-spec-row { display: flex; justify-content: space-between; gap: 12px; font-size: .84rem; }
.pdg-spec-row > span:first-child { color: var(--muted); }
.pdg-spec-row > span:last-child { color: var(--text); font-weight: 700; text-align: right; }
.pdg-spec[hidden] { display: none; }
.pdg-attributes { list-style: none; padding: 0; margin: 0 0 12px; font-size: .82rem; color: var(--muted); }
.pdg-attributes li { margin-bottom: 4px; }
.pdg-price {
  margin: 0 0 12px;
  font-family: var(--font-display, 'Space Grotesk', sans-serif);
  font-size: 1.6rem;
  font-weight: 900;
  color: var(--price, var(--cta));
}
.pdg-price del { font-size: 1rem; color: var(--muted); font-weight: 600; margin-right: 8px; }
.pdg-discount { margin-left: 8px; font-size: .8rem; font-weight: 800; color: var(--brand); }
.pdg-discount[hidden] { display: none; }

/* ── Variants (shared compact selector: Principal + variants, 3 per row) ── */
.pdg-variants { margin-bottom: 14px; min-width: 0; }
.pdg-variants-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.pdg-variants-head span { font-size: .78rem; font-weight: 700; color: var(--text); text-transform: uppercase; letter-spacing: .04em; }
.pdg-variant-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; min-width: 0; }
.pdg-variant-grid > * { min-width: 0; overflow-wrap: anywhere; }
.pdg-variant-option {
  min-height: 32px;
  min-width: 0;
  padding: 4px 6px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg-1);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  transition: all .15s;
}
.pdg-variant-option:hover { color: var(--text); border-color: color-mix(in oklab, var(--brand) 45%, transparent); }
.pdg-variant-option.active { background: var(--brand); border-color: transparent; color: var(--on-brand, #fff); }
.pdg-variant-option.active .pdg-opt-nostock { color: var(--on-brand, #fff) !important; opacity: .95; }
.pdg-variant-option:disabled { opacity: .55; cursor: not-allowed; }
.pdg-opt-label { font-size: .78rem; line-height: 1.2; overflow-wrap: anywhere; }
.pdg-opt-nostock { font-size: .72rem; color: #ef4444; font-weight: 600; }
.pdg-stock { font-size: .8rem; margin: 0 0 12px; font-weight: 600; }

/* ── Share / CTA / actions ── */
.pdg-share {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: 4px 10px;
  border: 1px solid color-mix(in oklab, #25D366 42%, var(--line));
  border-radius: 8px;
  background: color-mix(in oklab, #25D366 10%, transparent);
  color: color-mix(in oklab, #25D366 72%, var(--text));
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
  margin-bottom: 12px;
}
.pdg-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.pdg-qty { display: inline-flex; align-items: center; gap: .5rem; background: var(--bg-1); border: 1px solid var(--line); border-radius: 10px; padding: .4rem .75rem; }
.pdg-qty button { background: none; border: none; color: var(--text); font-size: 1.05rem; cursor: pointer; padding: 0 .2rem; }
.pdg-qty output { min-width: 1.5rem; text-align: center; font-weight: 600; color: var(--text); }
.pdg-add {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 32px;
  padding: 4px 12px;
  border-radius: 8px;
  border: 0;
  background: linear-gradient(135deg, var(--brand), var(--brand-dark, var(--brand)));
  color: var(--on-brand, #fff);
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
  width: auto;
  max-width: max-content;
  white-space: nowrap;
}
.pdg-add:disabled { opacity: .55; cursor: not-allowed; }
.pdg-wa-cta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  padding: .8rem 1.4rem;
  background: #25D366;
  color: #fff;
  border-radius: 10px;
  font-size: .95rem;
  font-weight: 700;
  text-decoration: none;
  margin-bottom: 12px;
}
.pdg-cart-message { font-size: .82rem; margin: 0 0 10px; }
.pdg-cart-message[hidden] { display: none; }
.pdg-fulfillment { display: grid; gap: 6px; margin: 8px 0 14px; color: var(--muted); font-size: .78rem; }
.pdg-fulfillment p { margin: 0; }
.pdg-fulfillment a { color: var(--brand); text-decoration: none; }

/* ── Reviews ── */
.pdg-reviews { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.pdg-reviews-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.pdg-reviews-head h3 { margin: 0; font-family: var(--font-display, 'Space Grotesk', sans-serif); font-size: 1.05rem; color: var(--text); }
.pdg-reviews-summary { color: var(--price, var(--cta)); font-size: .8rem; font-weight: 800; white-space: nowrap; }
.pdg-review-list { display: grid; gap: 10px; margin-bottom: 16px; }
.pdg-review-card { padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: color-mix(in oklab, var(--text) 4%, transparent); }
.pdg-review-stars { color: var(--price, var(--cta)); font-weight: 900; letter-spacing: .04em; }
.pdg-review-title { margin: 5px 0 4px; color: var(--text); font-weight: 800; }
.pdg-review-comment { margin: 0; color: var(--muted); line-height: 1.55; font-size: .86rem; }
.pdg-review-author { margin-top: 7px; color: var(--muted); font-size: .76rem; }
.pdg-review-empty { color: var(--muted); border: 1px dashed var(--line); border-radius: 14px; padding: 12px; font-size: .84rem; }
.pdg-review-form { display: flex; flex-direction: column; gap: 12px; }
.pdg-review-form label { display: block; font-size: .8rem; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.pdg-review-form select,
.pdg-review-form input,
.pdg-review-form textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--text);
  border-radius: 12px;
  padding: 11px;
  outline: none;
  font-size: .92rem;
}
.pdg-review-form textarea { min-height: 110px; resize: vertical; }
.pdg-review-msg { border-radius: 12px; padding: 10px 12px; margin-bottom: 14px; font-size: .85rem; }
.pdg-review-msg[hidden] { display: none; }
.pdg-review-msg--ok { background: rgba(16,185,129,.12); border: 1px solid rgba(16,185,129,.25); color: #6ee7b7; }
.pdg-review-msg--err { background: rgba(239,68,68,.12); border: 1px solid rgba(239,68,68,.25); color: #fca5a5; }
.pdg-review-submit {
  width: 100%;
  justify-content: center;
  margin-top: 4px;
}
.pdg-login-cta { font-size: .9rem; color: var(--muted); margin: 0 0 16px; }
.pdg-login-link { width: 100%; justify-content: center; }

/* Focus visibility */
.pdg-close:focus-visible,
.pdg-thumb:focus-visible,
.pdg-variant-option:focus-visible,
.pdg-add:focus-visible,
.pdg-qty button:focus-visible,
.pdg-review-submit:focus-visible {
  outline: 3px solid color-mix(in oklab, var(--brand) 60%, transparent);
  outline-offset: 2px;
}

/* ── Responsive (bounded, not fullscreen) ── */
@media (max-width: 820px) {
  .pdg-dialog {
    width: min(100%, 640px);
    max-height: 84dvh;
  }
  .pdg-grid {
    grid-template-columns: 1fr;
    overflow-y: auto;
  }
  .pdg-gallery { flex-direction: row; align-items: center; gap: 10px; padding: 12px 12px 0; }
  .pdg-media { flex: 1 1 auto; aspect-ratio: 1; max-height: clamp(200px, 40vh, 300px); }
  .pdg-thumbs { flex-direction: column; overflow-y: auto; overflow-x: visible; padding: 0 0 0 0; }
  .pdg-thumb { width: 46px; height: 46px; }
  .pdg-scroll { overflow: visible; padding: 14px 16px 16px; }
}
@media (max-width: 520px) {
  .pdg-overlay { padding: 12px; }
  .pdg-dialog { width: 100%; max-height: 84dvh; border-radius: 18px; }
  .pdg-gallery { flex-direction: column; }
  .pdg-thumbs { flex-direction: row; overflow-x: auto; }
}

/* ── Host page `/producto/<pk>/` — the same dialog, already open ─────────── */
.pdg-host-page { padding: 20px 0 56px; min-height: 70vh; }
.pdg-host { display: grid; place-items: center; }
.pdg-host .pdg-dialog { margin: 0 auto; }
.pdg-back {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  color: var(--muted);
  font-size: .875rem;
  text-decoration: none;
  margin-bottom: 1.25rem;
}
.pdg-back:hover { color: var(--text); }
@media (max-width: 820px) {
  .pdg-host-page { padding: 8px 0 32px; }
  .pdg-host { place-items: start center; }
  .pdg-host .pdg-dialog { width: min(94vw, 640px); }
}
