// (C) 2024-2025 GoodData Corporation

@use "sass:color";
@use "variables" as variables;
@use "@gooddata/sdk-ui-kit/styles/scss/variables" as kit-variables;
@use "@gooddata/sdk-ui-kit/styles/scss/mixins" as kit-mixins;
@use "@gooddata/sdk-ui-kit/styles/scss/Form/mixins" as form-mixins;
@use "@gooddata/sdk-ui-kit/styles/scss/typo-mixins" as typo-mixins;

$dataset_color: #952f8e;

//MIXINS

@mixin content-markdown($base, $type: "user") {
    & h1,
    & h2,
    & h3,
    & h4,
    & h5,
    & h6,
    & p,
    & li,
    & th,
    & td {
        color: $base;
    }

    & table {
        @include typo-mixins.gd-paragraph;
        width: 100%;
        border-collapse: collapse;
        margin: 8px 0;
        @if $type == "user" {
            border-color: rgba(255, 255, 255, 0.4);
        }
    }

    & th,
    & td {
        @if $type == "user" {
            border-color: rgba(255, 255, 255, 0.4);
        } @else {
            border: 1px solid kit-variables.$gd-border-color;
            padding: 4px 8px;
            text-align: left;
        }
    }

    & th {
        @if $type == "user" {
            background: rgba(255, 255, 255, 0.12);
        } @else {
            background: kit-variables.$is-focused-background;
        }
        font-weight: 600;
    }

    & h1,
    & h2,
    & h3,
    & h4,
    & h5,
    & h6,
    & p,
    & ul,
    & ol {
        margin: 0 0 8px;
    }

    & h1,
    & h2,
    & h3,
    & h4,
    & h5,
    & h6 {
        margin-top: 12px;
    }

    & h1:first-child,
    & h2:first-child,
    & h3:first-child,
    & h4:first-child,
    & h5:first-child,
    & h6:first-child {
        margin-top: 0;
    }

    & ul,
    & ol {
        padding-left: 20px;
    }

    & li {
        margin-bottom: 4px;

        &:last-child {
            margin-bottom: 0;
        }
    }

    & p:last-child,
    & ul:last-child,
    & ol:last-child {
        margin-bottom: 0;
    }
}

@mixin object-types($type: "user") {
    .gd-gen-ai-chat__message__object {
        font-weight: normal;
        border-radius: 20px;
        padding: 3px 7px;
        display: inline-flex;
        align-items: center;
        position: relative;
        top: 0.2em;
        font-size: 12px;
        line-height: 12px;
        cursor: pointer;

        @if $type == "user" {
            border: 1px solid var(--gd-palette-complementary-0-t10);

            &:hover {
                border: 1px solid var(--gd-palette-complementary-0-t50);
            }
        } @else {
            border: 1px solid var(--gd-palette-complementary-3);

            &:hover {
                border: 1px solid var(--gd-palette-complementary-5);
            }
        }

        &.metric {
            @if $type == "user" {
                color: kit-variables.$gd-color-white;
            } @else {
                color: kit-variables.$gd-color-link;
                .gd-gen-ai-chat__message-icon::before {
                    background-color: kit-variables.$gd-color-object-type-metric;
                }
            }
        }

        &.fact {
            @if $type == "user" {
                color: kit-variables.$gd-color-white;
            } @else {
                color: kit-variables.$gd-color-link;
                .gd-gen-ai-chat__message-icon::before {
                    background-color: kit-variables.$gd-color-object-type-metric;
                }
            }
        }

        &.attribute,
        &.label {
            @if $type == "user" {
                color: kit-variables.$gd-color-white;
            } @else {
                color: kit-variables.$gd-color-link;
                .gd-gen-ai-chat__message-icon::before {
                    background-color: kit-variables.$gd-color-object-type-attribute;
                }
            }
        }

        &.date {
            @if $type == "user" {
                color: kit-variables.$gd-color-white;
            } @else {
                color: kit-variables.$gd-color-link;
                .gd-gen-ai-chat__message-icon::before {
                    background-color: kit-variables.$gd-color-object-type-date;
                }
            }
        }

        &.dataset {
            @if $type == "user" {
                color: kit-variables.$gd-color-white;
            } @else {
                color: kit-variables.$gd-color-link;
                .gd-gen-ai-chat__message-icon::before {
                    background-color: $dataset_color;
                }
            }
        }

        &.dashboard {
            font-weight: bold;
            @if $type == "user" {
                color: kit-variables.$gd-color-white;
            } @else {
                color: kit-variables.$gd-color-link;
                .gd-gen-ai-chat__message-icon::before {
                    background-color: kit-variables.$gd-color-text;
                }
            }
        }

        &.visualization {
            font-weight: bold;
            @if $type == "user" {
                color: kit-variables.$gd-color-white;
            } @else {
                color: kit-variables.$gd-color-link;
                .gd-gen-ai-chat__message-icon::before {
                    background-color: kit-variables.$gd-color-text;
                }
            }
        }

        .gd-gen-ai-chat__message-icon {
            display: inline-block;
            width: 14px;
            height: 14px;
            margin-right: 5px;

            &::before {
                @if $type == "user" {
                    background-color: kit-variables.$gd-color-white;
                } @else {
                    background-color: kit-variables.$gd-color-dark;
                }
            }
        }

        &.metric .gd-gen-ai-chat__message-icon {
            @include variables.gd-svg-mask("metric");
        }

        &.attribute .gd-gen-ai-chat__message-icon,
        &.label .gd-gen-ai-chat__message-icon {
            @include variables.gd-svg-mask("attribute");
        }

        &.fact .gd-gen-ai-chat__message-icon {
            @include variables.gd-svg-mask("measure");
        }

        &.date .gd-gen-ai-chat__message-icon {
            @include variables.gd-svg-mask("date");
        }

        &.dataset .gd-gen-ai-chat__message-icon {
            @include variables.gd-svg-mask("dataset");
        }

        &.dashboard .gd-gen-ai-chat__message-icon {
            @include variables.gd-svg-mask("dashboard");
        }

        &.visualization .gd-gen-ai-chat__message-icon {
            @include variables.gd-svg-mask("visualization");
        }
    }

    .gd-ui-kit-tooltip__anchor {
        display: inline-flex;
    }
}

//UNIVERSAL

.gd-gen-ai-chat__messages {
    $root: &;

    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    display: flex;
    justify-content: center;

    // Use padding on the right to prevent the scrollbar from overlapping the content
    margin: variables.$y-spacing 0 0 variables.$x-spacing;
    padding-right: variables.$x-spacing;

    &--fullscreen#{$root}--big-screen#{$root}--empty {
        flex-grow: 0;
        overflow-y: visible;
    }

    &--agent-switching &__agent-change {
        display: flex;
        align-items: center;
        gap: 15px;
        margin: 18px 0;
        color: kit-variables.$gd-color-state-blank;
        font-size: 12px;
        line-height: 23px;

        &__line {
            flex: 1 1 0;
            height: 1px;
            background: kit-variables.$gd-border-color;
        }

        &__label {
            flex: 0 0 auto;
            text-align: center;
            white-space: nowrap;
        }
    }
}

.gd-gen-ai-chat__messages__scroll {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
    max-width: 720px;
}

.gd-gen-ai-chat__visually__hidden {
    position: absolute;
    top: -1000px;
    left: -1000px;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.gd-gen-ai-chat__summary__empty {
    color: kit-variables.$gd-color-link;
    font-style: italic;

    p {
        color: kit-variables.$gd-color-link;
        font-style: italic;
    }
}

//MESSAGES

.gd-gen-ai-chat__messages__message {
    display: flex;
}

.gd-gen-ai-chat__messages__message__contents_wrap {
    display: flex;
    flex-direction: column;
    gap: 5px;
    flex-grow: 1;
}

.gd-gen-ai-chat__messages__feedback {
    display: flex;
    flex-direction: row;
    height: 20px;

    svg {
        opacity: 0;
        transition: opacity 0.2s;
    }

    &:focus-within {
        svg {
            opacity: 1;
        }
    }
}

.gd-gen-ai-chat__messages__message:last-child .gd-gen-ai-chat__messages__feedback,
.gd-gen-ai-chat__messages__message:hover .gd-gen-ai-chat__messages__feedback,
.gd-gen-ai-chat__messages__feedback--assigned {
    svg {
        opacity: 1;
    }
}

.gd-gen-ai-chat__messages__message--user {
    .gd-gen-ai-chat__messages__content--text {
        $tail-height: 7px;
        $tail-width: 10px;

        max-width: 80%;
        background-color: kit-variables.$gd-palette-primary-base;
        border-radius: 3px 3px 0 3px;
        padding: 4.5px 12px;
        position: relative;
        align-self: flex-end;
        margin-bottom: 15px;
        animation: gd-gen-ai-message-in 0.3s ease-out;

        &::after {
            content: "";
            position: absolute;
            bottom: -$tail-height;
            right: 0;
            border: 0 solid transparent;
            border-top: $tail-height solid kit-variables.$gd-palette-primary-base;
            border-left-width: $tail-width;
            width: 0;
            height: 0;
        }

        @include content-markdown(kit-variables.$gd-color-white, "user");
    }

    &.gd-gen-ai-chat__messages__message--cancelled .gd-gen-ai-chat__messages__content--text {
        color: kit-variables.$gd-color-white;
        background-color: kit-variables.$gd-palette-primary-base-t80;
    }

    &.gd-gen-ai-chat__messages__message--cancelled .gd-gen-ai-chat__messages__content--text::after {
        border-top-color: kit-variables.$gd-palette-primary-base-t80;
    }
}

.gd-gen-ai-chat__messages__message--assistant {
    display: flex;
    flex-direction: row;
    gap: 10px;
    align-items: flex-start;
    margin-bottom: 19px;

    &:last-child {
        margin-bottom: 40px;
    }

    .gd-gen-ai-chat__messages__content {
        .gd-typography--h1,
        .gd-typography--h2,
        .gd-typography--h3,
        .gd-typography--h4 {
            margin-top: 15px;
            margin-bottom: 10px;
        }

        .gd-typography--p {
            margin-top: 5px;
            margin-bottom: 5px;
        }
    }
}

.gd-gen-ai-chat__messages__contents {
    flex: 1;
    padding: 4.5px 0;
    display: flex;
    flex-direction: column;
    gap: 15px;

    // UI kit links have white-space nowrap, which is not desired in the chat
    & .gd-hyperlink,
    & .gd-hyperlink-text {
        white-space: normal;
    }

    // List contents should be styled same as a pargraph
    & li {
        @include typo-mixins.gd-paragraph;
    }

    @include object-types("user");
}

.gd-gen-ai-chat__messages__content--text {
    h1,
    h2,
    h3,
    h4,
    h5,
    h6,
    p,
    ul,
    ol {
        margin: 0 0 8px;
    }

    h1,
    h2,
    h3,
    h4,
    h5,
    h6 {
        margin-top: 12px;
    }

    h1:first-child,
    h2:first-child,
    h3:first-child,
    h4:first-child,
    h5:first-child,
    h6:first-child {
        margin-top: 0;
    }

    ul,
    ol {
        padding-left: 20px;
    }

    li {
        margin-bottom: 4px;

        &:last-child {
            margin-bottom: 0;
        }
    }

    p:last-child,
    ul:last-child,
    ol:last-child {
        margin-bottom: 0;
    }

    table {
        @include typo-mixins.gd-paragraph;
        width: 100%;
        border-collapse: collapse;
        margin: 8px 0;
    }

    th,
    td {
        border: 1px solid kit-variables.$gd-border-color;
        padding: 4px 8px;
        text-align: left;
    }

    th {
        background: kit-variables.$is-focused-background;
        font-weight: 600;
    }
}

.gd-gen-ai-chat__messages__content--error {
    flex: unset;
    padding: 4px 10px;
    border-radius: 3px;
    background: kit-variables.$gd-palette-error-dimmed;
    color: kit-variables.$gd-palette-error-base;
}

.gd-gen-ai-chat__messages__content--changeAnalysis {
    &__button {
        margin-top: 15px;
    }

    &__metric {
        display: inline-flex;
        align-items: baseline;
        flex-direction: row;
        gap: 5px;
        color: kit-variables.$gd-color-object-type-metric;

        svg {
            position: relative;
            bottom: -4px;
        }
    }
}

.gd-gen-ai-chat__messages__content--semantic-search {
    display: grid;

    .gd-gen-ai-chat__messages__semantic-search-header {
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 7px;
        margin: 10px 0 5px 0;
        font-size: 14px;
        font-weight: 400;
        color: var(--gd-palette-complementary-7);
    }

    .gd-ui-kit-treeview {
        border: 1px solid kit-variables.$gd-border-color;
        border-radius: 8px;
        overflow-x: hidden;
        overflow-y: auto;
        overscroll-behavior: contain;
        margin: 0;
    }
}

.gd-gen-ai-chat__messages__message--cancelled .gd-gen-ai-chat__messages__content {
    &,
    & p,
    & a,
    & a:hover,
    & a:active,
    & a:visited {
        color: kit-variables.$gd-color-disabled;
    }
}

.gd-gen-ai-chat__loading {
    animation: gd-gen-ai-message-loading 3s infinite linear;
}

.gd-gen-ai-chat__visualization {
    margin: 10px 0;
    padding: 10px;
    border-radius: 8px;
    position: relative;
    border: 1px solid kit-variables.$is-focused-background;
    background: kit-variables.$gd-chart-background;
    color: variables.$gd-dashboards-content-widget-title-color;

    &--headline {
        height: auto;
        min-height: 50px;

        // Headline value is smaller in chart, looks much better with contrast with other text
        .headline-value {
            font-size: 0.8em;
        }

        .gd-icon-filter::before {
            background: none;
        }
    }

    &--table {
        background: kit-variables.$gd-table-background;
    }

    &__wrapper {
        height: 250px;

        &--headline {
            height: auto;
            min-height: 50px;
        }
    }

    &__drill_overlay {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.01);
    }

    &__title {
        text-align: center;
        margin-top: 15px;
    }

    &__suggestions {
        display: flex;
        flex-wrap: wrap;
        flex-direction: row;
        gap: 10px;

        .gd-ui-kit-button + .gd-ui-kit-button {
            margin-left: 0;
        }
    }

    &__save-dialog {
        width: 565px;

        .gd-dialog-content p {
            margin-bottom: 1em;
        }
    }

    &__buttons {
        position: absolute;
        top: 0.5em;
        right: 0.5em;
        display: flex;
        flex-direction: row;
        gap: 5px;
    }

    &__save button:not(:focus):not(:focus-visible) {
        opacity: 0;
    }

    &__table button:not(:focus):not(:focus-visible) {
        opacity: 0;
    }

    // Show menu button on hover or when menu is open (active class)
    &:hover,
    &.active {
        .gd-gen-ai-chat__visualization__save button {
            opacity: 1;
        }

        .gd-gen-ai-chat__visualization__table button {
            opacity: 1;
        }
    }

    &__menu_overlay {
        padding: 8px 0;
        box-shadow: 0 1px 20px var(--gd-shadow-color-from-theme, rgba(20, 56, 93, 0.2));
        background: kit-variables.$gd-color-white;
        border-radius: 3px;
    }

    &__what-if-group {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }
}

.gd-gen-ai-chat__messages__empty {
    display: flex;
    flex-direction: column;
    align-items: center;

    &__container {
        $root: &;

        width: 100%;
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        max-width: 720px;

        &--fullscreen#{$root}--big-screen {
            margin-top: 40px;
        }
    }

    &__questions {
        $root: &;

        width: 100%;
        display: flex;
        flex-direction: column;
        align-items: flex-start;

        &--fullscreen#{$root}--big-screen {
            flex-direction: row;
            flex-wrap: nowrap;
            gap: 10px;

            & .gd-ui-kit-button {
                margin-top: 1em;

                & + .gd-ui-kit-button {
                    margin-top: 1em;
                }
            }

            & > .gd-ui-kit-button {
                flex: 0 0 auto;
                min-width: 0;

                &:last-child {
                    flex-shrink: 1;
                }
            }

            & > .gd-ui-kit-tooltip__anchor {
                flex: 0 0 auto;
                min-width: 0;
                margin-top: 1em;

                & ~ .gd-ui-kit-tooltip__anchor,
                & ~ .gd-ui-kit-button {
                    margin-top: 1em;
                }

                .gd-ui-kit-button {
                    margin-top: 0;
                }
            }

            & > .gd-ui-kit-button ~ .gd-ui-kit-tooltip__anchor {
                margin-top: 1em;
            }
        }

        & > .gd-ui-kit-tooltip__anchor {
            margin-top: 2em;

            & ~ .gd-ui-kit-tooltip__anchor,
            & ~ .gd-ui-kit-button {
                margin-top: 1em;
            }

            .gd-ui-kit-button {
                margin-top: 0;
            }
        }

        & > .gd-ui-kit-button ~ .gd-ui-kit-tooltip__anchor {
            margin-top: 1em;
        }
    }

    &__h1--accent {
        color: kit-variables.$gd-palette-primary-base;
    }

    & .gd-ui-kit-button {
        margin-top: 2em;

        & + .gd-ui-kit-button {
            margin-top: 1em;
            margin-left: 0;
        }
    }
}

.gd-gen-ai-chat__messages__content .gd-hyperlink {
    display: inline;
}

.gd-gen-ai-chat__visualization__drill-header {
    padding: 4px 10px;
    display: flex;
    text-transform: uppercase;
    color: var(--gd-palette-complementary-5);
    font-size: 10px;
    font-weight: normal;
    margin: 0;
}

@keyframes gd-gen-ai-message-in {
    0% {
        opacity: 0;
        transform: translateY(10px);
    }

    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes gd-gen-ai-message-loading {
    0% {
        opacity: 1;
    }

    50% {
        opacity: 0.3;
    }

    100% {
        opacity: 1;
    }
}

// Thought process dropdown styles
.gd-gen-ai-chat__thought-process-dropdown {
    margin-bottom: 8px;

    .gd-ui-kit-button {
        padding: 0;
        text-decoration: none;
        transition: color 0.2s;
        border: none;
    }

    .gd-ui-kit-button__text {
        color: var(--gd-palette-complementary-7);
    }

    .gd-ui-kit-icon {
        fill: var(--gd-palette-complementary-7);
    }

    &--loading .gd-ui-kit-button__text {
        @include variables.gd-reasoning();
    }

    &__content {
        display: flex;
        flex-direction: row;
        gap: 0;
        border: none;
        border-radius: 0;
        padding: 0 0 0 0;
        background: transparent;
        animation: gd-gen-ai-dropdown-expand 0.2s ease-out;
    }

    &__timeline {
        flex-shrink: 0;
        width: 12px; // Same width as the arrow
        position: relative;

        &::before {
            content: "";
            position: absolute;
            left: 50%; // Center in the timeline column
            transform: translateX(-50%);
            top: 0;
            bottom: 0;
            width: 1px;
            background-color: kit-variables.$gd-border-color;
            opacity: 0.3;
        }
    }

    &__body {
        flex: 1;
    }
}

// Reasoning steps timeline styles
.gd-gen-ai-chat__reasoning {
    margin-top: 5px;
    padding-left: 0;
    position: relative;

    p {
        color: var(--gd-palette-complementary-7);
    }

    &__step {
        display: flex;
        flex-direction: column;
        gap: 0;
        position: relative;
        padding-bottom: 10px; // To be in line with the other messages

        &:last-child {
            padding-bottom: 0;
        }
    }

    &__headline {
        display: flex;
        gap: 0;
        align-items: flex-start;
        padding-top: 5px;
    }

    &__bullet {
        flex-shrink: 0;
        width: 12px;
        height: 6px;
        align-self: center; // Align with text baseline
        position: relative;
        z-index: 1; // Ensure bullet appears above the line

        // Bullet circle
        &::before {
            content: "";
            position: absolute;
            left: 50%;
            transform: translateX(-(3px + 12px)); // Move to the center of the line (half the size of the bullet + gap)
            width: 6px;
            height: 6px;
            border-radius: 50%;
            background-color: var(--gd-palette-complementary-7);
            box-shadow: 0 0 0 4px kit-variables.$gd-color-light; // break the line
        }
    }

    &__content {
        flex: 1;
        padding-top: 0;

        // Remove default paragraph margins
        p {
            padding: 0 0 0 0;
            margin: 0;
        }
    }

    &__title {
        margin-bottom: 0;
        margin-top: 0;

        display: inline-block;

        p {
            font-weight: bold;
        }
    }

    &__thoughts {
        margin: 0 0 0 12px;
        padding-left: 0;
        padding-top: 10px;
        display: flex;
        flex-direction: column;
        gap: 10px;

        p {
            margin: 0;
        }
    }
}

@keyframes gd-gen-ai-dropdown-expand {
    0% {
        opacity: 0;
        transform: translateY(-8px);
    }

    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

// Feedback Popup Content Styles (header, footer, and container now handled by UiPopover)
.gd-gen-ai-feedback-popup {
    &__body {
        display: flex;
        flex-direction: column;
        gap: 10px;
        width: 100%;
    }

    &__legend {
        color: var(--gd-palette-complementary-7);
        line-height: 21px;
        margin-bottom: 10px;
    }

    &__section {
        display: flex;
        flex-direction: column;

        fieldset {
            border: none;
            margin: 0;
            padding: 0;
        }
    }

    &__checkboxes {
        display: flex;
        flex-direction: column;
        gap: 10px;

        .gd-label {
            color: var(--gd-palette-complementary-8);
            line-height: 19px;
        }
    }

    &__textarea {
        resize: vertical;
        min-height: 92px;
        width: calc(100% - 4px);
        font-family: "Avenir", sans-serif;
        font-size: 14px;
        line-height: 22px;
        border-radius: 3px;
        border: 1px solid var(--gd-palette-complementary-4);
        background: var(--gd-palette-complementary-0);
        box-shadow: 0 1px 2px 0 rgba(31, 53, 74, 0.15) inset;

        &::placeholder {
            color: var(--gd-palette-complementary-5, #b0beca);
        }

        .gd-editable-label-inner {
            padding: 3px 4px;
            width: calc(100% - 6px);
        }

        textarea {
            margin: -3px -5px;
            min-height: 86px;
            padding: 3px 4px;
            width: 100%;
        }
    }
}

//CONVERSATIONS

@keyframes pulsate {
    0% {
        background-color: kit-variables.$gd-color-state-blank;
    }
    50% {
        background-color: kit-variables.$gd-color-white;
    }
    100% {
        background-color: kit-variables.$gd-color-state-blank;
    }
}

@keyframes pulsate-opacity {
    0% {
        opacity: 1;
    }
    50% {
        opacity: 0;
    }
    100% {
        opacity: 1;
    }
}

.gd-gen-ai-chat__messages__conversation-group {
    $root: &;
    font-family: kit-variables.$gd-font-primary;

    &--user {
        //User group
    }

    &--assistant {
        //Assistant group

        &:last-child {
            margin-bottom: 40px;
        }

        &:hover .gd-gen-ai-chat__conversation__item__feedback {
            svg {
                opacity: 1;
            }
        }
    }

    &--reasoning {
        margin-bottom: -15px;

        p:not(:last-child) {
            margin-bottom: 10px;
        }
    }
    &--reasoning#{$root}--expanded {
        margin-bottom: 0;
    }

    &--error {
        //Error group
        border-radius: 3px;
        flex: unset;
        padding: 4px 10px;
        background: kit-variables.$gd-palette-error-dimmed;
        color: kit-variables.$gd-palette-error-base;

        p {
            color: kit-variables.$gd-palette-error-base;
            margin: 0 0 5px 0;
            padding: 0;
        }
        p:last-child {
            margin-bottom: 0;
        }

        &:last-child {
            margin-bottom: 40px;
        }
    }

    &--system {
        margin: 18px 0;
    }

    // Reasoning header
    &--header {
        display: flex;
        align-items: center;

        .gd-ui-kit-button {
            padding: 0;
            text-decoration: none;
            transition: color 0.2s;
            border: none;
        }

        .gd-ui-kit-button__text {
            @include variables.gd-reasoning();
        }

        &--completed .gd-ui-kit-button__text {
            background: none;
            animation: none;
            background-clip: initial;
            -webkit-text-fill-color: initial;
        }

        &--duration {
            font-size: 0.8rem;
            line-height: 22px;
            color: kit-variables.$gd-color-state-blank;
            margin-left: 10px;
        }

        &--thinking {
            display: flex;
            align-items: center;
            color: kit-variables.$gd-color-link;
            font-size: 14px;
            font-style: normal;
            font-weight: 400;
            line-height: 22px;
        }
    }

    // Reasoning content
    &--content .gd-gen-ai-chat__messages__conversation {
        position: relative;
        padding-left: 15px;

        &::before {
            content: "";
            position: absolute;
            left: 5px;
            top: 0;
            bottom: 0;
            width: 1px;
            background-color: kit-variables.$gd-color-state-blank;
            opacity: 0.3;
        }

        & .gd-gen-ai-chat__icon {
            display: block;

            .gd-gen-ai-chat__icon__point {
                position: absolute;
                left: 1px;
                top: 9px;
                width: 9px;
                height: 9px;
                border-radius: 50%;
                background-color: kit-variables.$gd-color-state-blank;
                border-color: kit-variables.$gd-color-white;
                border-style: solid;
                border-width: 2px;
                box-sizing: border-box;
            }

            .gd-gen-ai-chat__icon__special {
                display: flex;
                position: absolute;
                left: 0;
                top: 9px;
                width: 12px;
                height: 12px;
                padding: 0;
                border-radius: 50%;
                background-color: kit-variables.$gd-color-white;
                box-sizing: border-box;
            }
        }

        &--isLast .gd-gen-ai-chat__icon .gd-gen-ai-chat__icon__point {
            animation: pulsate 1s infinite ease-in-out;
        }

        &--isLast .gd-gen-ai-chat__icon .gd-gen-ai-chat__icon__special {
            animation: pulsate-opacity 1s infinite ease-in-out;
        }
    }
}

.gd-gen-ai-chat__messages__conversation {
    $root: &;

    display: flex;
    flex-direction: column;
    line-height: normal;
    font-family: kit-variables.$gd-font-primary;

    &--user {
        justify-content: flex-end;

        .gd-gen-ai-chat__conversation__item__content--text {
            $tail-height: 7px;
            $tail-width: 10px;

            max-width: 80%;
            background-color: kit-variables.$gd-palette-primary-base;
            border-radius: 3px 3px 0 3px;
            padding: 4.5px 12px;
            position: relative;
            align-self: flex-end;
            margin-bottom: 15px;
            animation: gd-gen-ai-message-in 0.3s ease-out;

            &::after {
                content: "";
                position: absolute;
                bottom: -$tail-height;
                right: 0;
                border: 0 solid transparent;
                border-top: $tail-height solid kit-variables.$gd-palette-primary-base;
                border-left-width: $tail-width;
                width: 0;
                height: 0;
            }

            @include content-markdown(kit-variables.$gd-color-white, "user");
        }

        @include object-types("user");
    }

    &--assistant {
        justify-content: flex-start;
        color: kit-variables.$gd-color-text;

        .gd-gen-ai-chat__conversation__item__content--text {
            align-items: flex-start;

            @include content-markdown(kit-variables.$gd-color-text, "assistant");
        }

        @include object-types("assistant");
    }

    &--toolCall {
        background: transparent;
    }

    &--cancelled .gd-gen-ai-chat__conversation__item__content--text {
        color: kit-variables.$gd-color-white;
        background-color: kit-variables.$gd-palette-primary-base-t80;

        &::after {
            border-top-color: kit-variables.$gd-palette-primary-base-t80;
        }
    }

    // By default, icon must be hidden
    .gd-gen-ai-chat__icon {
        display: none;
    }
}

.gd-gen-ai-chat__conversation__item__content {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 4.5px 0;

    // UI kit links have white-space nowrap, which is not desired in the chat
    & .gd-hyperlink,
    & .gd-hyperlink-text {
        white-space: normal;
    }

    // List contents should be styled same as a pargraph
    & li {
        @include typo-mixins.gd-paragraph;
    }

    // Tool call content
    &--toolCall {
        code {
            display: inline-block;
            padding: 0 4px;
            border-radius: 4px;
            font-size: 12px;
            background-color: kit-variables.$gd-border-color;
        }
    }

    &--reasoning {
        word-break: break-word;
        padding-bottom: 10px;
    }

    &--search {
        display: grid;

        .gd-gen-ai-chat__conversation__item__content-search-header {
            display: flex;
            flex-direction: row;
            align-items: center;
            gap: 7px;
            margin: 10px 0 5px 0;
            font-size: 14px;
            font-weight: 400;
            color: kit-variables.$gd-color-link;
        }

        .gd-ui-kit-treeview {
            border: 1px solid kit-variables.$gd-border-color;
            border-radius: 8px;
            overflow-x: hidden;
            overflow-y: auto;
            overscroll-behavior: contain;
            margin: 0;
        }
    }

    &--alertProposal,
    &--dashboard {
        display: grid;

        .gd-gen-ai-chat__conversation__item__content-alertProposal-header,
        .gd-gen-ai-chat__conversation__item__content-dashboard-header {
            display: flex;
            flex-direction: row;
            align-items: center;
            gap: 7px;
            margin: 10px 0 5px 0;
            font-size: 14px;
            font-weight: 400;
            color: kit-variables.$gd-color-link;
        }

        .gd-gen-ai-chat__conversation__item__content-alertProposal-subheader {
            display: flex;
            flex-direction: row;
            align-items: center;
            gap: 7px;
            margin: 10px 0 5px 0;
            font-size: 14px;
            font-weight: 400;
            color: kit-variables.$gd-color-link;
        }

        .gd-gen-ai-chat__conversation__item__content-alertProposal-frame,
        .gd-gen-ai-chat__conversation__item__content-dashboard-frame {
            display: flex;
            max-height: 500px;
            padding: 10px;
            flex-direction: column;
            align-items: flex-start;
            align-self: stretch;
            border-radius: 8px;
            border: 1px solid kit-variables.$gd-border-color;
            background: kit-variables.$gd-color-white;
            overflow-y: auto;
            overscroll-behavior: auto;

            ul {
                padding: 0 0 0 20px;
                margin: 0;
            }

            .gd-gen-ai-chat__conversation__item__content-alertProposal-item-title,
            .gd-gen-ai-chat__conversation__item__content-dashboard-item-title {
                display: inline-block;
                margin-right: 5px;
            }

            .gd-gen-ai-chat__conversation__item__content-alertProposal-item-description,
            .gd-gen-ai-chat__conversation__item__content-dashboard-item-description {
                display: inline;

                p {
                    display: inline;
                }

                &.gd-gen-ai-chat__conversation__item__content-alertProposal-item-bold p,
                &.gd-gen-ai-chat__conversation__item__content-dashboard-item-bold p {
                    font-weight: bold;
                }

                code {
                    background: kit-variables.$is-focused-background;
                    padding: 2px 4px;
                    border-radius: 4px;
                }
            }

            .gd-gen-ai-chat__conversation__item__content-alertProposal-item-format {
                margin-left: 5px;
                display: inline;
                color: kit-variables.$gd-color-state-blank;
            }

            .gd-gen-ai-chat__conversation__item__content-alertProposal-item-buttons,
            .gd-gen-ai-chat__conversation__item__content-dashboard-item-buttons {
                display: flex;
                align-items: center;
                justify-content: flex-end;
                width: 100%;
            }
        }

        .gd-gen-ai-chat__conversation__item__content-alertProposal-condition {
            display: flex;
            flex-direction: row;
            gap: 5px;
            align-items: center;
            align-self: center;

            .alertProposal-operand-number {
                font-weight: bold;
            }
        }

        .gd-gen-ai-chat__conversation__item__content-alertProposal-anomaly {
            display: block;
            padding: 5px 15px 0 15px;
            text-align: center;

            .alertProposal-operand {
                display: inline-block;
            }
        }
    }

    &--kda {
        &__button {
            margin-top: 15px;
            display: flex;
            justify-content: flex-end;
        }
    }

    &--error {
        display: flex;
        flex-direction: column;
        padding: 0;

        .gd-gen-ai-chat__error-info {
            display: flex;
            flex-direction: row;
            align-items: stretch;
            justify-content: flex-start;
            gap: 7px;
        }

        .gd-gen-ai-chat__error-details {
            border-top: 1px solid
                color.mix(kit-variables.$gd-color-negative, kit-variables.$default-gd-color-text-light, 30%);
            margin: 0 -10px;
            padding: 5px 12px 0 12px;

            pre {
                font-size: 12px;
                overflow: auto;
                overscroll-behavior: auto;
            }
        }

        .gd-gen-ai-chat__show-more {
            margin-left: 5px;
        }

        .gd-gen-ai-chat__content {
            display: flex;
            align-items: center;
        }

        button {
            color: kit-variables.$gd-palette-error-base;
        }
    }

    &--visualization {
        position: relative;
    }
}

.gd-gen-ai-chat-clarifying-questions {
    $block: ".gd-gen-ai-chat-clarifying-questions";

    border-radius: 8px;
    border: 1px solid var(--gd-palette-complementary-3);
    background: var(--gd-palette-complementary-0, #fff);
    padding: 5px 10px 10px 10px;
    display: flex;
    flex-direction: column;
    align-items: stretch;

    &:focus-visible {
        outline: none;

        #{$block}__option--focused {
            border-radius: 3px;
            outline: 2px solid var(--gd-palette-primary-base);

            #{$block}__option-select {
                display: flex;
            }
        }
    }

    &__header {
        color: var(--gd-palette-complementary-8);
        font-size: 14px;
        font-style: normal;
        font-weight: 700;
        line-height: 23px; /* 164.286% */
        margin-bottom: 5px;
    }

    &__option {
        display: flex;
        position: relative;
        border-radius: 3px;
        padding: 10px 32px 10px 5px;
        align-items: flex-start;
        gap: 10px;
        margin-bottom: 3px;

        &:hover {
            cursor: pointer;
            border-radius: 3px;
            background: var(--gd-palette-complementary-2);

            #{$block}__option-select {
                display: flex;
            }
        }

        &-index {
            border-radius: 3px;
            background: var(--gd-palette-complementary-2);
            display: flex;
            min-width: 17px;
            padding: 1px var(--spacing-2px);
            justify-content: center;
            align-items: center;
            gap: 2px;
        }

        &-content {
            flex-grow: 1;
        }

        &-select {
            align-items: center;
            height: 100%;
            position: absolute;
            right: 10px;
            top: 0;
            bottom: 0;
            display: none;
        }

        &--focused {
            border-radius: 3px;
            outline: 2px solid var(--gd-palette-primary-base);

            #{$block}__option-select {
                display: flex;
            }
        }
    }

    &__footer {
        display: flex;
        flex-direction: row;
        justify-content: flex-end;
        align-items: center;
        width: 100%;
        gap: 10px;
        margin-top: 10px;
    }
}

.gd-gen-ai-chat__conversation__item__feedback {
    display: flex;
    flex-direction: row;

    svg {
        opacity: 0;
        transition: opacity 0.2s;
    }

    &:focus-within,
    &--assigned,
    &--last {
        svg {
            opacity: 1;
        }
    }
}

// Row holding the feedback thumbs plus any other per-message actions (e.g. the Interaction
// Intelligence trigger). Not nested under .conversation__item__feedback, since those actions
// aren't feedback and shouldn't share its hover/focus reveal behavior.
.gd-gen-ai-chat__conversation__item__actions {
    display: flex;
    align-items: center;
    // No gap: each icon button is a fixed-size box (like .conversation__item__feedback's
    // thumbs), so they should sit edge-to-edge, not with extra space between groups.
}

.gd-gen-ai-chat__conversation__visualization {
    margin: 10px 0;
    padding: 10px;
    border-radius: 8px;
    position: relative;
    border: 1px solid kit-variables.$is-focused-background;
    background: kit-variables.$gd-chart-background;
    color: variables.$gd-dashboards-content-widget-title-color;

    &--headline {
        height: auto;
        min-height: 50px;

        // Headline value is smaller in chart, looks much better with contrast with other text
        .headline-value {
            font-size: 0.8em;
        }

        .gd-icon-filter::before {
            background: none;
        }
    }

    &--table {
        background: kit-variables.$gd-table-background;
    }

    &__wrapper {
        height: 250px;

        &--headline {
            height: auto;
            min-height: 50px;
        }
    }

    &__title {
        text-align: center;
        margin-top: 15px;
    }

    &__buttons {
        position: absolute;
        top: 0.5em;
        right: 0.5em;
        display: flex;
        flex-direction: row;
        gap: 5px;

        &.active {
            .gd-gen-ai-chat__conversation__visualization__save button:not(:focus):not(:focus-visible) {
                opacity: 1;
            }
        }
    }

    &__suggestions {
        display: flex;
        flex-wrap: wrap;
        flex-direction: row;
        margin-top: 15px;
        gap: 10px;

        .gd-ui-kit-button + .gd-ui-kit-button {
            margin-left: 0;
        }
    }

    &__followUp {
        display: flex;
        margin-bottom: 5px;
    }

    &__drill_overlay {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.01);
    }

    //BUTTONS
    &__save button:not(:focus):not(:focus-visible) {
        opacity: 0;
    }

    &__table button:not(:focus):not(:focus-visible) {
        opacity: 0;
    }

    // Show menu button on hover or when menu is open (active class)
    &:hover {
        .gd-gen-ai-chat__conversation__visualization__save button {
            opacity: 1;
        }

        .gd-gen-ai-chat__conversation__visualization__table button {
            opacity: 1;
        }
    }

    // Menu overlay styles
    &__menu_overlay {
        padding: 8px 0;
        box-shadow: 0 1px 20px var(--gd-shadow-color-from-theme, rgba(20, 56, 93, 0.2));
        background: kit-variables.$gd-color-white;
        border-radius: 3px;
    }
}
