:root {
    --hui-modal-navy: #0b3762;
    --hui-modal-blue: #176b91;
    --hui-modal-gold: #c98a22;
    --hui-modal-text: #294b68;
    --hui-modal-muted: #6f8497;
    --hui-modal-line: #dfe9f0;
    --hui-modal-soft: #f4f8fb;
    --hui-modal-radius: 20px;
    --hui-modal-shadow: 0 28px 80px rgba(4, 31, 57, .3);
    --hui-modal-backdrop: rgba(7, 29, 49, .66);
}

/* Shared backdrop treatment. */
.hwi-overlay,
.hwb-overlay,
.hwe-overlay {
    background: var(--hui-modal-backdrop);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
}

/* Shared modal surface. */
.hwi-dialog,
.hwb-panel,
.hwe-card {
    border: 1px solid rgba(23, 107, 145, .16);
    border-radius: var(--hui-modal-radius);
    color: var(--hui-modal-text);
    background: #fff;
    box-shadow: var(--hui-modal-shadow);
}

/* Shared ocean-blue header. */
.hwi-header,
.hwb-head,
.hwe-head {
    color: #fff;
    background:
        radial-gradient(circle at 88% -40%, rgba(255, 255, 255, .2), transparent 45%),
        linear-gradient(135deg, #0a3563 0%, #135884 62%, #1f729b 100%);
    border-bottom: 0;
    box-shadow: none;
}

.hwi-header { padding: 28px 76px 24px 32px; }
.hwi-kicker { color: #f2c66f; }
.hwi-title { color: #fff; font-size: 27px; line-height: 1.38; }

/* Shared close control. */
.hwi-close,
.hwb-close,
.hwe-head button {
    width: 40px;
    height: 40px;
    border: 1px solid rgba(255, 255, 255, .45);
    border-radius: 50%;
    color: #fff;
    background: rgba(255, 255, 255, .1);
    font-size: 25px;
    line-height: 36px;
    transition: background-color .18s ease, transform .18s ease;
}
.hwi-close:hover,
.hwi-close:focus,
.hwb-close:hover,
.hwb-close:focus,
.hwe-head button:hover,
.hwe-head button:focus {
    outline: 0;
    background: rgba(255, 255, 255, .22);
    transform: rotate(4deg);
}
.hwi-close { top: 21px; right: 22px; }

/* Platform introduction: the body keeps the rich-text editor's own formatting. */
.hwi-dialog { width: min(820px, 100%); max-height: min(86vh, 820px); }
.hwi-content {
    padding: 28px 32px 12px;
    scrollbar-width: thin;
    scrollbar-color: #9db2c2 transparent;
}
.hwi-content::-webkit-scrollbar { width: 7px; }
.hwi-content::-webkit-scrollbar-thumb { border-radius: 8px; background: #9db2c2; }
.hwi-content a:not(.btn):not([class*="button"]):not([role="button"]) {
    color: #0875a8;
    font-weight: 700;
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
    transition: color .18s ease, text-decoration-color .18s ease;
}
.hwi-content a:not(.btn):not([class*="button"]):not([role="button"]):visited { color: #0875a8; }
.hwi-content a:not(.btn):not([class*="button"]):not([role="button"]):hover { color: #d08a18; }
.hwi-content a:not(.btn):not([class*="button"]):not([role="button"]):focus-visible {
    border-radius: 2px;
    outline: 2px solid rgba(8, 117, 168, .35);
    outline-offset: 3px;
}
.hwi-footer {
    padding: 16px 32px 24px;
    border-top: 1px solid var(--hui-modal-line);
    background: #fff;
    text-align: right;
}
.hwi-confirm,
.hwb-calculate,
.hwb-cta.is-primary {
    border-radius: 10px;
    background: linear-gradient(135deg, #0c4a78, #17739c);
    box-shadow: 0 9px 22px rgba(17, 93, 135, .22);
}
.hwi-confirm { min-width: 160px; min-height: 44px; }
.hwi-confirm:hover,
.hwi-confirm:focus,
.hwb-calculate:hover,
.hwb-calculate:focus,
.hwb-cta.is-primary:hover,
.hwb-cta.is-primary:focus { outline: 0; background: linear-gradient(135deg, #083d67, #125f87); }

/* Budget calculator uses the same centred modal shell. */
.hwb-overlay { z-index: 2147482980; }
.hwb-panel {
    top: 50%;
    right: auto;
    bottom: auto;
    left: 50%;
    width: min(520px, calc(100% - 32px));
    max-width: 520px;
    max-height: min(88vh, 820px);
    transform: translate(-50%, -46%) scale(.98);
    -webkit-transform: translate(-50%, -46%) scale(.98);
    opacity: 0;
    transition: transform .25s ease, opacity .2s ease, visibility .25s ease;
}
.hwb-panel.is-open {
    transform: translate(-50%, -50%) scale(1);
    -webkit-transform: translate(-50%, -50%) scale(1);
    opacity: 1;
}
.hwb-head { min-height: 76px; padding: 16px 64px 16px 22px; }
.hwb-head strong { font-size: 18px; }
.hwb-body { padding: 22px 24px 26px; }

/* Exchange-rate window receives a backdrop and matches the modal geometry. */
.hwe-overlay {
    position: fixed;
    z-index: 2147482970;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    inset: 0;
    visibility: hidden;
    opacity: 0;
    transition: opacity .22s ease, visibility .22s ease;
}
.hwe-widget.is-open .hwe-overlay { visibility: visible; opacity: 1; }
.hwe-card {
    z-index: 2147482980;
    top: 50%;
    right: auto;
    left: 50%;
    width: min(500px, calc(100% - 32px));
    max-height: min(88vh, 760px);
    transform: translate(-50%, -46%) scale(.98);
}
.hwe-widget.is-open .hwe-card { transform: translate(-50%, -50%) scale(1); }
.hwe-head { min-height: 76px; padding: 15px 18px; }
.hwe-head-icon { color: #0f5d87; background: #fff; box-shadow: none; }
.hwe-content { padding: 18px 20px 20px; }
body.huiwai-exchange-open { overflow: hidden !important; }

@media (max-width: 767px) {
    :root { --hui-modal-radius: 17px; }
    .hwi-overlay { align-items: flex-end; padding: 10px; }
    .hwi-dialog { max-height: 91vh; border-radius: 18px 18px 14px 14px; }
    .hwi-header { padding: 22px 60px 18px 20px; }
    .hwi-title { font-size: 21px; }
    .hwi-close { top: 15px; right: 14px; }
    .hwi-content { padding: 20px 18px 7px; }
    .hwi-footer { padding: 13px 18px max(18px, env(safe-area-inset-bottom)); }
    .hwi-confirm { width: 100%; }

    .hwb-panel,
    .hwe-card {
        top: auto;
        right: 8px;
        bottom: 8px;
        left: 8px;
        width: auto;
        max-width: none;
        max-height: calc(100vh - 16px);
        height: auto;
        border-radius: 18px;
        transform: translateY(28px) scale(.985);
        -webkit-transform: translateY(28px) scale(.985);
    }
    .hwb-panel.is-open,
    .hwe-widget.is-open .hwe-card {
        transform: translateY(0) scale(1);
        -webkit-transform: translateY(0) scale(1);
    }
    .hwb-head, .hwe-head { min-height: 70px; }
    .hwb-body { padding: 18px 16px 22px; }
    .hwe-content { padding: 14px 13px 16px; }
}

@media (prefers-reduced-motion: reduce) {
    .hwi-close, .hwb-close, .hwe-head button, .hwb-panel, .hwe-card, .hwe-overlay { transition: none !important; }
}
