/* Builder Page - Chat Panel
 * Inline chat panel for project-level AI assistance
 */

/* Chat Panel */
.panel-chat {
    min-width: 0;
    width: var(--width-panel-default);
    background: var(--color-background);
    border-left: var(--border-width) var(--border-style) var(--color-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

/* Collapsed state - panel completely hidden */
.panel-chat.collapsed {
    display: none;
}

/* Messages container */
.panel-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-2);
    padding-right: calc(var(--space-2) + var(--safe-area-right));
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    background: var(--color-background);
}

/* Individual message. The calc gives a fixed --space-5 gutter on the
   bubble's open side (right of assistant, left of user) instead of a
   percentage; short bubbles still shrink to fit their content. */
.panel-chat-message {
    max-width: calc(100% - var(--space-5));
    animation: chatPanelMessageSlide 0.2s ease;
}

@keyframes chatPanelMessageSlide {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Collapsing state for the agent's ephemeral status bubbles. When a turn
   ends they fade and shrink to nothing (max-height + opacity), and the
   negative margin swallows the flex gap so neighbours slide up smoothly
   instead of leaving a blank slot. max-height is set inline to the measured
   height first (see #clearStatusMessages) so the transition has a start
   value to animate from. The 0.25s duration must stay in sync with
   BuilderPanelChat.STATUS_COLLAPSE_MS (the JS side drives stagger + cleanup off
   the same value). */
.panel-chat-message.collapsing {
    overflow: hidden;
    opacity: 0;
    transform: translateY(-4px);
    margin-bottom: calc(-1 * var(--space-2));
    pointer-events: none;
    transition: max-height 0.25s ease, opacity 0.25s ease,
                transform 0.25s ease, margin-bottom 0.25s ease;
}

/* User/Assistant message styling */
.panel-chat-message-user {
    align-self: flex-end;
}

.panel-chat-message-user .panel-chat-message-content {
    background: var(--color-accent);
    color: var(--color-text);
    border-radius: var(--radius-lg) var(--radius-lg) 0 var(--radius-lg);
}

.panel-chat-message-assistant {
    align-self: flex-start;
}

.panel-chat-message-assistant .panel-chat-message-content {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) 0;
}

/* Message content. overflow-wrap is inherited, so this also covers
   unbreakable tokens (GUIDs, long URLs) inside inline code, list items,
   and table cells -- without it they spill past the bubble border. */
.panel-chat-message-content {
    padding: var(--space-2);
    overflow-wrap: anywhere;
}

/* Clickable asset/component references in assistant messages (project item
   names matched by BuilderPanelChat's linkifier). Same underline treatment
   as a.link in style.css -- these are spans, so that rule can't reach them. */
.panel-chat-message-content .ref-link {
    cursor: pointer;
    text-decoration: underline;
    text-decoration-color: var(--color-link);
    text-underline-offset: 2px;
    transition: text-decoration-color 0.25s ease;
}

.panel-chat-message-content .ref-link:hover {
    text-decoration-color: var(--color-link-light);
}

/* Typing indicator: three animated dots stand in for a typing ellipsis,
   so --color-text-dark (muted-variant text color) applies. */
.panel-chat-typing-indicator {
    display: inline-flex;
    gap: 4px;
    padding: var(--space-2);
}

.panel-chat-typing-indicator span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--color-text-dark);
    animation: typingBounce 1.5s infinite;
}

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

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

@keyframes typingBounce {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-8px);
    }
}


/* Message star rating */
.panel-chat-message-rating {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-top: var(--space-1);
    transition: opacity 0.25s ease;
}

.panel-chat-message-rating-label {
    font-size: var(--font-size);
    color: var(--color-text-dark);
    margin-right: var(--space-1);
}

.panel-chat-message-rating-hidden {
    opacity: 0;
}

.panel-chat-message-rating button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0 1px;
    font-size: var(--font-size);
    color: var(--color-text-dark);
}

/* Input container: the message box over one action row. The extra --space-5
   over the old two-header height is that row -- the buttons used to stack
   beside the box, so moving them under it is what buys the box its full
   width. */
.form-inst-chat-container {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    padding: var(--space-2);
    padding-right: calc(var(--space-2) + var(--safe-area-right));
    background: var(--color-surface);
    border-top: var(--border-width) var(--border-style) var(--color-border);
    flex-shrink: 0;
    height: calc(var(--height-header) * 2 + var(--space-5));
}

/* Action row: AI level on the left, Clear + Send on the right */
.form-inst-chat-actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-shrink: 0;
}

/* The level picker takes whatever the buttons leave. Its <select> carries
   .select-compact (common/style.css), which is what matches its height to the
   Clear / Send buttons beside it -- no chat-specific sizing needed. */
.panel-chat-tier {
    flex: 1;
    min-width: 0;
    display: flex;
}

/* Input textarea */
/* Composes the shared textarea base (common/style.css); chat deltas only. */
.form-inst-chat {
    flex: 1;
    line-height: 1.4;
    resize: none;
    overflow-y: auto;
    transition: border-color 0.15s ease;
}

.form-inst-chat:focus {
    outline: none;
    border-color: var(--color-accent);
}

.form-inst-chat:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.form-inst-chat::placeholder {
    color: var(--color-text-dark);
}

/* Button container - sits at the right end of the action row */
.form-inst-chat-container .buttons {
    flex-shrink: 0;
}

