/* Frontend de chat nuevo, aislado del CSS global */

body.nx-body:has(.gptx) .nx-topbar,
body.nx-body:has(.gptx) .nx-footer {
    display: none;
}

body.nx-body:has(.gptx) {
    padding: 0;
    margin: 0;
    overflow: hidden;
    background: #0b1020;
}

.gptx {
    width: 100%;
    max-width: none !important;
    padding: 0 !important;
    height: 100dvh;
    /* Aire mínimo bajo el último mensaje dentro del scroll (el input va fuera del log). */
    --gptx-composer-space: 18px;
}

.gptx__shell {
    height: 100%;
    display: grid;
    grid-template-columns: 272px minmax(0, 1fr);
}

.gptx__sidebar {
    background: #111827;
    border-right: 1px solid #1f2937;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px;
}

.gptx__sidebarTop {
    display: grid;
    gap: 8px;
}

.gptx__btn {
    min-height: 40px;
    border: 1px solid #374151;
    border-radius: 10px;
    background: #1f2937;
    color: #e5e7eb;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font: inherit;
    cursor: pointer;
}

.gptx__btn:hover {
    background: #28374c;
}

.gptx__btn--new {
    border-color: #4b5563;
}

.gptx__label {
    font-size: 0.76rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #9ca3af;
    padding: 2px 4px;
}

.gptx .nx-conversation-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.gptx .nx-conversation-item {
    width: 100%;
    text-align: left;
    border: 1px solid transparent;
    border-radius: 9px;
    background: transparent;
    color: #a3adc2;
    min-height: 38px;
    padding: 8px 10px;
    cursor: pointer;
    font: inherit;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.gptx .nx-conversation-item:hover {
    background: #1f2937;
    color: #f3f4f6;
}

.gptx .nx-conversation-item.is-active {
    background: #243246;
    border-color: #3b82f6;
    color: #f9fafb;
}

.gptx .nx-conversation-item__title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.gptx .nx-conversation-item__delete {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    border: 1px solid transparent;
    background: transparent;
    color: #9ca3af;
    font-size: 14px;
    line-height: 26px;
    text-align: center;
    cursor: pointer;
}

.gptx .nx-conversation-item__delete:hover {
    border-color: #ef4444;
    color: #fecaca;
    background: rgba(239, 68, 68, 0.16);
}

.gptx__main {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    background: #0b1020;
}

.gptx__header {
    height: 56px;
    border-bottom: 1px solid #1f2937;
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.gptx__brand {
    color: #e5e7eb;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.gptx__dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #22d3ee;
    box-shadow: 0 0 0 4px rgba(34, 211, 238, 0.2);
}

.gptx__select {
    display: none;
}

.gptx__headerActions {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.gptx__menuBtn {
    display: none;
    width: 40px;
    height: 36px;
    border-radius: 8px;
    border: 1px solid #374151;
    background: #111827;
    color: #e5e7eb;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    gap: 3px;
    flex-direction: column;
    padding: 0;
}

.gptx__menuBtn span {
    width: 16px;
    height: 2px;
    border-radius: 2px;
    background: currentColor;
}

.gptx__mobileMenu {
    display: none;
}

.gptx__dangerBtn {
    display: none;
    min-height: 36px;
    border-radius: 8px;
    border: 1px solid #4b5563;
    background: #1f2937;
    color: #fca5a5;
    font: inherit;
    padding: 0 10px;
    cursor: pointer;
}

.gptx__dangerBtn:hover {
    border-color: #f87171;
    color: #fecaca;
}

.gptx__btn--danger {
    border-color: #7f1d1d;
    color: #fecaca;
    background: #2b1316;
}

.gptx__btn--danger:hover {
    background: #3a161b;
}

.gptx__error {
    margin: 8px 16px 0;
    color: #f87171;
    font-size: 0.92rem;
}

.gptx__log {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    padding: 18px clamp(14px, 4vw, 64px) calc(var(--gptx-composer-space) + env(safe-area-inset-bottom)) !important;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    -webkit-overflow-scrolling: touch;
}

/* Empuja el bloque de mensajes hacia abajo cuando hay poco contenido,
   manteniendo scroll normal cuando el contenido crece. */
.gptx__log::before {
    content: "";
    margin-top: auto;
}

.gptx__log > .nx-msg {
    width: 100%;
}

.gptx .nx-msg {
    margin-bottom: 14px;
}

.gptx .nx-msg--assistant {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr);
    column-gap: 12px;
    row-gap: 8px;
    align-items: start;
}

.gptx .nx-msg--assistant .nx-msg__avatar {
    grid-column: 1;
    grid-row: 1 / span 2;
}

.gptx .nx-msg--assistant .nx-msg__bubble {
    grid-column: 2;
    grid-row: 1;
}

.gptx .nx-msg--assistant .nx-msg__actions {
    grid-column: 2;
    grid-row: 2;
    margin-top: 0;
}

.gptx .nx-msg--assistant.nx-msg--with-donation .nx-msg__actions {
    grid-row: 3;
}

.gptx .nx-msg--assistant .nx-msg__continue {
    grid-column: 2;
    grid-row: 2;
}

.gptx .nx-msg--assistant.nx-msg--with-donation .nx-msg__continue {
    grid-row: 3;
}

.gptx .nx-msg--assistant .nx-msg__continue + .nx-msg__actions {
    grid-row: 3;
}

.gptx .nx-msg--assistant.nx-msg--with-donation .nx-msg__continue + .nx-msg__actions {
    grid-row: 4;
}

.gptx__log > .nx-msg:last-child {
    margin-bottom: 8px;
}

.gptx .nx-msg__avatar {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    font-size: 0.72rem;
}

.gptx .nx-msg__bubble {
    max-width: min(100%, 840px);
    padding: 13px 16px;
    border-radius: 16px;
    border: 1px solid #273349;
    background: #111827;
    color: #e5e7eb;
    white-space: pre-wrap;
    word-break: break-word;
}

.gptx .nx-msg__bubble--code {
    white-space: normal;
}

.gptx .nx-rich-text {
    white-space: pre-wrap;
}

.gptx .nx-rich-text + .nx-codeblock,
.gptx .nx-codeblock + .nx-rich-text,
.gptx .nx-codeblock + .nx-codeblock {
    margin-top: 10px;
}

.gptx .nx-codeblock {
    border: 1px solid #334155;
    border-radius: 12px;
    overflow: hidden;
    background: #0b1220;
}

.gptx .nx-codeblock__head {
    min-height: 34px;
    padding: 6px 10px;
    border-bottom: 1px solid #243244;
    background: #0f172a;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.gptx .nx-codeblock__lang {
    font-size: 0.72rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #93c5fd;
}

.gptx .nx-codeblock__tools {
    display: inline-flex;
    gap: 6px;
}

.gptx .nx-codeblock__btn {
    min-height: 24px;
    padding: 0 8px;
    border-radius: 999px;
    border: 1px solid #334155;
    background: #111827;
    color: #cbd5e1;
    font-size: 0.72rem;
    cursor: pointer;
}

.gptx .nx-codeblock__btn:hover {
    border-color: #475569;
    color: #f8fafc;
}

.gptx .nx-codeblock__pre {
    margin: 0;
    padding: 12px;
    overflow: auto;
    max-height: min(48dvh, 420px);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 0.83rem;
    line-height: 1.5;
    color: #e2e8f0;
    background: #020617;
}

.gptx .nx-codeblock__pre code {
    white-space: pre;
}

.nx-preview-modal {
    position: fixed;
    inset: 0;
    z-index: 1200;
    background: rgba(2, 6, 23, 0.72);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 18px;
}

.nx-preview-modal.is-open {
    display: flex;
}

.nx-preview-modal__dialog {
    width: min(980px, 100%);
    height: min(78dvh, 760px);
    border-radius: 12px;
    border: 1px solid #334155;
    background: #0b1020;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.nx-preview-modal__bar {
    min-height: 42px;
    padding: 0 12px;
    border-bottom: 1px solid #243244;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: #e2e8f0;
}

.nx-preview-modal__close {
    min-height: 28px;
    padding: 0 10px;
    border-radius: 8px;
    border: 1px solid #374151;
    background: #111827;
    color: #cbd5e1;
    cursor: pointer;
}

.nx-preview-modal__close:hover {
    color: #fff;
}

.nx-preview-modal__frame {
    flex: 1;
    width: 100%;
    border: none;
    background: #fff;
}

.gptx .nx-donation-card {
    grid-column: 2;
    grid-row: 2;
    margin-top: 2px;
    padding: 10px 12px;
    border: 1px solid #2c3f57;
    border-radius: 12px;
    background: #0f1b2d;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    max-width: min(100%, 620px);
}

.gptx .nx-donation-card__text {
    margin: 0;
    font-size: 0.84rem;
    line-height: 1.4;
    color: #cbd5e1;
}

.gptx .nx-donation-card__btn {
    flex-shrink: 0;
    min-height: 32px;
    padding: 0 12px;
    border-radius: 999px;
    border: 1px solid #22d3ee;
    background: #22d3ee;
    color: #0b1020;
    font-weight: 700;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.gptx .nx-donation-card__btn:hover {
    background: #67e8f9;
    border-color: #67e8f9;
}

.gptx .nx-msg--user .nx-msg__bubble {
    background: #1f2937;
    border-color: #374151;
}

.gptx .nx-msg__actions button {
    min-height: 32px;
    border-radius: 999px;
    border: 1px solid #374151;
    background: #111827;
    color: #9ca3af;
    font-size: 0.78rem;
}

.gptx .nx-msg__actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    position: relative;
}

.gptx .nx-continue-btn {
    min-height: 34px;
    padding: 0 12px;
    border-radius: 999px;
    border: 1px solid #2563eb;
    background: #1d4ed8;
    color: #fff;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
}

.gptx .nx-continue-btn:hover {
    background: #2563eb;
    border-color: #3b82f6;
}

.gptx .nx-actions-menu {
    position: relative;
}

.gptx .nx-actions-menu__trigger {
    list-style: none;
    min-height: 32px;
    padding: 0 12px;
    border-radius: 999px;
    border: 1px solid #374151;
    background: #111827;
    color: #9ca3af;
    font-size: 0.78rem;
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    user-select: none;
}

.gptx .nx-actions-menu__trigger::-webkit-details-marker {
    display: none;
}

.gptx .nx-actions-menu__trigger::after {
    content: "▾";
    margin-left: 8px;
    font-size: 0.72rem;
    line-height: 1;
    opacity: 0.9;
}

.gptx .nx-actions-menu[open] .nx-actions-menu__trigger::after {
    content: "▴";
}

.gptx .nx-actions-menu__panel {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    z-index: 4;
    min-width: 170px;
    padding: 6px;
    border-radius: 10px;
    border: 1px solid #2d3a4f;
    background: #0f172a;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.45);
    display: grid;
    gap: 4px;
}

.gptx .nx-actions-menu__item {
    min-height: 32px;
    border-radius: 8px;
    border: 1px solid transparent;
    background: transparent;
    color: #cbd5e1;
    text-align: left;
    padding: 0 10px;
    font-size: 0.8rem;
    cursor: pointer;
}

.gptx .nx-actions-menu__item:hover {
    border-color: #334155;
    background: #18243a;
    color: #f3f4f6;
}

@media (max-width: 700px) {
    .gptx .nx-donation-card {
        flex-direction: column;
        align-items: flex-start;
    }

    .gptx .nx-donation-card__btn {
        width: 100%;
    }
}

.gptx__typing {
    padding: 0 clamp(12px, 3.2vw, 40px) 4px;
    color: #9ca3af;
    font-size: 0.9rem;
}

.gptx__composerWrap {
    position: sticky;
    bottom: 0;
    background: linear-gradient(to top, #0b1020 70%, rgba(11, 16, 32, 0.1));
    padding: 4px clamp(12px, 3.2vw, 40px) max(8px, env(safe-area-inset-bottom));
}

.gptx__composer {
    border: 1px solid #374151;
    border-radius: 14px;
    background: #111827;
    padding: 6px 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.35);
}

.gptx__composer:focus-within {
    border-color: #3b82f6;
}

.gptx__preview {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.gptx__row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.gptx__chatOpts {
    width: 100%;
}

.gptx__chatOpts__sum {
    list-style: none;
    display: none;
    align-items: center;
    gap: 8px;
    width: fit-content;
    max-width: 100%;
    min-height: 36px;
    padding: 0 12px;
    margin: 0 0 2px;
    border-radius: 10px;
    border: 1px solid #374151;
    background: #1f2937;
    color: #cbd5e1;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    user-select: none;
}

.gptx__chatOpts__sum::-webkit-details-marker {
    display: none;
}

.gptx__chatOpts__sumIcon {
    display: inline-flex;
    color: #22d3ee;
}

.gptx__chatOpts__panel {
    width: 100%;
}

.gptx__webSearch {
    padding: 0 4px 2px;
}

.gptx__webSearchLabel {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: #9ca3af;
    font-size: 0.82rem;
    cursor: pointer;
    user-select: none;
}

.gptx__webSearchLabel--stack {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
}

.gptx__webSearchRow {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.gptx__tierHint {
    display: block;
    margin-left: 24px;
    font-size: 0.74rem;
    line-height: 1.35;
    color: #6b7280;
    max-width: 42rem;
}

.gptx__webSearchInput {
    width: 16px;
    height: 16px;
    accent-color: #22d3ee;
}

.gptx__row textarea {
    flex: 1;
    min-height: clamp(46px, 6.2vh, 56px);
    max-height: min(34dvh, 220px);
    resize: none;
    border: none;
    background: transparent;
    color: #e5e7eb;
    padding: 10px 8px;
    font: inherit;
    line-height: 1.45;
}

.gptx__row textarea:focus {
    outline: none;
}

.gptx__row textarea::placeholder {
    color: #9ca3af;
}

.gptx__iconBtn {
    width: 46px;
    height: 46px;
    min-width: 46px;
    min-height: 46px;
    border-radius: 11px;
    border: 1px solid #374151;
    background: #1f2937;
    color: #e5e7eb;
    display: grid;
    place-items: center;
    cursor: pointer;
}

.gptx__iconBtn:hover {
    border-color: #4b5563;
}

.gptx__send {
    width: 46px;
    height: 46px;
    min-width: 46px;
    min-height: 46px;
    border-radius: 11px;
    border: none;
    background: #22d3ee;
    color: #0b1020;
    display: grid;
    place-items: center;
    cursor: pointer;
}

.gptx__send:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.gptx__send.is-stop {
    background: #ef4444;
    color: #fff;
}

.gptx__send.is-stop:hover {
    background: #f87171;
}

.gptx .nx-thumb {
    position: relative;
    width: 70px;
    height: 70px;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid #374151;
}

.gptx .nx-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.gptx .nx-thumb button {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    cursor: pointer;
}

.gptx .nx-doc-thumb {
    position: relative;
    min-width: 120px;
    max-width: 200px;
    padding: 8px 30px 8px 10px;
    border-radius: 10px;
    border: 1px solid #374151;
    background: #111827;
}

.gptx .nx-doc-thumb__name {
    font-size: 12px;
    font-weight: 600;
    color: #e5e7eb;
    word-break: break-all;
    line-height: 1.25;
}

.gptx .nx-doc-thumb__state {
    margin-top: 4px;
    font-size: 11px;
    color: #9ca3af;
}

.gptx .nx-doc-thumb button {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, 0.45);
    color: #fff;
    cursor: pointer;
    line-height: 1;
}

.gptx .nx-msg__files {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.gptx .nx-file-chip {
    display: inline-block;
    max-width: 100%;
    padding: 4px 8px;
    border-radius: 8px;
    font-size: 11px;
    background: rgba(34, 211, 238, 0.12);
    color: #a5f3fc;
    border: 1px solid rgba(34, 211, 238, 0.35);
    word-break: break-all;
}

.gptx .nx-file-chip--doc {
    background: rgba(167, 139, 250, 0.12);
    color: #ddd6fe;
    border-color: rgba(167, 139, 250, 0.35);
}

@media (max-width: 960px) {
    .gptx__chatOpts__sum {
        display: inline-flex;
    }

    .gptx__chatOpts[open] .gptx__chatOpts__sum {
        border-color: #3b82f6;
        color: #e5e7eb;
    }

    .gptx__chatOpts__panel {
        margin-top: 6px;
        padding: 10px 10px 8px;
        border-radius: 12px;
        border: 1px solid #2d3a4f;
        background: #0f172a;
        box-shadow: 0 8px 22px rgba(0, 0, 0, 0.35);
    }

    .gptx {
        --gptx-composer-space: 14px;
    }

    .gptx__shell {
        grid-template-columns: 1fr;
    }

    .gptx__sidebar {
        display: none;
    }

    .gptx__select,
    .gptx__dangerBtn {
        display: none !important;
    }

    .gptx__menuBtn {
        display: inline-flex;
        align-items: center;
    }

    .gptx__mobileMenu {
        display: none;
        border-bottom: 1px solid #1f2937;
        padding: 10px;
        background: #0f172a;
    }

    .gptx__mobileMenu.is-open {
        display: block;
    }

    .gptx__mobileMenuLinks {
        display: grid;
        gap: 8px;
    }

    .gptx__mobileMenuLabel {
        margin-top: 10px;
        margin-bottom: 6px;
        color: #9ca3af;
        font-size: 0.72rem;
        letter-spacing: 0.08em;
        text-transform: uppercase;
    }

    .gptx__mobileMenu .nx-conversation-list {
        display: flex;
        max-height: 220px;
        overflow-y: auto;
        gap: 4px;
    }

    .gptx__log {
        padding: 12px 10px calc(var(--gptx-composer-space) + env(safe-area-inset-bottom)) !important;
    }

    .gptx__composerWrap {
        padding: 6px 8px max(6px, env(safe-area-inset-bottom));
    }

    .gptx__row textarea {
        min-height: 44px;
        max-height: min(32dvh, 190px);
        padding: 9px 7px;
    }
}
