/* Scoped styles for the Hugo DocDia product partial. */

/* 1. Base styles */
.docdia-demo,
.docdia-demo *,
.docdia-demo *::before,
.docdia-demo *::after {
  box-sizing: border-box;
}

.docdia-demo {
  width: 100%;
  margin-inline: auto;
  color: #1f2937;
  line-height: 1.5;
}

.docdia-demo__container {
  container: docdia-demo / inline-size;
}

/* 2. Stage dimensions and narrow-screen overlap */
.docdia-demo__stage {
  --docdia-demo-stage-height: 400px;
  --docdia-demo-body-gap: 12px;
  --docdia-demo-panel-width: 320px;

  /* Leave at least 28px between each marker center and its nearby panel.
     The cqw caps preserve that clearance when the body scales on tiny screens. */
  --docdia-demo-overlap-top: max(0px, min(172px, calc(81.6cqw - 28px)));
  --docdia-demo-overlap-bottom: max(0px, min(80px, calc(44.8cqw - 28px)));
  --docdia-demo-upper-offset: 0px;
  --docdia-demo-lower-offset: 0px;
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(var(--docdia-demo-overlap-top), auto) auto minmax(var(--docdia-demo-overlap-bottom), auto);
  justify-items: center;
  align-items: start;
  padding: 16px 12px;
  border-radius: 10px;
  background: #fff;
  isolation: isolate;
}

/* 3. Body image and independent organ markers */

/* Stable grid tracks preserve the body position while panels fade in and out. */
.docdia-demo__homunculus {
  position: relative;
  grid-column: 1;
  grid-row: 2;
  margin-block: calc(-1 * var(--docdia-demo-overlap-top)) calc(-1 * var(--docdia-demo-overlap-bottom));
  /* Same container-based size in both side-by-side and stacked layouts. */
  width: min(calc((var(--docdia-demo-stage-height) - 2 * var(--docdia-demo-body-gap)) / 1.9), 80cqw);
  max-width: 100%;
}

/* Crop only the bottom 5% of the 1:2 image; preserve the original PNG. */
.docdia-demo__body-crop {
  width: 100%;
  aspect-ratio: 10 / 19;
  overflow: hidden;
}

.docdia-demo__body {
  display: block;
  width: 100%;
  height: auto;
}

.docdia-demo__marker {
  /* Matches renderExaminationBadge in the product renderer. */
  --docdia-demo-accent: #3b82f6;
  position: absolute;
  width: 34px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 2px solid var(--docdia-demo-accent);
  border-radius: 50%;
  background: #eff6ff;
  box-shadow: 0 0 0 3px #ffffffcc, 0 3px 12px #3b82f629;
  transform: translate(-50%, -50%);
}

.docdia-demo__marker img {
  display: block;
  width: 76%;
  height: 76%;
}

.docdia-demo__marker::after {
  content: "";
  position: absolute;
  inset: -8px;
  border: 2px solid var(--docdia-demo-accent);
  border-radius: inherit;
  opacity: 0;
  animation: docdia-demo-pulse-left 12s ease-in-out infinite;
}

/* Percentages are anchored to the cleaned image, not the page viewport. */
.docdia-demo__marker--colon {
  left: 31%;
  top: calc(67% / 0.95);
}

.docdia-demo__marker--stomach {
  left: 55%;
  top: calc(51% / 0.95);
}

.docdia-demo__marker--stomach::after {
  animation-name: docdia-demo-pulse-right;
}

/* 4. Panels: titles, hints, examinations, and date lists */

/* Based on organ-examination-panel.component.scss, without tooltip/interaction. */
.docdia-demo__panel {
  --docdia-demo-slide: 0px;
  position: relative;
  grid-column: 1;
  justify-self: center;
  z-index: 1;
  width: 95%;
  max-width: var(--docdia-demo-panel-width);
  padding: 0.5rem;
  background: #fff;
  border: 1px solid #d9e2ec;
  border-radius: 8px;
  box-shadow: 0 8px 24px #00000026;
  opacity: 0;
  visibility: hidden;
  animation: docdia-demo-panel-left 12s ease-in-out infinite;
}

.docdia-demo__panel--left {
  grid-row: 3;
  left: var(--docdia-demo-lower-offset);
}

.docdia-demo__panel--right {
  grid-row: 1;
  left: var(--docdia-demo-upper-offset);
  animation-name: docdia-demo-panel-right;
}

.docdia-demo__panel-title {
  margin: 0.3rem 0.2rem 0.35rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: #1f2937;
}

.docdia-demo__panel-hint {
  display: flex;
  align-items: flex-start;
  gap: 0.4rem;
  margin: 0 0.2rem 0.4rem;
  padding: 0.3rem 0.35rem;
  border-radius: 6px;
  background: #f8fafc;
  color: #64748b;
  font-size: 0.625rem;
  line-height: 1.3;
}

.docdia-demo__info {
  flex: 0 0 auto;
  width: 11px;
  height: 11px;
  margin-top: 2px;
  border: 1px solid currentColor;
  border-radius: 50%;
  text-align: center;
  font-size: 9px;
  line-height: 9px;
  font-family: Georgia, serif;
  font-weight: bold;
}

.docdia-demo__group {
  --docdia-demo-tree-gap: 0.72rem;
  margin: 0 0.35rem;
  padding-bottom: 0.28rem;
}

.docdia-demo__group-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 28px;
  margin: 0;
  padding: 0.25rem 0.35rem;
  border: 1px solid #edf2f7;
  border-radius: 6px;
  background: #f8fafc;
  font-size: 0.7rem;
  font-weight: 600;
}

.docdia-demo__icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  object-fit: contain;
}

.docdia-demo__dates {
  list-style: none;
  margin: 0 0 0 1rem;
  padding: 0 0 0 var(--docdia-demo-tree-gap);
  border-left: 1px solid #9ba2a9;
}

.docdia-demo__date-row {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: 25px;
  padding: 4px 0.35rem 4px 0;
  font-size: 0.65rem;
  font-weight: 500;
  line-height: 1.25;
  color: #64748b;
}

.docdia-demo__date-row::before {
  content: "";
  position: absolute;
  top: 50%;
  left: calc(-1 * var(--docdia-demo-tree-gap));
  width: 0.34rem;
  height: 1px;
  background: #9ba2a9;
}

.docdia-demo__date-row > :first-child {
  min-width: 0;
  overflow-wrap: anywhere;
}

.docdia-demo__count {
  flex: 0 0 auto;
}

.docdia-demo__sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* 5. Animation timeline (12 seconds)
 * 1s: colon marker highlights; 1.3–1.8s: colon panel fades in.
 * 3s: stomach marker highlights; 3.3–3.8s: stomach panel fades in.
 * Both panels remain until 11s, finish fading out at 11.6s, and restart at 12s.
 */

/* 12-second shared clock: both panels remain visible until 11s, reset at 11.6s. */
@keyframes docdia-demo-panel-left {
  0%, 10.8333%, 96.6667%, 100% {
    opacity: 0;
    visibility: hidden;
    transform: translateX(var(--docdia-demo-slide));
  }
  15%, 91.6667% {
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
  }
}

@keyframes docdia-demo-panel-right {
  0%, 27.5%, 96.6667%, 100% {
    opacity: 0;
    visibility: hidden;
    transform: translateX(var(--docdia-demo-slide));
  }
  31.6667%, 91.6667% {
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
  }
}

@keyframes docdia-demo-pulse-left {
  0%, 8.3333%, 96.6667%, 100% {
    opacity: 0;
    transform: scale(0.75);
  }
  10.8333% {
    opacity: 0.7;
    transform: scale(1.15);
  }
  15%, 91.6667% {
    opacity: 0.25;
    transform: scale(1);
  }
}

@keyframes docdia-demo-pulse-right {
  0%, 25%, 96.6667%, 100% {
    opacity: 0;
    transform: scale(0.75);
  }
  27.5% {
    opacity: 0.7;
    transform: scale(1.15);
  }
  31.6667%, 91.6667% {
    opacity: 0.25;
    transform: scale(1);
  }
}

/* 6. Responsive layout: side panels on wide screens, staggered panels on narrow screens */

/* Side panels require both a wide container and a non-mobile viewport.
   The stacked layout above is shared by all narrow-screen conditions. */
@container docdia-demo (min-width: 560px) {
  @media screen and (width > 850px) and (height > 500px),
         screen and (width > 850px) and (orientation: portrait) {
    .docdia-demo__stage {

      display: block;
      min-height: var(--docdia-demo-stage-height);
      padding: 0;
    }

    .docdia-demo__homunculus {
      position: absolute;
      top: 50%;
      left: 50%;
      margin-block: 0;
      transform: translate(-50%, -50%);
    }

    .docdia-demo__panel {
      --docdia-demo-slide: -12px;
      position: absolute;
      width: 40%;
    }

    .docdia-demo__panel--left {
      left: auto;
      right: calc(50% + 54px);
      top: 30%;
    }

    .docdia-demo__panel--right {
      --docdia-demo-slide: 12px;
      left: calc(50% + 54px);
      top: 15%;
    }

    .docdia-demo__date-row {
      min-height: 23px;
    }
  }
}

/* Use 60% of the distance from center to edge (panel width + 24px gutters).
   Below 440px both return to the shared center without changing their width. */
@container docdia-demo (min-width: 440px) {
  .docdia-demo__stage {
    --docdia-demo-upper-offset: calc((100cqw - var(--docdia-demo-panel-width) - 24px) * 0.3);
    --docdia-demo-lower-offset: calc(-1 * var(--docdia-demo-upper-offset));
  }
}

/* 7. Homepage container, product-switch reset, and reduced motion */

/* Reuse the shared preview frame without a second set of inner gutters. */
.product-preview.product-preview--docdia {
  padding: 0;
  background: #fff;
}

/* Hidden product panels restart at the first frame when selected again. */
[data-product-panel="docdia"]:not(.is-active) .docdia-demo__panel,
[data-product-panel="docdia"]:not(.is-active) .docdia-demo__marker::after {
  animation: none;
}

@media (prefers-reduced-motion: reduce) {
  .docdia-demo__panel {
    animation: none;
    opacity: 1;
    visibility: visible;
    transform: none;
  }

  .docdia-demo__marker::after {
    animation: none;
    opacity: 0.25;
    transform: none;
  }
}
