/* Chat Interface for Assistant */

/* Chat Container */
.assistant-chat-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 640px;
    height: 600px;
    min-width: 300px;
    min-height: 400px;
    max-width: 95vw;
    max-height: 90vh;
    background-color: white;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    display: none;
    flex-direction: column;
    z-index: 1000;
    transition: width 0.1s ease, height 0.1s ease, opacity 0.3s ease;
    overflow: hidden;
}

/* Resize Handles (PC Only) */
@media (min-width: 769px) {
    .assistant-chat-container::before {
        content: "";
        position: absolute;
        top: 0;
        left: 0;
        width: 8px; /* Slightly thinner for precision */
        height: 100%;
        cursor: w-resize;
        z-index: 1001;
    }

    .assistant-chat-container::after {
        content: "";
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 8px;
        cursor: n-resize;
        z-index: 1001;
    }

    .assistant-resize-corner {
        position: absolute;
        top: 0;
        left: 0;
        width: 16px;
        height: 16px;
        cursor: nw-resize;
        z-index: 1002;
        background: transparent;
    }
}

.assistant-chat-container.resizing {
    transition: none !important;
    user-select: none;
}

.assistant-chat-container.resizing * {
    user-select: none;
    pointer-events: none;
}

.assistant-chat-container.show {
    display: flex;
    animation: fadeIn 0.3s ease;
}

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

/* Chat Header */
.assistant-chat-header {
    padding: 12px 20px;
    background-color: #3b82f6;
    color: white;
    border-radius: 12px 12px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    cursor: grab;
    user-select: none;
    touch-action: none;
    position: relative;
}

.assistant-chat-header:active {
    cursor: grabbing;
}

.assistant-chat-container.closing {
    animation: fadeOut 0.2s ease forwards;
}

.assistant-chat-container.closing-mobile {
    animation: slideDownOut 0.3s ease forwards;
}

.assistant-chat-title-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.assistant-chat-title {
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.assistant-chat-title svg {
    width: 20px;
    height: 20px;
}

.assistant-provider-badge {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 10px;
    background-color: rgba(255, 255, 255, 0.2);
    padding: 2px 8px;
    border-radius: 10px;
    width: fit-content;
    transition: background-color 0.2s;
}

.provider-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: #10B981; /* Green for API */
}

.assistant-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.assistant-chat-close {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.assistant-chat-close:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.assistant-chat-close svg {
    width: 20px;
    height: 20px;
}

/* Messages Container */
.assistant-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Message Bubbles */
.assistant-message {
    max-width: 95%;
    width: fit-content;
    word-wrap: break-word;
    display: flex;
    flex-direction: column;
}

.assistant-message.user {
    align-self: flex-end;
}

.assistant-message.assistant {
    align-self: flex-start;
    width: 100%;
}

.assistant-message-bubble {
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.5;
    width: 100%; /* Make bubble responsive to message container */
    box-sizing: border-box;
}

.assistant-message.user .assistant-message-bubble {
    background-color: #3b82f6;
    color: white;
    border-bottom-right-radius: 4px;
    width: auto; /* User messages stay compact */
    align-self: flex-end;
}

.assistant-message.assistant .assistant-message-bubble {
    background-color: #F3F4F6;
    color: #1F2937;
    border-bottom-left-radius: 4px;
    width: 100%; /* Assistant reports fill the width */
}

/* Table styling for reports */
.assistant-message-bubble table {
    width: 100%;
    min-width: 280px;
    border-collapse: collapse;
    margin: 10px 0;
    font-size: 13px;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.assistant-message-bubble th {
    background-color: #F9FAFB;
    color: #374151;
    font-weight: 600;
    text-align: left;
    padding: 8px 12px;
    border-bottom: 1px solid #E5E7EB;
}

.assistant-message-bubble td {
    padding: 8px 12px;
    border-bottom: 1px solid #F3F4F6;
    color: #4B5563;
    white-space: nowrap;
}

.assistant-message-bubble tr:last-child td {
    border-bottom: none;
}

.assistant-message-bubble .table-container {
    overflow-x: auto;
    margin: 10px 0;
    border-radius: 8px;
}

/* Formatted content inside bubbles */
.assistant-message-bubble strong {
    color: #2563eb; /* Blue-600 */
    font-weight: 700;
}

.assistant-message-bubble ul {
    margin: 8px 0;
    padding-left: 20px;
    list-style-type: disc;
}

.assistant-message-bubble li {
    margin-bottom: 4px;
}

.assistant-message-bubble .data-label {
    color: #6b7280; /* Gray-500 */
    font-size: 0.85em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.assistant-message-bubble .highlight-green {
    color: #059669; /* Green-600 */
}

.assistant-message-bubble .highlight-red {
    color: #dc2626; /* Red-600 */
}

.assistant-message-time {
    font-size: 11px;
    color: #9CA3AF;
    margin-top: 4px;
    padding: 0 14px;
}

.assistant-message.user .assistant-message-time {
    text-align: right;
}

/* Quick Actions */
.assistant-quick-actions {
    padding: 8px 16px;
    display: flex;
    gap: 8px;
    overflow-x: auto;
    scrollbar-width: none; /* Hide scrollbar for Firefox */
    -ms-overflow-style: none; /* Hide scrollbar for IE/Edge */
    border-top: 1px solid #F3F4F6;
    background-color: white;
}

.assistant-quick-actions::-webkit-scrollbar {
    display: none; /* Hide scrollbar for Chrome/Safari */
}

.quick-action-btn {
    white-space: nowrap;
    padding: 6px 12px;
    background-color: #F3F4F6;
    border: 1px solid #E5E7EB;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 500;
    color: #3B82F6;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all 0.2s ease;
}

.quick-action-btn:hover {
    background-color: #E5E7EB;
    border-color: #D1D5DB;
    transform: translateY(-1px);
}

.quick-action-btn svg {
    flex-shrink: 0;
}

/* Typing Indicator */
.assistant-typing {
    display: none;
    align-items: center;
    gap: 4px;
    padding: 12px 20px;
    background-color: #E5E7EB;
    border: 1px solid #D1D5DB;
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    max-width: 250px;
    margin: 0 20px 12px 20px;
}

.assistant-typing.show {
    display: flex;
}

.assistant-typing span {
    width: 8px;
    height: 8px;
    background-color: #6B7280;
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

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

/* Input Container */
.assistant-input-container {
    padding: 16px;
    border-top: 1px solid #E5E7EB;
    display: flex;
    gap: 8px;
}

.assistant-input {
    flex: 1;
    padding: 8px 16px;
    border: 1px solid #D1D5DB;
    border-radius: 20px;
    font-size: 14px;
    outline: none;
}

.assistant-submit {
    background-color: #3b82f6;
    color: white;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

/* FAB */
.assistant-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 999;
}

.assistant-fab.hidden {
    display: none;
}

.assistant-fab-button {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background-color: #3b82f6;
    color: white;
    border: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.assistant-fab-button svg {
    width: 28px;
    height: 28px;
}

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

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

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .assistant-chat-container {
        width: 100%;
        height: 100%;
        bottom: 0;
        right: 0;
        border-radius: 0;
    }
    
    .assistant-chat-container.show {
        animation: slideUpMobile 0.3s ease;
    }
    
    .assistant-chat-header {
        border-radius: 0;
        padding: 16px 20px;
    }
    
    .assistant-fab {
        bottom: 16px;
        right: 16px;
    }
}

@keyframes slideUpMobile {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

@keyframes slideDownOut {
    from { transform: translateY(0); opacity: 1; }
    to { transform: translateY(100%); opacity: 0; }
}
