/**
 * Portal Chat Widget Styles
 *
 * Floating "Ask Sarah" chat widget for client portal users.
 *
 * DOC-CHANGE: 2026-01-11 - Claude - Initial chat widget styles for RAG Chat feature
 * DOC-CHANGE: 2026-01-11 - Claude - Added resize handle styles for top-left corner resize
 * DOC-CHANGE: 2026-01-11 - Claude - Added blockquote styles for document citations
 */

/* Chat Toggle Button */
.portal-chat-toggle {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(79, 70, 229, 0.4);
    transition: all 0.3s ease;
    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;
}

.portal-chat-toggle:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 24px rgba(79, 70, 229, 0.5);
}

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

.portal-chat-toggle-icon {
    width: 28px;
    height: 28px;
    fill: white;
}

.portal-chat-toggle-close {
    display: none;
}

.portal-chat-toggle.open .portal-chat-toggle-chat {
    display: none;
}

.portal-chat-toggle.open .portal-chat-toggle-close {
    display: block;
}

/* Chat Widget Container */
.portal-chat-widget {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 380px;
    min-width: 320px;
    max-width: calc(100vw - 48px);
    height: 520px;
    min-height: 400px;
    max-height: calc(100vh - 150px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    display: none;
    flex-direction: column;
    overflow: hidden;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Resize Handle - Top Left Corner */
.portal-chat-resize {
    position: absolute;
    top: 0;
    left: 0;
    width: 20px;
    height: 20px;
    cursor: nwse-resize;
    z-index: 10;
    background: transparent;
}

.portal-chat-resize::before {
    content: '';
    position: absolute;
    top: 4px;
    left: 4px;
    width: 8px;
    height: 8px;
    border-left: 2px solid rgba(255, 255, 255, 0.6);
    border-top: 2px solid rgba(255, 255, 255, 0.6);
    border-radius: 2px 0 0 0;
    opacity: 0;
    transition: opacity 0.2s;
}

.portal-chat-widget:hover .portal-chat-resize::before {
    opacity: 1;
}

.portal-chat-widget.resizing {
    user-select: none;
}

.portal-chat-widget.resizing .portal-chat-resize::before {
    opacity: 1;
    border-color: rgba(255, 255, 255, 0.9);
}

.portal-chat-widget.open {
    display: flex;
    animation: chatSlideIn 0.3s ease;
}

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

/* Chat Header */
.portal-chat-header {
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.portal-chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.portal-chat-header-info {
    flex: 1;
}

.portal-chat-header-name {
    font-weight: 600;
    font-size: 16px;
    margin-bottom: 2px;
}

.portal-chat-header-status {
    font-size: 12px;
    opacity: 0.9;
}

.portal-chat-header-clear {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    padding: 6px 10px;
    border-radius: 6px;
    color: white;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.2s;
}

.portal-chat-header-clear:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Chat Messages Area */
.portal-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: #f9fafb;
}

/* Message Bubbles */
.portal-chat-message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 16px;
    line-height: 1.5;
    font-size: 14px;
}

.portal-chat-message.user {
    align-self: flex-end;
    background: #4f46e5;
    color: white;
    border-bottom-right-radius: 4px;
}

.portal-chat-message.assistant {
    align-self: flex-start;
    background: white;
    color: #1f2937;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.portal-chat-message.welcome {
    text-align: center;
    align-self: center;
    max-width: 90%;
    background: transparent;
    color: #6b7280;
    font-size: 13px;
    padding: 8px;
}

/* Typing Indicator */
.portal-chat-typing {
    display: none;
    align-self: flex-start;
    background: white;
    padding: 12px 16px;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.portal-chat-typing.active {
    display: flex;
    gap: 4px;
    align-items: center;
}

.portal-chat-typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #9ca3af;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.portal-chat-typing-dot:nth-child(1) {
    animation-delay: 0s;
}

.portal-chat-typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.portal-chat-typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

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

/* Sources */
.portal-chat-sources {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid #e5e7eb;
}

.portal-chat-sources-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #6b7280;
    margin-bottom: 6px;
}

.portal-chat-source-tag {
    display: block;
    background: #f3f4f6;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 11px;
    color: #4b5563;
    margin-bottom: 4px;
    line-height: 1.4;
    border-left: 3px solid #4f46e5;
}

/* Chat Input Area */
.portal-chat-input-area {
    padding: 16px 20px;
    background: white;
    border-top: 1px solid #e5e7eb;
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.portal-chat-input {
    flex: 1;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 12px 16px;
    font-size: 14px;
    resize: none;
    max-height: 100px;
    min-height: 44px;
    line-height: 1.4;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
}

.portal-chat-input:focus {
    border-color: #4f46e5;
}

.portal-chat-input::placeholder {
    color: #9ca3af;
}

.portal-chat-send {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: #4f46e5;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.portal-chat-send:hover:not(:disabled) {
    background: #4338ca;
}

.portal-chat-send:disabled {
    background: #9ca3af;
    cursor: not-allowed;
}

.portal-chat-send svg {
    width: 20px;
    height: 20px;
    fill: white;
}

/* Error State */
.portal-chat-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #dc2626;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 13px;
    margin: 10px 20px;
    display: none;
}

.portal-chat-error.visible {
    display: block;
}

/* Markdown Formatting */
.portal-chat-message.assistant h2 {
    font-size: 16px;
    font-weight: 600;
    margin: 12px 0 8px 0;
}

.portal-chat-message.assistant h2:first-child {
    margin-top: 0;
}

.portal-chat-message.assistant ul {
    margin: 8px 0;
    padding-left: 20px;
}

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

.portal-chat-message.assistant strong {
    font-weight: 600;
}

.portal-chat-message.assistant p {
    margin: 8px 0;
}

.portal-chat-message.assistant p:first-child {
    margin-top: 0;
}

.portal-chat-message.assistant p:last-child {
    margin-bottom: 0;
}

/* Blockquote for document citations */
.portal-chat-quote {
    margin: 10px 0;
    padding: 10px 14px;
    background: #f8fafc;
    border-left: 3px solid #4f46e5;
    border-radius: 0 6px 6px 0;
    font-style: italic;
    color: #374151;
}

.portal-chat-quote p {
    margin: 4px 0;
}

.portal-chat-quote p:first-child {
    margin-top: 0;
}

.portal-chat-quote p:last-child {
    margin-bottom: 0;
    font-style: normal;
    font-size: 11px;
    color: #6b7280;
    margin-top: 8px;
}

/* Mobile Responsive */
@media (max-width: 480px) {
    .portal-chat-widget {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100% !important;
        max-width: 100%;
        height: 100% !important;
        max-height: 100%;
        border-radius: 0;
    }

    .portal-chat-toggle {
        bottom: 16px;
        right: 16px;
        width: 56px;
        height: 56px;
    }

    .portal-chat-widget.open {
        animation: none;
    }

    .portal-chat-resize {
        display: none;
    }
}
