/* 
 * Attain Paper 2 Performance Enhancer — Grade Engine 
 * Premium Mobile-First UI (Design Aligned)
 */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=Outfit:wght@600;700;800&display=swap');

:root {
    --p2-primary: #6366f1;
    --p2-primary-light: #f0eeff;
    --p2-primary-dark: #4338ca;
    --p2-secondary: #7c3aed;
    --p2-bg: #fdfdfd;
    --p2-card-bg: #ffffff;
    --p2-text: #1e293b;
    --p2-text-muted: #64748b;
    --p2-border: #e2e8f0;
    --p2-border-light: #f1f5f9;
    --p2-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    --p2-success-bg: #ecfdf5;
    --p2-success-text: #065f46;
}

.p2-grader-container {
    font-family: 'Inter', sans-serif;
    color: var(--p2-text);
    background: var(--p2-bg);
    min-height: 100vh;
    max-width: 500px;
    margin: 0 auto;
    position: relative;
    padding-bottom: 120px;
}

/* ── HEADER ─────────────────────────────────────────── */
.p2-grader-header-unified {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: #fff;
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid #ddd;
}

.p2-header-back,
.p2-header-help {
    background: none !important;
    border: none !important;
    color: var(--p2-text) !important;
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    display: none;
}

.p2-header-back .material-symbols-outlined {
    font-size: 28px;
}

.p2-header-help {
    display: none !important;
}

.p2-header-help .material-symbols-outlined {
    font-size: 28px;
    color: var(--p2-primary);
}

.p2-header-center {
    text-align: center;
    flex: 1;
}

.p2-header-title {
    font-size: 20px !important;
    font-weight: 700 !important;
    margin: 0;
    letter-spacing: -0.01em;
}

.p2-subject-trigger {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    font-size: 16px;
    font-weight: 600;
    color: var(--p2-primary);
    cursor: pointer;
    margin-top: 2px;
}

.p2-subject-trigger .material-symbols-outlined {
    font-size: 18px;
}

/* ── MAIN CONTENT ───────────────────────────────────── */
.p2-grader-main {
    padding: 16px;
}

.p2-card-intro {
    display: flex;
    gap: 16px;
    margin-bottom: 20px;
}

.p2-card-icon {
    width: 32px;
    height: 32px;
    color: var(--p2-primary);
    flex-shrink: 0;
}

.p2-card-icon .material-symbols-outlined {
    font-size: 32px;
}

.p2-card-title {
    font-size: 18px;
    font-weight: 700;
    margin: 0 0 4px;
}

.p2-card-helper {
    font-size: 14px;
    color: var(--p2-text-muted);
    line-height: 1.4;
    margin: 0;
}

/* ── UNIFIED WIDGET ─────────────────────────────────── */
.p2-unified-widget {
    position: relative;
    background: #fff;
    border: 1px solid var(--p2-primary-light);
    border-radius: 16px;
    box-shadow: 0 8px 30px rgba(99, 102, 241, 0.05);
    overflow: hidden;
    margin-bottom: 16px;
}

.p2-widget-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(4px);
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s ease;
}

.p2-unified-widget.is-uploading .p2-widget-overlay {
    opacity: 1;
    pointer-events: auto;
}

.p2-widget-overlay span {
    font-weight: 700;
    color: var(--p2-primary);
    font-size: 14px;
}

.p2-spinner-small {
    width: 28px;
    height: 28px;
    border: 3px solid var(--p2-primary-light);
    border-top-color: var(--p2-primary);
    border-radius: 50%;
    animation: p2-spin 0.8s linear infinite;
}

.p2-textarea {
    width: 100%;
    min-height: 200px;
    border: none;
    padding: 24px;
    font-family: inherit;
    font-size: 16px;
    line-height: 1.5;
    resize: none;
    color: var(--p2-text);
}

.p2-textarea::placeholder {
    color: #94a3b8;
    font-weight: 400;
}

.p2-textarea:focus {
    outline: none;
}

.p2-widget-footer {
    padding: 16px 20px;
    border-top: 1px dashed var(--p2-border);
}

.p2-add-btn-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
}

.p2-add-photos-btn {
    background: var(--p2-primary-light);
    color: var(--p2-primary);
    padding: 10px 16px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.p2-add-photos-btn .plus-icon {
    font-size: 18px;
    margin-top: -2px;
    display: none;
}

.p2-widget-helper {
    font-size: 13px;
    color: var(--p2-text-muted);
    flex: 1;
}

.p2-camera-icon {
    color: #64748b;
    font-size: 24px;
    cursor: pointer;
    display: none !important;
}

span.material-symbols-outlined.p2-camera-icon {
    display: none !important;
}

/* ── TIP SECTION ────────────────────────────────────── */
.p2-tip-section {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 32px;
    padding: 0 4px;
}

.p2-tip-section .material-symbols-outlined {
    font-size: 20px;
    color: var(--p2-primary);
    margin-top: 2px;
}

.p2-tip-section p {
    margin: 0;
    font-size: 14px;
    color: var(--p2-text);
    line-height: 1.4;
}

.p2-tip-section strong {
    font-weight: 700;
}

/* ── UPLOADED LIST ──────────────────────────────────── */
/*.p2-uploaded-list-wrap {
    margin-bottom: 24px;
}
*/
.p2-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding: 10px 20px;
    display: none;
}

.p2-list-title {
    font-size: 16px;
    font-weight: 700;
    margin: 0;
}

.p2-reorder-toggle {
    background: none !important;
    border: none !important;
    color: var(--p2-primary) !important;
    font-size: 14px !important;
    font-weight: 700 !important;
    display: flex !important;
    align-items: center !important;
    gap: 6px !important;
    cursor: auto !important;
}

.p2-reorder-toggle .material-symbols-outlined {
    font-size: 20px !important;
}

.p2-uploaded-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.p2-list-item {
    background: #fff;
    border: 1px solid var(--p2-border-light);
    border-radius: 12px;
    padding: 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
}

.p2-item-thumb {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    overflow: hidden;
    background: #f1f5f9;
}

.p2-item-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.p2-item-info {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.p2-item-name {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px;
}

.p2-item-tag {
    font-size: 12px;
    font-weight: 700;
    padding: 6px 12px;
    border-radius: 8px;
}

.tag-question {
    background: var(--p2-primary-light);
    color: var(--p2-primary);
}

.tag-answer {
    background: var(--p2-success-bg);
    color: var(--p2-success-text);
}

.tag-both {
    background: #fff7ed;
    color: #9a3412;
}

.p2-item-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.p2-item-handle {
    cursor: grab;
    color: #cbd5e1;
}

.p2-item-delete {
    background: none !important;
    border: none !important;
    color: #1e293b !important;
    cursor: pointer;
    padding: 4px !important;
}

/* ── AI NOTICE ──────────────────────────────────────── */
.p2-ai-notice-premium {
    background: #f5f3ff;
    border-radius: 12px;
    padding: 16px 20px;
    display: flex;
    gap: 16px;
    align-items: center;
    margin-bottom: 32px;
}

.p2-notice-shield {
    color: var(--p2-primary);
}

.p2-ai-notice-premium p {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--p2-primary);
    line-height: 1.5;
}

/* ── SUBMIT BAR ─────────────────────────────────────── */
.p2-submit-bar-unified {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #fff;
    padding: 16px 20px 32px;
    max-width: 500px;
    margin: 0 auto;
    z-index: 90;
}

.p2-grade-btn-premium {
    width: 100% !important;
    background: var(--p2-primary) !important;
    color: #fff !important;
    border: none !important;
    border-radius: 12px !important;
    padding: 16px !important;
    font-size: 18px !important;
    font-weight: 700 !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
    gap: 10px;
    cursor: pointer !important;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
}

.p2-grade-btn-premium:disabled {
    background: #e2e8f0 !important;
    color: #94a3b8 !important;
    box-shadow: none;
    cursor: not-allowed !important;
}

.p2-usage-hint {
    text-align: center;
    font-size: 12px;
    color: var(--p2-text-muted);
    margin-top: 12px;
}

/* ── BOTTOM SHEETS ──────────────────────────────────── */
.p2-sheet {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    visibility: hidden;
    pointer-events: none;
}

.p2-sheet.active {
    visibility: visible;
    pointer-events: auto;
}

.p2-sheet-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    opacity: 0;
    transition: opacity 0.3s;
}

.p2-sheet.active .p2-sheet-backdrop {
    opacity: 1;
}

.p2-sheet-content {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: #fff;
    border-radius: 24px 24px 0 0;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    max-height: 85vh;
    overflow-y: auto;
    max-width: 500px;
    margin: 0 auto;
}

.p2-sheet.active .p2-sheet-content {
    transform: translateY(0);
}

.p2-sheet-handle {
    width: 36px;
    height: 4px;
    background: #e2e8f0;
    border-radius: 2px;
    margin: 12px auto;
}

.p2-sheet-header {
    padding: 4px 24px 16px;
    border-bottom: 1px solid var(--p2-border-light);
}

.p2-sheet-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 800;
}

.p2-sheet-header p {
    margin: 4px 0 0;
    font-size: 14px;
    color: var(--p2-text-muted);
}

.p2-sheet-body {
    padding: 16px 24px 32px;
}

/* ── SUBJECT SELECTOR ENHANCEMENTS ──────────────────── */
.p2-subject-search-wrap {
    margin-top: 16px;
    position: relative;
    display: flex;
    align-items: center;
}

.p2-subject-search-wrap .material-symbols-outlined {
    position: absolute;
    left: 12px;
    color: var(--p2-text-muted);
    font-size: 20px;
    pointer-events: none;
}

#p2-subject-search {
    width: 100%;
    padding: 12px 12px 12px 40px;
    border-radius: 12px;
    border: 1px solid var(--p2-border);
    background: var(--p2-bg);
    font-family: inherit;
    font-size: 15px;
    transition: all 0.2s ease;
}

#p2-subject-search:focus {
    outline: none;
    border-color: var(--p2-primary);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
    background: #fff;
}

.p2-subject-group-title {
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--p2-text-muted);
    margin: 24px 0 12px;
    padding-left: 4px;
}

.p2-subject-list-container {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.p2-subject-option {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.p2-subject-option:hover {
    background: var(--p2-primary-light);
    color: var(--p2-primary);
}

.p2-subject-option.selected {
    background: var(--p2-primary-light);
    color: var(--p2-primary);
    border-color: rgba(99, 102, 241, 0.2);
}

.p2-subject-icon {
    width: 36px;
    height: 36px;
    background: var(--p2-border-light);
    color: var(--p2-text-muted);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.p2-subject-option:hover .p2-subject-icon,
.p2-subject-option.selected .p2-subject-icon {
    background: var(--p2-primary);
    color: #fff;
}

.p2-subject-name {
    flex: 1;
    font-size: 15px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.p2-subject-option.selected .p2-subject-name {
    font-weight: 700;
}

.p2-check {
    font-size: 20px;
    color: var(--p2-primary);
    opacity: 0;
    transform: scale(0.8);
    transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.p2-subject-option.selected .p2-check {
    opacity: 1;
    transform: scale(1);
}

.p2-subject-separator {
    height: 1px;
    background: linear-gradient(to right, transparent, var(--p2-border), transparent);
    margin: 24px 0 8px;
}

.p2-tag-option {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    border: 1px solid var(--p2-border-light);
    border-radius: 16px;
    margin-bottom: 12px;
    cursor: pointer;
}

.p2-tag-option-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.p2-tag-option-icon.q {
    background: var(--p2-primary-light);
    color: var(--p2-primary);
}

.p2-tag-option-icon.a {
    background: var(--p2-success-bg);
    color: var(--p2-success-text);
}

.p2-tag-option-icon.b {
    background: #fff7ed;
    color: #9a3412;
}

.p2-tag-option-text strong {
    display: block;
    font-size: 15px;
}

.p2-tag-option-text span {
    font-size: 12px;
    color: var(--p2-text-muted);
}

.p2-sheet-cancel {
    width: 100%;
    background: var(--p2-border-light);
    border: none;
    border-radius: 12px;
    padding: 16px;
    font-weight: 700;
    margin-top: 12px;
    cursor: pointer;
}

/* ── PROGRESS SHEET ─────────────────────────────────── */
.p2-progress-stages {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.p2-stage {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 16px;
    color: var(--p2-text-muted);
    opacity: 0.5;
    transition: all 0.3s ease;
}

.p2-stage-dot {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid var(--p2-border);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.p2-stage.active {
    opacity: 1;
    color: var(--p2-text);
    font-weight: 600;
}

.p2-stage.active .p2-stage-dot {
    border-color: var(--p2-primary);
    border-width: 3px;
    border-top-color: transparent;
    animation: p2-spin 1s linear infinite;
}

.p2-stage.done {
    opacity: 1;
    color: var(--p2-text);
}

.p2-stage.done .p2-stage-dot {
    background: var(--p2-primary);
    border-color: var(--p2-primary);
}

.p2-stage.done .p2-stage-dot::after {
    content: '';
    width: 6px;
    height: 10px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
    margin-top: -2px;
}

@keyframes p2-spin {
    100% {
        transform: rotate(360deg);
    }
}

/* ── RESULTS VIEW ───────────────────────────────────── */
.p2-results-view {
    animation: fadeIn 0.4s ease forwards;
    padding-bottom: 24px;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.p2-results-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
}

.p2-results-back {
    /* background: none !important; */
    border: none;
    cursor: pointer;
    color: var(--p2-text) !important;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--p2-bg) !important;
}

.p2-results-header h2 {
    margin: 0;
    font-size: 20px;
    font-weight: 800;
}

.p2-res-card {
    background: #fff;
    border-radius: 16px;
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: var(--p2-shadow);
    border: 1px solid var(--p2-border-light);
}

.p2-res-card h3 {
    margin: 0 0 16px !important;
    font-size: 18px !important;
    font-weight: 700 !important;
    color: var(--p2-primary-dark);
}

/* Score Card */
.score-card {
    text-align: center;
    background: linear-gradient(135deg, #4338ca 0%, #6366f1 100%);
    color: #fff;
    border: none;
    margin-bottom: 0;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

.p2-score-circle-wrap {
    width: 160px;
    height: 160px;
    margin: 0 auto 20px;
    position: relative;
}

.p2-score-circle-wrap svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.p2-circle-bg {
    fill: none;
    stroke: rgba(255, 255, 255, 0.2);
    stroke-width: 2.5;
}

.p2-circle-fill {
    fill: none;
    stroke: #fff;
    stroke-width: 2.5;
    stroke-dasharray: 0 100;
    transition: stroke-dasharray 1s cubic-bezier(0.4, 0, 0.2, 1);
    stroke-linecap: round;
}

.p2-score-num {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 32px;
    font-weight: 800;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.p2-score-num span {
    font-size: 16px;
    font-weight: 600;
    opacity: 0.9;
}

.p2-score-meta {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin-bottom: 20px;
}

.p2-grade-badge {
    background: rgba(255, 255, 255, 0.2);
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 18px;
    font-weight: 800;
    backdrop-filter: blur(4px);
}

.p2-grade-label {
    font-size: 14px;
    opacity: 0.9;
}

/* Question Card - Attached to Score Card */
.p2-question-card.p2-question-toggle {
    padding: 16px 24px;
    border-top-left-radius: 0;
    border-top-right-radius: 0;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    cursor: pointer;
}

.p2-question-card.p2-question-toggle h3 {
    margin: 0;
    font-size: 14px;
    font-weight: 700;
    color: var(--p2-text-muted);
}

.p2-question-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.p2-chevron {
    transition: transform 0.3s ease;
    color: var(--p2-text-muted);
    font-size: 20px;
}

.p2-question-card.expanded .p2-chevron {
    transform: rotate(180deg);
}

.p2-question-content {
    margin-top: 4px;
    overflow: hidden;
}

.p2-question-text {
    display: block !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    max-height: 1.5em !important;
    font-size: 14px;
    line-height: 1.5;
    color: var(--p2-text-muted);
}

.p2-question-card.expanded .p2-question-text {
    white-space: pre-wrap !important;
    overflow: visible !important;
    max-height: none !important;
    text-overflow: clip !important;
    color: var(--p2-text);
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--p2-border-light);
}

/* Summary Card */
.p2-summary-card h3 {
    color: var(--p2-primary);
    font-size: 16px;
    margin-bottom: 12px;
}

.p2-examiner-summary-text {
    font-size: 15px;
    line-height: 1.6;
    color: var(--p2-text);
}

/* Breakdown Card */
.p2-breakdown-item {
    margin-bottom: 16px;
}

.p2-breakdown-item:last-child {
    margin-bottom: 0;
}

.p2-break-label {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 8px;
}

.p2-progress-bar {
    height: 8px;
    background: var(--p2-border-light);
    border-radius: 4px;
    overflow: hidden;
}

.p2-progress-fill {
    height: 100%;
    background: var(--p2-primary);
    border-radius: 4px;
    transition: width 1s ease-out;
}

/* Lists */
.p2-lost-list {
    margin: 0;
    padding-left: 20px;
    color: var(--p2-text);
    line-height: 1.6;
}

.p2-lost-list li {
    margin-bottom: 8px;
}

.p2-syllabus-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.p2-syllabus-item {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 12px 0;
    border-bottom: 1px solid var(--p2-border-light);
    font-size: 14px;
    gap: 16px;
}

.p2-syllabus-item:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.status-covered {
    color: var(--p2-success-text);
    font-weight: 700;
    background: var(--p2-success-bg);
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 12px;
}

.status-partial {
    color: #b45309;
    font-weight: 700;
    background: #fef3c7;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 12px;
}

.status-missing {
    color: #b91c1c;
    font-weight: 700;
    background: #fee2e2;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 12px;
}

/* AI Rewrite */
.ai-rewrite-card {
    background: #f8fafc;
}

.p2-rewrite-text {
    font-size: 15px;
    line-height: 1.7;
    color: var(--p2-text);
}

.p2-try-again-btn {
    width: 100%;
    background: var(--p2-primary-light);
    color: var(--p2-primary);
    border: none;
    border-radius: 12px;
    padding: 16px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    margin-top: 12px;
}