.tfw-weakness {
    border: 1px solid #dcdcde;
    border-radius: 8px;
    padding: 16px;
    background: #fff;
}

.tfw-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.tfw-toolbar > strong,
.tfw-subject-title {
    font-size: clamp(1.4rem, 2.4vw, 1.65rem);
    line-height: 1.35;
}

.tfw-actions {
    display: flex;
    gap: 8px;
}

.tfw-actions button {
    border: 1px solid #2271b1;
    border-radius: 4px;
    padding: 7px 12px;
    background: #2271b1;
    color: #fff;
    cursor: pointer;
}

.tfw-refresh-button {
    background: #fff !important;
    color: #2271b1 !important;
}

.tfw-status,
.tfw-meta {
    color: #646970;
    font-size: 0.9em;
}

.tfw-warning,
.tfw-error {
    color: #b32d2e;
}

.tfw-inline-status {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.tfw-inline-status[hidden] {
    display: none;
}

.tfw-inline-status .tfw-status {
    margin: 0;
}

.tfw-retry-button {
    border: 1px solid #2271b1;
    border-radius: 4px;
    padding: 5px 9px;
    background: #fff;
    color: #2271b1;
    cursor: pointer;
}

.tfw-result h3 {
    margin-top: 20px;
}

.tfw-table {
    width: 100%;
    border-collapse: collapse;
}

.tfw-table-scroll {
    overflow-x: auto;
}

.tfw-table th,
.tfw-table td {
    border-bottom: 1px solid #eee;
    padding: 8px;
    text-align: left;
}

.tfw-table th:last-child,
.tfw-table td:last-child {
    white-space: nowrap;
}

.tfw-table-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
}

.tfw-table-count,
.tfw-no-wrong {
    color: #646970;
    font-size: 0.9em;
}

.tfw-table-more-button,
.tfw-table-collapse-button,
.tfw-scope-practice-button {
    border: 1px solid #2271b1;
    border-radius: 4px;
    padding: 6px 10px;
    background: #fff;
    color: #2271b1;
    cursor: pointer;
}

.tfw-scope-history-trigger {
    display: inline-flex;
    align-items: center;
    max-width: 100%;
    border: 0;
    padding: 3px 2px;
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.tfw-scope-history-trigger:hover {
    color: #135e96;
}

.tfw-scope-history-trigger:focus-visible {
    outline: 2px solid #2271b1;
    outline-offset: 2px;
    border-radius: 2px;
}

.tfw-scope-history-caret {
    flex: 0 0 auto;
    margin-right: 7px;
    color: #2271b1;
    font-size: 0.75em;
    transition: transform 0.15s ease;
}

.tfw-table tr.is-open {
    background: #f4f9ff;
}

.tfw-table tr.is-open .tfw-scope-history-caret {
    transform: rotate(90deg);
}

.tfw-scope-history-trigger-count {
    flex: 0 0 auto;
    margin-left: 4px;
    color: #646970;
    font-size: 0.85em;
}

.tfw-table-collapse-button {
    border-color: #8c8f94;
    color: #50575e;
}

.tfw-scope-practice-button {
    border-color: #6f42c1;
    background: #6f42c1;
    color: #fff;
    line-height: 1.35;
    white-space: normal;
}

.tfw-scope-practice-button:hover,
.tfw-scope-practice-button:focus-visible {
    border-color: #59339d;
    background: #59339d;
}

.tfw-scope-practice-button:disabled {
    cursor: wait;
    opacity: 0.65;
}

.tfw-scope-history-row > td {
    padding: 0 !important;
    background: #f7faff;
}

.tfw-scope-history-panel {
    padding: 14px 16px 16px;
    white-space: normal;
}

.tfw-scope-history-heading {
    color: #2c3338;
    font-weight: 700;
}

.tfw-scope-history-legend {
    margin: 5px 0 10px;
    color: #667085;
    font-size: 0.82em;
}

.tfw-scope-history-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
    gap: 8px;
}

.tfw-scope-history-item {
    min-width: 0;
    display: grid;
    grid-template-columns: minmax(4.5rem, auto) minmax(210px, 1fr) auto;
    gap: 10px;
    align-items: center;
    padding: 9px 11px;
    border: 1px solid #e3e9ef;
    border-radius: 4px;
    background: #fff;
}

.tfw-scope-history-label {
    justify-self: start;
    border: 0;
    padding: 2px 3px;
    background: transparent;
    color: #2271b1;
    font: inherit;
    font-weight: 700;
    text-decoration: underline;
    text-underline-offset: 2px;
    cursor: pointer;
}

.tfw-scope-history-label:hover,
.tfw-scope-history-label:focus-visible {
    color: #135e96;
}

.tfw-scope-history-marks {
    min-width: 0;
    display: grid;
    grid-template-columns: repeat(5, minmax(34px, 1fr));
    gap: 3px;
}

.tfw-scope-history-mark {
    min-height: 27px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    border-radius: 2px;
    padding: 4px 6px;
    font-weight: 700;
    line-height: 1;
}

.tfw-scope-history-mark.is-correct {
    background: #eaf6ec;
    color: #216e39;
}

.tfw-scope-history-mark.is-wrong {
    background: #fcebec;
    color: #a42828;
}

.tfw-scope-history-mark.is-empty {
    background: #f5f5f5;
    color: #999;
}

.tfw-scope-favorites {
    display: inline-flex;
    gap: 3px;
}

.tfw-scope-favorite-button {
    min-width: 36px;
    border: 1px solid #c3c4c7;
    border-radius: 4px;
    padding: 5px 6px;
    background: #fff;
    color: #8c8f94;
    cursor: pointer;
}

.tfw-scope-favorite-button[data-type="1"].is-active {
    border-color: #d63638;
    background: #d63638;
    color: #fff;
}

.tfw-scope-favorite-button[data-type="2"].is-active {
    border-color: #d69e36;
    background: #d69e36;
    color: #fff;
}

.tfw-scope-favorite-button[data-type="3"].is-active {
    border-color: #2271b1;
    background: #2271b1;
    color: #fff;
}

.tfw-scope-history-message {
    margin: 0;
    padding: 18px;
    color: #667085;
    text-align: center;
}

.tfw-scope-history-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    color: #646970;
    font-size: 0.9em;
}

.tfw-scope-history-more {
    border: 1px solid #2271b1;
    border-radius: 4px;
    padding: 6px 10px;
    background: #fff;
    color: #2271b1;
    cursor: pointer;
}

.tfw-misconception-list {
    display: grid;
    gap: 12px;
}

.tfw-granularity-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-top: 20px;
    padding-bottom: 8px;
    border-bottom: 6px solid #e5e5e5;
}

.tfw-result .tfw-granularity-header h3 {
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0 !important;
}

.tfw-granularity-controls {
    display: inline-grid;
    flex: 0 0 auto;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    max-width: 420px;
    padding: 4px;
    border-radius: 7px;
    background: #f0f0f1;
}

.tfw-granularity-button {
    border: 1px solid transparent;
    border-radius: 5px;
    padding: 7px 12px;
    background: transparent;
    color: #50575e;
    font-weight: 600;
    cursor: pointer;
}

.tfw-granularity-button.is-active {
    border-color: #0073aa;
    background: #0073aa;
    color: #fff;
}

.tfw-granularity-note {
    margin: 8px 0 12px;
    color: #646970;
    font-size: 0.9em;
}

.tfw-misconception-card {
    border: 1px solid #dcdcde;
    border-left: 4px solid #d63638;
    border-radius: 6px;
    padding: 14px;
    background: #fcfcfc;
}

.tfw-misconception-card.is-reference {
    border-left-color: #dba617;
}

.tfw-reference-label {
    display: inline-block;
    margin: 2px 0 6px;
    border-radius: 999px;
    padding: 3px 8px;
    background: #fff3cd;
    color: #664d03;
    font-size: 0.82em;
}

.tfw-misconception-card h4 {
    margin: 0 0 6px;
}

.tfw-card-metrics,
.tfw-remediation-hint {
    margin: 6px 0;
}

.tfw-card-metrics {
    color: #646970;
    font-size: 0.9em;
}

.tfw-practice-button {
    margin-top: 8px;
    border: 1px solid #2271b1;
    border-radius: 4px;
    padding: 8px 14px;
    background: #2271b1;
    color: #fff;
    cursor: pointer;
}

.tfw-practice-button:disabled {
    cursor: wait;
    opacity: 0.65;
}

.tfw-practice-note {
    border-left: 4px solid #2271b1;
    padding: 10px 12px;
    background: #f0f6fc;
}

.tfw-lms-entry {
    margin-bottom: 18px;
    border: 0;
    border-radius: 0;
    padding: 0;
    background: transparent;
}

.tfw-lms-entry[hidden] {
    display: none !important;
}

.tfw-version-title {
    margin: 0 0 12px;
    color: #2c3338;
    font-size: 1.1em;
    line-height: 1.4;
}

.tfw-version-note {
    margin: 8px 0 0;
    color: #50575e;
    font-size: 0.9em;
}

.tfw-version-selector {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.tfw-version-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #8c8f94;
    border-radius: 5px;
    padding: 10px 14px;
    background: #fff;
    color: #2c3338;
    font-weight: bold;
    cursor: pointer;
}

.tfw-version-button.is-active {
    border-color: #0073aa;
    background: #0073aa;
    color: #fff;
}

.tfw-version-button.is-ai::before {
    content: '';
    width: 8px;
    height: 8px;
    margin-right: 7px;
    border-radius: 50%;
    background: #6f42c1;
}

.tfw-version-button.is-ai.is-active::before {
    background: #fff;
    box-shadow: 0 0 0 2px rgba(111, 66, 193, 0.65);
}

.tfw-lms-panel .tfw-embedded-weakness {
    margin-top: 14px;
}

#area-wrong.tfw-ai-view-active > :not(#tfw-lms-weakness-entry):not(.tfw-lms-panel),
form.tfw-ai-view-active #mtq-ext-options-container,
form.tfw-ai-view-active .mtq-form-actions {
    display: none !important;
}

.tfw-table tr.tfw-return-focus > td {
    background: #f3f8fc;
}

.tfw-table tr.tfw-return-focus > td:first-child {
    box-shadow: inset 3px 0 #0073aa;
}

.tfw-return-focus .tfw-scope-history-trigger {
    flex-wrap: wrap;
    row-gap: 4px;
}

.tfw-misconception-card.tfw-return-focus {
    border-left-color: #0073aa;
    background: #f3f8fc;
}

.tfw-return-badge {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    margin-left: 8px;
    border-radius: 999px;
    padding: 2px 7px;
    background: #dceef8;
    color: #135e96;
    font-size: 0.72em;
    font-weight: 600;
    line-height: 1.4;
    white-space: nowrap;
}

.tfw-misconception-card h4 .tfw-return-badge {
    vertical-align: middle;
}

@media (max-width: 700px) {
    .tfw-toolbar {
        align-items: center;
        flex-direction: row;
        gap: 8px;
    }

    .tfw-actions {
        flex: 0 0 auto;
        width: auto;
        margin-left: auto;
    }

    .tfw-actions button {
        min-height: 0;
        padding: 7px 10px;
        white-space: nowrap;
    }

    .tfw-granularity-header {
        align-items: center;
        flex-wrap: nowrap;
        gap: 6px;
    }

    .tfw-result .tfw-granularity-header h3 {
        white-space: nowrap;
    }

    .tfw-granularity-header .tfw-granularity-controls {
        margin-left: auto;
        gap: 2px;
        max-width: none;
        width: auto;
        padding: 2px;
        border-radius: 6px;
    }

    .tfw-granularity-header .tfw-granularity-button {
        min-height: 0;
        padding: 5px 8px;
        line-height: 1.25;
        white-space: nowrap;
    }

    .tfw-granularity-controls {
        display: grid;
        max-width: none;
        width: 100%;
        box-sizing: border-box;
    }

    .tfw-table-scroll {
        overflow: visible;
    }

    .tfw-table {
        display: block;
        font-size: 0.85em;
    }

    .tfw-table thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
    }

    .tfw-table tbody,
    .tfw-table tr,
    .tfw-table td {
        display: block;
        width: 100%;
        box-sizing: border-box;
    }

    .tfw-table tr {
        margin-bottom: 10px;
        border: 1px solid #dcdcde;
        border-radius: 7px;
        overflow: hidden;
        background: #fff;
    }

    .tfw-table tr.tfw-return-focus {
        border-left: 3px solid #0073aa;
    }

    .tfw-table tr.tfw-return-focus > td:first-child {
        box-shadow: none;
    }

    .tfw-table td,
    .tfw-table td:last-child {
        display: grid;
        grid-template-columns: minmax(7.5rem, 38%) minmax(0, 1fr);
        gap: 10px;
        align-items: center;
        border-bottom: 1px solid #eee;
        white-space: normal;
        overflow-wrap: anywhere;
    }

    .tfw-table td:last-child {
        border-bottom: 0;
    }

    .tfw-table td::before {
        content: attr(data-label);
        color: #50575e;
        font-weight: 700;
    }

    .tfw-scope-practice-button {
        width: 100%;
        min-height: 44px;
        box-sizing: border-box;
    }

    .tfw-scope-history-trigger {
        width: 100%;
        min-height: 44px;
        box-sizing: border-box;
    }

    .tfw-table tr.tfw-scope-history-row {
        border: 0;
        overflow: visible;
    }

    .tfw-table .tfw-scope-history-row > td {
        display: block;
        padding: 0 !important;
    }

    .tfw-table .tfw-scope-history-row > td::before {
        display: none;
    }

    .tfw-scope-history-panel {
        padding: 12px 8px 14px;
    }

    .tfw-scope-history-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .tfw-scope-history-item {
        grid-template-columns: minmax(4rem, auto) minmax(0, 1fr);
    }

    .tfw-scope-favorites {
        grid-column: 1 / -1;
        justify-self: end;
    }

    .tfw-scope-history-mark {
        min-height: 25px;
        padding: 4px;
        font-size: 0.9em;
    }

    .tfw-practice-button {
        width: 100%;
        min-height: 44px;
        white-space: normal;
    }
}
