:root {
    /* Professional Color Palette (Slate/Blue) */
    --primary-color: #0f172a;
    /* Slate 900 */
    --primary-light: #334155;
    /* Slate 700 */
    --accent-color: #2563eb;
    /* Blue 600 */
    --accent-hover: #1d4ed8;
    /* Blue 700 */
    --bg-color: #f8fafc;
    /* Slate 50 */
    --surface-color: #ffffff;
    --border-color: #e2e8f0;
    /* Slate 200 */

    --text-main: #1e293b;
    /* Slate 800 */
    --text-muted: #64748b;
    /* Slate 500 */

    --selected-bg: #eff6ff;
    /* Blue 50 */
    --selected-border: #3b82f6;
    /* Blue 500 */

    --correct-bg: #f0fdf4;
    /* Green 50 */
    --correct-border: #22c55e;
    /* Green 500 */

    --wrong-bg: #fef2f2;
    /* Red 50 */
    --wrong-border: #ef4444;
    /* Red 500 */

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    color: var(--text-main);
    background-color: var(--bg-color);
    -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    font-weight: 600;
    letter-spacing: -0.025em;
}

/* Utilities */
.cursor-pointer {
    cursor: pointer;
}

.transition {
    transition: all 0.2s ease-in-out;
}

.fw-medium {
    font-weight: 500;
}

.letter-spacing-1 {
    letter-spacing: 1px;
}

/* Conversion upload progress */
.conversion-steps .conversion-step {
    padding: 0.5rem 0;
    display: flex;
    align-items: center;
    color: var(--text-muted);
}

.conversion-step-pending i {
    color: #cbd5e1;
}

.conversion-step-running {
    color: var(--accent-color);
    font-weight: 600;
}

.conversion-step-pages {
    font-weight: 500;
    font-size: 0.9em;
    color: var(--accent-color);
    white-space: nowrap;
}

.conversion-step-completed {
    color: #16a34a;
}

.conversion-step-skipped {
    color: #94a3b8;
}

.conversion-step-failed {
    color: #dc2626;
    font-weight: 600;
}

body.upload-conversion-active #uploadQuizModal {
    z-index: 1075;
}

body.upload-conversion-active .modal-backdrop.show {
    z-index: 1070;
}

#uploadQuizModal .btn-close:disabled {
    opacity: 0.25;
    pointer-events: none;
}

/* Source quiz document panel */
.source-document-pane {
    background: #f8fafc;
    min-width: 0;
}

.source-document-pane:focus {
    outline: none;
}

.source-document-header h6 {
    font-size: 0.95rem;
}

#source-btn-page-lock.active {
    border-color: #ffc107;
}

#source-btn-page-lock.active i {
    color: #856404;
}

.source-image-stage {
    user-select: none;
    cursor: crosshair;
    display: inline-block;
    max-width: 100%;
}

.source-page-image {
    display: block;
    max-width: 100%;
    height: auto;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    background: #fff;
}

.source-crop-selection {
    position: absolute;
    border: 2px dashed #2563eb;
    background: rgba(37, 99, 235, 0.12);
    pointer-events: none;
    box-shadow: 0 0 0 9999px rgba(15, 23, 42, 0.25);
}

#btn-toggle-source-doc.active,
#btn-toggle-answer-doc.active {
    background: rgba(255, 255, 255, 0.2);
    border-color: #fff;
    color: #fff;
}

/* Answer key reference panel */
.answer-document-pane {
    background: #f8fafc;
    min-width: 0;
}

.answer-document-pane:focus {
    outline: none;
}

.answer-document-header h6 {
    font-size: 0.95rem;
}

.answer-image-stage {
    display: inline-block;
    max-width: 100%;
}

.answer-page-image {
    display: block;
    max-width: 100%;
    height: auto;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    background: #fff;
}

.answer-field-blank {
    display: inline-block;
    vertical-align: text-bottom;
    min-width: 1.75rem;
    height: 1.35em;
    margin: 0 0.15rem;
    padding: 0 0.35rem;
    background-color: #fff3cd;
    border-bottom: 2px solid #ffecb5;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: #856404;
    line-height: 1.35em;
    text-align: center;
}

.btn-insert-answer-field .edit-shortcut-hint {
    font-size: 0.65rem;
    padding: 0.05rem 0.25rem;
}

.btn-insert-answer-field .fa-square-plus {
    font-size: 0.85em;
}

.btn-field-preview {
    min-width: 2rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-field-preview .fa-solid {
    font-size: 0.85rem;
    line-height: 1;
}

.navigator-item-reorder {
    min-width: 140px;
    cursor: grab;
    user-select: none;
}

.navigator-item-reorder:active {
    cursor: grabbing;
}

.navigator-item-dragging {
    opacity: 0.55;
}

.navigator-display-num {
    min-width: 1.5rem;
    text-align: center;
}

.navigator-item-id {
    font-size: 0.75rem;
}

.navigator-drag-handle {
    cursor: grab;
}

.gen-options-panel .form-check-label {
    cursor: pointer;
}

.gen-result-preview {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    font-size: 0.9rem;
}

#explanation-pane.gen-panel-active {
    min-height: 0;
}

#explanation-pane.gen-panel-active .gen-panel-header,
#explanation-pane.gen-panel-active .gen-options-panel {
    flex-shrink: 0;
}

#explanation-pane.gen-panel-active .gen-result-area {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
}

#explanation-pane.gen-panel-active .gen-result-area-settings {
    flex: 0 1 auto;
    overflow: visible;
}

#explanation-pane.gen-panel-active.gen-panel-settings-mode {
    overflow-y: auto;
}

#explanation-pane.gen-panel-active .gen-result-layout {
    flex: 1 1 auto;
    min-height: 0;
}

#explanation-pane.gen-panel-active .gen-result-layout {
    flex: 1 1 auto;
    min-height: 0;
}

/* Quiz Bank home list */
.app-shell-nav {
    background: #fff;
    border-bottom: 1px solid var(--border-color);
    padding: 0.75rem 1rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

.app-shell-nav-inner {
    max-width: 1280px;
    margin: 0 auto;
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.app-shell-nav-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding-bottom: 0.5rem;
}

.app-shell-nav-username {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
}

body.role-editor .admin-only {
    display: none !important;
}

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: linear-gradient(180deg, #eff6ff 0%, var(--bg-color) 220px);
}

.login-card {
    width: 100%;
    max-width: 420px;
    border-radius: 1rem;
}

.login-icon {
    width: 3rem;
    height: 3rem;
    margin: 0 auto;
    border-radius: 0.85rem;
    background: var(--selected-bg);
    color: var(--accent-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.app-shell-nav-link {
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.95rem;
    padding: 0.65rem 1.25rem;
    border-radius: 999px 999px 0 0;
    border-bottom: 3px solid transparent;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.app-shell-nav-link:hover {
    color: var(--accent-color);
    background: #f8fafc;
}

.app-shell-nav-link.active {
    color: var(--accent-color);
    border-bottom-color: var(--accent-color);
    background: #eff6ff;
}

.quiz-bank-home {
    min-height: 100vh;
    padding: 1.5rem 1rem 2.5rem;
    background: linear-gradient(180deg, #eff6ff 0%, var(--bg-color) 220px);
}

.quiz-bank-home-inner {
    max-width: 1280px;
    margin: 0 auto;
}

.quiz-bank-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.quiz-bank-title {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 0.25rem;
}

.quiz-bank-subtitle {
    color: var(--text-muted);
    margin-bottom: 0;
    font-size: 0.95rem;
}

.quiz-bank-toolbar {
    margin-bottom: 0.75rem;
    border-radius: 0.875rem !important;
}

.quiz-bank-toolbar-inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem 1rem;
}

.quiz-bank-toolbar-search {
    flex: 1 1 16rem;
    min-width: 0;
    max-width: 22rem;
}

.quiz-bank-toolbar-filters {
    flex: 1 1 auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem 0.75rem;
    min-width: 0;
}

.quiz-filter-favorite {
    flex-shrink: 0;
    padding-right: 0.25rem;
    border-right: 1px solid var(--border-color);
    margin-right: 0.15rem;
}

.quiz-filter-field {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    flex-shrink: 0;
}

.quiz-filter-label {
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin-bottom: 0;
    white-space: nowrap;
}

.quiz-filter-clear {
    flex-shrink: 0;
    align-self: center;
    white-space: nowrap;
    padding-left: 0.35rem;
    padding-right: 0.35rem;
}

.quiz-search-group .input-group-text,
.quiz-search-group .form-control {
    border-color: var(--border-color);
}

.quiz-search-group .form-control:focus {
    box-shadow: none;
    border-color: var(--accent-color);
}

.quiz-search-group:focus-within .input-group-text {
    border-color: var(--accent-color);
}

.quiz-filter-select {
    border-color: var(--border-color);
    background: #fff;
}

.quiz-filter-select--org {
    min-width: 7.5rem;
    max-width: 10.5rem;
}

.quiz-filter-select--year {
    min-width: 6.75rem;
    max-width: 8.5rem;
}

.quiz-filter-select--subject {
    min-width: 5.5rem;
    max-width: 7rem;
}

@media (min-width: 1200px) {
    .quiz-bank-toolbar-inner {
        flex-wrap: nowrap;
    }

    .quiz-bank-toolbar-search {
        flex: 0 1 20rem;
    }

    .quiz-bank-toolbar-filters {
        flex-wrap: nowrap;
    }
}

.quiz-list-summary {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
    padding-left: 0.25rem;
}

/* Knowledge base management */
.knowledge-bank-home {
    min-height: calc(100vh - 56px);
    padding: 1.5rem 1rem 2.5rem;
    background: linear-gradient(180deg, #f0fdf4 0%, var(--bg-color) 220px);
}

.knowledge-bank-home-inner {
    max-width: 1280px;
    margin: 0 auto;
}

.knowledge-bank-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.knowledge-bank-title {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 0.25rem;
}

.knowledge-bank-subtitle {
    color: var(--text-muted);
    margin-bottom: 0;
    font-size: 0.95rem;
}

.knowledge-list-summary {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
    padding-left: 0.25rem;
}

.knowledge-list-card {
    border-radius: 0.875rem !important;
    overflow: hidden;
}

.knowledge-list-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #f8fafc;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    white-space: nowrap;
}

.knowledge-list-table tbody tr:hover {
    background: #f8fafc;
}

.knowledge-status-badge {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.25rem 0.55rem;
    border-radius: 999px;
}

.knowledge-status-uploaded { background: #e2e8f0; color: #475569; }
.knowledge-status-processing { background: #dbeafe; color: #1d4ed8; }
.knowledge-status-indexed { background: #dcfce7; color: #15803d; }
.knowledge-status-failed { background: #fee2e2; color: #b91c1c; }

.knowledge-search-results {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.knowledge-search-result-card {
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 0.85rem 1rem;
    background: #fff;
}

.knowledge-search-result-card .result-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.35rem;
}

.knowledge-search-result-card .result-text {
    font-size: 0.9rem;
    color: var(--text-main);
    margin-bottom: 0;
    white-space: pre-wrap;
}

.knowledge-upload-dropzone {
    min-height: 160px;
}

.knowledge-upload-dropzone .upload-dropzone-content {
    width: 100%;
    max-width: 100%;
}

.knowledge-upload-dropzone .upload-dropzone-filename {
    margin-top: 0.75rem;
    word-break: break-all;
}

.knowledge-upload-dropzone .upload-dropzone-filename.is-placeholder {
    color: var(--text-muted);
    font-weight: 400;
}

.knowledge-upload-dropzone .upload-dropzone-filename:not(.is-placeholder) {
    color: #15803d;
    font-weight: 600;
}

.knowledge-upload-dropzone:hover,
.knowledge-upload-dropzone.dragover {
    border-color: var(--accent-color);
    background: #eff6ff;
}

.knowledge-row-actions {
    display: flex;
    gap: 0.25rem;
    justify-content: flex-end;
    flex-wrap: wrap;
}

.quiz-list-card {
    border-radius: 0.875rem !important;
    overflow: hidden;
}

.quiz-list-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #f8fafc;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    white-space: nowrap;
    padding-top: 0.85rem;
    padding-bottom: 0.85rem;
}

.quiz-list-table tbody tr.quiz-list-row {
    transition: background-color 0.15s ease;
}

.quiz-list-table tbody tr.quiz-list-row:hover {
    background: #f8fafc;
}

.quiz-col-select { width: 44px; text-align: center; }
.quiz-col-fav { width: 44px; text-align: center; }
.quiz-col-id { width: 72px; }
.quiz-col-exam { min-width: 220px; max-width: 360px; }
.quiz-col-subject { width: 88px; }
.quiz-col-grade { width: 64px; text-align: center; }
.quiz-col-term { width: 72px; text-align: center; white-space: nowrap; }
.quiz-col-category { width: 120px; }
.quiz-col-items { width: 72px; text-align: center; }
.quiz-col-action { width: 140px; text-align: end; }

.quiz-row-actions {
    display: flex;
    gap: 0.25rem;
    justify-content: flex-end;
    flex-wrap: nowrap;
    align-items: center;
}

.quiz-row-action-icon {
    width: 2rem;
    height: 2rem;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.quiz-row-action-icon i {
    font-size: 0.85rem;
}

.quiz-row-action {
    white-space: nowrap;
}

.quiz-id-badge {
    display: inline-block;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--accent-color);
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 0.375rem;
    padding: 0.15rem 0.45rem;
}

.quiz-exam-title {
    font-weight: 600;
    color: var(--text-main);
    font-size: 0.92rem;
    line-height: 1.35;
    max-width: 340px;
}

.quiz-exam-org {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 0.15rem;
    max-width: 340px;
}

.quiz-badge-subject {
    display: inline-block;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    white-space: nowrap;
}

.quiz-badge-subject-default { background: #f1f5f9; color: #475569; }
.quiz-badge-subject-chinese { background: #fef3c7; color: #92400e; }
.quiz-badge-subject-english { background: #dbeafe; color: #1e40af; }
.quiz-badge-subject-math { background: #ede9fe; color: #5b21b6; }
.quiz-badge-subject-social { background: #ffedd5; color: #9a3412; }
.quiz-badge-subject-science { background: #dcfce7; color: #166534; }
.quiz-badge-subject-pe { background: #fce7f3; color: #9d174d; }
.quiz-badge-subject-art { background: #fae8ff; color: #86198f; }

.quiz-badge-category {
    display: inline-block;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 0.15rem 0.45rem;
    border-radius: 0.35rem;
    background: #f8fafc;
    border: 1px solid var(--border-color);
    color: #475569;
}

.quiz-badge-seq {
    display: inline-block;
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-left: 0.25rem;
}

.quiz-items-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.82rem;
    font-weight: 600;
    color: #334155;
    background: #f1f5f9;
    border-radius: 999px;
    padding: 0.2rem 0.55rem;
    min-width: 2.5rem;
}

.quiz-list-empty td {
    border: none !important;
}

/* Upload drop zones */
.upload-dropzone {
    position: relative;
    border: 2px dashed var(--border-color);
    border-radius: 0.75rem;
    background: #f8fafc;
    min-height: 160px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}

.upload-dropzone:hover {
    border-color: var(--accent-color);
    background: #eff6ff;
}

.upload-dropzone.upload-dropzone-active {
    border-color: var(--accent-color);
    background: #dbeafe;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.upload-dropzone.upload-dropzone-filled {
    border-color: #16a34a;
    background: #f0fdf4;
}

.upload-dropzone-input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    width: 100%;
    height: 100%;
}

.upload-dropzone-content {
    pointer-events: none;
    padding: 1.25rem;
}

.upload-dropzone-icon {
    font-size: 1.75rem;
    color: var(--accent-color);
    margin-bottom: 0.5rem;
}

.upload-dropzone-title {
    font-weight: 600;
    color: var(--text-main);
}

.upload-dropzone-hint {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.upload-dropzone-filename {
    margin-top: 0.75rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: #15803d;
    word-break: break-all;
}

.upload-dropzone.upload-dropzone-error {
    border-color: #dc2626;
    background: #fef2f2;
}

/* Home & Landing */
.card {
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    border-radius: 0.75rem;
    /* 12px */
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.hover-shadow:hover {
    transform: translateY(-2px);
    border-color: var(--accent-color) !important;
}

/* Quiz Header */
.quiz-header {
    background-color: var(--primary-color);
    color: white;
    box-shadow: var(--shadow-md);
    height: 60px;
    z-index: 1030;
    position: relative;
}

.quiz-header h5 {
    font-size: 1.1rem;
    font-weight: 500;
}

/* Quiz Footer */
.quiz-footer {
    background-color: var(--surface-color);
    border-top: 1px solid var(--border-color);
    height: 70px;
    z-index: 1030;
    box-shadow: 0 -1px 3px rgba(0, 0, 0, 0.05);
}

.edit-shortcut-hint {
    display: inline-block;
    margin-left: 0.35rem;
    padding: 0.08rem 0.35rem;
    font-size: 0.68rem;
    font-weight: 600;
    line-height: 1.2;
    color: inherit;
    background: rgba(255, 255, 255, 0.85);
    border: 1px solid rgba(0, 0, 0, 0.12);
    border-radius: 0.25rem;
    opacity: 0.9;
    vertical-align: middle;
}

.btn-primary .edit-shortcut-hint,
.btn-info.text-white .edit-shortcut-hint,
.btn-secondary .edit-shortcut-hint {
    background: rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.35);
}

.btn-outline-secondary .edit-shortcut-hint {
    background: #f8fafc;
    border-color: #cbd5e1;
    color: #475569;
}

.quiz-header .edit-shortcut-hint {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.35);
    color: #fff;
}

.modal-shortcut-hint {
    font-size: 0.75rem;
    color: #64748b;
}

.editor-help-table kbd {
    font-size: 0.78rem;
    padding: 0.15rem 0.4rem;
}

.editor-help-table td {
    vertical-align: top;
    padding: 0.35rem 0.5rem;
}

.editor-help-table td:first-child {
    white-space: nowrap;
    width: 11rem;
    font-weight: 500;
}

/* Layout Screens */
#quiz-screen {
    /* Base: Desktop Fixed Layout */
    height: 100vh;
    overflow: hidden;
    background-color: var(--bg-color);
}

.quiz-content {
    background-color: var(--bg-color);
    position: relative;
}

/* Question Pane */
#question-pane {
    background-color: var(--surface-color);
    border-right: 1px solid var(--border-color);
    box-shadow: inset -1px 0 0 rgba(0, 0, 0, 0.02);
}

#question-text {
    font-size: 1.15rem;
    line-height: 1.7;
    color: var(--text-main);
}

/* Options Pane */
#options-pane {
    background-color: var(--bg-color);
    /* Slightly grey contrast */
}

/* Edit mode: auto-height text areas, scrollable panes */
#question-pane.edit-mode-active,
#options-pane.edit-mode-active {
    overflow: auto;
}

#question-pane:not(.edit-mode-active),
#options-pane:not(.edit-mode-active) {
    overflow: auto;
}

.quiz-edit-difficulty {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.5rem;
    border-radius: 0.375rem;
    background: #fff;
    border: 1px solid var(--border-color, #dee2e6);
    white-space: nowrap;
}

.btn-source-page-link {
    display: inline-flex;
    align-items: center;
    font-weight: 600;
    border-width: 1.5px;
    white-space: nowrap;
}

/* Linked → green; unlinked → gray (icon + label) */
.btn-source-page-link.is-linked,
.btn-source-page-link.is-linked .fa-link {
    color: #198754 !important;
    border-color: #198754;
    background: rgba(25, 135, 84, 0.08);
}

.btn-source-page-link.is-linked:hover,
.btn-source-page-link.is-linked:focus,
.btn-source-page-link.is-linked:hover .fa-link,
.btn-source-page-link.is-linked:focus .fa-link {
    color: #fff !important;
    background: #198754;
    border-color: #198754;
}

.btn-source-page-link.is-unlinked,
.btn-source-page-link.is-unlinked .fa-link {
    color: #9aa0a6 !important;
    border-color: #ced4da;
    background: #fff;
}

.btn-source-page-link.is-unlinked:hover,
.btn-source-page-link.is-unlinked:focus,
.btn-source-page-link.is-unlinked:hover .fa-link,
.btn-source-page-link.is-unlinked:focus .fa-link {
    color: #6c757d !important;
    background: #f8f9fa;
    border-color: #adb5bd;
}

.btn-source-page-link:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

#question-header-badges .ee-difficulty-stars .ee-star {
    font-size: 0.75rem;
}

.edit-auto-textarea {
    width: 100%;
    min-height: 3rem;
    resize: vertical;
    overflow-y: hidden;
    field-sizing: content;
}

@supports not (field-sizing: content) {
    .edit-auto-textarea {
        overflow-y: hidden;
    }
}

.question-image-preview .question-image-display {
    max-height: 350px;
    object-fit: contain;
}

.metadata-editor-section {
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 1rem 1.1rem;
    margin-bottom: 1rem;
    background: #fff;
}

.metadata-editor-section-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 0.85rem;
}

.metadata-readonly-panel {
    border: 1px dashed #cbd5e1;
    border-radius: 0.75rem;
    padding: 0.85rem 1rem;
    background: #f8fafc;
    margin-top: 0.5rem;
}

.metadata-readonly-panel .metadata-readonly-label {
    font-size: 0.78rem;
    font-weight: 600;
    color: #64748b;
}

.metadata-readonly-panel .metadata-readonly-value {
    font-size: 0.85rem;
    color: #334155;
    word-break: break-word;
}

/* Option Cards */
.option-card {
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    /* 12px */
    padding: 1rem 1.25rem;
    cursor: pointer;
    background-color: var(--surface-color);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: flex-start;
    /* Align top for long text */
    position: relative;
}

@media (hover: hover) {
    .option-card:hover {
        border-color: var(--accent-color);
        background-color: white;
        transform: translateY(-1px);
        box-shadow: var(--shadow-sm);
    }
}

.option-card.selected {
    border-color: var(--selected-border);
    background-color: var(--selected-bg);
    box-shadow: 0 0 0 1px var(--selected-border);
}

/* Markers */
.option-label {
    min-width: 24px;
    font-weight: 600;
    color: var(--text-muted);
}

.option-card.selected .option-label {
    color: var(--accent-color);
}

.option-marker {
    width: 20px;
    height: 20px;
    border: 2px solid #cbd5e1;
    /* Slate 300 */
    border-radius: 50%;
    margin-right: 1rem;
    margin-top: 2px;
    /* Visual alignment with text */
    flex-shrink: 0;
    background-color: white;
    transition: all 0.2s;
}

.option-card.selected .option-marker {
    border-color: var(--selected-border);
    background-color: var(--selected-border);
    box-shadow: inset 0 0 0 4px white;
}

.option-text {
    font-size: 1.05rem;
    color: var(--text-main);
    line-height: 1.5;
}

/* Feedback States - Enforced */
.option-card.correct-answer {
    border-color: var(--correct-border) !important;
    background-color: var(--correct-bg) !important;
    box-shadow: 0 0 0 1px var(--correct-border) !important;
    /* Force visibility */
}

.option-card.correct-answer .option-marker {
    border-color: var(--correct-border) !important;
    background-color: var(--correct-border) !important;
    box-shadow: inset 0 0 0 4px white;
}

.option-card.correct-answer .option-text {
    color: #15803d !important;
    /* Dark Green Text */
    font-weight: 600;
}

.fill-blank-answer-value {
    border-color: var(--correct-border) !important;
    background-color: var(--correct-bg) !important;
    color: #15803d;
    font-weight: 600;
}

.option-card.wrong-answer {
    border-color: var(--wrong-border) !important;
    background-color: var(--wrong-bg) !important;
}

.option-card.wrong-answer .option-marker {
    border-color: var(--wrong-border) !important;
    background-color: var(--wrong-border) !important;
}

/* AI Tutor Offcanvas */
.offcanvas {
    border-left: none;
    box-shadow: -4px 0 25px rgba(0, 0, 0, 0.1);
}

.offcanvas-header {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: white !important;
}

.offcanvas-title {
    font-weight: 700;
    letter-spacing: 0.5px;
}

.offcanvas-body {
    background-color: #fffbeb;
    /* Amber 50 */
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* --- Mobile Optimization --- */
@media (max-width: 991.98px) {

    /* Break Layout */
    #quiz-screen {
        height: auto !important;
        /* Allow growing */
        min-height: 100vh;
        overflow: visible !important;
        padding-top: 60px;
        /* Header height */
        padding-bottom: 70px;
        /* Footer height */
    }

    .quiz-header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        width: 100%;
    }

    .quiz-footer {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
    }

    .quiz-content {
        display: block !important;
        /* Remove flex */
        overflow: visible !important;
        /* Allow page scroll */
        height: auto !important;
    }

    .quiz-content .row {
        height: auto !important;
        margin: 0 !important;
        display: block !important;
        /* Stack columns */
    }

    #question-pane.edit-mode-active,
    #options-pane.edit-mode-active {
        overflow: visible !important;
        height: auto !important;
    }

    .edit-auto-textarea {
        min-height: 120px;
        height: auto !important;
    }

    #question-pane,
    #options-pane {
        height: auto !important;
        overflow: visible !important;
        width: 100% !important;
        border: none !important;
        padding: 1.5rem !important;
    }

    #question-pane {
        border-bottom: 4px solid var(--border-color) !important;
        /* Visual separator */
        padding-bottom: 2rem !important;
    }

    #options-pane {
        padding-top: 2rem !important;
        background-color: var(--bg-color);
        padding-bottom: 80px !important;
        /* Extra bottom padding for footer overlap check */
    }

    /* Adjust typography for mobile */
    #question-text {
        font-size: 1.1rem;
    }

    .option-card {
        padding: 0.875rem 1rem;
    }
}

/* Markdown Content Styling */
.markdown-content B,
.markdown-content I,
.markdown-content U,
.option-text B,
.option-text I,
.option-text U {
    font: inherit;
}

.markdown-content B,
.option-text B {
    font-weight: 700;
}

.markdown-content I,
.option-text I {
    font-style: italic;
}

.markdown-content U,
.option-text U {
    text-decoration: underline;
}

.markdown-content ul,
.markdown-content ol {
    padding-left: 1.25rem;
    margin-bottom: 1rem;
}

.markdown-content li {
    margin-bottom: 0.5rem;
}

.markdown-content h1,
.markdown-content h2,
.markdown-content h3,
.markdown-content h4,
.markdown-content h5,
.markdown-content h6 {
    font-weight: 700;
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    color: var(--primary-color);
    font-size: 1rem;
    /* Maintain consistent body text size */
}

.markdown-content p {
    margin-bottom: 1rem;
}

.markdown-content strong {
    color: var(--primary-light);
}

.markdown-content blockquote {
    border-left: 4px solid var(--accent-color);
    padding-left: 1rem;
    color: var(--text-muted);
    font-style: italic;
    margin-bottom: 1rem;
}

/* Ensure code blocks don't overflow */
.markdown-content pre {
    background-color: #f1f5f9;
    padding: 1rem;
    border-radius: 0.5rem;
    overflow-x: auto;
}

/* Markdown Table Styling */
.markdown-content table {
    width: 100%;
    margin-bottom: 1rem;
    color: var(--text-main);
    border-collapse: collapse;
    font-size: 0.95rem;
}

.markdown-content table th,
.markdown-content table td {
    padding: 0.75rem;
    border: 1px solid var(--border-color);
}

.markdown-content table th {
    background-color: #f1f5f9;
    /* Slate 100 */
    font-weight: 600;
    text-align: left;
    color: var(--primary-light);
}

.markdown-content table tbody tr:nth-of-type(odd) {
    background-color: rgba(255, 255, 255, 0.5);
}

.markdown-content table tbody tr:nth-of-type(even) {
    background-color: #f8fafc;
    /* Slate 50 */
}

/* Opacity Helpers */
.opacity-75 {
    opacity: 0.75;
}

.hover-opacity-100:hover {
    opacity: 1 !important;
    transform: translateX(-3px);
}


/* Force the MathJax container to stay inline */
mjx-container[jax="CHTML"][display="true"] {
    display: inline-block !important;
    text-align: left !important;
    margin-left: 1rem !important;
    margin-right: 1rem !important;
}

mjx-container {
    display: inline !important;
    margin-left: 0.5rem !important;
    margin-right: 0.5rem !important;
}

/* Accessiblity Utility */
.visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* =========================================
   Mobile Optimization (Max Width: 768px)
   ========================================= */
@media (max-width: 768px) {

    /* --- Top Header Compact --- */
    .quiz-header {
        height: auto !important;
        min-height: 50px;
        padding: 0.5rem 1rem !important;
        flex-wrap: nowrap;
    }

    #quiz-title-display {
        font-size: 1rem;
        max-width: 40vw !important;
    }

    /* Hide less important badges/labels to save space */
    #mode-badge {
        display: none !important;
    }

    /* Compact timer and summary buttons */
    #timer-container {
        font-size: 0.85rem;
    }

    #summary-indicator {
        padding: 0.25rem 0.5rem !important;
        font-size: 0.85rem;
    }

    /* Hide "Question 1 of 50" text, keep navigation clear or rely on modal */
    .quiz-header .text-white-50.border-start {
        display: none !important;
    }

    /* --- Bottom Footer Compact --- */
    .quiz-footer {
        padding: 0.5rem !important;
        display: flex !important;
        justify-content: space-between !important;
        gap: 0.5rem;
    }

    /* Target the Left Div (Previous container) */
    .quiz-footer>div:first-child {
        flex: 1;
        display: flex;
        justify-content: flex-start;
    }

    /* Target the Right Div (Show Answer, Next, Finish container) */
    .quiz-footer>div:last-child {
        flex: 2;
        /* Give more space to the right side buttons */
        display: flex;
        justify-content: flex-end;
        gap: 0.5rem;
    }

    /* Button Specifics */
    .quiz-footer button {
        padding: 0.5rem 0.75rem !important;
        font-size: 0.9rem !important;
        white-space: nowrap;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Make buttons grow to fill space */
    #btn-prev,
    #btn-next,
    #btn-show-answer {
        height: 44px;
        /* Touch target size */
    }

    #btn-prev {
        width: 100%;
        /* Fill the left container */
        max-width: 120px;
    }

    #btn-next {
        flex-grow: 1;
    }

    #btn-show-answer {
        flex-grow: 1;
    }

    /* Hide text on very narrow screens if needed */
    @media (max-width: 380px) {
        .quiz-footer button {
            padding: 0.5rem !important;
        }

        #btn-prev,
        #btn-next {
            font-size: 0.8rem !important;
        }
    }

    .quiz-bank-header {
        flex-direction: column;
    }

    .quiz-bank-title {
        font-size: 1.35rem;
    }

    .quiz-list-table thead th {
        position: static;
    }

    /* --- Quiz List Table-to-Grid Transformation --- */
    #quiz-list table,
    #quiz-list thead,
    #quiz-list tbody,
    #quiz-list th,
    #quiz-list td,
    #quiz-list tr {
        display: block;
    }

    /* Hide Headers */
    #quiz-list thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }

    #quiz-list tr {
        background-color: white;
        border: 1px solid var(--border-color);
        border-radius: 0.75rem;
        margin-bottom: 1rem;
        box-shadow: var(--shadow-sm);
        padding: 1rem;
        position: relative;
    }

    #quiz-list tr:hover {
        transform: none;
        /* Disable shift on mobile */
        box-shadow: var(--shadow-md);
    }

    #quiz-list td {
        border: none;
        position: relative;
        padding-left: 0;
        padding-right: 0;
        padding-top: 0.25rem;
        padding-bottom: 0.25rem;
        display: flex;
        justify-content: space-between;
        align-items: center;
        text-align: right;
    }

    /* Column Headers via Data Label */
    #quiz-list td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-muted);
        font-size: 0.85rem;
        text-transform: uppercase;
        margin-right: 1rem;
        text-align: left;
    }

    /* Special Styling for specific columns */

    /* Favorite: Top Right Absolute */
    #quiz-list td[data-label="Select"] {
        position: absolute;
        top: 0.75rem;
        left: 0.75rem;
        width: auto;
        padding: 0;
        z-index: 2;
        border-bottom: none;
    }

    #quiz-list td[data-label="Select"]::before {
        display: none;
    }

    #quiz-list td[data-label="Favorite"] {
        position: absolute;
        top: 0.75rem;
        right: 0.75rem;
        width: auto;
        padding: 0;
        z-index: 2;
        border-bottom: none;
    }

    #quiz-list td[data-label="Favorite"]::before {
        display: none;
    }

    /* Exam: Title block at top */
    #quiz-list td[data-label="Exam"] {
        display: block;
        text-align: left;
        margin-bottom: 0.5rem;
        padding-top: 0.5rem;
        padding-right: 2.5rem;
        padding-left: 2.5rem;
    }

    #quiz-list td[data-label="Exam"]::before {
        display: none;
    }

    #quiz-list td[data-label="Exam"] .quiz-exam-title {
        font-size: 1rem;
        max-width: none;
        white-space: normal;
    }

    #quiz-list td[data-label="ID"] {
        position: absolute;
        top: 0.75rem;
        left: 0.75rem;
        width: auto;
        padding: 0;
        border-bottom: none;
    }

    #quiz-list td[data-label="ID"]::before {
        display: none;
    }

    #quiz-list td[data-label="Action"] {
        justify-content: stretch;
        padding-top: 0.75rem;
    }

    #quiz-list td[data-label="Action"]::before {
        display: none;
    }

    #quiz-list td[data-label="Action"] .quiz-row-actions {
        width: auto;
        flex-direction: row;
        justify-content: flex-end;
    }

    #quiz-list td[data-label="Action"] .quiz-row-action-icon {
        width: 2.25rem;
        height: 2.25rem;
    }

    /* Legacy Organization label fallback */
    #quiz-list td[data-label="Organization"] {
        display: block;
        text-align: left;
        font-size: 1.1rem;
        color: var(--primary-color);
        margin-bottom: 0.5rem;
        padding-right: 2rem;
        /* Avoid overlap with Star */
        border-bottom: 1px solid var(--border-color);
        padding-bottom: 0.75rem;
    }

    #quiz-list td[data-label="Organization"]::before {
        display: none;
    }

    /* Subject: Slightly emphasized */
    #quiz-list td[data-label="Subject"] {
        font-weight: 600;
        color: var(--accent-color);
    }

    /* Score: Bold and Colorful */
    #quiz-list td[data-label="Score"] {
        font-size: 1rem;
        margin-top: 0.5rem;
        border-top: 1px dashed var(--border-color);
        padding-top: 0.75rem;
    }
}

/* --- Image Zoom Modal --- */
.cursor-zoom-in {
    cursor: zoom-in;
}

.cursor-zoom-out {
    cursor: zoom-out;
}

#imageZoomModal .modal-dialog {
    max-width: 95vw;
}

#imageZoomModal .modal-content {
    background: transparent;
}

/* --- Question Image Editor Modal --- */
.qimg-editor-stage {
    max-width: 100%;
    overflow: auto;
    background: #e9ecef;
    border: 1px solid #dee2e6;
    border-radius: 0.5rem;
    min-height: 200px;
    max-height: min(70vh, 720px);
    display: flex;
    align-items: center;
    justify-content: center;
}

#qimg-editor-canvas {
    display: block;
    max-width: 100%;
    max-height: min(70vh, 720px);
    cursor: crosshair;
    touch-action: none;
}

#qimg-editor-canvas.qimg-cursor-eraser {
    cursor: none;
}

.qimg-editor-selection {
    position: absolute;
    border: 2px dashed #0d6efd;
    background: rgba(13, 110, 253, 0.12);
    pointer-events: none;
    box-sizing: border-box;
}

.qimg-editor-selection.qimg-selection-clear {
    border-color: #dc3545;
    background: rgba(255, 255, 255, 0.55);
    border-style: solid;
}

.qimg-editor-selection.qimg-selection-crop {
    border-color: #0d6efd;
    background: rgba(13, 110, 253, 0.12);
}

.qimg-editor-eraser-cursor {
    position: absolute;
    border: 2px solid rgba(220, 53, 69, 0.85);
    background: rgba(255, 255, 255, 0.25);
    border-radius: 50%;
    pointer-events: none;
    transform: translate(-50%, -50%);
    box-sizing: border-box;
    z-index: 2;
}

.qimg-brush-range {
    width: 120px;
}

.question-image-editable {
    cursor: pointer;
    transition: box-shadow 0.15s ease;
}

.question-image-editable:hover {
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.35);
}

/* Enhanced explanation modal */
#enhancedExplanationModal .ee-modal-dialog {
    max-width: 100%;
    width: 100%;
    margin: 0;
    height: 100%;
}

.ee-modal-content {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-height: 100vh;
    overflow: hidden;
    border-radius: 0;
}

.ee-modal-header {
    background: #f8fafc;
    flex-shrink: 0;
}

.ee-header-title-row {
    background: #fff;
    border-bottom: 1px solid var(--border-color, #dee2e6);
}

.ee-header-controls {
    background: #f8fafc;
}

.ee-toolbar-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    min-width: 0;
}

.ee-toolbar-label {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted, #6c757d);
    line-height: 1.2;
}

.ee-toolbar-body {
    min-height: 2rem;
}

.ee-meta-chip {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.5rem;
    border-radius: 0.375rem;
    background: #fff;
    border: 1px solid var(--border-color, #dee2e6);
    white-space: nowrap;
}

.ee-difficulty-chip {
    gap: 0.15rem;
}

#ee-nav-indicator-btn {
    pointer-events: none;
    min-width: 5.5rem;
    font-weight: 600;
    color: var(--bs-body-color, #212529);
    opacity: 1;
}

.ee-batch-panel {
    flex-shrink: 0;
    background: #f1f5f9;
}

.ee-batch-panel-inner {
    max-width: 100%;
}

.ee-batch-range-input {
    width: 4.5rem;
}

.ee-batch-progress {
    height: 6px;
}

.ee-right-toolbar {
    flex-shrink: 0;
    padding: 0.65rem 0.75rem;
    background: #fff;
    border: 1px solid var(--border-color, #dee2e6);
    border-radius: 0.5rem;
}

#ee-batch-toggle-btn.active {
    background: var(--bs-primary);
    border-color: var(--bs-primary);
    color: #fff;
}

.ee-modal-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.ee-workspace {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    position: relative;
}

.ee-split-panels {
    display: flex;
    flex-direction: row;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
}

#ee-main-panel {
    flex: 1 1 auto;
    min-height: 0;
}

.ee-left-panel,
.ee-right-panel {
    flex: 1 1 50%;
    min-width: 0;
    min-height: 0;
}

.ee-left-panel {
    border-right: 1px solid var(--border-color, #dee2e6);
    background: #fff;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.ee-right-panel {
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.ee-panel-inner {
    padding: 1rem 1.25rem;
}

.ee-right-panel-inner {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    height: 100%;
    padding-bottom: 1rem;
}

.ee-right-toolbar {
    flex-shrink: 0;
}

.ee-editor-shell {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.ee-language-select {
    min-width: 7.5rem;
}

.ee-question-filter {
    min-width: 9.5rem;
    max-width: 12rem;
}

.ee-explanation-textarea,
.ee-explanation-preview {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.ee-explanation-textarea {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.875rem;
    line-height: 1.5;
    resize: none;
}

.ee-explanation-preview {
    font-family: inherit;
    font-size: 0.9375rem;
    line-height: 1.6;
}

.ee-preview-block {
    margin-bottom: 1rem;
}

.ee-preview-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted, #6c757d);
    margin-bottom: 0.35rem;
}

.ee-option-row {
    padding: 0.35rem 0.5rem;
    border-radius: 0.375rem;
    margin-bottom: 0.25rem;
    border: 1px solid transparent;
}

.ee-option-correct {
    background: rgba(25, 135, 84, 0.08);
    border-color: rgba(25, 135, 84, 0.25);
}

.ee-difficulty-stars {
    display: inline-flex;
    align-items: center;
    gap: 0.1rem;
    letter-spacing: 0;
}

.ee-difficulty-stars .ee-star {
    font-size: 0.8rem;
    line-height: 1;
}

.ee-difficulty-stars .ee-star-filled {
    color: #f59e0b;
}

.ee-difficulty-stars .ee-star-empty {
    color: #cbd5e1;
}

.ee-difficulty-stars .ee-star-none {
    color: #94a3b8;
    font-size: 0.75rem;
}

.ee-knowledge-base-select {
    min-width: 10rem;
    max-width: 16rem;
}

.ee-knowledge-reference {
    padding: 0.35rem 0.6rem;
    background: rgba(25, 135, 84, 0.08);
    border: 1px solid rgba(25, 135, 84, 0.25);
    border-radius: 0.375rem;
    line-height: 1.4;
}

.ee-knowledge-reference .ee-page-link {
    font-size: 0.8125rem;
    text-decoration: none;
}

.ee-knowledge-reference .ee-page-link:hover {
    text-decoration: underline;
}

.ee-page-viewer {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    background: #f8fafc;
}

.ee-page-viewer-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    padding: 0;
    background: #e2e8f0;
    cursor: grab;
    touch-action: none;
    user-select: none;
}

.ee-page-viewer-body.is-dragging {
    cursor: grabbing;
}

.ee-page-viewer-stage {
    display: inline-block;
    transform-origin: 0 0;
    will-change: transform;
}

.ee-page-viewer-image {
    display: block;
    width: auto;
    height: auto;
    max-width: none;
    box-shadow: 0 4px 16px rgba(15, 23, 42, 0.15);
    background: #fff;
    pointer-events: none;
}

.ee-left-panel.ee-showing-page-viewer .ee-panel-inner {
    display: none;
}

.ee-console-panel {
    flex: 0 0 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: #0f172a;
    color: #e2e8f0;
    border-top: 2px solid #334155;
}

.ee-console-panel.collapsed {
    flex: 0 0 auto;
}

.ee-console-panel.collapsed .ee-console-body {
    display: none;
}

.ee-console-panel.ee-console-expanded {
    position: absolute;
    inset: 0;
    z-index: 40;
    flex: none;
    width: 100%;
    height: 100%;
    border-top: none;
}

.ee-console-header {
    flex-shrink: 0;
    background: #1e293b;
    border-top: none !important;
}

.ee-console-title {
    letter-spacing: 0.08em;
    color: #94a3b8;
}

.ee-console-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
}

.ee-console-log {
    height: 100%;
    overflow: auto;
    padding: 0.75rem 1rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.75rem;
    line-height: 1.45;
}

.ee-console-empty {
    padding: 0.5rem 0;
}

.ee-console-entry {
    margin-bottom: 0.75rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid rgba(148, 163, 184, 0.2);
}

.ee-console-entry:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.ee-console-entry-head {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    margin-bottom: 0.35rem;
    flex-wrap: wrap;
}

.ee-console-entry-time {
    color: #64748b;
    font-size: 0.6875rem;
}

.ee-console-entry-step {
    font-size: 0.625rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 0.1rem 0.35rem;
    border-radius: 0.25rem;
    background: rgba(148, 163, 184, 0.15);
    color: #cbd5e1;
}

.ee-console-entry-title {
    font-weight: 600;
    color: #f8fafc;
}

.ee-console-entry-detail {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
    color: #cbd5e1;
}

.ee-console-entry.step-knowledge .ee-console-entry-step { background: rgba(34, 197, 94, 0.2); color: #86efac; }
.ee-console-entry.step-ai_request .ee-console-entry-step,
.ee-console-entry.step-ai_response .ee-console-entry-step { background: rgba(59, 130, 246, 0.2); color: #93c5fd; }
.ee-console-entry.step-save .ee-console-entry-step,
.ee-console-entry.step-update .ee-console-entry-step { background: rgba(245, 158, 11, 0.2); color: #fcd34d; }
.ee-console-entry.step-error .ee-console-entry-step { background: rgba(239, 68, 68, 0.2); color: #fca5a5; }

@media (max-width: 991.98px) {
    #enhancedExplanationModal .ee-modal-dialog {
        max-width: 100%;
        width: 100%;
        margin: 0;
    }

    .ee-modal-content {
        height: 100vh;
        max-height: 100vh;
    }

    .ee-header-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .ee-toolbar-settings {
        margin-left: 0 !important;
    }

    .ee-toolbar-settings .ee-toolbar-body {
        justify-content: flex-start;
    }

    .ee-split-panels {
        flex-direction: column;
    }

    .ee-left-panel {
        border-right: none;
        border-bottom: 1px solid var(--border-color, #dee2e6);
        flex: 1 1 45%;
        max-height: none;
    }

    .ee-right-panel {
        flex: 1 1 55%;
        max-height: none;
    }
}