/* Report Templates. Scoped under .report-templates.
   Tokens match the design preview. Cards use white because the preview's
   Bootstrap --bs-body-bg is #fff, while this app's body background is grey. */
.report-templates {
    --rt-ink: var(--bs-body-color);
    --rt-muted: var(--bs-secondary-color);
    --rt-line: var(--bs-border-color);
    --rt-surface: var(--bs-white, #fff);
    --rt-canvas: #f8f9fa;
    --rt-tint: color-mix(in srgb, var(--bs-primary) 7%, var(--bs-white, #fff));
    flex: 1 0 auto;
    min-height: 100%;
    background: var(--rt-canvas);
    color: var(--rt-ink);
    font: 600 13px/1.5 "Nunito", sans-serif;
    text-align: left;
}

.report-templates *,
.report-templates *::before,
.report-templates *::after { box-sizing: border-box; }

.report-templates button,
.report-templates input,
.report-templates select,
.report-templates textarea { font: inherit; }

.report-templates button { cursor: pointer; }

.report-templates svg { flex-shrink: 0; }

.report-templates button:focus-visible,
.report-templates input:focus-visible,
.report-templates select:focus-visible,
.report-templates textarea:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--bs-primary) 35%, transparent);
    outline-offset: 3px;
}

.report-templates h1,
.report-templates h2,
.report-templates h3,
.report-templates p { margin: 0; }

.report-templates .rt-main {
    max-width: 1440px;
    margin: 0 auto;
    padding: 24px 32px 28px;
}

.report-templates .rt-breadcrumb {
    display: flex;
    gap: 8px;
    align-items: center;
    color: var(--rt-muted);
    font-size: 11px;
    margin-bottom: 19px;
}

.report-templates .rt-breadcrumb a {
    color: inherit;
    text-decoration: none;
}

.report-templates .rt-pagehead {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    margin-bottom: 24px;
}

.report-templates h1 {
    font-size: 28px;
    font-weight: 900;
    letter-spacing: -.04em;
    margin-bottom: 4px;
}

.report-templates .rt-pagehead p {
    color: var(--rt-muted);
    font-size: 12px;
}

.report-templates .rt-layout {
    display: grid;
    grid-template-columns: 274px minmax(0, 1fr);
    gap: 20px;
    align-items: start;
}

.report-templates .rt-card {
    border: 1px solid var(--rt-line);
    border-radius: 16px;
    background: var(--rt-surface);
    min-width: 0;
    box-shadow: 0 4px 14px color-mix(in srgb, var(--rt-ink) 3%, transparent);
    overflow: hidden;
}

.report-templates .rt-rail-head {
    padding: 19px 18px 15px;
    border-bottom: 1px solid var(--rt-line);
}

.report-templates h2 {
    font-size: 17px;
    font-weight: 900;
    letter-spacing: -.025em;
}

.report-templates .rt-rail-head h2 {
    font-size: 14px;
    margin: 0;
}

.report-templates .rt-count {
    color: var(--rt-muted);
    font-weight: 600;
    margin-left: 5px;
    font-size: 11px;
}

.report-templates .rt-type-add {
    display: grid;
    gap: 10px;
    padding: 14px 16px 16px;
    border-bottom: 1px solid var(--rt-line);
}

.report-templates .rt-type-add > .rt-btn { justify-self: start; }

.report-templates .rt-field {
    display: grid;
    align-content: start;
    gap: 6px;
    font-size: 11px;
    font-weight: 800;
    min-width: 0;
    margin: 0;
}

.report-templates .rt-field.full { grid-column: 1 / -1; }

.report-templates .rt-field input,
.report-templates .rt-field select,
.report-templates .rt-field textarea {
    min-width: 0;
    width: 100%;
    border: 1px solid var(--rt-line);
    border-radius: 8px;
    background: var(--rt-surface);
    padding: 9px 10px;
    color: var(--rt-ink);
    font-size: 12px;
    font-weight: 600;
}

.report-templates .rt-field textarea {
    min-height: 86px;
    resize: vertical;
}

.report-templates .rt-field textarea.rt-question-text { min-height: 100px; }

.report-templates .rt-btn {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--rt-line);
    border-radius: 8px;
    padding: 8px 12px;
    min-height: 36px;
    background: var(--rt-surface);
    color: var(--rt-ink);
    font-size: 12px;
    font-weight: 800;
    line-height: 1.4;
    white-space: nowrap;
}

.report-templates .rt-btn:hover {
    background: var(--rt-tint);
    border-color: var(--bs-primary);
    color: var(--bs-primary);
}

.report-templates .rt-btn.primary {
    color: var(--bs-white);
    background: var(--bs-primary);
    border-color: var(--bs-primary);
}

.report-templates .rt-btn.primary:hover {
    filter: brightness(.94);
    color: var(--bs-white);
    background: var(--bs-primary);
}

.report-templates .rt-btn.outline { color: var(--bs-primary); }

.report-templates .rt-btn.small {
    font-size: 11px;
    min-height: 30px;
    padding: 5px 9px;
}

.report-templates .rt-btn.danger-outline {
    color: var(--bs-danger);
    border-color: color-mix(in srgb, var(--bs-danger) 45%, var(--rt-line));
}

.report-templates .rt-btn.danger-outline:hover {
    background: var(--bs-danger-bg-subtle);
    color: var(--bs-danger);
    border-color: var(--bs-danger);
}

.report-templates .rt-btn:disabled {
    cursor: not-allowed;
    opacity: .4;
}

.report-templates .rt-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.report-templates .rt-types { padding: 10px; }

.report-templates .rt-syllabus {
    border: 1px solid transparent;
    border-radius: 10px;
    padding: 13px 11px;
    margin-bottom: 5px;
}

.report-templates .rt-syllabus.selected {
    background: var(--rt-tint);
    border-color: color-mix(in srgb, var(--bs-primary) 25%, var(--rt-surface));
}

.report-templates .rt-syllabus:not(.selected) { border-color: transparent; }

.report-templates .rt-type-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.report-templates .rt-type-copy {
    flex: 1;
    min-width: 0;
    display: grid;
    justify-items: start;
    gap: 5px;
}

.report-templates .rt-type-copy strong {
    font-size: 13px;
    font-weight: 900;
    overflow-wrap: anywhere;
}

.report-templates .rt-syllabus.selected .rt-type-copy strong { color: var(--bs-primary); }

.report-templates .rt-type-editing {
    display: grid;
    gap: 10px;
    border-color: var(--rt-line) !important;
    background: color-mix(in srgb, var(--rt-canvas) 50%, var(--rt-surface));
}

.report-templates .rt-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    border-radius: 999px;
    padding: 3px 8px;
    font-size: 9px;
    font-weight: 800;
    background: var(--rt-canvas);
    color: var(--rt-muted);
    white-space: nowrap;
}

.report-templates .rt-icon-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    margin-left: auto;
}

.report-templates .rt-icon-btn {
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    border: 1px solid var(--rt-line);
    border-radius: 8px;
    background: var(--rt-surface);
    color: var(--rt-muted);
    padding: 0;
}

.report-templates .rt-icon-btn:hover {
    border-color: var(--bs-primary);
    color: var(--bs-primary);
    background: var(--rt-tint);
}

.report-templates .rt-icon-btn.danger { color: var(--bs-danger); }

.report-templates .rt-icon-btn.danger:hover {
    border-color: var(--bs-danger);
    background: var(--bs-danger-bg-subtle);
    color: var(--bs-danger);
}

.report-templates .rt-work-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 22px 24px 18px;
}

.report-templates .rt-sheet-backdrop,
.report-templates .rt-sheet-close { display: none; }

.report-templates .rt-heading-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.report-templates .rt-award-icon {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: 11px;
    background: var(--rt-tint);
    color: var(--bs-primary);
}

.report-templates .rt-eyebrow {
    font-size: 9px;
    letter-spacing: .1em;
    text-transform: uppercase;
    font-weight: 900;
    color: var(--rt-muted);
    display: block;
    margin-bottom: 3px;
}

.report-templates .rt-work-head h2 { font-size: 21px; }

.report-templates .rt-work-body {
    padding: 20px 24px 22px;
    border-top: 1px solid var(--rt-line);
}

.report-templates .rt-qform {
    display: grid;
    gap: 14px;
}

.report-templates .rt-req {
    color: var(--bs-danger);
    margin-left: 2px;
}

.report-templates .rt-form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 15px;
}

.report-templates .rt-field.rt-type { max-width: 320px; }

.report-templates .rt-field-error {
    color: var(--bs-danger);
    font-size: 11px;
    margin-top: 6px;
}

.report-templates .rt-options {
    display: grid;
    gap: 9px;
    padding: 13px;
    border: 1px solid var(--rt-line);
    border-radius: 10px;
    background: color-mix(in srgb, var(--rt-canvas) 40%, var(--rt-surface));
}

.report-templates .rt-options-label {
    font-size: 11px;
    font-weight: 800;
}

.report-templates .rt-option-add { display: flex; gap: 8px; }

.report-templates .rt-option-add input {
    flex: 1;
    min-width: 0;
    border: 1px solid var(--rt-line);
    border-radius: 8px;
    background: var(--rt-surface);
    padding: 8px 10px;
    color: var(--rt-ink);
    font-size: 12px;
    font-weight: 600;
}

.report-templates .rt-option-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 6px;
}

.report-templates .rt-option {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding: 6px 6px 6px 13px;
    border-radius: 999px;
    background: var(--rt-tint);
    border: 1px solid color-mix(in srgb, var(--bs-primary) 18%, var(--rt-line));
    font-size: 12px;
    font-weight: 700;
}

.report-templates .rt-option > span {
    flex: 1;
    min-width: 100px;
}

.report-templates .rt-option-actions { display: flex; gap: 4px; }

.report-templates .rt-option-actions .rt-btn {
    border-radius: 999px;
    min-width: 30px;
}

.report-templates .rt-divider {
    border: 0;
    border-top: 1px solid var(--rt-line);
    margin: 22px 0 10px;
    opacity: 1;
}

.report-templates .rt-questions {
    list-style: none;
    margin: 0;
    padding: 0;
}

.report-templates .rt-question {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 4px;
    border-bottom: 1px solid var(--rt-line);
}

.report-templates .rt-question:last-child { border-bottom: 0; }

.report-templates .rt-question-copy {
    flex: 1;
    min-width: 0;
    font-size: 13px;
    font-weight: 700;
    overflow-wrap: anywhere;
}

.report-templates .rt-question.editing {
    display: block;
    padding: 14px;
    margin: 8px 0;
    border: 1px solid color-mix(in srgb, var(--bs-primary) 30%, var(--rt-line));
    border-radius: 12px;
    background: color-mix(in srgb, var(--rt-tint) 60%, var(--rt-surface));
}

.report-templates .rt-empty {
    padding: 35px 20px;
    text-align: center;
    color: var(--rt-muted);
    display: grid;
    justify-items: center;
    gap: 9px;
}

.report-templates .rt-empty strong { color: var(--rt-ink); }

.report-templates .rt-soft-empty {
    border-top: 1px solid var(--rt-line);
    padding: 60px 24px;
    background: color-mix(in srgb, var(--rt-canvas) 45%, var(--rt-surface));
}

.report-templates .rt-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--rt-line);
    font-size: 10px;
    color: var(--rt-muted);
    display: flex;
    align-items: center;
    gap: 7px;
}

@media (max-width: 1000px) {
    .report-templates .rt-main { padding: 20px; }
    .report-templates .rt-layout {
        grid-template-columns: 235px minmax(0, 1fr);
        gap: 14px;
    }
    .report-templates .rt-pagehead { align-items: flex-start; }
    .report-templates .rt-work-head { padding-left: 18px; padding-right: 18px; }
}

@media (max-width: 767px) {
    .report-templates .rt-main { padding: 17px 12px; }
    .report-templates .rt-layout { grid-template-columns: minmax(0, 1fr); }
    .report-templates .rt-pagehead {
        display: block;
        margin-bottom: 19px;
    }
    .report-templates h1 { font-size: 25px; }
    .report-templates .rt-btn {
        font-size: 11px;
        padding: 7px 10px;
    }
    .report-templates .rt-rail-head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        padding: 13px;
    }
    .report-templates .rt-rail-head h2 { margin: 0; }
    .report-templates .rt-syllabus {
        padding: 11px;
        margin: 0 0 4px;
    }
    .report-templates .rt-work-head { padding: 18px 16px; }
    .report-templates .rt-work-head h2 { font-size: 19px; }
    .report-templates .rt-form-grid { grid-template-columns: minmax(0, 1fr); }
    .report-templates .rt-type-add { padding: 13px; }
    .report-templates .rt-types { padding: 7px; }
    .report-templates .rt-icon-btn {
        width: 36px;
        height: 36px;
    }
    .report-templates .rt-type-row { flex-wrap: wrap; }
    .report-templates .rt-type-copy { min-width: 120px; }
    .report-templates .rt-work-body { padding: 16px 14px 18px; }
    .report-templates .rt-question { flex-wrap: wrap; }
    .report-templates .rt-question-copy { min-width: 180px; }
    .report-templates .rt-type-add > .rt-btn,
    .report-templates .rt-qform .rt-btn.primary { width: 100%; }
    .report-templates .rt-questions-panel { display: none; }
    .report-templates .rt-questions-panel .rt-footer { display: none; }
    body:has(.report-templates.rt-sheet-open) .authorized-layout__main { overflow: hidden; }
    .report-templates.rt-sheet-open .rt-sheet-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 1040;
        border: 0;
        padding: 0;
        background: color-mix(in srgb, var(--bs-dark) 42%, transparent);
    }
    .report-templates.rt-sheet-open .rt-questions-panel {
        display: flex;
        flex-direction: column;
        position: fixed;
        z-index: 1050;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: min(92dvh, 100svh);
        max-height: min(92dvh, 100svh);
        border-radius: 18px 18px 0 0;
        border-bottom: 0;
        animation: rt-sheet .2s ease;
    }
    .report-templates.rt-sheet-open .rt-questions-panel .rt-work-head {
        position: relative;
        flex: 0 0 auto;
        align-items: center;
        padding: 22px 16px 14px;
    }
    .report-templates.rt-sheet-open .rt-questions-panel .rt-work-head::before {
        content: "";
        position: absolute;
        left: 50%;
        top: 8px;
        width: 36px;
        height: 4px;
        border-radius: 2px;
        background: var(--rt-line);
        transform: translateX(-50%);
    }
    .report-templates.rt-sheet-open .rt-sheet-close {
        display: grid;
        place-items: center;
        width: 36px;
        height: 36px;
        flex-shrink: 0;
        border: 0;
        border-radius: 8px;
        background: transparent;
        color: var(--rt-muted);
        padding: 0;
    }
    .report-templates.rt-sheet-open .rt-sheet-close:hover {
        background: var(--rt-tint);
        color: var(--bs-primary);
    }
    .report-templates.rt-sheet-open .rt-questions-panel .rt-work-body {
        flex: 1 1 auto;
        min-height: 0;
        overflow-y: auto;
        padding-bottom: calc(18px + env(safe-area-inset-bottom, 0px));
    }
}

@keyframes rt-sheet {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

@media (hover: none) and (pointer: coarse) {
    .report-templates .rt-field input,
    .report-templates .rt-field select,
    .report-templates .rt-field textarea,
    .report-templates .rt-option-add input { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
    .report-templates * { animation: none !important; }
}
