/* --- ChatInterface Component --- */
.chat-interface {
    position: fixed;
    right: var(--spacing-md);
    bottom: 100px;
    /* Above bottom bar */
    width: 350px;
    height: 500px;
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    transition: transform var(--transition-normal), opacity var(--transition-normal);
    z-index: 95;
    overflow: hidden;
}

.chat-interface.closed {
    transform: translateY(20px);
    opacity: 0;
    pointer-events: none;
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-md);
    border-bottom: 1px solid var(--border-light);
    background: rgba(255, 255, 255, 0.3);
}

.chat-title {
    font-size: var(--text-xs);
    font-weight: var(--font-bold);
    color: var(--text-tertiary);
    letter-spacing: 1px;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--spacing-md);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: var(--text-sm);
    line-height: 1.5;
}

.message.bot {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.6);
    border-bottom-left-radius: 4px;
    color: var(--text-primary);
}

.message.user {
    align-self: flex-end;
    background: var(--accent-primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-input-area {
    padding: var(--spacing-md);
    border-top: 1px solid var(--border-light);
    background: rgba(255, 255, 255, 0.3);
}

.input-wrapper {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    background: rgba(255, 255, 255, 0.8);
    border-radius: var(--radius-full);
    padding: 4px 4px 4px 16px;
    border: 1px solid var(--border-medium);
    transition: border-color var(--transition-fast);
}

.input-wrapper:focus-within {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(45, 80, 22, 0.1);
}

.input-wrapper input {
    flex: 1;
    border: none;
    background: transparent;
    font-family: var(--font-sans);
    font-size: var(--text-sm);
    color: var(--text-primary);
    outline: none;
}

.send-btn {
    background: var(--accent-primary);
    color: white;
    width: 32px;
    height: 32px;
}

.send-btn:hover {
    background: #234010;
}

/* Markdown Support */
.ai-message {
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.6;
    margin-bottom: 8px;
    position: relative;
    overflow-wrap: break-word;
    /* Prevent long words from overflowing */
}

/* User Message - Outline Style */
.ai-message.user-message {
    align-self: flex-end;
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--accent-primary);
    border-radius: 12px;
    border-bottom-right-radius: 4px;
    max-width: 85%;
}

.ai-message.ai-message {
    align-self: flex-start;
    /* background: rgba(255, 255, 255, 0.95);  Removed as per user request */
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
    max-width: 95%;
    /* box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); Removed to make it cleaner */
}

.ai-message p {
    margin: 0 0 10px 0;
}

.ai-message p:last-child {
    margin-bottom: 0;
}

.ai-message strong {
    font-weight: 700;
    color: #1a1a1a;
}

.user-message strong {
    color: var(--accent-primary);
}

.ai-message em {
    font-style: italic;
}

/* Horizontal Rule */
.ai-message hr {
    border: none;
    border-top: 1px solid var(--border-medium);
    margin: 16px 0;
}

/* Tables */
.ai-message table {
    width: 100%;
    border-collapse: collapse;
    margin: 10px 0;
    font-size: 13px;
    border: 1px solid var(--border-medium);
    /* Stronger border */
    background: transparent;
    /* No background */
    border-radius: 6px;
    overflow: hidden;
}

.ai-message th {
    background: transparent;
    /* No background */
    font-weight: 600;
    text-align: left;
    padding: 8px 12px;
    border-bottom: 2px solid var(--border-medium);
    /* Stronger separator */
    border-right: 1px solid var(--border-light);
    /* Column separation */
    color: var(--text-primary);
}

.ai-message th:last-child {
    border-right: none;
}

.ai-message td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-light);
    border-right: 1px solid var(--border-light);
    /* Column separation */
    color: var(--text-secondary);
    vertical-align: top;
    /* Align top for better reading */
}

.ai-message td:last-child {
    border-right: none;
}

.ai-message tr:last-child td {
    border-bottom: none;
}

/* Code Blocks */
.ai-message pre {
    background: #1e1e1e;
    color: #d4d4d4;
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 10px 0;
    font-family: 'Fira Code', monospace;
    font-size: 12px;
    position: relative;
}

.ai-message code {
    font-family: 'Fira Code', monospace;
    font-size: 12px;
    background: rgba(0, 0, 0, 0.06);
    padding: 2px 4px;
    border-radius: 4px;
    color: #e01e5a;
}

.ai-message pre code {
    background: transparent;
    color: inherit;
    padding: 0;
}

.user-message code {
    background: rgba(45, 90, 74, 0.1);
    /* Subtle green tint */
    color: var(--accent-primary);
}

/* Lists */
.ai-message ul,
.ai-message ol {
    margin: 8px 0;
    padding-left: 20px;
}

.ai-message li {
    margin-bottom: 4px;
}

/* Message Actions (Copy/Apply) */
.message-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    justify-content: flex-end;
    opacity: 0;
    /* Hidden by default until hover */
    transition: opacity 0.2s;
}

.ai-message:hover .message-actions {
    opacity: 1;
}

.action-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    background: transparent;
    border: 1px solid var(--border-medium);
    border-radius: 4px;
    padding: 2px 8px;
    cursor: pointer;
    font-size: 11px;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.action-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-primary);
}

.action-btn .material-icons {
    font-size: 14px;
}

/* Typing Indicator */
.typing-dots {
    display: inline-block;
}

.typing-dots span {
    animation: blink 1.4s infinite both;
    margin: 0 1px;
    font-size: 20px;
}

.typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes blink {
    0% {
        opacity: 0.2;
    }

    20% {
        opacity: 1;
    }

    100% {
        opacity: 0.2;
    }
}