#pericias-chat-launcher {
    position: fixed;
    right: 24px;
    bottom: 26px;
    z-index: 4600;
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 11px 16px;
    border: 1px solid var(--neon-blue);
    border-radius: 999px;
    background: color-mix(in srgb, var(--dark-bg) 90%, transparent);
    color: var(--neon-blue);
    font: inherit;
    font-size: .75rem;
    font-weight: 800;
    letter-spacing: .07em;
    text-transform: uppercase;
    cursor: grab;
    box-shadow: 0 0 18px rgba(0, 243, 255, .18);
    backdrop-filter: blur(12px);
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    will-change: left, top, transform;
}

#pericias-chat-launcher.dragging {
    cursor: grabbing;
    box-shadow: 0 0 28px rgba(0, 243, 255, .34);
}

#pericias-chat-launcher img {
    width: 22px;
    height: 22px;
    pointer-events: none;
}

#pericias-chat-launcher span {
    pointer-events: none;
}

#pericias-chat-launcher:hover:not(.dragging) {
    transform: translateY(-1px);
    box-shadow: 0 0 24px rgba(0, 243, 255, .3);
}

#pericias-chat-panel {
    position: fixed;
    right: 22px;
    bottom: 92px;
    z-index: 4700;
    width: min(410px, calc(100vw - 28px));
    height: min(620px, calc(100vh - 120px));
    display: none;
    grid-template-rows: auto minmax(0, 1fr) auto;
    overflow: hidden;
    border: 1px solid var(--border-color);
    border-radius: 22px;
    background: color-mix(in srgb, var(--dark-bg) 96%, transparent);
    color: var(--text-color);
    box-shadow: 0 24px 70px rgba(0, 0, 0, .42), 0 0 34px rgba(0, 255, 204, .12);
    backdrop-filter: blur(18px);
}

#pericias-chat-panel.open {
    display: grid;
    animation: periciasChatIn .22s ease-out;
}

@keyframes periciasChatIn {
    from { opacity: 0; transform: translateY(12px) scale(.98); }
    to { opacity: 1; transform: none; }
}

.pericias-chat-header {
    min-height: 72px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 13px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
    background: linear-gradient(135deg, rgba(0, 243, 255, .15), rgba(0, 255, 204, .12));
}

.pericias-chat-avatar-shell {
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    display: grid;
    place-items: center;
    border: 1px solid rgba(0, 243, 255, .35);
    border-radius: 50%;
    background: rgba(0, 243, 255, .08);
    box-shadow: 0 0 18px rgba(0, 243, 255, .12);
}

.pericias-chat-avatar-shell img {
    width: 34px;
    height: 34px;
}

.pericias-chat-title {
    min-width: 0;
    flex: 1;
}

.pericias-chat-title strong {
    display: block;
    color: var(--neon-green);
    font-size: .94rem;
    letter-spacing: .025em;
}

.pericias-chat-title span {
    display: flex;
    align-items: center;
    gap: 7px;
    margin-top: 4px;
    color: var(--text-muted);
    font-size: .7rem;
}

.pericias-chat-title span::before {
    content: '';
    width: 7px;
    height: 7px;
    flex: 0 0 7px;
    border-radius: 50%;
    background: var(--neon-green);
    box-shadow: 0 0 0 3px rgba(0, 255, 204, .12);
}

.pericias-chat-close {
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    display: grid;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, .12);
    border-radius: 50%;
    background: rgba(255, 255, 255, .04);
    color: var(--text-color);
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
}

.pericias-chat-close:hover {
    border-color: var(--neon-blue);
    background: rgba(0, 243, 255, .08);
}

.pericias-chat-messages {
    min-height: 0;
    overflow-y: auto;
    padding: 18px 14px 16px;
    scroll-behavior: smooth;
    overscroll-behavior: contain;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scrollbar-width: thin;
    scrollbar-color: color-mix(in srgb, var(--neon-blue) 45%, transparent) transparent;
}

.pericias-chat-message-row {
    width: 100%;
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.pericias-chat-message-row.assistant {
    justify-content: flex-start;
}

.pericias-chat-message-row.user {
    justify-content: flex-end;
}

.pericias-chat-mini-avatar {
    width: 25px;
    height: 25px;
    flex: 0 0 25px;
    display: grid;
    place-items: center;
    border: 1px solid rgba(0, 255, 204, .22);
    border-radius: 50%;
    background: rgba(0, 255, 204, .06);
}

.pericias-chat-mini-avatar img {
    width: 19px;
    height: 19px;
}

.pericias-chat-message {
    max-width: min(84%, 330px);
    margin: 0;
    padding: 10px 12px 11px;
    border-radius: 15px;
    line-height: 1.48;
    font-size: .84rem;
    user-select: text;
    -webkit-user-select: text;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.pericias-chat-message-label {
    display: block;
    margin-bottom: 5px;
    font-size: .66rem;
    font-weight: 800;
    letter-spacing: .025em;
    opacity: .78;
}

.pericias-chat-message.assistant {
    border: 1px solid rgba(0, 255, 204, .22);
    border-bottom-left-radius: 5px;
    background: rgba(0, 255, 204, .07);
    color: var(--text-color);
}

.pericias-chat-message.assistant .pericias-chat-message-label {
    color: var(--neon-green);
}

.pericias-chat-message.user {
    border: 1px solid rgba(0, 243, 255, .28);
    border-bottom-right-radius: 5px;
    background: rgba(0, 243, 255, .11);
    color: var(--text-color);
}

.pericias-chat-message.user .pericias-chat-message-label {
    color: var(--neon-blue);
}

.pericias-chat-quick {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    margin: 2px 0 6px 33px;
}

.pericias-chat-quick button {
    border: 1px solid var(--border-color);
    border-radius: 999px;
    padding: 7px 10px;
    background: transparent;
    color: var(--neon-blue);
    font: inherit;
    font-size: .72rem;
    cursor: pointer;
}

.pericias-chat-quick button:hover {
    border-color: var(--neon-green);
    color: var(--neon-green);
}

.pericias-chat-bottom {
    border-top: 1px solid var(--border-color);
    background: color-mix(in srgb, var(--dark-bg) 93%, transparent);
}

.pericias-chat-composer {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 11px 12px 9px;
}

.pericias-chat-composer input {
    flex: 1;
    min-width: 0;
    height: 46px;
    box-sizing: border-box;
    border: 1px solid var(--border-color);
    border-radius: 15px;
    padding: 0 14px;
    background: var(--input-bg);
    color: var(--text-color);
    font: inherit;
    font-size: .86rem;
    outline: none;
    transition: border-color .2s ease, box-shadow .2s ease, background .2s ease;
}

.pericias-chat-composer input:focus {
    border-color: var(--neon-blue);
    box-shadow: 0 0 0 3px rgba(0, 243, 255, .09);
}

.pericias-chat-send {
    width: 46px;
    height: 46px;
    flex: 0 0 46px;
    display: grid;
    place-items: center;
    border: 1px solid var(--neon-green);
    border-radius: 15px;
    background: linear-gradient(135deg, rgba(0, 243, 255, .12), rgba(0, 255, 204, .18));
    color: var(--neon-green);
    cursor: pointer;
    box-shadow: 0 8px 22px rgba(0, 255, 204, .09);
}

.pericias-chat-send svg {
    width: 21px;
    height: 21px;
}

.pericias-chat-send:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 26px rgba(0, 255, 204, .16);
}

.pericias-chat-privacy {
    padding: 0 14px 11px;
    color: var(--text-muted);
    font-size: .62rem;
    line-height: 1.35;
}

body.light-mode #pericias-chat-launcher,
body.light-mode #pericias-chat-panel,
body.light-mode .pericias-chat-bottom {
    background: rgba(255, 255, 255, .98);
}

body.light-mode .pericias-chat-header {
    border-bottom-color: rgba(0, 102, 255, .12);
    background: linear-gradient(135deg, rgba(0, 102, 255, .08), rgba(0, 179, 0, .07));
}

body.light-mode .pericias-chat-message.assistant {
    background: rgba(0, 179, 0, .055);
}

body.light-mode .pericias-chat-message.user {
    background: rgba(0, 102, 255, .065);
}

@media (max-width: 600px) {
    #pericias-chat-launcher {
        right: 12px;
        bottom: 18px;
        padding: 9px 12px;
        font-size: .66rem;
    }

    body.pericias-chat-open-mobile {
        overflow: hidden !important;
    }

    body.pericias-chat-open-mobile #pericias-chat-launcher {
        visibility: hidden;
        pointer-events: none;
    }

    #pericias-chat-panel,
    #pericias-chat-panel.open {
        position: fixed;
        top: var(--pericias-chat-viewport-top, 0px);
        right: 0;
        bottom: auto;
        left: 0;
        width: 100vw;
        max-width: none;
        height: var(--pericias-chat-viewport-height, 100dvh);
        max-height: none;
        border: 0;
        border-radius: 0;
        box-shadow: none;
        background: var(--dark-bg);
        backdrop-filter: none;
    }

    #pericias-chat-panel.open {
        animation: periciasChatMobileIn .18s ease-out;
    }

    @keyframes periciasChatMobileIn {
        from { opacity: 0; transform: translateY(10px); }
        to { opacity: 1; transform: none; }
    }

    .pericias-chat-header {
        min-height: 68px;
        padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
        box-sizing: content-box;
    }

    .pericias-chat-avatar-shell {
        width: 42px;
        height: 42px;
        flex-basis: 42px;
    }

    .pericias-chat-title strong {
        font-size: .92rem;
    }

    .pericias-chat-title span {
        font-size: .68rem;
    }

    .pericias-chat-close {
        width: 42px;
        height: 42px;
        flex-basis: 42px;
        font-size: 1.65rem;
    }

    .pericias-chat-messages {
        padding: 14px 12px 12px;
        gap: 9px;
    }

    .pericias-chat-message {
        max-width: 82%;
        font-size: .9rem;
        padding: 10px 12px 11px;
    }

    .pericias-chat-quick {
        margin-left: 33px;
        padding-right: 4px;
    }

    .pericias-chat-bottom {
        padding-bottom: env(safe-area-inset-bottom);
    }

    .pericias-chat-composer {
        padding: 10px 10px 8px;
    }

    .pericias-chat-composer input {
        height: 48px;
        border-radius: 16px;
        font-size: 16px;
    }

    .pericias-chat-send {
        width: 48px;
        height: 48px;
        flex-basis: 48px;
        border-radius: 16px;
    }

    .pericias-chat-privacy {
        padding: 0 12px 9px;
        font-size: .58rem;
    }
}
