/* CSS Variables for Theming */
:root {
    --kbb-primary: #7c49a3;
    /* Header, FAB, Send Button */
    --kbb-bg: #ffffff;
    /* Widget Container Background */
    --kbb-chat-bg: #f0f0f0;
    /* Chat Area Background */
    --kbb-bot-bg: #ffffff;
    /* Bot Message Bubble */
    --kbb-bot-text: #000000;
    --kbb-user-bg: #7c49a3;
    /* User Message Bubble */
    --kbb-user-text: #ffffff;

    /* Position Defaults (Overridden by JS injection) */
    --kbb-desktop-bottom: 20px;
    --kbb-desktop-right: 20px;
    --kbb-mobile-bottom: 20px;
    --kbb-mobile-right: 20px;
}

/* Floating Action Button */
.kbb-fab {
    position: fixed;
    top: var(--kbb-fab-top);
    bottom: var(--kbb-fab-bottom);
    left: var(--kbb-fab-left);
    right: var(--kbb-fab-right);
    width: 60px;
    height: 60px;
    background-color: var(--kbb-primary);
    border-radius: 50%;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}

.kbb-fab:hover {
    transform: scale(1.05);
}

.kbb-fab svg {
    width: 32px;
    height: 32px;
    fill: white;
}

/* Chat Container */
.kbb-chat-widget {
    position: fixed;
    /* Widget positions are calculated in PHP based on anchor */
    top: var(--kbb-win-top);
    bottom: var(--kbb-win-bottom);
    left: var(--kbb-win-left);
    right: var(--kbb-win-right);

    width: 350px;
    height: 500px;
    background-color: var(--kbb-bg);
    border-radius: 12px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.15);
    z-index: 9999;
    display: none;
    flex-direction: column;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ... (skip unchanged styles) ... */

@media (max-width: 480px) {
    .kbb-fab {
        top: var(--kbb-fab-m-top);
        bottom: var(--kbb-fab-m-bottom);
        left: var(--kbb-fab-m-left);
        right: var(--kbb-fab-m-right);
    }

    .kbb-chat-widget {
        width: 100%;
        height: 100%;
        top: var(--kbb-win-m-top);
        bottom: var(--kbb-win-m-bottom);
        left: var(--kbb-win-m-left);
        right: var(--kbb-win-m-right);
        border-radius: 0;
    }
}

/* Header */
.kbb-chat-header {
    background-color: var(--kbb-primary);
    color: white;
    padding: 15px;
    font-weight: bold;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.kbb-close-btn {
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
}

/* Messages Area */
.kbb-chat-body {
    flex: 1;
    background-color: var(--kbb-chat-bg);
    padding: 10px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.kbb-message {
    max-width: 80%;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
}

.kbb-message.bot {
    align-self: flex-start;
    background-color: var(--kbb-bot-bg);
    color: var(--kbb-bot-text);
    border-top-left-radius: 2px;
}

.kbb-message.user {
    align-self: flex-end;
    background-color: var(--kbb-user-bg);
    color: var(--kbb-user-text);
    border-top-right-radius: 2px;
}

/* Markdown Styles */
.kbb-message h3 {
    margin: 10px 0 5px 0;
    font-size: 16px;
    font-weight: bold;
    border-bottom: 2px solid rgba(0, 0, 0, 0.1);
    padding-bottom: 2px;
}

.kbb-message h4 {
    margin: 8px 0 4px 0;
    font-size: 15px;
    font-weight: bold;
}

.kbb-message b {
    font-weight: 700;
}

.kbb-message a {
    color: inherit;
    text-decoration: underline;
}

/* Table Styles */
.kbb-table-wrapper {
    overflow-x: auto;
    margin: 10px 0;
    border-radius: 8px;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.kbb-message table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    background: rgba(255, 255, 255, 0.5);
}

.kbb-message th {
    background-color: rgba(0, 0, 0, 0.05);
    font-weight: bold;
    text-align: left;
    padding: 6px 10px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.kbb-message td {
    padding: 6px 10px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.kbb-message tr:last-child td {
    border-bottom: none;
}

.kbb-typing {
    font-size: 12px;
    color: #888;
    margin-left: 5px;
    display: none;
}

/* Footer (Input) */
.kbb-chat-footer {
    padding: 10px;
    background-color: var(--kbb-bg);
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    display: flex;
    gap: 10px;
}

.kbb-chat-footer input {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 8px 12px;
    outline: none;
    background-color: #fff;
    color: #000;
}

.kbb-chat-footer button {
    background-color: var(--kbb-primary);
    color: white;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.kbb-chat-footer button:disabled {
    background-color: #ccc;
    filter: grayscale(1);
    opacity: 0.7;
}

.kbb-chat-footer button svg {
    width: 20px;
    height: 20px;
    fill: white;
    display: block; /* Safety against theme reset */
}

@media (max-width: 480px) {
    .kbb-fab {
        bottom: var(--kbb-mobile-bottom);
        right: var(--kbb-mobile-right);
    }

    .kbb-chat-widget {
        width: 100%;
        height: 100%;
        bottom: 0;
        right: 0;
        border-radius: 0;
    }
}