/**
 * Tattoo Listings v2.0 - Detail View (Lightbox)
 * @description Full-screen overlay (mobile) / centered modal (desktop)
 *              for tattoo card detail with rich metadata and SEO tag links.
 * @version 1.0.0
 * @date 2026-02-26
 */

/* ================================================================
   OVERLAY BACKDROP
   ================================================================ */
.tattoo-detail-overlay {
  position: fixed;
  inset: 0;
  z-index: 9500;
  background: rgba(0, 0, 0, 0.92);
  display: none;
  opacity: 0;
  transition: opacity 0.25s ease;
  overflow: hidden;
}

.tattoo-detail-overlay.open {
  display: flex;
  align-items: center;
  justify-content: center;
}

.tattoo-detail-overlay.visible {
  opacity: 1;
}

/* ================================================================
   DETAIL CONTAINER
   ================================================================ */
.tattoo-detail {
  position: relative;
  width: 100%;
  height: 100%;
  background: var(--bg, #0d0d0d);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  transform: scale(0.97);
  opacity: 0;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1),
              opacity 0.25s ease;
}

.tattoo-detail-overlay.visible .tattoo-detail {
  transform: scale(1);
  opacity: 1;
}

/* Safe area for iOS */
.tattoo-detail {
  padding-bottom: env(safe-area-inset-bottom);
}

/* ================================================================
   TOP BAR (mobile: close + save)
   ================================================================ */
.td-topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0.75rem 1rem;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.6), transparent);
}

.td-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: none;
  cursor: pointer;
  color: var(--color-white);
  transition: background 0.2s ease, transform 0.2s ease;
  padding: 0;
}

.td-close:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(1.05);
}

.td-close svg {
  width: 18px;
  height: 18px;
}

.td-save-btn {
  position: absolute;
  right: 0.6rem;
  top: 0.6rem;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.18);
  cursor: pointer;
  color: var(--color-white);
  transition: background 0.2s ease, transform 0.2s ease;
  padding: 0;
}

.td-save-btn:hover {
  background: var(--gold, #e8c547);
  color: var(--color-black);
}

.td-save-btn svg {
  width: 14px;
  height: 14px;
}

/* Saved state — red filled heart (mirrors .masonry-save.saved) */
.td-save-btn.saved svg,
.td-save-desktop.saved svg {
  fill: #e74c3c;
  stroke: #e74c3c;
}

/* ================================================================
   IMAGE CONTAINER
   ================================================================ */
.td-image-wrap {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-shrink: 0;
  background: var(--color-black);
  min-height: 40vh;
}

.td-image-inner {
  position: relative;
  display: inline-block;
  max-width: 100%;
  line-height: 0;
}

.td-image {
  display: block;
  width: 100%;
  max-height: 65vh;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

/* ================================================================
   METADATA PANEL
   ================================================================ */
.td-meta {
  padding: 1.25rem 1rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* ================================================================
   ARTIST ROW
   ================================================================ */
.td-artist {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.td-artist-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid var(--border, rgba(255, 255, 255, 0.1));
  object-fit: cover;
  flex-shrink: 0;
}

.td-artist-info {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.td-artist-name {
  font-family: var(--font-ui);
  font-size: var(--text-sm, 0.875rem);
  font-weight: var(--font-weight-bold);
  color: var(--text, var(--color-white));
  text-decoration: none;
  transition: color 0.2s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.td-artist-name:hover {
  color: var(--gold, #e8c547);
}

.td-artist-location {
  font-family: var(--font-ui);
  font-size: var(--text-xs, 0.75rem);
  color: var(--text-3, rgba(255, 255, 255, 0.45));
}

.td-profile-link {
  margin-left: auto;
  font-family: var(--font-ui);
  font-size: var(--text-xs, 0.75rem);
  font-weight: var(--font-weight-bold);
  color: var(--gold, #e8c547);
  text-decoration: none;
  white-space: nowrap;
  transition: opacity 0.2s ease;
  flex-shrink: 0;
}

.td-profile-link:hover {
  opacity: 0.7;
}

/* ================================================================
   TAG SECTIONS
   ================================================================ */
.td-section {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.td-section-label {
  font-family: var(--font-ui);
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-3, rgba(255, 255, 255, 0.45));
}

.td-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* ================================================================
   TAG PILLS (clickable <a> links)
   ================================================================ */
.td-tag {
  display: inline-flex;
  align-items: center;
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-full, 9999px);
  font-family: var(--font-ui);
  font-size: var(--text-xs, 0.75rem);
  font-weight: var(--font-weight-bold);
  letter-spacing: 0.02em;
  text-decoration: none;
  transition: all 0.2s ease;
  border: 1px solid var(--border, rgba(255, 255, 255, 0.1));
  color: var(--text-2, rgba(255, 255, 255, 0.7));
  background: transparent;
}

.td-tag:hover {
  border-color: var(--gold, #e8c547);
  color: var(--gold, #e8c547);
  transform: translateY(-1px);
}

/* Style tag pills -- match masonry-style badge colors */
.td-tag--style[data-style="japanese"] {
  color: var(--color-family-japanese, #c62828);
  border-color: rgba(198, 40, 40, 0.35);
  background: rgba(198, 40, 40, 0.08);
}
.td-tag--style[data-style="japanese"]:hover {
  background: rgba(198, 40, 40, 0.18);
  border-color: var(--color-family-japanese, #c62828);
}

.td-tag--style[data-style="realism"] {
  color: var(--color-family-realism, #00838f);
  border-color: rgba(0, 131, 143, 0.35);
  background: rgba(0, 131, 143, 0.08);
}
.td-tag--style[data-style="realism"]:hover {
  background: rgba(0, 131, 143, 0.18);
  border-color: var(--color-family-realism, #00838f);
}

.td-tag--style[data-style="blackwork"] {
  color: #8b9ca6;
  border-color: rgba(55, 71, 79, 0.45);
  background: rgba(55, 71, 79, 0.1);
}
.td-tag--style[data-style="blackwork"]:hover {
  background: rgba(55, 71, 79, 0.25);
  border-color: #8b9ca6;
}

.td-tag--style[data-style="watercolor"],
.td-tag--style[data-style="fineline"],
.td-tag--style[data-style="fine_line"] {
  color: var(--color-family-fineline, #00897b);
  border-color: rgba(0, 137, 123, 0.35);
  background: rgba(0, 137, 123, 0.08);
}
.td-tag--style[data-style="watercolor"]:hover,
.td-tag--style[data-style="fineline"]:hover,
.td-tag--style[data-style="fine_line"]:hover {
  background: rgba(0, 137, 123, 0.18);
  border-color: var(--color-family-fineline, #00897b);
}

.td-tag--style[data-style="traditional"],
.td-tag--style[data-style="neo-traditional"],
.td-tag--style[data-style="neo_traditional"],
.td-tag--style[data-style="neotraditional"] {
  color: #5b9bd5;
  border-color: rgba(21, 101, 192, 0.35);
  background: rgba(21, 101, 192, 0.08);
}
.td-tag--style[data-style="traditional"]:hover,
.td-tag--style[data-style="neo-traditional"]:hover,
.td-tag--style[data-style="neo_traditional"]:hover,
.td-tag--style[data-style="neotraditional"]:hover {
  background: rgba(21, 101, 192, 0.18);
  border-color: #5b9bd5;
}

.td-tag--style[data-style="lettering"] {
  color: var(--color-family-lettering, #f57c00);
  border-color: rgba(245, 124, 0, 0.35);
  background: rgba(245, 124, 0, 0.08);
}
.td-tag--style[data-style="lettering"]:hover {
  background: rgba(245, 124, 0, 0.18);
  border-color: var(--color-family-lettering, #f57c00);
}

.td-tag--style[data-style="geometric"],
.td-tag--style[data-style="illustrative"] {
  color: #9575cd;
  border-color: rgba(94, 53, 177, 0.35);
  background: rgba(94, 53, 177, 0.08);
}
.td-tag--style[data-style="geometric"]:hover,
.td-tag--style[data-style="illustrative"]:hover {
  background: rgba(94, 53, 177, 0.18);
  border-color: #9575cd;
}

.td-tag--style[data-style="chicano"],
.td-tag--style[data-style="mandala"] {
  color: #ba68c8;
  border-color: rgba(106, 27, 154, 0.35);
  background: rgba(106, 27, 154, 0.08);
}
.td-tag--style[data-style="chicano"]:hover,
.td-tag--style[data-style="mandala"]:hover {
  background: rgba(106, 27, 154, 0.18);
  border-color: #ba68c8;
}

.td-tag--style[data-style="tribal"] {
  color: #e57c5b;
  border-color: rgba(216, 67, 21, 0.35);
  background: rgba(216, 67, 21, 0.08);
}
.td-tag--style[data-style="tribal"]:hover {
  background: rgba(216, 67, 21, 0.18);
  border-color: #e57c5b;
}

.td-tag--style[data-style="minimalism"],
.td-tag--style[data-style="modern"] {
  color: #66bb6a;
  border-color: rgba(46, 125, 50, 0.35);
  background: rgba(46, 125, 50, 0.08);
}
.td-tag--style[data-style="minimalism"]:hover,
.td-tag--style[data-style="modern"]:hover {
  background: rgba(46, 125, 50, 0.18);
  border-color: #66bb6a;
}

.td-tag--style[data-style="dotwork"],
.td-tag--style[data-style="ornamental"] {
  color: #a1887f;
  border-color: rgba(121, 85, 72, 0.35);
  background: rgba(121, 85, 72, 0.08);
}
.td-tag--style[data-style="dotwork"]:hover,
.td-tag--style[data-style="ornamental"]:hover {
  background: rgba(121, 85, 72, 0.18);
  border-color: #a1887f;
}

/* ================================================================
   NAVIGATION ARROWS (prev/next)
   ================================================================ */
.td-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0 0;
  border-top: 1px solid var(--border, rgba(255, 255, 255, 0.1));
  margin-top: auto;
}

.td-nav-prev,
.td-nav-next {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font-ui);
  font-size: var(--text-xs, 0.75rem);
  font-weight: var(--font-weight-bold);
  color: var(--text-2, rgba(255, 255, 255, 0.7));
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-md, 8px);
  transition: color 0.2s ease, background 0.2s ease;
}

.td-nav-prev:hover,
.td-nav-next:hover {
  color: var(--gold, #e8c547);
  background: rgba(255, 255, 255, 0.05);
}

.td-nav-prev svg,
.td-nav-next svg {
  width: 16px;
  height: 16px;
}

.td-nav-prev:disabled,
.td-nav-next:disabled {
  opacity: 0.25;
  cursor: default;
  pointer-events: none;
}

/* Mobile: swipe handles prev/next, the .td-nav bar is desktop-only */
@media (max-width: 767px) {
  .td-nav {
    display: none;
  }
}

/* ================================================================
   DESKTOP LAYOUT (min-width: 768px)
   ================================================================ */
@media (min-width: 768px) {
  .tattoo-detail {
    flex-direction: row;
    max-width: 900px;
    max-height: 90vh;
    width: 90vw;
    height: auto;
    border-radius: 16px;
    overflow: hidden;
  }

  .td-topbar {
    display: none;
  }

  .td-save-btn {
    display: none;
  }

  .td-image-wrap {
    flex: 1 1 55%;
    min-height: 0;
    max-height: 90vh;
  }

  .td-image {
    max-height: 90vh;
    height: 100%;
    object-fit: contain;
  }

  .td-meta {
    flex: 0 0 340px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 1.5rem;
    border-left: 1px solid var(--border, rgba(255, 255, 255, 0.1));
    position: relative;
  }

  /* Desktop close button — absolute positioned relative to .tattoo-detail
     (INK-DEV-145 Bug C). z-index lifts it above .td-meta / .td-image-wrap
     which are later siblings in DOM order and would otherwise paint over it.
     Positioned over the image area (away from .td-meta) so it does not
     overlap with the artist row / profile link at the top of the info panel.
     Solid dark background ensures visibility over both light and dark image
     content. */
  .td-close-desktop {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.18);
    cursor: pointer;
    color: var(--color-white);
    transition: all 0.2s ease;
    position: absolute;
    top: 1rem;
    right: calc(340px + 1rem);
    padding: 0;
    z-index: 20;
  }

  .td-close-desktop:hover {
    background: rgba(0, 0, 0, 0.75);
    color: var(--color-white);
    transform: scale(1.05);
  }

  .td-close-desktop svg {
    width: 16px;
    height: 16px;
  }

  /* Desktop nav arrows on image sides */
  .td-nav {
    position: absolute;
    inset: 0;
    border: none;
    padding: 0;
    margin: 0;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .td-nav-prev,
  .td-nav-next {
    pointer-events: auto;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    color: var(--color-white);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    margin: 0 0.75rem;
    transition: background 0.2s ease, transform 0.2s ease;
  }

  .td-nav-prev:hover,
  .td-nav-next:hover {
    background: rgba(0, 0, 0, 0.7);
    transform: scale(1.08);
    color: var(--color-white);
  }

  /* Hide text labels on desktop nav, show only icons */
  .td-nav-label {
    display: none;
  }
}

/* Hide desktop close on mobile */
.td-close-desktop {
  display: none;
}

@media (min-width: 768px) {
  .td-close-desktop {
    display: flex;
  }
}

/* Desktop favorite (heart) — sits left of the close button. Hidden on
   mobile because the mobile topbar already has its own heart. */
.td-save-desktop {
  display: none;
}

@media (min-width: 768px) {
  .td-save-desktop {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.18);
    cursor: pointer;
    color: var(--color-white);
    transition: all 0.2s ease;
    position: absolute;
    top: 1rem;
    /* Sits left of .td-close-desktop on the image area (info panel = 340px,
       close button at right calc(340px+1rem) = 36+16 wide, so heart sits at
       calc(340px + 1rem + 36px + 0.5rem) = calc(340px + 3.625rem)). */
    right: calc(340px + 3.625rem);
    padding: 0;
    z-index: 20;
  }

  .td-save-desktop:hover {
    background: rgba(0, 0, 0, 0.75);
    color: var(--color-white);
    transform: scale(1.05);
  }

  .td-save-desktop svg {
    width: 16px;
    height: 16px;
  }
}

/* ================================================================
   EMPTY STATE (no artist data)
   ================================================================ */
.td-artist--empty {
  display: none;
}

.td-section--empty {
  display: none;
}

/* ================================================================
   LIGHT THEME OVERRIDES
   ================================================================ */
.light-theme .tattoo-detail-overlay {
  background: rgba(0, 0, 0, 0.65);
}

.light-theme .tattoo-detail {
  background: var(--bg, var(--color-white));
}

.light-theme .td-topbar {
  background: linear-gradient(to bottom, rgba(255, 255, 255, 0.8), transparent);
}

.light-theme .td-close {
  background: rgba(0, 0, 0, 0.06);
  color: var(--text, var(--color-bg-card));
}

.light-theme .td-close:hover {
  background: rgba(0, 0, 0, 0.12);
}

.light-theme .td-save-btn {
  background: rgba(0, 0, 0, 0.06);
  color: var(--text, var(--color-bg-card));
}

.light-theme .td-image-wrap {
  background: var(--color-gray-100);
}

.light-theme .td-tag {
  border-color: var(--border, rgba(0, 0, 0, 0.1));
  color: var(--text-2, #555);
  background: transparent;
}

.light-theme .td-tag:hover {
  border-color: var(--gold, #e8c547);
  color: var(--gold, #e8c547);
}

.light-theme .td-nav-prev,
.light-theme .td-nav-next {
  color: var(--text-2, #555);
}

.light-theme .td-nav-prev:hover,
.light-theme .td-nav-next:hover {
  color: var(--gold, #e8c547);
  background: rgba(0, 0, 0, 0.04);
}

@media (min-width: 768px) {
  .light-theme .td-nav-prev,
  .light-theme .td-nav-next {
    background: rgba(255, 255, 255, 0.7);
    color: var(--color-border);
  }

  .light-theme .td-nav-prev:hover,
  .light-theme .td-nav-next:hover {
    background: rgba(255, 255, 255, 0.9);
    color: var(--color-black);
  }

  /* Light theme: keep dark glass — close button sits over image area
     where the underlying surface is always dark (.td-image-wrap is black). */
  .light-theme .td-close-desktop,
  .light-theme .td-save-desktop {
    background: rgba(0, 0, 0, 0.55);
    border-color: rgba(255, 255, 255, 0.18);
    color: var(--color-white);
  }

  .light-theme .td-close-desktop:hover,
  .light-theme .td-save-desktop:hover {
    background: rgba(0, 0, 0, 0.75);
    color: var(--color-white);
  }
}

/* ================================================================
   TOOLBAR BADGE (already in listing.css, but ensure z-index)
   ================================================================ */
.toolbar-badge {
  font-family: var(--font-mono);
  font-size: 0.55rem;
  font-weight: var(--font-weight-black);
  background: var(--gold, #e8c547);
  color: var(--color-black);
  padding: 0.1rem 0.35rem;
  border-radius: var(--radius-full, 9999px);
  margin-left: 0.3rem;
  line-height: 1.2;
}
