/* ChatKit Product Assistant Styles v3.7.0 */
/* Features: Pink Theme, Bottom Right, Mobile Header Stability Fixes, Z-Index/Visibility Patch */

/* --- Utility (FIXED FOR PRODUCTION SPECIFICITY) --- */
/* We target the ID specifically to override any theme CSS forcing display:block */
.chatkit-hidden,
#chatkit-trigger.chatkit-hidden,
#chatkit-sidebar-wrapper.chatkit-hidden {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

/* --- Trigger Button (Bottom Right) --- */
.chatkit-trigger {
    position: fixed;
    bottom: 20px;
    right: 20px !important; /* Force Right */
    left: auto !important;  /* Reset Left */
    background: #E91E8C;    /* PINK */
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 25px;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    font-size: 14px;
    font-weight: 600;
    
    /* FIX: Lower Z-Index slightly so the Sidebar (at max int) always covers it */
    z-index: 2147483640;    
    
    transition: all 0.3s ease;
}

.chatkit-trigger:hover {
    background: #C2185B;    /* Darker Pink */
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}

/* --- Sidebar Container (Bottom Right) --- */
#chatkit-sidebar-wrapper {
    position: fixed;
    bottom: 20px;
    right: 20px !important; /* Force Right */
    left: auto !important;  /* Reset Left */
    width: 380px;
    max-height: 600px;
    height: calc(100% - 40px); /* Ensure it fits on small screens */
    
    /* FIX: Keep at Maximum Integer to ensure it is the top-most layer */
    z-index: 2147483647;    
    
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    border-radius: 12px;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

#chatkit-sidebar {
    background: white;
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* --- Header (CRITICAL MOBILE FIXES) --- */
.chatkit-header {
    background: #E91E8C; /* PINK */
    color: white;
    padding: 15px;
    
    /* FIX 1: Relative positioning to anchor the absolute close button */
    position: relative;
    
    /* FIX 2: Right padding so text doesn't go under the close button */
    padding-right: 90px;
    
    /* FIX 3: Flex setup */
    display: flex;
    justify-content: space-between;
    align-items: center;

    /* FIX 4: Prevent the header from shrinking/vanishing when chat content is long */
    flex-shrink: 0; 
    min-height: 60px; /* Force physical space */
}

.chatkit-header-content {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;       /* Take available space */
    overflow: hidden;  /* Ensure text truncates if too long */
}

/* Text Truncation for Product Title */
.chatkit-header-content div {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
}

.chatkit-icon {
    font-size: 24px;
    flex-shrink: 0; /* Keep icon size stable */
}

.chatkit-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.chatkit-subtitle {
    margin: 0;
    font-size: 12px;
    opacity: 0.9;
}

/* --- Close Button (Absolute Position) --- */
.chatkit-close {
    background: none;
    border: none;
    color: white;
    font-size: 28px; /* Large touch target */
    cursor: pointer;
    padding: 0;
    line-height: 1;
    
    /* FIX 5: Absolute Position. Pinned to the top-right. */
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    
    width: 40px; /* Explicit size */
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.chatkit-close:hover {
    opacity: 0.8;
}

/* --- Download Transcript Button --- */
.chatkit-download-btn {
    background: none;
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    position: absolute;
    right: 50px;
    top: 50%;
    transform: translateY(-50%);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    opacity: 0.85;
    transition: opacity 0.2s ease;
    border-radius: 4px;
}

.chatkit-download-btn:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.15);
}

.chatkit-download-btn.chatkit-btn-hidden {
    display: none;
}

/* --- Chat Area --- */
.chatkit-messages {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    background: #f5f5f5;
    /* Ensure scrolling works smoothly on mobile */
    -webkit-overflow-scrolling: touch; 
}

.chatkit-message {
    margin-bottom: 12px;
    display: flex;
}

.chatkit-message-content {
    padding: 10px 15px;
    border-radius: 8px;
    max-width: 85%;
    word-wrap: break-word;
    line-height: 1.5;
    font-size: 14px;
}

.chatkit-message-content a {
    color: inherit;
    text-decoration: underline;
}

.chatkit-user .chatkit-message-content {
    background: #E91E8C; /* PINK */
    color: white;
    margin-left: auto;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.chatkit-assistant .chatkit-message-content {
    background: white;
    color: #333;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

/* --- Quick Actions (Buttons) --- */
.chatkit-quick-starters {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 10px;
}

.chatkit-starter-btn {
    background: white;
    border: 1px solid #ddd;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    text-align: left;
    transition: all 0.2s;
    color: #333;
}

.chatkit-starter-btn .chatkit-btn-subtitle {
    display: block;
    font-size: 10px;
    color: #888;
    font-weight: 400;
    margin-top: 2px;
    line-height: 1.2;
}

.chatkit-starter-btn:hover {
    background: #E91E8C; /* PINK */
    color: white;
    border-color: #E91E8C;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.chatkit-starter-btn:hover .chatkit-btn-subtitle {
    color: rgba(255, 255, 255, 0.8);
}

.chatkit-back-btn {
    grid-column: span 2; 
    text-align: center;
    background-color: #f0f0f0;
    font-weight: 500;
}

.chatkit-back-btn:hover {
    background-color: #e0e0e0;
    color: #333;
    border-color: #bbb;
}

/* --- Utility Section (Compare, Analyze Doc, Image Analysis) --- */
.chatkit-utility-section {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #e8e8e8;
}

.chatkit-utility-btn {
    background: #f0f4ff;
    border-color: #d0d8f0;
}

.chatkit-utility-btn:hover {
    background: #E91E8C;
    color: white;
    border-color: #E91E8C;
}

/* --- Input Area --- */
.chatkit-input-wrapper {
    padding: 15px;
    background: white;
    border-top: 1px solid #e0e0e0;
    /* Ensure input area doesn't shrink */
    flex-shrink: 0; 
}

.chatkit-input-container {
    display: flex;
    gap: 8px;
    align-items: center;
}

#chatkit-input {
    flex: 1;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 16px; /* 16px prevents iOS Safari auto-zoom on focus */
    outline: none;
    -webkit-appearance: none; /* Mobile Safari fix */
}

#chatkit-input:focus {
    border-color: #E91E8C;
}

.chatkit-file-btn {
    padding: 8px 12px;
    background: #f0f0f0;
    border: 1px solid #ddd;
    border-radius: 6px;
    cursor: pointer;
    font-size: 18px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chatkit-file-btn:hover {
    background: #e0e0e0;
}

.chatkit-file-btn.chatkit-disabled {
    opacity: 0.4;
    pointer-events: none;
    cursor: not-allowed;
}

.chatkit-send-btn {
    padding: 10px 15px;
    background: #E91E8C; /* PINK */
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chatkit-send-btn:hover {
    background: #C2185B;
}

.chatkit-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#chatkit-input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    background: #f5f5f5;
    color: #999;
}

#chatkit-input:disabled::placeholder {
    color: #E91E8C;
    opacity: 0.8;
    font-weight: 500;
}

.chatkit-guest-notice {
    margin-top: 8px;
    font-size: 12px;
    color: #666;
    text-align: center;
}

.chatkit-guest-notice a {
    color: #E91E8C;
    text-decoration: none;
    font-weight: 600;
}

.chatkit-guest-notice a:hover {
    text-decoration: underline;
}

/* --- Attachments --- */
.chatkit-attachment-preview {
    padding: 10px 15px;
    background: #f9f9f9;
    border-top: 1px solid #e0e0e0;
    display: none;
}

.chatkit-attachment-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    background: white;
    border-radius: 4px;
    margin-bottom: 5px;
    border: 1px solid #e0e0e0;
}

.chatkit-attachment-icon {
    font-size: 20px;
}

.chatkit-attachment-name {
    flex: 1;
    font-size: 13px;
    color: #333;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chatkit-attachment-remove {
    margin-left: auto;
    background: none;
    border: none;
    color: #999;
    font-size: 18px;
    cursor: pointer;
    padding: 0 5px;
}

.chatkit-attachment-remove:hover {
    color: #d32f2f;
}

/* --- Form Styles --- */
.chatkit-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
}

.chatkit-form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chatkit-form-label {
    font-size: 12px;
    font-weight: 600;
    color: #555;
    margin-left: 2px;
}

.chatkit-form-input,
.chatkit-form-textarea {
    padding: 8px 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 16px; /* 16px prevents iOS Safari auto-zoom on focus */
    font-family: inherit;
    width: 100%;
    box-sizing: border-box;
    -webkit-appearance: none;
}

.chatkit-form-input:focus, 
.chatkit-form-textarea:focus {
    outline: none;
    border-color: #E91E8C;
    background-color: #fafafa;
}

.chatkit-form-textarea {
    resize: vertical;
    min-height: 60px;
}

.chatkit-form-submit {
    background: #E91E8C; /* PINK */
    color: white;
    border: none;
    padding: 10px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 5px;
    transition: background 0.2s;
}

.chatkit-form-submit:hover {
    background: #C2185B;
}

/* --- Animations --- */
.chatkit-typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 0;
}

.chatkit-typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #E91E8C;
    opacity: 0.6;
    animation: chatkit-typing-bounce 1.4s infinite ease-in-out both;
}

.chatkit-typing-indicator span:nth-child(1) {
    animation-delay: -0.32s;
}

.chatkit-typing-indicator span:nth-child(2) {
    animation-delay: -0.16s;
}

.chatkit-typing-indicator span:nth-child(3) {
    animation-delay: 0s;
}

@keyframes chatkit-typing-bounce {
    0%, 80%, 100% {
        transform: scale(0);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

.chatkit-thinking-indicator {
    animation: chatkit-fade-in 0.3s ease-in;
}

@keyframes chatkit-fade-in {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

#chatkit-status-message-wrapper {
    padding-top: 5px;
}

.chatkit-status-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 13px;
    color: #666;
    padding: 4px 0;
    margin-top: 5px;
    animation: chatkit-fade-in 0.3s ease-in;
}

.chatkit-status-icon {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 500;
    color: #C2185B;
}

.chatkit-status-time {
    font-size: 11px;
    color: #999;
    font-style: italic;
    margin-left: 20px;
}

.chatkit-progress-bar {
    width: 100%;
    height: 4px;
    background: #f0f0f0;
    border-radius: 2px;
    margin-top: 8px;
    overflow: hidden;
}

.chatkit-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #E91E8C 0%, #F48FB1 50%, #E91E8C 100%);
    background-size: 200% 100%;
    animation: progress-animation 1.5s ease-in-out infinite;
    border-radius: 2px;
}

@keyframes progress-animation {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

#streaming-message {
    animation: pulse-subtle 2s ease-in-out infinite;
}

@keyframes pulse-subtle {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.95; }
}

.chatkit-persistent-actions {
    border-top: 1px solid #e0e0e0;
    margin-top: 10px;
    padding-top: 10px;
    background: #f9f9f9 !important;
}

.chatkit-persistent-actions .chatkit-message-content {
    background: #f9f9f9 !important;
    box-shadow: none !important;
}

/* --- Document Type Badge --- */
.chatkit-doc-badge {
    display: inline-block;
    background: #e3f2fd;
    color: #1565c0;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.3px;
}

/* --- Comparison Prompt --- */
.chatkit-compare-prompt {
    padding: 12px;
}

.chatkit-compare-prompt p {
    margin: 0 0 4px 0;
    font-size: 14px;
}

.chatkit-compare-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 10px;
}

/* --- Comparison Table --- */
.chatkit-table-wrapper {
    overflow-x: auto;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
    margin: 8px 0;
}

.chatkit-comparison-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.chatkit-comparison-table th {
    background: #f5f5f5;
    font-weight: 600;
    padding: 8px 10px;
    text-align: left;
    border-bottom: 2px solid #ddd;
    white-space: nowrap;
}

.chatkit-comparison-table td {
    padding: 6px 10px;
    border-bottom: 1px solid #eee;
    vertical-align: top;
}

.chatkit-comparison-table tr:hover td {
    background: #fafafa;
}

/* --- Image Thumbnail in Attachment Preview --- */
.chatkit-attachment-thumb {
    width: 36px;
    height: 36px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid #e0e0e0;
    flex-shrink: 0;
}

/* --- Doc Label Badge (A/B in attachment preview) --- */
.chatkit-doc-label {
    background: #E91E8C;
    color: white;
    font-size: 10px;
    font-weight: 700;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* --- Responsive Adjustments --- */
@media (max-width: 480px) {
    #chatkit-sidebar-wrapper {
        width: 100% !important;
        height: 100%;       /* No !important — JS visualViewport handler overrides this */
        max-height: 100%;   /* No !important — allows JS keyboard resize */
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        border-radius: 0 !important;
    }

    .chatkit-quick-starters {
        grid-template-columns: 1fr;
    }

    /* Ensure the text truncates properly on really small screens */
    .chatkit-header-content {
        max-width: calc(100% - 80px);
    }

    .chatkit-header {
        border-radius: 0;
    }
}

/* --- Email Validation Error Styles --- */
.chatkit-input-error {
    border-color: #e53935 !important;
    box-shadow: 0 0 0 2px rgba(229, 57, 53, 0.15) !important;
}

.chatkit-email-error {
    color: #e53935;
    font-size: 12px;
    margin-top: 4px;
    line-height: 1.3;
}

.chatkit-email-suggestion {
    color: #E91E8C;
    text-decoration: underline;
    cursor: pointer;
    font-weight: 600;
}

.chatkit-email-suggestion:hover {
    color: #c2185b;
}