/* ==========================================================================
   WEAKNESS ANALYSIS — dedicated page

   Replaces the "Performance Analysis" modal, which was a 500px box listing
   chapter names against a raw mistake counter and nothing else: no severity,
   no cause, no sense of whether the student was getting better, and nothing to
   click.

   Same design-system tokens as test-history.css and syllabus-tracker.css.
   Prefix is wk- throughout.
   ========================================================================== */

#weakness-view {
    padding: 0;
}

.wk-page {
    max-width: 1200px;
    margin: 0 auto;
    padding: 4px 0 48px;
    color: var(--text-main);
    animation: wk-rise 0.3s ease both;
}

@keyframes wk-rise {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

/* .content-area is a flex item: anything in here that reports a wide
   min-content would push the whole app shell past the window. */
.wk-two-col > *,
.wk-card,
.wk-chart-wrap,
.wk-row,
.wk-row-main > * {
    min-width: 0;
}

.wk-table-scroll {
    overflow-x: auto;
    contain: inline-size;
}

/* ── Hero ───────────────────────────────────────────────────────────────── */

.wk-hero {
    position: relative;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background:
        radial-gradient(circle at 12% -40%, color-mix(in srgb, var(--danger) 24%, transparent), transparent 58%),
        radial-gradient(circle at 88% -20%, color-mix(in srgb, var(--brand) 20%, transparent), transparent 55%),
        var(--surface-solid);
    box-shadow: var(--shadow-sm);
    padding: 22px 24px;
    display: flex;
    flex-wrap: wrap;
    gap: 22px;
    align-items: center;
    margin-bottom: var(--sp-4);
}

.wk-score {
    position: relative;
    width: 132px;
    height: 132px;
    flex-shrink: 0;
}

.wk-score svg {
    width: 132px;
    height: 132px;
    transform: rotate(-90deg);
}

.wk-score circle {
    fill: none;
    stroke-width: 11;
    stroke-linecap: round;
}

.wk-score-track {
    stroke: color-mix(in srgb, var(--text-muted) 18%, transparent);
}

.wk-score-value {
    transition: stroke-dasharray 0.6s ease;
}

.wk-score-label {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.wk-score-label b {
    font-size: 1.6rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1;
}

.wk-score-label span {
    margin-top: 4px;
    font-size: 0.6rem;
    font-weight: 800;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.wk-hero-body {
    flex: 1;
    min-width: 250px;
}

.wk-subject-chip {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 4px 12px 4px 8px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--danger) 12%, transparent);
    border: 1px solid color-mix(in srgb, var(--danger) 34%, transparent);
    color: var(--danger);
    font-size: 0.74rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.wk-hero-body h2 {
    margin: 10px 0 6px;
    font-size: 1.7rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.wk-hero-sub {
    margin: 0 0 14px;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
    line-height: 1.5;
}

.wk-hero-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* ── Buttons ────────────────────────────────────────────────────────────── */

.wk-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 9px 16px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--surface-raised);
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
    transition: transform 0.15s ease, background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.wk-btn:hover {
    transform: translateY(-1px);
    border-color: color-mix(in srgb, var(--brand) 45%, transparent);
}

.wk-btn:active {
    transform: translateY(0) scale(0.98);
}

.wk-btn.primary {
    background: var(--danger);
    border-color: var(--danger);
    color: #12060a;
}

html.theme-light .wk-btn.primary {
    color: #fff;
}

.wk-btn.accent {
    background: color-mix(in srgb, var(--brand) 16%, transparent);
    border-color: color-mix(in srgb, var(--brand) 45%, transparent);
    color: var(--brand);
}

.wk-btn.tiny {
    padding: 6px 12px;
    font-size: 0.76rem;
}

/* ── KPI strip ──────────────────────────────────────────────────────────── */

.wk-kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(178px, 1fr));
    gap: var(--sp-3);
    margin-bottom: var(--sp-4);
}

.wk-kpi {
    position: relative;
    background: var(--surface-solid);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 15px 16px;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    transition: transform 0.18s ease, border-color 0.18s ease;
}

.wk-kpi::before {
    content: '';
    position: absolute;
    inset: 0 auto 0 0;
    width: 3px;
    background: var(--kpi-tint, var(--danger));
}

.wk-kpi:hover {
    transform: translateY(-2px);
    border-color: color-mix(in srgb, var(--kpi-tint, var(--danger)) 40%, transparent);
}

.wk-kpi-label {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.wk-kpi-label i {
    color: var(--kpi-tint, var(--danger));
}

.wk-kpi-value {
    margin-top: 8px;
    font-size: 1.55rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.1;
}

.wk-kpi-value small {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-muted);
}

.wk-kpi-foot {
    margin-top: 5px;
    font-size: 0.74rem;
    color: var(--text-muted);
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.wk-delta {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-weight: 800;
}

.wk-delta.up {
    color: var(--success);
}

.wk-delta.down {
    color: var(--danger);
}

.wk-delta.flat {
    color: var(--text-muted);
}

/* ── Fix plan ───────────────────────────────────────────────────────────── */

.wk-plan {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: var(--sp-3);
}

.wk-plan-step {
    position: relative;
    padding: 16px 16px 16px 52px;
    border-radius: var(--radius-sm);
    border: 1px solid color-mix(in srgb, var(--step-tint, var(--danger)) 30%, transparent);
    background: color-mix(in srgb, var(--step-tint, var(--danger)) 8%, var(--surface-raised));
}

.wk-plan-step::before {
    content: attr(data-step);
    position: absolute;
    left: 15px;
    top: 15px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--step-tint, var(--danger));
    color: #12060a;
    font-size: 0.78rem;
    font-weight: 800;
}

html.theme-light .wk-plan-step::before {
    color: #fff;
}

.wk-plan-step h5 {
    margin: 0 0 4px;
    font-size: 0.9rem;
    font-weight: 800;
}

.wk-plan-step p {
    margin: 0 0 10px;
    font-size: 0.78rem;
    line-height: 1.45;
    color: var(--text-muted);
    font-weight: 500;
}

/* ── Cards ──────────────────────────────────────────────────────────────── */

.wk-card {
    background: var(--surface-solid);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 18px 20px;
    margin-bottom: var(--sp-4);
}

.wk-card-head {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}

.wk-card-head h4 {
    margin: 0;
    font-size: 1rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    gap: 8px;
}

.wk-card-head h4 i {
    color: var(--danger);
}

.wk-card-head p {
    margin: 3px 0 0;
    font-size: 0.76rem;
    color: var(--text-muted);
    font-weight: 500;
}

.wk-two-col {
    display: grid;
    grid-template-columns: 1.5fr 1fr;
    gap: var(--sp-4);
    align-items: start;
}

/* ── Error-type split ───────────────────────────────────────────────────── */

.wk-causes {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: var(--sp-3);
}

.wk-cause {
    padding: 14px 15px;
    border-radius: var(--radius-sm);
    border: 1px solid color-mix(in srgb, var(--cause-tint, var(--danger)) 28%, transparent);
    background: color-mix(in srgb, var(--cause-tint, var(--danger)) 8%, transparent);
}

.wk-cause i {
    color: var(--cause-tint, var(--danger));
    font-size: 0.95rem;
}

.wk-cause b {
    display: block;
    margin: 8px 0 2px;
    font-size: 1.35rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.wk-cause span {
    display: block;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.wk-cause p {
    margin: 7px 0 0;
    font-size: 0.74rem;
    line-height: 1.45;
    color: var(--text-muted);
    font-weight: 500;
}

/* ── Recovery chart ─────────────────────────────────────────────────────── */

.wk-chart {
    width: 100%;
    height: auto;
    display: block;
    overflow: visible;
}

.wk-chart .wk-grid-line {
    stroke: var(--line);
    stroke-width: 1;
}

.wk-chart .wk-axis-text {
    fill: var(--text-muted);
    font-size: 9px;
    font-weight: 600;
}

.wk-chart .wk-line {
    fill: none;
    stroke: var(--success);
    stroke-width: 2.4;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.wk-chart .wk-line.err {
    stroke: var(--danger);
}

.wk-chart .wk-dot {
    fill: var(--surface-solid);
    stroke: var(--success);
    stroke-width: 2;
}

.wk-chart .wk-dot.err {
    stroke: var(--danger);
}

.wk-chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    margin-top: 10px;
    font-size: 0.74rem;
    color: var(--text-muted);
    font-weight: 600;
}

.wk-chart-legend span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.wk-swatch {
    width: 12px;
    height: 3px;
    border-radius: 2px;
    background: var(--success);
}

.wk-swatch.err {
    background: var(--danger);
}

.wk-chart-empty {
    padding: 26px 0;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.83rem;
    font-weight: 600;
    line-height: 1.6;
}

/* ── Recovered list ─────────────────────────────────────────────────────── */

.wk-recovered {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.wk-recovered-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 13px;
    border-radius: 10px;
    background: color-mix(in srgb, var(--success) 8%, transparent);
    border: 1px solid color-mix(in srgb, var(--success) 26%, transparent);
    font-size: 0.82rem;
}

.wk-recovered-row .name {
    flex: 1;
    min-width: 0;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.wk-jump {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 800;
    white-space: nowrap;
}

.wk-jump .from {
    color: var(--danger);
}

.wk-jump .to {
    color: var(--success);
}

/* ── Toolbar ────────────────────────────────────────────────────────────── */

.wk-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-bottom: 14px;
}

.wk-search {
    position: relative;
    flex: 1;
    min-width: 190px;
}

.wk-search i {
    position: absolute;
    left: 13px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 0.8rem;
    pointer-events: none;
}

.wk-search input {
    width: 100%;
    padding: 10px 14px 10px 34px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--surface-raised);
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.83rem;
    font-weight: 500;
    outline: none;
    box-sizing: border-box;
    transition: border-color 0.18s ease;
}

.wk-search input:focus {
    border-color: color-mix(in srgb, var(--brand) 55%, transparent);
}

.wk-select {
    padding: 9px 12px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--surface-raised);
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.79rem;
    font-weight: 700;
    cursor: pointer;
    outline: none;
}

/* ── Weakness rows ──────────────────────────────────────────────────────── */

.wk-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.wk-row {
    border: 1px solid var(--line);
    border-left: 3px solid var(--row-tint, var(--danger));
    border-radius: var(--radius-sm);
    background: var(--surface-raised);
    overflow: hidden;
    transition: border-color 0.18s ease;
}

.wk-row:hover {
    border-color: color-mix(in srgb, var(--row-tint, var(--danger)) 45%, transparent);
    border-left-color: var(--row-tint, var(--danger));
}

.wk-row-main {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    cursor: pointer;
}

.wk-row-id {
    flex: 1;
    min-width: 200px;
}

.wk-row-title {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 0.95rem;
    font-weight: 700;
    margin-bottom: 5px;
}

.wk-row-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    color: var(--text-muted);
    font-size: 0.74rem;
    font-weight: 600;
}

.wk-row-meta span {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

/* Severity bar */
.wk-sev {
    width: 130px;
}

.wk-sev-track {
    position: relative;
    height: 8px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--text-muted) 16%, transparent);
    overflow: hidden;
}

.wk-sev-fill {
    position: absolute;
    inset: 0 auto 0 0;
    border-radius: 999px;
    background: var(--row-tint, var(--danger));
}

.wk-sev-label {
    margin-top: 5px;
    font-size: 0.71rem;
    font-weight: 700;
    color: var(--text-muted);
}

.wk-row-actions {
    display: flex;
    gap: 7px;
    align-items: center;
}

.wk-chevron {
    color: var(--text-muted);
    transition: transform 0.22s ease;
    font-size: 0.8rem;
}

.wk-row.open .wk-chevron {
    transform: rotate(180deg);
}

.wk-row-detail {
    display: none;
    padding: 0 16px 16px;
    border-top: 1px dashed var(--line);
}

.wk-row.open .wk-row-detail {
    display: block;
    animation: wk-rise 0.22s ease both;
}

.wk-mini-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 14px 0;
}

.wk-mini {
    flex: 1;
    min-width: 116px;
    background: var(--surface-solid);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px 12px;
}

.wk-mini span {
    display: block;
    font-size: 0.65rem;
    color: var(--text-muted);
    font-weight: 800;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.wk-mini b {
    font-size: 0.98rem;
    font-weight: 800;
}

/* Offending questions */
.wk-q {
    display: flex;
    gap: 11px;
    align-items: flex-start;
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--surface-solid);
    border: 1px solid var(--line);
    margin-bottom: 8px;
}

.wk-q-rank {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    border-radius: 7px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.68rem;
    font-weight: 800;
    background: color-mix(in srgb, var(--danger) 18%, transparent);
    color: var(--danger);
    border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
}

.wk-q-body {
    flex: 1;
    min-width: 0;
}

.wk-q-text {
    font-size: 0.8rem;
    line-height: 1.45;
    font-weight: 500;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.wk-q-meta {
    margin-top: 5px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-muted);
}

.wk-q-meta .bad {
    color: var(--danger);
}

.wk-q-meta .warn {
    color: var(--warning);
}

/* ── Pills ──────────────────────────────────────────────────────────────── */

.wk-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.69rem;
    font-weight: 800;
    white-space: nowrap;
    border: 1px solid transparent;
}

.wk-pill.critical {
    color: var(--danger);
    background: color-mix(in srgb, var(--danger) 15%, transparent);
    border-color: color-mix(in srgb, var(--danger) 36%, transparent);
}

.wk-pill.weak {
    color: var(--warning);
    background: color-mix(in srgb, var(--warning) 14%, transparent);
    border-color: color-mix(in srgb, var(--warning) 34%, transparent);
}

.wk-pill.improving {
    color: var(--brand);
    background: var(--brand-soft);
    border-color: color-mix(in srgb, var(--brand) 34%, transparent);
}

.wk-pill.recovered {
    color: var(--success);
    background: color-mix(in srgb, var(--success) 14%, transparent);
    border-color: color-mix(in srgb, var(--success) 34%, transparent);
}

.wk-pill.ghost {
    color: var(--text-muted);
    background: color-mix(in srgb, var(--text-muted) 12%, transparent);
    border-color: var(--line);
}

/* ── Empty state ────────────────────────────────────────────────────────── */

.wk-empty {
    text-align: center;
    padding: 50px 20px;
}

.wk-empty-icon {
    width: 76px;
    height: 76px;
    margin: 0 auto 16px;
    border-radius: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.9rem;
    color: var(--success);
    background: color-mix(in srgb, var(--success) 12%, transparent);
    border: 1px solid color-mix(in srgb, var(--success) 30%, transparent);
}

.wk-empty h4 {
    margin: 0 0 7px;
    font-size: 1.1rem;
    font-weight: 800;
}

.wk-empty p {
    margin: 0 auto 18px;
    max-width: 430px;
    color: var(--text-muted);
    font-size: 0.86rem;
    line-height: 1.55;
    font-weight: 500;
}

/* ── Toast ──────────────────────────────────────────────────────────────── */

.wk-toast {
    position: fixed;
    left: 50%;
    bottom: 34px;
    transform: translateX(-50%) translateY(14px);
    z-index: 100000;
    padding: 11px 20px;
    border-radius: 999px;
    background: var(--surface-solid);
    border: 1px solid var(--line);
    box-shadow: var(--shadow-md);
    color: var(--text-main);
    font-size: 0.83rem;
    font-weight: 700;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.wk-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

@media (max-width: 900px) {

    body:not(.test-taking-mode):not(.practice-taking-mode) .wk-toast {
        bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 14px);
    }
}

/* ── Responsive ─────────────────────────────────────────────────────────── */

@media (max-width: 980px) {
    .wk-two-col {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 720px) {
    .wk-hero {
        padding: 18px;
        gap: 16px;
    }

    .wk-score,
    .wk-score svg {
        width: 104px;
        height: 104px;
    }

    .wk-hero-body h2 {
        font-size: 1.35rem;
    }

    .wk-hero-actions {
        width: 100%;
    }

    .wk-hero-actions .wk-btn {
        flex: 1;
    }

    .wk-kpis {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .wk-kpi-value {
        font-size: 1.3rem;
    }

    .wk-card {
        padding: 15px;
        border-radius: 14px;
    }

    .wk-row-main {
        padding: 13px 14px;
        gap: 10px;
    }

    .wk-row-id {
        min-width: 100%;
    }

    .wk-sev {
        width: 100%;
    }

    .wk-row-actions {
        margin-left: auto;
    }

    .wk-toolbar .wk-select {
        flex: 1;
    }
}
