.chat-stage {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.chat-thread {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    width: min(100%, var(--chat-stage-max));
    margin: 0 auto;
    min-height: 0;
    height: 100%;
}

.chat-thread__empty {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
    padding: 8px 4px;
}

.chat-thread__empty[hidden] {
    display: none !important;
}

.chat-thread__scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px 10px 12px 4px;
}

.chat-thread__scroll[hidden] {
    display: none !important;
}

.chat-thread__list {
    display: flex;
    flex-direction: column;
    gap: 28px;
    width: 100%;
    padding-bottom: 12px;
}

.chat-msg {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    max-width: 100%;
    animation: chat-msg-in 220ms ease both;
}

@keyframes chat-msg-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

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

.chat-msg--assistant {
    align-items: flex-start;
}

.chat-msg__bubble {
    max-width: min(100%, 720px);
    font-size: 16px;
    line-height: 1.7;
    word-break: break-word;
    color: var(--chat-text);
}

.chat-msg--user .chat-msg__bubble {
    padding: 10px 16px;
    border-radius: 22px;
    background: #e8f1ff;
    color: #0f172a;
}

html[data-theme="dark"] .chat-msg--user .chat-msg__bubble {
    background: rgba(96, 165, 250, 0.18);
    color: #eef2ff;
}

.chat-msg--assistant .chat-msg__bubble {
    padding: 2px 2px;
    background: transparent;
    border: 0;
    max-width: 100%;
}

.chat-msg__code {
    display: inline;
    padding: 0.12em 0.4em;
    border-radius: 6px;
    background: rgba(15, 23, 42, 0.06);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.92em;
}

html[data-theme="dark"] .chat-msg__code {
    background: rgba(255, 255, 255, 0.08);
}

.chat-msg__actions {
    display: inline-flex;
    align-items: center;
    gap: 0;
    margin-top: 6px;
    opacity: 1;
}

.chat-msg__action {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #8e8e8e;
    flex-shrink: 0;
}

.chat-msg__action .ui-icon {
    width: 16px;
    height: 16px;
}

.chat-msg__action:hover {
    background: rgba(0, 0, 0, 0.05);
    color: #5d5d5d;
}

.chat-msg__action:active {
    transform: scale(0.96);
}

.chat-msg__action.is-on {
    color: #0f172a;
    background: rgba(0, 0, 0, 0.06);
}

.chat-msg__action.is-on-danger {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}

html[data-theme="dark"] .chat-msg__action {
    color: rgba(255, 255, 255, 0.45);
}

html[data-theme="dark"] .chat-msg__action:hover {
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.78);
}

html[data-theme="dark"] .chat-msg__action.is-on {
    color: #f8fafc;
    background: rgba(255, 255, 255, 0.1);
}

.chat-thread__typing {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 10px 14px;
    border-radius: 16px;
    background: var(--chat-bg-hover);
    border: 1px solid var(--chat-border);
    width: fit-content;
}

.chat-thread__typing[hidden] {
    display: none !important;
}

.chat-thread__dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--chat-text-muted);
    animation: chat-dot 1.1s ease-in-out infinite;
}

.chat-thread__dot:nth-child(2) { animation-delay: 0.15s; }
.chat-thread__dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes chat-dot {
    0%, 80%, 100% { opacity: 0.35; transform: translateY(0); }
    40% { opacity: 1; transform: translateY(-2px); }
}

@media (max-width: 900px) {
    .chat-thread {
        width: 100%;
    }

    .chat-thread__list {
        gap: 22px;
    }

    .chat-msg--user .chat-msg__bubble {
        max-width: 88%;
    }
}

@media (hover: none) {
    .chat-msg__action {
        width: 34px;
        height: 34px;
    }
}
