.post-overlay { position: fixed; inset: 0; z-index: 1050; }
.post-overlay-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.65); }
.post-overlay-content {
  position: absolute;
  top: 5%;
  left: 50%;
  transform: translateX(-50%);
  width: min(900px, 96vw);
  max-height: 90vh;
  max-height: 90dvh; /* Dynamic viewport height - accounts for mobile browser bar */
  overflow: visible;
  padding: 0; /* Remove default padding to allow edge-to-edge hero */
}

.post-overlay-scroll {
  max-height: 90vh;
  max-height: 90dvh; /* Dynamic viewport height - accounts for mobile browser bar */
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: env(safe-area-inset-bottom, 0); /* Account for notch/home indicator */
}

/* Hero image container - full width at top */
.overlay-hero-container {
  position: relative;
  width: 100%;
  margin: 0;
  padding: 0;
  border-radius: 0.375rem 0.375rem 0 0; /* Match card top radius */
  overflow: hidden;
}

/* When there's no hero image, hide the container */
.overlay-hero-container:empty {
  display: none;
}

/* When hero is empty, add top padding to card body for close button spacing */
.post-overlay-content:has(.overlay-hero-container:empty) .card-body {
  padding-top: 4rem;
}

/* When hero is empty, position action buttons with solid background */
.post-overlay-content:has(.overlay-hero-container:empty) .overlay-actions {
  background: rgba(248, 249, 250, 0.95);
  padding: 0.5rem;
  border-radius: 0 0 0.375rem 0.375rem;
}

.post-overlay-content:has(.overlay-hero-container:empty) .overlay-actions .btn {
  background: transparent;
  border-color: #dee2e6;
}

.post-overlay-content:has(.overlay-hero-container:empty) .overlay-actions .btn-close {
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.3));
}

.post-overlay-content:has(.overlay-hero-container:empty) .overlay-actions .btn-outline-light {
  color: #0d6efd;
  border-color: #0d6efd;
}

.post-overlay-content:has(.overlay-hero-container:empty) .overlay-actions .btn-outline-light:hover {
  background: #0d6efd;
  color: white;
}

/* Hero images should fill the container */
.overlay-hero-container img {
  width: 100%;
  height: auto;
  display: block;
  margin: 0;
}

.overlay-hero-container picture {
  display: block;
  margin: 0;
}

/* Action buttons overlaid on hero image */
.overlay-actions {
  position: absolute;
  top: 0.375rem;
  right: 1rem;
  z-index: 10;
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.overlay-metrics-left {
  position: absolute;
  top: 0.375rem;
  left: 0.375rem;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  align-items: flex-start;
}

.overlay-metrics-left .badge {
  backdrop-filter: blur(4px);
}

.overlay-actions .btn {
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  transition: all 0.2s ease;
}

.overlay-actions .btn:hover {
  background: rgba(0, 0, 0, 0.7);
  border-color: rgba(255, 255, 255, 0.4);
  transform: scale(1.05);
}

.overlay-actions .btn-close {
  opacity: 0.95;
  filter:
    drop-shadow(1px 0 0 rgba(255, 255, 255, 0.9))
    drop-shadow(-1px 0 0 rgba(255, 255, 255, 0.9))
    drop-shadow(0 1px 0 rgba(255, 255, 255, 0.9))
    drop-shadow(0 -1px 0 rgba(255, 255, 255, 0.9))
    drop-shadow(0 2px 6px rgba(0, 0, 0, 0.6));
}

.overlay-actions .btn-close:hover {
  opacity: 1;
  filter:
    drop-shadow(1px 0 0 rgba(255, 255, 255, 1))
    drop-shadow(-1px 0 0 rgba(255, 255, 255, 1))
    drop-shadow(0 1px 0 rgba(255, 255, 255, 1))
    drop-shadow(0 -1px 0 rgba(255, 255, 255, 1))
    drop-shadow(0 3px 8px rgba(0, 0, 0, 0.7));
}

/* Title styling in card body */
#overlay-title {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.2;
  color: #212529;
  margin-top: 0;
}

/* Hero title overlay in post detail modal */
.overlay-hero-title {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.9) 0%, rgba(0, 0, 0, 0.7) 50%, rgba(0, 0, 0, 0.3) 80%, transparent 100%);
  padding: 4rem 2rem 2rem;
  z-index: 2;
}

.overlay-hero-title h2 {
  margin: 0;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.3;
}

/* Ensure card body has proper padding */
.post-overlay-content .card-body {
  padding: 1rem 1.5rem;
}

/* Mobile adjustments */
@media (max-width: 768px) {
  .post-overlay-content {
    top: 2.5%;
    width: 98vw;
    max-height: 95vh;
    max-height: 95dvh;
  }

  .post-overlay-scroll {
    max-height: 95vh;
    max-height: 95dvh;
  }

  #overlay-title {
    font-size: 1.5rem;
  }

  .overlay-hero-title {
    padding: 2rem 1.5rem 1rem;
  }

  .overlay-hero-title h2 {
    font-size: 1.5rem;
  }

  .overlay-actions {
    top: 0.5rem;
    right: 0.5rem;
    gap: 0.25rem;
  }

  .overlay-actions .btn {
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
  }
}

/* Constrain images in overlay body content while honoring CKEditor dimensions */
#overlay-body img {
  max-width: 100%;
  height: auto;
}

/* Default centered images only when no alignment class is present AND not in a list */
#overlay-body p img:not(.ql-align-left):not(.ql-align-right):not(.ql-align-center),
#overlay-body > img:not(.ql-align-left):not(.ql-align-right):not(.ql-align-center) {
  display: block;
  margin: 1rem auto;
}

/* Images in list items default to left (normal flow) unless alignment is specified */
#overlay-body li img {
  display: inline-block;
  margin: 0.5rem 0;
}

/* Ensure images in aligned paragraphs/containers follow parent alignment */
#overlay-body .ql-align-center img,
#overlay-body p.ql-align-center img,
#overlay-body li.ql-align-center img {
  display: inline-block !important;
  margin-left: auto;
  margin-right: auto;
}

#overlay-body .ql-align-right img,
#overlay-body p.ql-align-right img,
#overlay-body li.ql-align-right img {
  display: inline-block !important;
  margin-left: auto;
  margin-right: 0;
}

#overlay-body .ql-align-left img,
#overlay-body p.ql-align-left img,
#overlay-body li.ql-align-left img {
  display: inline-block !important;
  margin-left: 0;
  margin-right: auto;
}

/* For standalone images with alignment classes applied directly */
#overlay-body img.ql-align-center {
  display: block;
  margin-left: auto;
  margin-right: auto;
}

#overlay-body img.ql-align-right {
  display: block;
  margin-left: auto;
  margin-right: 0;
}

#overlay-body img.ql-align-left {
  display: block;
  margin-left: 0;
  margin-right: auto;
}

#overlay-body figure {
  max-width: 100%;
  margin: 1rem auto;
}

#overlay-body figure img {
  max-width: 100%;
  height: auto;
}

/* CKEditor content formatting styles */
#overlay-body h1,
#overlay-body h2,
#overlay-body h3,
#overlay-body h4,
#overlay-body h5,
#overlay-body h6 {
  margin-top: 1.5rem;
  margin-bottom: 0.75rem;
  font-weight: 700;
  line-height: 1.2;
}

#overlay-body h1:first-child,
#overlay-body h2:first-child,
#overlay-body h3:first-child,
#overlay-body h4:first-child,
#overlay-body h5:first-child,
#overlay-body h6:first-child {
  margin-top: 0;
}

#overlay-body h1 { font-size: 2.5rem; }
#overlay-body h2 { font-size: 2rem; }
#overlay-body h3 { font-size: 1.75rem; }
#overlay-body h4 { font-size: 1.5rem; }
#overlay-body h5 { font-size: 1.25rem; }
#overlay-body h6 { font-size: 1rem; }

#overlay-body p {
  margin-top: 0;
  margin-bottom: 1rem;
  line-height: 1.6;
}

#overlay-body strong,
#overlay-body b {
  font-weight: 700;
}

#overlay-body em,
#overlay-body i {
  font-style: italic;
}

#overlay-body blockquote {
  border-left: 4px solid #0d6efd;
  padding-left: 1.5rem;
  margin-left: 0;
  margin-right: 0;
  margin-top: 1rem;
  margin-bottom: 1rem;
  font-style: italic;
  color: #6c757d;
  background-color: #f8f9fa;
  padding: 1rem 1rem 1rem 1.5rem;
  border-radius: 0.25rem;
}

#overlay-body blockquote p {
  margin-bottom: 0.5rem;
}

#overlay-body blockquote p:last-child {
  margin-bottom: 0;
}

#overlay-body ul,
#overlay-body ol {
  padding-left: 2rem;
  margin-bottom: 1rem;
  line-height: 1.6;
}

#overlay-body li {
  margin-bottom: 0.5rem;
}

/* Nested list styling - ensure proper indentation and list markers */
#overlay-body ul ul,
#overlay-body ol ol,
#overlay-body ul ol,
#overlay-body ol ul {
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
  padding-left: 1.5rem;
}

/* Different bullet styles for nested unordered lists */
#overlay-body ul {
  list-style-type: disc;
}

#overlay-body ul ul {
  list-style-type: circle;
}

#overlay-body ul ul ul {
  list-style-type: square;
}

/* Ensure ordered lists maintain proper numbering at each level */
#overlay-body ol {
  list-style-type: decimal;
}

#overlay-body ol ol {
  list-style-type: lower-alpha;
}

#overlay-body ol ol ol {
  list-style-type: lower-roman;
}

#overlay-body a {
  color: #0d6efd;
  text-decoration: underline;
}

#overlay-body a:hover {
  color: #0a58ca;
  text-decoration: none;
}

#overlay-body code {
  background-color: #f8f9fa;
  padding: 0.2rem 0.4rem;
  border-radius: 0.25rem;
  font-family: 'SFMono-Regular', 'Menlo', 'Monaco', 'Consolas', 'Liberation Mono', 'Courier New', monospace;
  font-size: 0.875em;
  color: #d63384;
}

#overlay-body pre {
  background-color: #f8f9fa;
  padding: 1rem;
  border-radius: 0.25rem;
  overflow-x: auto;
  margin-bottom: 1rem;
}

#overlay-body pre code {
  background-color: transparent;
  padding: 0;
  color: inherit;
  font-size: 0.875rem;
}

/* Mobile responsive typography */
@media (max-width: 768px) {
  #overlay-body h1 { font-size: 2rem; }
  #overlay-body h2 { font-size: 1.75rem; }
  #overlay-body h3 { font-size: 1.5rem; }
  #overlay-body h4 { font-size: 1.25rem; }

  #overlay-body blockquote {
    padding-left: 1rem;
  }
}

/* Gallery Grid Layout */
.post-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 1rem;
}

/* Gallery in overlay body has margin */
#overlay-body .post-gallery {
  margin-top: 1.5rem;
  margin-bottom: 1.5rem;
}

@media (min-width: 768px) {
  .post-gallery {
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  }
}

@media (min-width: 992px) {
  .post-gallery {
    grid-template-columns: repeat(3, 1fr);
  }
}

.post-gallery-item {
  position: relative;
  overflow: hidden;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  background: #f8f9fa;
}

.post-gallery-item:hover {
  transform: scale(1.02);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.post-gallery-item picture,
.post-gallery-item img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.gallery-image {
  aspect-ratio: 1;
  width: 100%;
  height: auto;
}

/* Lightbox Styles */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
}

.lightbox-content {
  position: relative;
  z-index: 2001;
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-content img,
.lightbox-content picture {
  max-width: 100%;
  max-height: 90vh;
  object-fit: contain;
}

.lightbox-close,
.lightbox-prev,
.lightbox-next {
  position: absolute;
  background: rgba(255, 255, 255, 0.9);
  border: none;
  font-size: 2rem;
  line-height: 1;
  padding: 0.5rem 1rem;
  cursor: pointer;
  transition: background 0.2s ease;
  z-index: 2002;
  color: #333;
}

.lightbox-close:hover,
.lightbox-prev:hover,
.lightbox-next:hover {
  background: rgba(255, 255, 255, 1);
}

.lightbox-close {
  top: 1rem;
  right: 1rem;
  border-radius: 50%;
  width: 3rem;
  height: 3rem;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-prev {
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  border-radius: 0.25rem;
}

.lightbox-next {
  right: 1rem;
  top: 50%;
  transform: translateY(-50%);
  border-radius: 0.25rem;
}

.lightbox-counter {
  position: absolute;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 0.5rem 1rem;
  border-radius: 1rem;
  font-size: 0.9rem;
  z-index: 2002;
}

/* Mobile responsiveness for lightbox controls */
@media (max-width: 768px) {
  .lightbox-prev,
  .lightbox-next {
    font-size: 1.5rem;
    padding: 0.25rem 0.5rem;
  }

  .lightbox-close {
    width: 2.5rem;
    height: 2.5rem;
    font-size: 1.5rem;
  }
}
