/**
 * Task Editor & Creator - Shared Components Styles
 *
 * Used by:
 * - Admin Task Editor
 * - Teacher Task Creator (Phase 2)
 */

/* ========== LaTeX Input Field ========== */

.latex-input-field {
    margin-bottom: 1.5rem;
}

.field-label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: #374151;
    font-size: 0.95rem;
}

.latex-textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 0.5rem;
    font-family: 'Courier New', Consolas, Monaco, monospace;
    font-size: 0.95rem;
    line-height: 1.5;
    resize: vertical;
    background: #ffffff;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.latex-textarea:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.latex-hint {
    display: block;
    margin-top: 0.25rem;
    font-size: 0.875rem;
    color: #6b7280;
    font-style: italic;
}

/* LaTeX Helper Buttons */
.latex-helpers {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
}

.latex-helper-btn {
    padding: 0.375rem 0.875rem;
    background: #f3f4f6;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    color: #374151;
}

.latex-helper-btn:hover {
    background: #e5e7eb;
    border-color: #9ca3af;
    transform: translateY(-1px);
}

.latex-helper-btn:active {
    transform: translateY(0);
}

/* ========== Multiple Choice Editor ========== */

.multiple-choice-editor {
    margin-bottom: 1.5rem;
}

.choice-field {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.choice-label {
    min-width: 160px;
    font-size: 0.95rem;
    font-weight: 500;
    flex-shrink: 0;
}

.choice-label.correct-label {
    color: #059669;
}

.choice-label.distractor-label {
    color: #dc2626;
}

.choice-input {
    flex: 1;
    padding: 0.5rem 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    font-size: 0.95rem;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.choice-input:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* ========== Metadata Selector ========== */

.metadata-selector {
    margin-bottom: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid #e5e7eb;
}

.metadata-heading {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: #374151;
}

.metadata-field {
    margin-bottom: 1rem;
}

.afb-buttons {
    display: flex;
    gap: 0.5rem;
}

.afb-btn {
    flex: 1;
    padding: 0.625rem 1rem;
    background: #f3f4f6;
    border: 2px solid #d1d5db;
    border-radius: 0.5rem;
    font-weight: 500;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s;
    color: #374151;
}

.afb-btn:hover {
    background: #e5e7eb;
    border-color: #9ca3af;
}

.afb-btn.active {
    background: #3b82f6;
    color: white;
    border-color: #3b82f6;
}

.metadata-input {
    width: 100%;
    max-width: 200px;
    padding: 0.5rem 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    font-size: 0.95rem;
}

.metadata-input:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.metadata-info {
    padding: 0.75rem;
    background: #f9fafb;
    border-radius: 0.375rem;
    border: 1px solid #e5e7eb;
}

/* ========== Task Preview Panel ========== */

.task-preview-panel {
    /* Inherited from parent container */
}

.preview-section {
    margin-bottom: 1.5rem;
}

.preview-section:last-child {
    margin-bottom: 0;
}

.preview-section-title {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: #374151;
}

.preview-box {
    padding: 1rem;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    min-height: 60px;
}

.preview-loading {
    color: #6b7280;
    font-style: italic;
    font-size: 0.9rem;
}

.preview-empty {
    color: #9ca3af;
    font-style: italic;
    margin: 0;
}

.preview-latex-rendered {
    /* SVG container with height limit */
    display: flex;
    justify-content: center;
    align-items: center;
    max-height: 120px;
    overflow: auto;
    border-radius: 0.375rem;
}

.preview-latex-rendered svg {
    max-width: 100%;
    max-height: 100px;
    width: auto !important;
    height: auto !important;
}

.preview-text-fallback {
    margin: 0;
    font-family: 'Courier New', Consolas, Monaco, monospace;
    font-size: 0.9rem;
    color: #374151;
    padding: 0.5rem;
    background: white;
    border-radius: 0.25rem;
}

/* Choice Preview */
.choice-preview {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    border-radius: 0.375rem;
}

.choice-preview:last-child {
    margin-bottom: 0;
}

.choice-preview.correct-choice {
    background: #d1fae5;
    border: 1px solid #059669;
}

.choice-preview.distractor-choice {
    background: #fee2e2;
    border: 1px solid #dc2626;
}

.choice-icon {
    font-size: 1.25rem;
    font-weight: bold;
    flex-shrink: 0;
}

.choice-content {
    flex: 1;
}

.choice-content svg {
    max-width: 100%;
    height: auto;
}

/* Metadata Preview */
.metadata-preview {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    padding: 0.75rem !important;
}

.badge {
    padding: 0.375rem 0.75rem;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-weight: 500;
    display: inline-block;
}

.badge-afb {
    background: #dbeafe;
    color: #1e40af;
}

.badge-points {
    background: #fef3c7;
    color: #92400e;
}

/* ========== Task Diff View ========== */

.task-diff-view {
    margin: 1rem 0;
    max-height: 400px;
    overflow-y: auto;
}

.diff-heading {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: #374151;
}

.diff-section {
    margin-bottom: 1rem;
    padding: 0.75rem;
    background: #f9fafb;
    border-radius: 0.5rem;
    border: 1px solid #e5e7eb;
}

.diff-field-name {
    display: block;
    margin-bottom: 0.5rem;
    color: #374151;
    font-weight: 600;
}

.diff-old,
.diff-new {
    margin-bottom: 0.5rem;
}

.diff-old:last-child,
.diff-new:last-child {
    margin-bottom: 0;
}

.diff-label {
    font-weight: 600;
    margin-right: 0.5rem;
    font-size: 0.875rem;
}

.diff-old .diff-label {
    color: #dc2626;
}

.diff-new .diff-label {
    color: #059669;
}

.diff-code {
    padding: 0.5rem;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 0.25rem;
    font-family: 'Courier New', Consolas, Monaco, monospace;
    font-size: 0.875rem;
    display: block;
    margin-top: 0.25rem;
    white-space: pre-wrap;
    word-break: break-word;
}

.no-changes {
    color: #059669;
    font-weight: 500;
    margin: 0;
}

/* ========== Task Editor Page Layout ========== */

.task-editor-page {
    max-width: 1600px;
    margin: 0 auto;
    padding: 1rem;
}

.editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.editor-header h1 {
    margin: 0;
    font-size: 1.75rem;
}

.editor-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.editor-panel,
.preview-panel {
    /* Card styles inherited from global */
}

.editor-panel h3,
.preview-panel h3 {
    margin-top: 0;
    margin-bottom: 1rem;
    font-size: 1.25rem;
    color: #374151;
}

.editor-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    padding-top: 1rem;
    border-top: 1px solid #e5e7eb;
}

/* ========== Responsive Design ========== */

@media (max-width: 1024px) {
    .editor-grid {
        grid-template-columns: 1fr;
    }

    .preview-panel {
        order: 2;
    }

    .editor-panel {
        order: 1;
    }
}

@media (max-width: 640px) {
    .task-editor-page {
        padding: 0.5rem;
    }

    .editor-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .choice-field {
        flex-direction: column;
        align-items: flex-start;
    }

    .choice-label {
        min-width: auto;
    }

    .afb-buttons {
        flex-direction: column;
    }

    .latex-helpers {
        gap: 0.25rem;
    }

    .latex-helper-btn {
        padding: 0.25rem 0.5rem;
        font-size: 0.8rem;
    }
}

/* ========== Confirmation Modal ========== */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

.modal-content {
    background: white;
    border-radius: 0.75rem;
    padding: 1.5rem;
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1),
                0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

.modal-content h3 {
    margin-top: 0;
    margin-bottom: 1rem;
    font-size: 1.25rem;
    color: #374151;
}

.warning-text {
    padding: 1rem;
    background: #fef3c7;
    border: 1px solid #f59e0b;
    border-radius: 0.5rem;
    margin: 1rem 0;
    font-size: 0.95rem;
    color: #92400e;
}

.dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    margin-top: 1.5rem;
}

/* ========== Utility Classes ========== */

.card {
    background: white;
    border-radius: 0.75rem;
    padding: 1.5rem;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1),
                0 1px 2px 0 rgba(0, 0, 0, 0.06);
}

.btn {
    padding: 0.625rem 1.25rem;
    border-radius: 0.5rem;
    font-weight: 500;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-primary {
    background: #3b82f6;
    color: white;
}

.btn-primary:hover {
    background: #2563eb;
}

.btn-primary:disabled {
    background: #9ca3af;
    cursor: not-allowed;
}

.btn-secondary {
    background: #e5e7eb !important;
    color: #374151 !important;
    border: 1px solid #d1d5db !important;
}

.btn-secondary:hover {
    background: #d1d5db !important;
    border-color: #9ca3af !important;
}

.btn-secondary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
