/* ============================================================
   ux.css – Phase 7.2 UX Polish
   Loaded after mobile.css. Covers:
     - Toast notifications (animated)
     - Custom confirm dialog
     - Button loading states
     - Form validation feedback
     - Page progress bar
     - Tooltips
     - Unsaved changes indicator
     - Skeleton loaders
     - Better empty states
     - Helpful hints for non-technical users
   ============================================================ */

/* ═══════════════════════════════════════════════════════════
   PAGE PROGRESS BAR – thin bar at top during navigation
═══════════════════════════════════════════════════════════ */
#pageProgress {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    width: 0;
    background: linear-gradient(90deg, #2563eb, #7c3aed);
    z-index: 9999;
    transition: width 0.2s ease, opacity 0.4s ease;
    border-radius: 0 2px 2px 0;
    pointer-events: none;
}

#pageProgress.done {
    width: 100% !important;
    opacity: 0;
}

/* ═══════════════════════════════════════════════════════════
   TOAST NOTIFICATIONS – slide in from top-right
═══════════════════════════════════════════════════════════ */
#toastContainer {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
    max-width: 360px;
    width: calc(100vw - 32px);
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 16px;
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 4px 20px rgba(0,0,0,0.14), 0 1px 4px rgba(0,0,0,0.08);
    pointer-events: all;
    animation: toastIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) both;
    position: relative;
    overflow: hidden;
}

.toast.toast--out {
    animation: toastOut 0.25s ease forwards;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(60px) scale(0.96); }
    to   { opacity: 1; transform: translateX(0)   scale(1);     }
}

@keyframes toastOut {
    from { opacity: 1; transform: translateX(0)   scale(1);     max-height: 100px; }
    to   { opacity: 0; transform: translateX(40px) scale(0.95); max-height: 0;     }
}

/* Coloured left border */
.toast::before {
    content: '';
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 4px;
    border-radius: 10px 0 0 10px;
}

.toast--success::before { background: #16a34a; }
.toast--error::before   { background: #dc2626; }
.toast--warning::before { background: #d97706; }
.toast--info::before    { background: #2563eb; }

.toast-icon {
    width: 20px; height: 20px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 800;
    flex-shrink: 0;
    margin-top: 1px;
}

.toast--success .toast-icon { background: #dcfce7; color: #16a34a; }
.toast--error   .toast-icon { background: #fee2e2; color: #dc2626; }
.toast--warning .toast-icon { background: #fef9c3; color: #d97706; }
.toast--info    .toast-icon { background: #dbeafe; color: #2563eb; }

.toast-body { flex: 1; min-width: 0; }
.toast-title {
    font-size: 13px; font-weight: 700;
    color: #111827;
    margin-bottom: 2px;
    line-height: 1.3;
}
.toast-message {
    font-size: 12px;
    color: #6b7280;
    line-height: 1.4;
}

.toast-close {
    background: none; border: none; cursor: pointer;
    color: #9ca3af; font-size: 16px; line-height: 1;
    padding: 0; flex-shrink: 0;
    transition: color 0.15s;
}
.toast-close:hover { color: #374151; }

/* Progress bar inside toast */
.toast-progress {
    position: absolute;
    bottom: 0; left: 0;
    height: 3px;
    border-radius: 0 0 10px 10px;
    animation: toastProgress linear forwards;
}
.toast--success .toast-progress { background: #16a34a; }
.toast--error   .toast-progress { background: #dc2626; }
.toast--warning .toast-progress { background: #d97706; }
.toast--info    .toast-progress { background: #2563eb; }

@keyframes toastProgress {
    from { width: 100%; }
    to   { width: 0%; }
}

/* ═══════════════════════════════════════════════════════════
   CUSTOM CONFIRM DIALOG
═══════════════════════════════════════════════════════════ */
#confirmDialog {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 10001;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.45);
    backdrop-filter: blur(2px);
    padding: 16px;
}

#confirmDialog.open {
    display: flex;
}

.confirm-box {
    background: #fff;
    border-radius: 16px;
    padding: 28px 28px 22px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    animation: confirmIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes confirmIn {
    from { opacity: 0; transform: scale(0.92) translateY(12px); }
    to   { opacity: 1; transform: scale(1)    translateY(0);    }
}

.confirm-icon {
    width: 48px; height: 48px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px;
    margin-bottom: 16px;
}

.confirm-icon--danger  { background: #fee2e2; }
.confirm-icon--warning { background: #fef9c3; }
.confirm-icon--info    { background: #dbeafe; }

.confirm-title {
    font-size: 16px; font-weight: 700;
    color: #111827;
    margin-bottom: 8px;
}

.confirm-message {
    font-size: 13px;
    color: #6b7280;
    line-height: 1.5;
    margin-bottom: 22px;
}

.confirm-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.confirm-actions .btn-confirm-cancel {
    padding: 9px 18px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #fff;
    color: #374151;
    font-size: 13px; font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}
.confirm-actions .btn-confirm-cancel:hover { background: #f9fafb; }

.confirm-actions .btn-confirm-ok {
    padding: 9px 18px;
    border: none;
    border-radius: 8px;
    font-size: 13px; font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s;
}
.confirm-actions .btn-confirm-ok:hover { opacity: 0.9; }
.confirm-actions .btn-confirm-ok.danger  { background: #dc2626; color: #fff; }
.confirm-actions .btn-confirm-ok.warning { background: #d97706; color: #fff; }
.confirm-actions .btn-confirm-ok.primary { background: #1a1060; color: #fff; }

/* ═══════════════════════════════════════════════════════════
   BUTTON LOADING STATES
═══════════════════════════════════════════════════════════ */
.btn-loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
    opacity: 0.8;
}

.btn-loading::after {
    content: '';
    position: absolute;
    width: 14px; height: 14px;
    top: 50%; left: 50%;
    margin-top: -7px; margin-left: -7px;
    border: 2px solid rgba(255,255,255,0.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: btnSpin 0.6s linear infinite;
}

.btn-loading.btn-secondary::after {
    border-color: rgba(107,114,128,0.3);
    border-top-color: #374151;
}

@keyframes btnSpin {
    to { transform: rotate(360deg); }
}

/* ═══════════════════════════════════════════════════════════
   FORM VALIDATION FEEDBACK
═══════════════════════════════════════════════════════════ */
.form-input.is-invalid,
.form-select.is-invalid {
    border-color: #dc2626 !important;
    background: #fff8f8;
}

.form-input.is-valid,
.form-select.is-valid {
    border-color: #16a34a !important;
    background: #f0fdf4;
}

.form-error-msg {
    font-size: 11px;
    color: #dc2626;
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
    animation: fadeIn 0.2s ease;
}

.form-char-count {
    font-size: 11px;
    color: #9ca3af;
    text-align: right;
    margin-top: 3px;
    transition: color 0.2s;
}

.form-char-count.near-limit  { color: #d97706; }
.form-char-count.over-limit  { color: #dc2626; font-weight: 700; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0);    }
}

/* ═══════════════════════════════════════════════════════════
   UNSAVED CHANGES INDICATOR
═══════════════════════════════════════════════════════════ */
#unsavedBanner {
    display: none;
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #1a1060;
    color: #fff;
    padding: 10px 20px;
    border-radius: 30px;
    font-size: 13px;
    font-weight: 600;
    z-index: 9000;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
    gap: 14px;
    align-items: center;
    animation: slideUp 0.3s ease both;
    white-space: nowrap;
}

#unsavedBanner.visible {
    display: flex;
}

#unsavedBanner button {
    background: rgba(255,255,255,0.2);
    border: 1px solid rgba(255,255,255,0.3);
    color: #fff;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

#unsavedBanner button:hover { background: rgba(255,255,255,0.3); }

@keyframes slideUp {
    from { opacity: 0; transform: translateX(-50%) translateY(20px); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0);    }
}

/* ═══════════════════════════════════════════════════════════
   TOOLTIPS
═══════════════════════════════════════════════════════════ */
[data-tip] {
    position: relative;
    cursor: help;
}

[data-tip]::after {
    content: attr(data-tip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: #1f2937;
    color: #fff;
    font-size: 11px;
    font-weight: 500;
    line-height: 1.4;
    padding: 6px 10px;
    border-radius: 6px;
    white-space: nowrap;
    max-width: 220px;
    white-space: normal;
    text-align: center;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s, transform 0.15s;
    transform: translateX(-50%) translateY(4px);
    z-index: 5000;
}

[data-tip]::before {
    content: '';
    position: absolute;
    bottom: calc(100% + 2px);
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: #1f2937;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 5000;
}

[data-tip]:hover::after,
[data-tip]:hover::before {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ═══════════════════════════════════════════════════════════
   SKELETON LOADERS – for async content
═══════════════════════════════════════════════════════════ */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.4s infinite;
    border-radius: 6px;
}

@keyframes shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.skeleton-text  { height: 14px; margin-bottom: 8px; }
.skeleton-title { height: 22px; width: 60%; margin-bottom: 12px; }
.skeleton-row   { height: 48px; margin-bottom: 4px; border-radius: 0; }
.skeleton-card  { height: 90px; border-radius: var(--radius-lg); margin-bottom: 12px; }

/* ═══════════════════════════════════════════════════════════
   IMPROVED EMPTY STATES
═══════════════════════════════════════════════════════════ */
.empty-state {
    text-align: center;
    padding: 56px 24px;
    color: var(--gray-400);
}

.empty-state-icon {
    width: 72px; height: 72px;
    border-radius: 50%;
    background: var(--gray-100);
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 20px;
    color: var(--gray-400);
}

.empty-state-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--gray-600);
    margin-bottom: 8px;
}

.empty-state-desc {
    font-size: 13px;
    color: var(--gray-400);
    max-width: 320px;
    margin: 0 auto 20px;
    line-height: 1.5;
}

.empty-state-action {
    display: inline-block;
}

/* ═══════════════════════════════════════════════════════════
   HINT BOXES – inline help for non-technical users
═══════════════════════════════════════════════════════════ */
.hint-box {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-left: 4px solid #2563eb;
    border-radius: 8px;
    padding: 12px 16px;
    font-size: 12px;
    color: #1e40af;
    line-height: 1.5;
    margin-bottom: 16px;
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.hint-box--warning {
    background: #fffbeb;
    border-color: #fde68a;
    border-left-color: #f59e0b;
    color: #92400e;
}

.hint-box--success {
    background: #f0fdf4;
    border-color: #bbf7d0;
    border-left-color: #16a34a;
    color: #166534;
}

.hint-box-icon { font-size: 16px; flex-shrink: 0; margin-top: 1px; }
.hint-box-text { flex: 1; }
.hint-box strong { font-weight: 700; }

/* ═══════════════════════════════════════════════════════════
   STEP INDICATOR – for multi-step workflows
   e.g. Open result set → Enter scores → Review → Publish
═══════════════════════════════════════════════════════════ */
.step-track {
    display: flex;
    align-items: center;
    gap: 0;
    margin-bottom: 28px;
    overflow-x: auto;
    padding-bottom: 2px;
}

.step-item {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.step-num {
    width: 28px; height: 28px;
    border-radius: 50%;
    border: 2px solid var(--gray-300);
    background: var(--white);
    color: var(--gray-400);
    font-size: 12px; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s;
}

.step-label {
    font-size: 12px;
    color: var(--gray-400);
    font-weight: 500;
    white-space: nowrap;
}

.step-line {
    width: 32px; height: 2px;
    background: var(--gray-200);
    flex-shrink: 0;
    margin: 0 4px;
}

/* Active step */
.step-item.active .step-num {
    background: var(--purple-deep);
    border-color: var(--purple-deep);
    color: #fff;
}
.step-item.active .step-label {
    color: var(--purple-deep);
    font-weight: 700;
}

/* Completed step */
.step-item.done .step-num {
    background: #16a34a;
    border-color: #16a34a;
    color: #fff;
}
.step-item.done .step-num::before { content: '✓'; }
.step-item.done .step-label { color: #16a34a; }
.step-item.done + .step-line { background: #16a34a; }

/* ═══════════════════════════════════════════════════════════
   STATUS BADGE IMPROVEMENTS
═══════════════════════════════════════════════════════════ */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    font-weight: 600;
    padding: 3px 9px;
    border-radius: 20px;
    letter-spacing: 0.2px;
    white-space: nowrap;
}

.badge--green  { background: #dcfce7; color: #166534; }
.badge--red    { background: #fee2e2; color: #991b1b; }
.badge--amber  { background: #fef9c3; color: #854d0e; }
.badge--blue   { background: #dbeafe; color: #1e40af; }
.badge--purple { background: #ede9fe; color: #6d28d9; }
.badge--gray   { background: #f3f4f6; color: #374151; }

.badge::before {
    content: '';
    width: 6px; height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}

.badge--green::before  { background: #16a34a; }
.badge--red::before    { background: #dc2626; }
.badge--amber::before  { background: #d97706; }
.badge--blue::before   { background: #2563eb; }
.badge--purple::before { background: #7c3aed; }
.badge--gray::before   { background: #9ca3af; }

/* ═══════════════════════════════════════════════════════════
   SMOOTH TRANSITIONS – page feel
═══════════════════════════════════════════════════════════ */
.section-card,
.summary-card,
.student-result-card,
.analytics-card {
    transition: box-shadow 0.2s ease, transform 0.15s ease;
}

.btn-primary,
.btn-secondary,
.btn-danger,
.btn-xs {
    transition: background 0.15s ease, box-shadow 0.15s ease,
                transform 0.1s ease, opacity 0.15s ease;
}

.btn-primary:active,
.btn-secondary:active,
.btn-danger:active {
    transform: scale(0.98);
}

.nav-item {
    transition: background 0.15s ease, color 0.15s ease;
}

/* ═══════════════════════════════════════════════════════════
   FOCUS STATES – keyboard accessibility
═══════════════════════════════════════════════════════════ */
.btn-primary:focus-visible,
.btn-secondary:focus-visible,
.btn-danger:focus-visible,
.form-input:focus-visible,
.form-select:focus-visible {
    outline: 3px solid rgba(37, 99, 235, 0.5);
    outline-offset: 2px;
}

/* ═══════════════════════════════════════════════════════════
   RESULT SET STATUS – visual pipeline on manage page
═══════════════════════════════════════════════════════════ */
.rs-pipeline {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    font-weight: 600;
    margin-bottom: 16px;
    padding: 10px 14px;
    background: var(--gray-50);
    border-radius: 8px;
    border: 1px solid var(--gray-200);
    flex-wrap: wrap;
}

.rs-pipeline-step {
    display: flex;
    align-items: center;
    gap: 4px;
    color: var(--gray-400);
    padding: 3px 8px;
    border-radius: 20px;
}

.rs-pipeline-step.done {
    color: #166534;
    background: #dcfce7;
}

.rs-pipeline-step.active {
    color: #1e40af;
    background: #dbeafe;
}

.rs-pipeline-arrow {
    color: var(--gray-300);
    font-size: 10px;
}