/* =============================================================================
   KEYAML  -  AGENCY AND PUBLIC PAYMENT STYLING
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   ⭐  Used by /keyaml/login.php and the agency area (/keyaml/index.php)
   ⭐  Brand palette taken from keyaml.com.au / the supplied Canva dashboard:
           ink #0B0D12   navy #0B1F3A   blue #2E67E6   cyan #4FA3E3
           ice #7DD3F0   bg #F4F6F9     card #FFFFFF   line #E4E9F0
           muted #5B6475
       with the AML gradients:
           sidebar  linear-gradient(180deg, #2E67E6 0%, #4FA3E3 55%, #7DD3F0 100%)
           accent   linear-gradient(90deg,  #2E67E6 0%, #4FA3E3 55%, #7DD3F0 100%)
   ⭐  Typography: Inter (falls back to the system stack ... no font files required)
   ============================================================================= */

:root {
    --ink    : #0B0D12;
    --navy   : #0B1F3A;
    --blue   : #2E67E6;
    --cyan   : #4FA3E3;
    --ice    : #7DD3F0;
    --bg     : #F4F6F9;
    --card   : #FFFFFF;
    --line   : #E4E9F0;
    --muted  : #5B6475;
    --keyaml-child-bg: #F1F6FF;
    --keyaml-subtle-bg: #F7FAFF;
    --keyaml-selected-bg: #EEF4FE;

    --aml    : linear-gradient(180deg, #2E67E6 0%, #4FA3E3 55%, #7DD3F0 100%);
    --aml-h  : linear-gradient(90deg,  #2E67E6 0%, #4FA3E3 55%, #7DD3F0 100%);

    --sidebar-w : 222px;
    --top-h     : 60px;

    --keyaml-accent-text: var(--blue);
    --keyaml-danger-fill: #b00020;
    --keyaml-bad: var(--keyaml-danger-fill);
    --keyaml-success-text: #198754;
}

/* Public payment page served on the l.keyaml host. */
body.keyamlPaymentBody {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    font-family: Inter, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--ink);
    background: var(--bg);
}
.keyamlPaymentTopLabel {margin-left: auto; color: var(--muted); font-size: 0.85rem; font-weight: 600;}
.keyamlPaymentShell {
    flex: 1 0 auto;
    display: grid;
    place-items: center;
    padding: 28px 16px 48px;
}
.keyamlPaymentCard {
    width: min(100%, 540px);
    margin: 0;
    overflow: hidden;
    color: var(--ink);
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(11, 13, 18, 0.12);
}
.keyamlPaymentCard .card-body {padding: 30px 32px 28px;}
.keyamlPaymentIcon {
    display: grid;
    place-items: center;
    width: 52px;
    height: 52px;
    margin-bottom: 18px;
    border-radius: 14px;
    color: var(--blue);
    background: #eaf1ff;
    font-size: 1.5rem;
}
.keyamlPaymentIcon.isPaid {color: #116d42; background: #e6f4ed;}
.keyamlPaymentIcon.isPending {color: #895400; background: #fff4d6;}
.keyamlPaymentIcon.isError, .keyamlPaymentIcon.isUnavailable {color: #a12626; background: #fde9e8;}
.keyamlPaymentEyebrow {color: var(--blue); font-size: 0.75rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;}
.keyamlPaymentTitle {margin: 7px 0 14px; font-size: clamp(1.45rem, 4vw, 1.85rem); line-height: 1.25; font-weight: 700;}
.keyamlPaymentStatus {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 999px;
    color: #2557c9;
    background: #eaf1ff;
    font-size: 0.78rem;
    font-weight: 700;
}
.keyamlPaymentStatus.isPaid {color: #116d42; background: #e6f4ed;}
.keyamlPaymentStatus.isPending {color: #895400; background: #fff4d6;}
.keyamlPaymentStatus.isError, .keyamlPaymentStatus.isUnavailable {color: #a12626; background: #fde9e8;}
.keyamlPaymentMessage {margin: 18px 0 22px; color: var(--muted); line-height: 1.55;}
.keyamlPaymentSummary {
    margin-bottom: 22px;
    padding: 16px 18px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--bg);
}
.keyamlPaymentSummary span {color: var(--muted); font-size: 0.9rem;}
.keyamlPaymentSummaryDetail {display: grid; grid-template-columns: 86px minmax(0, 1fr); gap: 8px; padding: 0 0 12px; font-size: 0.9rem;}
.keyamlPaymentSummaryDetail strong {font-weight: 600; overflow-wrap: anywhere;}
.keyamlPaymentSummaryDetail.isFee {grid-template-columns: minmax(0, 1fr) max-content; column-gap: 16px;}
.keyamlPaymentSummaryDetail.isFee span {overflow-wrap: anywhere;}
.keyamlPaymentSummaryDetail.isFee strong {white-space: nowrap; text-align: right;}
.keyamlPaymentSummaryTotal {display: grid; grid-template-columns: minmax(0, 1fr) max-content; align-items: baseline; gap: 16px;}
.keyamlPaymentSummaryTotal span {overflow-wrap: anywhere;}
.keyamlPaymentSummaryDetail + .keyamlPaymentSummaryTotal {padding-top: 12px; border-top: 1px solid var(--line);}
.keyamlPaymentSummaryTotal strong {white-space: nowrap; font-size: 1.2rem;}
.keyamlPaymentSubmit, .keyamlPaymentRefresh {display: block; width: 100%; padding: 12px 16px; font-weight: 700; text-align: center;}
.keyamlPaymentSubmit {background: var(--blue); border-color: var(--blue); color: #fff;}
.keyamlPaymentSubmit:hover {background: #2557c9; border-color: #2557c9; color: #fff;}
.keyamlPaymentRefresh {background: var(--card); border-color: var(--blue); color: var(--blue);}
.keyamlPaymentRefresh:hover {background: #eef4fe; color: var(--blue);}
.keyamlPaymentSecurity {display: flex; gap: 8px; margin: 16px 0 0; color: var(--muted); font-size: 0.8rem; line-height: 1.45;}
.keyamlPaymentSecurity i {flex: 0 0 auto; color: #116d42;}
.keyamlPaymentFooter {padding: 15px 32px; border-top: 1px solid var(--line); background: var(--card); text-align: center; font-size: 0.84rem;}
.keyamlPaymentFooter a {color: var(--blue); text-decoration: none;}
.keyamlPaymentFooter a:hover {text-decoration: underline;}
.keyamlInvoicePaymentCard {width: min(100%, 920px);}
.keyamlInvoicePaymentSummary .keyamlPaymentSummaryDetail {grid-template-columns: 80px minmax(0, 1fr);}
.keyamlInvoicePaymentSummary .keyamlPaymentSummaryTotal {padding-top: 12px; border-top: 1px solid var(--line);}
.keyamlInvoicePaymentHeading {margin: 0 0 12px; color: var(--navy); font-size: 1rem; font-weight: 700;}
.keyamlInvoicePaymentTableWrap {max-height: 480px; margin-bottom: 22px; overflow: auto; border: 1px solid var(--line); border-radius: 10px;}
.keyamlInvoicePaymentTable {--bs-table-bg: var(--card); --bs-table-color: var(--ink); --bs-table-border-color: var(--line); min-width: 620px; margin: 0;}
.keyamlInvoicePaymentTable th {position: sticky; top: 0; z-index: 1; padding: 11px 12px; color: var(--blue); background: var(--bg); font-size: 0.78rem; text-transform: uppercase;}
.keyamlInvoicePaymentTable td {padding: 12px; vertical-align: top; overflow-wrap: anywhere;}
.keyamlInvoicePaymentTable .keyamlInvoicePaymentAmount {text-align: center; white-space: nowrap;}
.keyamlInvoicePaymentTable td.keyamlInvoicePaymentAmount {font-weight: 700;}
@media (max-width: 520px) {
    .keyamlPaymentTopBar {padding: 0 16px;}
    .keyamlPaymentShell {place-items: start center; padding: 24px 14px 32px;}
    .keyamlPaymentCard .card-body {padding: 26px 22px;}
    .keyamlPaymentFooter {padding: 15px 22px;}
}

[data-bs-theme="dark"] {
    --ink    : #F4F7FB;
    --navy   : #E7F0FF;
    --bg     : #121820;
    --card   : #1B2430;
    --line   : #344255;
    --muted  : #AAB7C8;
    --keyaml-child-bg: #233247;
    --keyaml-subtle-bg: #202C3C;
    --keyaml-selected-bg: #283D57;
    --keyaml-highlight-border: #587AA2;
    --keyaml-stat-button-bg: var(--keyaml-child-bg);
    --keyaml-active-stat-bg: var(--keyaml-selected-bg);
    --keyaml-review-focus: var(--bs-warning-bg-subtle);
    --keyaml-dialog-error-bg: var(--bs-danger-bg-subtle);
    --keyaml-dialog-error-border: var(--bs-danger-border-subtle);
    --keyaml-accent-text: #A9C7FF;
    --keyaml-bad: var(--bs-danger-text-emphasis);
    --keyaml-success-text: var(--bs-success-text-emphasis);
}

/* Horizontal accents follow the portal theme. The sidebar keeps the brand gradient. */
html[data-bs-theme="dark"] {
    --aml-h: linear-gradient(90deg, #153368, #10405A);
}

html[data-bs-theme="dark"] .btn-outline-primary {--bs-btn-color: var(--keyaml-accent-text);}
html[data-bs-theme="dark"] .btn-outline-secondary {--bs-btn-color: var(--muted);}
html[data-bs-theme="dark"] .btn-outline-success {--bs-btn-color: var(--keyaml-success-text);}
html[data-bs-theme="dark"] .btn-outline-danger {--bs-btn-color: var(--keyaml-bad);}
html[data-bs-theme="dark"] :is(.keyamlBody, .keyamlLoginBody) :is(input, textarea)::placeholder {
    color: var(--muted);
    opacity: 1;
}

body.keyamlLoginBody,
body.keyamlBody {
    margin: 0;
    font-family: Inter, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--ink);
    background: var(--bg);
}

/* KeyAML's API loader replaces the shared top-left spinner on these pages. */
body.keyamlBody #ui_api_spinner,
body.keyamlLoginBody #ui_api_spinner {display: none !important;}

.keyamlApiLoading[hidden] {display: none;}
.keyamlApiLoading {
    position: fixed;
    inset: 0;
    /* Stay above the page, but below ui_dialog's mask (10007) and dialog (10008). */
    z-index: 10006;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(11, 31, 58, 0.28);
    backdrop-filter: blur(2px);
}
.keyamlApiLoadingCard {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px 24px;
    color: var(--ink);
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: 0 16px 48px rgba(11, 31, 58, 0.18);
}
.keyamlApiLoadingIcon {
    display: block;
    color: var(--keyaml-accent-text);
    font-size: 32px;
    line-height: 1;
    animation: keyamlApiSpin 0.8s linear infinite;
}
@keyframes keyamlApiSpin {to {transform: rotate(360deg);}}
@media (prefers-reduced-motion: reduce) {
    .keyamlApiLoadingIcon {animation: none;}
}

.keyamlApp.app-wrapper {
    display: block;
    min-height: 100vh;
    background: var(--bg);
}

/* -----------------------------------------------------------------------------
   BRAND
   -----
   The KeyAML logo is an IMAGE ... see .keyamlLogo / .keyamlLogoFallback in the
   AGENCY AREA section below.  The top bar uses it on every KeyAML page.
   -------------------------------------------------------------------------- */
.keyamlDot {color: var(--keyaml-accent-text);}

/* -----------------------------------------------------------------------------
   SIGN IN  ...  the SAME top bar as the agency area, with the card centred
   -------------------------------------------------------------------------- */
.keyamlLoginShell {
    min-height: calc(100vh - var(--top-h));
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 28px 20px;
    box-sizing: border-box;
}

.keyamlLoginCard {
    width: 400px;
    max-width: 94vw;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 0;
    overflow: hidden;                 /* so the AML accent keeps the rounded corners */
    box-shadow: 0 12px 40px rgba(11, 13, 18, 0.12);
}

/* The AML gradient accent ... the same gradient the agency sidebar uses */
.keyamlLoginAccent {height: 5px; background: var(--aml-h);}

.keyamlLoginHead {padding: 1.5em 1.6em 0 1.6em;}

.keyamlLoginTitle {
    font-size: 1.35em;
    font-weight: 700;
    color: var(--ink);
    line-height: 1.2;
}

.keyamlLoginBrandSub {
    font-size: 82%;
    font-weight: 400;
    color: var(--muted);
    margin-top: 0.35em;
}

/* Everything inside the card, under the head */
.keyamlLoginInner {padding: 1.4em 1.6em 1.6em;}

.keyamlLoginLabel {font-weight: 600; color: var(--ink); margin-bottom: 0.6em;}

#keyamlStep2Hint {margin-bottom: 1.2em;}
#keyamlLocalCode {font-weight: 700; color: var(--ink); margin-bottom: 1em;}
#keyamlStep2 .keyamlMfaDigits {margin-bottom: 1em;}
#keyamlStep2 .keyamlLink {margin-top: 1.2em;}

.keyamlInput {
    display: block;
    width: 100%;
    box-sizing: border-box;
    font-family: inherit;
    font-size: 1em;
    color: var(--ink);
    padding: 0.68em 0.85em;
    margin-bottom: 0.6em;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 10px;
}

.keyamlInput::placeholder {color: var(--muted);}

.keyamlInput:focus {
    outline: none;
    background: var(--card);
    border-color: var(--cyan);
    box-shadow: 0 0 0 3px rgba(79, 163, 227, 0.22);
}

.keyamlCodeInput {
    letter-spacing: 0.4em;
    font-size: 1.3em;
    text-align: center;
    font-weight: 600;
}

.keyamlBtn {
    display: inline-block;
    cursor: pointer;
    font-family: inherit;
    border-radius: 10px;
    padding: 0.68em 1.1em;
    font-weight: 600;
    color: #fff;
    background: var(--blue);
    border: 1px solid var(--blue);
    text-align: center;
    user-select: none;
}

.keyamlBtn:hover {background: #2557c9; border-color: #2557c9;}
.keyamlBtnLight {background: var(--card); color: var(--keyaml-accent-text);}
.keyamlBtnLight:hover {background: var(--keyaml-selected-bg); color: var(--keyaml-accent-text);}
.keyamlBackBtn {
    display: inline-flex;
    align-items: center;
    gap: 0.35em;
    padding: 0.48em 0.8em;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.2;
}

.keyamlListBackBtn {margin-bottom: 0.75em;}

.keyamlBtnFull {width: 100%; box-sizing: border-box; margin-top: 0.3em; font-size: 1.02em;}

.keyamlLink {margin-top: 0.9em; color: var(--keyaml-accent-text); cursor: pointer; font-size: 92%;}
.keyamlLink:hover {text-decoration: underline;}

.keyamlMsg {margin-top: 0.7em; min-height: 1.2em; font-size: 92%;}
.keyamlMsg.isError, .keyamlEmpty.isError {color: var(--keyaml-bad);}
.keyamlSmall {font-size: 85%; color: var(--muted); line-height: 1.4em;}

.keyamlMfaDigits {display: flex; justify-content: center; gap: 8px; margin: 8px 0 16px;}
.keyamlMfaDigits input {
    width: clamp(32px, 8vw, 42px);
    height: 48px;
    border: 1px solid #b9c8db;
    border-radius: 8px;
    background: #fff;
    color: #1a1c21;
    font-size: 22px;
    font-weight: 600;
    text-align: center;
}
.keyamlMfaDigits input:focus {outline: 2px solid #2e67e6; outline-offset: 1px;}
html[data-bs-theme="dark"] .keyamlMfaDigits input {
    color: var(--ink);
    background: var(--bg);
    border-color: var(--muted);
}
html[data-bs-theme="dark"] .keyamlMfaDigits input:focus {outline-color: var(--keyaml-accent-text);}

.keyamlLoginFoot {
    margin-top: 1.4em;
    padding-top: 0.9em;
    border-top: 1px solid var(--line);
    font-size: 82%;
    color: var(--muted);
}

/* -----------------------------------------------------------------------------
   AGENCY AREA  ...  top bar, sidebar, content
   -------------------------------------------------------------------------- */
.keyamlTopBar {
    height: var(--top-h);
    background: var(--card);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    padding: 0 46px 0 28px;
    box-sizing: border-box;
}

.keyamlTopBar.app-header {
    position: static;
    margin: 0;
    z-index: 10;
    box-shadow: none;
}

.keyamlMenuToggle,
.keyamlIconBtn {
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: var(--muted);
    display: grid;
    place-items: center;
    padding: 0;
    margin-left: 10px;
    text-decoration: none;
}

.keyamlMenuToggle:hover,
.keyamlIconBtn:hover {
    background: var(--bg);
    color: var(--keyaml-accent-text);
}

.keyamlLogoLink {
    display: flex;
    align-items: center;
    text-decoration: none;
    color: var(--navy);
    flex: 0 0 auto;
}

.keyamlLogo {
    display: block;
    height: 38px;
    width: auto;
}

.keyamlLogoFallback {display: none; font-size: 1.2em;}
html[data-bs-theme="dark"] .keyamlTopBar .keyamlLogo {filter: brightness(0) invert(1);}

.keyamlTopAgency {
    margin-left: 1.1em;
    color: var(--muted);
    font-size: 90%;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.keyamlTopUser {margin-left: auto; position: relative;}
.keyamlAccountToggle {display: flex; align-items: center; gap: 12px; min-height: 44px; min-width: 44px; justify-content: center; padding: 0; border: 0; background: transparent; color: inherit; font: inherit;}
.keyamlAccountLabel {display: grid; min-width: 0;}
body.keyamlBody .keyamlThemeToggle {margin-left: auto;}
body.keyamlBody .keyamlTopUser {margin-left: 0;}

.keyamlNotification {
    margin-left: auto;
    position: relative;
}

.keyamlNotification .navbar-badge {
    position: absolute;
    top: 5px;
    right: 3px;
    font-size: 9px;
}

.keyamlTopBar .dropdown-menu {
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: 0 12px 35px rgba(11, 13, 18, 0.12);
}

.keyamlTopUser .dropdown-menu {
    top: calc(100% + 8px);
    right: 0;
    left: auto;
}

.keyamlTopUserName {
    font-size: 13px;
    font-weight: 600;
    color: var(--ink);
    text-align: right;
    line-height: 1.25;
}

.keyamlTopUserOrg {font-size: 11.5px; font-weight: 500; color: var(--muted); text-align: right;}

.keyamlAvatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--aml-h);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    display: grid;
    place-items: center;
    letter-spacing: 0.02em;
    flex: 0 0 auto;
}

.keyamlShell {
    min-height: calc(100vh - var(--top-h));
    display: flex;
}

.keyamlSide {
    width: var(--sidebar-w);
    background: var(--aml);
    color: #fff;
    padding: 28px 14px 20px 14px;
    box-sizing: border-box;
    min-height: 100%;
    display: flex;
    flex-direction: column;
    flex: 0 0 var(--sidebar-w);
}

.keyamlSide.app-sidebar {
    position: static;
    height: auto;
    max-height: none;
    min-width: var(--sidebar-w);
    box-shadow: none;
    transition: margin-left 0.2s ease;
}

@media (min-width: 992px) {
    body.keyamlBody.sidebar-collapse .keyamlSide.app-sidebar {
        margin-left: calc(0px - var(--sidebar-w));
        visibility: hidden;
    }
}

.keyamlSideNav .sidebar-menu {gap: 6px;}
.keyamlSideNav .nav-item > .nav-link {margin-bottom: 0; border-radius: 12px;}

.keyamlSideItem {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 44px;
    border: 0;
    background: transparent;
    text-align: left;
    padding: 0 14px;
    border-radius: 12px;
    color: rgba(255, 255, 255, 0.92);
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    margin-bottom: 0;
}

.keyamlSideIcon {font-size: 18px; width: 18px; text-align: center; line-height: 1;}

.keyamlSideItem:hover {background: rgba(255, 255, 255, 0.16); color: #fff;}
.keyamlSideItem:focus {color: #fff;}
.keyamlSideItem:focus-visible, .keyamlSideFoot:focus-visible {outline: 2px solid white; outline-offset: -3px;}

.keyamlSideItem[aria-current] {background: rgba(11, 31, 58, 0.28); font-weight: 600; color: #fff;}
:root:not([data-bs-theme="dark"]) .keyamlSideNav .nav-item:has(> .nav-treeview [aria-current]) > .nav-link {background: rgba(11, 31, 58, 0.12);}
.keyamlReportsToggle {width: 100%; border: 0; background: transparent; font-family: inherit; text-align: left;}
.keyamlSideNav .nav-treeview > .nav-item {margin: 6px 0 0 27px;}
.keyamlSideNav .nav-item > .keyamlSideSubItem {padding-left: 9px; border-left: 2px solid rgba(255, 255, 255, 0.55); border-radius: 0 10px 10px 0; font-size: 12.5px;}
.keyamlSideSubItem .keyamlSideIcon {font-size: 15px;}

.keyamlSideFoot {
    margin-top: auto;
    flex-shrink: 0;
    min-height: 44px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.22);
    border: 1px solid rgba(255, 255, 255, 0.45);
    color: #fff;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    text-align: center;
    padding: 10px 12px;
    cursor: pointer;
}

.keyamlSideFoot:hover {background: rgba(255, 255, 255, 0.3);}

/* Only the current destination gets a solid navy row on the brand gradient. */
html[data-bs-theme="dark"] .keyamlSide :is(.keyamlSideItem, .keyamlSideFoot) {
    color: #09172a;
    background-color: rgba(255, 255, 255, 0.16);
}
html[data-bs-theme="dark"] .keyamlSide :is(.keyamlSideItem, .keyamlSideFoot):hover {
    background-color: rgba(255, 255, 255, 0.32);
}
html[data-bs-theme="dark"] .keyamlSide :is(.keyamlSideItem, .keyamlSideFoot):focus-visible {
    outline-color: currentColor;
}
html[data-bs-theme="dark"] .keyamlSide .keyamlSideItem[aria-current] {
    color: #fff;
    background-color: #0b1f3a;
}


.keyamlMain {flex: 1; padding: 46px 46px 40px 46px; min-width: 0;}
.keyamlMain.app-main {margin: 0;}

.keyamlH1 {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: 0;
    color: var(--ink);
    margin: 0;
    line-height: 1.15;
}

.keyamlReadOnly {display: grid; gap: 10px;}
.keyamlReadOnly > div {display: grid; grid-template-columns: minmax(120px, 35%) 1fr; gap: 12px; padding-bottom: 8px; border-bottom: 1px solid var(--line);}
.keyamlReadOnly > div > b {color: var(--muted); font-size: 12px;}
.keyamlReadOnly > div > span {overflow-wrap: anywhere;}
.keyamlReadOnly > .keyamlProviderRow {background: var(--keyaml-selected-bg); border: 1px solid var(--keyaml-highlight-border, #bcd3ff); border-radius: 8px; padding: 10px 12px; align-items: center;}
.keyamlReadOnly > .keyamlProviderRow > b {color: var(--navy);}
.keyamlReadOnly > .keyamlProviderRow > span {color: var(--navy); font-weight: 700;}
.keyamlReadOnly > b {margin-top: 8px; color: var(--navy);}
.keyamlReadOnly > p {margin: 0; color: var(--muted);}
.keyamlReadOnly > .keyamlSpanAll {grid-template-columns: 1fr;}
.keyamlReadOnly > .keyamlOtherFirmDocRow {display: flex; align-items: center; justify-content: space-between; gap: 1.5em;}
.keyamlOtherFirmDocRow > span:first-child {min-width: 0; overflow-wrap: anywhere;}
.keyamlOtherFirmDocActions {display: inline-flex; gap: 0.5em; flex: none; margin-left: auto;}
@media (max-width: 760px) {
    .keyamlReadOnly > :is(.keyamlOtherFirmDocRow, .keyamlTrustDeedRow) {display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.5em;}
    .keyamlOtherFirmDocActions {margin-left: 0;}
}
.keyamlReadOnly > .keyamlSpanAll:has(#keyamlOtherFirmUpload) {display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.7em;}
.keyamlReadOnly > .keyamlSpanAll:has(#keyamlOtherFirmUpload) label {display: grid; gap: 0.3em;}
.keyamlReadOnly #keyamlOtherFirmUpload {align-self: end; justify-self: end; white-space: nowrap;}
.keyamlReadOnly .keyamlOtherFirmUploadHint {grid-column: 1 / -1;}
@media (max-width: 520px) {.keyamlReadOnly > .keyamlSpanAll:has(#keyamlOtherFirmUpload) {grid-template-columns: 1fr;}}

.keyamlDate {margin-top: 10px; font-size: 13.5px; font-weight: 500; color: var(--muted);}
.keyamlSub {color: var(--muted); font-size: 88%; margin-bottom: 1em;}

.keyamlKeyspaceCta {
    margin-top: 40px;
    width: 100%;
    min-height: 58px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
    font-size: 16px;
    font-weight: 600;
    color: var(--ink);
    cursor: pointer;
}

.keyamlKeyspaceCta:hover {border-color: var(--cyan);}
.keyamlKeyspaceCta span {color: var(--keyaml-accent-text); margin-right: 6px; font-weight: 700;}

.keyamlPanel {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 1em 1.1em 1.1em 1.1em;
    margin-top: 1.4em;
}

.keyamlToolbar {margin-bottom: 0.9em; display: flex; align-items: center; flex-wrap: wrap; gap: 0.4em;}

.keyamlFormPanel .keyamlToolbar {
    justify-content: flex-end;
    margin-top: 1em;
    margin-bottom: 0;
}

.keyamlToolbar input {
    flex: 1 1 18em;
    min-width: 12em;
    font-family: inherit;
    font-size: 95%;
    padding: 0.5em 0.8em;
    color: var(--ink);
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 10px;
}

.keyamlToolbar input:focus {
    outline: none;
    background: var(--card);
    border-color: var(--cyan);
    box-shadow: 0 0 0 3px rgba(79, 163, 227, 0.18);
}

.keyamlToolbar .keyamlBtn {font-size: 95%; padding: 0.5em 1em; margin-left: 0;}

.keyamlToolbarRight {margin-left: auto;}

.keyamlSearchHint {
    color: var(--muted);
    font-size: 0.85em;
    margin: -0.35em 0 0.85em;
}
.keyamlToolbar button:disabled {opacity: 0.55; cursor: not-allowed;}

.keyamlListStatusFilter {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.35em;
    margin-bottom: 0.75em;
}
.keyamlListStatusLabel {
    color: var(--navy);
    font-size: 0.82em;
    font-weight: 700;
    margin-right: 0.35em;
}
.keyamlStatusHelpPair {display: inline-flex; align-items: center; gap: 0.35em;}
.keyamlListStatusButton {
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--card);
    color: var(--navy);
    padding: 0.35em 0.9em;
    font: inherit;
    font-size: 0.85em;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.keyamlListStatusButton:hover {border-color: var(--blue); color: var(--keyaml-accent-text);}
.keyamlListStatusButton:focus-visible {outline: 2px solid var(--blue); outline-offset: 2px;}
.keyamlListStatusButton.isActive {
    background: var(--blue);
    border-color: var(--blue);
    color: #fff;
    font-weight: 700;
}

.keyamlAdminStatusFilter {margin-bottom: 0.4em;}
.keyamlAgencyFilterRow {display: flex; align-items: center; flex-wrap: wrap; gap: 0.65em; padding-top: 0.55em; margin-bottom: 0.75em; border-top: 1px solid var(--line);}
.keyamlAgencyFilterRow #keyamlKsResetFilters {margin-left: auto; font-size: 95%; padding: 0.5em 1em;}
.keyamlAgencyFilter {display: flex; align-items: center; gap: 0.5em;}
.keyamlAgencyFilter label {color: var(--navy); font-size: 0.82em; font-weight: 700;}
.keyamlAgencyPicker {position: relative;}
.keyamlAgencyFilter input {width: 220px; min-height: 34px; border: 1px solid var(--line); border-radius: 8px; padding: 0.35em 0.65em; background: var(--card); color: var(--ink);}
.keyamlAgencyFilter input:focus {outline: 2px solid var(--blue); outline-offset: 1px;}
.keyamlAccountingFilterRow #keyamlAccountingStatus,
#keyamlInvoicesStatus {width: 220px; min-height: 34px; border: 1px solid var(--line); border-radius: 8px; padding: 0.35em 0.65em; background: var(--card); color: var(--ink);}
.keyamlAccountingFilterRow #keyamlAccountingStatus:focus,
#keyamlInvoicesStatus:focus {outline: 2px solid var(--blue); outline-offset: 1px;}
.keyamlAccountingFilterRow #keyamlAccountingReset {margin-left: auto; font-size: 95%; padding: 0.5em 1em;}
.keyamlAgencyOptions {position: absolute; top: calc(100% + 4px); left: 0; z-index: 20; width: min(320px, 90vw); max-height: 240px; overflow-y: auto; padding: 0.3em; border: 1px solid var(--line); border-radius: 8px; background: var(--card); box-shadow: 0 8px 24px rgba(26, 47, 78, 0.14);}
.keyamlAgencyOptions[hidden] {display: none;}
.keyamlAgencyOption {display: block; width: 100%; padding: 0.55em 0.65em; border: 0; border-radius: 5px; background: transparent; color: var(--ink); text-align: left; cursor: pointer;}
.keyamlAgencyOption:hover, .keyamlAgencyOption:focus {background: var(--bg); outline: none;}
.keyamlAgencyOptionHint {padding: 0.55em 0.65em; color: var(--muted); font-size: 0.85em;}
@media (max-width: 760px) {
    .keyamlAgencyFilter {width: 100%;}
    .keyamlAgencyPicker {flex: 1; min-width: 0;}
    .keyamlAgencyFilter input, .keyamlAgencyOptions {width: 100%;}
}
@media (max-width: 760px) {.keyamlAccountingFilterRow #keyamlAccountingStatus, #keyamlInvoicesStatus {flex: 1; width: 100%;}}

.keyamlH2 {
    margin: 0;
    color: var(--ink);
    font-size: 18px;
    font-weight: 700;
}

.keyamlNote {
    background: var(--keyaml-selected-bg);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0.75em 0.9em;
    font-size: 90%;
    color: var(--navy);
    margin-bottom: 0.9em;
}

.keyamlCountLine {
    color: var(--navy);
    border-bottom: 1px solid var(--line);
    padding-bottom: 0.45em;
    margin-bottom: 0.5em;
    font-size: 92%;
    font-weight: 500;
}

.keyamlTbl {display: table; width: 100%; border-collapse: collapse;}
.keyamlRow {display: table-row;}

.keyamlRow > div {
    display: table-cell;
    padding: 0.5em 0.5em 0.5em 0.5em;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
    font-size: 92%;
}

.keyamlHdr > div {
    color: var(--muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-size: 11px;
    border-bottom: 1px solid var(--cyan);
}

.keyamlData:hover {background: var(--keyaml-subtle-bg);}

.keyamlTableWrap {
    border: 1px solid var(--line);
    border-radius: 12px;
    overflow: hidden;
    background: var(--card);
}

.keyamlBsTable {
    margin-bottom: 0;
    color: var(--ink);
}

.keyamlBsTable thead th {
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    background: var(--bg);
    border-bottom: 1px solid var(--cyan);
}

.keyamlSortButton {
    color: inherit;
    font: inherit;
    letter-spacing: inherit;
    text-transform: inherit;
    background: none;
    border: 0;
    padding: 0;
    cursor: pointer;
}
.keyamlSortButton:hover, .keyamlSortButton:focus-visible {color: var(--keyaml-accent-text);}
.keyamlSortButton i {margin-left: 0.25em; opacity: 0.65;}
.keyamlMobileSort {display: none;}
@media (min-width: 761px) and (max-width: 1180px), (pointer: coarse) {
    .keyamlBsTable thead .keyamlSortButton,
    .keyamlBsTable thead .keyamlActionsHelp {min-height: 44px; min-width: 44px;}
}

.keyamlBsTable td,
.keyamlBsTable th {
    border-color: var(--line);
    padding: 0.7em 0.75em;
}

.keyamlAgencyDetailTable {
    table-layout: fixed;
    --entity-number: 44px;
    --entity-toggle: 82px;
    --entity-status: 170px;
    --entity-risk: 220px;
    --entity-actions: 220px;
}
.keyamlAgencyDetailTable th:nth-child(1),
.keyamlAgencyDetailTable td:nth-child(1) {width: var(--entity-number);}
.keyamlAgencyDetailTable th:nth-child(2),
.keyamlAgencyDetailTable td:nth-child(2) {width: var(--entity-toggle);}
.keyamlAgencyDetailTable th:nth-child(4),
.keyamlAgencyDetailTable td:nth-child(4),
.keyamlAgencyDetailTable th:nth-child(5),
.keyamlAgencyDetailTable td:nth-child(5) {width: var(--entity-status);}
.keyamlAgencyDetailTable th:nth-child(6),
.keyamlAgencyDetailTable td:nth-child(6) {width: var(--entity-risk);}
.keyamlAgencyDetailTable th:nth-child(7),
.keyamlAgencyDetailTable td:nth-child(7) {width: var(--entity-actions);}

/* Email addresses, filenames and provider names can be longer than a tablet column. */
:is(#keyamlPeopleBox, #keyamlComplianceBox, .keyamlRecordList) tbody td {overflow-wrap: anywhere;}

@media (min-width: 761px) and (max-width: 1200px) {
    .keyamlRecordList :is(th, td) {padding-inline: 0.4em;}
}

.keyamlBsTable tbody tr:hover {
    background: var(--bg);
}

.keyamlBsTable tbody tr.keyamlEntityChildRow:hover {
    background: var(--bg);
}

.keyamlBsTable.table-hover > tbody > tr.keyamlEntityChildRow:hover > td {
    --bs-table-bg-state: transparent;
    --bs-table-color-state: var(--bs-table-color);
}

.keyamlNumberCol {
    width: 44px;
    text-align: center;
    color: var(--muted);
}

.keyamlToggleCol {
    width: 82px;
    min-width: 82px;
    text-align: center;
}

.keyamlEntityToggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35em;
    white-space: nowrap;
}

.keyamlListDivider {
    font-size: 1.2em;
    font-weight: 700;
}

.keyamlEntityChildRow {background: var(--bg);}
.keyamlEntityChildRow .keyamlRelatedPanel {margin-left: 0;}
.keyamlAdminChildRow {background: var(--bg);}
.keyamlAdminChildRow td:nth-child(2) {padding-left: 2em;}
.keyamlEntityChildRow > td {
    position: relative;
    padding: 0.55em 0;
}
.keyamlRelationshipArrow {
    display: none;
}
.keyamlRelatedPanel {
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--keyaml-child-bg);
    box-shadow: inset 3px 0 0 var(--blue);
    overflow: hidden;
}
.keyamlRelatedPanel:has(.keyamlAgencyActionMenu.show) {overflow: visible;}
.keyamlRelatedPanelHead {
    display: flex;
    justify-content: space-between;
    gap: 0.75em;
    padding: 0.65em 0.8em;
    background: var(--bg);
    border-bottom: 1px solid var(--line);
}
.keyamlRelatedPanelHead span {color: var(--muted); font-size: 88%; font-weight: 600;}
.keyamlRelatedGrid {
    display: grid;
    /* Match the seven columns of the parent entity table. Column 4 is the
       parent's AML provider; associated people leave that column empty. */
    grid-template-columns: var(--entity-number) var(--entity-toggle) minmax(0, 1fr)
        var(--entity-status) var(--entity-status) var(--entity-risk) var(--entity-actions);
    gap: 0;
    align-items: center;
    padding: 0.7em 0;
    border-bottom: 1px solid var(--line);
}
.keyamlRelatedGrid > :nth-child(1) {grid-column: 1;}
.keyamlRelatedGrid > :nth-child(2) {grid-column: 2;}
.keyamlRelatedGrid > :nth-child(3) {grid-column: 3;}
.keyamlRelatedGrid > :nth-child(4) {grid-column: 4;}
.keyamlRelatedGrid > :nth-child(5) {grid-column: 5;}
.keyamlRelatedGrid > :nth-child(6) {grid-column: 6;}
.keyamlRelatedGrid > :nth-child(7) {grid-column: 7;}
.keyamlRelatedGrid > div:nth-child(n+5),
.keyamlRelatedGrid > span:nth-child(n+5) {
    text-align: center;
}
.keyamlRelatedNumber {text-align: center; color: var(--muted);}
.keyamlRelatedGrid:last-child {border-bottom: none;}
.keyamlRelatedGrid small {
    display: block;
    color: var(--muted);
    margin-top: 0.15em;
}
.keyamlRelatedCenter {
    display: flex;
    justify-content: center;
    align-items: center;
}
.keyamlRelatedActions {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.55em 0.65em;
    flex-wrap: nowrap;
    overflow: visible;
}
.keyamlRelatedActions .btn {
    flex: 0 0 auto;
    white-space: nowrap;
}
.keyamlRelatedActions .keyamlAdminActions {margin-top: 0; gap: 0.4em; justify-content: center; flex-wrap: nowrap;}

/* Size the parent and associated people together when the sidebar leaves a narrow table. */
@media (min-width: 761px) {
    .keyamlTableWrap:has(> .keyamlAgencyDetailTable) {container: entity-list / inline-size;}
    @container entity-list (max-width: 1146px) {
        .keyamlAgencyDetailTable {
            --entity-number: 4%;
            --entity-toggle: 9%;
            --entity-status: 13%;
            --entity-risk: 15%;
            --entity-actions: 22%;
            overflow-wrap: anywhere;
        }
        .keyamlAgencyDetailTable :is(td, th) {padding-inline: 0.35em;}
        .keyamlAgencyDetailTable .keyamlToggleCol {min-width: 0;}
        .keyamlRelatedActions .keyamlAdminActions {flex-wrap: wrap;}
    }
}
.keyamlRelatedGridHead {
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    padding-top: 0.55em;
    padding-bottom: 0.55em;
}
.keyamlChildEntityCard {
    display: grid;
    grid-template-columns: 44% 16% 20% 20%;
    gap: 0.75em;
    align-items: center;
}
.keyamlChildEntityCard > div:first-child {padding-left: 1.25em;}
.keyamlChildLabel {
    display: none;
    color: var(--muted);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    margin-bottom: 0.2em;
}
.keyamlEntityParentLine {
    color: var(--muted);
    font-size: 86%;
    margin-top: 0.15em;
}
.keyamlDetailAction.isOn {background: var(--keyaml-selected-bg); color: var(--keyaml-accent-text);}

.keyamlPager {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 0.45em;
    margin-top: 0.85em;
}

.keyamlPagerInfo {
    color: var(--muted);
    font-size: 88%;
    margin-right: auto;
}

.keyamlPagerSize,
.keyamlPagerBtn,
.keyamlKsPagerSize,
.keyamlKsPagerBtn,
.keyamlDocPagerSize,
.keyamlDocPagerBtn {
    min-height: 34px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--card);
    color: var(--ink);
    font-family: inherit;
    font-size: 88%;
    padding: 0.35em 0.75em;
}

.keyamlPagerBtn,
.keyamlKsPagerBtn,
.keyamlDocPagerBtn {
    color: #fff;
    background: var(--blue);
    border-color: var(--blue);
    font-weight: 600;
}

.keyamlPagerBtn:disabled,
.keyamlKsPagerBtn:disabled,
.keyamlDocPagerBtn:disabled {
    color: var(--muted);
    background: var(--bg);
    border-color: var(--line);
    cursor: not-allowed;
}

/* -----------------------------------------------------------------------------
   INTERNAL ADMIN AREA
   -------------------------------------------------------------------------- */
.keyamlAdminBody {min-height: 100vh; --sidebar-w: 300px;}

.keyamlAdminCard {
    border-bottom: 1px solid var(--line);
    padding: 0.75em 0.35em;
    cursor: default;
}

.keyamlAdminCard:hover {background: var(--keyaml-subtle-bg);}
.keyamlAdminCard.isOn {background: var(--keyaml-selected-bg); border-radius: 8px; padding-left: 0.55em;}
[data-bs-theme="dark"] .keyamlBsTable .keyamlAdminCard.isOn {--bs-table-bg: var(--keyaml-selected-bg);}

.keyamlAdminTitle {font-weight: 700; color: var(--ink); margin-bottom: 0.2em;}
.keyamlAdminMeta {font-size: 86%; color: var(--muted); line-height: 1.45;}

.keyamlAdminActions {margin-top: 0.5em; display: flex; flex-wrap: wrap; gap: 0.55em 0.65em;}
.keyamlActionBtn,
.keyamlAction {
    font-weight: 600;
    border-radius: 8px;
}

.keyamlSectionHead {
    display: flex;
    justify-content: space-between;
    gap: 1em;
    align-items: flex-start;
    margin-bottom: 0.85em;
}

.keyamlSectionTitle {
    margin: 0;
    font-size: inherit;
    font-weight: 700;
    color: var(--ink);
    line-height: 1.25;
}

.keyamlAgencyDetailPanel {
    margin-top: 1em;
}

.keyamlAgencyInfo {
    display: flex;
    justify-content: space-between;
    gap: 1em;
    align-items: flex-start;
    padding-bottom: 0.9em;
    border-bottom: 1px solid var(--line);
}

.keyamlStatsGrid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0.75em;
    margin-top: 0.9em;
}

.keyamlReportsGrid {grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));}
#keyamlAccountingSummary {margin-bottom: 1.4em;}
#keyamlBillingReportSummary {grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.25em; margin-bottom: 1.4em;}
.keyamlBillingReportTableActions {justify-content: flex-end; margin-bottom: 0.7em;}
.keyamlBillingReportToolbar label {color: var(--navy); font-size: 0.82em; font-weight: 700;}
.keyamlBillingReportDateFilters {column-gap: 1.5em; row-gap: 0.75em;}
.keyamlBillingReportDateFilters label {display: inline-flex; align-items: center; gap: 0.45em; white-space: nowrap;}
#keyamlBillingReportMode {min-height: 38px; min-width: 190px; padding: 0.5em 0.75em; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--ink); font: inherit;}
#keyamlBillingReportMode:focus {outline: 2px solid var(--blue); outline-offset: 1px;}
.keyamlBillingReportToolbar input[type='date'] {flex: 0 1 155px; min-width: 145px;}
.keyamlInvoiceDialogScroll {max-height: min(65vh, 640px); overflow-y: auto; overscroll-behavior: contain; padding-right: 0.5em;}
.keyamlInvoiceDialogScroll h3 {margin: 0.1em 0 0.5em; overflow-wrap: anywhere;}
.keyamlInvoiceDialogScroll .keyamlToolbar {margin: 1em 0 0;}
.keyamlInvoiceDialogActions {justify-content: flex-end; gap: 0.5em;}
.keyamlInvoiceDialogError {margin: 0.9em 0 0;}
.keyamlInvoiceActionsCol {text-align: right; white-space: nowrap;}
.keyamlInvoiceActionsCol .btn + .btn {margin-left: 0.35em;}
@media (max-width: 760px) {#keyamlBillingReportSummary {grid-template-columns: 1fr;} #keyamlBillingReportMode {flex: 1;}}
.keyamlAccountingTabs > .card-header {background-color: var(--bg);}
.keyamlAccountingTabs .nav-item {display: flex; min-width: 0;}
.keyamlAccountingTabs .nav-link {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 44px;
    width: 100%;
    line-height: 1.25;
}
.keyamlAccountingTabs .nav-link.active {
    box-shadow: inset 0 3px var(--blue);
    font-weight: 700;
}
.keyamlAccountingTabs .nav-link:focus-visible {
    outline: 2px solid var(--bs-emphasis-color);
    outline-offset: -3px;
}
@media (max-width: 575px) {
    .keyamlAccountingTabs .nav-item {flex: 1 1 0;}
    .keyamlAccountingTabs .nav-link {padding-inline: 0.5rem;}
}
#keyamlInvoiceUsage .keyamlTableWrap {margin-top: 1em;}
#keyamlAdminUsage {margin-bottom: 1.25em;}
.keyamlAccountingTitleRow {display: flex; align-items: center; justify-content: space-between; gap: 0.75em;}
.keyamlAccountingTitleRow .keyamlActionBtn {flex: none;}
#keyamlAdminUsageRows .keyamlInvoiceListAction {text-align: center; width: 90px; white-space: nowrap;}
#keyamlInvoiceTopBack {margin-bottom: 0.9em;}
#keyamlAdminUsageDetails {margin-top: 1.25em;}
.keyamlInvoiceDetailHero {display: flex; justify-content: space-between; align-items: stretch; gap: 1.5em; padding: 1.25em 1.4em; border: 1px solid var(--line); border-radius: 14px; background: var(--bg);}
.keyamlInvoiceDetailIntro {align-self: center; min-width: 0;}
.keyamlInvoiceEyebrow {color: var(--muted); font-size: 0.75em; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;}
.keyamlInvoiceDetailIntro h2 {margin: 0.25em 0 0.35em; color: var(--navy); font-size: 1.35em; font-weight: 700; overflow-wrap: anywhere;}
.keyamlInvoiceDetailIntro p {margin: 0; color: var(--muted);}
.keyamlInvoiceDetailTotal {display: flex; flex-direction: column; align-items: flex-end; justify-content: center; min-width: 205px; padding-left: 1.5em; border-left: 1px solid var(--line);}
.keyamlInvoiceDetailTotal span {color: var(--muted); font-size: 0.85em;}
.keyamlInvoiceDetailTotal strong {color: var(--navy); font-size: 1.7em; line-height: 1.25;}
.keyamlInvoiceDetailTotal button {margin-top: 0.8em;}
.keyamlInvoiceCycleDetails {display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.75em; margin-top: 0.85em;}
.keyamlInvoiceCycleDetails > div {display: flex; flex-direction: column; gap: 0.2em; min-width: 0; padding: 0.9em 1em; border: 1px solid var(--line); border-radius: 10px; background: var(--card);}
.keyamlInvoiceCycleDetails span {color: var(--muted); font-size: 0.78em; font-weight: 700; text-transform: uppercase;}
.keyamlInvoiceCycleDetails strong {color: var(--navy); font-size: 0.97em; overflow-wrap: anywhere;}
.keyamlInvoiceCycleDetails small {color: var(--muted); overflow-wrap: anywhere;}
#keyamlAdminIssueResult:not(:empty) {margin-top: 0.85em; padding: 0.75em 1em; border: 1px solid var(--line); border-radius: 10px; background: var(--bg);}
.keyamlInvoiceServicesToolbar {display: flex; flex-direction: column; align-items: flex-start; gap: 0.75em; margin: 1.5em 0 0.7em;}
.keyamlInvoiceDetailListTitle {color: var(--navy); font-size: 1.05em; font-weight: 700;}
.keyamlInvoiceServicesSearch {width: min(390px, 100%); margin-bottom: 0;}
#keyamlAdminUsageDetailContent .keyamlTableWrap {margin-top: 0;}
#keyamlAdminUsageDetailContent .keyamlInvoiceAmount {text-align: right; font-weight: 700; white-space: nowrap;}
#keyamlAdminUsageDetailContent .keyamlBsTable th:last-child {text-align: right;}
#keyamlAdminUsagePager {margin-top: 0.8em;}
@media (max-width: 1050px) {.keyamlInvoiceCycleDetails {grid-template-columns: repeat(2, minmax(0, 1fr));}}
@media (max-width: 760px) {
    .keyamlInvoiceDetailHero {flex-direction: column; gap: 1em; padding: 1em;}
    .keyamlInvoiceDetailTotal {align-items: flex-start; min-width: 0; padding: 1em 0 0; border-left: 0; border-top: 1px solid var(--line);}
    .keyamlInvoiceDetailTotal button {width: 100%;}
    .keyamlInvoiceCycleDetails {grid-template-columns: 1fr;}
    .keyamlInvoiceServicesSearch {width: 100%;}
    #keyamlAdminUsageRows .keyamlInvoiceListAction {text-align: center !important;}
}
.keyamlInvoiceAgencyFilter input {width: min(340px, 60vw);}
.keyamlBillingSummary {margin: 0.5em 0 0.85em; color: var(--navy);}

@media (min-width: 761px) and (max-width: 1200px) {
    #keyamlInvoiceRows .keyamlBsTable :is(th, td) {padding: 0.45rem 0.35rem; overflow-wrap: anywhere;}
    #keyamlInvoiceRows .keyamlInvoiceActionsCol {white-space: normal;}
}
@media (max-width: 760px) {
    #keyamlAccountingRoot :is(.keyamlBillingReportDateFilters, .keyamlPaymentFilters) {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        align-items: end;
        gap: 0.65rem;
    }
    #keyamlAccountingRoot :is(.keyamlBillingReportDateFilters, .keyamlPaymentFilters) label,
    #keyamlAccountingRoot .keyamlInvoiceFilters .keyamlAgencyFilter {
        display: grid;
        gap: 0.25rem;
        min-width: 0;
        font-size: 0.875rem;
        font-weight: 600;
    }
    #keyamlAccountingRoot :is(.keyamlBillingReportDateFilters, .keyamlPaymentFilters) input,
    #keyamlAccountingRoot .keyamlInvoiceFilters :is(input, select) {
        box-sizing: border-box;
        width: 100%;
        min-width: 0;
        min-height: 44px;
        font-size: 1rem;
    }
    #keyamlAccountingRoot .keyamlPaymentFilters input[type='search'],
    #keyamlAccountingRoot .keyamlBillingReportDateFilters > button {grid-column: 1 / -1;}
    #keyamlAccountingRoot .keyamlBillingReportDateFilters > button {min-height: 44px; margin-left: 0;}
    #keyamlAccountingRoot .keyamlPaymentFilters > [role='status']:empty {display: none;}
    #keyamlAccountingRoot .keyamlInvoiceFilters {display: grid; gap: 0.65rem;}

    :is(#keyamlInvoiceRows, #keyamlAccountingRows, #keyamlBillingReportRows, #keyamlInvoiceUsage, #keyamlInvoiceDialogContent) .keyamlBsTable > tbody > tr {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        align-items: start;
        gap: 0.65rem 0.8rem;
        padding: 0.9rem;
    }
    :is(#keyamlInvoiceRows, #keyamlAccountingRows, #keyamlBillingReportRows, #keyamlInvoiceUsage, #keyamlInvoiceDialogContent) .keyamlBsTable > tbody > tr > td {
        min-width: 0;
        padding: 0;
        white-space: normal;
    }
    :is(#keyamlAccountingRows, #keyamlBillingReportRows, #keyamlInvoiceUsage, #keyamlInvoiceDialogContent) td:is([data-label='KeySpace'], [data-label='Agency'], [data-label='Property'], [data-label='Payment reference'], [data-label='Invoice'], [data-label='Actions']) {
        grid-column: 1 / -1;
    }
    #keyamlInvoiceRows .keyamlBsTable > tbody > tr {
        grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
        grid-template-areas: 'agency total' 'reference status' 'issued due' 'items items' 'actions actions';
    }
    #keyamlInvoiceRows td[data-label='Agency'] {grid-area: agency; color: var(--navy); font-weight: 700;}
    #keyamlInvoiceRows td[data-label='Total (incl. GST)'] {grid-area: total; color: var(--navy); font-weight: 700;}
    #keyamlInvoiceRows td[data-label='Invoice'] {grid-area: reference;}
    #keyamlInvoiceRows td[data-label='Invoice'] strong {font-weight: 500;}
    #keyamlInvoiceRows td[data-label='Status'] {grid-area: status;}
    #keyamlInvoiceRows td[data-label='Issued'] {grid-area: issued;}
    #keyamlInvoiceRows td[data-label='Due'] {grid-area: due;}
    #keyamlInvoiceRows td[data-label='Items'] {grid-area: items;}
    #keyamlInvoiceRows .keyamlBsTable > tbody > tr > td[data-label='Actions'] {
        grid-area: actions;
        border-top: 1px solid var(--line);
        padding-top: 0.65rem;
    }
}
@media (max-width: 359px) {
    #keyamlAccountingRoot :is(.keyamlBillingReportDateFilters, .keyamlPaymentFilters) {grid-template-columns: minmax(0, 1fr);}
}
.keyamlGraph {height: 320px; width: 100%; color: var(--muted);}
.keyamlGraphTall {height: 400px;}
.keyamlGraphHead {display: flex; justify-content: space-between; align-items: center; gap: 0.75em; flex-wrap: wrap;}
.keyamlGraphHead label {color: var(--muted); font-size: 90%;}
.keyamlGraphHead select {margin-left: 0.4em; padding: 0.35em 0.5em; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--ink);}
.keyamlReportsToolbar {margin-top: 1.2em;}
.keyamlReportsToolbar select {
    padding: 0.5em 0.75em;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--card);
    color: var(--ink);
}

.keyamlStatCard {
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--keyaml-subtle-bg);
    padding: 0.75em;
}

.keyamlStatCardButton {
    width: 100%;
    border: 1px solid var(--keyaml-highlight-border, #8FB3FF);
    background: var(--keyaml-stat-button-bg, #F3F7FF);
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}
.keyamlStatCardButton:hover,
.keyamlStatCardButton:focus-visible {
    border-color: var(--blue);
    background: var(--card);
    box-shadow: 0 0 0 2px rgba(47, 101, 235, 0.12);
    outline: none;
}
.keyamlNextStepCard.isActive {border-color: var(--keyaml-accent-text); background: var(--keyaml-active-stat-bg, #EAF1FF);}
#keyamlNextStepCards {grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));}
#keyamlNextStepRows {margin-top: 1em;}
.keyamlNextStepPeople {margin: 0.35em 0 0; padding-left: 1.25em;}
@media (min-width: 761px) {
    #keyamlNextStepRows :is(th:last-child, td[data-label='Action']) {width: 190px; text-align: center;}
    #keyamlNextStepRows td .keyamlAdminActions {justify-content: center;}
}

.keyamlStatValue {
    color: var(--navy);
    font-size: 1.25em;
    font-weight: 700;
    line-height: 1.15;
}

.keyamlStatLabel {
    margin-top: 0.2em;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.keyamlFormPanel {margin-top: 0.75em; margin-bottom: 0.75em;}

.keyamlFormGrid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.keyamlFormGrid label {
    display: block;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
}

.keyamlFormGrid input,
.keyamlFormGrid select {
    width: 100%;
    box-sizing: border-box;
    margin-top: 5px;
    font-family: inherit;
    font-size: 14px;
    color: var(--ink);
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0.58em 0.75em;
}

.keyamlFormGrid input:focus,
.keyamlFormGrid select:focus {
    outline: none;
    background: var(--card);
    border-color: var(--cyan);
    box-shadow: 0 0 0 3px rgba(79, 163, 227, 0.18);
}

.keyamlMuted {
    color: var(--muted);
    font-size: 88%;
}
.keyamlEntitySummary {color: var(--ink); font-size: 92%; margin-top: 0.2em;}

.keyamlDocCenterCol,
.keyamlDocActionsCol {text-align: center;}
.keyamlDocActionsCol > .keyamlAdminActions {margin-top: 0;}

.keyamlKsCenterCol,
.keyamlKsActionsCol {text-align: center;}

.keyamlDetailHead {
    margin-bottom: 0.75em;
}

.keyamlDetailMeta {
    color: var(--muted);
    font-size: 13px;
    margin-top: 1em;
}

.keyamlStagePanel {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.6em 1em;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
    margin-top: 0.7em;
    padding: 0.6em 0.8em;
    box-shadow: 0 2px 10px rgba(26, 47, 78, 0.04);
}

.keyamlStageHeading {
    display: inline-flex;
    align-items: center;
    gap: 0.25em;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    white-space: nowrap;
}

.keyamlStageStepGroup {display: inline-flex; align-items: center; gap: 0.35em;}
.keyamlStageSteps {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    flex: 0 0 270px;
    gap: 0.25em;
}

.keyamlStageChip {
    color: var(--muted);
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    padding: 0.5em 0.25em;
    text-align: center;
}

.keyamlStageChip.isOn {
    color: #fff;
    background: var(--blue);
    border-color: var(--blue);
}

.keyamlStageActions {display: flex; flex-wrap: wrap; gap: 0.4em; margin-left: auto;}

.keyamlStageAction {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5em;
    min-height: 34px;
    padding: 0.45em 0.7em;
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
}

.keyamlStageAction.isPrimary {background: var(--blue); color: #fff;}
.keyamlStageAction.isPrimary:hover {filter: brightness(0.92);}
.keyamlStageAction.isSecondary {background: var(--card); color: var(--keyaml-accent-text); border-color: var(--blue);}
.keyamlStageAction.isSecondary:hover,
.keyamlStageAction.isText:hover {background: var(--bg);}
.keyamlStageAction.isText {background: transparent; color: var(--muted); font-weight: 500;}
.keyamlStageAction:focus-visible {outline: 3px solid var(--cyan); outline-offset: 2px;}
.keyamlStageAction:disabled {opacity: 0.6; cursor: wait;}

.keyamlStageSupport {
    flex: 1 1 220px;
    color: var(--ink);
    background: var(--bg);
    border-left: 3px solid var(--blue);
    border-radius: 4px;
    font-size: 12px;
    line-height: 1.45;
    padding: 0.7em;
    margin: 0;
}

@media (max-width: 760px) {
    .keyamlStagePanel {display: flex;}
    .keyamlStageHeading {width: 100%; margin-bottom: 0.6em;}
    .keyamlStageStepGroup {display: flex; width: 100%;}
    .keyamlStageSteps {flex: 1 1 auto; min-width: 0;}
    .keyamlStageActions {flex: 1 1 auto; margin-top: 0.7em;}
    .keyamlStageAction {width: 100%;}
    .keyamlStageHelp {margin-top: 0.7em;}
}

.keyamlStatusDialogSummary {line-height: 1.55; margin: 0 0 1em;}
.keyamlStatusReasonLabel {display: block; font-weight: 600; margin-bottom: 0.4em;}

.keyamlDetailToolbar {align-items: center;}

.keyamlCheckState {
    color: var(--muted);
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 8px;
    display: inline-block;
    font-size: 12px;
    padding: 0.2em 0.55em;
}

.keyamlAdminCenterCol,
.keyamlAdminActionsCol {text-align: center;}

.keyamlActionsHeading {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35em;
    white-space: nowrap;
}

.keyamlStatusHelp,
.keyamlActionsHelp,
.keyamlResponsesHelp {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 12px;
    line-height: 1;
}

.keyamlStatusHelp:hover,
.keyamlStatusHelp:focus,
.keyamlActionsHelp:hover,
.keyamlActionsHelp:focus {color: var(--keyaml-accent-text);}

.keyamlStatusHelp {width: 26px; height: 26px; font-size: 14px;}
.keyamlStageHelp {
    width: 34px;
    min-height: 34px;
    padding: 0;
    margin-left: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--keyaml-accent-text);
    background: var(--card);
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}
.keyamlStageActions + .keyamlStageHelp {margin-left: 0;}
.keyamlStageHelp:hover,
.keyamlStageHelp:focus-visible {border-color: var(--blue); background: var(--bg);}

.keyamlActionsHelpList {
    display: grid;
    gap: 0.8em;
    padding: 0.25em 0;
}

.keyamlInvoiceHelpHeading {margin: 1em 0 0.25em; color: var(--navy); font-weight: 700;}

.keyamlActionsHelpItem {
    display: grid;
    grid-template-columns: 30px minmax(0, 1fr);
    align-items: center;
    gap: 0.7em;
}
.keyamlEntityStatusHelpItem {grid-template-columns: minmax(0, 1fr);}

.keyamlActionsHelpItem > i {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--keyaml-accent-text);
}

.keyamlActionsHelpItem b,
.keyamlActionsHelpItem span {display: block;}

.keyamlActionsHelpItem span {
    color: var(--muted);
    font-size: 12px;
    margin-top: 0.15em;
}

.keyamlAdminActionsCol {
    min-width: 190px;
    white-space: nowrap;
}

.keyamlAdminActionsCol .keyamlAdminActions {justify-content: center;}

@media (min-width: 761px) {
    #keyamlAgenciesBox .keyamlAdminActionsCol {min-width: 175px;}
    #keyamlAgenciesBox .keyamlAdminActions {flex-wrap: nowrap;}
    #keyamlAdminReportRows .keyamlAdminActionsCol {width: 190px;}
    :is(#keyamlComplianceBox td.keyamlDocActionsCol, #keyamlKeyspacesBox td.keyamlKsActionsCol) > .keyamlAdminActions {
        width: max-content;
        max-width: 100%;
        margin-inline: auto;
        justify-content: center;
        flex-wrap: nowrap;
    }
    #keyamlKeyspacesBox td.keyamlKsActionsCol > .keyamlAdminActions {
        display: grid;
        grid-template-columns: max-content minmax(90px, max-content);
        align-items: center;
    }
}
#keyamlAgenciesBox .keyamlTableWrap,
#keyamlKeyspacesBox .keyamlTableWrap,
#keyamlKsBox .keyamlTableWrap,
#keyamlUnfinishedBox .keyamlTableWrap {overflow: visible;}
body.keyamlBody :where(td) .keyamlAdminActions {margin-top: 0; gap: 0.4em; justify-content: flex-start;}
@media (min-width: 761px) {
    :is(#keyamlAgenciesBox, #keyamlKeyspacesBox, #keyamlKsBox, #keyamlUnfinishedBox) .keyamlAdminActions {flex-wrap: nowrap;}
    :is(#keyamlReviewBox, #keyamlAmlReviewBox, #keyamlCompanyQueueBox, #keyamlAgenciesBox, #keyamlKsBox, #keyamlUnfinishedBox, #keyamlUsersBox, #keyamlAdminReportRows, #keyamlAccountingRows, #keyamlInvoiceRows, #keyamlAdminUsageRows, #keyamlPeopleBox, #keyamlComplianceBox, #keyamlMissingReportsBox) td .keyamlAdminActions {justify-content: center;}
    :is(#keyamlKeyspaceDetailBox, #keyamlAdminKeyspaceDetailBox) td.keyamlKsActionsCol .keyamlAdminActions {justify-content: center;}
}
#keyamlReviewBox th:last-child {text-align: center;}
#keyamlInvoiceRows .keyamlInvoiceActionsCol,
#keyamlAdminUsageRows .keyamlInvoiceListAction {text-align: center;}
body.keyamlBody :is(td, .keyamlResponseActions, .keyamlRelatedActions) .keyamlAgencyIconBtn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4em;
    width: auto;
    height: 36px;
    margin: 0;
    padding: 0 0.7em;
    color: var(--keyaml-accent-text);
    background: var(--card);
    border: 1px solid var(--blue);
    border-radius: 8px;
    font-size: 13px;
    font-weight: 400;
}
body.keyamlBody :is(td, .keyamlResponseActions, .keyamlRelatedActions) .keyamlAgencyIconBtn:hover,
body.keyamlBody :is(td, .keyamlResponseActions, .keyamlRelatedActions) .keyamlAgencyIconBtn[aria-expanded="true"] {color: #fff; background: var(--blue);}
body.keyamlBody :is(td, .keyamlResponseActions, .keyamlRelatedActions) .keyamlAgencyIconBtn.isDanger {color: var(--keyaml-bad); border-color: var(--keyaml-bad);}
body.keyamlBody :is(td, .keyamlResponseActions, .keyamlRelatedActions) .keyamlAgencyIconBtn.isDanger:hover {color: #fff; background: var(--keyaml-danger-fill);}
body.keyamlBody :is(td, .keyamlResponseActions, .keyamlRelatedActions) .keyamlAgencyIconBtn.isSuccess {color: var(--keyaml-success-text); border-color: var(--keyaml-success-text);}
body.keyamlBody :is(td, .keyamlResponseActions, .keyamlRelatedActions) .keyamlAgencyIconBtn.isSuccess:hover {color: #fff; background: #198754;}
body.keyamlBody .keyamlAgencyActionMenu {
    min-width: 205px;
    max-width: calc(100vw - 24px);
    padding: 8px;
    color: var(--ink);
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: 0 12px 35px rgba(11, 31, 58, 0.18);
}
body.keyamlBody .keyamlAgencyActionMenu .dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.6em;
    width: 100%;
    min-height: 38px;
    white-space: normal;
    overflow-wrap: anywhere;
    margin: 0;
    padding: 0.45em 0.6em;
    color: var(--ink);
    background: transparent;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 400;
}
body.keyamlBody .keyamlAgencyActionMenu .dropdown-item i {width: 1.2em; color: var(--keyaml-accent-text); font-size: 16px;}
body.keyamlBody .keyamlAgencyActionMenu .dropdown-item:hover,
body.keyamlBody .keyamlAgencyActionMenu .dropdown-item:focus-visible {color: #fff; background: var(--blue);}
body.keyamlBody .keyamlAgencyActionMenu .dropdown-item:hover i,
body.keyamlBody .keyamlAgencyActionMenu .dropdown-item:focus-visible i {color: #fff;}
body.keyamlBody .keyamlAgencyActionMenu .dropdown-item.isDanger,
body.keyamlBody .keyamlAgencyActionMenu .dropdown-item.isDanger i {color: var(--keyaml-bad);}
body.keyamlBody .keyamlAgencyActionMenu .dropdown-item.isDanger:hover,
body.keyamlBody .keyamlAgencyActionMenu .dropdown-item.isDanger:focus-visible {color: #fff; background: var(--keyaml-danger-fill);}
body.keyamlBody .keyamlAgencyActionMenu .dropdown-item.isDanger:hover i,
body.keyamlBody .keyamlAgencyActionMenu .dropdown-item.isDanger:focus-visible i {color: #fff;}
body.keyamlBody .keyamlAgencyActionMenu .dropdown-item.isSuccess,
body.keyamlBody .keyamlAgencyActionMenu .dropdown-item.isSuccess i {color: var(--keyaml-success-text);}
body.keyamlBody .keyamlAgencyActionMenu .dropdown-item.isSuccess:hover,
body.keyamlBody .keyamlAgencyActionMenu .dropdown-item.isSuccess:focus-visible {color: #fff; background: #198754;}
body.keyamlBody .keyamlAgencyActionMenu .dropdown-item.isSuccess:hover i,
body.keyamlBody .keyamlAgencyActionMenu .dropdown-item.isSuccess:focus-visible i {color: #fff;}
body.keyamlBody .keyamlAgencyActionMenu .dropdown-item:disabled,
body.keyamlBody .keyamlAgencyActionMenu .dropdown-item:disabled:hover {color: var(--muted); background: transparent; opacity: 0.75;}
body.keyamlBody .keyamlAgencyActionMenu .dropdown-item:disabled i,
body.keyamlBody .keyamlAgencyActionMenu .dropdown-item:disabled:hover i {color: var(--muted);}
body.keyamlBody .keyamlTableWrap:has(.keyamlAgencyActionMenu) {overflow: visible;}

/* KeySpace progress uses AdminLTE's timeline inside the existing dialog. */
.keyamlProgressDialog {max-height: min(70vh, 680px); overflow-y: auto; padding: 0.15em 0.35em 0.2em 0; color: var(--ink);}
.keyamlProgressIntro {display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.35em 1em; margin-bottom: 0.35em;}
.keyamlProgressIntro span, .keyamlProgressHint {color: var(--muted); font-size: 0.88em;}
.keyamlProgressHint {margin: 0 0 1em;}
.keyamlProgressTimeline::before {background: var(--line);}
.keyamlProgressTimeline .timeline-icon {color: #fff; background: var(--muted); font-size: 0.9em;}
.keyamlProgressTimeline .isDone .timeline-icon {background: #198754;}
.keyamlProgressTimeline .isReady .timeline-icon {background: var(--blue);}
.keyamlProgressTimeline .isWaiting .timeline-icon {background: #d68a16;}
[data-bs-theme="dark"] .keyamlProgressTimeline :is(.isNext, .isWaiting) .timeline-icon {color: var(--bg);}
[data-bs-theme="dark"] .keyamlProgressTimeline .isNext .timeline-icon {background: var(--muted);}
.keyamlProgressTimeline .timeline-item {background: var(--card); border: 1px solid var(--line); color: var(--ink); box-shadow: none;}
.keyamlProgressTimeline .timeline-header {color: var(--ink); font-size: 0.95em; font-weight: 700;}
.keyamlProgressTimeline .timeline-body {font-size: 0.88em; line-height: 1.5; overflow-wrap: anywhere;}
.keyamlProgressPeopleList {margin: 0.2em 0 0.45em; padding-left: 1.4em;}
.keyamlProgressPeopleList li + li {margin-top: 0.2em;}
.keyamlProgressPeopleList span {color: var(--muted); font-size: 0.9em; white-space: nowrap;}
.keyamlProgressEntityList li {padding: 0.15em 0;}
.keyamlProgressEntityList span {display: block; white-space: normal;}
.keyamlProgressGroup {margin: 1em 0 0.7em 3.3em; padding: 0.55em 0.8em; border-left: 3px solid var(--blue); background: var(--bg); border-radius: 0 8px 8px 0;}
.keyamlProgressGroup b {display: block;}
.keyamlProgressGroup span {display: block; color: var(--muted); font-size: 0.85em;}
.keyamlProgressReviewHelp {margin-top: 0.6em; padding-top: 0.6em; border-top: 1px solid var(--line); color: var(--muted);}
.keyamlProgressTimeline .time {font-size: 0.77em; color: var(--muted);}
.keyamlProgressNext {background: var(--bg); border: 1px solid var(--line); border-radius: 9px; padding: 0.8em 1em; margin: 0.7em 0 1em; font-size: 0.9em;}
.keyamlProgressNext ul {margin: 0.45em 0 0; padding-left: 1.25em;}
.keyamlProgressNext li + li {margin-top: 0.35em;}
.keyamlProgressNext p {margin: 0.35em 0 0;}
.keyamlProgressActivity {margin-top: 1.2em;}
.keyamlProgressDocument {color: var(--muted); font-size: 0.92em;}
.keyamlProgressHistory {margin: 0.6em 0 0; padding: 0.5em 0 0 1.25em; border-top: 1px solid var(--line);}
.keyamlProgressHistory li + li {margin-top: 0.25em;}
.keyamlProgressHistory li {display: flex; flex-wrap: wrap; gap: 0.15em 0.75em; position: relative;}
.keyamlProgressHistory li::before {content: '•'; position: absolute; left: -1em;}
.keyamlProgressHistory li span {flex: 1 1 13em; min-width: 0;}
.keyamlProgressHistory time {color: var(--muted); margin-left: auto; white-space: nowrap;}

.keyamlDialogForm {
    display: grid;
    gap: 0.85em;
    padding: 0.35em 0 0.75em;
}

.keyamlAccountingDetails {
    display: grid;
    grid-template-columns: minmax(7em, 1fr) minmax(0, 2fr);
    margin: 0;
}
.keyamlAccountingDialogScroll {
    max-height: min(70vh, 640px);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-right: 0.5em;
}
.keyamlAccountingDetails dt,
.keyamlAccountingDetails dd {
    margin: 0;
    padding: 0.55em 0;
    border-bottom: 1px solid var(--line);
}
.keyamlAccountingDetails dt {color: var(--muted); padding-right: 0.75em;}
.keyamlAccountingDetails dd {overflow-wrap: anywhere;}
.keyamlStripeReport {margin: 1.2em 0 1.5em; overflow: hidden; border: 1px solid var(--line); border-radius: 14px; background: var(--card); box-shadow: 0 10px 28px rgba(11, 31, 58, 0.07);}
.keyamlStripeReport[hidden] {display: none;}
.keyamlStripeHead {display: flex; justify-content: space-between; gap: 1em; padding: 1.3em 1.5em; background: linear-gradient(90deg, #f0f5ff, #e9f8ff); color: #0b1f3a;}
.keyamlStripeHead h3 {margin: 0.15em 0 0.3em; font-size: 1.28em; font-weight: 700;}
.keyamlStripeHead p {max-width: 65ch; margin: 0; color: #4f5f77; line-height: 1.45;}
.keyamlStripeEyebrow {color: #2557c9; font-size: 0.7em; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase;}
.keyamlStripeHead button {align-self: flex-start; flex: 0 0 auto;}
.keyamlStripeControls {padding: 1.2em 1.5em; border-bottom: 1px solid var(--line);}
.keyamlStripePresets, .keyamlStripeViews {display: flex; flex-wrap: wrap; gap: 0.4em;}
.keyamlStripePreset, .keyamlStripeView {border: 1px solid var(--line); border-radius: 999px; padding: 0.45em 0.85em; background: var(--card); color: var(--ink); font: inherit; font-size: 0.88em; cursor: pointer;}
.keyamlStripePreset:hover, .keyamlStripeView:hover {border-color: var(--blue); color: var(--keyaml-accent-text);}
.keyamlStripePreset.isActive, .keyamlStripeView.isActive {border-color: var(--blue); background: var(--blue); color: #fff;}
.keyamlStripeDateRow {display: flex; flex-wrap: wrap; align-items: end; gap: 0.7em; margin-top: 1em;}
.keyamlStripeDateRow label {display: grid; gap: 0.25em; color: var(--muted); font-size: 0.86em; font-weight: 600;}
.keyamlStripeDateRow input {min-height: 36px; padding: 0.3em 0.6em; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--ink); font: inherit;}
.keyamlStripeDateRow .btn {min-height: 36px;}
.keyamlStripeHint {margin: 0.85em 0 0; color: var(--muted); font-size: 0.8em; line-height: 1.45;}
#keyamlStripeResults {padding: 1.2em 1.5em 1.5em;}
.keyamlStripeEmpty, .keyamlStripeLoading, .keyamlStripeNotice {padding: 1.1em 1.2em; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--muted); line-height: 1.45;}
.keyamlStripeLoading {display: flex; align-items: center; gap: 0.7em;}
.keyamlStripeNotice.isGood {border-color: #b6dfc7; background: #eaf7ef; color: #17613b;}
.keyamlStripeNotice.isError {border-color: #f0b6b6; background: #fff0f0; color: #9c2929;}
.keyamlStripeResultHead {display: flex; align-items: center; flex-wrap: wrap; gap: 0.7em; color: var(--muted); font-size: 0.82em;}
.keyamlStripeMode {display: inline-block; border-radius: 999px; padding: 0.3em 0.7em; font-weight: 700;}
.keyamlStripeMode.isTest {background: #e9f1ff; color: #2557c9;}
.keyamlStripeMode.isLive {background: #eaf7ef; color: #17613b;}
.keyamlStripeMetrics {display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.7em; margin: 0.9em 0 1.2em;}
.keyamlStripeMetric {display: grid; gap: 0.15em; padding: 0.9em 1em; border: 1px solid var(--line); border-radius: 10px; background: var(--bg);}
.keyamlStripeMetric strong {color: var(--ink); font-size: 1.4em; line-height: 1.1;}
.keyamlStripeMetric span {color: var(--muted); font-size: 0.78em; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em;}
.keyamlStripeMetric.isIssue {border-color: #f0d294; background: #fff9eb;}
.keyamlStripeMetric.isIssue strong {color: #895400;}
.keyamlStripeMetric.isGood {border-color: #b6dfc7; background: #f0faf4;}
.keyamlStripeMetric.isGood strong {color: #17613b;}
.keyamlStripeResultTools {display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 0.7em; margin-bottom: 0.85em;}
.keyamlStripeTable td {vertical-align: middle;}
.keyamlStripeTable td small {display: block; margin-top: 0.2em; color: var(--muted); line-height: 1.35;}
.keyamlStripeResultTag {display: inline-block; padding: 0.3em 0.65em; border-radius: 999px; font-size: 0.78em; font-weight: 700; white-space: nowrap;}
.keyamlStripeResultTag.isIssue {background: #fff1d5; color: #895400;}
.keyamlStripeResultTag.isGood {background: #eaf7ef; color: #17613b;}
.keyamlStripeTable .keyamlStripeIssueHint {max-width: 18em; color: #895400;}
.keyamlStripeStatusPair {display: grid; gap: 0.2em; font-size: 0.87em; white-space: nowrap;}
.keyamlStripeDetailIssues {margin-bottom: 1em; padding: 0.8em 1em; border: 1px solid #f0d294; border-radius: 9px; background: #fff9eb; color: #704400;}
.keyamlStripeDetailIssues ul {margin: 0.4em 0 0; padding-left: 1.2em;}
.keyamlStripeReference {overflow-wrap: anywhere;}
.keyamlStripeCopy {margin-left: 0.5em;}
@media (max-width: 700px) {
    .keyamlStripeHead, .keyamlStripeControls, #keyamlStripeResults {padding: 1em;}
    .keyamlStripeMetrics {grid-template-columns: 1fr 1fr;}
    .keyamlStripeDateRow label {flex: 1 1 8em;}
    .keyamlStripeDateRow .btn {flex: 1 1 100%;}
}
[data-bs-theme="dark"] .keyamlStripeHead {background: linear-gradient(90deg, #1b2d4b, #173746); color: #f4f7fb;}
[data-bs-theme="dark"] .keyamlStripeHead p {color: #bdcde4;}
[data-bs-theme="dark"] .keyamlStripeEyebrow {color: var(--keyaml-accent-text);}
[data-bs-theme="dark"] :is(.keyamlStripeMetric.isIssue, .keyamlStripeDetailIssues, .keyamlStripeResultTag.isIssue,
    .keyamlReviewCount, .keyamlTag.isPaymentWaiting, .keyamlTag.isPdfNeeded, .keyamlTag.isLearningPending, .keyamlRisk.isMedium) {
    background: var(--bs-warning-bg-subtle);
    color: var(--bs-warning-text-emphasis);
    border-color: var(--bs-warning-border-subtle);
}
[data-bs-theme="dark"] :is(.keyamlStripeTable .keyamlStripeIssueHint, .keyamlStripeMetric.isIssue strong) {color: var(--bs-warning-text-emphasis);}
[data-bs-theme="dark"] :is(.keyamlStripeMetric.isGood, .keyamlStripeNotice.isGood, .keyamlStripeMode.isLive, .keyamlStripeResultTag.isGood,
    .keyamlTag.isPdfRecorded, .keyamlTag.isAgencyActive, .keyamlTag.isSignInActive, .keyamlRisk.isLow) {
    background: var(--bs-success-bg-subtle);
    color: var(--keyaml-success-text);
    border-color: var(--bs-success-border-subtle);
}
[data-bs-theme="dark"] .keyamlStripeMetric.isGood strong {color: var(--keyaml-success-text);}
[data-bs-theme="dark"] :is(.keyamlStripeNotice.isError, .keyamlTag.isAgencyInactive, .keyamlRisk.isHigh) {
    background: var(--bs-danger-bg-subtle);
    color: var(--keyaml-bad);
    border-color: var(--bs-danger-border-subtle);
}
[data-bs-theme="dark"] .keyamlStripeMode.isTest {background: var(--keyaml-selected-bg); color: var(--keyaml-accent-text);}

.keyamlDialogForm label {
    color: var(--muted);
    display: block;
    font-size: 12px;
    font-weight: 600;
}

.keyamlDialogForm input {
    width: 100%;
    box-sizing: border-box;
    margin-top: 0.45em;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0.58em 0.75em;
}

.keyamlDialogForm input[type="radio"],
.keyamlDialogForm input[type="checkbox"] {
    width: auto;
    margin: 0 0.45em 0 0;
    padding: 0;
    vertical-align: middle;
}

.keyamlDialogForm [hidden] {display: none !important;}
.keyamlSourceChoice {border: 1px solid var(--line); border-radius: 8px; padding: 0.7em 0.85em;}
.keyamlSourceChoice legend {float: none; width: auto; margin: 0 0 0.45em; font-size: 13px; font-weight: 600;}
.keyamlSourceChoice label {margin: 0.5em 0; font-size: 13px;}

.keyamlAddressField {
    position: relative;
}

.keyamlAddressField input {
    padding-right: 2.35em;
}

.keyamlAddressLoading {
    display: none;
    width: 18px;
    height: 18px;
    position: absolute;
    right: 0.7em;
    top: 50%;
    margin-top: -5px;
    border: 2px solid var(--line);
    border-top-color: var(--blue);
    border-radius: 50%;
    animation: keyamlSpin 0.7s linear infinite;
}

.keyamlAddressLoading.isOn {display: inline-block;}

.keyamlAddressMode {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5em;
    justify-self: start;
    border: 1px solid var(--blue);
    border-radius: 8px;
    background: #eef5ff;
    color: var(--blue);
    padding: 0.55em 0.8em;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}
.keyamlAddressMode:hover, .keyamlAddressMode:focus-visible {background: #dceaff;}
[data-bs-theme="dark"] .keyamlAddressMode {background: #1d3559; color: #a9c7ff; border-color: #557dd0;}
[data-bs-theme="dark"] .keyamlAddressMode:hover,
[data-bs-theme="dark"] .keyamlAddressMode:focus-visible {background: #284773;}

.keyamlManualAddress {display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.7em;}
.keyamlManualAddress[hidden], #kwAddressLookup[hidden] {display: none;}
.keyamlManualAddress .keyamlAddressWide {grid-column: 1 / -1;}
.keyamlManualAddress select {border: 1px solid var(--line); border-radius: 8px; padding: 0.58em 0.75em;}
@media (max-width: 420px) {.keyamlManualAddress {grid-template-columns: 1fr;}}

@keyframes keyamlSpin {
    to {transform: rotate(360deg);}
}

.keyamlDialogForm select {
    width: 100%;
    box-sizing: border-box;
    margin-top: 0.45em;
}

.keyamlWizard {
    min-width: 0;
    max-height: calc(100vh - 92px);
    display: flex;
    flex-direction: column;
}

.keyamlWizardHero {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1em;
    margin: -0.1em 0 1em;
    padding: 0.95em 1em;
    border: 1px solid rgba(79, 163, 227, 0.28);
    border-radius: 12px;
    background: linear-gradient(135deg, rgba(47, 107, 214, 0.10), rgba(79, 163, 227, 0.16));
}

.keyamlWizardHero div {
    display: grid;
    gap: 0.15em;
}

.keyamlWizardHero span,
.keyamlWizardHero em {
    color: var(--muted);
    font-size: 12px;
    font-style: normal;
    font-weight: 700;
    text-transform: uppercase;
}

.keyamlWizardHero strong {
    color: var(--ink);
    font-size: 20px;
}

.keyamlWizardHero em {
    color: var(--keyaml-accent-text);
    white-space: nowrap;
}

.keyamlWizardSteps {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.5em;
    margin-bottom: 1em;
}

.keyamlWizardStep {
    display: grid;
    grid-template-columns: 26px minmax(0, 1fr);
    align-content: center;
    align-items: center;
    column-gap: 0.45em;
    row-gap: 0.15em;
    min-height: 58px;
    min-width: 0;
    color: var(--muted);
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0.55em 0.65em;
}

.keyamlWizardStep span {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    color: var(--muted);
    background: var(--card);
    border: 1px solid var(--line);
    font-size: 12px;
    font-weight: 700;
}

.keyamlWizardStep b {
    min-width: 0;
    font-size: 13px;
}

.keyamlWizardStep small {
    display: none;
    grid-column: 2;
    align-self: start;
    color: inherit;
    opacity: 0.78;
    font-size: 11px;
    font-weight: 500;
    line-height: 1.25;
}

.keyamlWizardStep.isOn {
    color: #fff;
    background: var(--blue);
    border-color: var(--blue);
}

.keyamlWizardStep.isOn small {
    display: block;
}

.keyamlWizardStep.isOn span,
.keyamlWizardStep.isDone span {
    color: var(--blue);
    background: #fff;
    border-color: #fff;
}

.keyamlWizardStep.isDone {
    color: var(--navy);
    border-color: rgba(79, 163, 227, 0.45);
    background: #EEF4FE;
}

.keyamlWizardBody {
    flex: 1 1 auto;
    min-height: 210px;
    overflow-y: auto;
    max-height: calc(100vh - 355px);
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--card);
    padding: 1em;
}

.keyamlWizardChoice {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0.85em 0.95em;
    background: var(--bg);
}

.keyamlWizardChoice label {
    display: flex;
    gap: 0.55em;
    align-items: flex-start;
    color: var(--ink);
    font-weight: 600;
}

.keyamlWizardChoice input {margin-top: 0.2em;}

.keyamlWizardChoice span {
    display: grid;
    gap: 0.2em;
}

.keyamlWizardChoice small {
    color: var(--muted);
    font-weight: 500;
}

.keyamlWizardForm {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.85em;
}

.keyamlWizardForm label:first-child {
    grid-column: 1 / -1;
}

.keyamlWizardForm label:first-of-type,
.keyamlWizardSubhead,
.keyamlSpanAll {
    grid-column: 1 / -1;
}

.keyamlSpan2 {grid-column: span 2;}

.keyamlFieldWithLink {
    display: grid;
    grid-template-columns: minmax(160px, 1fr) auto;
    align-items: center;
    gap: 0.5em;
}

.keyamlFieldWithLink a {
    min-height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    white-space: nowrap;
}

.keyamlWizardSubhead {
    color: var(--ink);
    font-size: 13px;
    font-weight: 700;
    margin-top: 0.45em;
    padding: 0.8em 0 0.15em;
    border-top: 1px solid var(--line);
}

.keyamlWizardSubheadFirst {
    margin-top: 0;
    border-top: 0;
    padding-top: 0.15em;
}

.keyamlCheckRow {
    display: flex !important;
    align-items: center;
    gap: 0.55em;
}

.keyamlCheckRow input {width: auto;}

/* Let the representative fields share the wizard grid when the section is visible. */
#kwRepresentativeSection:not([hidden]) {display: contents;}

.keyamlWizardHint {
    color: var(--muted);
    font-size: 12px;
    margin: -0.1em 0 0.1em;
}

.keyamlLockedCompanyNote {
    color: var(--ink);
    font-weight: 700;
}

.keyamlWizardRole {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    gap: 1.25em;
}

.keyamlWizardRole label {
    display: inline-flex;
    align-items: center;
    gap: 0.35em;
    white-space: nowrap;
}

.keyamlWizardRole input {width: auto;}

.keyamlWizardRoleField {display: block;}
.keyamlWizardRoleField > span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    font-weight: 500;
    margin-bottom: 0.35em;
}
.keyamlWizardRoleInline {
    grid-column: auto;
    margin-top: 0.35em;
}

.keyamlWizardForm input:disabled,
.keyamlWizardForm select:disabled {
    background: #eef1f5;
    border-color: #d8dee8;
    color: #687386;
    cursor: not-allowed;
}

.keyamlWizardForm input:not(:disabled):not([type='radio']),
.keyamlWizardForm select:not(:disabled) {
    background: #fff;
    border-color: #7aa7e8;
}

.keyamlFieldHint {
    display: block;
    color: var(--muted);
    font-size: 11px;
    font-weight: 500;
    line-height: 1.35;
    margin-top: 0.35em;
}

#kwTrustDeedName + .keyamlTrustDeedDownload {
    margin-top: 0.65em;
}

.keyamlWizardSectionError {
    display: none;
    grid-column: 1 / -1;
    color: #8a1f1f;
    background: #fff3f3;
    border: 1px solid #f1b7b7;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.35;
    padding: 0.55em 0.7em;
}

.keyamlFieldInvalid {
    color: #8a1f1f !important;
}

.keyamlFieldInvalid input,
.keyamlFieldInvalid select {
    border-color: #d85c5c !important;
    background: #fff8f8;
    box-shadow: 0 0 0 3px rgba(216, 92, 92, 0.12);
}

/* Both portals use this wizard for adding and editing KeySpace entities. */
[data-bs-theme="dark"] .keyamlWizardStep.isDone {background: var(--keyaml-child-bg);}
[data-bs-theme="dark"] .keyamlWizardStep.isOn small {opacity: 1;}

[data-bs-theme="dark"] .keyamlWizardForm :is(input, select):enabled {
    color: var(--ink);
    background-color: var(--bg);
    border-color: #657992;
}
[data-bs-theme="dark"] .keyamlWizardForm :is(input, select):disabled {
    color: var(--muted);
    background-color: var(--card);
    border-color: var(--line);
}
[data-bs-theme="dark"] .keyamlWizardSectionError {
    color: var(--bs-danger-text-emphasis);
    background-color: var(--bs-danger-bg-subtle);
    border-color: var(--bs-danger-text-emphasis);
}
[data-bs-theme="dark"] .keyamlFieldInvalid {color: var(--bs-danger-text-emphasis) !important;}
[data-bs-theme="dark"] .keyamlWizardForm .keyamlFieldInvalid :is(input, select) {
    background-color: var(--bs-danger-bg-subtle);
}

.keyamlWizardForm .keyamlWizardNote,
.keyamlWizardChoice .keyamlWizardNote {
    grid-column: 1 / -1;
    border: 1px solid rgba(79, 163, 227, 0.25);
    border-radius: 10px;
    background: rgba(79, 163, 227, 0.08);
    padding: 0.75em 0.85em;
    margin-bottom: 0.35em;
}

.keyamlWizardForm .keyamlWizardNote b,
.keyamlWizardChoice .keyamlWizardNote b {
    display: block;
    color: var(--muted);
    font-size: 12px;
    margin-bottom: 0.25em;
    text-transform: uppercase;
}

.keyamlWizardForm .keyamlWizardNote span,
.keyamlWizardChoice .keyamlWizardNote span {
    color: var(--muted);
}

.keyamlWizardFormActions,
.keyamlWizardEntities {
    grid-column: 1 / -1;
}

.keyamlWizardFormActions {
    display: flex;
    justify-content: flex-end;
}

.keyamlWizardEntities {
    display: grid;
    gap: 0.45em;
}

.keyamlWizardEntities.isEmpty {
    color: var(--muted);
    border: 1px dashed var(--line);
    border-radius: 10px;
    padding: 0.75em;
}

.keyamlWizardEntities > div {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75em;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0.65em 0.75em;
    background: var(--bg);
}

.keyamlWizardEntities span,
.keyamlWizardReviewList li {
    display: grid;
    gap: 0.15em;
}

.keyamlWizardEntities small,
.keyamlWizardReviewList small {
    color: var(--muted);
    font-size: 12px;
}

.keyamlWizardEntities > div > span:first-child {min-width: 0; margin-right: auto; overflow-wrap: anywhere;}
.keyamlWizardEntityActions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.55em 0.65em;
}
@media (max-width: 760px) {
    .keyamlWizardEntities > div {align-items: stretch; flex-direction: column;}
    .keyamlWizardEntities > div > .keyamlTag {align-self: flex-start;}
}

.keyamlKsActionsCol > .btn,
.keyamlDocActionsCol > .btn {
    margin: 0.275em 0.325em;
}

.keyamlWizardReviewList {
    margin: 0;
    padding-left: 1.1em;
    display: grid;
    gap: 0.45em;
}

.keyamlWizardReview {
    display: grid;
    gap: 0.55em;
}

.keyamlWizardReview div {
    display: grid;
    grid-template-columns: 160px minmax(0, 1fr);
    gap: 0.75em;
    border-bottom: 1px solid var(--line);
    padding-bottom: 0.55em;
}

.keyamlWizardReview b {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.keyamlWizardReview span {
    color: var(--ink);
    overflow-wrap: anywhere;
}

.keyamlWizardReview .keyamlWizardNote {
    grid-template-columns: 1fr;
    gap: 0.25em;
    border: 1px solid rgba(79, 163, 227, 0.25);
    border-radius: 10px;
    background: rgba(79, 163, 227, 0.08);
    padding: 0.75em 0.85em;
}

.keyamlWizardReview .keyamlWizardNote span {
    color: var(--muted);
}

.keyamlWizardActions {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.5em;
    border-top: 1px solid var(--line);
    margin-top: 1em;
    padding-top: 0.85em;
    flex: 0 0 auto;
}

/* On a phone or a short screen the dialog scrolls from the steps through the final actions. */
@media (max-width: 760px), (max-height: 600px) {
    .keyamlWizard {display: block; max-height: none;}
    .keyamlWizardBody {min-height: 0; max-height: none; overflow: visible;}
}

@media (max-width: 991.98px) {
    .keyamlTopBar {padding: 0 16px; width: 100%; overflow: visible;}
    .keyamlLogoLink {min-width: 92px; overflow: visible;}
    .keyamlLogo {max-width: 125px; height: auto;}
    .keyamlNotification {margin-left: auto;}
    .keyamlTopUserName {max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;}
    .keyamlTopUserOrg {display: none;}
    .keyamlShell {display: block; min-height: calc(100vh - var(--top-h));}
    body.keyamlBody .keyamlSide.app-sidebar {
        position: fixed !important;
        top: var(--top-h) !important;
        bottom: 0 !important;
        left: 0 !important;
        z-index: 1040 !important;
        width: min(82vw, 280px) !important;
        min-width: 0 !important;
        height: auto !important;
        min-height: 0 !important;
        margin-left: 0 !important;
        flex-direction: column;
        align-items: stretch;
        padding: 22px 14px 18px 14px;
        box-shadow: 14px 0 35px rgba(11, 13, 18, 0.18);
        transform: translateX(-105%) !important;
        transition: transform 0.2s ease;
        overflow-y: auto;
        overscroll-behavior: contain;
        visibility: hidden;
    }
    body.keyamlAdminBody .keyamlSide.app-sidebar {width: min(95vw, 320px) !important;}
    body.sidebar-collapse .keyamlSide {
        margin-left: 0;
        display: flex;
        transform: translateX(-105%);
    }
    body.keyamlBody.sidebar-open .keyamlSide.app-sidebar {
        transform: translateX(0) !important;
        visibility: visible;
    }
    body.keyamlBody.sidebar-open .sidebar-overlay {
        display: block !important;
        position: fixed;
        inset: var(--top-h) 0 0 0;
        z-index: 1030;
        background: rgba(11, 13, 18, 0.28);
    }
    .keyamlSideNav {flex: 0 0 auto; flex-direction: column;}
    .keyamlSideItem {flex: 0 0 auto; justify-content: flex-start; padding: 0 14px;}
    .keyamlSideFoot {margin-top: auto; margin-left: 0; white-space: normal;}
    .keyamlSideNav {padding-bottom: 12px;}
    .keyamlMain {padding: 28px 18px 30px 18px;}
    .keyamlFormGrid {grid-template-columns: 1fr;}
    .keyamlWizardSteps {grid-template-columns: repeat(2, minmax(0, 1fr));}
    .keyamlWizardForm {grid-template-columns: repeat(2, minmax(0, 1fr));}
    .keyamlSpan2 {grid-column: 1 / -1;}
}

.kcName    {width: 20%;}
.kcRole    {width: 14%;}
.kcEmail   {width: 20%;}
.kcLearning {width: 13%;}
.kcAdmin   {width: 15%;}
.kcActions {width: 18%; text-align: center; white-space: nowrap;}
.kcActions .keyamlAdminActions {justify-content: center;}

/* KeySpaces table (internal admin ... see ui_keyaml_admin.js) */
.kcKsTitle  {width: 30%;}
.kcKsAgency {width: 20%;}
.kcKsCount  {width: 10%;}
.kcKsWhen   {width: 22%;}
.kcKsDo     {width: 18%;}
.keyamlReviewNav {width: 100%; border: 0; background: transparent; text-align: left; font-family: inherit;}
.keyamlReviewNav > span:nth-child(2) {white-space: nowrap;}
.keyamlReviewNavCount {flex: 0 0 auto; margin-left: auto; min-width: 20px; padding: 0.1em 0.35em; border-radius: 999px; background: #fff; color: #0B1F3A; font-size: 12px; font-weight: 700; line-height: 1.4; text-align: center;}

.keyamlReviewTable th:first-child {width: 30%;}
.keyamlReviewTable th:nth-child(2) {width: 45%;}
.keyamlReviewTable th:nth-child(3) {width: 10%;}
.keyamlReviewTable th:last-child {width: 15%; text-align: center;}
.keyamlAmlReviewTable th:nth-child(1) {width: 24%;}
.keyamlAmlReviewTable th:nth-child(2) {width: 36%;}
.keyamlAmlReviewTable th:nth-child(3) {width: 10%;}
.keyamlAmlReviewTable th:nth-child(4) {width: 18%;}
.keyamlAmlReviewTable th:nth-child(5) {width: 12%; text-align: center;}
.keyamlReviewSub {display: block; margin-top: 0.2em; color: var(--muted); line-height: 1.4;}
.keyamlReviewCount {display: inline-block; min-width: 2em; padding: 0.15em 0.5em; text-align: center; border-radius: 999px; color: #8a4b00; background: #fff3da; font-weight: 700;}
.keyamlReviewActions {white-space: nowrap; text-align: center;}
.keyamlReviewActions .btn {margin: 0.15em;}
.keyamlReviewFocus {background: var(--keyaml-review-focus, #fff3da) !important; box-shadow: inset 3px 0 #e5a238;}
[data-bs-theme="dark"] .keyamlBsTable tr.keyamlReviewFocus {--bs-table-bg: var(--keyaml-review-focus);}

@media (max-width: 760px) {
    .keyamlReviewActions {white-space: normal;}
}

.keyamlTag {
    display: inline-block;
    font-size: 80%;
    padding: 0.12em 0.55em 0.12em 0.55em;
    border-radius: 999px;
    border: 1px solid var(--line);
    color: var(--muted);
    background: var(--bg);
    margin-right: 0.3em;
}

.keyamlTag.isAdmin {color: #fff; background: var(--blue); border-color: var(--blue);}
.keyamlTag.isPaymentWaiting {color: #895400; background: #fff4d6; border-color: #edce80;}
.keyamlTag.isNoLogin {color: var(--muted);}
.keyamlTag.isPdfRecorded, .keyamlTag.isAgencyActive {color: #116d42; background: #e6f4ed; border-color: #9cd9b8;}
.keyamlTag.isPdfNeeded {color: #895400; background: #fff4d6; border-color: #edce80;}
.keyamlTag.isAgencyInactive {color: #a12626; background: #fde9e8; border-color: #f2b8b5;}

.keyamlRisk {
    display: inline-block;
    padding: 0.12em 0.55em;
    border: 1px solid;
    border-radius: 999px;
    font-size: 80%;
    font-weight: 600;
}
.keyamlRisk.isLow {color: #176b2c; background: #e8f6ec; border-color: #7ac58b;}
.keyamlRisk.isMedium {color: #8a5a00; background: #fff4d6; border-color: #e2b84d;}
.keyamlRisk.isHigh {color: #a51d2d; background: #fde8eb; border-color: #e28a96;}

.keyamlAction {margin-right: 0.35em; margin-top: 0.25em;}
.keyamlAction.isOff,
.keyamlActionBtn.isOff {
    color: var(--muted);
    background: var(--bg);
    border-color: var(--line);
    cursor: default;
}

.keyamlEmpty {color: var(--muted); font-style: italic; padding: 1.1em 0.1em 1.1em 0.1em;}

/* Stored reviewer memos and ASIC notes may use black text on a transparent page. */
.keyamlDocumentPreview {
    width: 100%;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background-color: #fff;
    color-scheme: light;
}

/* -----------------------------------------------------------------------------
   KEYAML DIALOG SKIN
   -------------------------------------------------------------------------- */
body.keyamlBody .ui_dialog,
body.keyamlLoginBody .ui_dialog {
    /* ui_dialog computes pixel coordinates once. Keep an open KeyAML dialog centred after rotation. */
    position: fixed;
    box-sizing: border-box;
    top: 50% !important;
    left: 50% !important;
    right: auto !important;
    transform: translate(-50%, -50%);
    max-width: calc(100% - 24px);
    height: auto !important;
    max-height: calc(100vh - 18px);
    max-height: calc(100dvh - 18px);
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: 0 18px 55px rgba(11, 13, 18, 0.18);
    color: var(--ink);
    font-family: Inter, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    overflow: auto;
    overscroll-behavior: contain;
}

body.keyamlBody .ui_dialog_mask,
body.keyamlLoginBody .ui_dialog_mask {
    position: fixed;
    inset: 0 !important;
    width: 100%;
    height: 100%;
    opacity: 1;
    background: rgba(11, 13, 18, 0.34);
}

body.keyamlBody .ui_dialog_title,
body.keyamlLoginBody .ui_dialog_title {
    background: var(--aml-h);
    color: #fff;
    font-weight: 700;
    border-radius: 14px 14px 0 0;
    padding: 0.72em 1em;
}

body.keyamlBody .ui_dialog_msgDiv,
body.keyamlLoginBody .ui_dialog_msgDiv {
    padding: 1em 1.1em;
    line-height: 1.45;
    box-sizing: border-box;
    overflow: visible;
}

/* Keep long Responses dialogs inside the viewport; title and Close stay fixed. */
body.keyamlBody #ui_dialog:has(.keyamlResponsesList) {
    display: flex;
    flex-direction: column;
    height: auto;
    max-height: calc(100vh - 24px);
    overflow: hidden;
}

body.keyamlBody #ui_dialog:has(.keyamlResponsesList) .ui_dialog_msgDiv {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden !important;
}

#ui_dialog .keyamlResponsesList {
    flex: 0 1 auto;
    height: auto;
    min-height: 0;
    max-height: calc(100vh - 180px);
    overflow-y: auto !important;
    scrollbar-width: auto;
    align-content: start;
    gap: 0.85rem;
    padding-right: 0.4rem;
}

#ui_dialog .keyamlResponsesList > .keyamlResponsesTop {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.65rem 0.8rem;
    border: 0;
    border-left: 3px solid var(--blue);
    border-radius: 6px;
    background: var(--bg);
}

#ui_dialog .keyamlResponsesList > .keyamlResponsesTop:not(:first-child) {
    margin-top: 0.85rem;
}

#ui_dialog .keyamlResponsesTop > b,
#ui_dialog .keyamlResponsesList > .keyamlResponsesSection {
    color: var(--navy);
    font-size: 15px;
    line-height: 1.3;
}

#ui_dialog .keyamlResponsesList > .keyamlResponsesSection {
    display: block;
    margin-top: 0.85rem;
    padding: 0.7rem 0.8rem;
    border-left: 3px solid var(--blue);
    border-radius: 6px;
    background: var(--bg);
}

#ui_dialog .keyamlResponsesTop .keyamlResponsesHelp {
    width: 24px;
    height: 24px;
    font-size: 15px;
}

#ui_dialog .keyamlResponsesList > .keyamlResponsePeriod {
    display: block;
    padding: 0.35rem 0 0;
    border: 0;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

#ui_dialog .keyamlResponsesList > .keyamlResponsePeriod.isPrevious {
    margin-top: 0.75rem;
    padding-top: 0.9rem;
    border-top: 2px solid var(--blue);
}

#ui_dialog .keyamlResponsesList > .keyamlResponseDoc {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(130px, 170px) auto;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
}

#ui_dialog .keyamlResponseDoc > b {
    min-width: 0;
    color: var(--ink);
    font-size: 13px;
    line-height: 1.4;
    overflow-wrap: anywhere;
}

#ui_dialog .keyamlResponseMeta {
    display: grid;
    gap: 3px;
    min-width: 0;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.35;
    overflow-wrap: anywhere;
}

#ui_dialog .keyamlResponseMeta small {font-size: inherit;}

@media (min-width: 761px) {
    #ui_dialog .keyamlResponseActions {
        display: flex;
        align-items: center;
        justify-content: flex-end;
        gap: 5px;
        white-space: nowrap;
    }
}

#ui_dialog1 .keyamlResponseReviewActions {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 16px;
}

@media (max-width: 760px) {
    #ui_dialog .keyamlResponsesList > .keyamlResponseDoc {
        grid-template-columns: minmax(0, 1fr);
        gap: 6px;
    }
}

body.keyamlBody .ui_dialog .roundBtnBox,
body.keyamlLoginBody .ui_dialog .roundBtnBox {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
}

body.keyamlBody .ui_dialog_close,
body.keyamlLoginBody .ui_dialog_close {
    border-top: 1px solid var(--line);
    padding: 0.8em 1em;
    text-align: right;
}

body.keyamlBody .ui_dialog_closeBtn,
body.keyamlLoginBody .ui_dialog_closeBtn,
body.keyamlBody .ui_dialog .roundBtn,
body.keyamlLoginBody .ui_dialog .roundBtn {
    display: inline-block;
    cursor: pointer;
    color: #fff;
    background: var(--blue);
    border: 1px solid var(--blue);
    border-radius: 10px;
    font-family: inherit;
    font-weight: 600;
    padding: 0.52em 0.95em;
    margin: 0.2em 0.25em;
    text-align: center;
}

body.keyamlBody .ui_dialog_closeBtn:hover,
body.keyamlLoginBody .ui_dialog_closeBtn:hover,
body.keyamlBody .ui_dialog .roundBtn:hover,
body.keyamlLoginBody .ui_dialog .roundBtn:hover {
    background: #2557c9;
    border-color: #2557c9;
    color: #fff;
}

body.keyamlBody .ui_dialog_close,
body.keyamlLoginBody .ui_dialog_close {
    border: 0;
    padding: 0;
    position: absolute;
    right: 0.65em;
    top: 0.45em;
    z-index: 1;
}

body.keyamlBody .ui_dialog_closeBtn,
body.keyamlLoginBody .ui_dialog_closeBtn,
body.keyamlBody .ui_dialog_closeBtn:hover,
body.keyamlLoginBody .ui_dialog_closeBtn:hover {
    background: transparent;
    border: 0;
    color: #fff;
    font-size: 0;
    margin: 0;
    padding: 0.1em 0.25em;
}

body.keyamlBody .ui_dialog_closeBtn::before,
body.keyamlLoginBody .ui_dialog_closeBtn::before {
    content: "\00d7";
    font-size: 24px;
    font-weight: 400;
    line-height: 1;
}

body.keyamlBody .ui_dialog input,
body.keyamlBody .ui_dialog select,
body.keyamlBody .ui_dialog textarea,
body.keyamlLoginBody .ui_dialog input,
body.keyamlLoginBody .ui_dialog select,
body.keyamlLoginBody .ui_dialog textarea {
    box-sizing: border-box;
    font-family: inherit;
    color: var(--ink);
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0.55em 0.7em;
}

body.keyamlBody .ui_dialog #keyamlMfaCode input {
    width: clamp(38px, 11vw, 52px);
    height: 56px;
    padding: 0;
    font-size: 26px;
}

body.keyamlBody .ui_dialog input:focus,
body.keyamlBody .ui_dialog select:focus,
body.keyamlBody .ui_dialog textarea:focus,
body.keyamlLoginBody .ui_dialog input:focus,
body.keyamlLoginBody .ui_dialog select:focus,
body.keyamlLoginBody .ui_dialog textarea:focus {
    outline: none;
    background: var(--card);
    border-color: var(--cyan);
    box-shadow: 0 0 0 3px rgba(79, 163, 227, 0.18);
}

/* Browsers paint saved contact details over the field's background. */
@media (forced-colors: none) {
    html[data-bs-theme="dark"] .keyamlBody :is(.keyamlDialogForm, .keyamlToolbar) input:enabled:is(:autofill, :-webkit-autofill) {
        -webkit-text-fill-color: var(--ink);
        caret-color: var(--ink);
        box-shadow: inset 0 0 0 1000px var(--keyaml-autofill-bg, var(--bg));
    }
    html[data-bs-theme="dark"] .keyamlBody :is(.keyamlDialogForm, .keyamlToolbar) input:enabled:is(:autofill, :-webkit-autofill):focus {
        box-shadow: inset 0 0 0 1000px var(--keyaml-autofill-bg, var(--card)), 0 0 0 3px rgba(79, 163, 227, 0.18);
    }
    .keyamlFieldInvalid {--keyaml-autofill-bg: var(--bs-danger-bg-subtle);}
}

body.keyamlBody .ui_dialog_err,
body.keyamlLoginBody .ui_dialog_err {
    color: var(--keyaml-bad);
    background: var(--keyaml-dialog-error-bg, #FFF5F6);
    border: 1px solid var(--keyaml-dialog-error-border, rgba(176, 0, 32, 0.25));
    border-radius: 10px;
}

body.keyamlBody .autocompleter {
    z-index: 100000;
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: 0 12px 35px rgba(11, 13, 18, 0.16);
    overflow: hidden;
    min-width: 320px;
    max-height: 260px;
    overflow-y: auto;
    background: var(--card);
}

body.keyamlBody .autocompleter-item {
    padding: 0.55em 0.75em;
    color: var(--ink);
}

body.keyamlBody .autocompleter-item-selected,
body.keyamlBody .autocompleter-item:hover {
    background: var(--keyaml-selected-bg);
}

/* -----------------------------------------------------------------------------
   SMALL EDIT ROW (inside the people list)
   -------------------------------------------------------------------------- */
.keyamlEditRow > div {background: var(--keyaml-subtle-bg);}

.keyamlEditRow input {
    width: 95%;
    font-family: inherit;
    font-size: 92%;
    color: var(--ink);
    padding: 0.35em 0.5em 0.35em 0.5em;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 8px;
    margin-bottom: 0.25em;
}

@media (max-width: 760px) {
    .keyamlLoginShell {
        align-items: flex-start;
        padding: 24px 14px;
    }

    .keyamlPanel {
        padding: 0.85em;
        border-radius: 12px;
    }

    .keyamlToolbar {
        align-items: stretch;
    }

    .keyamlToolbar input {
        flex-basis: 100%;
        min-width: 0;
        width: 100%;
    }

    .keyamlToolbar .keyamlBtn {
        flex: 1 1 9em;
        box-sizing: border-box;
    }

    .keyamlToolbar .btn,
    .keyamlToolbar button {
        flex: 1 1 9em;
    }

    .keyamlToolbarRight {margin-left: 0;}

    .keyamlKeyspaceToolbar > button.btn {
        flex: 1 1 auto;
        width: auto;
        min-height: 44px;
        padding-inline: 0.375rem;
        font-size: 0.875rem;
    }

    .keyamlTbl,
    .keyamlRow,
    .keyamlRow > div {
        display: block;
        width: auto;
    }

    .keyamlTableWrap {
        border: none;
        overflow: visible;
        background: transparent;
    }

    .keyamlBsTable,
    .keyamlBsTable thead,
    .keyamlBsTable tbody,
    .keyamlBsTable tr,
    .keyamlBsTable td {
        display: block;
        width: 100%;
    }

    .keyamlBsTable thead {display: none;}

    .keyamlBsTable tbody tr:hover {
        background: var(--card) !important;
    }

    .keyamlBsTable tbody tr.keyamlEntityChildRow:hover {
        background: var(--bg) !important;
    }

    .keyamlBsTable.table-hover > tbody > tr:hover > * {
        --bs-table-bg-state: transparent;
        --bs-table-color-state: var(--bs-table-color);
    }

    .keyamlData:hover,
    .keyamlAdminCard:not(.isOn):hover {background: var(--card);}

    .keyamlBsTable tr {
        display: block;
        border: 1px solid var(--line);
        border-radius: 12px;
        padding: 0.65em 0;
        margin-bottom: 0.75em;
        background: var(--card);
    }

    .keyamlBsTable tr.keyamlEntityChildRow {background: var(--bg);}

    .keyamlBsTable td {
        border: none;
        padding: 0.45em 0.75em;
        overflow-wrap: anywhere;
        text-align: left !important;
    }

    #keyamlViewAgency .keyamlToolbar {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
    #keyamlPeopleSearch {grid-column: 1 / -1;}
    #keyamlViewAgency .keyamlToolbar button {min-height: 44px; padding-inline: 0.25em;}

    /* Each record leads with its identity. Short status fields share a row. */
    .keyamlRecordList > tbody > tr {
        position: relative;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.45em 0.75em;
        padding: 0.75em;
    }
    .keyamlRecordList > tbody > tr > td {
        grid-column: 1 / -1;
        width: auto;
        min-width: 0;
        padding: 0;
    }
    .keyamlRecordList > tbody > tr > td:is(
        [data-label='Open'], [data-label='Monitoring'], [data-label='Complete'], [data-label='Total'],
        [data-label='Entities'], [data-label='Created'], [data-label='Status'], [data-label='Billing method'],
        [data-label='Role/status'], [data-label='Learning'], [data-label='Risk'], [data-label='Received'],
        [data-label='Uploaded'], [data-label='Uploaded by']
    ) {grid-column: span 1;}
    .keyamlRecordList > tbody > tr > .keyamlNumberCol {
        position: absolute;
        top: 0.75em;
        right: 0.75em;
        padding: 0;
        width: auto;
        font-size: 0.85em;
    }
    .keyamlRecordList > tbody > tr > .keyamlNumberCol::before {display: inline;}
    .keyamlRecordList > tbody > tr > .keyamlNumberCol + td {padding-right: 4em;}
    .keyamlRecordList > tbody > tr > :is(:first-child:not(.keyamlNumberCol), .keyamlNumberCol + td, [data-label='Action'], [data-label='Actions'])::before {
        display: none;
    }

    /* Keep the uploaded filename immediately below the document title in both portals. */
    .keyamlDocumentList > tbody > tr > td[data-label='File'] {
        grid-row: 2;
        font-size: 0.9em;
        color: var(--muted);
    }
    .keyamlDocumentList > tbody > tr > td[data-label='File']::before {display: none;}
    .keyamlDocumentList > tbody > tr > td[data-label='Size'] {grid-column: span 1;}

    #keyamlPeopleBox .keyamlData {
        grid-template-areas: "name name" "email email" "role learning" "access access" "actions actions";
        row-gap: 0;
    }
    #keyamlPeopleBox td.kcName {grid-area: name;}
    #keyamlPeopleBox td.kcName b {font-size: 1.05rem; line-height: 1.3;}
    #keyamlPeopleBox td.kcEmail {grid-area: email; margin-top: 0.15em; color: var(--muted);}
    #keyamlPeopleBox td.kcRole {grid-area: role;}
    #keyamlPeopleBox td.kcLearning {grid-area: learning;}
    #keyamlPeopleBox td.kcAdmin {grid-area: access; display: flex; flex-wrap: wrap; gap: 0.25rem;}
    #keyamlPeopleBox td.kcAdmin::before {flex-basis: 100%; margin: 0;}
    #keyamlPeopleBox td.kcAdmin .keyamlTag {margin: 0;}
    #keyamlPeopleBox td.kcActions {grid-area: actions;}
    #keyamlPeopleBox td:is(.kcRole, .kcLearning, .kcAdmin, .kcActions) {margin-top: 0.5rem;}
    #keyamlPeopleBox td:is(.kcName, .kcEmail, .kcActions)::before {display: none;}

    .keyamlAgencyDetailTable > tbody > tr:not(.keyamlEntityChildRow) {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 0.15em 0.35em;
    }

    .keyamlAgencyDetailTable > tbody > tr:not(.keyamlEntityChildRow) > td {
        box-sizing: border-box;
        min-width: 0;
    }

    .keyamlAgencyDetailTable > tbody > tr:not(.keyamlEntityChildRow) > td.keyamlNumberCol {display: none;}

    .keyamlAgencyDetailTable > tbody > tr:not(.keyamlEntityChildRow) > td.keyamlToggleCol {
        grid-area: 1 / 2;
        width: auto;
        padding: 0.35em 0.6em 0 0;
    }

    .keyamlAgencyDetailTable .keyamlEntityToggle::before {
        content: 'People';
        font-size: 12px;
        font-weight: 600;
    }

    .keyamlAgencyDetailTable > tbody > tr:not(.keyamlEntityChildRow) > td[data-label='Entity'] {
        grid-area: 1 / 1;
        width: 100%;
    }

    .keyamlAgencyDetailTable > tbody > tr:not(.keyamlEntityChildRow) > td[data-label='Entity']::before {display: none;}

    .keyamlAgencyDetailTable > tbody > tr:not(.keyamlEntityChildRow) > td.keyamlKsCenterCol,
    .keyamlAgencyDetailTable > tbody > tr:not(.keyamlEntityChildRow) > td.keyamlKsActionsCol {
        grid-column: 1 / -1;
    }

    .keyamlBsTable tr:not(.keyamlEntityChildRow) > td.keyamlNumberCol,
    .keyamlBsTable tr:not(.keyamlEntityChildRow) > td.keyamlToggleCol {
        display: inline-block;
        width: auto;
        padding-bottom: 0.15em;
        vertical-align: middle;
    }

    .keyamlBsTable tr:not(.keyamlEntityChildRow) > td.keyamlKsCenterCol:empty {
        display: none;
    }

    .keyamlBsTable tr:not(.keyamlEntityChildRow) > td[data-label='Entity'] {
        padding-top: 0.3em;
    }

    .keyamlBsTable tr:not(.keyamlEntityChildRow) > td[data-label='Entity'] > b:first-child {
        display: block;
        font-size: 1.05rem;
        line-height: 1.3;
    }

    .keyamlBsTable tr:not(.keyamlEntityChildRow) > td[data-label='Entity'] .keyamlEntitySummary {
        line-height: 1.4;
    }

    .keyamlBsTable tr:not(.keyamlEntityChildRow) > td[data-label='Actions'] {
        padding-top: 0.25em;
    }

    /* The file reference identifies a KeySpace on a card. The desktop row number is only an ordinal. */
    .keyamlKeyspaceTable > tbody > tr {
        grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr) fit-content(38%);
        align-items: start;
    }
    .keyamlKeyspaceTable.keyamlRecordList > tbody > tr > td:is(.keyamlNumberCol, .keyamlDesktopSuburb) {display: none;}
    .keyamlKeyspaceTable > tbody > tr > td[data-label='Property / reference'] {
        grid-area: 1 / 1 / 2 / 3;
        padding: 0;
    }
    .keyamlKeyspaceTable > tbody > tr > td[data-label='Status'] {grid-area: 1 / 3; justify-self: end;}
    .keyamlKeyspaceTable td[data-label='Status']::before {display: none;}
    .keyamlKeyspaceTable > tbody > tr > td[data-label='Entities'] {grid-column: 1;}
    .keyamlKeyspaceTable > tbody > tr > td[data-label='Created'] {grid-column: 2 / -1;}
    .keyamlKeyspaceTable td[data-label='Property / reference'] > b {font-size: 1.05rem; line-height: 1.3;}
    .keyamlKeyspaceTable td[data-label='Property / reference'] .keyamlMuted {margin-top: 0.15em;}
    /* Keep actions in the same footer on KeySpace, agency, user and document cards. */
    :is(.keyamlKeyspaceTable, .keyamlDocumentList, #keyamlPeopleBox, #keyamlAgenciesBox, #keyamlUsersBox) tbody > tr > td[data-label='Actions'] {
        border-top: 1px solid var(--line);
        padding: 0.5rem 0 0;
    }

    .keyamlBsTable td::before {
        content: attr(data-label);
        display: block;
        color: var(--muted);
        font-size: 11px;
        font-weight: 700;
        letter-spacing: 0.04em;
        text-transform: uppercase;
        margin-bottom: 0.15em;
    }

    .keyamlToggleCol::before {display: none !important;}

    .keyamlPager {
        justify-content: stretch;
    }

    .keyamlPagerInfo {
        flex-basis: 100%;
    }

    .keyamlPagerSize,
    .keyamlPagerBtn,
    .keyamlKsPagerSize,
    .keyamlKsPagerBtn,
    .keyamlDocPagerSize,
    .keyamlDocPagerBtn {
        flex: 1 1 7em;
    }

    .keyamlHdr {display: none;}

    .keyamlData {
        border: 1px solid var(--line);
        border-radius: 12px;
        padding: 0.35em 0;
        margin-bottom: 0.75em;
        background: var(--card);
    }

    .keyamlRow > div {
        border-bottom: none;
        padding: 0.42em 0.75em;
        overflow-wrap: anywhere;
    }

    .keyamlAdminCenterCol,
    .keyamlAdminActionsCol {
        text-align: left !important;
    }

    .keyamlAdminActionsCol {
        min-width: 0;
        white-space: normal;
    }

    /* A More dropdown occupies one button slot. An unpaired action gets the full row. */
    body.keyamlBody :is(.keyamlAdminActions, .keyamlCardActions) {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        align-items: stretch;
        gap: 8px;
        width: 100%;
        min-width: 0;
    }
    body.keyamlBody :is(.keyamlAdminActions, .keyamlCardActions) > :last-child:nth-child(odd) {grid-column: 1 / -1;}
    body.keyamlBody :is(.keyamlAdminActions, .keyamlCardActions) > .dropdown {display: grid; min-width: 0;}
    body.keyamlBody :is(.keyamlAdminActions, .keyamlCardActions) > :is(button, a.btn),
    body.keyamlBody :is(.keyamlAdminActions, .keyamlCardActions) > .dropdown > [data-bs-toggle='dropdown'] {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 100%;
        min-width: 0;
        height: auto;
        min-height: 44px;
        margin: 0;
        white-space: normal;
        overflow-wrap: anywhere;
    }
    body.keyamlBody .keyamlAgencyActionMenu .dropdown-item {min-height: 44px;}
    .keyamlBsTable td:is([data-label='Action'], [data-label='Actions'])::before {display: none;}

    .keyamlAgencyInfo,
    .keyamlSectionHead {
        display: block;
    }

    .keyamlStatsGrid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .keyamlAction,
    .keyamlActionBtn {
        display: inline-block;
        margin-top: 0.25em;
        margin-right: 0.7em;
    }

    .keyamlKsCenterCol,
    .keyamlKsActionsCol,
    .keyamlDetailTable .keyamlKsCenterCol,
    .keyamlDetailTable .keyamlKsActionsCol,
    .keyamlDocCenterCol,
    .keyamlDocActionsCol {
        text-align: left !important;
    }

    .keyamlKsActionsCol .keyamlKsAction,
    .keyamlDetailTable .keyamlKsActionsCol .btn,
    .keyamlDocActionsCol .btn {
        width: 100%;
        margin: 0.25em 0 0 0;
        justify-content: center;
    }

    .keyamlAgencyDetailTable .keyamlEntityChildRow > td {
        box-sizing: border-box;
        width: 100%;
        min-width: 0;
        padding: 0.55em 0.45em;
    }

    .keyamlEntityChildRow .keyamlRelatedPanel {
        box-sizing: border-box;
        width: 100%;
        min-width: 0;
    }

    .keyamlAdminEntityChildRow,
    .keyamlAdminEntityChildRow > td,
    .keyamlAdminEntityChildRow .keyamlRelatedPanel {
        box-sizing: border-box;
        width: 100%;
        min-width: 0;
    }

    .keyamlAdminEntityChildRow .keyamlRelatedPanel {
        margin-left: 0;
    }

    .keyamlRelatedPanel {
        border: none;
        background: transparent;
        overflow: visible;
    }

    .keyamlEntityChildRow .keyamlRelatedPanel {margin-left: 0;}

    .keyamlRelatedPanelHead {
        padding: 0.55em 0.75em;
        border: 1px solid var(--line);
        border-radius: 10px 10px 0 0;
    }

    .keyamlRelatedGrid:not(.keyamlRelatedGridHead) {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 0.5em;
        padding: 0.7em 0.75em;
        border: 1px solid var(--line);
        border-top: none;
        background: var(--keyaml-child-bg);
    }

    .keyamlRelatedGrid:not(.keyamlRelatedGridHead) > :nth-child(-n+2),
    .keyamlRelatedGrid:not(.keyamlRelatedGridHead) > :nth-child(4) {display: none;}

    .keyamlRelatedGrid:not(.keyamlRelatedGridHead) > div {
        display: block;
        margin: 0;
    }

    .keyamlRelatedGrid:not(.keyamlRelatedGridHead) > div:nth-child(3) {
        min-width: 0;
    }

    .keyamlRelatedGrid:not(.keyamlRelatedGridHead) > .keyamlRelatedCenter {
        display: flex;
        justify-content: space-between;
        gap: 0.75em;
        text-align: left;
    }

    .keyamlRelatedGrid:not(.keyamlRelatedGridHead) > .keyamlRelatedActions {
        display: block;
        text-align: left;
    }

    .keyamlChildEntityCard {
        grid-template-columns: 1fr;
        gap: 0.45em;
    }

    .keyamlRelatedPanelHead,
    .keyamlRelatedGrid {
        display: block;
    }

    .keyamlRelatedGrid > div,
    .keyamlRelatedGrid > span {
        display: block;
        margin-bottom: 0.45em;
    }

    .keyamlRelatedGrid > :nth-child(3),
    .keyamlRelatedGrid > :nth-child(4) {
        left: 0;
    }
    .keyamlRelatedGridHead > :nth-child(5) {left: 0;}

    .keyamlRelatedGridHead {display: none;}

    .keyamlChildLabel {
        display: block;
    }

    .keyamlBsTable td[data-label='Property / reference'] {
        padding-top: 0.75em;
    }

    .keyamlBsTable td[data-label='Actions'] {
        padding-bottom: 0.75em;
    }

    .keyamlDetailToolbar {
        display: grid;
        grid-template-columns: 1fr;
        align-items: stretch;
    }

    .keyamlDetailToolbar .keyamlToolbarRight {
        width: 100%;
    }

    .keyamlEditRow input {
        width: 100%;
    }

}

@media (max-width: 520px) {
    :root {
        --top-h: 56px;
    }

    .keyamlTopBar {
        padding: 0 10px;
        gap: 6px;
    }

    .keyamlLogo {
        max-width: 125px;
        height: auto;
    }

    .keyamlTopAgency {
        display: none;
    }

    .keyamlMenuToggle,
    .keyamlIconBtn {
        width: 44px;
        height: 44px;
        margin-left: 2px;
    }

    .keyamlTopUser {
        gap: 0;
        margin-left: 0;
    }

    .keyamlAccountLabel {
        display: none;
    }

    .keyamlAvatar {
        width: 32px;
        height: 32px;
        font-size: 11px;
    }

    .keyamlNotification {
        margin-left: auto;
    }

    .keyamlMain {
        padding: 22px 12px 28px 12px;
    }

    .keyamlH1 {
        font-size: 24px;
    }

    .keyamlKeyspaceCta {
        min-height: 54px;
        margin-top: 28px;
        font-size: 15px;
        padding: 0 0.8em;
    }

    .keyamlSideItem {
        min-width: 0;
        gap: 7px;
        font-size: 12.5px;
    }

    .keyamlSideIcon {
        width: 16px;
        font-size: 16px;
    }

    .keyamlSideFoot {
        width: 100%;
        margin-left: 0;
    }

    .keyamlFormGrid {
        gap: 10px;
    }

    .keyamlStatsGrid {
        grid-template-columns: 1fr;
    }

    .keyamlToolbar .keyamlBtn {
        flex-basis: 100%;
    }

    .keyamlToolbar .btn,
    .keyamlToolbar button {
        flex-basis: 100%;
    }

    .keyamlLoginCard {
        width: 100%;
        max-width: none;
        border-radius: 14px;
    }

    .keyamlLoginHead {
        padding: 1.2em 1.1em 0 1.1em;
    }

    .keyamlLoginInner {
        padding: 1.25em 1.1em 1.4em;
    }

    .keyamlWizardHero {
        display: none;
    }

    .keyamlWizardSteps {
        grid-template-columns: 1fr;
        gap: 0.5em;
        margin-bottom: 0.75em;
    }

    .keyamlWizardStep {
        min-height: 50px;
    }

    .keyamlWizardBody {
        padding: 0.8em;
    }

    .keyamlWizardForm {
        grid-template-columns: 1fr;
        gap: 0.75em;
    }

    .keyamlFieldWithLink {
        grid-template-columns: 1fr;
    }

    .keyamlWizardReview div {grid-template-columns: 1fr;}
    .keyamlWizardActions {
        gap: 0.55em;
        padding-top: 0.65em;
    }
    .keyamlWizardActions .btn {flex: 1 1 100%;}

    body.keyamlBody .ui_dialog,
    body.keyamlLoginBody .ui_dialog {
        width: calc(100vw - 16px) !important;
        max-width: calc(100vw - 16px);
    }

    .keyamlCodeInput {
        letter-spacing: 0.2em;
        font-size: 1.15em;
    }
}

/* Restore the full table layout after leaving mobile width. */
@media (min-width: 761px) {
    .keyamlBsTable,
    .keyamlBsTable thead,
    .keyamlBsTable tbody {
        display: table;
        width: 100%;
    }
    .keyamlBsTable thead {display: table-header-group;}
    .keyamlBsTable tbody {display: table-row-group;}
    .keyamlBsTable tr {
        display: table-row;
        width: auto;
        border: 0;
        border-radius: 0;
        padding: 0;
        margin: 0;
        background: transparent;
    }
    .keyamlBsTable td,
    .keyamlBsTable th {
        display: table-cell;
        width: auto;
    }
    .keyamlBsTable td::before {display: none !important; content: none !important;}
}

body.keyamlBody .ui_dialog:has(.keyamlWizard) {
    width: min(980px, calc(100vw - 28px)) !important;
}

body.keyamlBody .ui_dialog:has(.keyamlWizard) .ui_dialog_msgDiv {
    box-sizing: border-box;
    width: 100% !important;
}

@media (max-width: 520px) {
    body.keyamlBody .ui_dialog:has(.keyamlWizard) {
        max-width: calc(100vw - 16px) !important;
        width: calc(100vw - 16px) !important;
    }
    body.keyamlBody .autocompleter {
        min-width: 0;
        max-width: calc(100vw - 24px);
    }
    .keyamlProgressPeopleList span {white-space: normal;}
    .keyamlProgressGroup {margin-left: 0.5em;}
}

@media (max-width: 760px) {
    .keyamlBsTable thead:has(.keyamlActionsHeading) {display: block; width: 100%;}
    .keyamlBsTable thead:has(.keyamlActionsHeading) tr {
        display: flex;
        justify-content: flex-end;
        width: 100%;
        margin: 0 0 0.4em;
        padding: 0;
        border: 0;
        background: transparent;
    }
    .keyamlBsTable thead:has(.keyamlActionsHeading) th {display: none;}
    .keyamlBsTable thead:has(.keyamlActionsHeading) th:has(.keyamlActionsHeading) {
        display: block;
        width: auto;
        padding: 0;
        border: 0;
        background: transparent;
        text-align: right;
    }
    .keyamlBsTable thead .keyamlActionsHeading {display: flex; font-size: 0; gap: 0;}
    .keyamlBsTable thead .keyamlActionsHelp {
        min-width: 44px;
        min-height: 44px;
        margin: 0;
        font-size: 16px;
    }

    /* The native selector fits beside the existing action help on small screens. */
    .keyamlBsTable thead:has(.keyamlMobileSort) {
        display: block;
        width: 100%;
        margin-bottom: 0.5em;
    }
    .keyamlBsTable thead:has(.keyamlMobileSort) tr {
        display: flex;
        align-items: center;
        gap: 0.4em;
        width: 100%;
        margin: 0;
        padding: 0;
        border: 0;
        background: transparent;
    }
    .keyamlBsTable thead:has(.keyamlMobileSort) th,
    .keyamlBsTable thead:has(.keyamlMobileSort) .keyamlSortButton {display: none;}
    .keyamlBsTable thead th:has(> .keyamlMobileSort) {
        display: block;
        flex: 1;
        min-width: 0;
        width: auto;
        padding: 0;
        border: 0;
        background: transparent;
    }
    .keyamlMobileSort {
        display: flex;
        align-items: center;
        gap: 8px;
        color: var(--ink);
        font-size: 14px;
        text-transform: none;
        letter-spacing: normal;
        white-space: nowrap;
    }
    .keyamlMobileSort select {
        min-width: 0;
        flex: 1;
        min-height: 44px;
        padding: 0 8px;
        border: 1px solid var(--line);
        border-radius: 8px;
        background: var(--card);
        color: var(--ink);
        font: inherit;
        font-weight: 400;
    }
    .keyamlBsTable thead:has(.keyamlMobileSort) th:has(.keyamlActionsHeading) {
        display: block;
        flex: 0 0 auto;
        margin-left: auto;
    }

}
