/**
 * Modal chrome and the verified-source evidence panel.
 *
 * The modal reproduces Streamlit's [data-testid="stDialog"]: a blurred scrim
 * that fades in, over a dialog that scales up on the spring curve, capped at
 * 38rem wide and 60vh tall with the accent aura painted into its background.
 *
 * The evidence rules below are the source's own, verbatim - the panel is built
 * from the same .evidence-meta / .evidence-chip / .evidence-section /
 * .evidence-passage structure that render_evidence_meta() and friends emit.
 */

/* ==========================================================================
   Dialog shell
   ========================================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000060;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: color-mix(in srgb, var(--product-ink) 42%, transparent);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  animation: dialog-scrim-enter var(--motion-standard) var(--ease-standard) forwards;
}

.modal-dialog {
  width: 60vw;
  max-width: min(38rem, 92vw);
  min-width: min(60vw, 26rem);
  height: auto;
  max-height: 60vh;
  margin: auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  padding: 1.35rem 1.5rem;
  border-radius: 1.05rem;
  background:
    radial-gradient(ellipse at 85% 0%, var(--product-accent-aura1), transparent 70%),
    radial-gradient(ellipse at 15% 100%, var(--product-accent-aura2), transparent 60%),
    color-mix(in srgb, var(--product-surface) 95%, var(--product-page));
  border: 1px solid color-mix(in srgb, var(--product-accent) 22%, var(--glass-rim));
  box-shadow:
    0 20px 40px -6px color-mix(in srgb, var(--product-ink) 22%, transparent),
    0 0 0 1px rgba(255, 255, 255, 0.45) inset,
    var(--glass-sheen);
  backdrop-filter: var(--glass-blur-soft);
  -webkit-backdrop-filter: var(--glass-blur-soft);
  animation: dialog-modal-scale-rise var(--motion-surface) var(--ease-spring) forwards;
  will-change: transform, opacity;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  flex-shrink: 0;
}

.modal-title {
  font-size: 1.15rem;
  font-weight: 750;
  letter-spacing: -0.02em;
  color: var(--product-ink);
  margin: 0 0 0.65rem 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Streamlit's close control: a small circle that spins as it lights up. */
.modal-header .icon-btn {
  width: 1.35rem;
  height: 1.35rem;
  min-width: 1.35rem;
  min-height: 1.35rem;
  padding: 0;
  border-radius: 999px;
  background: color-mix(in srgb, var(--product-surface) 80%, var(--product-page));
  border: 1px solid var(--glass-rim);
  box-shadow: 0 1px 2px color-mix(in srgb, var(--product-ink) 6%, transparent);
  transition: all var(--motion-micro) var(--ease-micro);
  color: var(--product-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.65rem;
  line-height: 1;
  flex-shrink: 0;
}

.modal-header .icon-btn:hover {
  background: color-mix(in srgb, var(--product-accent) 18%, transparent);
  color: var(--product-accent);
  border-color: color-mix(in srgb, var(--product-accent) 45%, transparent);
  transform: scale(1.08) rotate(90deg);
}

.modal-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

.modal-footer {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  padding-top: 0.85rem;
}

@media (max-width: 900px) {
  .modal-dialog {
    width: calc(100vw - 2rem);
    max-width: calc(100vw - 2rem);
    height: 80vh;
    max-height: 80vh;
  }
}

/* Progress and caption text inside the evidence dialog. */
.evidence-dialog__loading {
  padding: 1.5rem 0;
  color: var(--product-muted);
  font-size: var(--product-type-body);
}

/* st.caption equivalent: the note shown when a region could not be marked. */
.evidence-dialog__caption {
  margin-top: 0.5rem;
  color: var(--product-muted);
  font-size: var(--product-type-caption);
  line-height: 1.5;
}

/* ==========================================================================
   Evidence panel - rules carried over verbatim from inject_product_styles()
   ========================================================================== */
.evidence-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  padding: 0.65rem 0.95rem;
  margin-bottom: 0.95rem;
  border: 1px solid color-mix(in srgb, var(--product-border) 75%, transparent);
  border-radius: 0.75rem;
  background: linear-gradient(135deg, color-mix(in srgb, var(--product-surface) 95%, var(--product-accent) 5%) 0%, color-mix(in srgb, var(--product-surface) 98%, var(--product-page) 2%) 100%);
  box-shadow: 0 2px 8px -2px color-mix(in srgb, var(--product-ink) 6%, transparent), inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

.evidence-meta__doc {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
  flex: 1 1 auto;
}

.evidence-meta__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.85rem;
  height: 1.85rem;
  border-radius: 0.5rem;
  background: linear-gradient(135deg, color-mix(in srgb, var(--product-accent) 18%, var(--product-surface)) 0%, color-mix(in srgb, var(--product-accent) 8%, var(--product-surface)) 100%);
  border: 1px solid color-mix(in srgb, var(--product-accent) 26%, transparent);
  color: var(--product-accent);
  font-size: 0.9rem;
  flex-shrink: 0;
  box-shadow: 0 2px 5px color-mix(in srgb, var(--product-accent) 15%, transparent);
}

.evidence-meta__icon svg {
  display: block;
}

.evidence-meta__name {
  color: var(--product-ink);
  font-size: 0.88rem;
  font-weight: 700;
  letter-spacing: -0.015em;
  overflow-wrap: anywhere;
  line-height: 1.35;
}

.evidence-meta__tags {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  flex-shrink: 0;
}

.evidence-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.55rem;
  border: 1px solid color-mix(in srgb, var(--product-ink) 12%, transparent);
  border-radius: 999px;
  background: color-mix(in srgb, var(--product-surface) 92%, var(--product-page));
  color: var(--product-muted);
  font-size: 0.68rem;
  font-weight: 650;
  line-height: 1.3;
  white-space: nowrap;
  box-shadow: 0 1px 2px color-mix(in srgb, var(--product-ink) 4%, transparent);
}

.evidence-chip--verified {
  border-color: color-mix(in srgb, var(--product-success) 40%, transparent);
  background: linear-gradient(135deg, color-mix(in srgb, var(--product-success) 14%, var(--product-surface)) 0%, color-mix(in srgb, var(--product-success) 8%, var(--product-surface)) 100%);
  color: var(--product-success);
  box-shadow: 0 1px 4px color-mix(in srgb, var(--product-success) 16%, transparent);
}

.evidence-chip--verified svg {
  stroke: currentColor;
  display: block;
}

.evidence-section {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0.65rem 0 0.45rem;
  color: var(--product-muted);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.evidence-section::before {
  content: "";
  display: inline-block;
  width: 0.22rem;
  height: 0.72rem;
  border-radius: 999px;
  background: var(--product-accent);
}

blockquote.evidence-quote {
  margin: 0 0 0.85rem;
  padding: 0.85rem 1.1rem;
  border: 1px solid color-mix(in srgb, var(--product-border) 80%, transparent);
  border-radius: 0.65rem;
  background: var(--product-surface);
  color: var(--product-ink);
  font-size: var(--product-type-body);
  line-height: 1.65;
  overflow-wrap: anywhere;
  box-shadow: 0 2px 8px -2px color-mix(in srgb, var(--product-ink) 5%, transparent);
}

.evidence-passage {
  max-height: 36vh;
  overflow-y: auto;
  padding: 0.95rem 1.15rem;
  margin: 0 !important;
  border: 1px solid color-mix(in srgb, var(--product-border) 80%, transparent);
  border-radius: 0.65rem;
  background: var(--product-surface);
  color: var(--product-ink);
  font-size: var(--product-type-body);
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  box-shadow: 0 2px 8px -2px color-mix(in srgb, var(--product-ink) 5%, transparent), inset 0 1px 0 rgba(255, 255, 255, 0.35);
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--product-ink) 20%, transparent) transparent;
}

.evidence-passage::-webkit-scrollbar {
  width: 5px;
}

.evidence-passage::-webkit-scrollbar-track {
  background: transparent;
}

.evidence-passage::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--product-ink) 20%, transparent);
  border-radius: 999px;
}

.evidence-passage::-webkit-scrollbar-thumb:hover {
  background: color-mix(in srgb, var(--product-ink) 35%, transparent);
}

mark.evidence-mark {
  padding: 0.12rem 0.35rem;
  border-radius: 0.28rem;
  background: color-mix(in srgb, var(--product-accent) 14%, var(--product-surface));
  color: var(--product-ink);
  font-weight: 400;
}

.evidence-page {
  position: relative;
  overflow: hidden;
  width: 100%;
  border: 1px solid color-mix(in srgb, var(--product-border) 80%, transparent);
  border-radius: 0.75rem;
  background: #ffffff;
  line-height: 0;
  box-shadow: 0 4px 18px -3px color-mix(in srgb, var(--product-ink) 12%, transparent);
}

.evidence-page img {
  display: block;
  width: 100%;
  height: auto;
}

.conflict-panel__source-tag {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--product-accent);
  text-transform: none;
  letter-spacing: normal;
}

.conflict-panel__value--empty {
  color: var(--product-muted);
  font-style: italic;
  font-weight: 500;
}

/* Percentage-based bounding box drawn over the page raster. The 9999px spread
   dims everything outside the box, so the cited region reads as spotlit. */
.evidence-page__box {
  position: absolute;
  border: 2px solid var(--product-accent);
  background: color-mix(in srgb, var(--product-accent) 22%, transparent);
  box-shadow:
    0 0 0 9999px color-mix(in srgb, var(--product-ink) 28%, transparent),
    0 0 14px color-mix(in srgb, var(--product-accent) 55%, transparent);
  border-radius: 3px;
  pointer-events: none;
  z-index: 10;
}
