/*
 * Capiboss property assistant chat widget.
 * Scoped under .chatbot so the theme's own styles are untouched.
 * Colors reuse the CSS variables defined by styles.css.
 */

.chatbot {
    position: fixed;
    left: 24px;
    bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    z-index: 9999;
    font-family: inherit;
}

/* When the panel is open the launcher disappears so only the
   interface itself is visible. */
.chatbot--open .chatbot-launcher {
    display: none;
}

.chatbot--open .chatbot-panel {
    margin-bottom: 0;
}

.chatbot-launcher {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    margin-left: auto;
    border: none;
    border-radius: 50%;
    background: var(--Primary, #43a91b);
    color: var(--White, #ffffff);
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}

/* Red unread-replies pill anchored to the top-right of the launcher.
   Hidden entirely when there is nothing unread. */
.chatbot-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 999px;
    background: #e02424;
    color: var(--White, #ffffff);
    font-size: 12px;
    font-weight: 700;
    line-height: 20px;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
    pointer-events: none;
}

.chatbot-panel {
    display: flex;
    flex-direction: column;
    width: 360px;
    max-width: calc(100vw - 32px);
    height: 520px;
    max-height: calc(100vh - 120px);
    margin-bottom: 12px;
    overflow: hidden;
    border: 1px solid var(--Line, #e4e4e4);
    border-radius: 16px;
    background: var(--White, #ffffff);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.2);
}

.chatbot-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--Primary, #43a91b);
    color: var(--White, #ffffff);
}

.chatbot-head-text h6 {
    margin: 0;
    color: var(--White, #ffffff);
}

.chatbot-head-text span {
    font-size: 12px;
}

/* Clear and close buttons share one row in the panel header. */
.chatbot-head-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.chatbot-close,
.chatbot-clear {
    border: none;
    background: transparent;
    color: var(--White, #ffffff);
    font-size: 20px;
    cursor: pointer;
}

.chatbot-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    background: var(--Bg-light, #f8f7f3);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chatbot-msg {
    margin: 0;
    padding: 10px 12px;
    border-radius: 12px;
    max-width: 85%;
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-line;
    word-wrap: break-word;
}

.chatbot-msg--bot {
    align-self: flex-start;
    width: fit-content;
    max-width: 88%;
    padding: 14px 16px;
    border-radius: 16px;
    background: var(--White, #ffffff);
    color: var(--Text-primary, #111111);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

/* Formatted assistant replies manage their own spacing, so they do
   not use the pre-line behaviour of plain messages. Everything below
   is scoped under .chatbot-msg--bot so no other component is affected. */
.chatbot-msg--bot {
    white-space: normal;
    font-size: 14px;
    line-height: 1.6;
}

.chatbot-msg--bot > :first-child {
    margin-top: 0;
}

.chatbot-msg--bot > :last-child {
    margin-bottom: 0;
}

.chatbot-msg--bot p {
    margin: 0 0 10px;
}

.chatbot-msg--bot h4,
.chatbot-msg--bot h5 {
    margin: 14px 0 6px;
    font-weight: 700;
    line-height: 1.35;
    color: var(--Text-primary, #111111);
}

.chatbot-msg--bot h4 {
    font-size: 15px;
}

.chatbot-msg--bot h5 {
    font-size: 14px;
}

.chatbot-msg--bot strong {
    font-weight: 600;
}

.chatbot-msg--bot em {
    font-style: italic;
}

.chatbot-msg--bot ul,
.chatbot-msg--bot ol {
    margin: 4px 0 12px;
    padding-left: 20px;
}

.chatbot-msg--bot li {
    margin: 4px 0;
    padding-left: 2px;
}

.chatbot-msg--bot li::marker {
    color: var(--Primary, #43a91b);
}

.chatbot-msg--bot a {
    color: var(--Primary, #43a91b);
    font-weight: 500;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.chatbot-msg--bot a:hover {
    color: var(--Orange-hover, #FC6A03);
}

.chatbot-msg--bot code {
    padding: 1px 5px;
    border-radius: 5px;
    background: var(--Bg-light, #f8f7f3);
    font-family: "Consolas", "Menlo", monospace;
    font-size: 13px;
}

.chatbot-msg--bot pre {
    margin: 8px 0 12px;
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--Bg-light, #f8f7f3);
    overflow-x: auto;
}

.chatbot-msg--bot pre code {
    padding: 0;
    background: transparent;
    white-space: pre;
}

.chatbot-msg--bot blockquote {
    margin: 8px 0 12px;
    padding-left: 12px;
    border-left: 3px solid var(--Primary, #43a91b);
    color: var(--Text-secondary, #5c6368);
}

.chatbot-msg--bot blockquote p {
    margin: 0;
}

.chatbot-table-wrap {
    margin: 8px 0 12px;
    overflow-x: auto;
}

.chatbot-msg--bot table {
    border-collapse: collapse;
    font-size: 13px;
}

.chatbot-msg--bot th,
.chatbot-msg--bot td {
    padding: 6px 10px;
    border-bottom: 1px solid var(--Line, #e4e4e4);
    text-align: left;
}

.chatbot-msg--bot th {
    font-weight: 600;
}

.chatbot-msg--user {
    align-self: flex-end;
    background: var(--Primary, #43a91b);
    color: var(--White, #ffffff);
}

.chatbot-card {
    align-self: flex-start;
    display: block;
    max-width: 85%;
    padding: 10px 12px;
    border: 1px solid var(--Line, #e4e4e4);
    border-left: 3px solid var(--Primary, #43a91b);
    border-radius: 12px;
    background: var(--White, #ffffff);
    text-decoration: none;
}

.chatbot-card:hover {
    border-color: var(--Primary, #43a91b);
}

.chatbot-msg--typing {
    display: flex;
    gap: 4px;
    align-items: center;
    min-height: 14px;
}

.chatbot-msg--typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--Text-secondary-2, #a4aeb5);
    animation: chatbot-typing 1.2s infinite ease-in-out;
}

.chatbot-msg--typing span:nth-child(2) {
    animation-delay: 0.15s;
}

.chatbot-msg--typing span:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes chatbot-typing {
    0%,
    60%,
    100% {
        opacity: 0.25;
        transform: translateY(0);
    }
    30% {
        opacity: 1;
        transform: translateY(-2px);
    }
}

.chatbot-escalation {
    align-self: flex-start;
    max-width: 85%;
    padding: 12px;
    border: 1px solid var(--Line, #e4e4e4);
    border-left: 3px solid var(--Secondary-2, #77f3a7);
    border-radius: 12px;
    background: var(--White, #ffffff);
}

.chatbot-escalation-text {
    margin: 0 0 10px;
    font-size: 14px;
    color: var(--Text-primary, #111111);
}

.chatbot-whatsapp-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: 999px;
    background: var(--Primary, #43a91b);
    color: var(--White, #ffffff);
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
}

.chatbot-whatsapp-btn:hover {
    background: var(--Orange-hover, #FC6A03);
    color: var(--White, #ffffff);
}

.chatbot-card-title {
    margin: 0 0 4px;
    font-size: 14px;
    font-weight: 600;
    color: var(--Text-primary, #111111);
}

.chatbot-card-meta {
    margin: 0;
    font-size: 13px;
    color: var(--Text-secondary, #5c6368);
}

.chatbot-form {
    display: flex;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid var(--Line, #e4e4e4);
    background: var(--White, #ffffff);
}

.chatbot-input {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid var(--Line, #e4e4e4);
    border-radius: 999px;
    font-size: 14px;
    outline: none;
}

.chatbot-input:focus {
    border-color: var(--Primary, #43a91b);
}

.chatbot-send {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: var(--Primary, #43a91b);
    color: var(--White, #ffffff);
    font-size: 18px;
}

.chatbot-send[disabled] {
    opacity: 0.6;
}
