/**
 * Question Generator Component Styles
 * Shared styles for the question generator across all pages
 */

#questionForm {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-md);
    margin: 0 auto var(--space-3xl);
    width: 100%;
    max-width: 1100px;
    align-items: center;
    justify-content: center;
    padding: 0 20px;
}

body.focus-mode-page #questionForm {
    margin-top: var(--space-xl);
}

#classSelect,
#unitSelect {
    width: 280px;
    min-width: 280px;
    padding: var(--space-md) var(--space-lg);
    font-size: var(--font-size-base);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    transition: border-color 0.2s, background-color 0.3s ease;
    font-family: inherit;
    cursor: pointer;
    appearance: none;
}

#classSelect:focus,
#unitSelect:focus {
    outline: none;
    border-color: var(--accent-color);
}

#classSelect optgroup {
    font-weight: var(--font-weight-semibold);
    color: var(--text-primary);
    background: var(--bg-secondary);
}

#unitSelect:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.range-label {
    font-weight: 500;
    color: var(--accent-color);
    padding: 2px 8px;
    background: var(--hover-bg);
    border-radius: 4px;
    font-size: 0.75rem;
}

.slider::-webkit-slider-track {
    width: 100%;
    height: 4px;
    background: var(--border-color);
    border-radius: 2px;
}

.question-generator-component {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 20px;
    background: var(--bg-secondary, #f5f5f5);
    border-radius: 12px;
    border: 1px solid var(--border-color, #e0e0e0);
}

.question-generator-component form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.question-generator-component select {
    padding: 10px 12px;
    border: 1px solid var(--border-color, #d0d0d0);
    border-radius: 8px;
    background: var(--bg-primary, #fff);
    color: var(--text-primary, #000);
    font-size: 14px;
    cursor: pointer;
    transition: border-color 0.2s ease;
}

.question-generator-component select:hover {
    border-color: var(--accent-color, #0066cc);
}

.question-generator-component select:focus {
    outline: none;
    border-color: var(--accent-color, #0066cc);
    box-shadow: 0 0 0 2px rgba(0, 102, 204, 0.1);
}

.question-generator-component select:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.question-generator-component button[type="submit"] {
    padding: 12px 20px;
    background: var(--accent-color, #0066cc);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.question-generator-component button[type="submit"]:hover {
    background: var(--accent-color-hover, #0052a3);
}

.question-generator-component button[type="submit"]:active {
    transform: scale(0.98);
}

.question-generator-component button[type="submit"]:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Range Slider Styles */
#rangeSliderContainer {
    padding: 16px;
    background: var(--bg-tertiary, #fafafa);
    border-radius: 8px;
}

.range-slider-wrapper {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.range-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    text-align: center;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary, #000);
}

.range-separator {
    margin: 0 12px;
    color: var(--text-secondary, #666);
}

.slider-track {
    position: relative;
    display: flex;
    align-items: center;
    height: 4px;
    background: var(--border-color, #e0e0e0);
    border-radius: 2px;
    margin: 20px 0;
}

.slider {
    position: absolute;
    width: 100%;
    height: 4px;
    top: 0;
    margin: 0;
    padding: 0;
    pointer-events: none;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    border: none;
    outline: none;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent-color, #0066cc);
    cursor: pointer;
    pointer-events: auto;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: background-color 0.2s ease;
}

.slider::-webkit-slider-thumb:hover {
    background: var(--accent-color-hover, #0052a3);
}

.slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent-color, #0066cc);
    cursor: pointer;
    pointer-events: auto;
    border: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: background-color 0.2s ease;
}

.slider::-moz-range-thumb:hover {
    background: var(--accent-color-hover, #0052a3);
}

.slider-range {
    position: absolute;
    height: 4px;
    background: var(--accent-color, #0066cc);
    border-radius: 2px;
    pointer-events: none;
    z-index: 1;
}

/* Answer Section Styles */
.answer-section-component {
    padding: 20px;
    background: var(--bg-secondary, #f5f5f5);
    border-radius: 12px;
    border: 1px solid var(--border-color, #e0e0e0);
}

#answerOutput {
    min-height: 100px;
    padding: 20px;
    background: var(--bg-primary, #fff);
    border-radius: 8px;
    line-height: 1.6;
    color: var(--text-primary, #000);
}

#answerOutput:empty::before {
    content: 'Your answer will appear here';
    color: var(--text-secondary, #999);
    font-style: italic;
}

/* Question Display */
#answerSection {
    margin: 30px auto 0;
    width: 100%;
    max-width: calc(100vw - 40px);
    padding: 0 20px;
}

body.focus-mode-page #answerSection {
    margin-bottom: var(--space-3xl);
}

.question-container {
    background: var(--bg-secondary);
    padding: 30px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    width: 100%;
    max-width: 700px;
    margin: 0 auto;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

/* Two-column layout for long questions (desktop only) */
.question-container.has-long-question {
    max-width: 1400px;
    display: grid;
    grid-template-columns: 1fr 1.2fr;
    gap: 20px;
    grid-template-areas:
        "badge badge"
        "question options"
        "actions actions";
}

.question-container.has-long-question .provider-badge {
    grid-area: badge;
}

.question-container.has-long-question .question-section {
    grid-area: question;
    border-bottom: none;
    padding-right: 20px;
    margin-bottom: 0;
    overflow: visible;
    max-height: none;
}

.question-container.has-long-question .options-section {
    grid-area: options;
    overflow: visible;
    max-height: none;
}

.question-container.has-long-question .question-actions {
    grid-area: actions;
    border-top: 2px solid var(--border-color);
    padding-top: 20px;
}

.provider-badge {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.question-section,
.answer-section,
.explanation-section {
    margin-bottom: 25px;
    padding-bottom: 20px;
}

.question-section p,
.answer-section p,
.explanation-section p,
.option-btn .option-text {
    line-height: 1.7;
}

.question-section h3,
.answer-section h3,
.explanation-section h3 {
    color: var(--accent-color);
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
    margin-top: 0;
    margin-bottom: var(--space-md);
}

/* Options / Answer Choices */
.options-section {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    margin-top: var(--space-xl);
}

.option-btn {
    padding: var(--space-md) var(--space-lg);
    font-size: var(--font-size-base);
    text-align: left;
    background: var(--hover-bg);
    color: var(--text-primary);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s ease;
    display: flex;
    align-items: flex-start;
    gap: var(--space-md);
    min-height: 44px;
}

.option-btn .option-label {
    font-weight: var(--font-weight-semibold);
    flex-shrink: 0;
}

.option-btn .option-text {
    flex: 1;
    line-height: 1.5;
    word-wrap: break-word;
}

.option-btn:hover:not(:disabled) {
    background: var(--hover-bg);
    border-color: var(--accent-color);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.option-btn:disabled {
    cursor: not-allowed;
}

.option-btn.correct {
    background: rgba(48, 209, 88, 0.15);
    border-color: var(--success-color);
    color: var(--success-color);
}

.option-btn.incorrect {
    background: rgba(255, 69, 58, 0.15);
    border-color: var(--error-color);
    color: var(--error-color);
}

/* Question Actions */
.question-actions {
    display: flex;
    gap: var(--space-md);
    margin-top: var(--space-md);
    flex-wrap: wrap;
}

.question-action-btn {
    padding: var(--space-sm) var(--space-md);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-normal);
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s;
    flex: 0 0 auto;
}

.question-action-btn:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
    border-color: var(--text-tertiary);
}

.question-action-split {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-top: 12px;
    width: 100%;
}

.next-question-btn {
    padding: 14px 20px;
    font-size: 1rem;
    font-weight: 600;
    background: var(--accent-color);
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    flex: 1 1 auto;
    min-width: 160px;
}

.next-question-btn:hover {
    opacity: 0.92;
    transform: translateY(-1px);
}

.show-explanation-btn {
    padding: 14px 18px;
    font-size: 1rem;
    font-weight: 600;
    background: rgba(255,255,255,0.06);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s;
    flex: 0 0 auto;
    min-width: 160px;
}

.show-explanation-btn:hover {
    background: var(--hover-bg);
    border-color: var(--text-tertiary);
}

/* Progress Sidebar */
.progress-panel {
    position: fixed;
    right: 16px;
    top: 110px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow: var(--shadow-sm);
    z-index: 900;
    transition: all 0.3s ease;
    display: none; /* Hidden by default */
}

.progress-panel.hidden {
    display: inline-block;
    width: auto;
    padding: 8px 14px;
    cursor: pointer;
}

.progress-panel.hidden:hover {
    background: var(--hover-bg);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.progress-panel.hidden .progress-content {
    display: none;
}

.progress-content {
    padding: 8px;
}

.progress-panel.hidden .progress-show-text {
    display: block;
    font-size: 0.85rem;
    color: var(--text-primary);
    font-weight: 500;
    white-space: nowrap;
}

.progress-panel.show {
    display: block;
    width: 220px;
    padding: 12px;
    cursor: default;
}

.progress-panel.show .progress-content {
    display: block;
}

.progress-panel.show .progress-show-text {
    display: none;
}

.progress-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.progress-header h3 {
    margin: 0;
    font-size: 0.95rem;
    color: var(--accent-color);
}

.progress-hide-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 2px 6px;
    border-radius: 4px;
    transition: all 0.2s ease;
    line-height: 1;
}

.progress-hide-btn:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
}

.progress-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
    font-size: 0.9rem;
}

.progress-subtext {
    padding: 4px 0;
    margin: 4px;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.progress-show-text {
    display: none;
}

/* Loading animation */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    color: var(--text-tertiary);
}

.loading-bar {
    width: 100%;
    max-width: 400px;
    height: 8px;
    background: var(--border-color);
    border-radius: 4px;
    overflow: hidden;
}

.loading-bar-fill {
    height: 100%;
    background: var(--accent-color);
    border-radius: 4px;
    animation: loadingBar 1.5s ease-in-out infinite;
}

@keyframes loadingBar {
    0% { width: 0%; }
    50% { width: 100%; }
    100% { width: 0%; }
}

/* Code and pre-formatted text inside questions/options */
pre.question-text,
pre.option-text,
pre.explanation-text {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
    font-size: 16px;
    font-weight: 300;
    line-height: 1.7;
    white-space: pre-wrap;
    word-wrap: break-word;
    margin: 0;
    padding: 0;
    background: none;
    border: none;
    color: var(--text-primary);
}

pre code {
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Code', monospace;
    background: var(--bg-primary);
    padding: 12px;
    border-radius: 6px;
    display: block;
    overflow-x: auto;
    font-size: 0.9em;
    line-height: 1.5;
}

/* Inline code */
code {
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', monospace;
    background: var(--bg-primary);
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.9em;
}

/* KaTeX math rendering */
.katex {
    font-size: 1em;
}

.katex-display {
    display: block;
    margin: 12px 0;
    overflow-x: auto;
    text-align: center;
}

.explanation-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.45);
    z-index: 60;
    border-radius: 8px;
    padding: 12px;
}

.explanation-card {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    max-width: 880px;
    width: 95%;
    max-height: 85%;
    overflow: auto;
    padding: 20px;
}

.explanation-card h2 {
    margin: 0 0 10px 0;
    font-size: 1.4rem;
}

.explanation-card .explanation-text {
    margin-top: 8px;
    white-space: pre-wrap;
}

.explanation-card .explain-actions {
    text-align: center;
    margin-top: 16px;
}

/* Responsive Design */
@media (max-width: 768px) {
    .question-generator-component {
        padding: 16px;
    }

    .question-generator-component form {
        gap: 10px;
    }

    .range-info {
        flex-direction: column;
        gap: 8px;
    }

    .range-separator {
        margin: 0;
    }

    #questionForm {
        flex-direction: column;
        padding: 0 16px;
    }

    #classSelect,
    #unitSelect {
        width: 100%;
        font-size: 16px; /* Prevents iOS zoom */
    }

    #rangeSliderContainer {
        width: calc(100% - 32px);
        margin-left: 16px;
        margin-right: 16px;
    }

    #answerSection {
        padding: 0;
    }

    .question-container {
        padding: 12px;
        width: 100%;
        max-width: none;
        margin: 0;
    }

    .question-container.has-long-question {
        display: block;
        width: 100%;
        max-width: none;
    }

    .question-container.has-long-question .question-section {
        border-right: none;
        border-bottom: 2px solid var(--border-color);
        max-height: none;
    }

    .question-container.has-long-question .options-section {
        max-height: none;
    }

    .question-actions {
        flex-direction: column;
    }

    .question-action-btn {
        width: 100%;
    }

    .question-action-split {
        flex-direction: column;
    }

    .next-question-btn,
    .show-explanation-btn {
        width: 100%;
        min-width: 0;
    }

    .progress-panel {
        display: none !important;
    }

    .explanation-card {
        padding: 16px;
        max-height: 90%;
    }
}

@media (max-width: 1024px) {
    .question-container.has-long-question {
        grid-template-columns: 1fr;
        grid-template-areas:
            "badge"
            "question"
            "options"
            "actions";
    }

    .question-container.has-long-question .question-section {
        border-right: none;
        border-bottom: 2px solid var(--border-color);
        padding-right: 0;
        margin-bottom: 25px;
        max-height: none;
        overflow-y: visible;
    }

    .question-container.has-long-question .options-section {
        max-height: none;
        overflow-y: visible;
    }
}

@media (max-width: 480px) {
    #answerSection {
        padding: 0;
    }

    .question-container {
        width: 100%;
        max-width: none;
        padding: 10px;
        margin: 0;
    }

    .question-container.has-long-question {
        width: 100%;
        max-width: none;
    }
}
