/**
 * Match Night Live - Chat Feature Styles
 * Phase 2: Frontend UI Components
 * 
 * @package    Club_Manager_Pro
 * @subpackage Match_Night_Live
 * @since      7.2.3.4
 */

/* ===== FLOATING CHAT BUBBLE ===== */

.mnl-chat-bubble {
    position: fixed;
    bottom: 120px;  /* Raised to avoid notification panel overlap */
    right: 20px;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #10b981, #059669);
    border-radius: 50%;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
    cursor: pointer;
    z-index: 10050;  /* Above notification toggle/panels */
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    border: none;
}

.mnl-chat-bubble:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.6);
}

.mnl-chat-bubble:active {
    transform: scale(1.05);
}

.mnl-chat-icon {
    font-size: 28px;
    line-height: 1;
    user-select: none;
}

.mnl-chat-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ef4444;
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* ===== CHAT MODAL (FULL SCREEN) ===== */

.mnl-chat-modal {
    position: fixed;
    /* Use inset for robust full-viewport anchoring */
    inset: 0;
    width: 100%;
    /* Prefer dynamic viewport units to avoid URL bar overlap */
    height: 100dvh;
    max-width: 100vw;
    max-height: 100dvh;
    background: white;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s ease-out;
    overflow: hidden;
    box-sizing: border-box;
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
    }
    to {
        transform: translateY(0);
    }
}

/* ===== CHAT HEADER ===== */

.mnl-chat-header {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    flex-shrink: 0;
}

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

.mnl-chat-close {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    font-size: 32px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    line-height: 1;
    padding: 0;
}

.mnl-chat-close:hover {
    background: rgba(255,255,255,0.3);
}

/* ===== CHAT MESSAGES AREA ===== */

.mnl-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f3f4f6;
    scroll-behavior: smooth;
    /* Critical in flex column containers to prevent overflow beyond viewport */
    min-height: 0;
}

.mnl-chat-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #9ca3af;
    text-align: center;
}

.mnl-chat-empty p {
    font-size: 16px;
    margin: 0;
}

/* ===== CHAT MESSAGE BUBBLES ===== */

.mnl-chat-message {
    margin-bottom: 12px;
    padding: 12px 16px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.mnl-chat-message-user {
    font-weight: 600;
    color: #10b981;
    margin-bottom: 4px;
    font-size: 14px;
}

.mnl-chat-message-text {
    color: #1f2937;
    font-size: 15px;
    line-height: 1.5;
    word-wrap: break-word;
}

.mnl-chat-message-time {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 4px;
    display: block;
}

/* ===== CHAT INPUT AREA ===== */

.mnl-chat-input-container {
    display: flex;
    padding: 12px;
    background: white;
    border-top: 1px solid #e5e7eb;
    gap: 8px;
    flex-shrink: 0;
    box-sizing: border-box;
    /* Keep controls above the iOS home indicator / Android nav bar */
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
}

.mnl-chat-input {
    flex: 1;
    padding: 10px 14px;
    border: 2px solid #e5e7eb;
    border-radius: 20px;
    font-size: 16px;
    outline: none;
    transition: border-color 0.2s;
    box-sizing: border-box;
    min-width: 0;
}

.mnl-chat-input:focus {
    border-color: #10b981;
}

.mnl-chat-send {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 4px rgba(16, 185, 129, 0.3);
    flex-shrink: 0;
    white-space: nowrap;
}

.mnl-chat-send:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(16, 185, 129, 0.4);
}

.mnl-chat-send:active {
    transform: translateY(0);
}

.mnl-chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ===== DESKTOP: SIDEBAR MODE ===== */

@media (min-width: 768px) {
    .mnl-chat-modal {
        width: 400px;
        right: 0;
        left: auto;
        box-shadow: -4px 0 12px rgba(0,0,0,0.1);
        animation: slideIn 0.3s ease-out;
        /* Ensure it never exceeds the viewport height on desktop either */
        height: 100dvh;
        max-height: 100dvh;
    }
    
    @keyframes slideIn {
        from {
            transform: translateX(100%);
        }
        to {
            transform: translateX(0);
        }
    }
}

/* ===== MOBILE OPTIMIZATIONS ===== */

@media (max-width: 480px) {
    .mnl-chat-modal {
        width: 100vw;
        height: 100dvh;
        height: -webkit-fill-available; /* Safari fallback */
    }
    
    .mnl-chat-bubble {
        width: 56px;
        height: 56px;
        bottom: 110px;  /* Raised to clear notification panel on mobile */
        right: 16px;
    }
    
    .mnl-chat-icon {
        font-size: 24px;
    }
    
    .mnl-chat-header {
        padding: 10px 12px;
    }
    
    .mnl-chat-header h3 {
        font-size: 14px;
    }
    
    .mnl-chat-close {
        width: 36px;
        height: 36px;
        font-size: 28px;
    }
    
    .mnl-chat-messages {
        padding: 12px;
    }
    
    .mnl-chat-input-container {
        padding: 10px;
        gap: 6px;
    }
    
    .mnl-chat-input {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 8px 12px;
    }
    
    .mnl-chat-send {
        padding: 8px 16px;
        font-size: 13px;
    }
    
    .mnl-chat-message {
        padding: 10px 12px;
        margin-bottom: 10px;
    }
}

/* ===== PREVENT BODY SCROLL WHEN CHAT OPEN ===== */

body.mnl-chat-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100dvh; /* lock body height to viewport */
    top: 0;
    left: 0;
}

/* iOS Safari keyboard fix */
@supports (-webkit-touch-callout: none) {
    .mnl-chat-modal {
        height: -webkit-fill-available;
        min-height: -webkit-fill-available;
    }
}

/* Prevent layout shift when keyboard appears/disappears */
.mnl-chat-messages {
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.mnl-chat-input-container {
    position: relative;
    z-index: 100;
}

/* ===== GUEST NAME MODAL ===== */

.mnl-chat-name-modal {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100dvh;
    z-index: 10001;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mnl-chat-name-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
}

.mnl-chat-name-content {
    position: relative;
    background: white;
    padding: 30px;
    border-radius: 12px;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    animation: slideUp 0.3s ease-out;
    /* Prevent overflow on small screens */
    max-height: calc(100dvh - 40px);
    overflow: auto;
}

.mnl-chat-name-content h3 {
    margin: 0 0 10px 0;
    color: #1f2937;
    font-size: 20px;
}

.mnl-chat-name-content p {
    margin: 0 0 20px 0;
    color: #6b7280;
    font-size: 14px;
}

.mnl-chat-guest-name-input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    font-size: 16px;
    margin-bottom: 16px;
    box-sizing: border-box;
    outline: none;
    transition: border-color 0.2s;
}

.mnl-chat-guest-name-input:focus {
    border-color: #10b981;
}

.mnl-chat-name-submit {
    width: 100%;
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    border: none;
    padding: 12px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.mnl-chat-name-submit:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
}

.mnl-chat-name-submit:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ===== ACCESSIBILITY ===== */

.mnl-chat-bubble:focus,
.mnl-chat-close:focus,
.mnl-chat-send:focus {
    outline: 2px solid #10b981;
    outline-offset: 2px;
}

/* ===== LOADING STATE ===== */

.mnl-chat-loading {
    display: flex;
    justify-content: center;
    padding: 20px;
}

.mnl-chat-loading::after {
    content: '●●●';
    font-size: 20px;
    color: #10b981;
    animation: dots 1.5s infinite;
}

@keyframes dots {
    0%, 20% { opacity: 0.2; }
    40% { opacity: 1; }
    60%, 100% { opacity: 0.2; }
}
