/* public/css/view.chat.css */

/* --- Floating Widget Container --- */
.chat-widget-container {
    position: fixed;
    bottom: 90px; /* Above the FAB */
    right: 20px;
    width: 400px;
    height: 600px;
    background-color: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.25);
    display: flex;
    flex-direction: column;
    z-index: 3000; /* High z-index to float above everything */
    overflow: hidden;
    transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1), opacity 0.3s ease;
    transform: translateY(120%); /* Hidden by default (slid down) */
    opacity: 0;
    pointer-events: none; /* Prevent clicking when hidden */
}

.chat-widget-container.active {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
}

/* --- Floating Action Button (FAB) --- */
.chat-fab {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background-color: var(--color-primary);
    color: white;
    border: none;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    font-size: 28px;
    cursor: pointer;
    z-index: 3001; /* Above the widget */
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, background-color 0.2s;
}

.chat-fab:hover {
    background-color: var(--color-primary-hover);
    transform: scale(1.05);
}

.chat-fab:active {
    transform: scale(0.95);
}

/* --- Chat Header --- */
.chat-header {
    background-color: var(--color-primary);
    color: var(--color-header-text);
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
}

.chat-controls button {
    background: transparent;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 16px;
    padding: 4px;
    border-radius: 4px;
    transition: background 0.2s;
}
.chat-controls button:hover {
    background-color: rgba(255,255,255,0.2);
}

/* --- Chat Body (Area for History + Input) --- */
.chat-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-color: var(--color-bg);
}

/* --- Chat History --- */
.chat-history-container {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* --- Messages --- */
.chat-message {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 0.9em;
    line-height: 1.4;
    word-wrap: break-word;
}

.chat-message.user {
    align-self: flex-end;
    background-color: var(--color-primary);
    color: white;
    border-bottom-right-radius: 2px;
}

.chat-message.assistant {
    align-self: flex-start;
    background-color: var(--color-bg-secondary);
    border: 1px solid var(--color-border-secondary);
    color: var(--color-text);
    border-bottom-left-radius: 2px;
    box-shadow: 0 1px 2px var(--color-shadow);
}

.chat-message.system {
    align-self: center;
    font-size: 0.8em;
    color: var(--color-text-secondary);
    background: rgba(0,0,0,0.05);
    padding: 6px 12px;
    border-radius: 12px;
    text-align: center;
    max-width: 95%;
}

/* Error Message Style */
.chat-message.error {
    align-self: center;
    background-color: rgba(220, 53, 69, 0.15);
    color: var(--color-danger);
    border: 1px solid var(--color-danger);
    border-radius: 8px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
}
.chat-message.error::before {
    content: '⚠️';
    font-size: 1.2em;
}

/* --- Image in Chat Styles --- */
.chat-image-container {
    margin: 5px 0;
}
.chat-image {
    max-width: 100%;
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.2);
}

/* --- Tool Usage Styles --- */
.tool-usage {
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.8em;
    margin-top: 6px;
    padding: 6px;
    background-color: rgba(0,0,0,0.05);
    border-left: 3px solid var(--color-success);
    border-radius: 4px;
    color: var(--color-text-secondary);
}
.tool-usage-header {
    font-weight: bold;
    display: flex;
    gap: 6px;
    margin-bottom: 2px;
}

/* --- Typing Indicator --- */
.typing-indicator-container {
    align-self: flex-start;
    background-color: var(--color-bg-secondary);
    border: 1px solid var(--color-border-secondary);
    padding: 12px 16px;
    border-radius: 12px;
    border-bottom-left-radius: 2px;
    box-shadow: 0 1px 2px var(--color-shadow);
    display: flex;
    align-items: center;
    width: fit-content;
}

.typing-dot {
    height: 8px;
    width: 8px;
    margin: 0 2px;
    background-color: var(--color-text-secondary);
    border-radius: 50%;
    display: inline-block;
    animation: typing-blink 1.4s infinite both;
}

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

@keyframes typing-blink {
    0% { opacity: 0.2; transform: scale(0.8); }
    20% { opacity: 1; transform: scale(1); }
    100% { opacity: 0.2; transform: scale(0.8); }
}

/* --- Input Area --- */
.chat-input-area {
    padding: 12px;
    background-color: var(--color-bg-secondary);
    border-top: 1px solid var(--color-border);
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

#chat-input {
    flex: 1;
    padding: 10px;
    border-radius: 20px;
    border: 1px solid var(--color-border);
    background-color: var(--color-bg);
    color: var(--color-text);
    resize: none;
    min-height: 20px;
    max-height: 100px;
    font-family: inherit;
    font-size: 0.95em;
}
#chat-input:focus {
    outline: none;
    border-color: var(--color-primary);
}

/* Attach File Button */
#btn-chat-attach {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background-color: transparent;
    color: var(--color-text-secondary);
    font-size: 1.4em;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, color 0.2s;
    margin-bottom: 2px; /* Align with textarea bottom */
}
#btn-chat-attach:hover {
    background-color: var(--color-bg-accent);
    color: var(--color-text);
}

#btn-send-chat {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background-color: var(--color-primary);
    color: white;
    font-size: 1.2em;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}
#btn-send-chat:hover {
    background-color: var(--color-primary-hover);
}
#btn-send-chat:disabled {
    background-color: var(--color-text-secondary);
    cursor: not-allowed;
}

/* --- File Preview Area --- */
#chat-file-preview {
    padding: 10px 15px;
    background-color: var(--color-bg-accent);
    border-top: 1px solid var(--color-border);
    display: flex;
    align-items: center;
}

.preview-item {
    display: flex;
    align-items: center;
    gap: 10px;
    background-color: var(--color-bg-secondary);
    padding: 6px 12px;
    border-radius: 8px;
    border: 1px solid var(--color-border);
    max-width: 100%;
}

.preview-item img {
    height: 32px;
    width: 32px;
    object-fit: cover;
    border-radius: 4px;
}

.file-icon {
    font-size: 24px;
}

.file-name {
    font-size: 0.85em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

.btn-remove-attachment {
    background: transparent;
    border: none;
    color: var(--color-text-secondary);
    font-size: 1.2em;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}
.btn-remove-attachment:hover {
    color: var(--color-danger);
}

/* --- Markdown Styling inside bubbles --- */
.chat-message pre {
    background-color: rgba(0,0,0,0.1);
    padding: 8px;
    border-radius: 4px;
    overflow-x: auto;
    font-family: monospace;
    font-size: 0.9em;
    margin: 6px 0;
}
.chat-message code {
    font-family: monospace;
    background-color: rgba(0,0,0,0.1);
    padding: 2px 4px;
    border-radius: 3px;
}

/* --- Mobile Responsive --- */
@media (max-width: 480px) {
    .chat-widget-container {
        width: 100%;
        height: 100%;
        bottom: 0;
        right: 0;
        border-radius: 0;
        transform: translateY(100%);
    }
    .chat-fab {
        bottom: 20px;
        right: 20px;
    }
}