/* =================================================== */
/* Styling for the Existing Questions Section          */
/* =================================================== */

/* --- Variable Definitions for Easy Customization --- */
:root {
    --card-bg: #ffffff;
    --card-border: #e0e0e0;
    --shadow-light: 0 2px 5px rgba(0, 0, 0, 0.05);
    --shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.1);
    --correct-bg: #e6f4ea; /* Light green */
    --correct-text: #2d6a4f; /* Dark green */
    --correct-border: #b7e4c7;
    --primary-text: #333;
    --secondary-text: #666;
    --action-edit-bg: #007bff;
    --action-edit-bg-hover: #0056b3;
    --action-delete-bg: #dc3545;
    --action-delete-bg-hover: #c82333;
    --border-radius: 8px;
}

html {
  scroll-padding-top: 100px; /* Adjust this value to match your header's height + a little extra space */
}

main {
    width: 100%;
    max-width: 1280px; /* Common max-width */
    margin-left: auto;
    margin-right: auto;
    padding-left: var(--container-padding);
    padding-right: var(--container-padding);
}

/*
 * ===================================================================
 *  AI Section Toggle & Animation Styles
 * ===================================================================
 */

/* Bar that holds the title and the toggle switch */
.ai-toggle-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 12px;
    padding: 15px 25px;
    margin-top: 20px;
    cursor: pointer; /* Makes the whole bar clickable */
    user-select: none; /* Prevents text selection on click */
}

.ai-toggle-bar span {
    font-size: 1.1em;
    font-weight: 600;
    color: #343a40;
}

.ai-toggle-bar .icon-sparkle {
    color: #1DA1F2; /* Match the sparkle color */
    margin-right: 8px;
    vertical-align: middle;
}

/* The switch - a checkbox with a sliding handle */
.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
}

/* Hide default HTML checkbox */
.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

/* The slider */
.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    -webkit-transition: .4s;
    transition: .4s;
}

.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    -webkit-transition: .4s;
    transition: .4s;
}

input:checked + .slider {
    background-color: #1DA1F2; /* A nice blue color for 'on' state */
}

input:focus + .slider {
    box-shadow: 0 0 1px #1DA1F2;
}

input:checked + .slider:before {
    -webkit-transform: translateX(22px);
    -ms-transform: translateX(22px);
    transform: translateX(22px);
}

/* Rounded sliders */
.slider.round {
    border-radius: 34px;
}

.slider.round:before {
    border-radius: 50%;
}


/* 
 * MODIFIED: Your .ai-tools-container
 * This is the key to the sliding animation.
 * We transition `max-height` instead of `display`.
*/
.ai-tools-container {
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    border: 1px solid #dee2e6;
    border-radius: 12px;
    padding: 25px 30px;
    position: relative;
    overflow: hidden; /* Crucial for the max-height animation */
    
    /* Animation Properties */
    max-height: 0;
    opacity: 0;
    margin-top: 0;
    border-top: 0; /* Hide border when collapsed */
    padding-top: 0;
    padding-bottom: 0;
    transition: max-height 0.5s ease-in-out, 
                opacity 0.4s ease-in-out,
                margin-top 0.5s ease-in-out,
                padding 0.5s ease-in-out;
}

/* This class will be added by JavaScript to show the section */
.ai-tools-container.visible {
    max-height: 1500px; /* A value larger than the content will ever be */
    opacity: 1;
    margin-top: -10px; /* Connects it visually to the toggle bar */
    border-top: 1px solid #dee2e6;
    padding-top: 25px;
    padding-bottom: 30px;
    border-top-left-radius: 0; /* Makes it look like one connected component */
    border-top-right-radius: 0;
}

.ai-tools-container.no-transition {
    transition: none !important;
}

/* =================================================
   AI Magic Tools Section Styles
   ================================================= */

/* The magic sparkle icon in the corner */
.magic-icon {
    position: absolute;
    top: -10px;
    right: -10px;
    opacity: 0.15;
    /* color: #007bff; */
    pointer-events: none; /* Makes it unclickable */
    /* transform: rotate(15deg); */
}

/* The main title for the section */
.ai-tools-container > h3 {
    text-align: center;
    margin-top: 0;
    margin-bottom: 20px;
    font-size: 1.5em;
    color: #495057;
}

/* The container for the Generate/Import buttons */
.ai-actions-bar {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-bottom: 20px;
}

/* A simple text divider (e.g., "OR") */
.ai-section-divider {
    text-align: center;
    font-weight: bold;
    color: #adb5bd;
    margin: 20px 0;
}

/* The container for the original single-question generator */
.single-generator-content {
    background-color: #ffffff;
    border: 1px solid #ced4da;
    border-radius: 8px;
    padding: 20px;
}


/* --- Main Container --- */
/* .existing-questions {
    margin-top: 30px;
} */

.existing-questions h3 {
    font-size: 1.5em;
    color: var(--primary-text);
    padding-bottom: 10px;
    margin-bottom: 20px;
    border-bottom: 2px solid var(--card-border);
}

/* --- Question List (the <ul>) --- */
.question-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 1.2rem; /* Clean spacing between cards */
}

/* --- Individual Question Card (the <li>) --- */
.question-list li {
    background-color: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-light);
    transition: box-shadow 0.3s ease, transform 0.3s ease;
    display: flex;
    align-items: flex-start;
}

.question-list li:hover {
    box-shadow: var(--shadow-hover);
    transform: translateY(-2px);
}

/* --- Flexbox Layout for controls and content --- */
.question-item {
    display: flex;
    align-items: flex-start;
    padding: 20px;
    gap: 20px;
    /* overflow-x: scroll; */
}

@media (max-width: 600px) {
    .question-item {
    overflow-x: scroll;
}
}

/* --- Reorder Controls on the left --- */
.question-order-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
}

.question-order-controls .button-small {
    background-color: #f0f0f0;
    border: 1px solid #ccc;
    color: var(--secondary-text);
    width: 30px;
    height: 30px;
    font-size: 1rem;
    line-height: 1;
    margin-bottom: 5px;
    text-align: center;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
    display: flex;
    justify-content: center;
}

.question-order-controls .button-small:hover {
    background-color: #e0e0e0;
    color: var(--primary-text);
}

.question-order-controls .disabled-placeholder {
    width: 30px;
    height: 30px;
}

/* --- Main Question Content on the right --- */
.question-content {
    flex: 1; /* Takes up the remaining space */
}

/*
 * ==============================================================
 * REPLACEMENT CSS for Question Text and Metadata (Combined)
 * ==============================================================
 */

/* The main container for the question line */
.question-text-display {
    /* Your original styles, combined with the new layout */
    font-size: 1.1rem;
    color: var(--primary-text);
    margin-bottom: 15px;
    line-height: 1.5;

    /* New layout rules for alignment */
    display: flex;
    align-items: baseline;
    gap: 0.5em; /* Modern way to handle spacing */
}

/* Keeps your custom color for the question number */
.question-text-display strong {
    color: var(--action-edit-bg);
}

/* Style for the question text itself */
.question-text-display .question-title {
    font-weight: 600; /* Makes the text bold */
    color: var(--primary-text); /* Uses your primary text color */
}

/* Style for the metadata (type, time, points) */
.question-text-display .question-meta {
    font-style: italic; /* Makes the text italic */
    font-size: 0.9rem; /* Uses your original smaller font size */
    color: var(--secondary-text); /* Uses your secondary text color */
    white-space: nowrap;
    margin-left: auto; /* Pushes the metadata to the far right */
    padding-left: 1em;
}

.question-image-preview img {
    border-radius: 4px;
    border: 1px solid var(--card-border);
    margin-bottom: 15px;
}


/*
 * ==========================================================
 * UNIFIED STYLING FOR ALL ANSWER DISPLAY TYPES (UPDATED)
 * ==========================================================
 */

/* 1. Core Layout Component for all answer blocks */
.answer-display-block {
    /* --- CRITICAL FIX FOR WIDTH ISSUE (Applied to all types) --- */
    display: inline-flex;
    flex-direction: column;
    width: max-content;
    min-width: 250px;
    max-width: 100%;
    box-sizing: border-box;
    
    /* Common visual styles */
    margin-top: 15px;
    margin-bottom: 15px;
    padding: 12px;
    border: 1px solid var(--card-border, #e0e0e0);
    border-radius: 6px;
    background-color: var(--card-bg, #f9f9f9);
}


/* 2. Specific styles for MCQ/True-False Options */
.mcq-options-display {
    padding: 0; /* Override parent padding as li has its own */
    border: none; /* Let the li elements define the look */
    background: none;
    list-style-type: none;
    gap: 8px; /* Space between each option */
}
.mcq-options-display li {
    padding: 8px 12px;
    border: 1px solid var(--card-border, #e0e0e0);
    border-radius: 4px;
    background-color: var(--card-bg, #ffffff);
    color: var(--secondary-text);
}
.mcq-options-display li.correct-answer {
    background-color: var(--correct-bg);
    color: var(--correct-text);
    border: 1px solid var(--correct-text);
    border-left: 4px solid var(--correct-text);
    font-weight: bold;
}
.mcq-options-display li.correct-answer::before {
    content: '✔ ';
    margin-right: 6px;
}


/* 3. Specific styles for Open Ended Answers */
.open-ended-answer-display {
    color: var(--secondary-text);
    border-style: dashed; /* Retain your original dashed border */
}
.open-ended-answer-display em {
    font-style: normal;
    font-weight: bold;
    color: var(--primary-text);
}


/* 4. Specific styles for Ordering Question Options */
.ordering-options-display {
    gap: 10px; /* Space between the title and the list */
}
.ordering-options-display strong {
    font-size: 0.9em;
    color: var(--secondary-text);
}
.ordering-options-display ol {
    list-style-type: decimal;
    margin: 0 0 0 20px; /* Reset margin and add left margin for numbers */
    padding: 0;
}
.ordering-options-display ol li {
    padding: 4px 0 4px 4px;
    margin: 3px 0px;
    color: var(--primary-text);
}


/* --- Action Buttons (Edit, Delete) --- */
.question-actions {
    margin-top: 20px;
    border-top: 1px solid #f0f0f0;
    padding-top: 15px;
    display: flex;
    gap: 10px;
}

.question-actions .button-small {
    border: none;
    color: white;
    padding: 8px 16px;
    border-radius: 4px;
    text-decoration: none;
    font-weight: bold;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.2s ease;
}

.question-actions .button-small:hover {
    transform: translateY(-1px);
}

.question-actions .button-small.edit {
    background-color: var(--action-edit-bg);
}

.question-actions .button-small.edit:hover {
    background-color: var(--action-edit-bg-hover);
}

.question-actions .button-small.delete {
    background-color: var(--action-delete-bg);
}

.question-actions .button-small.delete:hover {
    background-color: var(--action-delete-bg-hover);
}


/* =================================================================== */
/*      Highlight Effect for Newly Added Questions                     */
/* =================================================================== */

.question-list li.newly-added {
    background-color: #fffbe5; /* A soft yellow highlight */
    border-color: #ffe58f;
    box-shadow: 0 4px 12px rgba(255, 200, 0, 0.2);
    transition: background-color 1.5s ease, border-color 1.5s ease, box-shadow 1.5s ease;
}

/* Highlight Effect for Newly Edited Questions */

.question-highlight {
  background-color: #e0f2fe !important; /* A light, noticeable blue. Use !important if needed to override existing styles. */
  transition: background-color 1s ease-out; /* This makes the color fade out smoothly over 1 second */
  border-radius: 8px; /* Optional: If your items have rounded corners, this will look better */
}

/* Scroll buttons */

.scroll_btns {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column; /* stack vertically */
  gap: 10px; /* spacing between buttons */
  z-index: 1000;
}

.scroll_btns button {
  background: #ffffff;
  border: none;
  border-radius: 50%;
  padding: 10px;
  cursor: pointer;
  box-shadow: 0 4px 6px rgba(0,0,0,0.2);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.scroll_btns button img {
  width: 24px;
  height: 24px;
}

.scroll_btns button:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 10px rgba(0,0,0,0.3);
}

#scroll_to_top {
    background: #ffffff;
    margin-left: 20px;
    border: none;
    border-radius: 50%;
    padding: 10px;
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#scroll_to_top img {
  width: 24px;
  height: 24px;
}

#scroll_to_top:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 10px rgba(0,0,0,0.3);
}




/* --- Custom File Upload Styling --- */

/* 1. Hide the ugly native browser input */
.input-file-hidden {
    display: none !important;
}

/* Container to align the button and filename text */
.custom-upload-container {
    display: flex;
    align-items: center;
    gap: 15px; /* Space between button and filename */
    margin-bottom: 10px;
}

/* The Label that looks like a button */
.custom-file-label {
    border: solid 1px #007bff;
    border-radius: 5px;
    box-shadow: 0px 1px 6px black;
    cursor: pointer;
    display: inline-block;
    /* Ensure it aligns well if .button-small has margins */
    margin: 0; 
    /* Optional: Add an icon specific color or override .button-small here */
}

/* Visual feedback when the hidden input is disabled (e.g. after pasting) */
.input-file-hidden:disabled + .custom-file-label {
    opacity: 0.5;
    cursor: not-allowed;
    background-color: #999; /* Gray out the button */
    border-color: #ccc;
}

/* The text showing "No file chosen" or the filename */
#file_chosen_text {
    font-style: italic;
    color: #666;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 250px; /* Prevent long filenames from breaking layout */
}

/* Cleanup for the paste area layout */
.paste-image-area {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 5px;
}

.paste-image-area .separator-text {
    font-size: 0.85rem;
    font-weight: bold;
    color: #888;
    text-transform: uppercase;
}

#image_preview_container {
    margin-top: 15px;
}

/* Ensure previews fit nicely */
#image_preview_container img {
    max-width: 100%; /* Adjusted from fixed 250px to be responsive */
    width: 250px;
    border: 1px solid #ddd;
    padding: 5px;
    border-radius: 4px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}


/* Styling for the "OR" separator between image options */
.image-option-separator {
    text-align: center;
    margin: 12px 0; /* Adds vertical space above and below */
}

.image-option-separator span {
    font-size: 0.9rem;
    font-weight: bold;
    color: #888;
    text-transform: uppercase;
    background-color: #fff; /* Ensures it sits above any lines */
    padding: 0 10px; /* Space on the left/right of the text */
    position: relative; /* Needed for the line effect */
}

/* Optional: Add lines on either side of the "OR" for a professional look */
.image-option-separator span::before,
.image-option-separator span::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 80px; /* Adjust width of the line */
    height: 1px;
    background-color: #e0e0e0;
}

.image-option-separator span::before {
    left: 100%;
}

.image-option-separator span::after {
    right: 100%;
}

.question-text-section,
.question-image-section,
.time-and-point-section,
.question-type-section {
    /* border: solid 1px royalblue; */
    padding: 12px;
    border-radius: 8px;
    /* box-shadow: 0px 0px 5px royalblue; */
}

.question-text-section {
    box-shadow: 0px 0px 5px green;
    border: solid 1px green;
    transition: box-shadow 0.3s, border-color 0.3s;
}
.question-type-section {
    box-shadow: 0px 0px 5px orange;
    border: solid 1px orange;
}
.question-image-section {
    box-shadow: 0px 0px 5px royalblue;
    border: solid 1px royalblue;
}
.time-and-point-section {
    box-shadow: 0px 0px 5px red;
    border: solid 1px red;
}

.time-and-point-section,
.question-type-section {
    margin-bottom: 15px;
}


/*
 * ===================================================================
 *  AI Disclaimer Note Style (Enhanced with Icon)
 * ===================================================================
 */
.ai-disclaimer.icon {
    display: flex; /* Enables flexbox alignment */
    align-items: center; /* Vertically aligns icon and text */
    font-size: 0.85em;
    color: #6c757d;
    font-style: italic;
    margin-top: 5px;
    margin-bottom: 15px;
}

.ai-disclaimer.icon svg {
    flex-shrink: 0; /* Prevents the icon from shrinking */
    margin-right: 8px; /* Adds space between icon and text */
    color: #5865f2; /* A nice, soft purple/blue for the icon */
}




/* Highlight animation for question text section */
/* Soft pulse animation */
@keyframes qts-pulse {
    0% {
        box-shadow: 0 0 5px green;
        border-color: green;
    }
    50% {
        box-shadow: 0 0 10px 1px rgba(7, 202, 0, 0.719);
        border-color: rgba(0, 255, 0, 0.8);
    }
    100% {
        box-shadow: 0 0 5px green;
        border-color: green;
    }
}

.question-text-section.highlight-animate {
    animation: qts-pulse 1s ease-in-out forwards;
}