/* =========================================================
   iDeate AI Chat Widget
   ========================================================= */

:root {
    --ideate-chat-dark: #19376d;
    --ideate-chat-green: #05c38a;
    --ideate-chat-pink: #f0316a;
    --ideate-chat-cyan: #41cccc;
    --ideate-chat-white: #ffffff;
    --ideate-chat-light: #f5f7f8;
    --ideate-chat-border: #e4e7e9;
    --ideate-chat-muted: #6b7075;
}

/* ---------- Widget container ---------- */

#ideate-chat-widget {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 99999;
    font-family: "Roboto", Arial, sans-serif;
    box-sizing: border-box;
}

#ideate-chat-widget *,
#ideate-chat-widget *::before,
#ideate-chat-widget *::after {
    box-sizing: border-box;
}

/* ---------- Launcher area ---------- */

.ideate-chat-launcher-wrap {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
}

.ideate-chat-teaser {
    position: relative;
    padding: 11px 17px;
    background: var(--ideate-chat-white);
    color: var(--ideate-chat-dark);
    border-radius: 20px;
    box-shadow: 0 5px 24px rgba(0, 0, 0, 0.16);
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
    transition:
        opacity 0.2s ease,
        transform 0.2s ease;
}

.ideate-chat-teaser:hover {
    transform: translateY(-2px);
}

.ideate-chat-launcher {
    width: 60px;
    height: 60px;
    border: 0;
    border-radius: 50%;
    background: var(--ideate-chat-green);
    color: var(--ideate-chat-white);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 7px 26px rgba(0, 0, 0, 0.22);
    transition:
        transform 0.2s ease,
        background 0.2s ease,
        box-shadow 0.2s ease;
}

.ideate-chat-launcher:hover {
    background: var(--ideate-chat-pink);
    transform: translateY(-2px);
    box-shadow: 0 9px 30px rgba(0, 0, 0, 0.25);
}

.ideate-chat-launcher:focus-visible,
.ideate-chat-close:focus-visible,
.ideate-chat-send:focus-visible,
.ideate-chat-quick-action:focus-visible {
    outline: 3px solid rgba(65, 204, 204, 0.45);
    outline-offset: 2px;
}

.ideate-chat-launcher svg {
    width: 28px;
    height: 28px;
    fill: currentColor;
}

/* ---------- Chat window ---------- */

.ideate-chat-window {
    position: absolute;
    right: 0;
    bottom: 76px;
    width: 380px;
    height: min(620px, calc(100vh - 130px));
    min-height: 480px;
    overflow: hidden;
    background: var(--ideate-chat-white);
    border: 1px solid rgba(0, 0, 0, 0.07);
    border-radius: 18px;
    box-shadow: 0 15px 50px rgba(0, 0, 0, 0.22);

    display: flex;
    flex-direction: column;

    opacity: 0;
    visibility: hidden;
    transform: translateY(14px) scale(0.98);
    transform-origin: bottom right;

    transition:
        opacity 0.2s ease,
        transform 0.2s ease,
        visibility 0.2s ease;
}

.ideate-chat-window.ideate-chat-open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* ---------- Header ---------- */

.ideate-chat-header {
    flex: 0 0 auto;
    padding: 18px 18px 16px;
    background: var(--ideate-chat-dark);
    color: var(--ideate-chat-white);

    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.ideate-chat-header-content {
    min-width: 0;
}

.ideate-chat-title {
    margin: 0;
    font-family: "Montserrat", Arial, sans-serif;
    font-size: 18px;
    line-height: 1.25;
    font-weight: 700;
    color: var(--ideate-chat-white);
}

.ideate-chat-subtitle {
    margin: 4px 0 0;
    font-size: 12px;
    line-height: 1.4;
    color: rgba(255, 255, 255, 0.72);
}

.ideate-chat-close {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--ideate-chat-white);
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.2s ease;
}

.ideate-chat-close:hover {
    background: rgba(255, 255, 255, 0.12);
}

/* ---------- Messages ---------- */

.ideate-chat-messages {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 18px;
    background: var(--ideate-chat-light);
    scroll-behavior: smooth;
}

.ideate-chat-message {
    display: flex;
    width: 100%;
    margin-bottom: 12px;
}

.ideate-chat-message.bot {
    justify-content: flex-start;
}

.ideate-chat-message.user {
    justify-content: flex-end;
}

.ideate-chat-bubble {
    max-width: 84%;
    padding: 11px 14px;
    border-radius: 15px;
    font-size: 14px;
    line-height: 1.5;
    overflow-wrap: anywhere;
}

.ideate-chat-message.bot .ideate-chat-bubble {
    background: var(--ideate-chat-white);
    color: var(--ideate-chat-dark);
    border: 1px solid var(--ideate-chat-border);
    border-bottom-left-radius: 5px;
}

.ideate-chat-message.user .ideate-chat-bubble {
    background: var(--ideate-chat-green);
    color: var(--ideate-chat-white);
    border-bottom-right-radius: 5px;
}

.ideate-chat-bubble p {
    margin: 0 0 8px;
}

.ideate-chat-bubble p:last-child {
    margin-bottom: 0;
}

.ideate-chat-bubble strong {
    font-weight: 700;
}

.ideate-chat-bubble a {
    color: #008f69;
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.ideate-chat-message.user .ideate-chat-bubble a {
    color: var(--ideate-chat-white);
}

/* ---------- Quick actions ---------- */

.ideate-chat-quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 4px 0 16px;
}

.ideate-chat-quick-action {
    border: 1px solid var(--ideate-chat-green);
    border-radius: 18px;
    padding: 8px 11px;
    background: var(--ideate-chat-white);
    color: var(--ideate-chat-dark);
    font-family: "Roboto", Arial, sans-serif;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition:
        background 0.2s ease,
        color 0.2s ease,
        border-color 0.2s ease;
}

.ideate-chat-quick-action:hover {
    background: var(--ideate-chat-green);
    border-color: var(--ideate-chat-green);
    color: var(--ideate-chat-white);
}

/* ---------- Typing indicator ---------- */

.ideate-chat-typing {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-height: 20px;
}

.ideate-chat-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--ideate-chat-muted);
    animation: ideate-chat-dot 1.2s infinite ease-in-out;
}

.ideate-chat-typing span:nth-child(2) {
    animation-delay: 0.15s;
}

.ideate-chat-typing span:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes ideate-chat-dot {
    0%,
    60%,
    100% {
        opacity: 0.35;
        transform: translateY(0);
    }

    30% {
        opacity: 1;
        transform: translateY(-3px);
    }
}

/* ---------- Composer ---------- */

.ideate-chat-composer {
    flex: 0 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 9px;
    padding: 12px;
    background: var(--ideate-chat-white);
    border-top: 1px solid var(--ideate-chat-border);
}

.ideate-chat-input {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 42px;
    max-height: 105px;
    resize: none;
    overflow-y: auto;

    border: 1px solid #d6dadd;
    border-radius: 12px;
    padding: 10px 12px;

    background: var(--ideate-chat-white);
    color: var(--ideate-chat-dark);

    font-family: "Roboto", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.45;

    outline: none;
    transition:
        border-color 0.2s ease,
        box-shadow 0.2s ease;
}

.ideate-chat-input::placeholder {
    color: #8b9094;
}

.ideate-chat-input:focus {
    border-color: var(--ideate-chat-cyan);
    box-shadow: 0 0 0 3px rgba(65, 204, 204, 0.14);
}

.ideate-chat-send {
    flex: 0 0 auto;
    width: 42px;
    height: 42px;
    border: 0;
    border-radius: 12px;

    display: flex;
    align-items: center;
    justify-content: center;

    background: var(--ideate-chat-green);
    color: var(--ideate-chat-white);
    cursor: pointer;

    transition:
        background 0.2s ease,
        transform 0.2s ease;
}

.ideate-chat-send:hover {
    background: var(--ideate-chat-pink);
    transform: translateY(-1px);
}

.ideate-chat-send:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
}

.ideate-chat-send svg {
    width: 19px;
    height: 19px;
    fill: currentColor;
}

/* ---------- Footer ---------- */

.ideate-chat-footer {
    flex: 0 0 auto;
    padding: 0 12px 9px;
    background: var(--ideate-chat-white);
    text-align: center;
    font-size: 10px;
    line-height: 1.3;
    color: var(--ideate-chat-muted);
}

/* ---------- Hidden utility ---------- */

.ideate-chat-hidden {
    display: none !important;
}

/* ---------- Mobile ---------- */

@media (max-width: 600px) {

    #ideate-chat-widget {
        right: 12px;
        bottom: calc(12px + env(safe-area-inset-bottom));
    }

    .ideate-chat-launcher {
        width: 56px;
        height: 56px;
    }

    .ideate-chat-teaser {
        max-width: 190px;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .ideate-chat-window {
        position: fixed;

        left: 10px;
        right: 10px;
        top: auto;

        bottom: calc(82px + env(safe-area-inset-bottom));

        width: auto;
        max-width: none;

        height: min(640px, calc(100dvh - 105px));
        max-height: calc(100dvh - 105px);
        min-height: 0;

        border-radius: 16px;
        transform-origin: bottom center;
    }

    /* Header stays fixed inside chat window */
    .ideate-chat-header {
        flex-shrink: 0;
    }

    /* Only message area should consume flexible space */
    .ideate-chat-messages {
        flex: 1 1 0;
        min-height: 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Prevent composer from exceeding widget width */
    .ideate-chat-composer {
        flex: 0 0 auto;
        width: 100%;
        min-width: 0;

        display: grid;
        grid-template-columns: minmax(0, 1fr) 42px;
        align-items: end;
        gap: 9px;

        padding: 12px;
    }

    /* Critical on mobile: allow input to shrink */
    .ideate-chat-input {
        width: 100%;
        min-width: 0;
        max-width: 100%;

        font-size: 16px;
    }

    .ideate-chat-send {
        width: 42px;
        min-width: 42px;
        height: 42px;
    }

    .ideate-chat-footer {
        flex-shrink: 0;
        padding-bottom: 9px;
    }
}

@media (max-width: 380px) {

    .ideate-chat-teaser {
        display: none;
    }

    .ideate-chat-window {
        left: 6px;
        right: 6px;

        bottom: calc(76px + env(safe-area-inset-bottom));

        height: calc(100dvh - 94px);
        max-height: calc(100dvh - 94px);
    }

    .ideate-chat-header {
        padding: 15px;
    }

    .ideate-chat-messages {
        padding: 14px;
    }

    .ideate-chat-composer {
        padding: 10px;
        gap: 8px;
        grid-template-columns: minmax(0, 1fr) 42px;
    }
}

    /* Hide launcher while chat window is open */
    #ideate-chat-widget:has(.ideate-chat-window.ideate-chat-open)
    .ideate-chat-launcher-wrap {
        display: none;
    }

    /* Hide theme back-to-top button while chat is open */
    body:has(.ideate-chat-window.ideate-chat-open) .go-top {
        display: none !important;
    }

/* Keep theme's back-to-top button clear of iDeate Assistant */
.go-top {
    bottom: 100px !important;
    right: 34px !important;
}

@media (max-width: 767px) {
    .go-top {
        bottom: 85px !important;
        right: 34px !important;
    }
}

/* Delayed launcher on secondary pages */
#ideate-chat-widget.ideate-chat-delayed .ideate-chat-launcher-wrap {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(8px);
    transition:
        opacity 0.3s ease,
        transform 0.3s ease,
        visibility 0.3s ease;
}

#ideate-chat-widget.ideate-chat-delayed.ideate-chat-ready
.ideate-chat-launcher-wrap {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0);
}

