/**
 * SP Live Chat - Frontend Styles
 * Chat widget for visitors
 */

/* Chat Widget */
.sp-chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 380px;
    max-width: calc(100vw - 40px);
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    z-index: 999999;
    display: flex;
    flex-direction: column;
    max-height: 600px;
    box-sizing: border-box;
}

.sp-chat-widget-header {
    background: linear-gradient(135deg, #002868 0%, #001a47 100%);
    color: white;
    padding: 16px 20px;
    border-radius: 12px 12px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-sizing: border-box;
}

.sp-chat-widget-title {
    font-size: 16px;
    font-weight: 600;
    flex: 1;
}

.sp-chat-widget-test-sound {
    background: none;
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    padding: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.7;
    transition: opacity 0.2s;
    margin-left: 8px;
}

.sp-chat-widget-test-sound:hover {
    opacity: 1;
}

.sp-chat-widget-minimize,
.sp-chat-widget-close {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.8;
    transition: opacity 0.2s;
    margin-left: 8px;
}

.sp-chat-widget-minimize:hover,
.sp-chat-widget-close:hover {
    opacity: 1;
}

.sp-chat-widget-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #F8FAFC;
    min-height: 300px;
    max-height: 400px;
    box-sizing: border-box;
}

.sp-chat-widget-message {
    margin-bottom: 15px;
    display: flex;
}

.sp-chat-widget-message.admin {
    justify-content: flex-start;
}

.sp-chat-widget-message.visitor {
    justify-content: flex-end;
}

.sp-chat-widget-bubble {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 12px;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.sp-chat-widget-message.admin .sp-chat-widget-bubble {
    background: #002868;
    color: white;
}

.sp-chat-widget-message.visitor .sp-chat-widget-bubble {
    background: white;
    color: #1E293B;
    border: 1px solid #E2E8F0;
}

.sp-chat-widget-sender {
    font-size: 11px;
    font-weight: 600;
    margin-bottom: 4px;
    opacity: 0.8;
}

.sp-chat-widget-text {
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.sp-chat-widget-input {
    padding: 16px;
    border-top: 1px solid #E2E8F0;
    display: flex;
    gap: 10px;
    box-sizing: border-box;
}

.sp-chat-widget-input textarea {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid #CBD5E0;
    border-radius: 6px;
    font-size: 14px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    resize: none;
    box-sizing: border-box;
    min-height: 42px;
    max-height: 42px;
    height: 42px;
    overflow-y: auto;
}

.sp-chat-widget-input textarea:focus {
    outline: none;
    border-color: #002868;
}

.sp-chat-widget-input button {
    background: #d3302d;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
    box-sizing: border-box;
}

.sp-chat-widget-input button:hover {
    background: #b8271f;
}

/* Chat Button (minimized state) */
.sp-chat-button {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #002868 0%, #001a47 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    z-index: 999998;
    transition: transform 0.2s;
}

.sp-chat-button:hover {
    transform: scale(1.1);
}

.sp-chat-button .dashicons {
    color: white;
    font-size: 28px;
    width: 28px;
    height: 28px;
}

.sp-chat-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #BF0A30;
    color: white;
    border-radius: 12px;
    padding: 4px 8px;
    font-size: 12px;
    font-weight: 600;
    min-width: 24px;
    text-align: center;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    /* Force viewport containment - AGGRESSIVE FIX */
    .sp-chat-widget {
        position: fixed !important;
        width: 100vw !important;
        max-width: 100vw !important;
        min-width: auto !important;
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        border-radius: 12px 12px 0 0 !important;
        max-height: 80vh !important;
        box-sizing: border-box !important;
        overflow-x: hidden !important;
        transform: translateX(0) !important;
    }
    
    .sp-chat-widget * {
        box-sizing: border-box !important;
    }
    
    .sp-chat-widget-header {
        padding: 14px 12px !important;
        width: 100% !important;
        max-width: 100% !important;
    }
    
    .sp-chat-widget-title {
        font-size: 14px !important;
    }
    
    .sp-chat-widget-test-sound {
        width: 24px !important;
        height: 24px !important;
        font-size: 16px !important;
        margin-left: 4px !important;
        flex-shrink: 0 !important;
    }
    
    .sp-chat-widget-minimize,
    .sp-chat-widget-close {
        width: 24px !important;
        height: 24px !important;
        font-size: 20px !important;
        margin-left: 4px !important;
        flex-shrink: 0 !important;
    }
    
    .sp-chat-widget-messages {
        max-height: calc(80vh - 180px) !important;
        padding: 12px !important;
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: hidden !important;
    }
    
    .sp-chat-widget-input {
        padding: 10px !important;
        width: 100% !important;
        max-width: 100% !important;
        display: flex !important;
        gap: 6px !important;
        flex-shrink: 0 !important;
    }
    
    .sp-chat-widget-input textarea {
        font-size: 16px !important; /* Prevents zoom on iOS */
        padding: 10px !important;
        flex: 1 1 0% !important;
        min-width: 0 !important;
        max-width: none !important;
        width: 0 !important; /* Force flex to calculate width */
    }
    
    .sp-chat-widget-input button {
        flex: 0 0 auto !important;
        flex-shrink: 0 !important;
        flex-grow: 0 !important;
        padding: 10px 14px !important;
        min-width: 60px !important;
        max-width: 70px !important;
        white-space: nowrap !important;
        overflow: hidden !important;
    }
    
    .sp-chat-button {
        bottom: 15px !important;
        right: 15px !important;
        width: 56px !important;
        height: 56px !important;
    }
}