/* ----------------------------------------------------------------
   SECTION: Problem Solution Feedback Base
   ---------------------------------------------------------------- */

/* Popup Styles */
.popup {
  display: none; /* Hidden by default */
  position: fixed;
  bottom: 0;
  right: 0;
  z-index: 9999;
  width: 450px;
  min-width: 400px;
  height: 100vh; /* Full height of viewport */
  max-height: 100vh; /* Prevent exceeding viewport */
  overflow: hidden; /* No scrolling */
  transition: all 0.25s ease-out;
  background: white;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
  z-index: 10;
}

.popup:not(.loading) {
  opacity: 1 !important;
  visibility: visible;
}

.popup.loading {
  height: auto;
  color: #0d847e;
  font-style: italic;
  line-height: 1.2;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0;
  overflow: visible;
  background: transparent;
  box-shadow: none;
}

/* The white circular background */
.popup.loading::before {
  content: var(--timer-value, "0");
  position: absolute;
  left: 420px;
  width: 50px;
  height: 50px;
  background-color: white;
  border-radius: 50%;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 400;
  color: rgb(90, 88, 88);
}

/* The animated spinner */
.popup.loading::after {
  content: "";
  position: absolute;
  left: calc(418px + (50px - 30px) / 2);
  width: 30px; /* Slightly larger for better visibility */
  height: 30px; /* Match width */
  border: 3px solid rgba(0, 0, 0, 0.1); /* Lighter inactive border */
  border-radius: 50%; /* Circular shape */
  border-top: 3px solid var(--primary-color); /* Keep the primary color for the spinner */
  animation: popupSpin 0.6s linear infinite;
  z-index: 4;
}

@keyframes rotateLoader {
  100% {
    transform: rotate(1turn);
  }
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.popup.slide-in {
  animation: popupSlideIn 0.25s ease-out forwards; /* Apply slide-in animation */
}

.popup.slide-out {
  animation: popupSlideOut 0.25s ease-out forwards; /* Apply slide-out animation */
}

.popup.collapsed {
  pointer-events: none;
}

.popup.expanded {
  animation: popupExpand 0.25s ease-out forwards;
}

.popup-drag-bar {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 5px;
  cursor: ew-resize;
}

/* Popup Content Styles */
.popup-content {
  height: 100%;
  overflow-y: auto;
  width: 100% !important;
  width: auto; /* Adjusted width to fit at bottom-right */
  position: relative;
}
.popup-content.hide-overflow {
  overflow: hidden;
}

.close-and-collapse-icon {
  display: flex;
  gap: 8px;
  align-items: center;
  position: sticky;
  z-index: 10000;
  width: 100%;
  top: 0;
  background-color: white;
  padding: 8px 16px;
  margin-bottom: 1rem;
}

.close-btn {
  cursor: pointer;
  width: 16px;
  height: 16px;
  transition: fill 0.2s ease-in-out;
}

.collapse-btn {
  display: none !important;
}

.close-btn:hover g path,
.collapse-btn:hover g path {
  fill: #6b6b6b;
}

#popup-body {
  display: flex;
  flex-direction: column;
  height: 100%;
}
#popup-body.loading {
  height: 100%;
}

.loader {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
}

.loader .loading-spinner {
  position: relative;
  z-index: 1;
}

.loader p {
  background: white;
  max-width: 350px;
  padding: 10px 15px;
  margin-right: 120px;
  box-shadow: 0 0 9px 3px #0003;
}
.loader p.fade-away {
  opacity: 0;
  transition: opacity 0.5s ease-in-out; /* Only transitions when fade-away is added */
}
.loader.submission {
  height: 100%;
  width: 100%;
  justify-content: center;
  padding-right: 0;
  gap: 0;
  overflow: hidden;
}

.loading-spinner {
  width: 35px; /* Increased size to fit timer */
  height: 35px; /* Match width */
  border: 3px solid rgba(0, 0, 0, 0.2); /* Subtle inactive border */
  border-radius: 50%; /* Circular shape */
  border-top: 3px solid var(--primary-color); /* Keep the primary color for the spinner */
  animation: popupSpin 0.6s linear infinite; /* Smooth and slightly faster spin */
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.loading-spinner.big {
  width: 50px; /* Increased size */
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.error {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.error h6 {
  font-size: 1.2rem;
  font-weight: bold;
  margin: 0;
  color: #d4380d;
}

#error p {
  font-size: var(--text-small);
  text-align: center;
  color: #595959;
  white-space: unset;
}

/* Submission popup css */
.problem-details {
  display: flex;
  gap: 0.8rem;
  flex-direction: column;
  margin: 0px 16px;
  padding-bottom: 20px;
  border-bottom: 2px solid #f1f1f1;
  margin-bottom: 25px;
}

.problem-id,
.problem-statement,
.problem-xp {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.problem-statement {
  align-items: flex-start;
}

.problem-id h3 {
  font-size: var(--text-large);
}

.problem-statement-text,
.problem-xp p {
  font-size: var(--text-base);
}

.problem-statement-text {
  position: relative;
  max-height: 4.5em;
  overflow: hidden;
  line-height: 1.5em;
  transition: max-height 0.3s ease-in-out;
}

.problem-statement-text.has-fade {
  cursor: pointer;
}

/* Apply fade only when class 'has-fade' is present */
.problem-statement-text.has-fade::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 1.5em; /* Match line height */
  background: linear-gradient(to bottom, rgba(255, 255, 255, 0) 0%, white 100%);
  pointer-events: none; /* Ensure clicks go through */
}

.problem-statement-text.expanded {
  max-height: none;
}

.problem-statement-text.expanded::after {
  display: none; /* Remove fade effect when expanded */
}

.problem-xp.statement {
  color: var(--purple);
}

.problem-id img,
.problem-statement img,
.problem-xp img {
  width: 24px;
}

.overall-grade-block {
  display: flex;
  justify-content: start;
  font-weight: 700;
}

.response-block {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: var(--text-base) !important;
  font-family: Cmu, Arial, sans-serif !important;
}

.response-block.long {
  flex-direction: column;
  gap: 3px;
  align-items: start !important;
}

.response-block.overall-grade {
  width: fit-content;
  margin-top: 5px;
}

.response-title {
  font-size: var(--text-base);
  white-space: nowrap;
}

.response-value {
  padding-right: 5px;
}

.submission {
  margin-top: 10px;
}

.hr-divider {
  margin-top: 15px;
}

.response-block p,
.response-block ul {
  font-size: var(--text-base);
}

/* Problems popup */
.response-field {
  font-size: 1.1rem;
  font-family: Cmu, Arial, sans-serif;
}

#expand-btn {
  display: none;
  position: fixed;
  bottom: 20px;
  right: 30px;
  width: 50px;
  cursor: pointer;
  padding: 7px;
  background-color: white;
  box-shadow: 0 0 9px 3px #0003;
  border-radius: 100%;
  transition: all 0.25s ease-out;
  z-index: 1111;
}

#expand-btn:hover {
  transform: scale(1.1);
  background-color: var(--bluish-gray);
}

@media only screen and (max-width: 600px) {
  .popup {
    min-width: 350px;
  }
}

.submission-loader-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.loader-label {
  font-size: 13px;
  color: #444;
  font-weight: 500;
}

#popup-timer,
.timer {
  font-size: 13px;
  color: #666;
}

/* ----------------------------------------------------------------
   SECTION: Keyframes
---------------------------------------------------------------- */
@keyframes popupSpin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

@keyframes popupSlideIn {
  from {
    transform: translateX(100%); /* Start off-screen to the right */
  }
  to {
    transform: translateX(0); /* Move to its final position */
  }
}

@keyframes popupSlideOut {
  from {
    transform: translateX(0); /* Start at its current position */
  }
  to {
    transform: translateX(100%); /* Move off-screen to the right */
  }
}

/* macOS-like Minimize Animation */
@keyframes popupCollapse {
  0% {
    opacity: 1;
    transform: scale(1) translate(0, 0);
    transform-origin: 50% 100%;
    filter: blur(0);
  }
  100% {
    opacity: 0;
    transform: scale(0.2) translate(150px, 300px);
    transform-origin: 50% 100%;
    filter: blur(2px);
  }
}

/* macOS-like Restore Animation */
@keyframes popupExpand {
  from {
    transform: scale(0.1) translate(100%, 100%);
    opacity: 0;
    visibility: hidden;
  }
  to {
    transform: scale(1) translate(0, 0);
    opacity: 1;
  }
}

.markdown-content {
  max-width: calc(
    100% - 10px
  ); /* Ensures it is slightly smaller than .popup-content */
  width: 100%;
  box-sizing: border-box; /* Ensures padding doesn't increase width */
  word-wrap: break-word; /* Ensures long words wrap properly */
}

#right-content {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tab-content {
  padding: 0 16px;
}

.markdown-content {
  line-height: 1.3; /* Reduce line spacing */
}

.markdown-content p {
  margin-top: 5px;
}

.markdown-content ul,
.markdown-content ol {
  margin: 0; /* Reduce space for lists */
  padding-left: 20px; /* Keep indentation */
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.markdown-content h3,
.markdown-content h4 {
  margin-bottom: 8px; /* Reduce space below headers */
}

.markdown-content blockquote {
  margin: 5px 0; /* Reduce space above and below blockquotes */
  padding: 5px 10px;
}

.markdown-content code {
  font-size: 0.95em; /* Reduce font size slightly */
  padding: 2px 4px;
}

.markdown-content pre {
  margin: 5px 0;
  padding: 5px;
}

.mjx-chtml {
  margin: 0.5rem 0;
}

.submission-time {
  font-style: italic;
  color: var(--gray);
  font-size: 14px;
}

/* Feedback buttons */
#feedback-buttons {
  margin: 0px 16px;
  margin-bottom: 24px;
  display: flex;
  align-items: center;
}

.feedback-container {
  background: #f3f3f2;
  padding: 8px 10px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  gap: 13px;
}

#thumb-up-btn.selected,
#thumb-down-btn.selected {
  cursor: not-allowed !important;
}

/* Thumbs-up/down styling */
#thumb-up-btn,
#thumb-down-btn {
  width: 18px;
  height: 18px;
  background: none !important;
}

#thumb-up-btn:not(.clicked):hover svg path,
#thumb-down-btn:not(.clicked):hover svg path {
  fill: var(--primary-color);
}

#thumb-up-btn svg,
#thumb-down-btn svg {
  width: 18px;
  height: 18px;
}

#thnk_feedback {
  white-space: normal;
  display: none;
  color: #909090;
  line-height: 100%;
  font-size: 14px;
  font-style: italic;
  margin-left: 10px;
  transform: translateY(2px);
}

.user-submission-block {
  background: var(--light-gray);
  padding: 16px;
  font-family: Cmu, Arial, sans-serif;
}

.user-submission-block * {
  line-height: normal;
  font-size: var(--text-base);
}

#right-content {
  margin-bottom: 20px;
}

.tooltip {
  position: absolute;
  background: black;
  color: white;
  padding: 5px 10px;
  border-radius: 5px;
  font-size: 12px;
  opacity: 0;
  transition: opacity 0.2s ease-in-out;
  pointer-events: none;
  white-space: nowrap;
  z-index: 10000000;
}

#popup-body.loading {
  padding: 16px;
}

.hidden {
  display: none !important;
}
.active {
  display: flex !important;
}

.nav-menu {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  margin-bottom: 10px;
}

.tab-toggle-button {
  width: 40px;
  height: 30px;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  background-color: transparent !important;
  border-radius: 8px;
  transition: transform 0.2s ease-in-out, background-color 0.2s ease-in-out;
}

.tab-toggle-button:not(.active) {
  background-color: #c6c7d1 !important;
}

.tab-toggle-button.active svg path {
  fill: #727c93;
  transition: fill 0.2s ease-in-out;
}

.tab-toggle-button.active:hover svg path {
  fill: #374a68;
}

.tab-toggle-button:hover {
  transform: scale(1.08);
}

.tab-toggle-button.active:hover {
  background-color: #c6c7d1 !important;
}

.tab-toggle-button svg {
  width: 28px;
}

@media (hover: none) and (pointer: coarse) {
  /* Prevent :hover from interfering visually */
  .tab-toggle-button:hover {
    background-color: transparent !important;
    transform: none !important;
  }

  .tab-toggle-button:hover svg path {
    fill: #727c93 !important;
  }

  /* Not active (default look on mobile) */
  .tab-toggle-button:not(.active) {
    background-color: #c6c7d1 !important;
  }

  .tab-toggle-button:not(.active) svg path {
    fill: #727c93 !important;
  }

  /* Active still = transparent bg + greyish svg */
  .tab-toggle-button.active {
    background-color: transparent !important;
  }

  .tab-toggle-button.active svg path {
    fill: #727c93 !important;
  }

  /* Manually applied hover effect (via JS) */
  .tab-toggle-button.force-hover svg path {
    fill: #374a68 !important;
  }
}

mjx-container {
  overflow: auto !important;
}

.MathJax {
  /* display: inline !important; */
}

/* Hide the separate timer element since we're using ::before */
.timer {
  display: none;
}

.markdown-content {
  font-family: Cmu, Arial, sans-serif !important;
}

.submission-image-container img {
  width: 100%;
  max-width: 100%;
  height: 180px;
  object-fit: contain;
  margin-top: 10px;
}

/* handles feedback popup in mobile */
@media (max-width: 780px) {
  .popup {
    width: 100vw !important;
    max-width: 100vw !important;
    left: 0 !important;
    right: 0 !important;
    border-radius: 0 !important;
    margin: 0 auto !important;
    padding-top: env(safe-area-inset-top, 20px);
  }

  .close-and-collapse-icon {
    display: none !important;
    /* position: sticky;
    top: env(safe-area-inset-top, 10px); */
    /* height: 95px; */
    /* z-index: 10000;
    background-color: white;
    padding: 8px 16px;
    align-items: end; */
  }

  .popup-content {
    max-width: 100vw;
    box-sizing: border-box;
    height: auto !important;
    max-height: 100vh !important;
    padding-top: calc(env(safe-area-inset-top, 10px) + 65px);
  }

  .popup-content * {

    /* max-width: 100%; */
    word-break: break-word;
  }

  .image-gallery img,
  .submission-image-container img {
    max-width: 100%;
    height: auto;
  }

  /* handles the thank you for submission and time spinner in mobile */
  .popup.loading {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
  }

  .popup.loading p {
    font-size: 13px;
    max-width: 65vw;
    text-align: center;
    margin-right: 80px;
    background: white;
    padding: 10px 14px;
    box-shadow: 0 0 9px 3px #0003;
    line-height: 1.4;
  }

  .popup.loading::before {
    content: var(--timer-value, "0");
    position: absolute;
    left: calc(100vw - 60px);
    bottom: 10px;
    width: 45px;
    height: 45px;
    background-color: white;
    border-radius: 50%;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 400;
    color: rgb(90, 88, 88);
    z-index: 3;
  }

  .popup.loading::after {
    content: "";
    position: absolute;
    left: calc(100vw - 55px);
    bottom: 15px;
    width: 29px;
    height: 29px;
    border: 3px solid rgba(0, 0, 0, 0.1);
    border-radius: 50%;
    border-top: 3px solid var(--primary-color);
    animation: popupSpin 0.6s linear infinite;
    z-index: 4;
  }

  body.no-scroll-mobile {
    overflow: hidden !important;
    position: fixed;
    width: 100%;
  }

  .popup-content {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain; /* Prevent scroll chaining to background */
    /* height: 100vh; Ensure it gets full scrollable height */
    /* padding-top: calc(env(safe-area-inset-top, 20px) + 25px); ensure content clears the top bar */
    box-sizing: border-box;
    /* margin-top: 80px !important; */
  }

  #popup-body {
    /* padding-top: calc(env(safe-area-inset-top, 20px) + 65px); */
  }
}

.popup-error-centered {
  height: 100%;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
}

.popup-error-message {
  font-size: 16px;
  color: #000;
  line-height: 1.5;
  max-width: 90%;
}

mjx-container[jax="CHTML"][display="false"] mjx-c.TEX-I::before {
  /* fixes for n alignment */
  padding: 0.694em 0.521em 0.011em 0 !important;
}

/* Copy Button for text input solution */
.copy-btn {
  position: absolute;
  top: -30px;
  right: 8px;
  background: #cac8c8;
  border: none;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
  z-index: 10;
}
