:root {
    --axira-black: #070706;
    --axira-panel: #11110f;
    --axira-panel-soft: #181713;
    --axira-gold: #c9902d;
    --axira-gold-light: #f1cb73;
    --axira-cream: #fff8e9;
    --axira-text: #f7f3e9;
    --axira-muted: #bdb6a7;
    --axira-line: rgba(240, 198, 103, 0.18);
    --axira-success: #68c98b;
    --axira-shadow: 0 28px 90px rgba(0, 0, 0, 0.66);
}


* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}


html,
body {
    min-height: 100%;
}


body {
    font-family:
        Inter,
        ui-sans-serif,
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;

    background:
        radial-gradient(
            circle at 85% 10%,
            rgba(201, 144, 45, 0.14),
            transparent 28%
        ),
        linear-gradient(
            180deg,
            #070706 0%,
            #0d0c09 100%
        );

    color: var(--axira-text);
}


/* ========================================
   BOTÓN FLOTANTE
======================================== */

.chat-button {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 9998;

    width: 72px;
    height: 72px;

    border:
        1px solid
        rgba(255, 231, 168, 0.55);

    border-radius: 50%;

    display: flex;
    align-items: center;
    justify-content: center;

    background:
        radial-gradient(
            circle at 35% 28%,
            #ffe19a 0%,
            #d49b35 38%,
            #9e6718 100%
        );

    color: #140d03;

    font-size: 31px;

    cursor: pointer;

    box-shadow:
        0 18px 50px rgba(0, 0, 0, 0.55),
        0 0 0 7px rgba(201, 144, 45, 0.1);

    transition:
        transform 180ms ease,
        box-shadow 180ms ease,
        filter 180ms ease;
}


.chat-button:hover {
    transform:
        translateY(-3px)
        scale(1.04);

    filter:
        brightness(1.06);

    box-shadow:
        0 24px 60px rgba(0, 0, 0, 0.66),
        0 0 0 9px rgba(201, 144, 45, 0.12);
}


.chat-button:active {
    transform: scale(0.96);
}


/* ========================================
   VENTANA PRINCIPAL
======================================== */

.chat-window {
    position: fixed;

    right: 24px;
    bottom: 112px;

    z-index: 9999;

    width:
        min(
            430px,
            calc(100vw - 32px)
        );

    height:
        min(
            700px,
            calc(100vh - 145px)
        );

    display: none;

    flex-direction: column;

    overflow: hidden;

    border:
        1px solid
        rgba(240, 198, 103, 0.28);

    border-radius: 26px;

    background:
        linear-gradient(
            180deg,
            rgba(24, 23, 19, 0.98) 0%,
            rgba(11, 11, 9, 0.99) 100%
        );

    box-shadow:
        var(--axira-shadow),
        inset 0 1px 0
        rgba(255, 255, 255, 0.04);

    backdrop-filter:
        blur(22px);

    -webkit-backdrop-filter:
        blur(22px);

    animation:
        axiraChatOpen
        220ms
        ease-out;
}


@keyframes axiraChatOpen {

    from {
        opacity: 0;

        transform:
            translateY(18px)
            scale(0.97);
    }

    to {
        opacity: 1;

        transform:
            translateY(0)
            scale(1);
    }

}


/* ========================================
   ENCABEZADO
======================================== */

.chat-header {
    position: relative;

    flex-shrink: 0;

    min-height: 92px;

    padding:
        15px
        18px;

    display: flex;

    align-items: center;

    justify-content:
        space-between;

    gap: 14px;

    color: #1a1105;

    background:
        radial-gradient(
            circle at 90% 0%,
            rgba(255, 239, 185, 0.72),
            transparent 34%
        ),
        linear-gradient(
            135deg,
            #a76f1c 0%,
            #d9a33f 48%,
            #f0cb72 100%
        );

    border-bottom:
        1px solid
        rgba(255, 241, 199, 0.25);
}


/*
El avatar ahora existe realmente
en el HTML. Eliminamos el círculo
falso del diseño anterior.
*/

.chat-header::before,
.chat-header::after {
    display: none;
}


/* ========================================
   IDENTIDAD DE LUNA
======================================== */

.luna-header {
    min-width: 0;

    display: flex;

    align-items: center;

    gap: 12px;
}


.luna-avatar {
    position: relative;

    flex:
        0 0 58px;

    width: 58px;
    height: 58px;

    border-radius: 50%;

    padding: 2px;

    background:
        linear-gradient(
            145deg,
            #fff4c7,
            #c98d28,
            #7f4c0e
        );

    box-shadow:
        0 9px 24px
        rgba(73, 40, 0, 0.30),
        0 0 0 3px
        rgba(255, 246, 213, 0.18);

    overflow: visible;
}


.luna-avatar img {
    display: block;

    width: 100%;
    height: 100%;

    border-radius: 50%;

    object-fit: cover;

    object-position:
        center top;

    background:
        #17130d;

    border:
        2px solid
        rgba(255, 249, 228, 0.86);
}


/*
Punto de disponibilidad
*/

.luna-status {
    position: absolute;

    right: 1px;
    bottom: 2px;

    width: 14px;
    height: 14px;

    border:
        2px solid
        #d7a343;

    border-radius: 50%;

    background:
        var(--axira-success);

    box-shadow:
        0 0 0 2px
        rgba(33, 24, 10, 0.18),
        0 0 12px
        rgba(104, 201, 139, 0.62);

    animation:
        lunaStatusPulse
        2.4s
        ease-in-out
        infinite;
}


@keyframes lunaStatusPulse {

    0%,
    100% {
        box-shadow:
            0 0 0 2px
            rgba(33, 24, 10, 0.18),
            0 0 8px
            rgba(104, 201, 139, 0.38);
    }

    50% {
        box-shadow:
            0 0 0 3px
            rgba(104, 201, 139, 0.14),
            0 0 15px
            rgba(104, 201, 139, 0.78);
    }

}


/* ========================================
   NOMBRE DE LUNA
======================================== */

.luna-identity {
    min-width: 0;

    display: flex;

    flex-direction: column;

    justify-content: center;

    gap: 3px;
}


.luna-name {
    color: #1b1104;

    font-size: 1.08rem;

    line-height: 1.1;

    font-weight: 900;

    letter-spacing:
        0.01em;
}


.luna-role {
    color:
        rgba(
            37,
            24,
            5,
            0.73
        );

    font-size: 0.70rem;

    line-height: 1.2;

    font-weight: 720;

    letter-spacing:
        0.015em;

    white-space: nowrap;

    overflow: hidden;

    text-overflow: ellipsis;
}


/* ========================================
   FIRMA AXIRA
======================================== */

.axira-header-brand {
    flex-shrink: 0;

    padding:
        6px
        8px;

    border:
        1px solid
        rgba(67, 40, 4, 0.18);

    border-radius:
        9px;

    color:
        rgba(
            39,
            24,
            3,
            0.78
        );

    background:
        rgba(
            255,
            248,
            218,
            0.18
        );

    font-size:
        0.61rem;

    font-weight:
        900;

    letter-spacing:
        0.08em;

    white-space:
        nowrap;
}


/* ========================================
   ÁREA DE MENSAJES
======================================== */

.chat-body {
    flex: 1;

    min-height: 0;

    padding:
        22px
        18px
        28px;

    overflow-y: auto;
    overflow-x: hidden;

    color:
        var(--axira-text);

    font-size:
        0.96rem;

    line-height:
        1.55;

    background:
        radial-gradient(
            circle at 12% 7%,
            rgba(201, 144, 45, 0.07),
            transparent 25%
        ),
        linear-gradient(
            180deg,
            rgba(18, 17, 14, 0.96),
            rgba(8, 8, 7, 0.98)
        );

    scroll-behavior:
        smooth;

    overflow-wrap:
        anywhere;
}


/* Scroll premium */

.chat-body::-webkit-scrollbar {
    width: 7px;
}


.chat-body::-webkit-scrollbar-track {
    background: transparent;
}


.chat-body::-webkit-scrollbar-thumb {
    border-radius: 999px;

    background:
        rgba(217, 163, 63, 0.42);
}


.chat-body::-webkit-scrollbar-thumb:hover {
    background:
        rgba(240, 203, 114, 0.62);
}


/* ========================================
   MENSAJES
======================================== */

.message {
    width: fit-content;

    max-width: 86%;

    margin-bottom: 14px;

    padding:
        12px
        15px;

    border-radius: 18px;

    line-height: 1.52;

    overflow-wrap: anywhere;

    animation:
        axiraMessageIn
        180ms
        ease-out;
}


@keyframes axiraMessageIn {

    from {
        opacity: 0;

        transform:
            translateY(7px);
    }

    to {
        opacity: 1;

        transform:
            translateY(0);
    }

}


.message.luna,
.message.assistant {
    margin-right: auto;

    border:
        1px solid
        rgba(240, 198, 103, 0.16);

    border-bottom-left-radius:
        6px;

    background:
        linear-gradient(
            145deg,
            rgba(39, 36, 29, 0.98),
            rgba(25, 24, 20, 0.98)
        );

    color:
        var(--axira-cream);

    box-shadow:
        0 10px 28px
        rgba(0, 0, 0, 0.22);
}


.message.user {
    margin-left: auto;

    border:
        1px solid
        rgba(255, 232, 169, 0.28);

    border-bottom-right-radius:
        6px;

    background:
        linear-gradient(
            135deg,
            #a96f19 0%,
            #d49a32 70%,
            #e6b553 100%
        );

    color:
        #160e03;

    font-weight:
        650;

    box-shadow:
        0 10px 28px
        rgba(105, 61, 6, 0.3);
}


.message strong {
    color:
        var(--axira-gold-light);
}


.message.user strong {
    color:
        #160e03;
}


.message a {
    color:
        var(--axira-gold-light);

    text-decoration:
        underline;

    text-underline-offset:
        3px;
}


.message ul,
.message ol {
    margin:
        9px
        0
        9px
        20px;

    padding-left:
        8px;
}


.message li {
    margin:
        5px
        0;

    padding-left:
        2px;
}


.message h1,
.message h2,
.message h3 {
    margin:
        8px
        0;

    color:
        var(--axira-gold-light);

    line-height:
        1.25;
}


.message h1 {
    font-size:
        1.16rem;
}


.message h2 {
    font-size:
        1.09rem;
}


.message h3 {
    font-size:
        1.02rem;
}


.message hr {
    margin:
        12px
        0;

    border:
        none;

    border-top:
        1px solid
        var(--axira-line);
}


.message code {
    padding:
        2px
        5px;

    border-radius:
        5px;

    background:
        rgba(
            255,
            255,
            255,
            0.08
        );

    color:
        var(--axira-gold-light);

    font-family:
        Consolas,
        monospace;

    font-size:
        0.9em;
}


.markdown-space {
    height: 8px;
}


/* ========================================
   INDICADOR DE ESCRITURA
======================================== */

.typing-indicator {
    display:
        inline-flex;

    align-items:
        center;

    gap:
        5px;

    margin:
        4px
        0
        15px;

    padding:
        12px
        15px;

    border:
        1px solid
        var(--axira-line);

    border-radius:
        18px
        18px
        18px
        6px;

    background:
        var(--axira-panel-soft);
}


.typing-indicator span {
    width: 7px;
    height: 7px;

    border-radius:
        50%;

    background:
        var(--axira-gold-light);

    animation:
        axiraTyping
        1.2s
        infinite
        ease-in-out;
}


.typing-indicator span:nth-child(2) {
    animation-delay:
        140ms;
}


.typing-indicator span:nth-child(3) {
    animation-delay:
        280ms;
}


@keyframes axiraTyping {

    0%,
    60%,
    100% {
        opacity:
            0.35;

        transform:
            translateY(0);
    }

    30% {
        opacity:
            1;

        transform:
            translateY(-4px);
    }

}


/* ========================================
   ÁREA DE ESCRITURA
======================================== */

.chat-footer {
    flex-shrink: 0;

    padding:
        14px;

    border-top:
        1px solid
        rgba(240, 198, 103, 0.14);

    background:
        linear-gradient(
            180deg,
            rgba(18, 17, 14, 0.98),
            rgba(11, 11, 9, 0.99)
        );
}


.chat-footer input {
    width: 100%;

    height: 54px;

    padding:
        0
        17px;

    border:
        1px solid
        rgba(240, 198, 103, 0.24);

    border-radius:
        15px;

    outline:
        none;

    background:
        rgba(255, 255, 255, 0.055);

    color:
        var(--axira-text);

    font:
        inherit;

    font-size:
        0.95rem;

    box-shadow:
        inset 0 1px 0
        rgba(255, 255, 255, 0.025),
        0 8px 22px
        rgba(0, 0, 0, 0.16);

    transition:
        border-color 180ms ease,
        background 180ms ease,
        box-shadow 180ms ease;
}


.chat-footer input::placeholder {
    color:
        rgba(238, 230, 212, 0.5);
}


.chat-footer input:focus {
    border-color:
        rgba(240, 203, 114, 0.72);

    background:
        rgba(255, 255, 255, 0.075);

    box-shadow:
        0 0 0 4px
        rgba(201, 144, 45, 0.11),
        0 10px 28px
        rgba(0, 0, 0, 0.22);
}


#sendButton {
    width: 100%;

    height: 48px;

    margin-top: 10px;

    border:
        1px solid
        rgba(255, 239, 192, 0.34)
        !important;

    border-radius:
        14px
        !important;

    background:
        linear-gradient(
            135deg,
            #a96f19 0%,
            #d59c35 56%,
            #edc66d 100%
        )
        !important;

    color:
        #150d02
        !important;

    font-size:
        0.93rem;

    font-weight:
        850
        !important;

    letter-spacing:
        0.015em;

    cursor:
        pointer;

    box-shadow:
        0 12px 26px
        rgba(115, 65, 5, 0.28),
        inset 0 1px 0
        rgba(255, 255, 255, 0.3);

    transition:
        transform 160ms ease,
        filter 160ms ease,
        box-shadow 160ms ease;
}


#sendButton:hover {
    filter:
        brightness(1.06);

    transform:
        translateY(-1px);

    box-shadow:
        0 15px 30px
        rgba(115, 65, 5, 0.34),
        inset 0 1px 0
        rgba(255, 255, 255, 0.34);
}


#sendButton:active {
    transform:
        translateY(1px);
}


/* ========================================
   HERRAMIENTAS DEL CHAT
======================================== */

.chat-tools {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 12px;
    min-height: 30px;
}


.tool-button {
    width: auto;
    min-width: 24px;
    height: 30px;
    padding: 0;

    border: none;
    border-radius: 0;

    background: transparent;

    color: var(--axira-gold-light);

    font-size: 17px;
    line-height: 1;

    cursor: pointer;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    box-shadow: none;

    transition:
        transform 160ms ease,
        color 160ms ease,
        opacity 160ms ease,
        filter 160ms ease;
}


.tool-button .tool-icon,
.tool-button .language-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    color: var(--axira-gold-light);

    font-size: 17px;
    line-height: 1;

    filter:
        sepia(1)
        saturate(1.7)
        hue-rotate(350deg)
        brightness(1.08);
}


.language-control {
    position: relative;

    display: inline-flex;
    align-items: center;
}


.language-button {
    gap: 4px;
    min-width: auto;
}


.language-code {
    color: var(--axira-gold-light);

    font-size: 0.68rem;
    line-height: 1;

    font-weight: 850;
    letter-spacing: 0.04em;
}


.language-menu {
    position: absolute;

    left: 0;
    bottom: calc(100% + 9px);

    z-index: 10020;

    min-width: 128px;

    padding: 6px;

    border:
        1px solid
        rgba(240, 198, 103, 0.24);

    border-radius: 12px;

    background:
        rgba(17, 17, 15, 0.98);

    box-shadow:
        0 16px 38px
        rgba(0, 0, 0, 0.48);

    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
}


.language-menu[hidden] {
    display: none;
}


.language-option {
    width: 100%;

    padding: 9px 10px;

    border: none;
    border-radius: 8px;

    background: transparent;

    color: var(--axira-cream);

    font: inherit;
    font-size: 0.78rem;

    cursor: pointer;

    display: flex;
    align-items: center;
    gap: 8px;

    text-align: left;

    transition:
        background 150ms ease,
        color 150ms ease;
}


.language-option:hover {
    background:
        rgba(201, 144, 45, 0.12);

    color:
        var(--axira-gold-light);
}


.language-option-flag {
    font-size: 14px;
    line-height: 1;
}


.tool-button:hover {
    transform:
        translateY(-1px);

    color:
        #ffe09a;

    filter:
        brightness(1.12);
}


.tool-button:focus-visible {
    outline:
        1px solid
        rgba(240, 203, 114, 0.72);

    outline-offset:
        5px;

    border-radius:
        4px;
}


.tool-button:active {
    transform:
        scale(0.92);
}


.mute-button[aria-pressed="true"] {
    opacity: 0.58;
}


/* ========================================
   TABLET
======================================== */

@media (max-width: 900px) {

    .chat-window {
        right:
            18px;

        bottom:
            104px;

        width:
            min(
                420px,
                calc(100vw - 28px)
            );

        height:
            min(
                690px,
                calc(100vh - 130px)
            );
    }


    .chat-button {
        right:
            18px;

        bottom:
            18px;
    }

}


/* ========================================
   CELULAR
======================================== */

@media (max-width: 768px) {

    body {
        overflow-x:
            hidden;
    }


    .chat-window {
        position:
            fixed;

        inset:
            0;

        z-index:
            10000;

        width:
            100%;

        height:
            100dvh;

        max-height:
            100dvh;

        border:
            none;

        border-radius:
            0;

        background:
            var(--axira-black);
    }


    .chat-header {
        min-height:
            86px;

        padding:
            max(
                12px,
                env(safe-area-inset-top)
            )
            15px
            12px;

        gap:
            10px;
    }


    .luna-avatar {
        flex-basis:
            54px;

        width:
            54px;

        height:
            54px;
    }


    .luna-name {
        font-size:
            1.04rem;
    }


    .luna-role {
        font-size:
            0.68rem;
    }


    .chat-body {
        padding:
            18px
            14px
            24px;

        font-size:
            0.95rem;
    }


    .chat-footer {
        padding:
            11px
            12px
            max(
                12px,
                env(safe-area-inset-bottom)
            );
    }


    .chat-footer input {
        height:
            52px;

        font-size:
            16px;
    }


    #sendButton {
        height:
            48px;
    }


    .chat-button {
        right:
            16px;

        bottom:
            max(
                16px,
                env(safe-area-inset-bottom)
            );

        width:
            62px;

        height:
            62px;

        font-size:
            27px;
    }

}


/* ========================================
   CELULARES PEQUEÑOS
======================================== */

@media (max-width: 420px) {

    .chat-header {
        min-height:
            82px;

        padding-left:
            12px;

        padding-right:
            12px;
    }


    .luna-header {
        gap:
            9px;
    }


    .luna-avatar {
        flex-basis:
            48px;

        width:
            48px;

        height:
            48px;
    }


    .luna-status {
        width:
            12px;

        height:
            12px;
    }


    .luna-name {
        font-size:
            1rem;
    }


    .luna-role {
        max-width:
            190px;

        font-size:
            0.64rem;
    }


    .axira-header-brand {
        padding:
            5px;

        font-size:
            0.54rem;

        letter-spacing:
            0.04em;
    }


    .chat-body {
        padding-left:
            12px;

        padding-right:
            12px;
    }


    .message {
        max-width:
            91%;
    }

}


/* ========================================
   ACCESIBILIDAD
======================================== */

@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        scroll-behavior:
            auto
            !important;

        animation-duration:
            0.01ms
            !important;

        animation-iteration-count:
            1
            !important;

        transition-duration:
            0.01ms
            !important;
    }

}

/* ========================================
   PREVIEW DE IMAGEN EN CHAT
======================================== */

.chat-image-preview {
    display: block;
    width: min(100%, 320px);
    max-height: 340px;
    margin-top: 10px;

    border-radius: 14px;

    object-fit: cover;

    border:
        1px solid
        rgba(255, 239, 190, 0.35);

    box-shadow:
        0 10px 28px
        rgba(0, 0, 0, 0.28);

    cursor: zoom-in;
}

.chat-image-name {
    display: block;
    margin-top: 8px;

    font-size: 0.88rem;
    font-weight: 700;

    opacity: 0.9;
}

.chat-image-overlay {
    position: fixed;
    inset: 0;

    z-index: 999999;

    display: none;
    align-items: center;
    justify-content: center;

    padding: 24px;

    background:
        rgba(0, 0, 0, 0.88);
}

.chat-image-overlay.open {
    display: flex;
}

.chat-image-overlay img {
    max-width: 94vw;
    max-height: 90vh;

    border-radius: 16px;

    object-fit: contain;

    box-shadow:
        0 20px 70px
        rgba(0, 0, 0, 0.6);
}

.chat-image-overlay-close {
    position: absolute;
    top: 18px;
    right: 22px;

    width: 44px;
    height: 44px;

    border: 0;
    border-radius: 50%;

    background:
        rgba(255, 255, 255, 0.12);

    color: #fff;

    font-size: 26px;
    line-height: 1;

    cursor: pointer;
}