/* Project Build chat + typing indicator (extracted from main.css) */

/* --- Ideavibes AI chat --- */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    height: 42px;
}

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

.chat-participants {
    display: flex;
    align-items: center;
    gap: 0;
}

.chat-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    color: #fff;
    margin-left: -4px;
    border: 2px solid var(--bg-primary);
}

.chat-avatar:first-child { margin-left: 0; }
.chat-avatar.ai { background: var(--accent); }
.chat-avatar.user { background: linear-gradient(135deg, var(--accent), #8b5cf6); }

.chat-messages {
    flex: 1;
    min-width: 0;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.chat-bubble {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
    width: fit-content;
    max-width: var(--msg-max-width);
    padding: 10px 14px;
    border-radius: 10px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    margin-bottom: 10px;
}

.chat-bubble:last-child {
    margin-bottom: 0;
}

.chat-bubble.ai {
    align-self: flex-start;
    border-left: 3px solid var(--accent);
}

.chat-bubble.user {
    width: fit-content;
    max-width: var(--msg-max-width);
    align-self: flex-end;
    margin-left: auto;
    background: var(--msg-user-bg);
    border-color: var(--msg-user-border);
    color: var(--msg-user-fg);
}

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

.chat-avatar-sm {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}

.chat-avatar-sm.ai { background: var(--accent); }
.chat-avatar-sm.user { background: linear-gradient(135deg, var(--accent), #8b5cf6); }

.chat-sender {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.chat-time {
    font-size: 14px;
    color: var(--text-muted);
    margin-left: auto;
}

.chat-bubble-content {
    min-width: 0;
    max-width: 100%;
    font-size: 14px;
    line-height: 1.6;
    color: var(--msg-ai-fg);
    overflow-wrap: anywhere;
    word-break: break-word;
}

.chat-bubble.user .chat-bubble-content {
    color: var(--msg-user-fg);
}

.chat-bubble.ai .chat-bubble-content {
    color: var(--msg-ai-fg);
}

.chat-bubble-content > div {
    min-width: 0;
    max-width: 100%;
}

/* Markdown rendering inside chat bubbles */
.chat-bubble-content ol,
.chat-bubble-content ul {
    margin: 8px 0;
    padding-left: 24px;
}

.chat-bubble-content ol {
    list-style-type: decimal;
}

.chat-bubble-content ul {
    list-style-type: disc;
}

.chat-bubble-content li {
    margin-bottom: 4px;
    padding-left: 4px;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.chat-bubble-content p {
    margin: 6px 0;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.chat-bubble-content p:first-child {
    margin-top: 0;
}

.chat-bubble-content p:last-child {
    margin-bottom: 0;
}

.chat-bubble-content code {
    background: var(--bg-tertiary);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 14px;
    font-family: 'JetBrains Mono', monospace;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.chat-bubble-content pre {
    background: var(--bg-tertiary);
    max-width: 100%;
    max-height: 180px;
    padding: 10px 12px;
    border-radius: 6px;
    overflow: auto;
    margin: 8px 0;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.chat-bubble-content pre code {
    background: none;
    padding: 0;
}

.chat-bubble-content blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 12px;
    margin: 8px 0;
    color: var(--msg-ai-muted);
}

.chat-bubble-content strong {
    color: inherit;
    font-weight: 650;
}

.chat-bubble.ai .chat-bubble-content strong {
    color: var(--msg-ai-fg);
}

.chat-bubble.user .chat-bubble-content strong {
    color: var(--msg-user-fg);
}

/* Links sit on muted body text, so give them a resting affordance
   (accent + underline) instead of relying on hover to reveal them. */
.chat-bubble-content a {
    color: var(--accent);
    font-weight: 500;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.chat-bubble-content a:hover {
    color: var(--accent-hover);
}

.chat-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 4px;
}

.chat-badge {
    font-size: 14px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 4px;
    background: rgba(113, 113, 122, 0.15);
    color: var(--text-muted);
}

.chat-badge.success {
    background: rgba(34, 197, 94, 0.15);
    color: #4ade80;
}

.chat-badge.active {
    background: rgba(59, 130, 246, 0.15);
    color: #60a5fa;
}

/* Chat input */
.chat-input-area {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.chat-file-input {
    display: none;
}

.chat-attach-btn,
.goal-attach-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 36px;
    min-width: 36px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    flex-shrink: 0;
    transition: border-color var(--transition-speed), color var(--transition-speed);
}

.chat-attach-btn {
    width: 36px;
    padding: 0;
}

.chat-attach-btn:hover,
.goal-attach-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.chat-image-preview-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 16px 12px;
    border-top: 1px solid transparent;
}

.wizard-image-preview-row {
    padding: 8px 0 0;
}

.chat-image-preview {
    position: relative;
    width: 72px;
    height: 72px;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    background: var(--bg-secondary);
}

.chat-image-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-image-preview button {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: rgba(15, 23, 42, 0.82);
    color: #fff;
    font-size: 16px;
    line-height: 1;
}

.chat-image-error {
    padding: 0 16px 10px;
    color: #ef4444;
    font-size: 14px;
}

.wizard-image-error {
    padding: 8px 0 0;
}

.goal-image-actions {
    display: flex;
    align-items: center;
    margin-top: 8px;
}

.chat-image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
    gap: 8px;
    margin-bottom: 8px;
}

/* --- Document attachments (.txt/.md) --- */

.chat-doc-preview-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 16px 12px;
}


.wizard-doc-preview-row {
    padding: 8px 0 0;
}

.chat-doc-preview {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: 240px;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-secondary);
    font-size: 14px;
}

.chat-doc-preview .chat-doc-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-doc-preview .chat-doc-size {
    color: var(--text-secondary);
    flex-shrink: 0;
}

.chat-doc-preview button {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(15, 23, 42, 0.82);
    color: #fff;
    font-size: 14px;
    line-height: 1;
}

.chat-doc-grid {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 8px;
}

.chat-doc-attachment {
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    background: var(--bg-secondary);
}

.chat-doc-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 10px;
    text-align: left;
    font-size: 14px;
    cursor: pointer;
}

.chat-doc-chip .chat-doc-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-doc-chip .chat-doc-size {
    margin-left: auto;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.chat-doc-body {
    margin: 0;
    max-height: 320px;
    overflow: auto;
    padding: 10px 12px;
    border-top: 1px solid var(--border);
    background: var(--bg);
    font-family: var(--font-mono, ui-monospace, monospace);
    font-size: 14px;
    white-space: pre-wrap;
    word-break: break-word;
}

.chat-doc-loading,
.chat-doc-load-error {
    padding: 8px 12px;
    border-top: 1px solid var(--border);
    font-size: 14px;
}

.chat-doc-load-error {
    color: #ef4444;
}

.chat-image-link {
    display: block;
    aspect-ratio: 4 / 3;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    background: var(--bg-secondary);
}

.chat-image-link img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.chat-image-loading,
.chat-image-load-error {
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 4 / 3;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-muted);
    font-size: 14px;
}

.chat-image-load-error {
    color: #ef4444;
}

.chat-input {
    flex: 1;
    min-height: 44px;
    max-height: 120px;
    padding: 10px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    line-height: 1.45;
    outline: none;
    resize: none;
    overflow-y: auto;
    field-sizing: content;
    transition: border-color var(--transition-speed);
}

.chat-input::placeholder {
    color: var(--text-muted);
}

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

.chat-send-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: var(--accent);
    color: #fff;
    border-radius: 8px;
    flex-shrink: 0;
    transition: background var(--transition-speed);
}

.chat-send-btn:hover {
    background: var(--accent-hover);
}

/* Plan list in chat */
.chat-plan-list {
    margin: 8px 0 6px 0;
    padding-left: 20px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    list-style: none;
    counter-reset: plan-step;
}

.chat-plan-item {
    counter-increment: plan-step;
    font-size: 14px;
    line-height: 1.5;
    padding: 5px 8px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    position: relative;
    padding-left: 30px;
}

.chat-plan-item::before {
    content: counter(plan-step);
    position: absolute;
    left: 8px;
    top: 5px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-plan-title {
    font-weight: 600;
    color: var(--text-primary);
}

.chat-plan-detail {
    color: var(--text-muted);
}

.chat-plan-summary {
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: 6px;
}

/* Build credit ceiling on pending confirm / resume cards (warn-only). */
.chat-credit-estimate {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 10px;
    padding: 8px 10px;
    border-radius: 6px;
    background: rgba(59, 130, 246, 0.08);
    border: 1px solid rgba(59, 130, 246, 0.18);
    line-height: 1.4;
}

.chat-credit-estimate.warn {
    color: var(--text-primary);
    background: rgba(245, 158, 11, 0.12);
    border-color: rgba(245, 158, 11, 0.35);
}

/* Confirm plan bubble */
.chat-bubble.confirm-plan {
    border: 1px solid rgba(59, 130, 246, 0.3);
    background: rgba(59, 130, 246, 0.06);
}

.chat-bubble.interim {
    border-color: rgba(59, 130, 246, 0.28);
    border-left: 3px solid var(--accent);
    background: linear-gradient(180deg, rgba(59, 130, 246, 0.08), rgba(59, 130, 246, 0.04));
}

.chat-confirm-action {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

.btn-confirm-plan {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 16px;
    font-size: 14px;
    font-weight: 600;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    transition: all var(--transition-speed);
    background: var(--success);
    color: #fff;
}

.btn-confirm-plan:disabled {
    background: rgba(34, 197, 94, 0.15);
    color: var(--success);
    cursor: default;
}

/* Confirmed user bubble */
.chat-bubble.confirmed {
    border: 1px solid rgba(34, 197, 94, 0.3);
    background: rgba(34, 197, 94, 0.06);
}

/* Project / Build conversation - ChatGPT-style reading surface. Keep the
   actionable confirmation controls, but remove decorative avatars and large
   assistant cards so the design-to-build handoff reads as one conversation.
 */
.project-chat-panel .chat-messages {
    gap: 0;
    padding: 26px 18px 12px;
}

.project-chat-panel .chat-thread {
    display: flex;
    width: var(--msg-thread-max-width);
    margin: 0 auto;
    flex-direction: column;
    gap: var(--msg-thread-gap);
}

.project-chat-panel .chat-bubble {
    width: fit-content;
    max-width: var(--msg-max-width);
    align-self: flex-start;
    margin: 0;
    padding: 0;
    gap: 4px;
    border: 0;
    border-radius: 0;
    background: transparent;
}

.project-chat-panel .chat-bubble.ai,
.project-chat-panel .chat-bubble.ai.confirm-plan,
.project-chat-panel .chat-bubble.ai.interim {
    width: fit-content;
    max-width: var(--msg-max-width);
    align-self: flex-start;
    border: 0;
    background: transparent;
}

.project-chat-panel .chat-bubble.user {
    width: fit-content;
    max-width: var(--msg-max-width);
    align-self: flex-end;
    margin-left: auto;
    justify-content: center;
    padding: var(--msg-user-padding);
    border: 1px solid var(--msg-user-border);
    border-radius: var(--msg-user-radius);
    background: var(--msg-user-bg);
    color: var(--msg-user-fg);
}

.project-chat-panel .chat-bubble.user.confirmed {
    border: 1px solid rgba(34, 197, 94, 0.3);
    background: rgba(34, 197, 94, 0.06);
    color: var(--msg-user-fg);
}

.project-chat-panel .chat-bubble.ai .chat-bubble-content {
    color: var(--msg-ai-fg);
}

.project-chat-panel .chat-bubble.user .chat-bubble-content {
    color: var(--msg-user-fg);
}

.project-chat-panel .chat-bubble-header {
    margin-bottom: 2px;
}

.project-chat-panel .chat-avatar,
.project-chat-panel .chat-avatar-sm,
.project-chat-panel .chat-participants {
    display: none;
}

.project-chat-panel .chat-sender {
    font-size: 14px;
}

.project-chat-panel .chat-bubble-content {
    font-size: 15px;
    line-height: 1.7;
}

.project-chat-panel .chat-typing {
    width: min(780px, calc(100% - 36px));
    margin: 0 auto;
    padding: 8px 0;
}

.project-chat-panel .chat-typing-label {
    font-size: 14px;
}

.project-chat-panel .chat-input-area {
    width: min(780px, calc(100% - 36px));
    margin: 8px auto 20px;
    padding: 6px 8px;
    gap: 4px;
    border: 1px solid var(--border);
    border-radius: 24px;
    background: var(--bg-secondary);
}

.project-chat-panel .chat-attach-btn {
    border: 0;
    border-radius: 50%;
    background: transparent;
}

.project-chat-panel .chat-input {
    min-height: 40px;
    padding: 10px 4px;
    border: 0;
    border-radius: 0;
    background: transparent;
    font-size: 15px;
    line-height: 20px;
}

.project-chat-panel .chat-input:focus {
    border-color: transparent;
}

.project-chat-panel .chat-send-btn {
    border-radius: 50%;
}

/* Narrow viewports: keep thread + composer inside the panel (no page-level
   horizontal scroll). Bubble width still uses --msg-max-width (80%). */
@media (max-width: 1024px) {
    .project-chat-panel .chat-messages {
        padding: 20px 14px 10px;
    }

    .project-chat-panel .chat-thread {
        width: 100%;
        max-width: 100%;
    }

    .project-chat-panel .chat-input-area,
    .project-chat-panel .chat-typing {
        width: min(780px, calc(100% - 24px));
    }
}

@media (max-width: 400px) {
    .project-chat-panel .chat-messages {
        padding: 14px 10px 8px;
    }

    .project-chat-panel .chat-input-area,
    .project-chat-panel .chat-typing {
        width: calc(100% - 16px);
        margin-left: auto;
        margin-right: auto;
        margin-bottom: 12px;
    }

    .chat-bubble,
    .project-chat-panel .chat-bubble,
    .project-chat-panel .chat-bubble.user,
    .project-chat-panel .chat-bubble.ai {
        max-width: var(--msg-max-width);
    }

    .chat-bubble-content {
        overflow-wrap: anywhere;
        word-break: break-word;
    }
}


/* --- Chat typing indicator --- */

.chat-typing {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
}

.chat-typing-label {
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 600;
}

.typing-dots {
    display: flex;
    gap: 4px;
}

.typing-dots .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted, #64748b);
    animation: typing-bounce 1.4s ease-in-out infinite;
}

.typing-dots .dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dots .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

