/* =========================================================
   KNOWLEDGE DRIVE / TRSP AI CHAT WIDGET
   Premium SaaS Style
========================================================= */

#kd-chat-widget,
#kd-chat-widget * {
    box-sizing: border-box;
    font-family:
        "Noto Sans Bengali",
        "Noto Sans",
        "Hind Siliguri",
        "Segoe UI",
        Arial,
        sans-serif;
}

#kd-chat-widget {
    --kd-primary: #c62828;
    --kd-primary-dark: #a91f1f;
    --kd-primary-light: #fff3f3;

    --kd-bg: #ffffff;
    --kd-soft: #f7f7f8;
    --kd-soft-2: #f2f2f3;

    --kd-text: #202020;
    --kd-muted: #777;
    --kd-border: #e9e9e9;

    position: fixed;
    right: 24px;
    bottom: 24px;

    z-index: 999999;

    font-size: 14px;
}

/* =========================================================
   LAUNCHER
========================================================= */

.kd-chat-launcher {
    width: 62px;
    height: 62px;

    padding: 0;
    border: 0;
    border-radius: 50%;

    background:
        linear-gradient(
            145deg,
            var(--kd-primary),
            var(--kd-primary-dark)
        );

    color: #fff;

    cursor: pointer;

    display: flex;
    align-items: center;
    justify-content: center;

    box-shadow:
        0 16px 35px rgba(0, 0, 0, 0.16),
        0 6px 15px rgba(198, 40, 40, 0.20);

    transition:
        transform 0.25s ease,
        box-shadow 0.25s ease;
}

.kd-chat-launcher:hover {
    transform: translateY(-3px) scale(1.04);

    box-shadow:
        0 20px 42px rgba(0, 0, 0, 0.18),
        0 8px 20px rgba(198, 40, 40, 0.24);
}

.kd-chat-launcher:active {
    transform: scale(0.96);
}

.kd-chat-launcher svg {
    width: 27px;
    height: 27px;
}

/* =========================================================
   CHAT WINDOW
========================================================= */

.kd-chat-window {
    position: absolute;

    right: 0;
    bottom: 78px;

    width: 390px;
    height: 620px;

    background: var(--kd-bg);

    border: 1px solid rgba(0, 0, 0, 0.055);

    border-radius: 24px;

    overflow: hidden;

    display: flex;
    flex-direction: column;

    box-shadow:
        0 30px 80px rgba(0, 0, 0, 0.17),
        0 10px 30px rgba(0, 0, 0, 0.08);

    opacity: 0;
    visibility: hidden;

    transform:
        translateY(18px)
        scale(0.97);

    transform-origin: bottom right;

    transition:
        opacity 0.22s ease,
        transform 0.22s ease,
        visibility 0.22s ease;
}

.kd-chat-window.active {
    opacity: 1;
    visibility: visible;

    transform:
        translateY(0)
        scale(1);
}

/* =========================================================
   HEADER
========================================================= */

.kd-chat-header {
    min-height: 88px;

    padding: 17px 18px;

    display: flex;
    align-items: center;
    justify-content: space-between;

    background:
        radial-gradient(
            circle at 90% 0%,
            rgba(255, 255, 255, 0.20),
            transparent 36%
        ),
        linear-gradient(
            135deg,
            #cc2b2b 0%,
            #b82020 55%,
            #a91f1f 100%
        );

    color: #fff;
}

.kd-chat-brand {
    display: flex;
    align-items: center;

    gap: 12px;

    min-width: 0;
}

.kd-chat-avatar {
    width: 46px;
    height: 46px;

    flex: 0 0 46px;

    border-radius: 15px;

    background: rgba(255, 255, 255, 0.14);

    border: 1px solid rgba(255, 255, 255, 0.25);

    display: flex;
    align-items: center;
    justify-content: center;

    backdrop-filter: blur(10px);
}

.kd-chat-avatar svg {
    width: 24px;
    height: 24px;
}

.kd-chat-title {
    font-size: 16px;

    font-weight: 700;

    line-height: 1.25;

    letter-spacing: -0.1px;

    white-space: nowrap;
}

.kd-chat-status {
    margin-top: 4px;

    display: flex;
    align-items: center;

    gap: 6px;

    font-size: 11.5px;

    line-height: 1;
}

.kd-chat-status-dot {
    width: 7px;
    height: 7px;

    flex: 0 0 7px;

    border-radius: 50%;

    background: #9cffad;

    box-shadow:
        0 0 0 3px rgba(156, 255, 173, 0.13);
}

.kd-chat-close {
    width: 36px;
    height: 36px;

    flex: 0 0 36px;

    padding: 0;

    border: 0;
    border-radius: 11px;

    background: rgba(255, 255, 255, 0.14);

    color: #fff;

    cursor: pointer;

    display: flex;
    align-items: center;
    justify-content: center;

    transition:
        background 0.2s ease,
        transform 0.2s ease;
}

.kd-chat-close:hover {
    background: rgba(255, 255, 255, 0.23);

    transform: rotate(3deg);
}

.kd-chat-close svg {
    width: 18px;
    height: 18px;
}

/* =========================================================
   MESSAGE AREA
========================================================= */

.kd-chat-messages {
    flex: 1;

    min-height: 0;

    padding: 18px 16px 16px;

    overflow-y: auto;

    background:
        radial-gradient(
            circle at 15% 0%,
            rgba(198, 40, 40, 0.028),
            transparent 30%
        ),
        #fff;

    scroll-behavior: smooth;

    overscroll-behavior: contain;
}

.kd-chat-messages::-webkit-scrollbar {
    width: 5px;
}

.kd-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.kd-chat-messages::-webkit-scrollbar-thumb {
    background: #d8d8d8;

    border-radius: 10px;
}

.kd-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #c5c5c5;
}

/* =========================================================
   WELCOME
========================================================= */

.kd-chat-welcome {
    text-align: center;

    padding: 15px 10px 13px;
}

.kd-chat-welcome-icon {
    width: 52px;
    height: 52px;

    margin: 0 auto 11px;

    border-radius: 16px;

    background: var(--kd-primary-light);

    color: var(--kd-primary);

    display: flex;
    align-items: center;
    justify-content: center;
}

.kd-chat-welcome-icon svg {
    width: 25px;
    height: 25px;
}

.kd-chat-welcome-title {
    font-size: 16px;

    font-weight: 700;

    line-height: 1.4;

    color: var(--kd-text);

    letter-spacing: -0.1px;
}

.kd-chat-welcome-text {
    max-width: 310px;

    margin: 6px auto 0;

    font-size: 12.5px;

    line-height: 1.6;

    color: var(--kd-muted);
}

/* =========================================================
   QUICK ACTIONS
========================================================= */

.kd-chat-quick-actions {
    display: flex;

    flex-wrap: wrap;

    gap: 7px;

    justify-content: center;

    margin-top: 13px;
}

.kd-chat-quick {
    padding: 8px 11px;

    border: 1px solid #e8e8e8;

    border-radius: 20px;

    background: #fff;

    color: #444;

    font-size: 11.5px;

    line-height: 1.2;

    cursor: pointer;

    transition:
        border-color 0.2s ease,
        color 0.2s ease,
        background 0.2s ease,
        transform 0.2s ease;
}

.kd-chat-quick:hover {
    border-color: #e2b0b0;

    color: var(--kd-primary);

    background: #fff8f8;

    transform: translateY(-1px);
}

.kd-chat-quick:active {
    transform: scale(0.97);
}

/* =========================================================
   MESSAGE ROW
========================================================= */

.kd-chat-message-row {
    display: flex;

    width: 100%;

    margin-bottom: 11px;
}

.kd-chat-message-row.customer {
    justify-content: flex-end;
}

.kd-chat-message-row.ai,
.kd-chat-message-row.agent {
    justify-content: flex-start;
}

/* =========================================================
   MESSAGE BUBBLE
========================================================= */

.kd-chat-bubble {
    max-width: 79%;

    padding: 10px 13px;

    font-size: 13px;

    line-height: 1.58;

    letter-spacing: -0.05px;

    word-break: break-word;

    overflow-wrap: anywhere;
}

.kd-chat-message-row.ai .kd-chat-bubble {
    background: #f4f4f5;

    color: var(--kd-text);

    border-radius:
        5px
        17px
        17px
        17px;
}

.kd-chat-message-row.agent .kd-chat-bubble {
    background: #fff4f4;

    color: var(--kd-text);

    border: 1px solid #f2dada;

    border-radius:
        5px
        17px
        17px
        17px;
}

.kd-chat-message-row.customer .kd-chat-bubble {
    background:
        linear-gradient(
            145deg,
            #ce2c2c,
            #bc2323
        );

    color: #fff;

    border-radius:
        17px
        5px
        17px
        17px;

    box-shadow:
        0 4px 10px rgba(198, 40, 40, 0.10);
}

/* =========================================================
   TYPING INDICATOR
========================================================= */

.kd-chat-typing {
    display: flex;

    align-items: center;

    gap: 4px;

    width: fit-content;

    padding: 11px 14px;

    background: #f4f4f5;

    border-radius:
        5px
        17px
        17px
        17px;
}

.kd-chat-typing span {
    width: 6px;
    height: 6px;

    border-radius: 50%;

    background: #999;

    animation:
        kdTyping 1.2s
        infinite
        ease-in-out;
}

.kd-chat-typing span:nth-child(2) {
    animation-delay: 0.15s;
}

.kd-chat-typing span:nth-child(3) {
    animation-delay: 0.30s;
}

@keyframes kdTyping {

    0%,
    60%,
    100% {
        transform: translateY(0);

        opacity: 0.45;
    }

    30% {
        transform: translateY(-4px);

        opacity: 1;
    }
}

/* =========================================================
   HUMAN HANDOFF NOTICE
========================================================= */

.kd-chat-human-notice {
    margin: 8px 4px 13px;

    padding: 10px 12px;

    background: #fff9eb;

    border: 1px solid #f1dfb4;

    border-radius: 12px;

    font-size: 11.5px;

    line-height: 1.55;

    color: #755d22;
}

/* =========================================================
   FOOTER
========================================================= */

.kd-chat-footer {
    flex: 0 0 auto;

    padding: 10px 12px 11px;

    border-top: 1px solid #ededed;

    background: #fff;
}

.kd-chat-input-wrap {
    display: flex;

    align-items: flex-end;

    gap: 8px;

    padding: 6px 6px 6px 13px;

    background: #f8f8f9;

    border: 1px solid #e8e8e9;

    border-radius: 17px;

    transition:
        border-color 0.2s ease,
        box-shadow 0.2s ease,
        background 0.2s ease;
}

.kd-chat-input-wrap:focus-within {
    background: #fff;

    border-color: #e0aaaa;

    box-shadow:
        0 0 0 3px rgba(198, 40, 40, 0.055);
}

.kd-chat-input {
    flex: 1;

    min-width: 0;

    min-height: 38px;

    max-height: 90px;

    padding: 8px 0;

    resize: none;

    border: 0;

    outline: 0;

    background: transparent;

    font-size: 13px;

    line-height: 1.5;

    color: var(--kd-text);
}

.kd-chat-input::placeholder {
    color: #9a9a9a;
}

.kd-chat-send {
    width: 38px;
    height: 38px;

    flex: 0 0 38px;

    padding: 0;

    border: 0;

    border-radius: 12px;

    background:
        linear-gradient(
            145deg,
            #cf2d2d,
            #b82020
        );

    color: #fff;

    display: flex;
    align-items: center;
    justify-content: center;

    cursor: pointer;

    box-shadow:
        0 4px 9px rgba(198, 40, 40, 0.15);

    transition:
        background 0.2s ease,
        transform 0.2s ease,
        box-shadow 0.2s ease;
}

.kd-chat-send:hover {
    background:
        linear-gradient(
            145deg,
            #c62828,
            #a91f1f
        );

    transform: translateY(-1px);

    box-shadow:
        0 6px 13px rgba(198, 40, 40, 0.20);
}

.kd-chat-send:active {
    transform: scale(0.94);
}

.kd-chat-send:disabled {
    opacity: 0.5;

    cursor: not-allowed;

    transform: none;

    box-shadow: none;
}

.kd-chat-send svg {
    width: 18px;
    height: 18px;
}

/* =========================================================
   POWERED TEXT
========================================================= */

.kd-chat-powered {
    text-align: center;

    margin-top: 7px;

    font-size: 9.5px;

    line-height: 1.2;

    color: #aaa;
}

/* =========================================================
   MOBILE
========================================================= */

@media (max-width: 520px) {

    #kd-chat-widget {
        right: 14px;
        bottom: 14px;
        left: 14px;
    }

    .kd-chat-window {
        right: 0;
        bottom: 74px;

        width: 100%;

        height:
            min(
                680px,
                calc(100vh - 105px)
            );

        border-radius: 22px;
    }

    .kd-chat-launcher {
        margin-left: auto;
    }

    .kd-chat-bubble {
        max-width: 82%;
    }
}

/* =========================================================
   SMALL MOBILE
========================================================= */

@media (max-width: 380px) {

    .kd-chat-window {
        bottom: 70px;

        height:
            calc(100vh - 90px);

        border-radius: 20px;
    }

    .kd-chat-header {
        min-height: 82px;

        padding: 15px;
    }

    .kd-chat-avatar {
        width: 43px;
        height: 43px;

        flex-basis: 43px;
    }

    .kd-chat-title {
        font-size: 15px;
    }

    .kd-chat-bubble {
        max-width: 85%;

        font-size: 12.8px;
    }
}

/* =========================================================
   REDUCED MOTION
========================================================= */

@media (prefers-reduced-motion: reduce) {

    #kd-chat-widget *,
    #kd-chat-widget *::before,
    #kd-chat-widget *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}