/* chat-widget.css - AI chat widget, loaded site-wide via blog/base.html.
   Deliberately independent of base.css - self-contained so it never
   collides with theme selectors, and can be dropped/replaced on its own. */

.ai-chat-widget {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 1050;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

.ai-chat-toggle {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: #ff6600;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(255, 102, 0, 0.35);
    transition: transform 0.2s ease, background-color 0.2s ease;
}

.ai-chat-toggle:hover {
    background: #e55a00;
    transform: translateY(-2px);
}

.ai-chat-panel {
    /* Default state: closed. Only .is-open on the wrapper switches this to
       flex - do not rely on the HTML `hidden` attribute here, mixing the
       two caused the panel to show regardless of state (#1). */
    display: none;
    position: absolute;
    right: 0;
    bottom: 70px;
    width: 340px;
    max-width: calc(100vw - 40px);
    height: 460px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
    flex-direction: column;
    overflow: hidden;
}

.ai-chat-widget.is-open .ai-chat-panel {
    display: flex;
}

.ai-chat-header {
    background: #1a1a1a;
    color: #fff;
    padding: 12px 10px 12px 18px;
    font-weight: 600;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.ai-chat-close {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0.8;
}

.ai-chat-close:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.12);
}

.ai-chat-messages {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #f7f7f8;
}

.ai-chat-msg {
    max-width: 85%;
    padding: 9px 13px;
    border-radius: 12px;
    font-size: 0.88rem;
    line-height: 1.4;
    white-space: pre-wrap;
    word-break: break-word;
}

.ai-chat-msg-bot {
    background: #fff;
    border: 1px solid #ececec;
    color: #333;
    align-self: flex-start;
    border-bottom-left-radius: 3px;
}

.ai-chat-msg-user {
    background: #ff6600;
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 3px;
}

.ai-chat-msg-error {
    background: #fdecea;
    border: 1px solid #f5c6cb;
    color: #7a1f1f;
    align-self: flex-start;
}

.ai-chat-msg-pending {
    background: #fff;
    border: 1px solid #ececec;
    color: #999;
    align-self: flex-start;
    font-style: italic;
}

.ai-chat-contact-card {
    max-width: 92%;
    align-self: flex-start;
    background: #fff;
    border: 1px solid #ffd7b8;
    border-radius: 12px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ai-chat-contact-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
}

.ai-chat-contact-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: #333;
}

.ai-chat-contact-cancel {
    flex: 0 0 auto;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: #999;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.ai-chat-contact-cancel:hover {
    background: #f2f2f2;
    color: #333;
}

.ai-chat-contact-card input {
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 0.85rem;
    outline: none;
}

.ai-chat-contact-card input:focus {
    border-color: #ff6600;
}

.ai-chat-contact-actions {
    display: flex;
    gap: 8px;
}

.ai-chat-contact-submit {
    flex: 1 1 auto;
    background: #ff6600;
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
}

.ai-chat-contact-submit:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.ai-chat-contact-skip {
    flex: 0 0 auto;
    background: transparent;
    color: #777;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 0.85rem;
    cursor: pointer;
}

.ai-chat-contact-skip:hover {
    background: #f5f5f5;
}

.ai-chat-leave-contact {
    border: none;
    background: transparent;
    color: #ff6600;
    font-size: 0.78rem;
    font-weight: 600;
    text-align: left;
    padding: 6px 14px 0;
    cursor: pointer;
}

.ai-chat-leave-contact:hover {
    text-decoration: underline;
}

.ai-chat-form {
    display: flex;
    gap: 8px;
    padding: 10px;
    border-top: 1px solid #ececec;
    background: #fff;
}

.ai-chat-form input {
    flex: 1 1 auto;
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 9px 14px;
    font-size: 0.88rem;
    outline: none;
}

.ai-chat-form input:focus {
    border-color: #ff6600;
}

.ai-chat-form button {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    background: #ff6600;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex: 0 0 auto;
}

.ai-chat-form button:disabled {
    background: #ccc;
    cursor: not-allowed;
}

@media (max-width: 480px) {
    .ai-chat-panel {
        width: calc(100vw - 24px);
        right: -8px;
        height: min(480px, calc(100vh - 110px));
    }
}
