/**
 * CampusQCM - Correction Modal — Premium Full-Screen Mobile App
 * 
 * Design philosophy: Full-viewport, native-app feel with fluid
 * typography, glassmorphism header, circular score hero and
 * card-based correction items.
 *
 * @package CampusQCM
 * @version 2.0.0
 */

/* ─────────────────────────────────────────
   CSS VARIABLES (local overrides)
   ───────────────────────────────────────── */
.correction-modal {
    --cm-radius: 14px;
    --cm-radius-lg: 20px;
    --cm-gap: 12px;
    --cm-green: #22c55e;
    --cm-red: #ef4444;
    --cm-orange: #f59e0b;
    --cm-indigo: #6366f1;
    --cm-indigo-glow: rgba(99, 102, 241, 0.35);
    --cm-font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ─────────────────────────────────────────
   MODAL SHELL — Full-screen overlay
   ───────────────────────────────────────── */
.correction-modal {
    position: fixed !important;
    inset: 0 !important;
    z-index: 10000;
    display: flex;
    align-items: stretch;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity .32s cubic-bezier(.4,0,.2,1),
                visibility .32s cubic-bezier(.4,0,.2,1);
    font-family: var(--cm-font);
    -webkit-font-smoothing: antialiased;
    max-height: none !important;
    width: 100% !important;
    height: 100% !important;
    margin: 0 !important;
    border-radius: 0 !important;
    transform: none !important;
    overflow: visible !important;
}

.correction-modal.is-open {
    opacity: 1;
    visibility: visible;
}

/* Backdrop */
.correction-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, .65);
    backdrop-filter: blur(12px) saturate(1.2);
    -webkit-backdrop-filter: blur(12px) saturate(1.2);
}

/* ─────────────────────────────────────────
   CONTAINER — The main panel
   ───────────────────────────────────────── */
.correction-modal__container {
    position: relative;
    width: 100%;
    height: 100%;
    max-height: 100dvh;
    background: var(--cq-bg, #0f172a);
    display: flex;
    flex-direction: column;
    transform: translateY(40px);
    transition: transform .38s cubic-bezier(.22,1,.36,1);
    overflow: hidden;
    box-shadow: 0 0 80px rgba(0,0,0,.45);
    margin: 0;
    border-radius: 0;
}

.correction-modal.is-open .correction-modal__container {
    transform: translateY(0);
}

/* Desktop: centered card */
@media (min-width: 769px) {
    .correction-modal {
        padding: 2rem;
        align-items: center;
    }
    .correction-modal__container {
        max-width: 520px;
        max-height: 92vh;
        border-radius: var(--cm-radius-lg);
    }
}

.correction-modal__content {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* No wildcard override needed — [class*="modal"] in mobile-override.css
   now excludes correction-modal elements via :not() */

/* ─────────────────────────────────────────
   TOP BAR — Sticky close + title
   ───────────────────────────────────────── */
.correction-modal__topbar {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px 16px;
    padding-top: max(10px, env(safe-area-inset-top, 10px));
    background: rgba(15, 23, 42, .82);
    backdrop-filter: blur(16px) saturate(1.4);
    -webkit-backdrop-filter: blur(16px) saturate(1.4);
    border-bottom: 1px solid rgba(255,255,255,.06);
    flex-shrink: 0;
}

.correction-modal__topbar-title {
    font-size: .9375rem;
    font-weight: 700;
    color: var(--cq-text, #f1f5f9);
    letter-spacing: -.01em;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Close button removed — "Fermer" in footer handles close */

/* ─────────────────────────────────────────
   HERO SECTION — Compact horizontal layout
   ───────────────────────────────────────── */
.correction-modal__hero {
    flex-shrink: 0;
    flex-grow: 0;
    padding: 10px 16px;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    max-height: 100px;
    overflow: hidden;
    background: linear-gradient(
        135deg,
        rgba(99, 102, 241, .08) 0%,
        transparent 60%
    );
    border-bottom: 1px solid rgba(255,255,255,.05);
}

/* Score ring — layout handled entirely via inline styles in JS
   to prevent cascade conflicts from mobile CSS files.
   Only text styles for .score-number / .score-unit live here. */

.score-number {
    font-size: 1rem;
    font-weight: 800;
    color: #fff;
    line-height: 1;
    letter-spacing: -.03em;
}

.score-unit {
    font-size: .5rem;
    font-weight: 600;
    color: var(--cq-text-muted, #94a3b8);
    text-transform: uppercase;
    letter-spacing: .06em;
    margin-top: 1px;
}

/* Hero info (right side) */
.correction-modal__hero-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding-top: 2px;
}

.correction-modal__hero-subtitle {
    font-size: .6875rem;
    color: var(--cq-text-muted, #94a3b8);
    line-height: 1.3;
    word-break: break-word;
}

/* Meta row (subject bullet level) */
.correction-modal__meta-row {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.correction-modal__meta-row .meta-subject {
    font-size: .75rem;
    font-weight: 600;
    color: var(--cm-indigo);
    word-break: break-word;
}

.correction-modal__meta-row .meta-sep {
    font-size: .6rem;
    color: rgba(255,255,255,.2);
}

.correction-modal__meta-row .meta-level {
    font-size: .6rem;
    font-weight: 700;
    background: rgba(99,102,241,.15);
    color: var(--cm-indigo);
    padding: 1px 6px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: .04em;
    flex-shrink: 0;
}

/* Stats pills row */
.correction-modal__stats-row {
    display: flex;
    align-items: center;
    gap: 5px;
    flex-wrap: wrap;
    margin-top: 2px;
}

.cm-pill {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 3px 8px;
    border-radius: 100px;
    font-size: .6875rem;
    font-weight: 600;
    background: rgba(255,255,255,.06);
    border: 1px solid rgba(255,255,255,.06);
    color: var(--cq-text, #f1f5f9);
    white-space: nowrap;
}

.cm-pill .pill-icon {
    font-size: .6875rem;
    line-height: 1;
}

.cm-pill--correct .pill-icon { color: var(--cm-green); }
.cm-pill--xp .pill-icon { color: var(--cm-indigo); }
.cm-pill--badge {
    background: rgba(99,102,241,.12);
    border-color: rgba(99,102,241,.2);
}

/* ─────────────────────────────────────────
   FILTER TABS
   ───────────────────────────────────────── */
.correction-modal__filters {
    flex-shrink: 0;
    display: flex;
    gap: 5px;
    padding: 8px 14px;
    border-bottom: 1px solid rgba(255,255,255,.06);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.correction-modal__filters::-webkit-scrollbar { display: none; }

.modal-filter {
    flex-shrink: 0;
    background: transparent;
    border: 1px solid rgba(255,255,255,.1);
    color: var(--cq-text-muted, #94a3b8);
    padding: 5px 12px;
    border-radius: 100px;
    font-size: .6875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all .2s;
    white-space: nowrap;
    letter-spacing: .01em;
}

.modal-filter:hover {
    border-color: rgba(99,102,241,.4);
    color: var(--cq-text, #f1f5f9);
}

.modal-filter--active {
    background: var(--cm-indigo);
    border-color: var(--cm-indigo);
    color: #fff;
    box-shadow: 0 2px 8px var(--cm-indigo-glow);
}

.modal-filter--active:hover {
    background: var(--cm-indigo);
    border-color: var(--cm-indigo);
    color: #fff;
}

/* ─────────────────────────────────────────
   SCROLLABLE BODY
   ───────────────────────────────────────── */
.correction-modal__body {
    flex: 1 1 0% !important;
    min-height: 0 !important;
    overflow-y: auto;
    padding: 10px 10px 16px;
    overscroll-behavior-y: contain;
    scroll-behavior: smooth;
}

.correction-modal__items {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* ─────────────────────────────────────────
   CORRECTION ITEM CARD
   ───────────────────────────────────────── */
.modal-correction-item {
    background: rgba(255,255,255,.04);
    border: 1px solid rgba(255,255,255,.06);
    border-radius: 12px;
    padding: 12px 12px 10px;
    animation: cm-card-in .35s cubic-bezier(.22,1,.36,1) both;
    position: relative;
    overflow: visible;
}

.modal-correction-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    border-radius: 0 3px 3px 0;
}

.modal-correction-item--correct::before {
    background: var(--cm-green);
    box-shadow: 0 0 8px rgba(34,197,94,.3);
}

.modal-correction-item--wrong::before {
    background: var(--cm-red);
    box-shadow: 0 0 8px rgba(239,68,68,.3);
}

@keyframes cm-card-in {
    from {
        opacity: 0;
        transform: translateY(16px) scale(.97);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Item top row */
.modal-correction-item__top,
.modal-correction-item__header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
}

.modal-correction-item .item-number {
    font-size: .625rem;
    font-weight: 700;
    padding: 2px 6px;
    background: rgba(99,102,241,.12);
    color: var(--cm-indigo);
    border-radius: 4px;
    letter-spacing: .03em;
}

.modal-correction-item .item-status {
    font-size: .75rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 3px;
}

.modal-correction-item--correct .item-status {
    color: var(--cm-green);
}

.modal-correction-item--wrong .item-status {
    color: var(--cm-red);
}

.modal-correction-item .item-hint {
    margin-left: auto;
    font-size: .6875rem;
    padding: 2px 8px;
    background: rgba(245,158,11,.12);
    color: var(--cm-orange);
    border-radius: 6px;
    font-weight: 600;
}

/* Question text */
.modal-correction-item__question {
    font-size: .8125rem;
    font-weight: 500;
    color: var(--cq-text, #f1f5f9);
    margin: 0 0 8px 0;
    line-height: 1.45;
    padding-left: 8px;
}

/* Answer rows */
.modal-correction-item__answers {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 0;
}

.item-answer {
    display: flex;
    gap: 6px;
    align-items: center;
    font-size: .75rem;
    padding: 7px 10px;
    border-radius: 8px;
    border: 1px solid transparent;
    line-height: 1.4;
}

.item-answer .answer-icon {
    font-size: .75rem;
    flex-shrink: 0;
    line-height: 1;
}

.item-answer .answer-label {
    font-weight: 500;
    color: var(--cq-text-muted, #94a3b8);
    flex-shrink: 0;
    font-size: .6875rem;
}

.item-answer .answer-value {
    font-weight: 600;
    line-height: 1.35;
}

/* Correct answer */
.item-answer--correct {
    background: rgba(34, 197, 94, .08);
    border-color: rgba(34, 197, 94, .15);
}

.item-answer--correct .answer-value {
    color: var(--cm-green);
}

/* Wrong answer */
.item-answer--wrong {
    background: rgba(239, 68, 68, .15);
    border-color: rgba(239, 68, 68, .25);
}

.item-answer--wrong .answer-value {
    color: var(--cm-red);
    font-weight: 700;
}

/* Expected answer */
.item-answer--expected {
    background: rgba(34, 197, 94, .12);
    border-color: rgba(34, 197, 94, .22);
}

.item-answer--expected .answer-value {
    color: var(--cm-green);
    font-weight: 700;
}

/* Explanation */
.modal-correction-item__explanation {
    padding: 8px 10px;
    background: rgba(99, 102, 241, .06);
    border: 1px solid rgba(99, 102, 241, .1);
    border-radius: 8px;
    margin-top: 8px;
}

.modal-correction-item__explanation .explanation-label {
    font-size: .6875rem;
    font-weight: 700;
    color: var(--cm-indigo);
    letter-spacing: .02em;
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 4px;
}

.modal-correction-item__explanation p {
    margin: 0;
    font-size: .75rem;
    color: var(--cq-text, #f1f5f9);
    line-height: 1.5;
    opacity: .9;
}

/* ─────────────────────────────────────────
   NO DETAILS / NOT FOUND STATES
   ───────────────────────────────────────── */
.correction-modal__no-details,
.correction-modal__not-found {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--cq-text-muted, #94a3b8);
}

.correction-modal__no-details .no-details-icon,
.correction-modal__not-found .not-found-icon {
    font-size: 2.5rem;
    margin-bottom: .75rem;
    opacity: .7;
}

.correction-modal__no-details h3,
.correction-modal__not-found h3 {
    font-size: 1rem;
    color: var(--cq-text, #f1f5f9);
    margin: 0 0 .5rem 0;
    font-weight: 700;
}

.correction-modal__no-details p,
.correction-modal__not-found p {
    margin: 0 0 .5rem 0;
    font-size: .875rem;
    line-height: 1.5;
}

.correction-modal__no-details .no-details-meta {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid rgba(255,255,255,.06);
}

/* ─────────────────────────────────────────
   PAGINATION
   ───────────────────────────────────────── */
.correction-modal__pagination {
    flex-shrink: 0;
    padding: 8px 14px;
    border-top: 1px solid rgba(255,255,255,.06);
}

.correction-modal__pagination:empty {
    display: none;
}

.pagination-info {
    text-align: center;
    font-size: .6875rem;
    color: var(--cq-text-muted, #94a3b8);
    margin-bottom: 6px;
}

.pagination-info strong {
    color: var(--cq-text, #f1f5f9);
}

.pagination-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.pagination-btn {
    background: rgba(255,255,255,.06);
    border: 1px solid rgba(255,255,255,.08);
    color: var(--cq-text, #f1f5f9);
    padding: 6px 12px;
    border-radius: 8px;
    font-size: .75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all .2s;
}

.pagination-btn:hover:not(:disabled) {
    background: rgba(99,102,241,.15);
    border-color: rgba(99,102,241,.3);
    color: #fff;
}

.pagination-btn:disabled {
    opacity: .3;
    cursor: not-allowed;
}

.pagination-pages {
    display: flex;
    gap: 4px;
}

.pagination-page {
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    background: rgba(255,255,255,.04);
    border: 1px solid rgba(255,255,255,.08);
    color: var(--cq-text-muted, #94a3b8);
    border-radius: 8px;
    font-size: .75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all .2s;
}

.pagination-page:hover {
    background: rgba(99,102,241,.12);
    color: #fff;
}

.pagination-page--active {
    background: var(--cm-indigo);
    border-color: var(--cm-indigo);
    color: #fff;
    box-shadow: 0 2px 8px var(--cm-indigo-glow);
}

/* ─────────────────────────────────────────
   FOOTER — Sticky CTA
   ───────────────────────────────────────── */
.correction-modal__footer {
    flex-shrink: 0;
    display: flex;
    gap: 8px;
    padding: 10px 14px;
    padding-bottom: max(10px, env(safe-area-inset-bottom, 10px));
    border-top: 1px solid rgba(255,255,255,.06);
    background: rgba(15, 23, 42, .92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.correction-modal__btn {
    padding: 12px 14px;
    border-radius: 10px;
    font-size: .8125rem;
    font-weight: 700;
    cursor: pointer;
    transition: all .2s;
    text-align: center;
    letter-spacing: -.01em;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    white-space: nowrap;
}

.correction-modal__btn--secondary {
    background: rgba(255,255,255,.06);
    border: 1px solid rgba(255,255,255,.1);
    color: var(--cq-text, #f1f5f9);
    flex: 1 1 0;
}

.correction-modal__btn--secondary:hover {
    background: rgba(255,255,255,.1);
}

.correction-modal__btn--primary {
    background: linear-gradient(135deg, var(--cm-indigo) 0%, #8b5cf6 100%);
    color: #fff;
    box-shadow: 0 4px 14px var(--cm-indigo-glow);
    flex: 1 1 0;
}

.correction-modal__btn--primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px var(--cm-indigo-glow);
}

.correction-modal__btn--primary:active {
    transform: translateY(0);
}

/* ─────────────────────────────────────────
   LIGHT MODE OVERRIDES
   ───────────────────────────────────────── */
body:not(.qcm-dark):not(.dark) .correction-modal__container,
html:not(.dark) body:not(.qcm-dark) .correction-modal__container {
    background: #f8fafc;
}

body:not(.qcm-dark):not(.dark) .correction-modal__topbar,
html:not(.dark) body:not(.qcm-dark) .correction-modal__topbar {
    background: rgba(255,255,255,.88);
    border-bottom-color: rgba(0,0,0,.06);
}

body:not(.qcm-dark):not(.dark) .correction-modal__topbar-title,
html:not(.dark) body:not(.qcm-dark) .correction-modal__topbar-title {
    color: #1e293b;
}

body:not(.qcm-dark):not(.dark) .correction-modal__hero,
html:not(.dark) body:not(.qcm-dark) .correction-modal__hero {
    background: linear-gradient(135deg, rgba(99,102,241,.06) 0%, transparent 60%);
    border-bottom-color: #e2e8f0;
}

body:not(.qcm-dark):not(.dark) .correction-modal__hero-subtitle,
html:not(.dark) body:not(.qcm-dark) .correction-modal__hero-subtitle {
    color: #64748b;
}

/* Score ring light mode: track color + text handled inline in JS.
   Only text fallback overrides kept here. */
body:not(.qcm-dark):not(.dark) .score-number,
html:not(.dark) body:not(.qcm-dark) .score-number {
    color: #1e293b;
}

body:not(.qcm-dark):not(.dark) .score-unit,
html:not(.dark) body:not(.qcm-dark) .score-unit {
    color: #64748b;
}

body:not(.qcm-dark):not(.dark) .cm-pill,
html:not(.dark) body:not(.qcm-dark) .cm-pill {
    background: #fff;
    border-color: #e2e8f0;
    color: #1e293b;
}

body:not(.qcm-dark):not(.dark) .modal-filter,
html:not(.dark) body:not(.qcm-dark) .modal-filter {
    background: #fff;
    border-color: #e2e8f0;
    color: #64748b;
}

body:not(.qcm-dark):not(.dark) .correction-modal__filters,
html:not(.dark) body:not(.qcm-dark) .correction-modal__filters {
    border-bottom-color: #e2e8f0;
}

body:not(.qcm-dark):not(.dark) .modal-correction-item,
html:not(.dark) body:not(.qcm-dark) .modal-correction-item {
    background: #fff;
    border-color: #e2e8f0;
}

body:not(.qcm-dark):not(.dark) .modal-correction-item__question,
html:not(.dark) body:not(.qcm-dark) .modal-correction-item__question {
    color: #1e293b;
}

body:not(.qcm-dark):not(.dark) .modal-correction-item__explanation,
html:not(.dark) body:not(.qcm-dark) .modal-correction-item__explanation {
    background: rgba(99,102,241,.04);
    border-color: rgba(99,102,241,.08);
}

body:not(.qcm-dark):not(.dark) .modal-correction-item__explanation p,
html:not(.dark) body:not(.qcm-dark) .modal-correction-item__explanation p {
    color: #334155;
}

body:not(.qcm-dark):not(.dark) .correction-modal__footer,
html:not(.dark) body:not(.qcm-dark) .correction-modal__footer {
    background: rgba(255,255,255,.92);
    border-top-color: #e2e8f0;
}

body:not(.qcm-dark):not(.dark) .correction-modal__btn--secondary,
html:not(.dark) body:not(.qcm-dark) .correction-modal__btn--secondary {
    background: #fff;
    border-color: #e2e8f0;
    color: #1e293b;
}

body:not(.qcm-dark):not(.dark) .correction-modal__pagination,
html:not(.dark) body:not(.qcm-dark) .correction-modal__pagination {
    border-top-color: #e2e8f0;
}

body:not(.qcm-dark):not(.dark) .pagination-btn,
body:not(.qcm-dark):not(.dark) .pagination-page,
html:not(.dark) body:not(.qcm-dark) .pagination-btn,
html:not(.dark) body:not(.qcm-dark) .pagination-page {
    background: #fff;
    border-color: #e2e8f0;
    color: #1e293b;
}

/* ─────────────────────────────────────────
   CLICKABLE HISTORY ITEMS
   ───────────────────────────────────────── */
.activity-item[data-correction-id],
.table-row[data-correction-id] {
    cursor: pointer;
    transition: all .2s;
}

.activity-item[data-correction-id]:hover {
    background: var(--cq-bg, #f8fafc);
}

.table-row[data-correction-id]:hover {
    background: var(--cq-bg, #f8fafc);
}

body.qcm-dark .activity-item[data-correction-id]:hover,
body.qcm-dark .table-row[data-correction-id]:hover,
html.dark .activity-item[data-correction-id]:hover,
html.dark .table-row[data-correction-id]:hover {
    background: var(--cq-card-bg, #1f2937);
}

.activity-item[data-correction-id]::after,
.table-row[data-correction-id]::after {
    content: '→';
    margin-left: auto;
    color: var(--cq-text-muted, #64748b);
    font-size: .875rem;
    opacity: 0;
    transition: opacity .2s;
}

.activity-item[data-correction-id]:hover::after,
.table-row[data-correction-id]:hover::after {
    opacity: 1;
}
