.topic-chat-section {
    border-top: 1px solid #e5e7eb;
    background: linear-gradient(180deg, #f5f9ff 0%, var(--primary-surface-soft, #d6e4fb) 100%);
}

.topic-chat-card {
    border-radius: 1rem;
    border: 1px solid #dbe3ee;
    background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
}

.topic-chat-shell {
    display: flex;
    flex-direction: column;
}

.topic-chat-header {
    width: 100%;
    border: 1px solid #d6e4fb;
    border-radius: 0.9rem;
    background: linear-gradient(135deg, #f5f9ff 0%, #eef5ff 100%);
    color: #0f172a;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.95rem 1rem;
    text-align: left;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.topic-chat-header:hover {
    border-color: #a8c3ef;
    box-shadow: 0 8px 20px rgba(29, 78, 216, 0.12);
    transform: translateY(-1px);
}

.topic-chat-header-disabled {
    border-color: #cddcee;
    background: linear-gradient(135deg, #f4f7fb 0%, #e9eef6 100%);
}

.topic-chat-header-disabled:hover {
    border-color: #cddcee;
    box-shadow: none;
    transform: none;
}

.topic-chat-header-start {
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.topic-chat-header-icon {
    width: 2.35rem;
    height: 2.35rem;
    border-radius: 0.7rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #1d4ed8;
    background: linear-gradient(145deg, #dbeafe 0%, #eff6ff 100%);
    border: 1px solid #bfdbfe;
    flex: 0 0 auto;
}

.topic-chat-header-copy {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topic-chat-header-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: #0f172a;
    line-height: 1.2;
}

.topic-chat-header-subtitle {
    margin-top: 0.1rem;
    color: #334155;
    font-size: 0.9rem;
    line-height: 1.3;
}

.topic-chat-header-end {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    flex: 0 0 auto;
}

.topic-chat-header-action {
    border-radius: 999px;
    background: #ffffff;
    border: 1px solid #c7dbfb;
    padding: 0.27rem 0.62rem;
    color: #1e3a8a;
    font-size: 0.79rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.topic-chat-header-action-disabled {
    background: #eef2f7;
    border-color: #d8e1ec;
    color: #334155;
    text-transform: none;
    letter-spacing: 0;
}

.topic-chat-header-chevron {
    color: #1e3a8a;
    transition: transform 0.24s ease;
}

#topicChatRoot.is-chat-open .topic-chat-header-chevron {
    transform: rotate(180deg);
}

.topic-chat-panel {
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    transform: translateY(-0.35rem);
    transition: max-height 0.36s ease, opacity 0.22s ease, transform 0.22s ease, margin-top 0.22s ease, padding 0.22s ease, border-color 0.22s ease, box-shadow 0.22s ease, background-color 0.22s ease;
    margin-top: 0;
    border: 1px solid transparent;
    border-radius: 0.9rem;
    background: transparent;
    box-shadow: none;
    padding: 0;
}

#topicChatRoot.is-chat-open .topic-chat-panel {
    max-height: 1800px;
    opacity: 1;
    transform: translateY(0);
    margin-top: 1rem;
    border-color: #d7e2f0;
    background: #ffffff;
    box-shadow: 0 12px 24px rgba(15, 23, 42, 0.06);
    padding: 1rem;
}

.topic-chat-subtitle {
    max-width: 70ch;
}

.topic-chat-disclaimer {
    margin: 0.35rem 0 0.8rem;
    font-size: 0.82rem;
    color: #64748b;
}

.topic-chat-disabled-actions {
    margin-top: 0.8rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.topic-chat-messages {
    border: 1px solid #d5deea;
    border-radius: 0.75rem;
    background: #f8fbff;
    min-height: 220px;
    max-height: 420px;
    overflow-y: auto;
    padding: 0.875rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.topic-chat-empty {
    color: #6b7280;
    font-size: 0.95rem;
    text-align: center;
    padding: 2.25rem 0.75rem;
}

.topic-chat-message {
    display: flex;
}

.topic-chat-message-user {
    justify-content: flex-end;
}

.topic-chat-message-assistant {
    justify-content: flex-start;
}

.topic-chat-bubble {
    max-width: min(100%, 44rem);
    border-radius: 0.9rem;
    padding: 0.7rem 0.85rem;
    font-size: 0.95rem;
    line-height: 1.5;
    border: 1px solid #d9e0ec;
    background: #ffffff;
    color: #111827;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.topic-chat-message-user .topic-chat-bubble {
    background: #ecf4ff;
    border-color: #bfd6ff;
}

.topic-chat-message-assistant .topic-chat-bubble {
    background: #ffffff;
}

.topic-chat-bubble p:last-child {
    margin-bottom: 0;
}

.topic-chat-bubble pre,
.topic-chat-bubble code {
    max-width: 100%;
    overflow-x: auto;
    white-space: pre-wrap;
}

.topic-chat-bubble pre {
    background: #0f172a;
    color: #e2e8f0;
    border-radius: 0.5rem;
    padding: 0.65rem 0.75rem;
    margin: 0.5rem 0 0;
}

.topic-chat-bubble code {
    background: #eef2f7;
    border-radius: 0.35rem;
    padding: 0.05rem 0.3rem;
}

.topic-chat-bubble pre code {
    display: block;
    background: transparent;
    color: inherit;
    border-radius: 0;
    padding: 0;
    white-space: inherit;
}

.topic-chat-bubble table {
    max-width: 100%;
    display: block;
    overflow-x: auto;
}

.topic-chat-bubble img {
    max-width: 100%;
    height: auto;
}

.topic-chat-meta {
    margin-top: 0.4rem;
    font-size: 0.75rem;
    color: #6b7280;
}

.topic-chat-status {
    margin-top: 0.6rem;
    font-size: 0.88rem;
    color: #1e3a8a;
}

.topic-chat-status-error {
    color: #b91c1c;
}

.topic-chat-progress {
    margin-top: 0.55rem;
    margin-bottom: 0.15rem;
    border: 1px solid #d7e3f2;
    border-radius: 0.7rem;
    background: #f8fbff;
    padding: 0.55rem 0.7rem;
    display: flex;
    align-items: center;
    gap: 0.55rem;
    color: #334155;
    font-size: 0.84rem;
    line-height: 1.4;
}

.topic-chat-progress-spinner {
    color: #1d4ed8;
    width: 0.95rem;
    height: 0.95rem;
    border-width: 0.15em;
    flex: 0 0 auto;
}

.topic-chat-progress-text {
    display: inline-block;
}

.topic-chat-input {
    resize: vertical;
    min-height: 6.2rem;
    border: 1px solid #cbd5e1;
    background: #ffffff;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.topic-chat-input:focus {
    border-color: #94a3b8;
    box-shadow: 0 0 0 0.18rem rgba(148, 163, 184, 0.2);
    outline: none;
}

#topicChatToggleBtn:focus-visible,
#topicChatSendBtn:focus-visible,
#topicChatClearBtn:focus-visible {
    outline: 3px solid #1d4ed8;
    outline-offset: 2px;
    box-shadow: none;
}

.topic-chat-actions {
    flex-wrap: wrap;
}

.topic-chat-blocked {
    border: 1px dashed #d5deea;
    border-radius: 0.75rem;
    padding: 1.25rem;
    background: #fafcff;
}

.topic-chat-blocked-icon {
    font-size: 1.5rem;
    color: #1d4ed8;
}

@media (max-width: 767px) {
    .topic-chat-header {
        gap: 0.75rem;
        padding: 0.85rem 0.85rem;
    }

    .topic-chat-header-subtitle {
        font-size: 0.84rem;
    }

    .topic-chat-header-action {
        font-size: 0.72rem;
    }

    .topic-chat-disabled-actions .btn {
        width: 100%;
    }

    .topic-chat-messages {
        max-height: 360px;
    }

    .topic-chat-actions {
        flex-direction: column;
        align-items: stretch !important;
    }

    #topicChatSendBtn {
        width: 100%;
    }
}
