/**
 * Frontend CSS for WP LiveChat
 */

/* Chat Widget Container */
.wp-livechat-widget {
    position: fixed;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    font-size: 14px;
    line-height: 1.4;
    color: #333;
}

.wp-livechat-widget * {
    box-sizing: border-box;
}

/* Position variants */
.wp-livechat-bottom-right {
    bottom: 20px;
    right: 20px;
}

.wp-livechat-bottom-left {
    bottom: 20px;
    left: 20px;
}

/* Mobile override - ALWAYS above system UI */
@media (max-width: 768px) {
    .wp-livechat-bottom-right,
    .wp-livechat-bottom-left {
        bottom: 120px !important;
        z-index: 9999999 !important;
        position: fixed !important;
    }
    
    .android .wp-livechat-bottom-right,
    .android .wp-livechat-bottom-left {
        bottom: 140px !important;
    }
}

/* Chat Toggle Button */
.wp-livechat-toggle {
    width: 60px;
    height: 60px;
    background: var(--primary-color, #007cba);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: all 0.3s ease;
    position: relative;
}

.wp-livechat-toggle:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

.wp-livechat-toggle.active {
    background: #666;
}

.wp-livechat-toggle-icon {
    color: white;
    width: 24px;
    height: 24px;
}

/* Notification Badge */
.wp-livechat-notification {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff4444;
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    min-width: 20px;
    padding: 2px;
}

/* Chat Window */
.wp-livechat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 350px;
    height: 500px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 999999;
}

.wp-livechat-bottom-left .wp-livechat-window {
    right: auto;
    left: 0;
}

/* Chat Header */
.wp-livechat-header {
    background: var(--primary-color, #007cba);
    color: white;
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.wp-livechat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.wp-livechat-avatar {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.wp-livechat-title {
    font-weight: 600;
    font-size: 16px;
    margin: 0;
}

.wp-livechat-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    opacity: 0.9;
}

.wp-livechat-status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ccc;
    transition: background-color 0.3s ease;
}

.wp-livechat-status-indicator.online {
    background: #4CAF50;
}

.wp-livechat-controls {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.wp-livechat-btn {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    min-height: 32px;
}

.wp-livechat-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Chat Body */
.wp-livechat-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Messages Container */
.wp-livechat-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    background: #f8f9fa;
}

.wp-livechat-welcome {
    text-align: center;
    color: #666;
    padding: 20px 0;
}

.wp-livechat-welcome-message {
    font-style: italic;
}

/* Individual Messages */
.wp-livechat-message {
    margin-bottom: 12px;
    display: flex;
}

.wp-livechat-message-visitor {
    justify-content: flex-end;
}

.wp-livechat-message-admin {
    justify-content: flex-start;
}

.wp-livechat-message-content {
    max-width: 80%;
    padding: 8px 12px;
    border-radius: 18px;
    position: relative;
}

.wp-livechat-message-visitor .wp-livechat-message-content {
    background: var(--primary-color, #007cba);
    color: white;
    border-bottom-right-radius: 4px;
}

.wp-livechat-message-admin .wp-livechat-message-content {
    background: white;
    color: #333;
    border: 1px solid #e0e0e0;
    border-bottom-left-radius: 4px;
}

.wp-livechat-message-text {
    word-wrap: break-word;
    line-height: 1.4;
}

.wp-livechat-message-time {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 4px;
    text-align: right;
}

.wp-livechat-message-admin .wp-livechat-message-time {
    text-align: left;
}

/* Login Form */
.wp-livechat-login {
    padding: 20px;
    background: white;
    border-top: 1px solid #e0e0e0;
}

.wp-livechat-login-form h3 {
    margin: 0 0 16px 0;
    font-size: 16px;
    color: #333;
}

.wp-livechat-form-group {
    margin-bottom: 16px;
}

.wp-livechat-form-group label {
    display: block;
    margin-bottom: 4px;
    font-weight: 500;
    color: #555;
}

.wp-livechat-form-group input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.2s ease;
}

.wp-livechat-form-group input:focus {
    outline: none;
    border-color: var(--primary-color, #007cba);
    box-shadow: 0 0 0 3px rgba(0, 124, 186, 0.1);
}

.wp-livechat-btn-primary {
    width: 100%;
    background: var(--primary-color, #007cba);
    color: white;
    border: none;
    padding: 10px 16px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.wp-livechat-btn-primary:hover {
    background: #005a87;
}

.wp-livechat-btn-primary:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* Input Area */
.wp-livechat-input-area {
    padding: 16px;
    background: white;
    border-top: 1px solid #e0e0e0;
    flex-shrink: 0;
}

.wp-livechat-input-wrapper {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.wp-livechat-input-wrapper input {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 20px;
    font-size: 14px;
    resize: none;
    outline: none;
    transition: border-color 0.2s ease;
}

.wp-livechat-input-wrapper input:focus {
    border-color: var(--primary-color, #007cba);
}

.wp-livechat-btn-send {
    background: var(--primary-color, #007cba);
    color: white;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s ease;
    flex-shrink: 0;
}

.wp-livechat-btn-send:hover {
    background: #005a87;
}

/* Typing Indicator */
.wp-livechat-typing-indicator {
    padding: 8px 12px;
    color: #666;
    font-style: italic;
    font-size: 12px;
    background: #f0f0f0;
    border-radius: 12px;
    margin-top: 8px;
    display: inline-block;
}

/* Loading States */
.wp-livechat-loading {
    text-align: center;
    color: #666;
    padding: 20px;
    font-style: italic;
}

/* Mobile Responsive Design */
@media (max-width: 768px) {
    .wp-livechat-window {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        /* Use viewport height minus safe areas */
        height: 100vh !important;
        height: calc(100vh - env(safe-area-inset-bottom)) !important;
        height: calc(100dvh - env(safe-area-inset-bottom)) !important; /* Dynamic viewport height */
        border-radius: 0 !important;
        z-index: 9999999 !important;
        padding-bottom: env(safe-area-inset-bottom, 0px) !important;
    }
    
    /* Fix header controls overlap on mobile */
    .wp-livechat-header {
        padding: 10px 12px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        gap: 10px !important;
    }
    
    .wp-livechat-header-info {
        flex: 1 !important;
        min-width: 0 !important;
        overflow: hidden !important;
        display: flex !important;
        align-items: center !important;
        gap: 8px !important;
    }
    
    .wp-livechat-avatar {
        width: 28px !important;
        height: 28px !important;
        flex-shrink: 0 !important;
    }
    
    .wp-livechat-header-text {
        flex: 1 !important;
        min-width: 0 !important;
        overflow: hidden !important;
    }
    
    .wp-livechat-title {
        font-size: 14px !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        margin: 0 !important;
    }
    
    .wp-livechat-status {
        font-size: 11px !important;
        white-space: nowrap !important;
    }
    
    .wp-livechat-controls {
        display: flex !important;
        gap: 8px !important;
        flex-shrink: 0 !important;
        margin-left: auto !important;
    }
    
    .wp-livechat-btn {
        min-width: 40px !important;
        min-height: 40px !important;
        width: 40px !important;
        height: 40px !important;
        padding: 8px !important;
        flex-shrink: 0 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
    
    .wp-livechat-btn svg {
        width: 18px !important;
        height: 18px !important;
        flex-shrink: 0 !important;
    }
    
    /* Adjust chat body to prevent overlap */
    .wp-livechat-body {
        height: calc(100vh - 70px - 120px) !important; /* header - input - safe area */
        max-height: calc(100vh - 70px - 120px) !important;
        overflow: hidden !important;
    }
    
    /* Messages area should scroll */
    .wp-livechat-messages {
        max-height: calc(100vh - 70px - 140px) !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    .wp-livechat-bottom-left .wp-livechat-window {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
    }
    
    /* Center login form on mobile */
    .wp-livechat-login {
        display: flex;
        align-items: center;
        justify-content: center;
        min-height: 100vh;
        padding: 20px;
        background: #f8f9fa;
    }
    
    /* Allow hiding when chat starts */
    .wp-livechat-login[style*="display: none"],
    .wp-livechat-login[style*="display:none"] {
        display: none !important;
        visibility: hidden !important;
        opacity: 0 !important;
        height: 0 !important;
        overflow: hidden !important;
    }
    
    .wp-livechat-login-form {
        background: white !important;
        padding: 30px !important;
        border-radius: 12px !important;
        box-shadow: 0 4px 20px rgba(0,0,0,0.1) !important;
        width: 100% !important;
        max-width: 400px !important;
        margin: 0 auto !important;
    }
    
    /* Center welcome message */
    .wp-livechat-welcome {
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        min-height: 100vh !important;
        text-align: center !important;
        padding: 20px !important;
    }
    
    /* Mobile-specific start chat button fixes */
    #wp-livechat-start-chat,
    .wp-livechat-start-chat,
    .wp-livechat-btn-primary {
        -webkit-tap-highlight-color: rgba(0, 124, 186, 0.2) !important;
        -webkit-touch-callout: none !important;
        -webkit-user-select: none !important;
        -khtml-user-select: none !important;
        -moz-user-select: none !important;
        -ms-user-select: none !important;
        user-select: none !important;
        touch-action: manipulation !important;
        cursor: pointer !important;
        min-height: 48px !important; /* iOS minimum touch target */
        width: 100% !important; /* Full width - rechthoekig */
        position: relative !important;
        z-index: 10 !important;
        pointer-events: auto !important; /* Force clickable */
        font-size: 16px !important; /* Prevent iOS zoom on focus */
        padding: 12px 20px !important; /* Extra padding voor grotere button */
    }
    
    /* Ensure button is clickable on mobile with visual feedback */
    #wp-livechat-start-chat:active,
    .wp-livechat-start-chat:active,
    .wp-livechat-btn-primary:active {
        transform: scale(0.98) !important;
        transition: transform 0.1s ease !important;
        background: #005a87 !important;
    }
    
    /* Ensure parent containers don't block touch events */
    .wp-livechat-login,
    .wp-livechat-login-form,
    .wp-livechat-form-group {
        pointer-events: auto !important;
    }
    
    /* Force show input area when active */
    .wp-livechat-input-area[style*="display: block"],
    .wp-livechat-input-area[style*="display:block"] {
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
    }
    
    /* Ensure input area is visible on mobile - ABOVE system UI */
    .wp-livechat-input-area {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        z-index: 9999999 !important;
        background: white !important;
        
        /* Safe area for notched devices - minimale padding */
        padding-bottom: env(safe-area-inset-bottom, 10px) !important;
        
        /* Box shadow to separate from messages */
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1) !important;
    }
    
    /* Also fix login form positioning */
    .wp-livechat-login {
        padding-bottom: env(safe-area-inset-bottom, 20px) !important;
        padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 20px) !important;
    }
    
    .wp-livechat-welcome-message {
        background: white !important;
        padding: 30px !important;
        border-radius: 12px !important;
        box-shadow: 0 4px 20px rgba(0,0,0,0.1) !important;
        max-width: 400px !important;
        margin: 0 auto !important;
        font-size: 16px !important;
        line-height: 1.5 !important;
    }
    
    /* Hide toggle button when chat is open on mobile */
    .wp-livechat-widget:has(.wp-livechat-window[style*="display: block"]) .wp-livechat-toggle {
        display: none;
    }
}

/* Tablet responsive */
@media (max-width: 1024px) and (min-width: 769px) {
    .wp-livechat-window {
        width: 400px;
        height: 600px;
        max-width: calc(100vw - 40px);
        max-height: calc(100vh - 100px);
    }
}

/* Small mobile devices */
@media (max-width: 480px) {
    .wp-livechat-toggle {
        width: 50px;
        height: 50px;
        bottom: 80px; /* Above Chrome mobile menu */
        right: 15px;
        z-index: 9999999;
    }
    
    .wp-livechat-bottom-left .wp-livechat-toggle {
        left: 15px;
        right: auto;
        bottom: 80px; /* Above Chrome mobile menu */
    }
    
    .wp-livechat-toggle-icon {
        width: 20px;
        height: 20px;
    }
    
    /* Full screen on very small devices */
    .wp-livechat-window {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        border-radius: 0 !important;
        z-index: 9999999 !important;
    }
}

/* Mobile positioning - ALWAYS above system UI */
@media (max-width: 768px) {
    .wp-livechat-toggle {
        bottom: 120px !important; /* Above ALL mobile system UI */
        z-index: 9999999 !important;
        position: fixed !important;
    }
    
    .wp-livechat-bottom-left .wp-livechat-toggle {
        bottom: 120px !important; /* Above ALL mobile system UI */
        z-index: 9999999 !important;
        position: fixed !important;
    }
}

/* Extra space for Android navigation bar */
@media (max-width: 768px) {
    .android .wp-livechat-toggle,
    .wp-livechat-toggle.android {
        bottom: 140px !important; /* Extra space for Android */
        z-index: 9999999 !important;
    }
    
    .android .wp-livechat-bottom-left .wp-livechat-toggle,
    .wp-livechat-bottom-left .wp-livechat-toggle.android {
        bottom: 140px !important; /* Extra space for Android */
    }
    
    /* Android-specific input area positioning */
    .android .wp-livechat-input-area {
        bottom: 0 !important;
        padding-bottom: 20px !important; /* Minimale ruimte voor Android nav buttons */
    }
    
    /* Android-specific chat body height adjustment */
    .android .wp-livechat-body {
        height: calc(100vh - 70px - 100px) !important; /* Header + input met minimale padding */
        max-height: calc(100vh - 70px - 100px) !important;
    }
    
    .android .wp-livechat-messages {
        max-height: calc(100vh - 70px - 120px) !important;
    }
}

/* Animation for smooth opening/closing */
.wp-livechat-window {
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Scrollbar Styling */
.wp-livechat-messages::-webkit-scrollbar {
    width: 6px;
}

.wp-livechat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.wp-livechat-messages::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.wp-livechat-messages::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Focus styles for accessibility */
.wp-livechat-btn:focus,
.wp-livechat-toggle:focus {
    outline: 2px solid var(--primary-color, #007cba);
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .wp-livechat-message-content {
        border: 2px solid currentColor;
    }
}

/* Mobile close button - DISABLED (we use header buttons instead) */
.wp-livechat-mobile-close-btn {
    display: none !important;
}

/* Mobile body scroll prevention */
.wp-livechat-mobile-open {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .wp-livechat-window,
    .wp-livechat-toggle,
    .wp-livechat-btn {
        transition: none;
        animation: none;
    }
}
