* {
  box-sizing: border-box;
}
body {
  margin: 0;
  padding: 0;
  font-family: "Poppins", sans-serif;
  /* Removed gradient, plain background now */
  background: #f9f9f9;
}

/* Top bar with single-line input + Ask button */
#topBar {
  width: 100%;
  background: #fff;
  padding: 20px;
  display: flex;
  align-items: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}
#topBar input {
  flex: 1;
  border: 1px solid #ccc;
  border-radius: 8px;
  padding: 10px;
  font-size: 14px;
  margin-right: 10px;
  outline: none;
}
#topBar button {
  padding: 10px 24px;
  background: #007bff;
  color: #fff;
  font-weight: 500;
  font-size: 14px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.3s ease, transform 0.2s ease;
}
#topBar button:hover {
  background: #0059b2;
  transform: translateY(-2px);
}
#topBar button:active {
  transform: translateY(0);
}

/* Container for Q/A, hidden by default */
#qaContainer {
  max-width: 900px;
  margin: 20px auto;
  background-color: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.07);
  padding: 20px;
  display: none; /* Hide until user asks a question */
}
#qaHeader {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
#qaHeader h2 {
  margin: 0;
  font-size: 20px;
  color: #444;
}
#resetBtn {
  color: #888;
  background: transparent;
  font-size: 24px;
  border: none;
  cursor: pointer;
  line-height: 1;
  transition: color 0.2s ease;
}
#resetBtn:hover {
  color: #f45b69;
}

#response {
  white-space: pre-wrap;
  margin-top: 10px;
  padding: 16px;
  border-radius: 8px;
  background-color: #f9f9f9;
  line-height: 1.5;
  color: #333;
}
/* Source references area */
#sources {
  margin-top: 20px;
  padding: 14px;
  background-color: #fafafa;
  border-radius: 8px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
#sources h2 {
  margin-top: 0;
  margin-bottom: 10px;
  color: #444;
}
#sourceList {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}
.source-item {
  background: #fff;
  border-radius: 6px;
  padding: 10px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.12);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 160px;
  position: relative;
}
.source-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.source-label {
  font-size: 14px;
  margin-bottom: 6px;
  text-align: center;
  font-weight: 500;
}
.thumb {
  width: 140px;
  height: 80px;
  margin-bottom: 6px;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  object-fit: cover;
}
.thumb.video-thumb::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border-left: 18px solid #ffffffcc;
  border-top: 12px solid transparent;
  border-bottom: 12px solid transparent;
}
.ref-sup {
  color: #007bff;
  cursor: pointer;
  text-decoration: none;
  font-size: 0.85em;
  vertical-align: super;
  margin-left: 2px;
}
.ref-sup:hover {
  text-decoration: underline;
}
.highlight-ref {
  outline: 2px solid #f45b69;
  outline-offset: -2px;
}

/* Spinner/Loader */
#spinner {
  display: none;
  border: 8px solid #f3f3f3;
  border-top: 8px solid #007bff;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 99999;
}
@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* GRID of video tiles (default view) */
/* Make the thumbnails fill the entire width, with minimal spacing. */
#videoGrid {
  display: grid;
  /* Force more/larger tiles across the width: */
  grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
  gap: 2px;              /* Almost no spacing */
  width: 100%;           /* Full width of the page */
  margin: 0;             /* Remove margins */
  padding: 0;            /* Remove padding */
}

/* When it “floats” to the bottom as a horizontal bar */
#videoGrid.bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 120px;         /* Adjust the height of that bottom strip if you like */
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  gap: 2px;
  background: #fff;
  z-index: 999;
  transition: all 0.3s ease;
}

/* In bottom-bar mode, shrink each tile’s width so they line up horizontally */
#videoGrid.bottom-bar .video-card {
  flex: 0 0 200px;       /* Each tile ~200px wide in the bottom bar */
  aspect-ratio: auto;    /* Don’t preserve 16:9 if you want them to fill the bar’s height */
  height: 100%;
}

/* Make sure the images scale nicely in bottom-bar mode */
#videoGrid.bottom-bar .video-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.video-card {
  position: relative;
  width: 100%; /* Let the grid handle width */
  aspect-ratio: 16/9; /* So they stay 16:9 shape */
  cursor: pointer;
  overflow: hidden;
  border-radius: 8px;
  background: #eee;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.video-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(0,0,0,0.15);
}
.video-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.video-title-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  color: #fff;
  background: linear-gradient(to top, rgba(0,0,0,0.7), rgba(0,0,0,0));
  padding: 10px 16px;
  font-size: 16px;
  font-weight: 500;
}

/* VIDEO Lightbox */
#lightbox {
  display: none;
  opacity: 0;
  position: fixed;
  z-index: 9999;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: rgba(0, 0, 0, 0.8);
  transition: opacity 0.3s ease;
  justify-content: center;
  align-items: center;
}
#lightbox.show {
  display: flex;
  opacity: 1;
}
#lightbox .lightbox-content {
  position: relative;
}
#lightbox .close-btn {
  position: absolute;
  top: -40px;
  right: 0;
  color: #fff;
  font-size: 40px;
  font-weight: bold;
  cursor: pointer;
  transition: color 0.2s ease;
}
#lightbox .close-btn:hover {
  color: #f45b69;
}
#lightbox video {
  max-width: 80vw;
  max-height: 80vh;
  border: 3px solid #fff;
  border-radius: 8px;
}

/* Segment Overlay */
#segmentOverlay {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: #ffffffee;
  padding: 20px;
  border-radius: 8px;
  z-index: 10000;
  text-align: center;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}
#segmentOverlay p {
  margin-bottom: 16px;
}

/* PDF Lightbox */
#pdfLightbox {
  display: none;
  opacity: 0;
  position: fixed;
  z-index: 9999;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.8);
  transition: opacity 0.3s ease;
  justify-content: center;
  align-items: center;
}
#pdfLightbox.show {
  display: flex;
  opacity: 1;
}
#pdfLightbox .lightbox-content {
  position: relative;
  width: 90%;
  max-width: 1200px;
  height: 90%;
  background-color: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  display: flex;
  flex-direction: column;
}
#pdfLightbox .close-btn {
  position: absolute;
  top: 10px;
  right: 16px;
  color: #333;
  font-size: 30px;
  font-weight: bold;
  cursor: pointer;
  transition: color 0.2s ease;
  z-index: 999;
}
#pdfLightbox .close-btn:hover {
  color: #f45b69;
}
#pdfToolbar {
  background: #f5f5f5;
  border-bottom: 1px solid #ccc;
  padding: 8px 16px;
  font-size: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
#pdfToolbar .pdf-title {
  font-weight: 600;
}
#pdfToolbar .pdf-page-info {
  font-weight: 500;
}
#pdfContainer {
  flex: 1;
  display: flex;
  overflow: hidden;
}
#pdfSidebar {
  width: 220px;
  overflow-y: auto;
  background: #2b2b2b;
  padding: 10px;
  box-shadow: 2px 0 6px rgba(0, 0, 0, 0.2);
}
.thumbnail {
  position: relative;
  margin-bottom: 10px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border 0.2s ease, transform 0.2s ease;
}
.thumbnail:hover {
  transform: scale(1.02);
  border-color: #f45b69;
}
.page-index {
  position: absolute;
  bottom: 2px;
  right: 4px;
  background: rgba(0,0,0,0.65);
  color: #fff;
  font-size: 10px;
  padding: 2px 4px;
  border-radius: 3px;
}
.thumbnail.selected {
  border: 2px solid #007bff;
}
#pdfViewer {
  flex: 1;
  overflow-y: auto;
  background: #fff;
  text-align: center;
  padding-top: 10px;
  padding-bottom: 10px;
}
.page-image {
  margin: 20px auto;
  display: block;
  background-color: #fff;
  max-width: 90%;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

body.modal-open {
  overflow: hidden !important;
}
