/* Messages list — padding from .page wrapper, viewport is flex column */
.messages {
    flex: 1 1 auto;
    min-height: 0;
    background: transparent;
}
.messages [data-overlayscrollbars-viewport] {
    display: flex !important;
    flex-direction: column;
    gap: var(--space-gap);
    padding: var(--space-inset) 0;
}
.messages [data-overlayscrollbars-viewport] > * {
    margin-right: calc(var(--space-page) + var(--space-inset));
}

/* Load more */
.load-more-btn {
    align-self: center;
    background: none;
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 4px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    margin-bottom: var(--space-gap);
    transition: color 0.15s, border-color 0.15s;
}
.load-more-btn:hover { color: var(--text); border-color: var(--text-dim); }

/* Message bubbles */
.message {
    max-width: 80%;
    padding: 12px 18px;
    border-radius: var(--radius);
    line-height: 1.5;
    white-space: normal;
    text-indent: 0;
    position: relative;
    overflow-wrap: break-word;
    word-break: break-word;
    min-width: 0;
}

.message.user {
    align-self: flex-end;
    background: var(--user-bubble);
    white-space: pre-wrap;
    margin-top: var(--space-page);
}

.message.assistant {
    align-self: flex-start;
    background: var(--surface);
}

.message.thinking {
    align-self: flex-start;
    background: rgba(139, 92, 246, 0.08);
    border: 1px solid rgba(139, 92, 246, 0.25);
    color: #a78bfa;
    padding: 6px 12px;
    border-radius: var(--radius);
    max-width: 80%;
}
.message.thinking summary {
    cursor: pointer;
    font-style: italic;
    opacity: 0.8;
    user-select: none;
    list-style: none;
}
.message.thinking summary::-webkit-details-marker { display: none; }
.message.thinking .thinking-content {
    margin-top: 8px;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: var(--font-mono);
    color: #c4b5fd;
    opacity: 0.85;
    max-height: 300px;
    overflow-y: auto;
}

.message.system {
    align-self: flex-start;
    background: transparent;
    border: none;
    color: var(--text-dim);
    padding: 1px 8px;
    margin: -2px 0;
    max-width: 100%;
    opacity: 0.7;
}


.message .bubble-footer:not(:empty) {
    color: var(--text-dim);
    margin-top: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: none;
}

.message hr { border: none; border-top: 1px solid var(--border); margin: 1.2rem 0.5rem; opacity: 0.4; }

.message table { border-collapse: collapse; margin: 6px 0; display: block; overflow-x: auto; }
.message th, .message td { padding: 0 10px; }
.message th { font-weight: 600; }
.message ul, .message ol { padding-left: 20px; margin: 4px 0; white-space: normal; }
.message li { margin: 2px 0; white-space: normal; }
.message li > p { margin: 0; }
.message p { margin: 0 0 6px 0; white-space: normal; }
.message p:last-child { margin-bottom: 0; }

.message pre {
    overflow-x: auto;
    white-space: pre;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    margin: 6px 0;
    max-width: 100%;
}

.message code { font-family: var(--font-mono); }
.message pre code { background: none; padding: 0; border: none; }

/* Copy button on messages */
.copy-btn {
    position: absolute;
    top: 6px;
    right: 8px;
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    opacity: 0;
    transition: opacity 0.15s;
}
.message:hover .copy-btn { opacity: 0.6; }
.copy-btn:hover { opacity: 1 !important; }

/* Copy button on code blocks */
.pre-copy-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-dim);
    padding: 2px 7px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s;
}
.message pre:hover .pre-copy-btn { opacity: 1; }

/* Status indicators */
.inline-hud {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.5rem 0 0.25rem;
}

.messages-sm-state {
    display: flex;
    justify-content: center;
    font-weight: 500;
    color: var(--text-dim);
    padding: 4px 0 0;
    margin: 0;
    line-height: 1.2;
    opacity: 0.6;
    pointer-events: none;
}
.messages-sm-state.AGENT_RUNNING { color: var(--warn); opacity: 1; animation: pulse 1.5s infinite; }
.messages-sm-state.STOP_PENDING  { color: var(--error); opacity: 1; }
.messages-sm-state.CONNECTING    { color: var(--warn); opacity: 0.7; }
.messages-sm-state.SWITCHING     { color: #60a5fa; opacity: 1; }

.agent-status-indicator {
    padding: 2px var(--space-page);
    color: var(--text-dim);
    opacity: 0.7;
    flex-shrink: 0;
}
.agent-status-indicator:not(.done) span { animation: pulse 1s infinite; }
.agent-status-indicator.done { opacity: var(--disabled-opacity); }

.typing-dots { animation: blink 1s infinite; }

/* Agent action bar — always visible above input */
.agent-action-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px var(--space-page);
    flex-shrink: 0;
}
.action-bar-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 3px 12px;
    height: 26px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
}
.action-bar-btn:hover:not(:disabled) { color: var(--text); border-color: var(--text-dim); }
.action-bar-btn:disabled { opacity: var(--disabled-opacity); cursor: default; }

/* Input area */
.input-area {
    display: flex;
    flex-direction: column;
    padding: var(--panel-gap) var(--panel-gap) var(--panel-gap);
    background: transparent;
    flex-shrink: 0;
}

.input-box {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.3rem 0.5rem;
    overflow: hidden;
    background: var(--panel-bg);
    border: none;
    border-radius: var(--radius-panel);
    box-shadow: var(--panel-shadow);
    padding: 0.5rem 0.5rem 0.5rem 0.85rem;
    transition: box-shadow 0.15s;
    width: 100%;
    box-sizing: border-box;
}

.input-box:focus-within {
    box-shadow: var(--panel-shadow), 0 0 0 2px rgba(74, 222, 128, 0.15);
}

.input-area .chat-input {
    flex: 1 1 100%;
    order: -1;
    min-width: 0 !important;
    max-width: 100% !important;
    background: transparent;
    color: var(--text);
    border: none;
    padding: 0;
    font-size: 1rem;
    font-family: inherit;
    resize: none;
    line-height: 1.5;
    min-height: 36px;
    max-height: 160px;
    overflow-y: auto;
    box-sizing: border-box;
    outline: none;
}
.input-area .chat-input:focus { outline: none; }

.input-area .chat-input.shake {
    animation: shake 0.4s cubic-bezier(.36,.07,.19,.97) both;
    border: 1px solid var(--error) !important;
}

@keyframes shake {
    10%, 90% { transform: translate3d(-1px, 0, 0); }
    20%, 80% { transform: translate3d(2px, 0, 0); }
    30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
    40%, 60% { transform: translate3d(4px, 0, 0); }
}

/* Input toolbar */
.input-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-page);
}

.input-toolbar-left,
.input-toolbar-center {
    display: flex;
    align-items: center;
    gap: 6px;
}

.input-toolbar-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

.input-toolbar-center {
    flex: 1;
    justify-content: center;
}

.v-stack {
    flex-direction: column;
    gap: 4px;
    align-items: center;
}

.toolbar-btn {
    background: none;
    border: 1px solid var(--primary);
    color: var(--primary);
    border-radius: var(--radius-sm);
    padding: 0 10px;
    height: var(--height-btn);
    line-height: 1;
    cursor: pointer;
    transition: color .15s, border-color .15s;
    display: inline-flex;
    align-items: center;
}
.toolbar-btn:hover:not(:disabled) { color: var(--text); border-color: var(--text-dim); }
.toolbar-btn:disabled { opacity: var(--disabled-opacity); cursor: default; }

.yes-btn {
    background: none;
    border: 1px solid var(--success);
    color: var(--success);
    padding: 0 16px;
    height: var(--height-btn);
    border-radius: var(--radius-sm);
    font-weight: 500;
    cursor: pointer;
    transition: background .15s, color .15s;
    display: inline-flex;
    align-items: center;
}
.yes-btn:hover:not(:disabled) { background: var(--success); color: #fff; }
.yes-btn:disabled { opacity: var(--disabled-opacity); cursor: default; }

.send-btn {
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    flex-shrink: 0;
    margin-left: auto;
    border-radius: 50%;
    border: none;
    background: var(--send-btn-bg, var(--accent));
    color: var(--send-btn-color, white);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: filter 0.15s, opacity 0.15s;
    padding: 0;
    margin-bottom: 1px;
}
.send-btn:hover:not(:disabled) { filter: brightness(1.1); }
.send-btn:disabled { opacity: 0.25; cursor: not-allowed; background: var(--muted); }

.stop-btn {
    background: none;
    border: 1px solid var(--error);
    color: var(--error);
    padding: 0 12px;
    height: var(--height-btn);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
}
.stop-btn:hover:not(:disabled) { background: var(--error); color: #fff; }
.stop-btn:disabled { cursor: default; }
.stop-btn.stop-muted { opacity: 0.25; }
.footer-stop-btn { margin-left: 4px; }

.kill-btn {
    background: none;
    border: 1px solid var(--error);
    color: var(--error);
    padding: 0 12px;
    height: var(--height-btn);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
}
.kill-btn:hover:not(:disabled) { background: var(--error); color: #fff; }

.finance-badge {
    color: var(--text-dim);
    border: 1px solid var(--border);
    padding: 2px 8px;
    height: 20px;
    border-radius: 12px;
    background: var(--bg);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
}
.finance-badge:hover { border-color: var(--accent); color: var(--text); }

/* ── File download buttons ── */
.file-download-link {
    display: inline-block;
    padding: 0.3rem 0.7rem;
    margin: 0.2rem 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--accent);
    font-size: 0.85rem;
    font-family: inherit;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}
.file-download-link:hover {
    border-color: var(--accent);
    background: rgba(74, 222, 128, 0.08);
}

/* ── Mobile — touch targets ── */
@media (max-width: 639px) {
    .send-btn { width: 44px; height: 44px; min-width: 44px; min-height: 44px; }
}
