.message-content.has-ai-chem {
    min-width: 0;
}

.ai-chem-card {
    width: 100%;
    margin: 15px 0;
    overflow: hidden;
    border: 1px solid rgba(96, 165, 250, .22);
    border-radius: 18px;
    background: linear-gradient(180deg, rgba(15, 33, 58, .98), rgba(8, 22, 42, .98));
    box-shadow: 0 12px 34px rgba(1, 8, 20, .18);
}

.ai-chem-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    padding: 14px 16px 8px;
}

.ai-chem-titles {
    min-width: 0;
}

.ai-chem-titles h3 {
    margin: 0;
    color: #fff;
    font-size: 17px;
    line-height: 1.3;
    font-weight: 800;
}

.ai-chem-titles p {
    margin: 5px 0 0;
    color: #8fa9ca;
    font-size: 12px;
    line-height: 1.45;
}

.ai-chem-text-stage {
    display: grid;
    place-items: center;
    min-height: 92px;
    padding: 18px 20px 20px;
    overflow-x: auto;
}

.ai-chem-formula-line {
    max-width: 100%;
    color: #f7fbff;
    font-family: "Times New Roman", Cambria, "STIX Two Text", serif;
    font-size: clamp(24px, 4.2vw, 38px);
    line-height: 1.35;
    letter-spacing: .01em;
    text-align: center;
    white-space: nowrap;
}

.ai-chem-text-reaction .ai-chem-formula-line {
    font-size: clamp(20px, 3.5vw, 31px);
}

.ai-chem-formula-line sub,
.ai-chem-formula-line sup {
    font-size: .62em;
    line-height: 0;
}

.ai-chem-formula-line sub {
    vertical-align: -.28em;
}

.ai-chem-formula-line sup {
    vertical-align: .58em;
}

.ai-chem-arrow {
    display: inline-block;
    margin: 0 .34em;
    color: #9fc8ff;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI Symbol", sans-serif;
    font-weight: 600;
}

.ai-chem-structure-stage {
    position: relative;
    display: grid;
    place-items: center;
    min-height: 260px;
    margin: 4px 10px 10px;
    padding: 10px;
    overflow: hidden;
    border: 1px solid rgba(148, 163, 184, .18);
    border-radius: 14px;
    background: #fbfdff;
}

.ai-chem-svg-viewport {
    display: grid;
    place-items: center;
    width: 100%;
    min-width: 0;
    height: min(360px, 58vw);
    min-height: 240px;
    overflow: auto hidden;
}

.ai-chem-svg {
    display: block;
    width: 100%;
    height: 100%;
    min-width: 360px;
    max-width: 760px;
}

.ai-chem-loading,
.ai-chem-streaming-placeholder {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: #8fa9ca;
    font-size: 13px;
    font-weight: 650;
}

.ai-chem-structure-stage .ai-chem-loading {
    color: #526b86;
}

.ai-chem-loading-dot {
    width: 8px;
    height: 8px;
    flex: 0 0 8px;
    border-radius: 50%;
    background: #60a5fa;
    box-shadow: 0 0 0 0 rgba(96, 165, 250, .4);
    animation: ai-chem-pulse 1.2s ease-out infinite;
}

.ai-chem-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 42px;
    padding: 8px 14px 12px;
    border-top: 1px solid rgba(148, 163, 184, .1);
}

.ai-chem-source {
    min-width: 0;
    overflow: hidden;
    color: #7189a8;
    font-size: 11px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-chem-copy {
    flex: 0 0 auto;
    min-height: 30px;
    padding: 5px 9px;
    border: 1px solid rgba(148, 163, 184, .16);
    border-radius: 8px;
    background: rgba(4, 14, 28, .55);
    color: #9fc8ff;
    font: inherit;
    font-size: 11px;
    font-weight: 750;
    cursor: pointer;
}

.ai-chem-copy:hover {
    border-color: rgba(96, 165, 250, .32);
    color: #dbeaff;
}

.ai-chem-error {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 14px 16px;
    border-color: rgba(248, 113, 113, .24);
    background: rgba(79, 20, 28, .24);
}

.ai-chem-error-icon {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    border-radius: 10px;
    background: rgba(248, 113, 113, .12);
    color: #ffb4b4;
    font-size: 17px;
}

.ai-chem-error-copy {
    display: grid;
    gap: 2px;
    padding: 10px;
    text-align: left;
}

.ai-chem-error-copy strong {
    color: #ffe4e4;
    font-size: 13px;
}

.ai-chem-error-copy small {
    color: #c99b9f;
    font-size: 11px;
    line-height: 1.4;
}

.ai-chem-structure-stage > .ai-chem-error-copy {
    max-width: 420px;
    color: #6b2530;
    text-align: center;
}

.ai-chem-structure-stage > .ai-chem-error-copy strong {
    color: #8c2636;
}

.ai-chem-structure-stage > .ai-chem-error-copy small {
    color: #a14754;
}

.ai-chem-stream-hidden {
    display: none !important;
}

@keyframes ai-chem-pulse {
    0% { box-shadow: 0 0 0 0 rgba(96, 165, 250, .4); }
    70% { box-shadow: 0 0 0 7px rgba(96, 165, 250, 0); }
    100% { box-shadow: 0 0 0 0 rgba(96, 165, 250, 0); }
}

@media (max-width: 700px) {
    .ai-chem-card {
        margin: 13px 0;
        border-radius: 15px;
    }

    .ai-chem-head {
        padding: 13px 12px 7px;
    }

    .ai-chem-text-stage {
        min-height: 80px;
        padding: 15px 12px 17px;
    }

    .ai-chem-formula-line {
        font-size: clamp(22px, 7vw, 31px);
    }

    .ai-chem-text-reaction .ai-chem-formula-line {
        font-size: clamp(18px, 5.4vw, 25px);
    }

    .ai-chem-structure-stage {
        min-height: 230px;
        margin: 3px 6px 8px;
        padding: 7px;
        border-radius: 12px;
    }

    .ai-chem-svg-viewport {
        height: 270px;
        min-height: 220px;
    }

    .ai-chem-svg {
        min-width: 320px;
    }

    .ai-chem-footer {
        padding: 8px 10px 10px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .ai-chem-loading-dot {
        animation: none;
    }
}
