/* Theme-aware tooltips and popovers */
.theme-aware-tooltip {
  --bs-tooltip-bg: var(--bs-secondary);
  --bs-tooltip-color: var(--bs-white);
}

/* Dark mode compatibility */
[data-bs-theme="dark"] .theme-aware-tooltip {
  --bs-tooltip-bg: var(--bs-gray-800);
  --bs-tooltip-color: var(--bs-white);
}

/* Small tooltip tweaks for better readability */
.tooltip-knowledge {
  opacity: 0.9;
  font-style: italic;
}

/* Theme-aware popovers */
.theme-aware-popover {
  --bs-popover-bg: var(--bs-body-bg);
  --bs-popover-border-color: var(--bs-border-color);
  color: var(--bs-body-color);
}

/* Ensure popover close button is visible in both light and dark modes */
.popover-close-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  z-index: 2;
  opacity: 0.5;
}

.popover-close-btn:hover {
  opacity: 1;
}

/* Make popovers larger and more readable */
.popover {
  max-width: 300px;
}

.citation-popover-content {
  padding-right: 1.5rem; /* Space for close button */
}

/* Ensure popover content has proper padding */
.citation-popover-content > div {
  margin-bottom: 0.25rem;
}

/* --- Visual Evidence Badge/Icon for Citations --- */
.citation-visual-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 1.8em;
  min-width: 1.8em;
  border-radius: 50%;
  background: linear-gradient(135deg, #4f8cff 60%, #00e6d0 100%);
  color: #fff;
  font-size: 1em;
  font-weight: bold;
  box-shadow: 0 2px 8px rgba(0,0,0,0.10);
  margin-left: 0.5em;
  margin-right: 0;
  border: 2px solid var(--bs-border-color, #e0e0e0);
  transition: box-shadow 0.2s, background 0.2s, border 0.2s;
  cursor: pointer;
  z-index: 1;
}

.citation-visual-badge:hover, .citation-visual-badge:focus {
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
  background: linear-gradient(135deg, #00e6d0 60%, #4f8cff 100%);
  border-color: #4f8cff;
  outline: none;
}

[data-bs-theme="dark"] .citation-visual-badge {
  background: linear-gradient(135deg, #1a6cff 60%, #00bfae 100%);
  color: #fff;
  border: 2px solid #222;
}

.citation-item-group {
  display: flex;
  align-items: center;
  gap: 0.25em;
  position: relative;
}

/* --- Modal Animation for Visual Evidence --- */
#visualGroundingModal .modal-dialog {
  transform: translateY(40px) scale(0.98);
  opacity: 0;
  transition: all 0.35s cubic-bezier(0.4,0,0.2,1);
}

#visualGroundingModal.show .modal-dialog {
  transform: translateY(0) scale(1);
  opacity: 1;
}

/* --- Glassmorphism and Stunning Modal Styles --- */
.stunning-modal .modal-content.glassy-bg {
  background: rgba(255,255,255,0.25);
  backdrop-filter: blur(16px) saturate(180%);
  border-radius: 1.5rem;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  border: 1.5px solid rgba(80,180,255,0.12);
  overflow: hidden;
}

.stunning-modal .modal-header {
  border-bottom: none;
  background: rgba(255,255,255,0.12);
  backdrop-filter: blur(8px);
}

.stunning-modal .modal-title {
  letter-spacing: 0.02em;
  font-size: 1.25rem;
}

.stunning-modal .btn-close {
  filter: invert(1) grayscale(1) brightness(1.5);
}

.evidence-image-wrapper {
  background: linear-gradient(135deg, #e0f7fa 0%, #e3f2fd 100%);
  border-radius: 1.5rem;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  position: relative;
  overflow: hidden;
}

.evidence-image {
  border-radius: 1.5rem;
  border: 4px solid rgba(80,180,255,0.25);
  box-shadow: 0 2px 16px rgba(80,180,255,0.08);
  transition: box-shadow 0.3s, border 0.3s;
}

.evidence-image:focus, .evidence-image:hover {
  box-shadow: 0 4px 32px rgba(80,180,255,0.18);
  border-color: #4f8cff;
}

.evidence-animated-border {
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: 1.5rem;
  border: 3px solid transparent;
  background: linear-gradient(120deg, #4f8cff 0%, #00e6d0 100%) border-box;
  mask: linear-gradient(#fff 0 0) padding-box, linear-gradient(#fff 0 0);
  mask-composite: exclude;
  animation: evidence-border-glow 2.5s linear infinite;
  z-index: 2;
  opacity: 0.7;
}

@keyframes evidence-border-glow {
  0% { filter: blur(0.5px) brightness(1.1);}
  50% { filter: blur(2.5px) brightness(1.4);}
  100% { filter: blur(0.5px) brightness(1.1);}
}

.evidence-meta-panel {
  font-size: 1rem;
  background: rgba(255,255,255,0.18);
  backdrop-filter: blur(4px);
  border-radius: 0.75rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  margin-top: 0.5rem;
}

.evidence-meta-source {
  font-weight: 600;
  color: #1976d2;
}

.evidence-meta-page {
  color: #607d8b;
  font-size: 0.95em;
}

.evidence-meta-snippet {
  color: #757575;
  font-size: 0.92em;
  margin-top: 0.25em;
}

.stunning-modal .btn-outline-primary,
.stunning-modal .btn-outline-secondary {
  border-radius: 2em;
  font-weight: 500;
  letter-spacing: 0.01em;
  box-shadow: 0 1px 4px rgba(80,180,255,0.08);
  transition: background 0.2s, color 0.2s, box-shadow 0.2s;
}

.stunning-modal .btn-outline-primary:hover,
.stunning-modal .btn-outline-secondary:hover {
  background: linear-gradient(120deg, #4f8cff 0%, #00e6d0 100%);
  color: #fff;
  box-shadow: 0 2px 12px rgba(80,180,255,0.18);
}

[data-bs-theme="dark"] .stunning-modal .modal-content.glassy-bg {
  background: rgba(30,40,60,0.45);
  border: 1.5px solid rgba(80,180,255,0.18);
}

[data-bs-theme="dark"] .evidence-meta-panel {
  background: rgba(30,40,60,0.25);
  color: #e0e0e0;
}

[data-bs-theme="dark"] .evidence-meta-source {
  color: #90caf9;
}

[data-bs-theme="dark"] .evidence-meta-page {
  color: #b0bec5;
}

[data-bs-theme="dark"] .evidence-meta-snippet {
  color: #bdbdbd;
}

/* --- Fix z-index for medium-zoom overlay and image --- */
.medium-zoom-overlay {
  z-index: 2001 !important; /* Above Bootstrap modal (z-index: 1050-1060) */
}
.medium-zoom-image--opened {
  z-index: 2002 !important;
  box-shadow: 0 8px 32px rgba(80,180,255,0.25), 0 2px 16px rgba(0,0,0,0.18);
  border-radius: 1.5rem;
}

/* --- Citation Hover/Click Theme-aware --- */
.citation-toggle-btn, .citation-item-group:hover {
  background: var(--bs-secondary-bg, #f0f4ff);
  color: var(--bs-primary, #1a6cff);
  border-radius: 0.5em;
  transition: background 0.2s, color 0.2s;
}

[data-bs-theme="dark"] .citation-toggle-btn, [data-bs-theme="dark"] .citation-item-group:hover {
  background: #232a3a;
  color: #00e6d0;
}
