/*
    Bank connection health (chx-): the connections strip on Accounts and My Accounts, the connection sheet that opens from
    it, from "Needs attention", an account's sheet and the Smart Signals, and the connection chip on an account row. Built
    on the Accounts tokens (--acx-* in admin-accounts.css) and the shared surfaces (--rc-*, --tx-*), so it follows the
    accent and both themes; dark mode follows the site's data-bs-theme="dark" on <html>.
*/

:root {
    --chx-sheet-bg: #FFFFFF;
    --chx-tile: #F4F5FA;
    --chx-tile-border: rgba(15, 23, 42, .06);
    --chx-line: rgba(15, 23, 42, .1);
    --chx-logo-bg: #FFFFFF;
    --chx-glow-critical: rgba(239, 68, 68, .16);
    --chx-glow-caution: rgba(245, 158, 11, .18);
    --chx-glow-positive: rgba(34, 197, 94, .16);
    --chx-glow-neutral: rgba(90, 69, 230, .12);
    --chx-upgrade: linear-gradient(135deg, #7C3AED 0%, #DB2777 100%);
    /* Text and glyphs on a solid tone fill: white on the deep light-theme tones. */
    --chx-on-tone: #FFFFFF;
    /* The primary button: the accent into a deep cyan, white text above 4.5:1 at both ends. */
    --chx-primary: linear-gradient(135deg, var(--acx-accent) 0%, color-mix(in srgb, var(--acx-accent) 72%, #0E7490) 100%);
}

[data-bs-theme="dark"] {
    --chx-sheet-bg: #151A26;
    --chx-tile: rgba(255, 255, 255, .05);
    --chx-tile-border: rgba(255, 255, 255, .07);
    --chx-line: rgba(255, 255, 255, .12);
    --chx-logo-bg: #F4F5FA;
    --chx-glow-critical: rgba(248, 113, 113, .22);
    --chx-glow-caution: rgba(251, 191, 36, .2);
    --chx-glow-positive: rgba(34, 197, 94, .2);
    --chx-glow-neutral: rgba(129, 115, 245, .2);
    /* The dark theme's tones are light (amber, rose, mint): white on them fails contrast, so the deeper fills stay. */
    --chx-upgrade: linear-gradient(135deg, #7C3AED 0%, #DB2777 100%);
    /* Dark ink on the bright dark-theme tone fills (about 7:1 on rose and amber). */
    --chx-on-tone: #0B1020;
    --chx-primary: linear-gradient(135deg, color-mix(in srgb, var(--acx-accent) 78%, #1E1B4B) 0%, color-mix(in srgb, var(--acx-accent) 60%, #155E75) 100%);
}

/* ------------------------------------------------------------------ Tones (AccountTonePalette classes) */

.chx-tone-positive { --chx-tone: var(--acx-positive); --chx-soft: var(--acx-positive-soft); --chx-glow: var(--chx-glow-positive); }
.chx-tone-negative,
.chx-tone-critical { --chx-tone: var(--acx-critical); --chx-soft: var(--acx-critical-soft); --chx-glow: var(--chx-glow-critical); }
.chx-tone-caution { --chx-tone: var(--acx-caution); --chx-soft: var(--acx-caution-soft); --chx-glow: var(--chx-glow-caution); }
.chx-tone-neutral { --chx-tone: var(--acx-accent); --chx-soft: var(--acx-neutral-soft); --chx-glow: var(--chx-glow-neutral); }

/* ------------------------------------------------------------------ The connections strip */

.chx-banner {
    position: relative;
    margin-bottom: 1.25rem;
    padding: 12px 14px;
    border-radius: 20px;
    border: 1px solid var(--rc-card-border);
    background:
        linear-gradient(120deg, var(--chx-soft) 0%, color-mix(in srgb, var(--chx-soft) 35%, transparent) 42%, transparent 78%),
        var(--rc-card);
    box-shadow: var(--rc-shadow);
    color: var(--rc-text);
    overflow: hidden;
    animation: acx-rise .4s cubic-bezier(.2, .8, .2, 1) both;
}

.chx-banner-main {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
}

.chx-banner-glyph {
    position: relative;
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
    width: 38px;
    height: 38px;
    border-radius: 12px;
    background: var(--chx-soft);
    color: var(--chx-tone);
    font-size: 15px;
}

/* While a check runs, a ring breathes around the glyph. */
.chx-banner.is-checking .chx-banner-glyph::after {
    content: "";
    position: absolute;
    inset: -4px;
    border-radius: 15px;
    border: 2px solid var(--chx-tone);
    opacity: 0;
    animation: chx-breathe 1.4s ease-in-out infinite;
}

.chx-banner-text {
    display: flex;
    flex-direction: column;
    gap: 1px;
    flex: 1 1 220px;
    min-width: 0;
}

.chx-banner-title {
    font-family: var(--tx-font);
    font-size: 14px;
    font-weight: 600;
    line-height: 1.3;
}

.chx-banner-detail {
    font-family: var(--tx-font-text);
    font-size: 12px;
    line-height: 1.4;
    color: var(--acx-muted);
}

.chx-banner-check {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    flex: 0 0 auto;
    margin-left: auto;
    padding: 7px 13px;
    border-radius: 999px;
    border: 1px solid var(--chx-line);
    background: var(--acx-glass);
    color: var(--rc-text);
    font-family: var(--tx-font);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color .15s ease, border-color .15s ease, transform .15s ease;
}

.chx-banner-check:hover:not(:disabled) { border-color: var(--chx-tone); transform: translateY(-1px); }
.chx-banner-check:disabled { opacity: .7; cursor: default; }
.chx-banner-check .spinner-border { width: 12px; height: 12px; border-width: 2px; color: var(--chx-tone); }

.chx-banner-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.chx-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    max-width: 100%;
    padding: 6px 10px 6px 6px;
    border-radius: 999px;
    border: 1px solid color-mix(in srgb, var(--chx-tone) 28%, transparent);
    background: var(--chx-soft);
    color: var(--rc-text);
    font-size: 12px;
    cursor: pointer;
    transition: transform .15s ease, box-shadow .15s ease;
}

.chx-chip:hover { transform: translateY(-1px); box-shadow: 0 6px 16px color-mix(in srgb, var(--chx-tone) 22%, transparent); }

.chx-chip-glyph {
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--chx-tone);
    color: var(--chx-on-tone);
    font-size: 11px;
}

/* min-width: 0 lets a long bank name shrink inside the pill (a flex child) so the ellipsis shows at 320 px. */
.chx-chip-bank { min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chx-chip-badge { color: var(--chx-tone); font-weight: 600; white-space: nowrap; }
.chx-chip-chevron { font-size: 10px; color: var(--acx-muted); }

.chx-banner-notice {
    margin: 10px 0 0;
    font-size: 12px;
    line-height: 1.45;
    animation: acx-rise .3s cubic-bezier(.2, .8, .2, 1) both;
}

.chx-banner-notice.chx-notice-positive { color: var(--acx-positive); }
.chx-banner-notice.chx-notice-caution { color: var(--acx-caution); }
.chx-banner-notice.chx-notice-critical { color: var(--acx-critical); }
.chx-banner-notice.chx-notice-neutral { color: var(--acx-muted); }

@media (max-width: 575.98px) {
    .chx-banner-check { flex: 1 1 100%; justify-content: center; margin-left: 0; }
}

/* ------------------------------------------------------------------ The account row's connection chip */

.chx-row-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex: 0 0 auto;
    max-width: 60%;
    padding: 1px 7px;
    border-radius: 999px;
    background: var(--chx-soft);
    color: var(--chx-tone);
    font-size: 10.5px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chx-row-chip i { flex: 0 0 auto; font-size: 9px; }
.chx-row-chip > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }

/* ------------------------------------------------------------------ The connection sheet */

section.dbs-sheet.chx-sheet {
    width: min(640px, calc(100vw - 1.5rem));
    max-height: min(92vh, calc(100dvh - 1rem));
    padding: .65rem 1.4rem 1.6rem;
    background:
        radial-gradient(120% 55% at 0% 0%, var(--chx-glow) 0%, transparent 60%),
        radial-gradient(90% 40% at 100% 0%, color-mix(in srgb, var(--chx-glow) 60%, transparent) 0%, transparent 70%),
        var(--chx-sheet-bg);
    background-attachment: local;
    scrollbar-width: thin;
}

section.dbs-sheet.chx-sheet--critical,
section.dbs-sheet.chx-sheet--negative { --chx-tone: var(--acx-critical); --chx-soft: var(--acx-critical-soft); --chx-glow: var(--chx-glow-critical); }
section.dbs-sheet.chx-sheet--caution { --chx-tone: var(--acx-caution); --chx-soft: var(--acx-caution-soft); --chx-glow: var(--chx-glow-caution); }
section.dbs-sheet.chx-sheet--positive { --chx-tone: var(--acx-positive); --chx-soft: var(--acx-positive-soft); --chx-glow: var(--chx-glow-positive); }
section.dbs-sheet.chx-sheet--neutral { --chx-tone: var(--acx-accent); --chx-soft: var(--acx-neutral-soft); --chx-glow: var(--chx-glow-neutral); }

[data-bs-theme="dark"] section.dbs-sheet.chx-sheet {
    background:
        radial-gradient(120% 55% at 0% 0%, var(--chx-glow) 0%, transparent 60%),
        radial-gradient(90% 40% at 100% 0%, color-mix(in srgb, var(--chx-glow) 60%, transparent) 0%, transparent 70%),
        var(--chx-sheet-bg);
}

.chx-body {
    display: flex;
    flex-direction: column;
    gap: 16px;
    color: var(--rc-text);
}

.chx-head { display: flex; align-items: flex-start; gap: 14px; }

.chx-logo-wrap { position: relative; flex: 0 0 auto; }

.chx-logo {
    display: grid;
    place-items: center;
    width: 52px;
    height: 52px;
    border-radius: 16px;
    background: var(--chx-logo-bg);
    border: 1px solid var(--chx-tile-border);
    overflow: hidden;
    box-shadow: 0 8px 22px color-mix(in srgb, var(--chx-tone) 22%, transparent);
}

.chx-logo img { width: 100%; height: 100%; object-fit: contain; padding: 7px; }

.chx-logo-initials {
    color: #FFFFFF;
    font-family: var(--tx-font);
    font-size: 17px;
    font-weight: 700;
    letter-spacing: .02em;
}

.chx-logo-badge {
    position: absolute;
    right: -6px;
    bottom: -6px;
    display: grid;
    place-items: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid var(--chx-sheet-bg);
    background: var(--chx-tone);
    color: var(--chx-on-tone);
    font-size: 10px;
}

.chx-titles { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 6px; }

.chx-eyebrow { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; font-size: 12px; color: var(--acx-muted); }

.chx-pill {
    display: inline-flex;
    align-items: center;
    padding: 2px 9px;
    border-radius: 999px;
    background: var(--chx-soft);
    color: var(--chx-tone);
    font-family: var(--tx-font);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .02em;
}

.chx-bank { font-weight: 600; }

.chx-shared {
    padding: 1px 7px;
    border-radius: 6px;
    background: var(--acx-neutral-soft);
    font-size: 10.5px;
    font-weight: 500;
}

.chx-title {
    margin: 0;
    font-family: var(--tx-font);
    font-size: 1.2rem;
    font-weight: 600;
    line-height: 1.28;
    color: var(--rc-text);
    overflow-wrap: anywhere;
}

.chx-close {
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 11px;
    background: var(--chx-tile);
    color: var(--rc-text);
    cursor: pointer;
}

.chx-close:disabled { opacity: .5; cursor: default; }

.chx-summary {
    margin: 0;
    font-family: var(--tx-font-text);
    font-size: 14px;
    line-height: 1.6;
    color: var(--rc-text);
}

.chx-facts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
    gap: 8px;
    margin: 0;
}

.chx-fact {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 10px 12px;
    border-radius: 14px;
    background: var(--chx-tile);
    border: 1px solid var(--chx-tile-border);
    min-width: 0;
}

.chx-fact dt {
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--acx-muted);
}

.chx-fact dd { margin: 0; font-family: var(--tx-font); font-size: 13.5px; font-weight: 600; overflow-wrap: anywhere; }
.chx-fact-positive { color: var(--acx-positive); }
.chx-fact-negative,
.chx-fact-critical { color: var(--acx-critical); }
.chx-fact-caution { color: var(--acx-caution); }
.chx-fact-neutral { color: var(--rc-text); }

.chx-section { display: flex; flex-direction: column; gap: 10px; }

.chx-kicker {
    margin: 0;
    font-family: var(--tx-font);
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--acx-muted);
}

.chx-steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }

.chx-step {
    position: relative;
    display: flex;
    gap: 12px;
    padding-bottom: 14px;
}

.chx-step:last-child { padding-bottom: 0; }

/* The thread between the numbers. */
.chx-step:not(:last-child)::before {
    content: "";
    position: absolute;
    left: 13px;
    top: 30px;
    bottom: 2px;
    width: 2px;
    border-radius: 2px;
    background: color-mix(in srgb, var(--chx-tone) 25%, transparent);
}

.chx-step-num {
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--chx-soft);
    color: var(--chx-tone);
    font-family: var(--tx-font);
    font-size: 12.5px;
    font-weight: 700;
}

.chx-step-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; padding-top: 4px; }
.chx-step-title { font-family: var(--tx-font); font-size: 13.5px; font-weight: 600; line-height: 1.35; }
.chx-step-detail { font-size: 12.5px; line-height: 1.5; color: var(--acx-muted); }

.chx-actions { display: flex; flex-direction: column; gap: 8px; }

.chx-btn,
.chx-ask {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 11px 14px;
    border-radius: 16px;
    font-family: var(--tx-font);
    text-align: left;
}

.chx-btn {
    border: 1px solid var(--chx-tile-border);
    background: var(--chx-tile);
    color: var(--rc-text);
    cursor: pointer;
    transition: transform .15s ease, box-shadow .2s ease, filter .15s ease;
}

.chx-btn:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 10px 22px rgba(15, 23, 42, .1); }
.chx-btn:focus-visible { outline: 2px solid var(--acx-accent); outline-offset: 2px; }
.chx-btn:disabled { opacity: .6; cursor: default; }
.chx-btn[aria-busy="true"]:disabled { opacity: 1; }

.chx-btn-primary {
    border-color: transparent;
    background: var(--chx-primary);
    color: #FFFFFF;
    box-shadow: 0 10px 24px color-mix(in srgb, var(--acx-accent) 32%, transparent);
}

.chx-btn-primary:hover:not(:disabled) { filter: brightness(1.05); box-shadow: 0 14px 28px color-mix(in srgb, var(--acx-accent) 38%, transparent); }

.chx-btn.is-upgrade {
    border-color: transparent;
    background: var(--chx-upgrade);
    color: #FFFFFF;
    box-shadow: 0 10px 24px rgba(219, 39, 119, .28);
}

.chx-btn-glyph {
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    border-radius: 11px;
    background: var(--chx-soft);
    color: var(--chx-tone);
    font-size: 14px;
}

.chx-btn-primary .chx-btn-glyph,
.chx-btn.is-upgrade .chx-btn-glyph { background: rgba(255, 255, 255, .2); color: #FFFFFF; }

.chx-btn-glyph .spinner-border { width: 15px; height: 15px; border-width: 2px; }

.chx-btn-text { display: flex; flex-direction: column; gap: 2px; flex: 1 1 auto; min-width: 0; }
.chx-btn-label { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 14px; font-weight: 600; line-height: 1.3; }
.chx-btn-detail { font-family: var(--tx-font-text); font-size: 12px; line-height: 1.4; opacity: .82; }
.chx-btn-chevron { flex: 0 0 auto; font-size: 11px; opacity: .6; }

.chx-tag {
    display: inline-flex;
    align-items: center;
    padding: 1px 7px;
    border-radius: 999px;
    background: var(--chx-upgrade);
    color: #FFFFFF;
    font-size: 9.5px;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
}

.chx-btn-primary .chx-tag,
.chx-btn.is-upgrade .chx-tag { background: rgba(255, 255, 255, .24); }

.chx-ask {
    border: 1px dashed var(--chx-line);
    background: transparent;
    color: var(--rc-text);
}

.chx-link {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    align-self: flex-start;
    padding: 4px 2px;
    color: var(--acx-accent);
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
}

.chx-link:hover { text-decoration: underline; }
.chx-link i { font-size: 11px; }

.chx-notice {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    padding: 10px 12px;
    border-radius: 14px;
    font-size: 13px;
    line-height: 1.5;
    animation: acx-rise .3s cubic-bezier(.2, .8, .2, 1) both;
}

.chx-notice i { margin-top: 3px; font-size: 12px; }
.chx-notice-positive { background: var(--acx-positive-soft); color: var(--acx-positive); }
.chx-notice-caution { background: var(--acx-caution-soft); color: var(--acx-caution); }
.chx-notice-critical { background: var(--acx-critical-soft); color: var(--acx-critical); }
.chx-notice-neutral { background: var(--chx-tile); color: var(--rc-text); }

.chx-note {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin: 0;
    font-size: 12.5px;
    line-height: 1.5;
    color: var(--acx-muted);
}

.chx-note i { margin-top: 3px; font-size: 11px; }

.chx-accounts { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; }

.chx-account {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    max-width: 100%;
    padding: 6px 11px 6px 6px;
    border-radius: 999px;
    background: var(--chx-tile);
    border: 1px solid var(--chx-tile-border);
    font-size: 12.5px;
}

.chx-account-glyph {
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--acx-chip-bg);
    color: var(--acx-chip-fg);
    font-size: 10px;
}

.chx-account-name { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chx-foot {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin: 2px 0 0;
    padding-top: 12px;
    border-top: 1px solid var(--chx-line);
    font-size: 11.5px;
    line-height: 1.5;
    color: var(--acx-muted);
}

.chx-foot i { margin-top: 2px; color: var(--acx-positive); }

.chx-empty { align-items: center; text-align: center; padding: 12px 0 4px; }
.chx-empty .chx-actions { width: 100%; }

.chx-empty-glyph {
    display: inline-grid;
    place-items: center;
    width: 48px;
    height: 48px;
    border-radius: 16px;
    background: var(--chx-soft, var(--acx-neutral-soft));
    color: var(--chx-tone, var(--acx-muted));
    font-size: 18px;
}

.chx-bone-logo { display: block; flex: 0 0 auto; width: 52px; height: 52px; border-radius: 16px; }
.chx-bone-line { display: block; height: 12px; border-radius: 6px; }
.chx-bone-title { display: block; width: 72%; height: 20px; border-radius: 8px; }
.chx-bone-button { display: block; height: 58px; border-radius: 16px; }

@keyframes chx-breathe {
    0% { opacity: 0; transform: scale(.92); }
    50% { opacity: .45; transform: scale(1); }
    100% { opacity: 0; transform: scale(1.08); }
}

@media (max-width: 575.98px) {
    section.dbs-sheet.chx-sheet { width: 100%; padding: .6rem 1rem 1.25rem; }
    .chx-title { font-size: 1.08rem; }
    .chx-facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
    .chx-banner,
    .chx-banner-notice,
    .chx-notice,
    .chx-banner.is-checking .chx-banner-glyph::after { animation: none; }

    .chx-btn,
    .chx-chip,
    .chx-banner-check { transition: none; }
}

/* The site's own Reduce motion setting (Settings > Accessibility), honored like prefers-reduced-motion. */
[data-a11y-reduce-motion="on"] .chx-banner,
[data-a11y-reduce-motion="on"] .chx-banner-notice,
[data-a11y-reduce-motion="on"] .chx-notice,
[data-a11y-reduce-motion="on"] .chx-banner.is-checking .chx-banner-glyph::after { animation: none !important; }

[data-a11y-reduce-motion="on"] .chx-btn,
[data-a11y-reduce-motion="on"] .chx-chip,
[data-a11y-reduce-motion="on"] .chx-banner-check { transition: none !important; }
