/*
 * Chat Widget Styles v8
 * --------------------------------------------------
 * This file contains styles for the enhanced chat widget with role-based authentication,
 * sticky Chat Agent button, and improved user experience.
 */

.chat-widget-container {
    position: fixed;
    bottom: 25px; /* Slightly reduced for better balance */
    right: 25px; /* Slightly reduced for better balance */
    z-index: 1000;
    font-family: "Lato", sans-serif;
}

/* The main button to open/close the chat */
.chat-toggle-button {
    background: linear-gradient(45deg, #4542d5, #7a77ff);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 6px 16px rgba(69, 66, 213, 0.25);
    width: 58px; /* Increased from 52px - balanced between 52px and 65px */
    height: 58px; /* Increased from 52px - balanced between 52px and 65px */
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.4s cubic-bezier(0.68, -0.55, 0.27, 1.55);
    position: relative;
    overflow: visible; /* Changed to visible to show the dot */
}

.chat-toggle-button:hover {
    transform: scale(1.08); /* Slightly reduced scale for smaller button */
    box-shadow: 0 8px 20px rgba(69, 66, 213, 0.35);
}

.chat-toggle-button svg {
    position: absolute;
    width: 24px; /* Increased proportionally with button size */
    height: 24px; /* Increased proportionally with button size */
    transition: transform 0.3s ease-in-out, opacity 0.2s ease-in-out;
}

.chat-icon-close {
    transform: rotate(-90deg) scale(0.7);
    opacity: 0;
}

.chat-toggle-button.open .chat-icon-open {
    transform: rotate(90deg) scale(0.7);
    opacity: 0;
}

.chat-toggle-button.open .chat-icon-close {
    transform: rotate(0deg) scale(1);
    opacity: 1;
}

/* Notification Dot Styles */
.notification-dot {
    position: absolute;
    top: 0px;
    right: 0px;
    width: 12px;
    height: 12px;
    background-color: #ff3b30; /* A bright red color */
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    transform: scale(0); /* Hidden by default */
    transition: transform 0.3s ease;
}

.notification-dot.visible {
    transform: scale(1); /* Visible state */
}

/* The chat window itself */
.chat-window {
    position: absolute;
    bottom: 80px; /* Adjusted for new button size (58px + 22px spacing) */
    right: 0; /* Aligned with button for consistent spacing */
    width: 420px; /* Increased from 370px for larger appearance */
    max-width: calc(100vw - 50px); /* Consistent 25px margins on both sides */
    height: 860px; /* Increased from 480px for taller appearance */
    max-height: calc(
        100vh - 130px
    ); /* Balanced top clearance (25px top + 80px bottom + 25px buffer) */
    background-color: #ffffff;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    visibility: hidden;
    transition: all 0.4s ease-out;
}

.chat-window.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    visibility: visible;
}

/* Header of the chat window - Revamped to match reference */
.chat-header {
    background: #fff;
    color: #1a202c;
    padding: 12px 12px 12px 20px; /* Adjusted padding */
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    position: relative;
}

/* Navigation button for conversation history */
.chat-nav-button {
    background: none;
    border: none;
    color: #6b7280;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
}

.chat-nav-button:hover {
    background-color: #f3f4f6;
    color: #374151;
}

.chat-nav-button svg {
    width: 20px;
    height: 20px;
    transition: transform 0.2s ease;
}

/* Header title with navigation context */
.chat-header-title {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-grow: 1;
}

.chat-header-title h3 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
    padding: 0;
}

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

.header-action-btn {
    background: transparent;
    border: none;
    border-radius: 50%;
    color: #4a5568;
    width: 36px;
    height: 36px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
}

.header-action-btn:hover {
    background-color: #f1f5f9;
}

#close-chat-btn {
    font-size: 28px;
    font-weight: 400;
}

/* Area where messages appear */
.chat-body {
    flex-grow: 1;
    padding: 20px;
    overflow: hidden; /* Remove scrolling from chat-body */
    background-color: #fff;
    display: flex;
    flex-direction: column;
    gap: 15px;
    position: relative;
}

/* Block chat body scrolling when history view is active */
.chat-body.history-active {
    overflow: hidden;
    touch-action: none; /* Prevent touch scrolling on mobile */
}

/* Conversation History View */
.conversation-history-view {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #fff;
    padding: 0;
    overflow: hidden; /* Let child elements handle their own scrolling */
    transform: translateX(-100%);
    transition: transform 0.3s ease-in-out;
    z-index: 100;
    pointer-events: none; /* Disable interactions when hidden */
    display: flex;
    flex-direction: column;
}

.conversation-history-view.active {
    transform: translateX(0);
    pointer-events: auto; /* Enable interactions when active */
}

/* Conversation History List */
.conversation-list {
    padding: 0;
    margin: 0;
    list-style: none;
    flex-grow: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

.conversation-item {
    padding: 16px 20px;
    font-size: 1.25rem;
    border-bottom: 1px solid #f1f5f9;
    cursor: pointer;
    transition: background-color 0.2s ease;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.conversation-item:hover {
    background-color: #f8fafc;
}

.conversation-item.active {
    background-color: #eff6ff;
    border-left: 3px solid #4542d5;
}

.conversation-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.conversation-date {
    font-weight: 600;
    color: #374151;
}

.conversation-status {
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 500;
}

.conversation-status.active {
    background-color: #dcfce7;
    color: #166534;
}

.conversation-status.ended {
    background-color: #f3f4f6;
    color: #6b7280;
}

.conversation-preview {
    color: #6b7280;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2; /* Standard property for compatibility */
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* New Conversation Button */
.new-conversation-btn {
    margin: 16px 20px;
    padding: 12px 16px;
    background: linear-gradient(45deg, #4542d5, #7a77ff);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-shrink: 0; /* Prevent button from shrinking */
}

.new-conversation-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(69, 66, 213, 0.3);
}

/* Empty State for Conversation History */
.conversation-empty-state {
    padding: 40px 20px;
    text-align: center;
    color: #6b7280;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.conversation-empty-state h4 {
    margin: 0 0 8px 0;
    font-size: 1.125rem;
    font-weight: 600;
    color: #374151;
}

.conversation-empty-state p {
    margin: 0;
    font-size: 0.875rem;
    line-height: 1.5;
}

/* Main Chat View */
.main-chat-view {
    display: flex;
    flex-direction: column;
    gap: 5px;
    height: 100%;
    transition: transform 0.3s ease-in-out;
    position: relative;
    z-index: 1;
    overflow-y: auto; /* Apply scrolling only to main-chat-view */
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

.main-chat-view.blocked {
    pointer-events: none; /* Block interactions when history view is active */
    overflow: hidden; /* Prevent scrolling when blocked */
    touch-action: none; /* Prevent touch scrolling on mobile */
}

.main-chat-view.hidden {
    transform: translateX(100%);
}

/* Individual chat message styling */
.chat-message {
    padding: 0; /* Remove padding from container */
    max-width: 100%; /* Allow full width */
    line-height: 1.5;
    word-wrap: break-word;
    animation: messageFadeIn 0.5s ease-out forwards;
    opacity: 0;
    transform: translateY(10px);
    display: flex;
    gap: 12px; /* Gap between icon and content */
}

@keyframes messageFadeIn {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-message.user {
    justify-content: flex-end;
}

.chat-message.user .message-content {
    background: #4542d5;
    color: white;
    border-bottom-right-radius: 5px;
}

.bot-icon {
    width: 32px;
    height: 32px;
    background-color: #6366f1;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    flex-shrink: 0;
}

.message-content {
    padding: 12px 18px;
    border-radius: 12px;
    background-color: #f1f5f9;
    color: #1e293b;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* Suggestions section */
.chat-suggestions {
    padding-top: 10px;
    border-top: 1px solid #f1f5f9;
    margin-top: 10px;
}

.suggestions-title {
    font-size: 0.875rem;
    color: #64748b;
    margin-bottom: 12px;
}

.suggestion-btn {
    width: 100%;
    background-color: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 12px 15px;
    text-align: left;
    font-size: 1.3rem;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: 8px;
}

.suggestion-btn:hover {
    background-color: #f8fafc;
    border-color: #cbd5e1;
}

/* Footer with input and send button */
.chat-footer {
    padding: 12px 15px;
    background-color: #fff;
    border-top: 1px solid #e2e8f0;
    display: flex;
    gap: 10px;
    align-items: center;
}

.chat-footer input {
    flex-grow: 1;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 12px 15px;
    font-size: 15px;
    transition: all 0.3s ease;
    background-color: #fff;
    box-shadow: none;
}

.chat-footer input:focus {
    outline: none;
    border-color: #4542d5;
    box-shadow: 0 0 0 3px rgba(69, 66, 213, 0.15);
}

.chat-footer button {
    background: #f1f5f9;
    color: #4a5568;
    border: none;
    border-radius: 12px;
    width: 46px;
    height: 46px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s ease;
    box-shadow: none;
    flex-shrink: 0;
}

.chat-footer button:hover {
    background: #e2e8f0;
}

/* Chat Agent Button Styling - Modern Redesign */
.chat-agent-section {
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border-top: 1px solid #e2e8f0;
    flex-shrink: 0;
    z-index: 10;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.08);
    position: relative;
}

.chat-agent-section::before {
    content: "";
    position: absolute;
    top: 0;
    left: 20px;
    right: 20px;
    height: 1px;
    background: linear-gradient(
        90deg,
        transparent 0%,
        #e2e8f0 50%,
        transparent 100%
    );
}

.chat-agent-btn {
    width: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 12px;
    padding: 14px 20px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 14px rgba(102, 126, 234, 0.25);
}

.chat-agent-btn::before {
    content: "";
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.2),
        transparent
    );
    transition: left 0.5s ease;
}

.chat-agent-btn:hover {
    background: linear-gradient(135deg, #5a67d8 0%, #6b46c1 100%);
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.35);
}

.chat-agent-btn:hover::before {
    left: 100%;
}

.chat-agent-btn:active {
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(102, 126, 234, 0.25);
}

.chat-agent-btn svg {
    transition: transform 0.3s ease;
}

.chat-agent-btn:hover svg {
    transform: scale(1.1);
}

/* Chat Footer Disabled State */
.chat-footer-disabled {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.chat-footer-disabled input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid #e0e0e0;
    border-radius: 25px;
    font-size: 14px;
    background-color: #f5f5f5;
    color: #999;
    cursor: not-allowed;
}

.chat-footer-disabled button {
    background: #e0e0e0;
    color: #999;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: not-allowed;
}

/* Continue Session Button */
.continue-session-btn {
    margin-top: 15px;
    padding: 0;
    text-align: center;
}

.btn-continue-session {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 25px;
    padding: 12px 20px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.btn-continue-session:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
    background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
}

.btn-continue-session:active {
    transform: translateY(0);
    box-shadow: 0 2px 10px rgba(102, 126, 234, 0.3);
}

.btn-continue-session svg {
    width: 18px;
    height: 18px;
    stroke-width: 2;
}

/* System Messages */
.chat-message.system {
    display: flex;
    justify-content: center;
    margin: 10px 0;
    padding: 0;
}

.chat-message.system .message-content {
    background: rgba(108, 117, 125, 0.1);
    color: #6c757d;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.85em;
    font-style: italic;
    text-align: center;
    border: 1px solid rgba(108, 117, 125, 0.2);
    max-width: 80%;
}

.chat-message.system .message-content.system-message {
    background: rgba(23, 162, 184, 0.1);
    color: #17a2b8;
    border-color: rgba(23, 162, 184, 0.2);
}

/* Button State Management */
.chat-agent-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    pointer-events: none;
}

.btn-continue-session:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    pointer-events: none;
    transform: none !important;
}

/* Responsive Design for Mobile */
@media (max-width: 768px) {
    .chat-widget-container {
        bottom: 20px; /* Consistent spacing */
        right: 20px; /* Consistent spacing */
    }

    .chat-toggle-button {
        width: 52px; /* Proportionally scaled from desktop 58px */
        height: 52px;
    }

    .chat-toggle-button svg {
        width: 22px; /* Proportionally scaled from desktop 24px */
        height: 22px;
    }

    .chat-window {
        width: calc(100vw - 40px); /* Consistent 20px margins on both sides */
        max-width: none;
        right: 0; /* Aligned with button for consistent spacing */
        left: auto;
        margin: 0;
        height: auto; /* Auto height for mobile to adapt to content */
        max-height: calc(
            100vh - 120px
        ); /* Balanced clearance (20px top + 72px bottom + 28px buffer) */
        bottom: 72px; /* Adjusted for mobile button size (52px + 20px spacing) */
    }

    .chat-agent-section {
        padding: 16px 18px; /* Adjusted for modern design */
    }

    .chat-agent-btn {
        padding: 12px 16px; /* Adjusted for modern design */
        font-size: 14px;
    }

    .chat-footer {
        padding: 10px 12px;
    }

    .chat-body {
        padding: 16px;
    }

    /* Ensure main chat view scrolling works properly on mobile */
    .main-chat-view {
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        max-height: calc(100% - 20px); /* Account for padding */
    }
}

/* Additional mobile breakpoint for very small screens */
@media (max-width: 480px) {
    .chat-widget-container {
        bottom: 15px; /* Consistent spacing */
        right: 15px; /* Consistent spacing */
    }

    .chat-toggle-button {
        width: 48px; /* Proportionally scaled from tablet 52px */
        height: 48px;
    }

    .chat-toggle-button svg {
        width: 20px; /* Proportionally scaled from tablet 22px */
        height: 20px;
    }

    .chat-window {
        width: calc(100vw - 30px); /* Consistent 15px margins on both sides */
        right: 0; /* Aligned with button for consistent spacing */
        left: auto;
        margin: 0;
        height: auto; /* Auto height for small mobile to adapt to content */
        max-height: calc(
            100vh - 110px
        ); /* Balanced clearance (15px top + 63px bottom + 32px buffer) */
        bottom: 63px; /* Adjusted for small mobile button size (48px + 15px spacing) */
    }

    .chat-header {
        padding: 10px 10px 10px 16px;
    }

    .chat-header-title h3 {
        font-size: 1.25rem;
    }

    .chat-body {
        padding: 12px;
    }

    .chat-footer {
        padding: 8px 10px;
    }

    .chat-agent-section {
        padding: 14px 16px; /* Adjusted for modern design */
    }

    .chat-agent-btn {
        padding: 10px 14px;
        font-size: 13px;
    }
}
