/* dialog_chat.css */
.chat-modal-bg {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadein 0.15s ease;
}

.chat-box {
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    width: 660px;
    max-width: 100%;
    height: 76vh;
    max-height: 720px;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow);
    overflow: hidden;
    animation: slidein 0.18s ease;
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--line);
    flex-shrink: 0;
}

.chat-header-avatar {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: var(--accent-dim);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 15px;
    flex-shrink: 0;
}

.chat-header-info {
    flex: 1;
    min-width: 0;
}

.chat-header-name {
    font-weight: 600;
    font-size: 14px;
}

.chat-header-sub {
    font-size: 11px;
    color: var(--ink-3);
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Countdown ring */
.chat-countdown {
    display: none;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--ink-3);
}

.chat-countdown.active {
    display: flex;
}

.chat-countdown.expiring {
    color: var(--warning);
}

.chat-countdown.expired {
    color: var(--danger);
}

.chat-countdown svg {
    flex-shrink: 0;
}

.chat-countdown .ccd-ring {
    fill: none;
    stroke: var(--accent);
    stroke-dasharray: 69.115 69.115;
    stroke-linecap: round;
    transform-origin: center;
    transform: rotate(-90deg);
    transition: stroke-dashoffset 0.9s linear;
}

.chat-countdown.expiring .ccd-ring {
    stroke: var(--warning);
}

.chat-countdown.expired .ccd-ring {
    stroke: var(--danger);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.msg-wrap {
    display: flex;
    gap: 10px;
}

.msg-wrap.user {
    flex-direction: row-reverse;
}

.msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
    margin-top: 2px;
}

.msg-wrap.assistant .msg-avatar {
    background: var(--accent-dim);
    color: var(--accent);
}

.msg-wrap.user .msg-avatar {
    background: var(--surface-3);
    color: var(--ink-2);
}

.msg-body {
    display: flex;
    flex-direction: column;
    gap: 3px;
    max-width: 78%;
}

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

.msg-bubble {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13px;
    line-height: 1.6;
    word-break: break-word;
}

.msg-wrap.assistant .msg-bubble {
    background: var(--surface-3);
    border-bottom-left-radius: 4px;
}

.msg-wrap.user .msg-bubble {
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.msg-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 2px;
}

.msg-wrap.user .msg-meta {
    flex-direction: row-reverse;
}

.msg-time {
    font-size: 10px;
    color: var(--ink-3);
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}

.msg-tok {
    font-size: 10px;
    color: var(--ink-3);
    font-family: var(--font-mono);
}

.chat-tok-counter {
    font-size: 10px;
    color: var(--ink-3);
    font-variant-numeric: tabular-nums;
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 4px 0;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--ink-3);
    animation: bounce 1.2s infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes bounce {

    0%,
    80%,
    100% {
        transform: translateY(0);
    }

    40% {
        transform: translateY(-5px);
    }
}

/* Input bar */
.chat-input-bar {
    padding: 12px 16px;
    border-top: 1px solid var(--line);
    display: flex;
    gap: 10px;
    align-items: flex-end;
    flex-shrink: 0;
    background: var(--surface);
}

.chat-input {
    flex: 1;
    padding: 9px 14px;
    background: var(--surface-3);
    border: 1px solid var(--line);
    border-radius: 20px;
    color: var(--ink);
    font-family: var(--font);
    font-size: 13px;
    outline: none;
    resize: none;
    max-height: 120px;
    line-height: 1.5;
    transition: border-color 0.15s;
}

.chat-input:focus {
    border-color: var(--accent);
}

.chat-send-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    flex-shrink: 0;
    transition: background 0.15s, transform 0.1s;
}

.chat-send-btn:hover {
    background: #7c74ff;
}

.chat-send-btn:active {
    transform: scale(0.92);
}

.chat-send-btn:disabled {
    opacity: 0.4;
    pointer-events: none;
}

.chat-send-btn svg {
    pointer-events: none;
}