/*
 * Template-renderer stylesheet (P2B AC-3, issue #1965; P2C journey parity).
 *
 * Owns the styling for every template-renderer surface: course page,
 * orientation, walkthrough, practice landing, practice, end, feedback.
 * Linked ONCE from `layout.html` (the pinned convention).
 *
 * P2C: the template pages now sit in the LEGACY page shells (`.step >
 * .landing-card`, `.course-detail`, `.module-card`, `.self-quiz-*`,
 * `.self-ratings`, `.btn`) so a template course reads exactly like a
 * hand-built one; those legacy classes are REUSED from `style.css`, never
 * re-declared here. This file styles only the template-owned vocabulary,
 * and mirrors the legacy deck look (`didactic.css`) for the template's own
 * deck classes.
 *
 * Scope discipline (ADR-0034 / N2 tripwire): `layout.html` is shared, so
 * rules are namespaced under template-only classes. The shared didactic
 * deck classes (`.didactic-slide-deck*`) are scoped under
 * `.template-didactic` / `.template-orientation` so the legacy deck is
 * untouched.
 *
 * Generic-selector law (forest §10.5-2): class selectors only — never step
 * names, concept names, or counts. Every value routes through a
 * `style.css` design token (ADR-0071).
 */

/* ── Course page ────────────────────────────────────────────────────────── */

.template-course {
    /* The legacy .course-detail shell lays the page out; this hook scopes
       the template-only additions below. */
    position: relative;
}

.template-course__badge {
    margin: calc(-1 * var(--space-sm)) 0 var(--space-md);
    color: var(--text-muted);
    font-size: var(--font-size-sm);
}

.template-course__goals {
    margin-block-end: var(--space-lg);
    color: var(--text-subtle);
    line-height: var(--line-height-relaxed);
}

.template-course__goals-title {
    margin: 0 0 var(--space-xs);
    font-weight: var(--font-weight-medium);
    color: var(--text);
}

.template-course__goals-list {
    margin: 0;
    padding-inline-start: var(--space-lg);
}

.template-course__fill {
    /* --progress is set from data-progress by template_runtime.js. */
    min-width: 0;
}

/* ── Walkthrough + orientation decks (legacy didactic.css look) ─────────── */

.template-didactic__title,
.template-orientation__title {
    margin-block-end: var(--space-md);
}

.template-orientation__error {
    padding: var(--space-md) var(--space-lg);
    background: var(--surface-raised);
    border-inline-start: 3px solid var(--error);
    border-radius: 0 var(--radius) var(--radius) 0;
    color: var(--color-error-text);
}

.didactic-component,
.orientation-component,
.didactic-deck {
    display: contents;
}

.template-didactic .didactic-slide-deck,
.template-orientation .didactic-slide-deck {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

.template-didactic .didactic-slide-deck__progress,
.template-orientation .didactic-slide-deck__progress {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    gap: var(--space-sm);
    justify-content: center;
}

.template-didactic .didactic-slide-deck__progress-dot,
.template-orientation .didactic-slide-deck__progress-dot {
    width: 0.625rem;
    height: 0.625rem;
    border-radius: 50%;
    background: var(--border);
    transition: background var(--duration-fast) var(--easing-standard);
}

.template-didactic .didactic-slide-deck__progress-dot[aria-current="step"],
.template-orientation .didactic-slide-deck__progress-dot[aria-current="step"] {
    background: var(--sage);
}

.template-didactic .didactic-slide-deck__nav,
.template-orientation .didactic-slide-deck__nav {
    display: flex;
    gap: var(--space-md);
    justify-content: space-between;
    margin-block-start: var(--space-lg);
}

.template-didactic .didactic-slide-deck__nav-button,
.template-orientation .didactic-slide-deck__nav-button {
    flex: 1 1 8rem;
}

.template-didactic .didactic-slide-deck__nav-button:disabled,
.template-orientation .didactic-slide-deck__nav-button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.didactic-slide {
    margin-block: var(--space-md);
    min-height: 6rem;
}

.didactic-slide:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    border-radius: var(--radius);
}

/* The slide the self-quiz feedback pointed at (legacy focus highlight). */
.didactic-slide[data-focus] {
    padding: var(--space-md);
    border-radius: var(--radius);
    box-shadow: 0 0 0 2px var(--sage);
    background: var(--color-white);
}

.didactic-slide__title {
    margin-block-end: var(--space-sm);
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-semibold);
    color: var(--text);
}

.didactic-slide__body {
    margin: 0;
    line-height: var(--line-height-relaxed);
    color: var(--text);
}

/* ── Self-quiz fragment (legacy .self-quiz-* look) ──────────────────────── */

.template-quiz {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.template-quiz .self-quiz-reprompt__message,
.template-quiz .self-quiz-response__slide-pointer {
    margin: 0;
    padding: var(--space-sm) var(--space-md);
    background: var(--sage-light);
    border-radius: var(--radius);
    color: var(--text);
}

.template-quiz .self-quiz-response__goal-title {
    margin: 0 0 var(--space-xs);
}

.template-quiz__thinking {
    margin: 0;
    color: var(--text-muted);
}

.template-quiz__secondary {
    align-self: center;
    color: var(--text-muted);
    font-size: var(--font-size-sm);
}

/* ── Orientation steps ──────────────────────────────────────────────────── */

.orientation-slide,
.orientation-quiz,
.orientation-picker,
.orientation-demo {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.orientation-slide[hidden],
.orientation-quiz[hidden],
.orientation-picker[hidden],
.orientation-demo[hidden] {
    display: none;
}

.orientation-picker__cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr));
    gap: var(--space-sm);
}

.orientation-picker__card {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    margin: 0; /* the global `label` rule adds a top margin to all but the first */
    padding: var(--space-md);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
}

.orientation-picker__card:has(input:checked) {
    border-color: var(--sage);
    box-shadow: 0 0 0 2px var(--sage);
}

.orientation-picker__card input {
    align-self: flex-start;
}

.orientation-picker__name {
    font-weight: var(--font-weight-semibold);
    color: var(--text);
}

.orientation-picker__summary {
    font-size: var(--font-size-sm);
    color: var(--text-subtle);
    line-height: var(--line-height-relaxed);
}

.orientation-demo__line {
    margin: 0;
    padding: var(--space-md);
    background: var(--surface);
    border-radius: var(--radius);
    font-style: italic;
    color: var(--text);
}

.orientation-demo__play {
    align-self: flex-start;
}

.orientation-demo__audio {
    display: none;
}

/* ── Practice landing ───────────────────────────────────────────────────── */

.template-practice-landing .practice-list {
    margin-block-end: var(--space-sm);
}

.template-practice-landing__label {
    margin-block: var(--space-md) var(--space-xs);
    font-weight: var(--font-weight-medium);
    color: var(--text);
}

.template-practice-landing__patient {
    margin-block: var(--space-md);
    font-weight: var(--font-weight-medium);
    color: var(--text);
}

.template-practice-landing__back {
    display: block;
    margin-block-start: var(--space-md);
    text-align: center;
    color: var(--text-muted);
    font-size: var(--font-size-sm);
}

.focus-card {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    margin-block: var(--space-md);
    padding: var(--space-md) var(--space-lg);
    background: var(--surface);
    border-inline-start: 3px solid var(--sage);
    border-radius: 0 var(--radius) var(--radius) 0;
}

.focus-card__title {
    margin: 0;
    font-weight: var(--font-weight-semibold);
    color: var(--text);
}

.focus-card__label {
    display: block;
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.focus-card__growth-moment,
.focus-card__lowest-criterion {
    color: var(--text-subtle);
    line-height: var(--line-height-relaxed);
}

/* ── Practice session ───────────────────────────────────────────────────── */

.template-practice {
    display: flex;
    flex-direction: column;
}

/* ── End surface ────────────────────────────────────────────────────────── */

.template-end form {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

.template-end__recap {
    margin-block-end: var(--space-lg);
    padding: var(--space-md) var(--space-lg);
    background: var(--surface);
    border-radius: var(--radius);
}

.template-end__recap-title {
    margin: 0 0 var(--space-sm);
    font-size: var(--font-size-base);
}

.template-end__recap-section + .template-end__recap-section {
    margin-block-start: var(--space-sm);
}

.template-end__recap-label {
    margin: 0;
    font-weight: var(--font-weight-semibold);
    color: var(--text);
}

.template-end__recap-fields {
    margin: var(--space-xs) 0 0;
    font-size: var(--font-size-sm);
}

.template-end__recap-fields dt {
    color: var(--text-muted);
}

.template-end__recap-fields dd {
    margin: 0 0 var(--space-xs);
    color: var(--text);
}

.template-end__criterion {
    display: block;
    font-size: var(--font-size-sm);
    color: var(--text-muted);
    line-height: var(--line-height-relaxed);
}

/* The capture fieldset is template-only vocabulary: grep confirms ZERO
 * legacy rules for `.capture-form`/`.capture-field` (the legacy capture
 * surface lives under `.guided-writing__capture`, style.css:3650). Scoped
 * under `.template-end` so the shared vocabulary never leaks. */
.template-end .capture-form {
    border: none;
    padding: 0;
    margin: 0;
}

.template-end .capture-form legend {
    padding: 0;
    margin-bottom: var(--space-sm);
    font-weight: var(--font-weight-semibold);
}

.template-end .capture-field {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    padding: var(--space-sm) 0;
    margin: 0;
}

.template-end .capture-field-label {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--text-muted);
}

.template-end .capture-field input[type="text"],
.template-end .capture-field textarea {
    width: 100%;
    padding: var(--space-sm);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: var(--font-size-base);
}

/* ── Not-graded completion surface ──────────────────────────────────────── */

.template-feedback .landing-card {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

/* ── Feedback page (#1994) ──────────────────────────────────────────────── */

.template-feedback {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
    max-width: 42.5rem;
    margin-inline: auto;
}

.template-feedback__header {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.template-feedback__kicker {
    margin: 0;
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.template-feedback__grade {
    margin: 0;
    font-size: var(--font-size-2xl);
    line-height: var(--line-height-tight);
    color: var(--text);
}

.template-feedback__grade[data-grade="proficient"],
.template-feedback__grade[data-grade="exemplary"] {
    color: var(--sage);
}

.template-feedback__note {
    margin: 0;
    font-size: var(--font-size-sm);
    color: var(--text-muted);
}

.template-feedback__card {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    padding: var(--space-lg) var(--space-xl);
    background: var(--surface-raised);
    border-radius: var(--radius-lg);
}

.template-feedback__label {
    margin: 0;
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.template-feedback__text {
    margin: 0;
    line-height: var(--line-height-relaxed);
}

.template-feedback__lead {
    margin: 0;
    font-size: var(--font-size-lg);
    line-height: var(--line-height-relaxed);
    color: var(--text);
}

.template-feedback__try-line {
    margin: 0;
    line-height: var(--line-height-relaxed);
    color: var(--sage);
}

.template-feedback__try-label {
    font-weight: var(--font-weight-semibold);
}

.template-feedback__rows {
    gap: 0;
    padding: var(--space-sm) var(--space-lg);
}

.template-feedback__actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-md);
}

.template-feedback__secondary {
    color: var(--sage);
    font-weight: var(--font-weight-medium);
}

.template-feedback__course-link {
    margin-inline-start: auto;
    color: var(--text-muted);
    font-size: var(--font-size-sm);
}

/* Compact criterion rows: one <details> per skill, one open at a time. */

.template-row + .template-row {
    border-top: 1px solid var(--border);
}

.template-row__summary {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    min-height: 3.25rem;
    padding-block: var(--space-sm);
    cursor: pointer;
    list-style: none;
}

.template-row__summary::-webkit-details-marker {
    display: none;
}

.template-row__summary:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    border-radius: var(--radius-sm);
}

.template-row__mark {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 999px;
    border: 2px solid var(--border);
    box-sizing: border-box;
    font-weight: var(--font-weight-semibold);
}

.template-row__mark[data-status="done"] {
    background: var(--sage);
    border-color: var(--sage);
    color: var(--color-white);
}

.template-row__mark[data-status="next"] {
    border-style: dashed;
    border-color: var(--sage);
}

.template-row__names {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.template-row__title {
    font-weight: var(--font-weight-semibold);
    color: var(--text);
}

.template-row__label {
    font-size: var(--font-size-sm);
    color: var(--text-muted);
}

.template-row__underrated,
.template-row__landed {
    align-self: flex-start;
    margin-block-start: var(--space-xs);
    padding: 2px var(--space-sm);
    border-radius: var(--radius-sm);
    background: var(--sage-light);
    color: var(--sage);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
}

.template-row__status {
    flex-shrink: 0;
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--text-muted);
}

.template-row__status[data-status="done"],
.template-row__status[data-status="next"] {
    font-weight: var(--font-weight-semibold);
    color: var(--sage);
}

.template-row__body {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    padding: 0 0 var(--space-md) calc(1.75rem + var(--space-md));
}

.criterion-block {
    min-width: 0;
}

.template-row__criterion {
    margin: 0;
    font-size: var(--font-size-sm);
    color: var(--text-subtle);
    line-height: var(--line-height-relaxed);
}

.template-row__aside {
    margin: 0;
    font-size: var(--font-size-sm);
    color: var(--text-muted);
}

.template-row__marker {
    margin: 0;
    font-size: var(--font-size-sm);
    color: var(--text-subtle);
}

.template-row__marker-mark {
    font-weight: var(--font-weight-semibold);
    color: var(--sage);
}

/* Quoted exchange: patient turns on mint, the clinician's on ink. */

.template-exchange {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.template-exchange__turn {
    margin: 0;
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-lg);
    background: var(--surface);
    font-size: var(--font-size-sm);
    line-height: var(--line-height-relaxed);
    color: var(--text);
}

.template-exchange__turn[data-role="clinician"] {
    background: var(--text);
    color: var(--color-white);
}

.template-exchange__who {
    font-weight: var(--font-weight-semibold);
}

.template-exchange__text {
    overflow-wrap: anywhere;
}

/* Thumbs up/down. */

.template-reaction {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.template-reaction__form {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-sm);
}

.template-reaction__prompt,
.template-reaction__thanks {
    font-size: var(--font-size-sm);
    color: var(--text-muted);
}

.template-reaction__button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.75rem;
    height: 2.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface-raised);
    color: var(--text-muted);
    cursor: pointer;
}

.template-reaction__button[aria-pressed="true"] {
    border-color: var(--sage);
    background: var(--sage-light);
    color: var(--sage);
}

.template-reaction__button:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.template-reaction__note {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.template-reaction__note-label {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    font-size: var(--font-size-xs);
    color: var(--text-muted);
}

.template-reaction__note-input,
.template-try__input {
    width: 100%;
    box-sizing: border-box;
    padding: var(--space-sm) var(--space-md);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: var(--font-size-sm);
    color: var(--text);
    resize: vertical;
}

.template-reaction__note-send {
    align-self: flex-start;
}

.template-reaction__noted {
    margin: 0;
    font-size: var(--font-size-sm);
    color: var(--text-muted);
}

/* Try it now. */

.template-try {
    border: 2px solid var(--sage);
}

.template-try__label {
    color: var(--sage);
}

.template-try__setup {
    margin: 0;
    color: var(--text-subtle);
    line-height: var(--line-height-relaxed);
}

.template-try__attempt {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.template-try__checking {
    margin: 0;
    font-size: var(--font-size-sm);
    color: var(--text-muted);
}

.template-try__result {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin: 0;
    font-weight: var(--font-weight-semibold);
    color: var(--text);
}

.template-try__mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 999px;
    border: 2px solid var(--border);
    box-sizing: border-box;
}

.template-try__mark[data-result="landed"] {
    background: var(--sage);
    border-color: var(--sage);
    color: var(--color-white);
}

.template-try__guidance {
    margin: 0;
    color: var(--text-subtle);
    line-height: var(--line-height-relaxed);
}

.template-try__form {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.template-try__field {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
}

.template-try__input {
    font-size: var(--font-size-base);
}

.template-try__error {
    margin: 0;
    color: var(--color-error-text);
    font-size: var(--font-size-sm);
}

.template-try__actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-md);
}

/* The legacy .btn-primary is full-width; these actions sit inline. */
.template-try__send,
.template-feedback__actions .btn {
    width: auto;
    min-height: 2.75rem;
}

.template-try__sending {
    display: none;
    font-size: var(--font-size-sm);
    color: var(--text-muted);
}

.template-try__form.htmx-request .template-try__sending {
    display: inline;
}

.template-try__left {
    margin-inline-start: auto;
    font-size: var(--font-size-sm);
    color: var(--text-muted);
}

.template-try__done {
    margin: 0;
    font-size: var(--font-size-sm);
    color: var(--text-muted);
}

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

@media (max-width: 39.99em) {
    .template-feedback__card {
        padding: var(--space-lg);
    }

    .template-row__body {
        padding-inline-start: 0;
    }

    .template-feedback__course-link {
        margin-inline-start: 0;
    }

    .orientation-picker__cards {
        grid-template-columns: 1fr;
    }
}

/* Study enrollment: the once-only list of freshly generated participant
   codes (admin/enrollment.html). */
.new-codes-table {
    border-collapse: collapse;
    margin: var(--space-sm) 0 var(--space-md);
}
.new-codes-table th,
.new-codes-table td {
    text-align: left;
    padding: var(--space-xs) var(--space-md) var(--space-xs) 0;
    border-bottom: 1px solid var(--color-border);
}
