/*
 * AISA Training framework — UI styling.
 *
 * Loaded alongside auth/gate.js on PD module pages that opt into the
 * step-by-step training experience. Designed to overlay any module's
 * existing styling rather than replace it.
 */

/* ------------ Layout ------------ */
.aisa-train-layout {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    gap: 2rem;
    align-items: start;
}
/* When training manages the page, widen the module's own (narrow,
 * centered) content wrapper so the chapter sidebar sits near the
 * page's left gutter instead of floating mid-page with dead space
 * on the left. 1536px matches the nav's container width, so the
 * sidebar lines up with the logo. */
.aisa-train-managed .aisa-train-widthhost {
    max-width: 1536px;
}
@media (max-width: 900px) {
    .aisa-train-layout {
        grid-template-columns: 1fr;
        gap: 0;
    }
}

/* ------------ Top progress bar ------------ */
.aisa-train-topbar {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid #e2e8f0;
    border-radius: 1rem;
    padding: 1rem 1.25rem;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}
.aisa-train-topbar-label {
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #64748b;
    flex-shrink: 0;
}
.aisa-train-topbar-bar {
    flex: 1;
    height: 8px;
    background: #e2e8f0;
    border-radius: 9999px;
    overflow: hidden;
    min-width: 120px;
}
.aisa-train-topbar-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #10b981, #06b6d4);
    border-radius: 9999px;
    width: 0%;
    transition: width 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}
.aisa-train-topbar-text {
    font-size: 0.875rem;
    font-weight: 700;
    color: #0f172a;
    flex-shrink: 0;
    min-width: 4.5rem;
    text-align: right;
}

/* ------------ Sidebar ------------ */
.aisa-train-sidebar {
    position: sticky;
    top: 1rem;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 1rem;
    padding: 1.25rem 0.75rem;
    box-shadow: 0 4px 12px -2px rgba(15, 23, 42, 0.06),
                0 1px 3px rgba(15, 23, 42, 0.04);
}
.aisa-train-sidebar-heading {
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: #64748b;
    padding: 0 0.75rem 0.75rem;
    margin-bottom: 0.5rem;
    border-bottom: 1px solid #f1f5f9;
}
.aisa-train-chapter-list {
    list-style: none;
    padding: 0;
    margin: 0;
}
.aisa-train-chapter-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 0.75rem;
    border-radius: 0.625rem;
    cursor: pointer;
    margin-bottom: 2px;
    position: relative;
    transition: background-color 0.15s;
}
.aisa-train-chapter-item.locked {
    cursor: not-allowed;
    opacity: 0.6;
}
.aisa-train-chapter-item:hover:not(.locked):not(.current) {
    background: #f8fafc;
}
.aisa-train-chapter-item.current {
    background: #f1f5f9;
}
/* Left accent strip on the current chapter so its position in the
 * list is unmissable even at a glance. */
.aisa-train-chapter-item.current::before {
    content: '';
    position: absolute;
    left: -0.75rem;
    top: 0.4rem;
    bottom: 0.4rem;
    width: 3px;
    background: #0f172a;
    border-radius: 0 3px 3px 0;
}

/* The marker swaps a numbered circle for a green check the moment
 * the chapter is marked done — that's what makes Next feel like
 * "ticking off" the current item. */
.aisa-train-chapter-marker {
    position: relative;
    width: 1.5rem;
    height: 1.5rem;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.aisa-train-chapter-num {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: #ffffff;
    border: 1.5px solid #cbd5e1;
    color: #64748b;
    font-size: 0.75rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, border-color 0.2s, color 0.2s;
}
.aisa-train-chapter-item.current .aisa-train-chapter-num {
    background: #0f172a;
    color: #ffffff;
    border-color: #0f172a;
}
.aisa-train-chapter-check {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    color: #ffffff;
    padding: 4px;
    border-radius: 50%;
    background: #10b981;
    opacity: 0;
    transform: scale(0.4);
    transition: opacity 0.2s ease, transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    pointer-events: none;
}
.aisa-train-chapter-item.done .aisa-train-chapter-check {
    opacity: 1;
    transform: scale(1);
    animation: aisa-train-check-pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.aisa-train-chapter-item.done .aisa-train-chapter-num {
    opacity: 0;
}
@keyframes aisa-train-check-pop {
    0%   { transform: scale(0.3); opacity: 0; }
    60%  { transform: scale(1.15); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

.aisa-train-chapter-text {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}
.aisa-train-chapter-kicker {
    font-size: 0.65rem;
    font-weight: 800;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: #94a3b8;
    line-height: 1;
}
.aisa-train-chapter-item.current .aisa-train-chapter-kicker {
    color: #475569;
}
.aisa-train-chapter-item.done .aisa-train-chapter-kicker {
    color: #10b981;
}
.aisa-train-chapter-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: #0f172a;
    line-height: 1.3;
}
.aisa-train-chapter-item.done .aisa-train-chapter-title {
    color: #475569;
    text-decoration: line-through;
    text-decoration-color: #cbd5e1;
    text-decoration-thickness: 1px;
}

@media (max-width: 900px) {
    .aisa-train-sidebar {
        position: static;
        margin-bottom: 1rem;
    }
}

/* ------------ Chapter visibility ------------ */
.aisa-train-managed [data-chapter] {
    display: none;
}
.aisa-train-managed [data-chapter].aisa-current {
    display: block;
    animation: aisa-train-fade-in 0.4s ease-out;
}
@keyframes aisa-train-fade-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ------------ Bottom navigation (floating sticky action bar) ------------ */
/* The bar sticks to the bottom of the viewport while the chapter
 * scrolls, so the primary "Next" action is always in view and never
 * has to be hunted for. It settles naturally above the completion
 * banner when you reach the end. */
.aisa-train-nav {
    position: sticky;
    bottom: 1rem;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 2.5rem;
    padding: 0.7rem 0.8rem;
    background: rgba(255, 255, 255, 0.92);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    border: 1px solid #e2e8f0;
    border-radius: 1rem;
    box-shadow: 0 14px 32px -12px rgba(15, 23, 42, 0.30),
                0 2px 6px rgba(15, 23, 42, 0.05);
}
/* Reserve space so the floating bar never hides the last lines of a
 * chapter when it settles. */
.aisa-train-managed .aisa-train-main {
    padding-bottom: 1rem;
}

.aisa-train-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.7rem 1.25rem;
    font-size: 0.95rem;
    font-weight: 700;
    border-radius: 0.75rem;
    border: 1px solid transparent;
    background: transparent;
    color: #475569;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}
/* Previous = quiet, secondary. */
.aisa-train-btn-prev:hover:not(:disabled) {
    background: #f1f5f9;
    color: #0f172a;
}
/* Next = the unmistakable primary action: bigger, brand gradient. */
.aisa-train-btn.primary {
    margin-left: auto;
    padding: 0.8rem 1.6rem;
    font-size: 1rem;
    font-weight: 800;
    color: #ffffff;
    background: linear-gradient(135deg, #059669, #0891b2);
    box-shadow: 0 8px 18px -6px rgba(8, 145, 178, 0.55);
}
.aisa-train-btn.primary:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 12px 24px -6px rgba(8, 145, 178, 0.6);
}
.aisa-train-btn.primary:active:not(:disabled) {
    transform: translateY(0);
}
.aisa-train-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}
.aisa-train-btn.primary:disabled {
    background: #cbd5e1;
    color: #ffffff;
}

/* Center locator / gate reason. */
.aisa-train-nav-center {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    line-height: 1.2;
}
.aisa-train-nav-counter {
    font-size: 0.8rem;
    font-weight: 700;
    color: #64748b;
    letter-spacing: 0.01em;
}
.aisa-train-nav-hint {
    font-size: 0.8rem;
    font-weight: 600;
    color: #b45309;
}
/* When gated, hide the plain counter and show the amber reason. */
.aisa-train-nav.is-gated .aisa-train-nav-counter { display: none; }
.aisa-train-nav:not(.is-gated) .aisa-train-nav-hint { display: none; }

/* One-shot attention pulse when Next becomes available. */
@keyframes aisa-train-next-pulse {
    0%   { box-shadow: 0 8px 18px -6px rgba(8, 145, 178, 0.55), 0 0 0 0 rgba(8, 145, 178, 0.5); }
    70%  { box-shadow: 0 8px 18px -6px rgba(8, 145, 178, 0.55), 0 0 0 12px rgba(8, 145, 178, 0); }
    100% { box-shadow: 0 8px 18px -6px rgba(8, 145, 178, 0.55), 0 0 0 0 rgba(8, 145, 178, 0); }
}
.aisa-train-btn.primary.aisa-train-pulse {
    animation: aisa-train-next-pulse 0.9s ease-out 2;
}
@media (prefers-reduced-motion: reduce) {
    .aisa-train-btn.primary.aisa-train-pulse { animation: none; }
}

/* On narrow screens, drop the "Previous" word to keep the bar tidy. */
@media (max-width: 560px) {
    .aisa-train-btn-prev-label { display: none; }
    .aisa-train-btn.primary { padding: 0.8rem 1.25rem; }
}

/* ------------ Quiz styling ------------ */
.aisa-quiz {
    background: #ffffff;
    border: 2px solid #fbbf24;
    border-radius: 1rem;
    padding: 1.5rem;
    margin: 2rem 0 1rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}
.aisa-quiz-tag {
    display: inline-block;
    background: #fef3c7;
    color: #92400e;
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    padding: 0.25rem 0.625rem;
    border-radius: 9999px;
    margin-bottom: 0.75rem;
}
.aisa-quiz-prompt {
    font-size: 1.0625rem;
    font-weight: 700;
    color: #0f172a;
    line-height: 1.4;
    margin: 0 0 1rem;
}
.aisa-quiz-options {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.aisa-quiz-option {
    text-align: left;
    padding: 0.875rem 1rem;
    border-radius: 0.625rem;
    border: 1.5px solid #e2e8f0;
    background: #ffffff;
    color: #0f172a;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
    line-height: 1.4;
}
.aisa-quiz-option:hover:not(:disabled) {
    background: #f8fafc;
    border-color: #cbd5e1;
}
.aisa-quiz-option.is-correct {
    background: #d1fae5;
    border-color: #10b981;
    color: #065f46;
    font-weight: 700;
}
.aisa-quiz-option.is-incorrect {
    background: #fee2e2;
    border-color: #ef4444;
    color: #991b1b;
}
.aisa-quiz-option:disabled,
.aisa-quiz-option.aisa-quiz-locked {
    cursor: default;
    pointer-events: none;
}
.aisa-quiz-feedback {
    display: none;
    margin-top: 1rem;
    padding: 0.875rem 1rem;
    border-radius: 0.625rem;
    font-size: 0.9rem;
    line-height: 1.5;
}
.aisa-quiz-feedback.show {
    display: block;
}
.aisa-quiz-feedback.correct {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #6ee7b7;
}
.aisa-quiz-feedback.wrong {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fca5a5;
}

/* Hide the original "Module Progress" card so it doesn't duplicate
 * the training top bar. The original card always contains #progress-bar;
 * we don't know the wrapper tag (div on most PD modules, section on
 * return-to-school) so we match both. */
.aisa-train-managed div:has(> #progress-bar),
.aisa-train-managed div:has(> div > #progress-bar),
.aisa-train-managed div:has(> div > div > #progress-bar),
.aisa-train-managed section:has(> div > #progress-bar),
.aisa-train-managed section:has(> div > div > #progress-bar) {
    display: none !important;
}

/* Hide the per-section round checkbox circles that the original module
 * shows next to each step — the training framework's sidebar already
 * shows chapter progress, and the checkboxes get auto-ticked behind
 * the scenes for the completion-tracking pipeline. */
.aisa-train-managed label:has(.module-checkbox) {
    display: none !important;
}
