/* BRAP dialog surfaces. Scope to dialogs: page tables, navigation and plugin menus stay independent. */
:root {
    --brap-dialog-navy: #0c2862;
    --brap-dialog-ink: #18273d;
    --brap-dialog-muted: #53647b;
    --brap-dialog-line: #dce4f0;
    --brap-dialog-footer: #f2f5fa;
    --brap-dialog-edge: linear-gradient(to right, #ff9933 0 33.333%, #fff 33.333% 66.667%, #138808 66.667% 100%);
    --brap-dialog-radius: 14px;
    --brap-dialog-gutter: clamp(1rem, 2vw, 1.85rem);
    --brap-dialog-shadow: 0 22px 64px rgb(9 26 59 / 30%);
}
.brap-theme .modal .modal-content,
dialog:is(.hp-dialog, .portal-leave-dialog, .brap-message-dialog) {
    color: var(--brap-dialog-ink);
    background: white;
    border: 0;
    /* Some views use Bootstrap's !important radius and shadow utilities. */
    border-radius: var(--brap-dialog-radius) !important;
    box-shadow: var(--brap-dialog-shadow) !important;
}
body.brap-theme .modal .modal-header,
dialog :is(.hp-dialog-header, .brap-dialog-bar, .brap-message-header),
#ai-chat-widget #ai-chat-window .ai-chat-header {
    display: flex;
    align-items: center;
    gap: .75rem;
    flex: 0 0 auto;
    /* A background strip, rather than generated content, also works inside a wrapping form. */
    background: var(--brap-dialog-edge) top / 100% 6px no-repeat, var(--brap-dialog-navy) !important;
    color: #fff !important;
    border: 0;
    border-radius: var(--brap-dialog-radius) var(--brap-dialog-radius) 0 0;
    padding: calc(.85rem + 6px) var(--brap-dialog-gutter) .85rem !important;
}
.brap-theme .modal .modal-header :is(h2,h3,h4,h5,h6,.modal-title),
dialog:is(.hp-dialog,.portal-leave-dialog,.brap-message-dialog) :is(.hp-dialog-header,.brap-dialog-bar,.brap-message-header) h2 {
    color: white !important;
    margin: 0;
    font-size: clamp(1.12rem, 1rem + .52vw, 1.55rem) !important;
    line-height: 1.25;
    font-weight: 750;
    overflow-wrap: anywhere;
}
.brap-theme .modal .modal-header p { margin: .2rem 0 0; color: #dee7fb; line-height: 1.45; }
.brap-theme .modal .modal-header .btn-close,
dialog :is(.hp-dialog-close,.brap-dialog-dismiss,.brap-message-close) {
    box-sizing: border-box;
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
    width: 2.6rem;
    height: 2.6rem;
    margin: 0 0 0 auto;
    padding: 0;
    border: 1px solid transparent;
    border-radius: .55rem;
    background-color: #1a3e7e;
    color: #fff;
    opacity: 1;
    filter: none;
    line-height: 1;
    font: 600 1.45rem/1 system-ui, sans-serif;
    cursor: pointer;
}
.brap-theme .modal .modal-header .btn-close {
    /* White X with no filter on the blue button surface. */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2.2' stroke-linecap='round'%3E%3Cpath d='m6 6 12 12M18 6 6 18'/%3E%3C/svg%3E");
    background-position: center;
    background-repeat: no-repeat;
    background-size: 1rem;
}
.brap-theme .modal .modal-header .btn-close:hover,
dialog :is(.hp-dialog-close,.brap-dialog-dismiss,.brap-message-close):hover { background-color: #284f94; }
.brap-theme .modal .modal-body { min-width: 0; }
.brap-theme .modal .modal-footer,
dialog :is(.portal-leave-actions,.brap-message-actions) {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .55rem;
    padding: .9rem var(--brap-dialog-gutter) !important;
    border-top: 2px solid var(--brap-dialog-navy) !important;
    border-radius: 0 0 var(--brap-dialog-radius) var(--brap-dialog-radius);
    background: var(--brap-dialog-footer) !important;
}
.brap-theme .modal .modal-footer > * { margin: 0; }
.brap-theme .modal :is(.modal-footer, form > .border-top) .btn,
dialog :is(.brap-message-actions,.portal-leave-actions) button { min-height: 2.55rem; border-radius: .5rem !important; font-weight: 650; }
body.brap-theme .modal-backdrop.show { background-color: #12203e; opacity: .68; }
dialog:is(.hp-dialog,.portal-leave-dialog,.brap-message-dialog)::backdrop { background: rgb(18 32 62 / 68%); }
:is(.brap-theme .modal, dialog.hp-dialog, dialog.portal-leave-dialog, dialog.brap-message-dialog) :focus-visible {
    outline: 3px solid #d8750a;
    outline-offset: 2px;
}
/* Retain each dialog's own width, focus and scroll contract. Closed native dialogs stay hidden. */
dialog:is(.hp-dialog,.portal-leave-dialog,.brap-message-dialog) {
    padding: 0;
    margin: auto;
    max-width: calc(100% - 1.5rem);
    max-height: calc(100dvh - 1.5rem);
    overflow: auto;
    overscroll-behavior: contain;
}
dialog.hp-dialog > :is(#hp-dialog-copy,#hp-dialog-video,#hp-dialog-guide) { margin-inline: var(--brap-dialog-gutter); }
dialog.hp-dialog > #hp-dialog-guide { margin-bottom: 1.4rem; }
dialog.hp-dialog #hp-dialog-video .hp-video { margin: 0 0 1rem; }
dialog.portal-leave-dialog .portal-leave-icon {
    width: 1.65rem; height: 1.65rem; margin: 0; border-radius: 50%;
    background: #ffb252; color: #142039; font: 800 1rem/1 system-ui, sans-serif; flex: none;
}
dialog.portal-leave-dialog > p, dialog.brap-message-dialog .brap-message-body {
    margin: 0; padding: 1.3rem var(--brap-dialog-gutter);
    color: var(--brap-dialog-ink); line-height: 1.55; overflow-wrap: anywhere;
}
dialog.brap-message-dialog { width: min(30rem, calc(100vw - 1.5rem)); }
dialog.brap-message-dialog .brap-message-body { white-space: pre-line; }
dialog.brap-message-dialog .brap-message-actions { justify-content: flex-end; }
dialog.brap-message-dialog .brap-message-actions button {
    padding: .45rem 1rem; border: 1px solid #b9c7dd; color: var(--brap-dialog-navy); background: white; cursor: pointer;
}
dialog.brap-message-dialog .brap-message-actions .brap-message-accept { background: var(--brap-dialog-navy); border-color: var(--brap-dialog-navy); color: #fff; }
/* Chat is a docked, nonmodal dialog: leave its composer, sizing and visibility controller intact. */
#ai-chat-widget #ai-chat-window { border-radius: var(--brap-dialog-radius); box-shadow: var(--brap-dialog-shadow); }
#ai-chat-widget #ai-chat-window .ai-chat-header { padding: 16px 12px 10px !important; }
#ai-chat-widget #ai-chat-window .ai-chat-header::after { content: none; }
#ai-chat-widget #ai-chat-window #ai-chat-title { color: white; }
#ai-chat-widget #ai-chat-window .ai-chat-identity p { color: #dbe5fa; }
#ai-chat-widget #ai-chat-window .ai-chat-header-actions button { color: white; background: #1a3e7e; }
#ai-chat-widget #ai-chat-window .ai-chat-header-actions button:hover { background: #284f94; }

/* All real tables within Bootstrap modals; no effect on the directory behind them. */
body.brap-theme .modal .modal-content table thead th {
    color: white !important; background: var(--brap-dialog-navy) !important; border-color: #304875;
    font-weight: 750; letter-spacing: .035em; text-transform: uppercase; vertical-align: middle;
    --bs-table-bg: var(--brap-dialog-navy); --bs-table-color: white;
}
.brap-theme .modal .modal-content table tbody tr:nth-child(even) { --bs-table-bg: #f7f9fc; }
body.brap-theme .modal .modal-content table tbody td { border-color: var(--brap-dialog-line); }
.brap-theme .modal .table-responsive { max-width: 100%; overflow-x: auto; }

/* Analytics drill-down: search | page length | exports, then data, then pager. */
#analytics-details .modal-dialog { width: calc(100% - 1.5rem); max-width: 1400px; margin-inline: auto; }
#analytics-details .modal-body { min-height: 0; padding: 0; }
#analytics-details-status { padding: 1rem var(--brap-dialog-gutter); margin: 0; }
#analytics-details-status:empty { display: none; }
#analytics-details .brap-dialog-toolbar, #analytics-details .brap-dialog-pager {
    display: flex; flex-wrap: wrap; align-items: center;
    gap: .7rem 1rem; padding: 1rem var(--brap-dialog-gutter);
}
#analytics-details .brap-dialog-toolbar { background: #fff; }
#analytics-details .brap-dialog-toolbar :is(label,input,button), #analytics-details .brap-dialog-pager .dataTables_info { font-size: .94rem; }
#analytics-details .brap-dialog-toolbar :is(.dataTables_filter,.dataTables_length,.dt-buttons) { float: none; margin: 0; }
#analytics-details .brap-dialog-toolbar .dataTables_filter {
    flex: 1 1 15rem; min-width: 0; max-width: 25rem; margin-inline-end: auto; text-align: start;
}
#analytics-details .brap-dialog-toolbar .dataTables_filter label { display: block; width: 100%; margin: 0; }
#analytics-details .brap-dialog-toolbar .dataTables_filter input {
    width: 100%; min-height: 2.65rem; margin: 0; padding: .5rem .8rem .5rem 2.45rem;
    border: 1px solid #b6c6df; border-radius: .6rem; color: var(--brap-dialog-ink);
    background: white url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235d7190' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='10' cy='10' r='6.8'/%3E%3Cpath d='m15 15 5 5'/%3E%3C/svg%3E") no-repeat .8rem center / 1rem;
}
#analytics-details .dataTables_length label { display: inline-flex; align-items: center; gap: .45rem; margin: 0; color: var(--brap-dialog-muted); }
#analytics-details .dataTables_length :is(select:not(.brap-dropdown-native),.brap-dropdown-toggle) { min-height: 2.65rem; border-color: #b6c6df; border-radius: .55rem; }
#analytics-details .brap-dialog-toolbar .dt-buttons { display: flex; flex-wrap: wrap; width: auto; gap: .5rem; }
#analytics-details .dt-buttons .btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .5rem; margin: 0;
    min-width: 0; min-height: 2.65rem; padding: .55rem 1rem; border-radius: .55rem;
    color: white; font-weight: 700;
}
#analytics-details .dt-buttons .buttons-excel { background: #127819; border-color: #127819; }
#analytics-details .dt-buttons .buttons-pdf { background: #b8231d; border-color: #b8231d; }
#analytics-details .dt-buttons button:hover { filter: brightness(.92); }
#analytics-details .brap-dialog-table-wrap { max-width: 100%; overflow: auto; overscroll-behavior-x: contain; }
#analytics-details table { margin: 0 !important; min-width: 58rem; font-size: .94rem; }
#analytics-details .modal-content thead th {
    padding-block: .85rem; padding-inline-start: 1rem; font-size: .8rem; white-space: nowrap;
}
#analytics-details .modal-content tbody td {
    padding: .95rem 1rem; vertical-align: middle; color: var(--brap-dialog-ink);
    background: white; box-shadow: none;
}
#analytics-details .modal-content tbody tr:nth-child(even) td { background: #f7f9fc; }
#analytics-details .modal-content tbody tr:hover td { background: #edf3fb; }
#analytics-details th[aria-sort=ascending]::before,
#analytics-details th[aria-sort=descending]::after { color: #ffae48; opacity: 1; }
#analytics-details .brap-dialog-id { color: #1c50bd; font-weight: 750; }
#analytics-details :is(.brap-dialog-programme,.brap-dialog-workflow) {
    display: inline-block; padding: .16rem .55rem; border-radius: .3rem; font-size: .87em; font-weight: 700;
}
#analytics-details .brap-dialog-programme { color: #133574; background: #e3ebfc; }
#analytics-details .brap-dialog-workflow { background: #e8edf4; color: #34455c; }
#analytics-details .brap-dialog-workflow.is-positive { color: white; background: #137320; }
#analytics-details .brap-dialog-workflow.is-pending { color: #202c49; background: #ffac52; }
#analytics-details .brap-dialog-workflow.is-negative { color: #922624; background: #ffe5e2; }
#analytics-details .brap-dialog-response { font-weight: 700; }
#analytics-details .brap-dialog-response.is-positive { color: #117225; }
#analytics-details .brap-dialog-response.is-positive::before {
    content: ""; display: inline-block; width: .4em; height: .75em; margin: 0 .5em .06em .1em;
    border: solid currentColor; border-width: 0 2px 2px 0; transform: rotate(45deg);
}
#analytics-details .brap-dialog-response.is-negative { color: #a32424; }
#analytics-details .brap-dialog-response.is-neutral, #analytics-details .brap-dialog-empty { color: var(--brap-dialog-muted); }
#analytics-details .brap-dialog-pager { justify-content: space-between; background: var(--brap-dialog-footer); border-top: 2px solid var(--brap-dialog-navy); }
#analytics-details .modal-footer .brap-dialog-pager { flex: 1 1 20rem; min-width: 0; padding: 0; border: 0; }
#analytics-details .brap-dialog-pager :is(.dataTables_info,.dataTables_paginate,.pagination) { margin: 0; padding: 0; }
#analytics-details .brap-dialog-pager .pagination { display: flex; flex-wrap: wrap; gap: .25rem; }
#analytics-details .brap-dialog-pager .page-link { margin: 0; border-radius: .4rem; color: var(--brap-dialog-navy); }
#analytics-details .brap-dialog-pager .active .page-link { background: var(--brap-dialog-navy); border-color: var(--brap-dialog-navy); color: white; }
#analytics-details .brap-dialog-pager .disabled .page-link { color: #687588; background: #f3f5f9; }
/* The rich text editor renders its own link, image and help dialogs, outside Bootstrap. */
.brap-theme .note-modal.open { overflow-y: auto; overscroll-behavior: contain; }
.brap-theme .note-modal .note-modal-content {
    max-width: calc(100vw - 2rem); border: none;
    border-radius: var(--brap-dialog-radius); box-shadow: var(--brap-dialog-shadow);
}
.brap-theme .note-modal .note-modal-header {
    display: flex; align-items: center; gap: 1rem; padding: calc(.8rem + 6px) var(--brap-dialog-gutter) .8rem;
    background: var(--brap-dialog-edge) top / 100% 6px no-repeat, var(--brap-dialog-navy);
    border: 0; border-radius: var(--brap-dialog-radius) var(--brap-dialog-radius) 0 0;
}
.brap-theme .note-modal .note-modal-title { color: white; order: -1; margin-inline-end: auto; }
.brap-theme .note-modal .note-modal-header button {
    display: grid; place-items: center; width: 2.6rem; height: 2.6rem; margin: 0; border: 0;
    border-radius: .55rem; background: #1a3e7e; color: white; text-shadow: none; opacity: 1;
}
.brap-theme .note-modal .note-modal-footer {
    display: flow-root; height: auto; padding: .75rem var(--brap-dialog-gutter);
    border-top: 2px solid var(--brap-dialog-navy); background: var(--brap-dialog-footer);
    border-radius: 0 0 var(--brap-dialog-radius) var(--brap-dialog-radius);
}
@media (max-width: 640px) {
    #analytics-details .brap-dialog-toolbar .dataTables_filter { flex-basis: 100%; max-width: none; }
    #analytics-details .brap-dialog-toolbar .dt-buttons { margin-inline-start: 0; }
    #analytics-details .brap-dialog-pager { justify-content: flex-start; }
    body.brap-theme .modal .modal-header { padding-inline: 1rem !important; }
}
@media (forced-colors: active) {
    .brap-theme .modal .modal-header .btn-close { background: ButtonFace; color: ButtonText; border: 1px solid ButtonText; }
    .brap-theme .modal .modal-header .btn-close::after { content: "\00d7"; }
}

