/* CSR Authoring, Patient narratives: the rules notice, the case list and the selection rules dialog. */
.csr-narratives {
    display: flex;
    flex-direction: column;
    gap: 0.875rem;
    padding: 0.5rem 0;
}

.csr-narratives-message {
    padding: 1rem;
    color: var(--cai-muted);
}

.csr-narratives-content {
    display: flex;
    flex-direction: column;
    gap: 0.875rem;
}

.csr-narratives-content[hidden],
.csr-narratives-message[hidden],
.csr-narratives-warning[hidden],
.csr-narratives-muted[hidden],
.csr-authoring-workspace-narratives[hidden] {
    display: none;
}

/* As the mockup: the title above the timeline date setting on the left; the muted meta line above the actions on
   the right. */
.csr-narratives-header {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 0.5rem 1rem;
    align-items: center;
}

/* One line; the full text is its tooltip. */
.csr-narratives-meta {
    min-width: 0;
    overflow: hidden;
    color: var(--cai-muted);
    font-size: 0.75rem;
    line-height: 1.5;
    text-align: right;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.csr-narratives-dates {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    justify-self: start;
}

.csr-narratives-dates > .csr-narratives-muted {
    font-size: 0.8125rem;
    white-space: nowrap;
}

/* nphase-wc fields take min(100%, --input-max-width), 28.75rem by default; these are compact. */
.csr-narratives-dates > :last-child {
    --input-max-width: 9rem;
    --label-width: 0rem;
    --label-input-gap: 0rem;
    width: 9rem;
}

@media (max-width: 73.75rem) {
    .csr-narratives-header {
        grid-template-columns: 1fr;
    }

    .csr-narratives-meta {
        text-align: left;
    }
}

.csr-narratives-title {
    font-size: 1.0625rem;
    font-weight: 600;
}

.csr-narratives-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    flex-wrap: wrap;
}

.csr-narratives-muted {
    color: var(--cai-muted);
    font-size: 0.875rem;
}

.csr-narratives-warning {
    color: var(--cai-warn);
    font-size: 0.875rem;
}

.csr-narratives-attest {
    padding: 0.625rem 0.75rem;
    border: 0.0625rem solid var(--cai-rule);
    border-radius: 0.375rem;
    background: var(--cai-inset);
    font-size: 0.875rem;
}

.csr-narratives-status {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.csr-narratives-rules {
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
}

.csr-narratives-rule {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    padding: 0.625rem 0.75rem;
    border: 0.0625rem solid var(--cai-rule);
    border-radius: 0.375rem;
}

.csr-narratives-rule-head {
    display: flex;
    gap: 0.5rem;
    font-weight: 600;
}

.csr-narratives-rule-id {
    color: var(--cai-ink);
}

.csr-narratives-facts {
    display: grid;
    grid-template-columns: minmax(9rem, max-content) 1fr;
    gap: 0.25rem 0.75rem;
    font-size: 0.875rem;
}

.csr-narratives-fact-label {
    color: var(--cai-muted);
}

.csr-narratives-expression {
    font-family: var(--csr-mono, ui-monospace, monospace);
    font-size: 0.8125rem;
}

.csr-narratives-adjustment {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.csr-narratives-list {
    margin: 0.25rem 0 0;
    padding-left: 1.25rem;
}

/* One compact line, as the mockup: search, the two selects, the checkbox, and the counts on the right. */
.csr-narratives-toolbar {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    flex-wrap: wrap;
    font-size: 0.8125rem;
}

.csr-narratives-counts > .csr-narratives-muted {
    font-size: 0.8125rem;
    white-space: nowrap;
}

/* The mockup's widths, so the line fits from 1280 px. */
.csr-narratives-toolbar > .csr-narratives-search {
    --input-max-width: 12.5rem;
    --label-width: 0rem;
    --label-input-gap: 0rem;
    flex: none;
    width: 12.5rem;
}

/* The counts and the coverage count stay together on one line, right-aligned. */
.csr-narratives-counts {
    display: flex;
    gap: 0.75rem;
    margin-left: auto;
    white-space: nowrap;
}

.csr-narratives-toolbar > .csr-narratives-select {
    --input-max-width: 10rem;
    --label-width: 0rem;
    --label-input-gap: 0rem;
    flex: none;
    width: 10rem;
}

.csr-narratives-toolbar[hidden] {
    display: none;
}

.csr-narratives-spacer {
    flex: 1;
}

/* The grid shell sits in the case list card's block body, where the page's flex sizing of grid shells leaves it no
   definite height: the grid's viewport resolved to 0 and only the pager showed. The surface sets its height from
   CsrNarrativeCaseListLayout; here it stops flexing. Three classes outrank the page's two. */
.csr-narratives .csr-narratives-grid.app-grid-page-grid-shell {
    flex: none;
    --ag-cell-horizontal-padding: 0.5rem;
}

/* Directly under the filters: the case list (about 38%) and the case with its card, top-aligned. */
.csr-narratives-split {
    display: grid;
    grid-template-columns: minmax(24rem, 42%) minmax(0, 1fr);
    gap: 0.875rem;
    align-items: start;
}

.csr-narratives-split.csr-narratives-collapsed {
    grid-template-columns: minmax(0, 1fr);
}

.csr-narratives-split.csr-narratives-collapsed > :first-child {
    display: none;
}

.csr-narratives-list-toggle {
    display: flex;
    justify-content: flex-end;
    padding-top: 0.25rem;
}

.csr-narratives-detail > [data-testid="csr-narratives-expand"] {
    align-self: flex-start;
}

.csr-narratives-message-inline {
    color: var(--cai-muted);
    font-size: 0.875rem;
}

@media (max-width: 60rem) {
    .csr-narratives-split {
        grid-template-columns: 1fr;
    }
}

.csr-narratives-case-section {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin-top: 0.625rem;
}

.csr-narratives-list-heading {
    font-weight: 600;
    font-size: 0.875rem;
}

/* The case shown and its narrative card, beside the case list. */
.csr-narratives-detail {
    display: flex;
    flex-direction: column;
    gap: 0.875rem;
    min-width: 0;
}

.csr-narratives-card {
    display: flex;
    flex-direction: column;
    gap: 0.875rem;
}

/* Five tabs at the library's medium padding outgrow the card beside the case list at 1280px and the AI tab spilled
   past its edge; compact padding fits them, and the strip scrolls rather than spills when a Checks count widens it. */
.csr-narratives-card nph-tab-panel {
    --nwc-tabs-nav-overflow-x: auto;
    --nwc-tabs-padding: .625rem .875rem;
}

.csr-narratives-card [hidden],
.csr-narratives-detail [hidden] {
    display: none;
}

.csr-narratives-pane {
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
    padding: 0.625rem 0;
}

.csr-narratives-text {
    font-family: "Source Serif 4", "Source Serif Pro", Georgia, "Times New Roman", serif;
    font-size: 0.9375rem;
    line-height: 1.6;
}

.csr-narratives-text p {
    margin: 0 0 0.625rem;
}

.csr-narratives-text[contenteditable] {
    padding: 0.5rem 0.75rem;
    border: 0.0625rem solid var(--cai-rule-strong);
    border-radius: 0.375rem;
    outline: none;
}

/* A cited fact as the mockup's chip: green when it matches its record, solid red with white text when a finding is
   open on it, grey while the checks have not compared it. Uncoloured (as in the review dialog and while editing) it
   reads as unchecked. */
.csr-narratives-fact {
    padding: 0 0.25rem;
    border-radius: 0.25rem;
    border-bottom: 0.09375rem dotted var(--cai-muted);
    background: var(--cai-hover);
    color: var(--cai-ink);
    font-variant-numeric: tabular-nums;
    cursor: pointer;
}

.csr-narratives-fact--matches {
    border-bottom-color: var(--cai-ok);
    background: var(--cai-duck-soft);
    color: #1f7f64;
}

.csr-narratives-fact--attention {
    border-bottom-color: var(--cai-err);
    background: var(--cai-err);
    color: #fff;
}

.csr-narratives-fact[role="button"]:hover,
.csr-narratives-fact--chosen {
    background: var(--cai-muted);
    color: #fff;
}

.csr-narratives-fact--matches[role="button"]:hover,
.csr-narratives-fact--matches.csr-narratives-fact--chosen {
    background: var(--cai-ok);
}

.csr-narratives-fact--attention[role="button"]:hover,
.csr-narratives-fact--attention.csr-narratives-fact--chosen {
    background: #8e2a20;
}

.csr-narratives-fact:focus-visible {
    outline: 0.125rem solid var(--cai-ok);
    outline-offset: 0.0625rem;
}

/* ── source panel: where a cited fact comes from, in the shared side panel (side-panel.css) ───────────── */

.csr-narratives-panel-claim {
    margin: 0;
    padding: 0.5rem 0.75rem;
    border-left: 0.1875rem solid var(--cai-ok);
    background: var(--nwc-ui-surface-soft);
    font-family: "Source Serif 4", "Source Serif Pro", Georgia, "Times New Roman", serif;
    font-size: 1.0625rem;
}

/* nphase-wc sets the font of every element (*), so the quote's own text nodes' spans need theirs. */
.csr-narratives-panel-cited {
    font-family: inherit;
    font-size: inherit;
    font-weight: 600;
}

.csr-narratives-panel-verdict {
    padding: 0.625rem 0.75rem;
    border-radius: 0.5rem;
    font-size: 0.9375rem;
}

.csr-narratives-panel-verdict--matches,
.csr-narratives-panel-verdict--dismissed {
    background: var(--cai-duck-soft);
    color: #145e43;
}

.csr-narratives-panel-verdict--attention {
    background: var(--cai-rest-soft);
    color: #8e2a20;
}

.csr-narratives-panel-verdict--unchecked {
    background: var(--cai-hover);
    color: var(--cai-muted);
}

.csr-narratives-panel-record {
    padding: 0.75rem;
    border: 0.0625rem solid var(--cai-rule);
    border-radius: 0.375rem;
}

.csr-narratives-panel-caption {
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    font-weight: 700;
}

.csr-narratives-panel-scroll {
    overflow-x: auto;
}

.csr-narratives-panel-table {
    width: 100%;
    border-collapse: collapse;
    font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.71875rem;
}

.csr-narratives-panel-table th,
.csr-narratives-panel-table td {
    font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.8125rem;
    line-height: 1.45;
    padding: 0.25rem 0.375rem;
    border-bottom: 0.0625rem solid var(--nwc-ui-border);
    text-align: left;
    white-space: nowrap;
}

.csr-narratives-panel-table th {
    font-weight: 700;
}

.csr-narratives-panel-table td:not(:first-child),
.csr-narratives-panel-table th:not(:first-child) {
    text-align: right;
}

.csr-narratives-panel-cell--matches,
.csr-narratives-panel-cell--attention,
.csr-narratives-panel-cell--unchecked {
    border-radius: 0.1875rem;
    color: #fff;
    font-weight: 700;
}

.csr-narratives-panel-cell--matches {
    background: var(--cai-ok);
}

.csr-narratives-panel-cell--attention {
    background: var(--cai-err);
}

.csr-narratives-panel-cell--unchecked {
    background: var(--cai-muted);
}

.csr-narratives-panel-lineage {
    margin: 0;
    padding: 0;
    list-style: none;
}

.csr-narratives-panel-lineage li {
    position: relative;
    padding: 0 0 0.875rem 1.5rem;
    font-size: 0.9375rem;
    line-height: 1.45;
}

.csr-narratives-panel-lineage strong,
.csr-narratives-panel-step {
    font-size: 0.9375rem;
    line-height: 1.45;
}

.csr-narratives-panel-lineage strong {
    font-weight: 700;
}

.csr-narratives-panel-lineage li::before {
    content: "";
    position: absolute;
    top: 0.375rem;
    left: 0.375rem;
    width: 0.5625rem;
    height: 0.5625rem;
    border-radius: 50%;
    background: var(--cai-ok);
    box-shadow: 0 0 0 0.1875rem var(--cai-duck-soft);
}

.csr-narratives-panel-lineage li::after {
    content: "";
    position: absolute;
    top: 1rem;
    bottom: -0.125rem;
    left: 0.625rem;
    width: 0.0625rem;
    background: var(--cai-rule);
}

.csr-narratives-panel-lineage li:last-child::after {
    display: none;
}

.csr-narratives-panel-step {
    margin-left: 0.25rem;
}

.csr-narratives-panel-lineage small {
    display: block;
    color: var(--cai-muted);
    font-size: 0.8rem;
    line-height: 1.45;
}

.csr-narratives-claim {
    font-style: italic;
}

.csr-narratives-highlight {
    font-weight: 600;
    color: var(--cai-ink);
    background: var(--cai-fs-soft);
}

.csr-narratives-timeline {
    margin: 0;
    padding-left: 1.25rem;
}

.csr-narratives-link {
    border: 0;
    padding: 0;
    background: none;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
    text-decoration: underline dotted;
}

.csr-narratives-qualifying {
    font-weight: 600;
}

.csr-narratives-drafting {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.csr-narratives-kept {
    white-space: pre-wrap;
    user-select: text;
    font-family: "Source Serif 4", "Source Serif Pro", Georgia, "Times New Roman", serif;
}

/* Case list cells: stacked status pills, and open findings in red or a muted dash. */
.csr-narratives-pills {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.125rem;
    padding: 0.25rem 0;
    line-height: 1.2;
}

.csr-narratives-open {
    color: var(--cai-muted);
}

.csr-narratives-open-attention {
    color: var(--cai-err);
    font-weight: 600;
}

.csr-narratives-case-id {
    font-family: var(--csr-mono, ui-monospace, monospace);
    font-size: 0.8125rem;
}

/* The narrative card's status pills, in a row under its heading as the mockup. */
.csr-narratives-pill-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
}

/* The feature owns its palette; geometry and semantic tone belong to Badge. */
.csr-narratives-pill {
    --nwc-badge-neutral-background: var(--nwc-raw-gray-50, var(--cai-inset));
    --nwc-badge-neutral-color: var(--cai-muted);
    --nwc-badge-neutral-border-color: var(--cai-rule);
    --nwc-badge-informative-background: var(--cai-sql-soft);
    --nwc-badge-informative-color: var(--cai-sql);
    --nwc-badge-positive-background: var(--csr-ok-soft, var(--cai-duck-soft));
    --nwc-badge-positive-color: var(--csr-ok, var(--cai-ok));
    --nwc-badge-notice-background: var(--csr-ai-soft, var(--nwc-warning-subtle));
    --nwc-badge-notice-color: var(--csr-ai, var(--cai-warn));
    --nwc-badge-negative-background: var(--csr-bad-soft, var(--cai-rest-soft));
    --nwc-badge-negative-color: var(--csr-bad, var(--cai-err));
}

/* Reason: at most CsrNarrativeCaseListLayout.REASON_LINES lines (the clamp is set per cell), ending in an ellipsis. */
.csr-narratives-reason {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.125rem;
    white-space: normal;
    word-break: normal;
    overflow-wrap: break-word;
    padding: 0.3125rem 0;
}

/* Generate narrative drafts: the cases as a compact table that scrolls inside the dialog, so its footer stays in
   view. */
.csr-narratives-table-scroll {
    max-height: min(50vh, 28rem);
    overflow: auto;
    border: 0.0625rem solid var(--cai-rule);
    border-radius: 0.375rem;
}

.csr-narratives-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
}

.csr-narratives-table th {
    position: sticky;
    top: 0;
    padding: 0.5rem 0.625rem;
    background: var(--cai-inset);
    color: var(--cai-muted);
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-align: left;
    text-transform: uppercase;
}

.csr-narratives-table td {
    padding: 0.4375rem 0.625rem;
    border-top: 0.0625rem solid var(--cai-rule);
    vertical-align: top;
}

.csr-narratives-table td {
    overflow-wrap: break-word;
}

/* A failed draft's reason and the fields a call sent wrap within the Action column, clamped; tooltips hold the rest. */
.csr-narratives-failure,
.csr-narratives-clamped {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-top: 0.25rem;
    line-height: 1.35;
    white-space: normal;
    overflow-wrap: anywhere;
}

.csr-narratives-failure {
    color: var(--cai-err);
}

.csr-narratives-failure .csr-narratives-muted {
    font-size: 0.75rem;
}

/* Information requests on the Checks and information tab: each row opens its request. */
.csr-narratives-request-row {
    cursor: pointer;
}

.csr-narratives-request-row:hover,
.csr-narratives-request-row:focus-visible {
    background: var(--cai-inset);
    outline: none;
}

.csr-narratives-request-item {
    font-weight: 600;
}

/* The status cell on one line, as the mockup's "sent 20 Oct · open". */
.csr-narratives-request-status {
    flex-wrap: nowrap;
    align-items: center;
    white-space: nowrap;
}

.csr-narratives-request-sent::after {
    content: "\00B7";
    margin-left: 0.375rem;
    color: var(--cai-muted);
}

/* Request missing information: a small button at the end of the heading row it sits in. */
.csr-narratives-status > .csr-narratives-request-button {
    margin-left: auto;
}

/* The information request dialogs, with the mockup's 16px title and 13px text. In px, and on the text elements
   themselves: the library sizes every element from the viewport (`* { font-size: clamp(...) }`), so neither rem nor a
   size on a container gives 13px. The mockup's 520px assumes labels above the fields; with the library's labels on
   the left, 640px leaves the fields room for the longest content item. Two classes outrank the library's one. */
.csr-narratives-info-dialog .wc-ui-modal-card {
    width: min(640px, calc(100vw - 2rem));
}

.csr-narratives-info-dialog .wc-ui-modal-title {
    font-size: 16px;
    line-height: 1.35;
}

.csr-narratives-info-dialog .wc-ui-modal-body-content div,
.csr-narratives-info-dialog .wc-ui-modal-body-content li {
    font-size: 13px;
}

.csr-narratives-info-dialog .wc-ui-modal-body-content .csr-narratives-muted,
.csr-narratives-info-dialog .wc-ui-modal-body-content .csr-narratives-attest,
.csr-narratives-info-dialog .wc-ui-modal-body-content .csr-narratives-warning {
    font-size: 12px;
}

.csr-narratives-info-dialog .csr-narratives-facts {
    grid-template-columns: minmax(9rem, max-content) minmax(0, 1fr);
    overflow-wrap: anywhere;
}

/* Nothing may widen the card: every grid track and field can shrink. A field's control column is exactly what its
   label leaves (--input-max-width, which the library also uses as the control's max-width), so the combobox shrinks
   with it and ellipsizes its selected text before the arrow instead of running past the card. */
.csr-narratives-info-dialog .wc-ui-modal-body,
.csr-narratives-info-dialog .wc-ui-modal-body-wrap,
.csr-narratives-info-dialog .wc-ui-modal-body-content,
.csr-narratives-info-dialog .wc-ui-form {
    grid-template-columns: minmax(0, 1fr);
    min-width: 0;
}

.csr-narratives-info-dialog .wc-ui-form > * {
    --input-max-width: calc(100% - var(--label-width) - var(--label-input-gap));
    min-width: 0;
    max-width: 100%;
}

/* The label column only as wide as the longest label with its required marker needs (rem, as the labels are), not
   the library's 10.5rem: "Missing item" when requesting; "Reason for withdrawing" in a request's own dialog, where
   "Supporting source reference" takes two lines so that its field keeps the room. */
.csr-narratives-info-dialog-request .wc-ui-form > * {
    --label-width: 6.75rem;
}

.csr-narratives-info-dialog-detail .wc-ui-form > * {
    --label-width: 11rem;
}

/* CAI-564: the narrative card's AI tab, the conversation with the narrative assistant. */
.csr-narratives-assistant {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    font-size: 0.8125rem;
}

.csr-narratives-assistant-content {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.csr-narratives-assistant-content[hidden] {
    display: none;
}

.csr-narratives-assistant-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 28rem;
    overflow-y: auto;
}

.csr-narratives-template-body {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.csr-narratives-template {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 1.25rem;
    align-items: start;
}

.csr-narratives-template[hidden] {
    display: none;
}

.csr-narratives-template-editor {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-width: 0;
}

.csr-narratives-template-editor nph-textarea {
    --label-width: auto;
    --input-max-width: 100%;
}

@media (max-width: 60rem) {
    .csr-narratives-template {
        grid-template-columns: 1fr;
    }
}
