.qdm-chat-launch {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .55rem;
    min-height: 44px;
    padding: .6rem 1rem;
    border: 1px solid #d5a74e;
    border-radius: 999px;
    background: #f5dfac;
    color: #2b2034;
    font: 800 .875rem/1.35 system-ui, sans-serif;
    text-decoration: none;
    cursor: pointer;
}

.qdm-chat-launch::before {
    content: '✦';
    color: #6a3d45;
}

.hero .qdm-chat-launch {
    position: relative;
    z-index: 1;
    margin: .9rem .25rem 0 0;
}

.qdm-chat-launch:hover {
    background: #f9ecce;
}

.qdm-chat {
    --qdm-chat-ink: #271d30;
    --qdm-chat-plum: #4b3154;
    --qdm-chat-muted: #65566b;
    --qdm-chat-line: #e6ddd1;
    --qdm-chat-paper: #fffdf8;
    width: min(94vw, 36rem);
    max-width: none;
    height: min(742px, 88vh);
    height: min(742px, 88dvh);
    max-height: none;
    margin: auto;
    padding: 0;
    overflow: hidden;
    border: 1px solid #d9cbbd;
    border-radius: 24px;
    background: var(--qdm-chat-paper);
    color: var(--qdm-chat-ink);
    box-shadow: 0 26px 90px #150f1a66;
    font: 400 .9375rem/1.5 system-ui, sans-serif;
    color-scheme: light;
    box-sizing: border-box;
}

.qdm-chat *,
.qdm-chat *::before,
.qdm-chat *::after {
    box-sizing: border-box;
}

.qdm-chat::backdrop {
    background: #20192d99;
}

.qdm-chat__layout {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    height: 100%;
}

.qdm-chat__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    margin: 0;
    padding: 1rem 1.25rem;
    background: #251d31;
    color: #fff7e6;
}

.qdm-chat__header h2 {
    margin: 0;
    color: inherit;
    font: 800 clamp(1.3rem, 3.9vw, 1.65rem)/1.12 Georgia, serif;
    letter-spacing: -.025em;
}

.qdm-chat__context {
    margin: .22rem 0 0;
    color: #f0d7a4;
    font-size: .79rem;
}

.qdm-chat__close,
.qdm-chat__suggestions button,
.qdm-chat__send {
    margin: 0;
    font: inherit;
    cursor: pointer;
}

.qdm-chat__close {
    flex: none;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 1px solid #8e7897;
    border-radius: 50%;
    background: transparent;
    color: #fff7e6;
    font-size: 1.6rem;
    line-height: 1;
}

.qdm-chat__body {
    min-height: 0;
    overflow: auto;
    overscroll-behavior: contain;
    padding: 1rem 1.25rem;
    scrollbar-gutter: stable;
}

.qdm-chat__intro {
    margin: 0 0 .65rem;
    color: var(--qdm-chat-muted);
}

.qdm-chat__suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: .35rem;
    margin-bottom: .85rem;
}

.qdm-chat__suggestions button {
    min-height: 44px;
    padding: .35rem .7rem;
    border: 1px solid #d7c8b7;
    border-radius: 14px;
    background: #f9f0e2;
    color: var(--qdm-chat-ink);
    text-align: left;
    font-size: .81rem;
    font-weight: 650;
}

.qdm-chat__suggestions button:hover {
    background: #f4e3ce;
}

.qdm-chat__log {
    display: grid;
    gap: .7rem;
}

.qdm-chat__message {
    min-width: 0;
    padding: .75rem .85rem;
    border: 1px solid var(--qdm-chat-line);
    border-radius: 16px;
    background: #fff;
    overflow-wrap: anywhere;
}

.qdm-chat__message--user {
    max-width: 92%;
    justify-self: end;
    border-color: #e5d8ed;
    background: #f5eef9;
}

.qdm-chat__author {
    margin: 0 0 .2rem;
    color: var(--qdm-chat-muted);
    font-size: .8rem;
    font-weight: 750;
}

.qdm-chat__text {
    margin: 0;
    white-space: pre-wrap;
}

.qdm-chat a {
    color: #55315d;
    font-weight: 700;
    text-decoration: underline;
    text-underline-offset: .15em;
}

.qdm-chat__citation {
    margin-inline: .15em;
    font-size: .79em;
    white-space: nowrap;
}

.qdm-chat__events {
    display: grid;
    gap: .45rem;
    margin: .75rem 0 0;
    padding: 0;
    list-style: none;
}

.qdm-chat__event {
    padding: .5rem .65rem;
    border: 1px solid var(--qdm-chat-line);
    border-radius: 11px;
    background: var(--qdm-chat-paper);
}

.qdm-chat__event p {
    margin: .15rem 0 0;
    color: var(--qdm-chat-muted);
    font-size: .85rem;
}

.qdm-chat__event-actions {
    display: flex;
    flex-wrap: wrap;
    gap: .2rem .85rem;
    margin-top: .2rem;
    font-size: .82rem;
}

.qdm-chat__event-detail {
    margin-top: .2rem;
    color: var(--qdm-chat-muted);
    font-size: .83rem;
}

.qdm-chat__event-detail summary {
    cursor: pointer;
    font-weight: 650;
}

.qdm-chat__sources-title {
    margin: .65rem 0 .2rem;
    font: 750 .85rem/1.4 system-ui, sans-serif;
}

.qdm-chat__sources {
    margin: 0;
    padding-left: 1.25rem;
    font-size: .83rem;
}

.qdm-chat__form {
    margin: 0;
    padding: .75rem 1.25rem 1rem;
    border-top: 1px solid var(--qdm-chat-line);
    background: var(--qdm-chat-paper);
}

.qdm-chat__form label {
    display: block;
    margin-bottom: .3rem;
    font-size: .86rem;
    font-weight: 750;
}

.qdm-chat__composer {
    display: flex;
    align-items: stretch;
    gap: .45rem;
}

.qdm-chat__composer textarea {
    display: block;
    flex: 1 1 auto;
    min-width: 0;
    min-height: 54px;
    max-height: 112px;
    margin: 0;
    padding: .52rem .6rem;
    border: 1px solid #a798a4;
    border-radius: 12px;
    background: #fff;
    color: var(--qdm-chat-ink);
    font: 400 1rem/1.35 system-ui, sans-serif;
    resize: vertical;
}

.qdm-chat__composer textarea::placeholder {
    color: #75697a;
}

.qdm-chat__send {
    min-width: 66px;
    padding: .5rem .7rem;
    border: 0;
    border-radius: 12px;
    background: var(--qdm-chat-plum);
    color: #fff;
    font-size: .83rem;
    font-weight: 800;
}

.qdm-chat button:disabled {
    opacity: .7;
    cursor: default;
}

.qdm-chat__links {
    display: flex;
    flex-wrap: wrap;
    gap: .15rem .85rem;
    margin-top: .5rem;
    font-size: .81rem;
}

.qdm-chat__links [hidden] {
    display: none;
}

.qdm-chat__status,
.qdm-chat__privacy {
    margin: .4rem 0 0;
    color: var(--qdm-chat-muted);
    font-size: .78rem;
}

.qdm-chat__status:empty {
    margin: 0;
}

.qdm-chat :focus-visible,
.qdm-chat-launch:focus-visible {
    outline: 2px solid #845697;
    outline-offset: 3px;
}

.qdm-chat__close:focus-visible {
    outline-color: #f5dfac;
}

@media (max-width: 600px) {
    .qdm-chat {
        inset: 0;
        width: 100%;
        height: 100%;
        height: 100dvh;
        margin: 0;
        border: 0;
        border-radius: 0;
    }

    .qdm-chat__header {
        padding: max(.6rem, env(safe-area-inset-top)) 1rem .6rem;
    }

    .qdm-chat__body {
        padding: .75rem 1rem;
    }

    .qdm-chat__form {
        padding: .6rem 1rem max(.7rem, env(safe-area-inset-bottom));
    }
}

#qdm-agente-madrid {
    position: fixed;
    z-index: 39;
    right: max(1rem, env(safe-area-inset-right));
    bottom: max(1rem, env(safe-area-inset-bottom));
    display: inline-flex;
    align-items: center;
    gap: .55rem;
    width: auto;
    max-width: calc(100vw - 2rem);
    height: auto;
    min-height: 52px;
    margin: 0;
    padding: 3px .85rem 3px 3px;
    border: 2px solid #efcb79;
    border-radius: 999px;
    background: #251e31;
    color: #fff8f1;
    box-shadow: 0 3px 14px #201a2e33;
    font: 800 .88rem/1.2 Mulish, system-ui, sans-serif;
    white-space: normal;
    cursor: pointer;
    touch-action: manipulation;
}
#qdm-agente-madrid:hover { background: #49364e; }
#qdm-agente-madrid:focus-visible { outline: 3px solid #f3cc77; outline-offset: 3px; box-shadow: 0 0 0 7px #302637; }
#qdm-agente-madrid .qdm-agent-portrait, #qdm-chat .qdm-chat__avatar { display: block; flex: none; width: 44px; height: 44px; object-fit: cover; border: 0; border-radius: 50%; }
#qdm-chat .qdm-chat__header > div { flex: 1; min-width: 0; }
#qdm-chat .qdm-chat__header h2 { color: #fff8f1; font-family: Fraunces, Georgia, serif; }
body.qdm-has-agent .totop { bottom: calc(max(1rem, env(safe-area-inset-bottom)) + 4.1rem); }
body.qdm-has-agent:has(dialog[open], .appgate, .portal-filter-overlay) #qdm-agente-madrid { visibility: hidden; }
@media (max-width: 40rem) {
    #qdm-agente-madrid { right: max(.7rem, env(safe-area-inset-right)); bottom: max(.7rem, env(safe-area-inset-bottom)); min-height: 48px; gap: .45rem; padding: 2px .7rem 2px 2px; }
    #qdm-agente-madrid .qdm-agent-portrait { width: 40px; height: 40px; }
    #qdm-agente-madrid .qdm-agent-label { display: block; font-size: .82rem; }
    body.qdm-has-agent:has(input:focus, textarea:focus, select:focus) #qdm-agente-madrid { visibility: hidden; }
    body.qdm-has-agent { padding-bottom: max(4.5rem, calc(3.9rem + env(safe-area-inset-bottom))); }
}
@media (max-height: 36rem) {
    #qdm-chat .qdm-chat__layout { display: block; height: 100%; overflow-y: auto; }
    #qdm-chat .qdm-chat__body { min-height: 4rem; max-height: 40dvh; }
}
@media print { #qdm-agente-madrid { display: none; } }
