.main-content.conversation-active {
    justify-content: flex-end !important;
    height: 100dvh;
    min-height: 0;
    padding-bottom: 24px;
    --chat-bottom-reserve: 24px;
}

.main-content.conversation-active:has(.input-shell.has-multiline:not(.has-file)) {
    --chat-bottom-reserve: 64px;
}

.main-content.conversation-active:has(.input-shell.has-file) {
    --chat-bottom-reserve: 72px;
}

.main-content.conversation-active:has(.input-shell.has-file.has-multiline) {
    --chat-bottom-reserve: 120px;
}

.main-content.conversation-active .input-shell::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: -42px;
    height: 42px;
    border-radius: 30px 30px 0 0;
    background: var(--hero-fade);
    pointer-events: none;
    z-index: 0;
}

.main-content.conversation-active .hero-video,
.main-content.conversation-active > h1,
.main-content.conversation-active .input-suggestions {
    display: none;
}

.chat-panel {
    position: relative;
    width: min(800px, 100%);
    flex: 1 1 auto;
    min-height: 0;
    margin: 0 auto 18px;
    padding-top: 36px;
    display: flex;
    flex-direction: column;
}

.chat-panel[hidden] {
    display: none;
}

.chat-thread {
    flex: 1 1 auto;
    min-height: 0;
    height: auto;
    max-height: none;
    display: flex;
    flex-direction: column;
    gap: 26px;
    overflow-y: auto;
    padding: 4px 6px var(--chat-bottom-reserve);
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.chat-thread::-webkit-scrollbar {
    display: none;
}

.chat-scroll-bottom {
    position: absolute;
    left: 50%;
    bottom: -7px;
    width: 36px;
    height: 36px;
    border: 1px solid var(--border-color);
    border-radius: 50%;
    background: var(--bg-card);
    color: var(--text-strong);
    display: grid;
    place-items: center;
    transform: translateX(-50%);
    box-shadow: var(--shadow-soft);
    cursor: pointer;
    z-index: 10070;
}

.chat-scroll-bottom[hidden] {
    display: none;
}

.chat-scroll-bottom:hover {
    background: var(--bg-card-hover);
}

.chat-scroll-bottom i {
    font-size: 18px;
    line-height: 1;
    pointer-events: none;
}

.chat-message {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    width: 100%;
}

.chat-message.user {
    justify-content: flex-end;
}

.chat-message.assistant {
    justify-content: flex-start;
}

.chat-message.pending {
    opacity: 0.95;
}

.chat-avatar {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    background: var(--bg-elevated);
    border: 1px solid var(--border-soft);
    color: var(--accent-color);
    overflow: hidden;
}

.chat-avatar-logo {
    width: 22px;
    height: 22px;
    object-fit: contain;
}

.chat-message.user .chat-avatar {
    display: none;
}

.chat-bubble-stack {
    max-width: min(640px, 92%);
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: flex-start;
}

.chat-message.user .chat-bubble-stack {
    align-items: flex-end;
}

.chat-attachments {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: flex-start;
}

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

.chat-downloads {
    width: 100%;
    align-items: stretch;
}

.chat-file-card {
    width: min(240px, 100%);
    min-height: 58px;
    padding: 8px 10px;
    border-radius: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: inherit;
    display: flex;
    align-items: center;
    gap: 12px;
    text-align: left;
    transition: background 0.16s ease, border-color 0.16s ease;
}

button.chat-file-card {
    appearance: none;
    cursor: pointer;
}

.chat-file-card:hover {
    background: var(--bg-card-hover);
    border-color: var(--accent-border);
}

.chat-output-file {
    width: min(280px, 100%);
    min-height: 66px;
    position: relative;
    padding: 10px 10px 12px 12px;
    color: inherit;
    text-decoration: none;
    cursor: default;
    transition: background 0.16s ease, border-color 0.16s ease;
}

.chat-output-file:hover,
.chat-output-file:focus-within {
    background: var(--bg-card-hover);
    border-color: var(--accent-border);
    color: inherit;
    outline: none;
}

.chat-output-file[aria-disabled="true"] {
    cursor: default;
    opacity: 0.7;
}

.chat-output-file.download-unavailable {
    border-color: var(--border-soft);
    background: var(--bg-card);
}

.chat-file-unavailable {
    width: fit-content;
    max-width: 100%;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 7px;
    border-radius: 8px;
    background: var(--bg-card-hover);
    color: var(--text-muted);
    font-size: 0.76rem;
    line-height: 1;
}

.chat-file-bundle {
    width: min(280px, 100%);
    min-height: 58px;
    padding: 8px 12px 8px 10px;
    border-radius: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-strong);
    display: flex;
    align-items: center;
    gap: 12px;
    text-align: left;
    cursor: default;
}

.chat-file-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--icon-tile-bg);
    color: var(--icon-tile-text);
    display: grid;
    place-items: center;
    flex: 0 0 auto;
}

.chat-output-file .chat-file-copy {
    flex: 1 1 auto;
    align-items: flex-start;
    padding-right: 8px;
}

.chat-output-file .chat-file-name {
    max-width: 100%;
    padding-right: 4px;
    text-align: left;
}

.chat-output-file .chat-file-meta {
    text-align: left;
}

.chat-output-file {
    position: relative;
}

.chat-file-card.preview-swap .chat-file-icon {
    position: relative;
    overflow: hidden;
}

.chat-file-card.preview-swap .chat-file-type-icon {
    transition: opacity 0.16s ease, transform 0.16s ease;
}

.chat-file-card.preview-swap:hover .chat-file-type-icon,
.chat-file-card.preview-swap:focus-within .chat-file-type-icon {
    opacity: 0;
    transform: scale(0.92);
}

.chat-output-file .chat-file-copy {
    flex: 1 1 auto;
    align-items: flex-start;
    padding-right: 8px;
}

.chat-output-file .chat-file-name {
    max-width: 100%;
    padding-right: 4px;
    text-align: left;
}

.chat-file-meta-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 6px;
}

.chat-output-file .chat-file-meta {
    text-align: left;
}

.chat-output-file .chat-file-badge {
    align-self: center;
    margin: 0;
}

.chat-file-preview-trigger {
    width: 36px;
    height: 36px;
    border: 1px solid var(--border-soft);
    border-radius: 10px;
    background: var(--bg-card);
    color: var(--text-color);
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.16s ease, background 0.16s ease;
}

.chat-file-card.preview-swap .chat-file-icon .chat-file-preview-trigger {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    border-radius: inherit;
    background: transparent;
    color: inherit;
}

.chat-file-card.preview-swap:hover .chat-file-icon .chat-file-preview-trigger,
.chat-file-card.preview-swap:focus-within .chat-file-icon .chat-file-preview-trigger,
.chat-file-preview-trigger:focus-visible {
    opacity: 1;
}

.chat-file-preview-trigger:hover {
    background: var(--button-hover);
}

.chat-output-action {
    width: 38px;
    height: 38px;
    border: 1px solid var(--border-soft);
    border-radius: 10px;
    background: var(--accent-soft);
    color: var(--accent-strong);
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    cursor: pointer;
}

.chat-output-action:hover,
.chat-output-action:focus-visible {
    background: var(--accent-color);
    color: var(--text-inverse);
    outline: none;
}

.chat-output-action:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

.chat-output-action[aria-disabled="true"] {
    cursor: not-allowed;
    opacity: 0.55;
}

.chat-output-action[aria-disabled="true"]:hover,
.chat-output-action[aria-disabled="true"]:focus-visible {
    background: var(--accent-soft);
    color: var(--accent-strong);
    outline: none;
}

.toolbuddy-tooltip {
    --bs-tooltip-bg: var(--text-strong);
    --bs-tooltip-color: var(--bg-color);
    --bs-tooltip-opacity: 1;
    --bs-tooltip-border-radius: 8px;
    --bs-tooltip-padding-x: 10px;
    --bs-tooltip-padding-y: 7px;
    --bs-tooltip-max-width: 260px;
    font-size: 0.78rem;
    line-height: 1.25;
}

.chat-download-actions {
    width: 100%;
    display: flex;
    justify-content: flex-start;
    gap: 8px;
    padding-top: 2px;
}

.chat-output-copy {
    background: var(--bg-card);
    color: var(--text-strong);
}

.chat-file-copy {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
    line-height: 1.15;
}

.chat-file-name-row {
    display: flex;
    align-items: center;
    gap: 7px;
    min-width: 0;
}

.chat-file-name {
    min-width: 0;
    color: var(--text-strong);
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-file-badge {
    flex: 0 0 auto;
    max-width: 42px;
    padding: 2px 5px;
    border-radius: 5px;
    background: var(--accent-soft);
    color: var(--accent-strong);
    border: 1px solid var(--accent-border);
    font-size: 9px;
    font-weight: 800;
    line-height: 1.2;
}

.chat-file-meta {
    color: var(--text-muted);
    font-size: 12px;
}

.chat-file-bundle-open {
    width: 34px;
    height: 34px;
    border: 1px solid var(--border-soft);
    border-radius: 10px;
    background: var(--accent-soft);
    color: var(--accent-strong);
    font-size: 15px;
    display: grid;
    place-items: center;
    margin-left: auto;
    flex: 0 0 auto;
    cursor: pointer;
}

.chat-file-bundle-open:hover,
.chat-file-bundle-open:focus-visible {
    background: var(--accent-color);
    color: var(--text-inverse);
    outline: none;
}

.chat-file-modal {
    position: fixed;
    inset: 0;
    z-index: 21000;
    display: grid;
    place-items: center;
    padding: 24px;
    background: var(--bg-modal-overlay);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s ease;
}

.chat-file-modal.visible {
    opacity: 1;
    pointer-events: auto;
}

.chat-file-dialog {
    width: min(560px, calc(100vw - 40px));
    height: min(560px, calc(100dvh - 48px));
    padding: 18px;
    border-radius: 16px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-elevated);
    color: var(--text-color);
    display: flex;
    flex-direction: column;
    gap: 14px;
    text-align: left;
}

.chat-file-modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.chat-file-modal-header h2 {
    margin: 0 0 4px;
    color: var(--text-color);
    font-size: 18px;
    font-weight: 700;
}

.chat-file-modal-header p {
    margin: 0;
    color: var(--text-muted);
    font-size: 13px;
}

.chat-file-close {
    width: 34px;
    height: 34px;
    border: 1px solid var(--border-color);
    border-radius: 9px;
    background: transparent;
    color: var(--text-color);
    display: grid;
    place-items: center;
    flex: 0 0 auto;
}

.chat-file-close:hover {
    background: var(--button-hover);
}

.chat-file-modal-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 2px 7px 2px 2px;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.chat-file-modal-list.has-top-fade.has-bottom-fade {
    -webkit-mask-image: linear-gradient(
        to bottom,
        transparent 0,
        var(--bg-color) 22px,
        var(--bg-color) calc(100% - 22px),
        transparent 100%
    );
    mask-image: linear-gradient(
        to bottom,
        transparent 0,
        var(--bg-color) 22px,
        var(--bg-color) calc(100% - 22px),
        transparent 100%
    );
}

.chat-file-modal-list.has-top-fade:not(.has-bottom-fade) {
    -webkit-mask-image: linear-gradient(to bottom, transparent 0, var(--bg-color) 22px, var(--bg-color) 100%);
    mask-image: linear-gradient(to bottom, transparent 0, var(--bg-color) 22px, var(--bg-color) 100%);
}

.chat-file-modal-list.has-bottom-fade:not(.has-top-fade) {
    -webkit-mask-image: linear-gradient(to bottom, var(--bg-color) 0, var(--bg-color) calc(100% - 22px), transparent 100%);
    mask-image: linear-gradient(to bottom, var(--bg-color) 0, var(--bg-color) calc(100% - 22px), transparent 100%);
}

.chat-file-modal-list::-webkit-scrollbar {
    display: none;
}

.chat-file-modal-list .chat-file-card {
    width: 100%;
}

.chat-file-modal-list .chat-file-name-row {
    width: 100%;
}

.chat-file-modal-actions {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    flex: 0 0 auto;
}

.chat-file-modal-actions .chat-file-preview-trigger {
    opacity: 1;
}

.chat-image-preview-modal {
    position: fixed;
    inset: 0;
    z-index: 22000;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(15, 23, 42, 0.75);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s ease;
}

.chat-image-preview-modal.visible {
    opacity: 1;
    pointer-events: auto;
}

.chat-image-preview-dialog {
    width: min(92vw, 900px);
    max-height: min(92dvh, 820px);
    border-radius: 18px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-elevated);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 12px;
    transform: translateY(18px);
    opacity: 0;
    transition: opacity 0.18s ease, transform 0.18s ease;
}

.chat-image-preview-modal.visible .chat-image-preview-dialog {
    transform: translateY(0);
    opacity: 1;
}

.chat-image-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px 0;
}

.chat-image-preview-header h2 {
    min-width: 0;
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-image-preview-close {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: transparent;
    display: grid;
    place-items: center;
    cursor: pointer;
}

.chat-image-preview-close:hover {
    background: var(--button-hover);
}

.chat-image-preview-content {
    flex: 1 1 auto;
    min-height: 0;
    display: grid;
    place-items: center;
    padding: 12px;
    background: var(--bg-card);
    overflow: auto;
}

.chat-image-preview-content img {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: calc(min(92dvh, 820px) - 86px);
    object-fit: contain;
    border-radius: 14px;
}

.chat-bubble {
    padding: 12px 15px;
    border-radius: 16px;
    font-size: 15px;
    line-height: 1.55;
    text-align: left;
    overflow-wrap: anywhere;
}

.chat-bubble.typing::after {
    content: "";
    display: inline-block;
    width: 7px;
    height: 1em;
    margin-left: 2px;
    border-radius: 999px;
    background: currentColor;
    vertical-align: -0.12em;
    animation: typing-caret 0.9s steps(2, start) infinite;
}

.chat-pending-bubble {
    min-height: 34px;
    padding: 7px 10px;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--text-muted);
    background: var(--bg-card);
    border: none;
    border-radius: 12px;
    overflow: hidden;
}

.chat-pending-label {
    display: inline-block;
    font-size: 13px;
    font-weight: 600;
    color: transparent;
    -webkit-text-fill-color: transparent;
    background:
        linear-gradient(
            100deg,
            var(--text-muted) 0%,
            var(--text-muted) 34%,
            var(--text-strong) 43%,
            #b8b8b8 50%,
            var(--text-strong) 57%,
            var(--text-muted) 66%,
            var(--text-muted) 100%
        );
    background-size: 280% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    animation: chat-pending-text-scan 1.35s linear infinite;
    /* Temporarily paused text blink:
    animation: chat-pending-pulse 1.2s ease-in-out infinite;
    */
}

@keyframes chat-pending-text-scan {
    0% {
        background-position: 140% 0;
    }
    100% {
        background-position: -140% 0;
    }
}

/*
@keyframes chat-pending-pulse {
    0%, 100% {
        opacity: 0.35;
    }
    50% {
        opacity: 1;
    }
}
*/

@keyframes typing-caret {
    50% {
        opacity: 0;
    }
}

.chat-message.user .chat-bubble {
    color: var(--text-strong);
    background: var(--bg-card-hover);
    border-top-right-radius: 6px;
}

.chat-message.assistant .chat-bubble {
    color: var(--text-color);
    background: transparent;
    padding: 2px 0 0;
}

.chat-bubble.markdown-rendered {
    width: 100%;
}

.chat-bubble.markdown-rendered > :first-child {
    margin-top: 0;
}

.chat-bubble.markdown-rendered > :last-child {
    margin-bottom: 0;
}

.chat-bubble.markdown-rendered h1,
.chat-bubble.markdown-rendered h2,
.chat-bubble.markdown-rendered h3,
.chat-bubble.markdown-rendered h4 {
    color: var(--text-strong);
    line-height: 1.25;
    letter-spacing: 0;
}

.chat-bubble.markdown-rendered h1 {
    margin: 4px 0 12px;
    font-size: 24px;
    font-weight: 780;
}

.chat-bubble.markdown-rendered h2 {
    margin: 18px 0 9px;
    font-size: 19px;
    font-weight: 760;
}

.chat-bubble.markdown-rendered h3 {
    margin: 15px 0 8px;
    font-size: 16px;
    font-weight: 740;
}

.chat-bubble.markdown-rendered h4 {
    margin: 13px 0 7px;
    font-size: 14px;
    font-weight: 730;
}

.chat-bubble.markdown-rendered p {
    margin: 0 0 11px;
}

.chat-bubble.markdown-rendered strong {
    color: var(--text-strong);
    font-weight: 760;
}

.chat-bubble.markdown-rendered em {
    color: var(--text-muted);
}

.chat-bubble.markdown-rendered ul,
.chat-bubble.markdown-rendered ol {
    margin: 8px 0 13px;
    padding-left: 22px;
}

.chat-bubble.markdown-rendered li {
    margin: 5px 0;
    padding-left: 2px;
}

.chat-bubble.markdown-rendered li::marker {
    color: var(--accent-color);
}

.chat-bubble.markdown-rendered blockquote {
    margin: 14px 0;
    padding: 10px 13px;
    border-left: 3px solid var(--accent-color);
    border-radius: 0 10px 10px 0;
    background: var(--accent-soft);
    color: var(--text-muted);
}

.chat-bubble.markdown-rendered code {
    padding: 2px 6px;
    border: 1px solid var(--border-soft);
    border-radius: 6px;
    background: var(--bg-card);
    color: var(--accent-strong);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    font-size: 0.92em;
}

.chat-bubble.markdown-rendered pre {
    margin: 13px 0;
    padding: 13px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--bg-card);
    color: var(--text-color);
    overflow-x: auto;
    white-space: pre;
}

.chat-bubble.markdown-rendered pre code {
    padding: 0;
    border: none;
    border-radius: 0;
    background: transparent;
    color: inherit;
    font-size: 13px;
}

.chat-bubble.markdown-rendered a {
    color: var(--accent-strong);
    text-decoration: none;
    border-bottom: 1px solid var(--accent-border);
}

.chat-bubble.markdown-rendered a:hover {
    border-bottom-color: var(--accent-color);
}

.chat-bubble.markdown-rendered hr {
    margin: 16px 0;
    border: none;
    border-top: 1px solid var(--border-color);
}

.chat-bubble.markdown-rendered table {
    width: 100%;
    margin: 13px 0;
    border-collapse: collapse;
    overflow: hidden;
    border-radius: 10px;
    font-size: 14px;
}

.chat-bubble.markdown-rendered th,
.chat-bubble.markdown-rendered td {
    padding: 9px 10px;
    border: 1px solid var(--border-color);
    text-align: left;
    vertical-align: top;
}

.chat-bubble.markdown-rendered th {
    color: var(--text-strong);
    background: var(--bg-card);
    font-weight: 740;
}

.chat-bubble.markdown-rendered td {
    color: var(--text-color);
}

@media (max-width: 520px) {
    .main-content.conversation-active {
        height: var(--toolbuddy-visual-height, 100dvh);
        padding-bottom: calc(82px + env(safe-area-inset-bottom, 0px));
        --chat-bottom-reserve: 16px;
    }

    .main-content.conversation-active:has(.input-shell.has-file) {
        padding-bottom: calc(160px + env(safe-area-inset-bottom, 0px));
        --chat-bottom-reserve: 16px;
    }

    .main-content.conversation-active:has(.input-shell.has-file.has-multiline) {
        padding-bottom: calc(244px + env(safe-area-inset-bottom, 0px));
        --chat-bottom-reserve: 16px;
    }

    .main-content.conversation-active .input-shell::before {
        top: -70px;
        height: 70px;
    }

    .chat-panel {
        padding-top: 46px;
        margin-bottom: 0;
    }

    .chat-thread {
        max-height: none;
        gap: 20px;
        padding-inline: 0;
    }

    .chat-bubble-stack {
        max-width: 88%;
    }

    .chat-avatar {
        width: 30px;
        height: 30px;
        border-radius: 9px;
    }

    .chat-bubble {
        font-size: 14px;
    }

    .chat-file-bundle {
        width: 100%;
    }

    .chat-file-dialog {
        width: calc(100vw - 28px);
        height: calc(100dvh - 36px);
        padding: 14px;
    }
}
