/* ═══════════════════════════════════════════════════════════════════════════
   LÂMINA VIEWER — engine visual da lâmina interativa
   Escopado sob .lamina-viewer — tema escuro fixo, independente do
   light/dark mode do resto do site (mesmo comportamento do protótipo
   arquivos/histo-demo.html).
   ═══════════════════════════════════════════════════════════════════════════ */

.lamina-viewer {
  --lv-bg: #0E2B22;
  --lv-accent: #31D17E;
  --lv-accent-dim: #1F8C57;
  --lv-text: #EAFFF5;
  --lv-text-dim: #8FB8A6;
  --lv-panel: #123A2C;
  --lv-line: #1D4C3A;
  --lv-gold: #E8C468;

  font-family: 'Space Grotesk', sans-serif;
  color: var(--lv-text);
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 26px;
  align-items: start;
}

@media (max-width: 840px) {
  .lamina-viewer { grid-template-columns: 1fr; gap: 16px; }
}

/* Lâmina renderizada como lente de lupa: círculo cheio (object-fit: cover,
   sem letterbox), aro de vidro/metal via box-shadow em camadas em vez de
   borda sólida, e vinheta interna pra dar profundidade de lente. */
.lv-scope {
  background: #000;
  border-radius: 50%;
  position: relative;
  overflow: hidden;
  aspect-ratio: var(--lv-aspect, 1/1);
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  -webkit-user-select: none;
  user-select: none;
  box-shadow:
    0 0 0 3px rgba(49, 209, 126, 0.32),
    0 0 0 5px rgba(255, 255, 255, 0.07),
    0 24px 48px rgba(0, 0, 0, 0.5),
    inset 0 0 36px rgba(0, 0, 0, 0.45);
}

.lv-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  -webkit-user-drag: none;
  user-select: none;
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  opacity: 0;
  transition: opacity .35s ease;
  pointer-events: none;
}

.lv-img.lv-active { opacity: 1; }

.lv-hotspots {
  position: absolute;
  inset: 0;
  display: none;
}

.lv-hotspots.lv-active { display: block; }

.lv-hotspot {
  position: absolute;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(49, 209, 126, 0.35);
  border: 2px solid var(--lv-accent);
  transform: translate(-50%, -50%);
  cursor: pointer;
  animation: lv-pulse 2s infinite;
  padding: 0;
}

.lv-hotspot:hover,
.lv-hotspot.lv-selected {
  background: rgba(232, 196, 104, 0.55);
  border-color: var(--lv-gold);
}

/* Region hotspots — outline traces the real structure boundary; the
   interior only fills in on hover/focus/tap/selection, not at rest,
   so a dense lâmina doesn't turn into a wall of colored shapes */
.lv-hotspot-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.lv-hotspot-region {
  fill: rgba(49, 209, 126, 0);
  stroke: rgba(49, 209, 126, 0.8);
  stroke-width: 0.45;
  vector-effect: non-scaling-stroke;
  cursor: pointer;
  pointer-events: auto;
  transition: fill 0.2s ease, stroke 0.2s ease, stroke-width 0.2s ease;
  animation: lv-region-pulse 1.5s ease-in-out infinite;
}

.lv-hotspot-region:hover,
.lv-hotspot-region:focus-visible {
  fill: rgba(49, 209, 126, 0.55);
  stroke-width: 0.8;
  animation: none;
}

.lv-hotspot-region.lv-selected {
  fill: rgba(232, 196, 104, 0.55);
  stroke: var(--lv-gold);
  stroke-width: 0.8;
  animation: none;
}

.lv-hotspot-region:focus-visible {
  outline: none;
  stroke: var(--lv-gold);
}

/* Pulse lasts 0.5s of the 1.5s cycle (0 → 33.3%), then rests. Safe to
   animate fill/stroke-width here even though :hover/.lv-selected also set
   them — those states switch the animation to "none" above, so there's
   never a frozen animated value left fighting the static hover/selected one */
@keyframes lv-region-pulse {
  0%, 100% {
    stroke-width: 0.45;
    fill: rgba(49, 209, 126, 0);
    filter: drop-shadow(0 0 0 rgba(49, 209, 126, 0));
  }
  16.6% {
    stroke-width: 1.6;
    fill: rgba(49, 209, 126, 0.25);
    filter: drop-shadow(0 0 6px rgba(49, 209, 126, 0.95));
  }
  33.3% {
    stroke-width: 0.45;
    fill: rgba(49, 209, 126, 0);
    filter: drop-shadow(0 0 0 rgba(49, 209, 126, 0));
  }
}

@keyframes lv-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(49, 209, 126, 0.4); }
  50% { box-shadow: 0 0 0 8px rgba(49, 209, 126, 0); }
}

.lv-zoombar {
  position: absolute;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  background: rgba(10, 25, 20, 0.75);
  padding: 6px;
  border-radius: 999px;
  backdrop-filter: blur(4px);
  z-index: 2;
}

.lv-zoombtn {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11.5px;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--lv-text-dim);
  cursor: pointer;
  transition: all .15s ease;
}

.lv-zoombtn.lv-active-btn {
  background: var(--lv-accent);
  color: #06180F;
  font-weight: 600;
}

.lv-zoomlabel {
  position: absolute;
  top: 22px;
  left: 50%;
  transform: translateX(-50%);
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--lv-text-dim);
  background: rgba(10, 25, 20, 0.75);
  padding: 5px 10px;
  border-radius: 8px;
  z-index: 2;
}

/* Painel lateral — desktop */
.lv-panel {
  position: relative;
  background: var(--lv-panel);
  border: 1px solid var(--lv-line);
  border-radius: 18px;
  padding: 20px;
  min-height: 200px;
}

.lv-panel h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--lv-text-dim);
  margin: 0 0 14px;
  font-weight: 600;
  font-family: 'JetBrains Mono', monospace;
}

.lv-struct-name {
  font-size: 19px;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--lv-accent);
}

.lv-struct-desc {
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--lv-text);
  /* As descrições em dados.json separam os tópicos por linha em branco, e o app
     (RN <Text>) já respeitava isso — aqui o HTML colapsava tudo num parágrafo só. */
  white-space: pre-line;
}

.lv-placeholder {
  font-size: 13px;
  color: var(--lv-text-dim);
  line-height: 1.6;
}

/* Estado de repouso do painel quando a lâmina tem `caracteristicas`: a descrição
   histológica geral ocupa o espaço, com a dica dos hotspots rebaixada pro rodapé. */
.lv-carac-desc {
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--lv-text);
  white-space: pre-line;
}

.lv-carac-hint {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--lv-line);
  font-size: 12px;
  line-height: 1.5;
  color: var(--lv-text-dim);
}

/* Empty state — centered icon + hint instead of text stranded at the top
   of an otherwise-blank panel */
.lv-struct-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  padding: 22px 6px 8px;
}
.lv-placeholder-icon {
  color: var(--lv-accent-dim);
  opacity: 0.75;
}
.lv-struct-empty .lv-placeholder { max-width: 220px; }

/* Bottom sheet — mobile */
.lv-sheet-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 199;
  opacity: 0;
  transition: opacity .25s ease;
}

.lv-sheet-close {
  display: none;
  position: absolute;
  top: 10px;
  right: 10px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.08);
  color: var(--lv-text-dim);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.lv-sheet-close:hover {
  background: rgba(255, 255, 255, 0.16);
  color: var(--lv-text);
}

/* Deselect button — visible on every breakpoint once a structure is
   selected, not just inside the mobile sheet */
.lv-sheet-close.lv-visible {
  display: flex;
  align-items: center;
  justify-content: center;
}

@media (max-width: 840px) {
  /* Capped by viewport height too, not just width — at 1:1 aspect-ratio a
     tablet-width lens would otherwise be as tall as it is wide and push
     the zoom toggle (and the fixed bottom bar, in portrait) off-screen */
  .lv-scope { max-width: min(420px, 82vw, 46vh); }

  .lv-panel {
    position: fixed;
    left: 0;
    right: 0;
    /* Sits above the fixed bottom nav bar instead of behind it —
       see .dash-sidebar in css/expandable-tabs.css */
    bottom: calc(58px + env(safe-area-inset-bottom, 0px));
    border-radius: 18px 18px 0 0;
    max-height: 50vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    /* translateY(100%) alone only clears the panel's own height — since it
       now sits raised above the nav bar (not at bottom:0), it needs that
       same offset added here too, or its rounded top edge pokes out right
       at the nav bar's top border when "closed" */
    transform: translateY(calc(100% + 58px + env(safe-area-inset-bottom, 0px)));
    transition: transform .3s ease;
    z-index: 200;
    box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.4);
  }

  .lv-panel.lv-sheet-open { transform: translateY(0); }

  /* Fade hint at the bottom edge so it reads as "swipe for more" even
     before the text is long enough to actually need scrolling */
  .lv-panel::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 28px;
    background: linear-gradient(transparent, var(--lv-panel));
    pointer-events: none;
    border-radius: 0 0 18px 18px;
  }

  .lv-sheet-backdrop.lv-sheet-open {
    display: block;
    opacity: 1;
  }

  .lv-sheet-close.lv-sheet-open { display: block; }
}
