/* ========================================================================= */
/* === GLOBAL APPLICATION LAYOUT RULES === */
/* ========================================================================= */

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
}

body {
    display: flex;
    flex-direction: column;
}

.page-container {
    flex-grow: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

page {
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* ========================================================================= */
/* === ANALYSIS PAGE STYLES === */
/* ========================================================================= */

page[data-hash="analyse"] {
    /* Layout */
    .analysis-page {
        height: 100%;
        display: flex;
        flex-direction: column;
        flex-grow: 1;
        background: #f5f5f5;
    }

    .analysis-page .container-fluid {
        display: flex;
        flex-direction: column;
        flex-grow: 1;
    }

    .analysis-page .row.g-4 {
        flex-grow: 1;
    }

    .list-material {
        flex-grow: 1;
        overflow-y: auto;
        padding: 0;
    }

    /* Material Cards */
    .material-card {
        background: white;
        border-radius: 8px;
        border: 1px solid #e0e0e0;
        overflow: hidden;
    }

    .card-header-material {
        padding: 20px 24px;
        font-weight: 600;
        font-size: 16px;
        color: #202124;
        border-bottom: 1px solid #e8eaed;
    }

    .card-body-material {
        padding: 24px;
    }

    /* Action Bar */
    .action-bar {
        background: white;
        padding: 20px 24px;
        border-radius: 8px;
        border: 1px solid #e0e0e0;
        display: flex;
        justify-content: space-between;
        align-items: center;
        flex-wrap: wrap;
        gap: 1rem;
    }

    /* Buttons */
    .btn-fab {
        width: 56px;
        height: 56px;
        border-radius: 50%;
        background: #1a73e8;
        color: white;
        border: none;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 24px;
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .btn-fab:hover {
        background: #1557b0;
        transform: scale(1.05);
    }

    .btn-primary-material {
        width: 100%;
        padding: 14px 24px;
        border-radius: 4px;
        background: #1a73e8;
        color: white;
        border: none;
        font-weight: 500;
        font-size: 15px;
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .btn-primary-material:hover {
        background: #1557b0;
    }

    .icon-button {
        width: 40px;
        height: 40px;
        border-radius: 50%;
        background: transparent;
        border: none;
        color: #5f6368;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .icon-button:hover {
        background: #f1f3f4;
        color: #202124;
    }

    /* Upload Cards */
    .upload-card {
        border: 2px dashed #dadce0;
        border-radius: 8px;
        padding: 32px 16px;
        text-align: center;
        cursor: pointer;
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        background: #fafafa;
    }

    .upload-card:hover {
        border-color: #1a73e8;
        background: #f8f9fa;
    }

    .upload-card.secondary:hover {
        border-color: #34a853;
    }

    .upload-icon-container {
        width: 64px;
        height: 64px;
        border-radius: 50%;
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        display: flex;
        align-items: center;
        justify-content: center;
        margin: 0 auto 16px;
        font-size: 28px;
        color: white;
    }

    .upload-card.secondary .upload-icon-container {
        background: linear-gradient(135deg, #34a853 0%, #0f9d58 100%);
    }

    .upload-text {
        font-weight: 500;
        color: #202124;
        margin-bottom: 4px;
    }

    .upload-hint {
        font-size: 13px;
        color: #5f6368;
        margin: 0;
    }

    /* File Preview */
    .file-chip {
        display: inline-flex;
        align-items: center;
        padding: 8px 16px;
        background: #e8f0fe;
        border-radius: 16px;
        color: #1a73e8;
        font-size: 13px;
        font-weight: 500;
    }

    .file-chip i {
        margin-right: 8px;
    }

    .file-chip .remove-chip {
        margin-left: 12px;
        cursor: pointer;
        opacity: 0.7;
    }

    .file-chip .remove-chip:hover {
        opacity: 1;
    }

    /* Labels */
    .input-label {
        display: block;
        font-size: 14px;
        font-weight: 500;
        color: #202124;
        margin-bottom: 8px;
    }

    /* List Items */
    .list-item-material {
        display: flex;
        align-items: center;
        padding: 16px 24px;
        border-bottom: 1px solid #e8eaed;
        cursor: pointer;
        transition: background 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .list-item-material:last-child {
        border-bottom: none;
    }

    .list-item-material:hover {
        background: #f8f9fa;
    }

    .list-icon {
        width: 40px;
        height: 40px;
        border-radius: 50%;
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        display: flex;
        align-items: center;
        justify-content: center;
        color: white;
        margin-right: 16px;
        flex-shrink: 0;
    }

    .list-content {
        flex-grow: 1;
        min-width: 0;
    }

    .list-title {
        font-weight: 500;
        color: #202124;
        font-size: 14px;
        margin-bottom: 6px;
    }

    .list-meta {
        display: flex;
        align-items: center;
        gap: 12px;
        font-size: 13px;
    }

    /* Chips */
    .chip {
        padding: 4px 12px;
        background: #e8eaed;
        border-radius: 12px;
        font-size: 12px;
        font-weight: 500;
        color: #5f6368;
    }

    .status-chip {
        padding: 4px 12px;
        border-radius: 12px;
        font-size: 12px;
        font-weight: 500;
    }

    .status-chip.success {
        background: #e6f4ea;
        color: #1e8e3e;
    }

    .score-chip {
        padding: 4px 12px;
        background: #e8f0fe;
        color: #1a73e8;
        border-radius: 12px;
        font-weight: 600;
        font-size: 12px;
    }

    /* Header Stats */
    .header-stats {
        display: flex;
        gap: 1.5rem;
        align-items: center;
    }

    .header-stat-item {
        display: flex;
        align-items: center;
        gap: 0.75rem;
    }

    .header-stat-item .stat-value {
        font-size: 1.1rem;
        font-weight: 600;
        line-height: 1.1;
    }

    .header-stat-item .stat-label {
        font-size: 0.75rem;
        color: #6c757d;
    }

    .header-stat-item .stat-icon,
    .stat-icon {
        width: 36px;
        height: 36px;
        border-radius: 12px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 16px;
        color: white;
    }

    .stat-icon.purple {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    }

    .stat-icon.blue {
        background: linear-gradient(135deg, #1a73e8 0%, #1557b0 100%);
    }

    .stat-icon.green {
        background: linear-gradient(135deg, #34a853 0%, #0f9d58 100%);
    }

    /* Loading Overlay */
    .loading-overlay {
        position: fixed;
        inset: 0;
        background: radial-gradient(circle at center, rgba(0, 0, 0, .65), rgba(0, 0, 0, .85));
        backdrop-filter: blur(4px);
        display: none;
        z-index: 5000;
        align-items: center;
        justify-content: center;
        animation: fadeIn .25s ease;
    }

    .loading-modal {
        width: 340px;
        max-width: 90vw;
        background: #121418;
        color: #fff;
        border: 1px solid rgba(255, 255, 255, .08);
        border-radius: 18px;
        padding: 28px 26px 30px;
        box-shadow: 0 10px 40px -10px rgba(0, 0, 0, .6), 0 0 0 1px rgba(255, 255, 255, .03) inset;
    }

    .spinner {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
    }

    .spinner .ring {
        width: 26px;
        height: 26px;
        border-radius: 50%;
        border: 3px solid transparent;
        border-top-color: #4d9fff;
        animation: spin 1s linear infinite;
    }

    .spinner .ring:nth-child(2) {
        border-top-color: #9d6bff;
        animation-delay: .15s;
    }

    .spinner .ring:nth-child(3) {
        border-top-color: #44d58d;
        animation-delay: .3s;
    }

    .progress {
        height: 6px;
        background: #1f242c;
        border-radius: 3px;
        overflow: hidden;
    }

    .progress-bar-animated {
        animation: progressPulse 1.2s ease-in-out infinite;
    }

    .loading-tips {
        display: flex;
        flex-direction: column;
        gap: 4px;
    }

    .loading-tips .tip {
        opacity: .35;
        transition: opacity .4s, transform .4s;
        display: inline-flex;
        align-items: center;
        gap: 6px;
    }

    .loading-tips .tip.active {
        opacity: 1;
        transform: translateX(4px);
    }

    .loading-tips .tip::before {
        content: "";
        width: 8px;
        height: 8px;
        background: linear-gradient(135deg, #4d9fff, #9d6bff);
        border-radius: 50%;
        box-shadow: 0 0 0 3px rgba(255, 255, 255, .08);
    }

    /* ========================================================================= */
    /* === ENHANCED ANALYSIS VIEWER OVERLAY === */
    /* ========================================================================= */

    .analysis-viewer-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.75);
        backdrop-filter: blur(8px);
        display: flex;
        align-items: center;
        justify-content: center;
        z-index: 6000;
        padding: 20px;
        animation: fadeIn 0.3s ease;
    }

    .analysis-modal-container {
        width: 100%;
        max-width: 1200px;
        max-height: 90vh;
        background: white;
        border-radius: 12px;
        box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    .analysis-modal-header {
        padding: 24px 32px;
        border-bottom: 1px solid #e8eaed;
        display: flex;
        justify-content: space-between;
        align-items: center;
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: white;
    }

    .analysis-modal-header h5 {
        margin: 0;
        font-size: 20px;
        font-weight: 600;
    }

    .analysis-modal-header .btn {
        background: rgba(255, 255, 255, 0.2);
        border: 1px solid rgba(255, 255, 255, 0.3);
        color: white;
    }

    .analysis-modal-header .btn:hover {
        background: rgba(255, 255, 255, 0.3);
    }

    .analysis-modal-body {
        flex: 1;
        overflow-y: auto;
        padding: 32px;
    }

    /* Overall Summary Section */
    .summary-section {
        background: linear-gradient(135deg, #e8f0fe 0%, #f0e7ff 100%);
        border-radius: 12px;
        padding: 24px;
        margin-bottom: 32px;
    }

    .summary-grid {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
        gap: 20px;
        margin-bottom: 24px;
    }

    .summary-stat {
        text-align: center;
    }

    .summary-stat-value {
        font-size: 36px;
        font-weight: 700;
        color: #1a73e8;
        line-height: 1;
    }

    .summary-stat-label {
        font-size: 13px;
        color: #5f6368;
        margin-top: 8px;
        font-weight: 500;
    }

    .summary-lists {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 24px;
        margin-top: 20px;
    }

    .summary-list-title {
        font-weight: 600;
        color: #202124;
        margin-bottom: 12px;
        font-size: 15px;
    }

    .summary-list {
        list-style: none;
        padding: 0;
        margin: 0;
    }

    .summary-list li {
        padding: 10px 16px;
        background: white;
        border-radius: 6px;
        margin-bottom: 8px;
        font-size: 14px;
        color: #202124;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    }

    /* Criterion Card */
    .criterion-card {
        background: white;
        border: 1px solid #e0e0e0;
        border-radius: 12px;
        padding: 24px;
        margin-bottom: 24px;
        transition: box-shadow 0.3s ease;
    }

    .criterion-card:hover {
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    }

    .criterion-header {
        display: flex;
        justify-content: space-between;
        align-items: start;
        margin-bottom: 16px;
    }

    .criterion-title {
        font-size: 18px;
        font-weight: 600;
        color: #202124;
        margin-bottom: 8px;
    }

    .criterion-badges {
        display: flex;
        gap: 8px;
        flex-shrink: 0;
    }

    .performance-badge {
        padding: 6px 14px;
        border-radius: 16px;
        font-size: 12px;
        font-weight: 600;
        text-transform: uppercase;
    }

    .performance-badge.excellent {
        background: #e6f4ea;
        color: #1e8e3e;
    }

    .performance-badge.good {
        background: #e8f0fe;
        color: #1a73e8;
    }

    .performance-badge.satisfactory {
        background: #fef7e0;
        color: #f9ab00;
    }

    .performance-badge.needs-improvement {
        background: #fce8e6;
        color: #d93025;
    }

    .marks-badge {
        padding: 6px 14px;
        border-radius: 16px;
        font-size: 13px;
        font-weight: 600;
        background: #f1f3f4;
        color: #202124;
    }

    .criterion-justification {
        padding: 16px;
        background: #f8f9fa;
        border-left: 4px solid #1a73e8;
        border-radius: 4px;
        margin-bottom: 20px;
        font-size: 14px;
        line-height: 1.6;
        color: #202124;
    }

    /* Criterion Points */
    .criterion-points {
        margin-bottom: 20px;
    }

    .criterion-point {
        padding: 16px;
        background: #fafafa;
        border-radius: 8px;
        margin-bottom: 12px;
        border-left: 4px solid #e0e0e0;
    }

    .criterion-point.met {
        border-left-color: #34a853;
        background: #f0f9f4;
    }

    .criterion-point.not-met {
        border-left-color: #ea4335;
        background: #fef3f2;
    }

    .point-header {
        display: flex;
        justify-content: space-between;
        align-items: start;
        margin-bottom: 12px;
    }

    .point-text {
        font-weight: 600;
        color: #202124;
        font-size: 14px;
        flex: 1;
    }

    .point-status {
        display: flex;
        align-items: center;
        gap: 8px;
        flex-shrink: 0;
    }

    .status-icon {
        width: 24px;
        height: 24px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 12px;
    }

    .status-icon.met {
        background: #34a853;
        color: white;
    }

    .status-icon.not-met {
        background: #ea4335;
        color: white;
    }

    .evidence-level {
        padding: 4px 10px;
        border-radius: 12px;
        font-size: 11px;
        font-weight: 600;
        text-transform: uppercase;
    }

    .evidence-level.comprehensive {
        background: #e6f4ea;
        color: #1e8e3e;
    }

    .evidence-level.adequate {
        background: #e8f0fe;
        color: #1a73e8;
    }

    .evidence-level.partial {
        background: #fef7e0;
        color: #f9ab00;
    }

    .evidence-level.minimal {
        background: #fce8e6;
        color: #d93025;
    }

    .evidence-level.absent {
        background: #f1f3f4;
        color: #5f6368;
    }

    .point-details {
        font-size: 13px;
        color: #5f6368;
        line-height: 1.6;
    }

    .point-details strong {
        color: #202124;
        display: block;
        margin-top: 8px;
        margin-bottom: 4px;
    }

    .evidence-box {
        margin-top: 12px;
        padding: 12px;
        background: white;
        border-radius: 6px;
        border: 1px solid #e0e0e0;
    }

    .evidence-location {
        font-size: 12px;
        color: #5f6368;
        margin-bottom: 6px;
    }

    .evidence-excerpt {
        font-size: 13px;
        color: #202124;
        font-style: italic;
        line-height: 1.5;
    }

    /* Strengths & Weaknesses */
    .strengths-weaknesses {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 16px;
        margin-top: 16px;
    }

    .strength-weakness-column h6 {
        font-size: 14px;
        font-weight: 600;
        color: #202124;
        margin-bottom: 12px;
        display: flex;
        align-items: center;
        gap: 8px;
    }

    .strength-weakness-column h6 i {
        font-size: 16px;
    }

    .strength-weakness-column.strengths h6 {
        color: #1e8e3e;
    }

    .strength-weakness-column.weaknesses h6 {
        color: #d93025;
    }

    .strength-weakness-list {
        list-style: none;
        padding: 0;
        margin: 0;
    }

    .strength-weakness-list li {
        padding: 10px 12px;
        background: white;
        border-radius: 6px;
        margin-bottom: 8px;
        font-size: 13px;
        border-left: 3px solid;
    }

    .strengths .strength-weakness-list li {
        border-left-color: #34a853;
        background: #f0f9f4;
    }

    .weaknesses .strength-weakness-list li {
        border-left-color: #ea4335;
        background: #fef3f2;
    }

    /* Feedback Section */
    .feedback-section {
        margin-top: 32px;
    }

    .section-title {
        font-size: 20px;
        font-weight: 600;
        color: #202124;
        margin-bottom: 20px;
        padding-bottom: 12px;
        border-bottom: 2px solid #e0e0e0;
    }

    .feedback-item {
        background: white;
        border: 1px solid #e0e0e0;
        border-radius: 8px;
        padding: 20px;
        margin-bottom: 16px;
    }

    .feedback-header {
        display: flex;
        gap: 8px;
        margin-bottom: 12px;
    }

    .priority-badge {
        padding: 4px 12px;
        border-radius: 12px;
        font-size: 11px;
        font-weight: 600;
        text-transform: uppercase;
    }

    .priority-badge.high {
        background: #fce8e6;
        color: #d93025;
    }

    .priority-badge.medium {
        background: #fef7e0;
        color: #f9ab00;
    }

    .priority-badge.low {
        background: #e8f0fe;
        color: #1a73e8;
    }

    .criterion-badge {
        padding: 4px 12px;
        border-radius: 12px;
        font-size: 11px;
        font-weight: 600;
        background: #f1f3f4;
        color: #5f6368;
    }

    .feedback-content {
        font-size: 14px;
        line-height: 1.6;
    }

    .feedback-issue {
        font-weight: 600;
        color: #202124;
        margin-bottom: 8px;
    }

    .feedback-impact {
        color: #5f6368;
        margin-bottom: 12px;
    }

    .feedback-advice {
        padding: 12px;
        background: #e8f0fe;
        border-left: 4px solid #1a73e8;
        border-radius: 4px;
        margin-bottom: 12px;
    }

    .feedback-example {
        padding: 12px;
        background: #fafafa;
        border-radius: 4px;
        font-style: italic;
        font-size: 13px;
        color: #5f6368;
    }

    /* Objectives Section */
    .objectives-section {
        margin-top: 32px;
    }

    .objective-item {
        background: white;
        border: 1px solid #e0e0e0;
        border-radius: 8px;
        padding: 16px;
        margin-bottom: 12px;
        display: flex;
        gap: 16px;
    }

    .objective-status {
        width: 32px;
        height: 32px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
        font-size: 16px;
    }

    .objective-status.met {
        background: #e6f4ea;
        color: #1e8e3e;
    }

    .objective-status.not-met {
        background: #fce8e6;
        color: #d93025;
    }

    .objective-content {
        flex: 1;
    }

    .objective-text {
        font-weight: 600;
        color: #202124;
        margin-bottom: 8px;
    }

    .objective-explanation {
        font-size: 14px;
        color: #5f6368;
        line-height: 1.6;
    }

    /* Animations */
    @keyframes fadeIn {
        from {
            opacity: 0;
            transform: scale(0.95);
        }
        to {
            opacity: 1;
            transform: scale(1);
        }
    }

    @keyframes spin {
        to {
            transform: rotate(360deg);
        }
    }

    @keyframes progressPulse {
        0%, 100% {
            background: linear-gradient(90deg, #4d9fff 0%, #9d6bff 33%, #44d58d 66%, #4d9fff 100%);
            filter: brightness(.9);
        }
        50% {
            filter: brightness(1.15);
        }
    }

    /* Responsive */
    @media (max-width: 992px) {
        .action-bar {
            flex-direction: column;
            align-items: flex-start;
        }

        .header-stats {
            width: 100%;
            justify-content: space-between;
            padding-top: 1rem;
            border-top: 1px solid #eee;
            margin-top: 1rem;
        }

        .summary-lists,
        .strengths-weaknesses {
            grid-template-columns: 1fr;
        }
    }

    @media (max-width: 768px) {
        .analysis-modal-body {
            padding: 20px;
        }

        .summary-grid {
            grid-template-columns: 1fr;
        }

        .criterion-header {
            flex-direction: column;
        }

        .criterion-badges {
            margin-top: 12px;
        }
    }

    @media (max-width: 576px) {
        .header-stats {
            flex-direction: column;
            align-items: flex-start;
            gap: 1rem;
        }

        .analysis-viewer-overlay {
            padding: 10px;
        }

        .analysis-modal-container {
            max-height: 95vh;
        }

        .analysis-modal-header {
            padding: 16px 20px;
        }
    }

    @media (max-width: 480px) {
        .loading-modal {
            width: 92vw;
            padding: 24px 20px;
        }

        .spinner .ring {
            width: 22px;
            height: 22px;
        }
    }
}