/* Keep the original RAP design while accommodating native Vaadin page elements. */
html {
    min-height: 100%;
    background-color: #eee;
}

body {
    margin: 0;
    min-height: 100vh;
    padding-bottom: 0;
}

#legacy-portal {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    width: 100%;
}

#portal-content {
    flex: 1 0 auto;
}

.portal-sign-in {
    margin: 8px auto 30px;
}

.portal-sign-in p {
    margin: 12px 0 0;
    color: #555;
}

.pending-service {
    color: #777;
    cursor: default;
}

.services-list-wrapper > p:last-child {
    font-size: 14px;
    color: #666;
    margin-top: 20px;
}

.portal-help {
    margin-top: 28px;
}

.portal-help a,
.portal-help a:hover,
.portal-help a:focus,
.portal-help a:active {
    color: #165891;
    text-decoration: none;
}

.portal-help-links {
    margin: 0;
    padding: 0;
    color: #526577;
}

.portal-policies {
    margin-bottom: 20px;
}

.portal-access-note {
    margin: 18px auto 0;
    color: #555;
}

#main-footer-wrapper {
    position: static;
    flex-shrink: 0;
    width: 100%;
    margin-top: 30px;
}

#main-footer {
    padding: 12px 20px;
}

#main-footer .portal-brand {
    display: inline-block;
    width: 380px;
    max-width: 100%;
    box-sizing: border-box;
    padding: 16px;
    background-color: #172b40;
    border-radius: 8px;
}

#main-footer img {
    display: block;
    width: 100%;
    max-width: 100%;
    height: auto;
}

#auth-panel {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 20px;
    width: 100%;
    max-width: 790px;
    margin: 20px auto 0;
}

#auth-panel .provider-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    min-width: 0;
    min-height: 185px;
    width: auto;
    height: auto;
    margin: 0;
    padding: 16px 10px 15px;
}

#auth-panel .provider-institutional {
    border-color: #7caccb;
    box-shadow: 0 1px 3px rgba(40, 96, 144, .2);
}

#auth-panel .img-wrapper,
#auth-panel .img-wrapper a {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 65px;
}

#auth-panel .img-wrapper {
    margin-bottom: 8px;
}

#auth-panel .img-wrapper img {
    display: block;
    max-width: 150px;
    width: auto;
    height: 60px;
    object-fit: contain;
}

.provider-title {
    margin: 0 0 12px;
    color: #244d70;
    font-size: 16px;
    font-weight: normal;
    line-height: 1.25;
}

/* All provider labels use the shared .provider-title typography. */

.provider-action,
.provider-unavailable-action {
    margin-top: auto;
    max-width: 100%;
    padding: 7px 10px;
    font-size: 12px;
    white-space: normal;
}

.provider-unavailable-action:disabled {
    border: 1px solid #d8dce1;
    border-radius: 4px;
    background-color: #f5f6f7;
    color: #626b75;
    line-height: 1.4;
    opacity: 1;
    cursor: default;
}

a:focus-visible {
    outline: 3px solid #24388e;
    outline-offset: 3px;
}

@media (max-width: 700px) {
    #auth-panel {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 15px;
    }
}

@media (max-width: 420px) {
    #auth-panel {
        grid-template-columns: 1fr;
        max-width: 280px;
    }
}

@media (max-width: 600px) {
    .page-title-wrapper h1 {
        font-size: 29px;
        margin-top: 15px;
    }

    .credits {
        font-size: 10px;
    }

    .services-list-wrapper {
        font-size: 16px;
    }

    #footer-credits {
        padding: 0 12px;
        font-size: 11px;
    }
}

/* Account Management heading and original decorative account icon. */
.account-management-title {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 12px 16px;
}

.account-management-title .account-management-icon {
    display: block;
    flex-shrink: 0;
    width: 63px;
    height: 50px;
    object-fit: contain;
}

@media (max-width: 600px) {
    .account-management-title {
        font-size: 28px;
        gap: 10px 12px;
    }
}

/* Responsive provider page: preserve content in normal document flow. */
html {
    height: auto;
    min-height: 100%;
    overflow-y: auto;
}

body {
    height: auto;
    min-height: 100vh;
    padding-bottom: 0;
}

#legacy-portal {
    height: auto;
    min-height: 100vh;
    min-height: 100svh;
    min-width: 0;
    overflow-wrap: break-word;
}

/* Let the banner title wrap and reserve room for the image credit. */
#main-header {
    height: auto;
    min-height: 90px;
    margin-bottom: 20px;
    background-size: auto 100%;
}

#main-header .page-title-wrapper {
    position: relative;
    top: auto;
    right: auto;
    bottom: auto;
    left: auto;
    box-sizing: border-box;
    width: 100%;
    padding: 16px 12px 26px;
}

#main-header .page-title-wrapper h1 {
    margin: 0;
    font-size: clamp(24px, 3.4vw, 42px);
    line-height: 1.12;
}

#main-header .credits {
    top: auto;
    right: 8px;
    bottom: 4px;
    left: 8px;
    font-size: clamp(8px, 1vw, 12px);
    line-height: 1.2;
    overflow-wrap: anywhere;
}

#portal-content {
    flex: 0 0 auto;
    box-sizing: border-box;
    width: 100%;
    max-width: 1170px;
    min-width: 0;
    padding-right: clamp(12px, 2vw, 24px);
    padding-left: clamp(12px, 2vw, 24px);
}

.account-management-title {
    margin: 0;
    font-size: clamp(26px, 3vw, 36px);
    line-height: 1.2;
}

/* Four providers above three centered providers on desktop windows. */
#auth-panel {
    display: grid;
    grid-template-columns: repeat(8, minmax(0, 1fr));
    width: 100%;
    max-width: 1060px;
    margin: 20px auto 0;
    gap: 20px;
}

#auth-panel > .provider-card {
    grid-column: span 2;
    min-width: 0;
    max-width: 100%;
}

#auth-panel > .provider-card:nth-child(5) {
    grid-column: 2 / span 2;
    grid-row: 2;
}

#auth-panel > .provider-card:nth-child(6) {
    grid-column: 4 / span 2;
    grid-row: 2;
}

#auth-panel > .provider-card:nth-child(7) {
    grid-column: 6 / span 2;
    grid-row: 2;
}

#auth-panel .img-wrapper,
#auth-panel .img-wrapper a {
    max-width: 100%;
}

#auth-panel .img-wrapper img {
    max-width: 150px;
    max-width: min(150px, 100%);
}

.provider-title {
    max-width: 100%;
    overflow-wrap: anywhere;
}

.portal-links {
    max-width: 100%;
    margin: 18px auto 6px;
    font-family: inherit;
    font-size: 13px;
    font-weight: normal;
    line-height: 1.42857143;
    color: #666;
    text-align: center;
}

.portal-links a,
.portal-links a:visited {
    color: inherit;
    text-decoration: none;
    white-space: nowrap;
}

.portal-links a:hover,
.portal-links a:focus,
.portal-links a:active {
    color: #165891;
    text-decoration: none;
}

#main-footer-wrapper {
    position: static;
    flex: 0 0 auto;
    width: 100%;
    margin: 0;
}

#footer-credits {
    max-width: 1170px;
    margin: 0 auto 6px;
    padding: 0 16px;
    font-size: 13px;
    line-height: 1.42857143;
    overflow-wrap: anywhere;
}

#main-footer {
    padding: 8px 16px;
}

#main-footer .portal-brand {
    width: 380px;
    max-width: 100%;
}

/* Three columns on medium windows; the final card remains centered. */
@media (max-width: 991px) {
    #auth-panel {
        grid-template-columns: repeat(6, minmax(0, 1fr));
        max-width: 790px;
        gap: 16px;
    }

    #auth-panel > .provider-card:nth-child(n) {
        grid-column: span 2;
        grid-row: auto;
        justify-self: stretch;
        width: auto;
    }

    #auth-panel > .provider-card:last-child {
        grid-column: 3 / span 2;
    }
}

/* Two columns on narrow windows. Text and navigation may wrap naturally. */
@media (max-width: 640px) {
    #auth-panel {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        max-width: 520px;
        gap: 12px;
    }

    #auth-panel > .provider-card:nth-child(n) {
        grid-column: span 2;
        grid-row: auto;
    }

    #auth-panel > .provider-card:last-child {
        grid-column: 2 / span 2;
    }

    .portal-links,
    #footer-credits {
        font-size: 12px;
    }

    #main-footer .portal-brand {
        width: 320px;
        padding: 12px;
    }
}

/* One readable column for phones and strongly zoomed browser windows. */
@media (max-width: 400px) {
    #auth-panel {
        grid-template-columns: 1fr;
        max-width: 320px;
    }

    #auth-panel > .provider-card:nth-child(n) {
        grid-column: auto;
        grid-row: auto;
        width: auto;
    }
}

/* Preserve the 60-pixel provider icons while saving height on laptops. */
@media (min-width: 641px) and (max-height: 800px) {
    #main-header {
        min-height: 64px;
        margin-bottom: 12px;
    }

    #main-header .page-title-wrapper {
        padding: 10px 12px 18px;
    }

    #main-header .page-title-wrapper h1 {
        font-size: 32px;
    }

    #main-header .credits {
        bottom: 3px;
        font-size: 10px;
    }

    .account-management-title {
        font-size: 32px;
    }

    .account-management-title .account-management-icon {
        width: 55px;
        height: 44px;
    }

    #auth-panel {
        margin-top: 12px;
        gap: 12px;
    }

    #auth-panel .provider-card {
        min-height: 148px;
        padding: 10px 10px 9px;
    }

    #auth-panel .img-wrapper,
    #auth-panel .img-wrapper a {
        height: 60px;
    }

    #auth-panel .img-wrapper {
        margin-bottom: 4px;
    }

    .provider-title {
        margin-bottom: 6px;
    }

    .provider-action,
    .provider-unavailable-action {
        padding: 6px 10px;
    }

    .portal-links {
        margin-top: 12px;
    }

    .portal-links,
    #footer-credits {
        font-size: 12px;
    }

    #main-footer .portal-brand {
        width: 300px;
        padding: 12px;
    }
}

/* A second height step keeps common 600-pixel desktop viewports usable. */
@media (min-width: 641px) and (max-height: 640px) {
    #main-header {
        min-height: 56px;
        margin-bottom: 8px;
    }

    #main-header .page-title-wrapper {
        padding: 8px 12px 16px;
    }

    #main-header .page-title-wrapper h1 {
        font-size: 28px;
    }

    .account-management-title {
        font-size: 28px;
    }

    .account-management-title .account-management-icon {
        width: 50px;
        height: 40px;
    }

    #auth-panel {
        margin-top: 10px;
        gap: 10px;
    }

    #auth-panel .provider-card {
        min-height: 136px;
        padding: 8px 10px;
    }

    .provider-title {
        margin-bottom: 4px;
    }

    .provider-action,
    .provider-unavailable-action {
        padding: 5px 10px;
    }

    .portal-links {
        margin-top: 10px;
    }

    .portal-links,
    #footer-credits {
        font-size: 11px;
    }

    #main-footer {
        padding: 6px 16px;
    }

    #main-footer .portal-brand {
        width: 240px;
    }
}

/* Keep the institutional site link inside the author credit. */
#footer-credits a,
#footer-credits a:visited {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
}

#footer-credits a:hover,
#footer-credits a:focus {
    color: #165891;
}

/* Shared institutional blue and underlined help links. */
#legacy-portal {
    --jrap-institutional-blue: #337ab7;
}

#portal-content .account-management-title {
    color: var(--jrap-institutional-blue);
}

.portal-links a,
.portal-links a:visited,
.portal-links a:hover,
.portal-links a:focus,
.portal-links a:active {
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
}

/* Preserve the original certificate emblem and render its wordmark as text. */
#auth-panel .img-wrapper:has(> img[src$="/x509-200.png"]) {
    position: relative;
    width: 150px;
    max-width: 100%;
}

#auth-panel .img-wrapper:has(> img[src$="/x509-200.png"]) > img {
    clip-path: inset(0 73% 0 0);
}

#auth-panel .img-wrapper:has(> img[src$="/x509-200.png"])::after {
    content: "X.509";
    content: "X.509" / "";
    position: absolute;
    top: 50%;
    left: 42px;
    transform: translateY(-50%);
    color: var(--jrap-institutional-blue);
    font-family: "DejaVu Sans", Arial, Helvetica, sans-serif;
    font-size: 32px;
    font-weight: 700;
    line-height: 1;
    white-space: nowrap;
    pointer-events: none;
}

/* Account management and verified identity joins share the existing portal layout. */
.account-page { max-width: 1060px; margin: 20px auto; overflow-wrap: anywhere; }
.account-page h1 { color: var(--jrap-institutional-blue, #337ab7); }
.account-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.account-identity .panel-body { min-width: 0; }
.account-form { display: inline-block; margin: 8px 12px 8px 0; }
.account-form label { display: inline-block; margin: 0 12px 12px 0; }
.account-form label input { margin-right: 6px; }
.account-page > a { display: inline-block; margin: 8px 18px 8px 0; text-decoration: underline; }
.account-login-notice { max-width: 900px; margin: 8px auto; text-align: center; }
@media (max-width: 640px) { .account-pair { grid-template-columns: minmax(0, 1fr); } }

/* BEGIN JRAP CIE PLACEHOLDER */
/* Eight providers: four per row on desktop, with the existing responsive breakpoints. */
#auth-panel > .provider-card:nth-child(n) {
    grid-column: span 2;
    grid-row: auto;
}

/* The official CieID mark is white; retain its original paths on the official blue. */
#auth-panel .img-wrapper img[src$="/cie-id.svg"] {
    box-sizing: border-box;
    width: 60px;
    height: 60px;
    padding: 6px;
    border-radius: 6px;
    background-color: #0053a2;
}

/* Center the two final providers in the existing three-column tablet layout. */
@media (min-width: 641px) and (max-width: 991px) {
    #auth-panel > .provider-card:nth-child(7) { grid-column: 2 / span 2; }
    #auth-panel > .provider-card:nth-child(8) { grid-column: 4 / span 2; }
}

@media (max-width: 400px) {
    #auth-panel > .provider-card:nth-child(n) {
        grid-column: auto;
        grid-row: auto;
    }
}
/* END JRAP CIE PLACEHOLDER */

/* Account hub: retain the original portal styling and separate user/admin actions. */
.portal-toolbar { display: flex; justify-content: flex-end; margin: 12px 0 -8px; }
.portal-settings-link, .portal-settings-link:visited {
    display: inline-flex; align-items: center; justify-content: center;
    width: 44px; height: 44px; border: 1px solid #c5d6e4; border-radius: 50%;
    background: #fff; color: #245780; text-decoration: none; font-family: Arial, sans-serif;
    font-size: 27px; line-height: 1;
}
.portal-settings-link:hover, .portal-settings-link:focus { background: #e8f1f8; color: #17456b; text-decoration: none; }
.account-tools-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; align-items: start; }
.account-tools-grid > .account-section { margin: 0; min-width: 0; }
.account-tools-grid .account-form { margin: 12px 0; }
.account-tools-grid .account-section > a { display: block; margin: 12px 0; }
.account-tools-grid + a { margin-top: 18px; }
.account-section {
    margin: 20px 0;
    padding: 18px 20px;
    border: 1px solid #d6dce1;
    border-radius: 4px;
    background: #fff;
}
.account-section > h2 {
    margin: 0 0 14px;
    color: var(--jrap-institutional-blue, #337ab7);
    font-size: 23px;
}
.account-section > a {
    display: inline-block;
    margin: 6px 18px 8px 0;
    text-decoration: underline;
}
.account-section p { color: #4b5660; }
.account-identities {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
    gap: 16px;
}
.account-identities .account-identity { margin-bottom: 0; }
.account-identities > h2 { grid-column: 1 / -1; margin: 0; font-size: 18px; }
@media (max-width: 640px) {
    .account-tools-grid { grid-template-columns: minmax(0, 1fr); }
    .account-section { padding: 14px 12px; }
    .account-section > h2 { font-size: 21px; }
}
/* Native email confirmation shares the same account cards and responsive grid. */
#ia2-registration-confirm[hidden],
#registration-profile[hidden],
#registration-duplicate[hidden] { display: none !important; }
.account-access-links { display: flex; flex-wrap: wrap; gap: 1rem; margin-top: 1rem; }
#legacy-portal .ia2-registration-form { display: block; width: 100%; margin-right: 0; }
#ia2-registration-confirm, #registration-profile { width: 100%; max-width: 640px; }
