/* ============================================================
   PYTHON COACH V2 — Analytics Dashboard styles
   Scoped to body[data-v2-analytics].
   All colours are V2 CSS design tokens — no hardcoded values.
   ============================================================ */

/* Local token: dark amber for "in progress" numeric cells.
   Defined here rather than v2.css because it is analytics-only.
   Hex value chosen for WCAG AA contrast on --bg (#FFFFFF).     */
body[data-v2-analytics] {
    --an-amber: #946800;            /* passes AA on white */
    --an-matrix-blue-1: #E8F4FD;   /* in progress background */
    --an-matrix-blue-1-text: #0E6B9E; /* in progress text — 4.58:1 on #E8F4FD ✓ AA */
    --an-matrix-blue-2: #1CB0F6;   /* completed clean — uses --primary */
    --an-matrix-blue-3: #0A5A8C;   /* completed with hints — uses --primary-dark */
}

/* ── PAGE SHELL ─────────────────────────────────────────────── */
body[data-v2-analytics] {
    min-height: 100vh;
    background: var(--surface);
    overflow-y: auto;
}

/* ── TOPBAR ─────────────────────────────────────────────────── */
/* Aligned to the #hub-topbar/#hub-logo pattern (v2css/v2-topbar.css) —
   property-for-property identical, kept here rather than linking
   v2-topbar.css so this migration doesn't add analytics.html as a new
   consumer of a file shared by hub.html/my-classes.html/superuser.html/
   teacher.html. See 2026-07-31 chrome migration directive. */
#hub-topbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 200;
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    padding-top: env(safe-area-inset-top, 0px);
    background: var(--bg);
    border-bottom: 2px solid var(--border);
}

#hub-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 17px;
    font-weight: 900;
    color: var(--text);
    letter-spacing: -0.01em;
    text-decoration: none;
}

.an-back-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--text);
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s;
    white-space: nowrap;
}

.an-back-btn:hover {
    background: var(--border);
    border-color: var(--border-dark);
}

/* ── MAIN CONTENT AREA ──────────────────────────────────────── */
#an-main {
    max-width: 1040px;
    margin: 0 auto;
    padding: calc(var(--topbar-h) + 28px) 20px 60px;
}

/* ── INLINE STATES (error + loading) ────────────────────────── */
/* Both are shown/hidden via the [hidden] attribute by JS.       */
.an-state-box {
    text-align: center;
    padding: 48px 24px;
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    margin-top: 8px;
}

.an-state-icon {
    font-size: 2.5rem;
    line-height: 1;
    margin-bottom: 16px;
}

.an-state-title {
    font-size: 1.05rem;
    font-weight: 800;
    color: var(--text);
    margin-bottom: 8px;
}

.an-state-body {
    font-size: 0.9rem;
    color: var(--text-muted);
    line-height: 1.55;
    margin-bottom: 20px;
}

.an-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: an-spin 0.75s linear infinite;
    margin: 0 auto 16px;
}

@keyframes an-spin {
    to { transform: rotate(360deg); }
}

/* ── CLASS HEADER ────────────────────────────────────────────── */
.an-class-header {
    margin-bottom: 24px;
}

.an-class-name {
    font-size: 1.5rem;
    font-weight: 900;
    color: var(--text);
    margin: 0 0 6px 0;
    letter-spacing: -0.01em;
}

.an-join-code-row {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.875rem;
    color: var(--text-muted);
}

.an-join-code {
    font-family: var(--mono);
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--primary);
    background: var(--surface);
    border: 2px solid var(--border);
    padding: 1px 8px;
    border-radius: var(--radius-xs, 6px);
}

/* ── OVERVIEW METRIC CARDS ───────────────────────────────────── */
.an-overview-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
    margin-bottom: 8px;
}

@media (max-width: 700px) {
    .an-overview-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 400px) {
    .an-overview-grid { grid-template-columns: 1fr; }
}

.an-metric-card {
    background: var(--bg);
    border: 2px solid var(--border);
    border-top: 4px solid var(--primary);
    border-radius: var(--radius);
    padding: 18px 14px 14px;
    text-align: center;
}

.an-metric-value {
    font-size: 2rem;
    font-weight: 900;
    color: var(--primary);
    line-height: 1.1;
    margin-bottom: 4px;
    letter-spacing: -0.02em;
}

.an-metric-label {
    font-size: 0.73rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* ── PROGRESS BAR (Avg Completion card) ─────────────────────── */
.an-progress-track {
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
    margin: 8px 0 6px;
}

.an-progress-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 4px;
    transition: width 0.4s ease;
    min-width: 0;
}

/* ── SECTION HEADERS ─────────────────────────────────────────── */
.an-section-header {
    display: flex;
    align-items: baseline;
    gap: 10px;
    margin: 28px 0 12px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--border);
    flex-wrap: wrap;
}

.an-section-title {
    font-size: 1rem;
    font-weight: 800;
    color: var(--text);
    margin: 0;
}

.an-section-sub {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ── ANALYTICS TABLE WRAPPER ─────────────────────────────────── */
.an-table-wrap {
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

/* ── ANALYTICS TABLE ─────────────────────────────────────────── */
.an-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.an-table thead th {
    text-align: left;
    padding: 10px 14px;
    font-size: 0.73rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    background: var(--surface);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

.an-table thead th.an-num-cell {
    text-align: right;
}

.an-table tbody td {
    padding: 12px 14px;
    color: var(--text);
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.an-table tbody tr:last-child td {
    border-bottom: none;
}

.an-table tbody tr.an-row-clickable {
    cursor: pointer;
    transition: background 0.1s;
}

.an-table tbody tr.an-row-clickable:hover {
    background: var(--surface);
}

/* Numeric cells — right-aligned for scannability */
.an-table .an-num-cell {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* In-table emphasis */
.an-cell-completed  { color: var(--primary);  font-weight: 700; }
.an-cell-in-progress { color: var(--an-amber); font-weight: 700; }

/* Email sub-line in roster */
.an-email-sub {
    display: block;
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* "Never started" indicator in last-active column */
.an-never-started {
    color: var(--text-muted);
    font-style: italic;
}

/* Challenge title sub-text */
.an-cid-sub {
    display: block;
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 1px;
}

/* ── EMPTY STATE ─────────────────────────────────────────────── */
.an-empty {
    padding: 32px 24px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* ── STATUS BADGES ───────────────────────────────────────────── */
/* Deuteranopia-safe: meaning carried by text label AND colour.   */
.an-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
    white-space: nowrap;
    letter-spacing: 0.01em;
}

/* Completed — primary fill, inverse text */
.an-badge--completed {
    background: var(--primary);
    color: var(--text-inverse);
}

/* In Progress — yellow fill, dark text (sufficient contrast) */
.an-badge--in-progress {
    background: var(--yellow);
    color: var(--text);
}

/* Not Started — muted surface, border */
.an-badge--not-started {
    background: var(--surface);
    color: var(--text-muted);
    border: 1px solid var(--border-dark);
}

/* ── STUDENT DETAIL MODAL ────────────────────────────────────── */
.an-modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 400;
    align-items: flex-start;
    justify-content: center;
    padding: 24px 16px;
    overflow-y: auto;
}

.an-modal-overlay.is-open {
    display: flex;
}

.an-modal-panel {
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
    width: 100%;
    max-width: 820px;
    position: relative;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
}

.an-modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 32px;
    height: 32px;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 16px;
    color: var(--text-muted);
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.an-modal-close:hover {
    background: var(--border);
    border-color: var(--border-dark);
    color: var(--text);
}

.an-modal-name {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--text);
    margin: 0 0 4px 0;
    padding-right: 44px;
}

.an-modal-subtitle {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 20px;
}

.an-modal-scroll {
    max-height: 60vh;
    overflow-y: auto;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    overflow-x: auto;
}

/* ── CLASSROOM SELECTOR ──────────────────────────────────────── */
#an-selector {
    margin-top: 8px;
}

.an-sel-header {
    margin-bottom: 20px;
}

.an-sel-heading {
    font-size: 1.25rem;
    font-weight: 900;
    color: var(--text);
    margin: 0 0 6px 0;
    letter-spacing: -0.01em;
}

.an-sel-sub {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin: 0;
}

.an-sel-spinner-wrap {
    text-align: center;
    padding: 32px 0;
}

/* Classroom card list — vertical stack */
.an-cls-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Individual classroom card — behaves as a button */
.an-cls-card {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 16px 18px;
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-family: var(--font);
    cursor: pointer;
    text-align: left;
    transition: border-color 0.15s, background 0.15s;
}

.an-cls-card:hover {
    border-color: var(--primary);
    background: var(--bg);
}

.an-cls-card:focus-visible {
    outline: none;
    border-color: var(--primary);
}

/* Classroom name — takes remaining horizontal space */
.an-cls-card-name {
    flex: 1;
    font-size: 1.05rem;
    font-weight: 800;
    color: var(--text);
    line-height: 1.3;
}

/* Archived card variant — muted name colour */
/* Deuteranopia-safe: muted colour + "Archived" text label, not colour alone. */
.an-cls-card--archived .an-cls-card-name {
    color: var(--text-muted);
}

/* "Archived" text pill badge */
.an-cls-archived-label {
    font-size: 0.73rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    background: var(--border);
    padding: 2px 8px;
    border-radius: 999px;
    white-space: nowrap;
    flex-shrink: 0;
}

/* Show-archived toggle button */
.an-sel-toggle {
    margin-top: 16px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.an-sel-toggle:hover {
    background: var(--border);
    border-color: var(--border-dark);
    color: var(--text);
}

/* Empty state within the selector (no classrooms / all archived) */
.an-sel-empty {
    padding: 32px 24px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: var(--radius);
}

.an-sel-empty a {
    color: var(--primary);
    font-weight: 700;
    text-decoration: none;
}

.an-sel-empty a:hover {
    text-decoration: underline;
}

/* ── RESPONSIVE ─────────────────────────────────────────────── */
@media (max-width: 700px) {
    #an-main {
        padding: 16px 14px 40px;
    }

    .an-table {
        font-size: 0.82rem;
    }

    .an-table thead th,
    .an-table tbody td {
        padding: 8px 10px;
    }

    .an-modal-panel {
        padding: 20px 14px;
    }

    .an-col-hide-mobile {
        display: none;
    }

    .an-class-name {
        font-size: 1.2rem;
    }
}

@media (max-width: 420px) {
    .an-metric-value {
        font-size: 1.6rem;
    }
}

@media (max-width: 374px) {
    #hub-topbar {
        padding: 0 12px;
    }

    #an-main {
        padding: 12px 10px 32px;
    }
}

/* ── ACCORDION CODE EXPAND (student detail modal) ────────────── */
.an-challenge-row {
    cursor: pointer;
    transition: background 0.1s;
}
.an-challenge-row:hover { background: var(--surface); }

.an-row-chevron {
    display: inline-block;
    margin-left: 6px;
    font-size: 0.85em;
    color: var(--text-muted);
    transition: transform 0.25s ease;
    vertical-align: middle;
    line-height: 1;
    user-select: none;
}
.an-challenge-row.is-open .an-row-chevron { transform: rotate(180deg); }

.an-table .an-code-expand-cell { padding: 0; border-bottom: none; }
.an-code-expand.is-open .an-code-expand-cell { border-bottom: 1px solid var(--border); }

.an-code-expand-inner {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.25s ease;
}
.an-code-expand.is-open .an-code-expand-inner { max-height: 600px; }

.an-code-block {
    display: block;
    background: var(--hint-code-bg);
    color: var(--hint-code-text);
    font-family: var(--mono);
    font-size: 13px;
    line-height: 1.6;
    padding: 14px 16px;
    overflow-x: auto;
    white-space: pre;
    margin: 0;
}
.an-code-empty {
    padding: 12px 16px;
    font-size: 0.875rem;
    color: var(--text-muted);
    font-style: italic;
    margin: 0;
}

/* ── COMPLETION MATRIX ───────────────────────────────────────── */
#an-matrix-wrap {
    width: 100%;
    margin-top: 12px;
    overflow: hidden;
}

#an-matrix-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 16px;
}

.an-matrix-filter-btn {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: background 0.15s;
}

.an-matrix-filter-btn:hover {
    background: var(--border);
}

.an-matrix-filter-btn--active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

#an-matrix-scroll {
    overflow-x: auto;
    width: 100%;
}

#an-matrix-table {
    border-collapse: collapse;
    min-width: 100%;
}

#an-matrix-table th {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    padding: 2px 4px;
    text-align: center;
    white-space: nowrap;
    position: sticky;
    top: 0;
    background: var(--surface);
}

#an-matrix-table th.an-matrix-student-col {
    text-align: left;
    min-width: 80px;
    max-width: 140px;
    position: sticky;
    left: 0;
    z-index: 3;
    background: var(--surface);
}

#an-matrix-table td {
    padding: 2px 3px;
    text-align: center;
    border: 1px solid var(--border);
    font-size: 0.75rem;
    min-width: 24px;
}

#an-matrix-table td:not(.an-matrix-student-name) {
    max-width: 28px;
}

#an-matrix-table th:not(.an-matrix-student-col) {
    max-width: 28px;
}

#an-matrix-table td.an-matrix-student-name {
    text-align: left;
    font-size: 0.8rem;
    color: var(--text);
    padding-left: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 180px;
    position: sticky;
    left: 0;
    z-index: 2;
    background: var(--surface);
}

.an-matrix-cell {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    border-radius: 4px;
    min-height: 18px;
    font-weight: 600;
    position: relative;
    cursor: default;
}

.an-matrix-cell--progress {
    background: var(--an-matrix-blue-1);
    color: var(--an-matrix-blue-1-text);
}

.an-matrix-cell--clean {
    background: var(--an-matrix-blue-2);
    color: #fff;
}

.an-matrix-cell--hints {
    background: var(--an-matrix-blue-3);
    color: #fff;
}

.an-matrix-cell[data-tooltip] {
    cursor: default;
}

#an-matrix-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    margin-top: 12px;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.an-matrix-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.an-matrix-cell-demo {
    display: inline-block;
    width: 20px;
    height: 20px;
    border-radius: 4px;
}

.an-matrix-legend--progress .an-matrix-cell-demo {
    background: var(--an-matrix-blue-1);
    border: 1px solid var(--an-matrix-blue-1-text);
}

.an-matrix-legend--clean .an-matrix-cell-demo {
    background: var(--an-matrix-blue-2);
}

.an-matrix-legend--hints .an-matrix-cell-demo {
    background: var(--an-matrix-blue-3);
}

.an-matrix-tooltip {
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: #1a1a1a;
    color: #fff;
    font-size: 0.72rem;
    padding: 4px 8px;
    border-radius: 4px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 100;
}

.an-matrix-cell:hover .an-matrix-tooltip {
    opacity: 1;
}

#an-matrix-th-tooltip {
    position: fixed;
    transform: translateX(-50%);
    background: #1a1a1a;
    color: #fff;
    font-size: 0.72rem;
    padding: 4px 8px;
    border-radius: 4px;
    white-space: nowrap;
    pointer-events: none;
    z-index: 500;
    display: none;
}

@keyframes an-pulse {
    from { box-shadow: 0 0 0 0 rgba(28, 176, 246, 0.7); }
    to   { box-shadow: 0 0 0 6px rgba(28, 176, 246, 0); }
}

.an-matrix-cell--pulse {
    animation: an-pulse 0.6s ease-out 5;
}

.an-matrix-filter-btn--today.an-matrix-filter-btn--active {
    background: var(--an-amber);
    color: #fff;
    border-color: var(--an-amber);
}

/* ── CONCERTINA SECTIONS ─────────────────────────────────────── */
.an-concertina {
    width: 100%;
    margin: 28px 0 0;
}

.an-concertina-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: transparent;
    border: none;
    border-bottom: 2px solid var(--border);
    padding: 0 0 10px;
    cursor: pointer;
    text-align: left;
    margin-bottom: 12px;
}

.an-concertina-toggle:hover {
    background: var(--surface);
}

.an-concertina-toggle .an-section-title {
    font-size: 1rem;
    font-weight: 800;
    color: var(--text);
    margin: 0;
}

.an-concertina-icon {
    color: var(--text-muted);
    font-size: 0.75rem;
    transition: transform 0.2s ease;
    display: inline-block;
}

.an-concertina-toggle[aria-expanded="true"] .an-concertina-icon {
    transform: rotate(90deg);
}

/* ── Superuser impersonation banner ─────────────────────────── */
#an-su-banner {
    background: #1a1a1a;
    color: #EEC252;
    font-family: var(--font);
    font-size: 0.85rem;
    font-weight: 600;
    padding: 8px 24px;
    text-align: center;
    letter-spacing: 0.01em;
}
