:host {
    display: block;
}

.biel-message {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    width: 100%;
}

.biel-message--user {
    align-items: flex-end;
}

.biel-message__label {
    font-size: var(--biel-message-label-font-size);
    color: var(--biel-text-color);
    margin-bottom: 6px;
    font-weight: 500;
}

.biel-message__bubble {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: var(--biel-message-font-size);
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.biel-message--user .biel-message__bubble {
    background-color: var(--biel-message-user-bg-color);
    color: var(--biel-message-user-text-color);
}

.biel-message--ai .biel-message__bubble {
    background-color: var(--biel-message-biel-bg-color);
    color: var(--biel-message-biel-text-color);
}

.biel-message--no-avatar {
    max-width: 100%;
}

.biel-message--no-avatar .biel-message__content {
    max-width: 100%;
}

.biel-message__content * {
    margin: 0;
}

.biel-message__content hr {
    display: none;
}

.biel-message__content ul,
.biel-message__content ol {
    padding-inline-start: 0;
    margin-left: 20px;
}

.biel-message__content>div>ul,
.biel-message__content>div>ol {
    padding: 0;
}

.biel-message__content>div:not(:first-child),
.biel-message__content li,
.biel-message__content p:not(:first-child),
.biel-message__content h1,
.biel-message__content h2,
.biel-message__content h3,
.biel-message__content h4,
.biel-message__content h5,
.biel-message__content h6 {
    margin-top: 10px;
}
.biel-message__content h1 {
    font-size: var(--biel-message-h1-font-size);
}

.biel-message__content h2 {
    font-size: var(--biel-message-h2-font-size);
}

.biel-message__content h3 {
    font-size: var(--biel-message-h3-font-size);
}

.biel-message__content h4 {
    font-size: var(--biel-message-h4-font-size);
}

.biel-message__content h5 {
    font-size: var(--biel-message-h5-font-size);
}

.biel-message__content h6 {
    font-size: var(--biel-message-h6-font-size);
}

.biel-message__content pre {
    margin: 10px 0;
}

.biel-message__content a {
    color: var(--biel-message-link-color);
    text-decoration: none;
}

@media (hover: hover) {
    .biel-message__content a:hover {
        text-decoration: underline;
    }
}

/* Inline action chip: an <action name="x"/> tag the LLM placed in the answer,
   resolved to a button-styled link rendered in place. */
.biel-message__content a.biel-inline-action {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: var(--biel-radius-sm);
    background: var(--biel-action-bg-color, var(--biel-message-source-bg-color));
    color: var(--biel-action-text-color, var(--biel-message-source-text-color));
    text-decoration: none;
    font-size: var(--biel-action-font-size, var(--biel-message-source-font-size));
    line-height: normal;
    vertical-align: middle;
}

.biel-message__content a.biel-inline-action::after {
    content: '→';
    font-size: 0.9em;
}

@media (hover: hover) {
    .biel-message__content a.biel-inline-action:hover {
        background: var(--biel-action-bg-hover-color, var(--biel-message-source-bg-hover-color));
        color: var(--biel-action-text-hover-color, var(--biel-message-source-text-color));
        text-decoration: none;
    }
}

.biel-message__avatar {
    display: none;
}

.biel-message__content {
    width: 100%;
    display: flex;
    flex-direction: column;
    line-height: 1.5;
}


.biel-table-container {
    margin: 10px 0;
    overflow-x: auto;
    background-color: var(--biel-table-bg-color);
    border-radius: var(--biel-radius-sm);
}

.biel-table-container table {
    width: 100%;
    border-collapse: collapse;
    overflow: hidden;
    color: var(--biel-table-content-text-color);
}

.biel-table-container th,
.biel-table-container td {
    padding: 8px;
    border: 1px solid #303030;
}

.biel-table-container th {
    background-color: var(--biel-table-th-bg-color);
}

.biel-table-container::-webkit-scrollbar {
    height: 8px;
}

.biel-table-container::-webkit-scrollbar-thumb:horizontal {
    background-color: var(--biel-chat-scrollbar-color);
    border-radius: 10px;
    border: 3px solid transparent;
}

.biel-table-container::-webkit-scrollbar-thumb:hover {
    background-color: var(--biel-chat-scrollbar-hover-color);
}

.biel-message__content code {
    background-color: var(--biel-message-code-inline-bg-color);
    padding: 2px 4px;
    border-radius: var(--biel-message-code-inline-border-radius);
    font-size: var(--biel-message-code-font-size);
    color: var(--biel-message-code-inline-text-color);
}

.biel-message__content pre code {
    color: initial;
    background-color: var(--biel-message-code-bg-color);
}

/* --- Answer footer -------------------------------------------------------- */
/* One compact row at the end of a completed AI answer: sources toggle on the
   left, icon actions (copy + thumbs) on the right. Spacing alone separates it
   from the answer — no rule, so the answer and its footer read as one block. */
.biel-message__footer {
    margin-top: 12px;
}

.biel-message__footer-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: nowrap;
}

.biel-message__footer-left {
    min-width: 0;
    display: flex;
    align-items: center;
}

.biel-message__footer-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.biel-message__sources-toggle {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    max-width: 100%;
    background-color: var(--biel-source-toggle-bg);
    color: var(--biel-message-source-text-color);
    border: 1px solid var(--biel-source-toggle-border);
    padding: 6px 10px;
    border-radius: var(--biel-input-border-radius);
    cursor: pointer;
    font-size: var(--biel-control-font-size);
    font-family: inherit;
    line-height: 1;
    white-space: nowrap;
    transition: all 0.2s ease;
}

/* Same hover as the biel-input-option trigger: surface tints and the border
   darkens together. */
@media (hover: hover) {
    .biel-message__sources-toggle:hover {
        background-color: var(--biel-input-options-button-hover-bg-color);
        border-color: var(--biel-input-options-button-hover-border-color);
    }
}

.biel-message__sources-toggle:focus {
    outline: none;
    border-color: var(--biel-input-options-button-focus-border-color);
}

.biel-message__chevron {
    flex-shrink: 0;
    transition: transform 0.2s ease;
}

.biel-message__chevron--up {
    transform: rotate(180deg);
}

/* Ghost icon button: transparent at rest, ~36px hit area around a small icon
   whose visual size is unchanged. */
.biel-message__action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: var(--biel-radius-sm);
    color: var(--biel-footer-action-color);
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease, opacity 0.15s ease, transform 0.15s ease;
}

@media (hover: hover) {
    .biel-message__action:hover {
        background-color: var(--biel-footer-action-hover-bg);
        color: var(--biel-message-source-text-color);
    }
}

/* Paired with :hover so the tint survives the pointer resting on the button
   after the click. */
.biel-message__action--copied,
.biel-message__action--copied:hover {
    color: var(--biel-footer-action-copied-color);
}

.biel-message__thumb--selected,
.biel-message__thumb--selected:hover {
    background-color: var(--biel-footer-thumb-selected-bg);
    color: var(--biel-footer-thumb-selected-color);
    animation: biel-thumb-pop 0.15s ease;
}

.biel-message__thumb--muted {
    opacity: 0.35;
}

@keyframes biel-thumb-pop {
    0% {
        transform: scale(1.15);
    }

    100% {
        transform: scale(1);
    }
}

@media (prefers-reduced-motion: reduce) {
    .biel-message__thumb--selected,
    .biel-message__thumb--selected:hover {
        animation: none;
    }

    .biel-message__chevron {
        transition: none;
    }
}

/* Expanded sources: document-icon cards. 2-up when the panel is wide enough,
   1-up when narrow (driven by the panel's own width, not the viewport). */
.biel-message__sources-panel {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 8px;
    margin-top: 10px;
}

.biel-message__source-card {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
    background-color: var(--biel-source-card-bg);
    border: 1px solid var(--biel-source-card-border);
    border-radius: var(--biel-input-border-radius);
    text-decoration: none;
    color: var(--biel-source-card-title-color);
    overflow: hidden;
    transition: all 0.2s ease;
}

/* Same hover as every other control: surface tint + border darken. No accent
   border or shadow — nothing else in the widget lifts on hover. */
@media (hover: hover) {
    .biel-message__source-card:hover {
        background-color: var(--biel-input-options-button-hover-bg-color);
        border-color: var(--biel-input-options-button-hover-border-color);
    }
}

.biel-message__source-icon {
    flex-shrink: 0;
    margin-top: 2px;
    color: var(--biel-source-card-icon-color);
    opacity: 0.6;
}

.biel-message__source-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.biel-message__source-title {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-size: var(--biel-text-font-size);
    line-height: 1.35;
}

.biel-message__source-host {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: var(--biel-text-sm-font-size);
    color: var(--biel-source-card-host-color);
}