@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap');

/* ── Ventana principal ── */
.chat-popup {
    background: #ffffff;
    border: none;
    border-radius: 16px 16px 0 0;
    bottom: 0;
    display: none;
    height: 700px;
    position: fixed;
    right: 24px;
    width: min(95vw, 1300px);
    font-family: 'Inter', 'Open Sans', sans-serif;
    z-index: 1000;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 148, 217, 0.1);
    overflow: hidden;
    display: none;
    flex-direction: column;
}

.chat-rh {
    position: absolute;
    z-index: 10;
}

.chat-rh:hover,
.chat-rh.resizing {
    background: rgba(0, 148, 217, 0.22);
}

.chat-rh--left {
    left: 0; top: 12px;
    width: 5px; height: calc(100% - 24px);
    cursor: ew-resize;
}

.chat-rh--top {
    top: 0; left: 12px;
    height: 5px; width: calc(100% - 24px);
    cursor: n-resize;
}

.chat-rh--topleft {
    top: 0; left: 0;
    width: 14px; height: 14px;
    cursor: nw-resize;
    border-radius: 16px 0 0 0;
}

.chat-rh--topright {
    top: 0; right: 0;
    width: 14px; height: 14px;
    cursor: ne-resize;
    border-radius: 0 16px 0 0;
}

.popup-box-on {
    display: flex !important;
}

/* ── Header ── */
.chat-popup .popup-head {
    background: linear-gradient(135deg, #0094d9 0%, #006fa8 100%);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.popup-head-left {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #ffffff;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.2px;
}

.popup-head-left svg {
    flex-shrink: 0;
}

.popup-head-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

.chat-header-button {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 50%;
    color: #ffffff;
    cursor: pointer;
    font-size: 12px;
    height: 30px;
    width: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    padding: 0;
}

.chat-header-button:hover {
    background: rgba(255, 255, 255, 0.28);
}

/* ── Área de mensajes ── */
.popup-messages {
    background: #f0f2f5;
    flex: 1;
    overflow-y: auto;
    padding: 16px 16px;
    display: flex;
    flex-direction: column;
    gap: 0;
}

#last_messages {
    display: flex;
    flex-direction: column;
}

.popup-messages::-webkit-scrollbar {
    width: 4px;
}
.popup-messages::-webkit-scrollbar-thumb {
    background: #c4c4c4;
    border-radius: 4px;
}

/* ── Mensajes ── */
.chatia-msg {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 100%;
    margin-bottom: 12px;
}

.chatia-msg:last-child {
    margin-bottom: 0;
}

.chatia-msg--user {
    flex-direction: row-reverse;
}

.chatia-msg--ai {
    flex-direction: row;
}

.chatia-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    padding: 5px;
}

.chatia-avatar--bot {
    background: #ffffff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}


.chatia-bubble {
    max-width: 90%;
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 13.5px;
    line-height: 1.55;
    word-break: break-word;
}

.chatia-bubble--user {
    max-width: 82%;
    background: #0094d9;
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

.chatia-bubble--ai {
    max-width: 94%;
    background: #ffffff;
    color: #2c3e50;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.chatia-msg--pending .chatia-bubble--user {
    opacity: 0.88;
}

.chatia-text-block {
    margin-bottom: 10px;
}

.chatia-text-block:last-child {
    margin-bottom: 0;
}

.chatia-table-wrap {
    overflow-x: auto;
    margin: 4px 0 8px;
    border: 1px solid #e2e7ee;
    border-radius: 10px;
    background: #fbfcfe;
}

.chatia-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 360px;
    font-size: 12px;
    line-height: 1.35;
}

.chatia-table th,
.chatia-table td {
    padding: 5px 10px;
    border-bottom: 1px solid #e8edf3;
    border-right: 1px solid #e8edf3;
    vertical-align: middle;
    white-space: normal;
    word-break: break-word;
}

.chatia-table th:last-child,
.chatia-table td:last-child {
    border-right: none;
}

.chatia-table th {
    background: #eef5fb;
    color: #1f4f76;
    font-weight: 600;
    text-align: center;
}

.chatia-table td {
    text-align: left;
}

.chatia-table tbody tr:last-child td {
    border-bottom: none;
}

.chatia-table tbody tr:hover td {
    background: #f4f8fc;
}

/* ── Markdown en respuesta IA ── */
.chatia-bubble--ai h1,
.chatia-bubble--ai h2,
.chatia-bubble--ai h3,
.chatia-bubble--ai h4 {
    margin: 10px 0 6px;
    color: #163f60;
    line-height: 1.3;
}

.chatia-bubble--ai h1 { font-size: 16px; }
.chatia-bubble--ai h2 { font-size: 15px; }
.chatia-bubble--ai h3 { font-size: 14px; }
.chatia-bubble--ai h4 { font-size: 13px; }

.chatia-bubble--ai ul,
.chatia-bubble--ai ol {
    margin: 8px 0 10px;
    padding-left: 18px;
}

.chatia-bubble--ai li {
    margin: 4px 0;
}

.chatia-bubble--ai a {
    color: #0b6ea7;
    text-decoration: underline;
    word-break: break-word;
}

.chatia-bubble--ai blockquote {
    margin: 6px 0;
    padding: 5px 8px;
    border-left: 2px solid #b8d9ef;
    background: #f4f9fd;
    color: #33566f;
    font-size: 12px;
}

.chatia-bubble--ai code {
    font-family: Consolas, Monaco, 'Courier New', monospace;
    font-size: 12px;
    background: #eef3f8;
    color: #254257;
    padding: 1px 5px;
    border-radius: 4px;
}

.chatia-bubble--ai pre {
    margin: 10px 0;
    padding: 10px 12px;
    border-radius: 8px;
    background: #0f1720;
    color: #d8e8f4;
    overflow-x: auto;
}

.chatia-bubble--ai pre code {
    background: transparent;
    color: inherit;
    padding: 0;
    border-radius: 0;
    font-size: 12px;
}

/* ── Scroll to bottom ── */
.chatia-scroll-btn {
    position: absolute;
    bottom: 78px;
    left: 50%;
    transform: translateX(-50%) translateY(6px);
    padding: 6px 10px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.72);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(0, 148, 217, 0.28);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.10);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
    z-index: 5;
    font-size: 12px;
    font-family: inherit;
    color: #0080be;
    white-space: nowrap;
}

.chatia-scroll-btn.visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(-50%) translateY(0);
}

.chatia-scroll-btn:hover {
    background: rgba(0, 148, 217, 0.12);
    border-color: rgba(0, 148, 217, 0.5);
}

.chatia-scroll-btn svg {
    flex-shrink: 0;
}

/* ── Indicador de carga ── */
.chatia-typing {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 12px 14px;
}

.chatia-typing span {
    width: 7px;
    height: 7px;
    background: #0094d9;
    border-radius: 50%;
    display: inline-block;
    animation: chatia-bounce 1.2s infinite ease-in-out;
}
.chatia-typing span:nth-child(2) { animation-delay: 0.2s; }
.chatia-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes chatia-bounce {
    0%, 80%, 100% { transform: scale(0.7); opacity: 0.5; }
    40%            { transform: scale(1);   opacity: 1; }
}

/* ── Footer / Input ── */
.popup-messages-footer {
    background: #ffffff;
    border-top: 1px solid #e8eaed;
    padding: 12px 16px;
    flex-shrink: 0;
}

.chatia-input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.chatia-input-row textarea {
    flex: 1;
    border: 1px solid #dde1e7;
    border-radius: 20px;
    font-family: inherit;
    font-size: 13.5px;
    line-height: 1.4;
    min-height: 38px;
    max-height: 90px;
    padding: 8px 14px;
    resize: none;
    outline: none;
    transition: border-color 0.2s;
    color: #2c3e50;
    background: #f7f8fa;
}

.chatia-input-row textarea:focus {
    border-color: #0094d9;
    background: #fff;
}

.chatia-send-btn {
    background: #0094d9;
    border: none;
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, transform 0.1s;
    padding: 0;
}

.chatia-send-btn:hover  { background: #0080be; }
.chatia-send-btn:active { transform: scale(0.93); }
.chatia-send-btn:disabled { background: #b0cfe8; cursor: default; }

.chatia-powered {
    font-size: 10px;
    color: #aab0bb;
    text-align: center;
    margin-top: 6px;
}

.chatia-powered a {
    color: #0094d9;
    text-decoration: none;
}

/* ── Documentos adjuntos — cards ── */
.chatia-doc-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 4px 0 8px;
}

.chatia-doc-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 13px;
    background: #f4f8fc;
    border: 1px solid #cde0ef;
    border-radius: 9px;
    text-decoration: none !important;
    color: #163f60 !important;
    font-size: 13px;
    font-weight: 500;
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
    cursor: pointer;
}

.chatia-doc-card:hover {
    background: #e3f0fb;
    border-color: #0094d9;
    box-shadow: 0 2px 8px rgba(0, 148, 217, 0.15);
    text-decoration: none !important;
    color: #0a3050 !important;
}

.chatia-doc-icon-inline {
    width: 22px;
    height: 27px;
    display: inline-block;
    vertical-align: middle;
    margin-right: 7px;
    flex-shrink: 0;
}

.chatia-doc-icon {
    width: 26px;
    height: 32px;  /* mantiene proporción 75:92 del SVG */
    flex-shrink: 0;
    display: block;
}

.chatia-doc-name {
    flex: 1;
    word-break: break-word;
    line-height: 1.35;
}

@media (max-width: 1024px) {
    .chat-popup {
        width: min(98vw, 1100px);
        height: 82vh;
        right: 4px;
    }
}

@media (max-width: 768px) {
    .chat-popup {
        width: 100vw;
        height: 88vh;
        right: 0;
        border-radius: 12px 12px 0 0;
    }

    .chatia-bubble--ai {
        max-width: 100%;
    }

    .chatia-table {
        min-width: 380px;
    }
}
