.chat-popup {
    position: fixed;
    top: 82px;
    right: 16px;
    width: min(390px, calc(100vw - 20px));
    height: min(520px, calc(100vh - 96px));
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fffdf8;
    box-shadow: 0 18px 36px rgba(18, 30, 36, 0.22);
    display: none;
    grid-template-rows: auto 1fr auto;
    z-index: 120;
}

.chat-popup.open {
    display: grid;
}

.chat-popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-bottom: 1px solid #e2d5c1;
    background: linear-gradient(140deg, #f8f0df 0%, #fefbf5 100%);
}

.chat-popup-header strong {
    display: block;
    font-size: 15px;
}

.chat-popup-header small {
    color: var(--muted);
    font-size: 12px;
}

.chat-popup-close {
    border: 1px solid #d3c5af;
    border-radius: 9px;
    background: #fff7eb;
    color: #5a4d3a;
    width: 32px;
    height: 30px;
    cursor: pointer;
    font-weight: 700;
}

.chat-popup-messages {
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-popup-empty {
    margin: auto;
    text-align: center;
    color: var(--muted);
    background: #f7f1e6;
    border: 1px dashed #dbcab1;
    border-radius: 10px;
    padding: 12px;
    font-size: 14px;
}

.chat-popup-msg {
    max-width: 92%;
    border-radius: 10px;
    padding: 8px 10px;
    white-space: pre-wrap;
    line-height: 1.35;
    font-size: 14px;
}

.chat-popup-msg.user {
    align-self: flex-end;
    background: #1f3440;
    color: #f7fbfd;
}

.chat-popup-msg.assistant {
    align-self: flex-start;
    background: #f3ebdc;
    border: 1px solid #e4d6c0;
    color: #27363f;
}

.chat-popup-msg.error {
    background: #fff2f2;
    border: 1px solid #e4b8b8;
    color: #722525;
}

.chat-popup-msg.loading {
    opacity: 0.9;
}

.chat-popup-form {
    border-top: 1px solid #e2d5c1;
    padding: 10px;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    align-items: end;
}

.chat-popup-input {
    border: 1px solid #d5c6ae;
    border-radius: 10px;
    background: #fff;
    color: var(--ink);
    font: inherit;
    resize: none;
    padding: 8px 10px;
}

.chat-popup-send {
    border: none;
    border-radius: 10px;
    padding: 9px 12px;
    color: #fff;
    background: linear-gradient(140deg, var(--brand) 0%, var(--brand-strong) 100%);
    font-weight: 700;
    cursor: pointer;
}

.chat-popup-send:disabled {
    opacity: 0.75;
    cursor: not-allowed;
}

@media (max-width: 620px) {
    .chat-popup {
        top: 70px;
        right: 10px;
        width: calc(100vw - 20px);
        height: min(500px, calc(100vh - 82px));
    }
}
