/* Mela AI website assistant */
.mela-widget {
    --mela-navy: #173b67;
    --mela-blue: #2f5597;
    --mela-blue-dark: #1e3a6b;
    --mela-bg: #f4f7fc;
    --mela-text: #26364a;
    --mela-muted: #8a96a8;
    --mela-border: #e3e9f2;
    /* Updated by mela-chat.js to the bottom edge of the site header. */
    --mela-top: 20px;
    /* Raised by mela-chat.js above the cookie bar while it is showing. */
    --mela-bottom: 30px;
    font-family: inherit;
}

.mela-widget [hidden] {
    display: none !important;
}

.mela-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* Panel: compact greeting ("teaser") that grows into the full chat ("open") */
.mela-panel {
    position: fixed;
    right: 30px;
    bottom: var(--mela-bottom);
    /* Above the cookie bar (1050); drops behind open menus via the :has() rule below. */
    z-index: 1060;
    display: flex;
    flex-direction: column;
    width: 360px;
    max-width: calc(100vw - 24px);
    max-height: calc(var(--mela-vh, 100vh) - var(--mela-top) - var(--mela-bottom));
    background: #fff;
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 12px 40px rgba(23, 59, 103, 0.28);
}

.mela-widget[data-state="teaser"] .mela-panel {
    max-height: min(470px, calc(var(--mela-vh, 100vh) - var(--mela-top) - var(--mela-bottom)));
}

body:has(.header .mega-nav-item.mega-open) .mela-panel,
body:has(.header .mega-nav-item.mega-open) .mela-launcher,
body:has(.mobile-dropdown-menu.open) .mela-panel,
body:has(.mobile-dropdown-menu.open) .mela-launcher {
    z-index: 990;
}

.mela-widget[data-state="open"] .mela-panel {
    width: 400px;
    height: min(680px, calc(var(--mela-vh, 100vh) - var(--mela-top) - var(--mela-bottom)));
}

@media (min-width: 1200px) {
    .mela-widget[data-state="open"] .mela-panel {
        height: min(clamp(680px, 50vw, 900px), calc(var(--mela-vh, 100vh) - var(--mela-top) - var(--mela-bottom)));
    }
}

.mela-widget[data-state="teaser"] .mela-disclaimer,
.mela-widget[data-state="teaser"] #melaRestart {
    display: none;
}

.mela-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: linear-gradient(135deg, var(--mela-navy), var(--mela-blue));
    color: #fff;
    flex-shrink: 0;
}

.mela-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: #fff;
    flex-shrink: 0;
}

.mela-title {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    line-height: 1.25;
}

.mela-title strong {
    font-size: 15px;
    font-weight: 600;
}

.mela-title span {
    font-size: 11px;
    opacity: 0.85;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mela-online-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    margin-right: 3px;
    border-radius: 50%;
    background: #3ddc84;
    vertical-align: middle;
}

.mela-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: #fff;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    opacity: 0.85;
    transition: background 0.2s ease, opacity 0.2s ease;
}

.mela-icon-btn.mela-close {
    font-size: 24px;
}

.mela-icon-btn:hover,
.mela-icon-btn:focus-visible {
    opacity: 1;
    background: rgba(255, 255, 255, 0.15);
    outline: none;
}

.mela-body {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
    min-height: 0;
    padding: 14px;
    background: var(--mela-bg);
    overflow-y: auto;
    overscroll-behavior: contain;
}

.mela-msg {
    max-width: 88%;
    padding: 10px 12px;
    font-size: 13.5px;
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    animation: melaFadeIn 0.3s ease-out;
}

.mela-msg-bot {
    align-self: flex-start;
    border-radius: 4px 14px 14px 14px;
    background: #fff;
    color: var(--mela-text);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.mela-msg-user {
    align-self: flex-end;
    border-radius: 14px 4px 14px 14px;
    background: var(--mela-blue);
    color: #fff;
    white-space: pre-wrap;
}

.mela-msg-error {
    border: 1px solid #f3c9c9;
    background: #fff7f7;
}

.mela-msg p {
    margin: 0;
}

.mela-msg p + p,
.mela-msg p + ul,
.mela-msg p + ol,
.mela-msg ul + p,
.mela-msg ol + p {
    margin-top: 8px;
}

.mela-msg ul,
.mela-msg ol {
    margin: 0;
    padding-left: 18px;
}

/* Site-wide styles reset list markers, so draw our own. */
.mela-widget .mela-msg ul,
.mela-widget .mela-msg ol {
    list-style: none;
    counter-reset: mela-item;
}

.mela-widget .mela-msg li {
    position: relative;
    display: block;
    counter-increment: mela-item;
}

.mela-widget .mela-msg ul > li::before {
    content: "";
    position: absolute;
    left: -12px;
    top: 0.62em;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--mela-blue);
}

.mela-widget .mela-msg ol > li::before {
    content: counter(mela-item) ".";
    position: absolute;
    left: -18px;
    color: var(--mela-blue);
    font-weight: 600;
}

.mela-msg li + li {
    margin-top: 3px;
}

.mela-msg a {
    color: var(--mela-blue);
    font-weight: 500;
    text-decoration: underline;
}

.mela-msg-sources {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 4px 10px;
    margin-top: 9px;
    padding-top: 7px;
    border-top: 1px solid var(--mela-border);
    font-size: 11px;
}

.mela-msg-sources-label {
    color: var(--mela-muted);
    font-weight: 600;
}

.mela-msg-sources a {
    overflow-wrap: anywhere;
}

.mela-retry {
    display: block;
    margin-top: 8px;
    padding: 5px 12px;
    border: 1px solid var(--mela-blue);
    border-radius: 14px;
    background: #fff;
    color: var(--mela-blue);
    font-size: 12px;
    cursor: pointer;
}

.mela-retry:hover {
    background: var(--mela-blue);
    color: #fff;
}

.mela-typing {
    align-self: flex-start;
    display: flex;
    gap: 4px;
    padding: 12px 14px;
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.mela-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #9aa8bd;
    animation: melaTyping 1.2s infinite ease-in-out;
}

.mela-typing span:nth-child(2) { animation-delay: 0.15s; }
.mela-typing span:nth-child(3) { animation-delay: 0.3s; }

.mela-quick-replies {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding: 2px 14px 14px;
    background: var(--mela-bg);
    flex-shrink: 0;
    animation: melaFadeIn 0.3s ease-out;
}

.mela-chip {
    display: flex;
    align-items: center;
    min-width: 0;
    min-height: 48px;
    padding: 9px 11px;
    border: 1px solid var(--mela-border);
    border-left: 3px solid var(--mela-blue);
    border-radius: 8px;
    background: #fff;
    color: var(--mela-navy);
    font-size: 12px;
    font-weight: 600;
    line-height: 1.3;
    text-align: left;
    overflow-wrap: anywhere;
    cursor: pointer;
    transition: background-color 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

.mela-chip:hover,
.mela-chip:focus-visible {
    border-color: #8ca8c7;
    background: #f0f5fb;
    box-shadow: 0 2px 7px rgba(23, 59, 103, 0.1);
    transform: translateY(-1px);
}

.mela-chip:focus-visible {
    outline: 2px solid var(--mela-blue);
    outline-offset: 2px;
}

.mela-chip:active {
    transform: translateY(0);
}

.mela-composer {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    margin: 0;
    padding: 10px 12px;
    border-top: 1px solid var(--mela-border);
    background: #fff;
    flex-shrink: 0;
}

.mela-composer textarea {
    flex: 1;
    min-height: 22px;
    max-height: 120px;
    padding: 6px 2px;
    border: none;
    outline: none;
    resize: none;
    background: transparent;
    color: var(--mela-text);
    font: inherit;
    font-size: 13.5px;
    line-height: 1.45;
}

.mela-composer textarea::placeholder {
    color: var(--mela-muted);
}

.mela-send {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    border: none;
    border-radius: 50%;
    background: var(--mela-blue);
    color: #fff;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.mela-send:hover {
    background: var(--mela-blue-dark);
}

.mela-send:disabled {
    background: #aab6c9;
    cursor: not-allowed;
}

.mela-disclaimer {
    margin: 0;
    padding: 0 12px 8px;
    background: #fff;
    color: var(--mela-muted);
    font-size: 10.5px;
    text-align: center;
    flex-shrink: 0;
}

/* Launcher */
.mela-launcher {
    position: fixed;
    right: 30px;
    bottom: var(--mela-bottom);
    z-index: 1060;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px 10px 10px;
    border: none;
    border-radius: 24px;
    background: var(--mela-blue);
    color: #fff;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.25;
    text-align: left;
    cursor: pointer;
    box-shadow: 0 5px 15px rgba(47, 85, 151, 0.3);
    transition: box-shadow 0.2s ease, transform 0.2s ease;
    animation: melaSlideUp 0.35s ease-out;
}

.mela-launcher:hover,
.mela-launcher:focus-visible {
    box-shadow: 0 8px 20px rgba(47, 85, 151, 0.45);
    transform: translateY(-1px);
    outline: none;
}

.mela-launcher-avatar {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    background: #fff;
}

.mela-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    background: #e53935;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 20px;
    text-align: center;
    animation: melaPulse 1.8s ease-in-out infinite;
}

/* Panel grows out of the launcher corner, and shrinks back into it. */
.mela-panel {
    transform-origin: bottom right;
}

.mela-panel.mela-opening {
    animation: melaGrow 0.42s cubic-bezier(0.2, 0.9, 0.3, 1.15);
}

.mela-panel.mela-closing {
    animation: melaShrink 0.22s ease-in forwards;
}

/* Attention nudges, only while auto-open is still allowed. */
.mela-launcher.is-nudging::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    box-shadow: 0 0 0 0 rgba(47, 85, 151, 0.55);
    animation: melaRing 2.4s ease-out infinite;
    pointer-events: none;
}

.mela-launcher.is-nudging .mela-launcher-avatar {
    animation: melaWave 4s ease-in-out infinite;
}

.mela-launcher-typing {
    display: none;
    align-items: center;
    gap: 4px;
    padding: 0 6px;
}

.mela-launcher-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #fff;
    animation: melaTyping 1.1s infinite ease-in-out;
}

.mela-launcher-typing span:nth-child(2) { animation-delay: 0.15s; }
.mela-launcher-typing span:nth-child(3) { animation-delay: 0.3s; }

.mela-launcher.is-typing .mela-launcher-text {
    display: none;
}

.mela-launcher.is-typing .mela-launcher-typing {
    display: inline-flex;
}

@keyframes melaGrow {
    0% { opacity: 0; transform: scale(0.25) translateY(24px); }
    60% { opacity: 1; }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes melaShrink {
    from { opacity: 1; transform: scale(1); }
    to { opacity: 0; transform: scale(0.3) translateY(24px); }
}

@keyframes melaRing {
    0% { box-shadow: 0 0 0 0 rgba(47, 85, 151, 0.55); }
    70%, 100% { box-shadow: 0 0 0 14px rgba(47, 85, 151, 0); }
}

@keyframes melaWave {
    0%, 70%, 100% { transform: rotate(0deg); }
    75% { transform: rotate(-12deg); }
    80% { transform: rotate(10deg); }
    85% { transform: rotate(-8deg); }
    90% { transform: rotate(6deg); }
}

@keyframes melaTyping {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30% { transform: translateY(-4px); opacity: 1; }
}

@keyframes melaFadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes melaSlideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes melaPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}

/* The site's back-to-top button (#scrollUp) shares the bottom-right corner. */
html.mela-panel-visible #scrollUp {
    display: none !important;
}

html.mela-launcher-visible #scrollUp {
    bottom: calc(var(--mela-launcher-offset, 90px)) !important;
}

@media (max-width: 1024px) {
    .mela-widget[data-state="open"] .mela-panel {
        width: 370px;
    }

    .mela-panel,
    .mela-launcher {
        right: 20px;
    }
}

@media (max-width: 768px) {
    .mela-panel,
    .mela-launcher {
        right: 12px;
    }

    .mela-panel,
    .mela-widget[data-state="open"] .mela-panel {
        width: min(360px, calc(100vw - 24px));
        max-height: calc(var(--mela-vh, 100vh) - var(--mela-top) - var(--mela-bottom));
    }

    .mela-launcher {
        padding: 8px 14px 8px 8px;
        font-size: 12px;
    }

    .mela-launcher-avatar {
        width: 30px;
        height: 30px;
    }
}

/* Short screens (landscape phones, small laptops): use the space that is available. */
@media (max-height: 560px) and (min-width: 521px) {
    .mela-widget[data-state="open"] .mela-panel,
    .mela-widget[data-state="teaser"] .mela-panel {
        height: calc(var(--mela-vh, 100vh) - var(--mela-top) - var(--mela-bottom));
    }

    .mela-disclaimer {
        display: none;
    }
}

@media (max-width: 520px) {
    /* Teaser stays a compact card; the open chat fills the width below the site header. */
    .mela-widget[data-state="teaser"] .mela-panel {
        left: 8px;
        right: 8px;
        width: auto;
        max-width: none;
    }

    .mela-widget[data-state="open"] .mela-panel {
        top: var(--mela-top);
        right: 0;
        bottom: var(--mela-bottom);
        left: 0;
        width: 100%;
        max-width: 100%;
        height: auto;
        max-height: none;
        border-radius: 14px 14px 0 0;
    }

    .mela-launcher {
        right: 10px;
        bottom: max(10px, var(--mela-bottom));
    }

    /* Icon-only launcher on phones so it doesn't cover page content. */
    .mela-launcher .mela-launcher-text {
        display: none;
    }

    .mela-launcher {
        padding: 6px;
        border-radius: 50%;
    }

    .mela-launcher-avatar {
        width: 44px;
        height: 44px;
    }

    html.mela-open,
    html.mela-open body {
        overflow: hidden;
    }

    .mela-composer textarea {
        font-size: 16px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .mela-panel,
    .mela-panel.mela-opening,
    .mela-panel.mela-closing,
    .mela-launcher,
    .mela-launcher.is-nudging::after,
    .mela-launcher.is-nudging .mela-launcher-avatar,
    .mela-msg,
    .mela-quick-replies,
    .mela-badge,
    .mela-typing span {
        animation: none;
    }
}
