/* ==================
   Chat message actions (js/chat/message-actions.js)
   Copy, regenerate, retry, edit & resend, Shorter / More detail
   ================== */

/* Revealed on hover and keyboard focus; always shown on touch screens and
   after a failed run (Retry is the way forward) */
.chat-msg-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    margin-top: 8px;
    opacity: 0;
    transition: opacity 0.15s ease;
}

[data-message-index]:hover .chat-msg-actions,
.chat-msg-actions:focus-within,
.chat-msg-actions.is-failed {
    opacity: 1;
}

@media (hover: none) {
    .chat-msg-actions {
        opacity: 1;
    }
}

/* Beside the user bubble (a flex sibling to its left), so it adds no height */
.chat-msg-actions-user {
    flex-wrap: nowrap;
    flex-shrink: 0;
    align-self: center;
    margin-top: 0;
}

.msg-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    font-size: 12px;
    font-weight: 500;
    color: rgb(var(--gray-500));
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.msg-action-btn:hover {
    color: rgb(var(--gray-700));
    background: rgb(var(--gray-100));
    border-color: rgb(var(--gray-200));
}

.msg-action-btn svg {
    flex-shrink: 0;
}

.msg-action-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.msg-action-primary {
    color: rgb(var(--blue-700));
    background: rgb(var(--blue-50));
    border-color: rgb(var(--blue-200));
}

.msg-action-primary:hover {
    color: rgb(var(--blue-800));
    background: rgb(var(--blue-100));
    border-color: rgb(var(--blue-300));
}

/* Actions that start a run: hidden while one is active, inert while a
   regenerate / edit is being set up */
.chat-run-active .msg-action-run {
    display: none;
}

.chat-actions-busy .msg-action-run {
    pointer-events: none;
    opacity: 0.5;
}

/* ---------- Code block copy ---------- */

.code-block-wrap {
    position: relative;
}

.code-copy-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 6px;
    font-family: inherit;
    font-size: 11px;
    font-weight: 500;
    color: rgb(var(--gray-200));
    background: rgb(var(--gray-0) / 0.08);
    border: 1px solid rgb(var(--gray-0) / 0.2);
    border-radius: 6px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s ease, background-color 0.15s ease;
}

.code-copy-btn svg {
    width: 14px;
    height: 14px;
}

.code-block-wrap:hover .code-copy-btn,
.code-copy-btn:focus-visible,
.code-copy-btn.copied {
    opacity: 1;
}

.code-copy-btn:hover {
    background: rgb(var(--gray-0) / 0.16);
}

.code-copy-btn.copied {
    color: rgb(var(--green-800));
    background: rgb(var(--green-100));
    border-color: rgb(var(--green-300));
}

@media (hover: none) {
    .code-copy-btn {
        opacity: 1;
    }
}

/* ---------- Inline edit ---------- */

[data-message-index].is-editing > div:last-child {
    flex: 1 1 auto;
}

.is-editing .chat-message-user,
.is-editing .chat-msg-actions-user {
    display: none;
}

.chat-msg-editor {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
}

.chat-msg-editor-input {
    width: 100%;
    min-height: 72px;
    resize: vertical;
    padding: 8px 10px;
    font: inherit;
    font-size: 14px;
    line-height: 1.5;
    color: rgb(var(--gray-900));
    background: rgb(var(--gray-0));
    border: 1px solid rgb(var(--blue-300));
    border-radius: 8px;
    outline: none;
    box-shadow: 0 0 0 3px rgb(var(--blue-500) / 0.12);
}

.chat-msg-editor-notice {
    font-size: 12px;
    color: rgb(var(--gray-600));
}

.chat-msg-editor-notice:empty {
    display: none;
}

.chat-msg-editor-notice.is-blocked {
    color: rgb(var(--red-600));
}

.chat-msg-editor-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
}

/* Messages that sending an edit would remove */
.msg-pending-removal {
    opacity: 0.4;
    transition: opacity 0.15s ease;
}

.chat-msg-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
