/**
 * xDREAM Gaming - Real-Time Chat System Styles
 * Bottom-left positioned chat with minimized/expanded states
 */

:root {
    --chat-primary: #ff0080;
    --chat-secondary: #00ffff;
    --chat-bg: rgba(26, 26, 46, 0.98);
    --chat-bg-light: rgba(31, 31, 53, 0.98);
    --chat-border: rgba(255, 0, 128, 0.3);
    --chat-text: #ffffff;
    --chat-text-muted: #b0b0c8;
    --chat-input-bg: rgba(15, 15, 26, 0.95);
    --chat-message-bg: rgba(45, 45, 68, 0.5);
    --chat-message-hover: rgba(45, 45, 68, 0.8);
    --chat-online-dot: #00ff88;
    --chat-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

/* Chat Container - Fixed Bottom-Left */
.chat-container {
    position: fixed;
    bottom: 20px;
    left: 20px;
    z-index: 9999;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* Chat Toggle Button (Minimized State) */
.chat-toggle-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--chat-primary), var(--chat-secondary));
    border: 3px solid var(--chat-border);
    color: white;
    font-size: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--chat-shadow);
    transition: all 0.3s ease;
    position: relative;
}

.chat-toggle-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 12px 40px rgba(255, 0, 128, 0.6);
}

.chat-toggle-btn.has-unread::after {
    content: '';
    position: absolute;
    top: 5px;
    right: 5px;
    width: 12px;
    height: 12px;
    background: #ff0055;
    border-radius: 50%;
    border: 2px solid white;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.2); opacity: 0.8; }
}

/* Chat Window (Expanded State) */
.chat-window {
    display: none;
    width: 400px;
    height: 500px;
    background: var(--chat-bg);
    border: 2px solid var(--chat-border);
    border-radius: 15px;
    box-shadow: var(--chat-shadow);
    flex-direction: column;
    overflow: hidden;
}

.chat-window.expanded {
    display: flex;
}

/* Chat Header */
.chat-header {
    background: linear-gradient(135deg, var(--chat-primary), var(--chat-secondary));
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid var(--chat-border);
}

.chat-header-title {
    font-size: 18px;
    font-weight: bold;
    color: white;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-online-count {
    font-size: 12px;
    background: rgba(0, 0, 0, 0.3);
    padding: 4px 8px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.chat-online-dot {
    width: 8px;
    height: 8px;
    background: var(--chat-online-dot);
    border-radius: 50%;
    animation: pulse 2s infinite;
}

.chat-header-actions {
    display: flex;
    gap: 8px;
}

.chat-header-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.chat-header-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

/* Chat Body */
.chat-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Messages Area */
.chat-messages-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: var(--chat-input-bg);
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--chat-primary);
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--chat-secondary);
}

/* Message Item */
.chat-message {
    display: flex;
    gap: 10px;
    padding: 10px;
    border-radius: 8px;
    background: var(--chat-message-bg);
    transition: background 0.2s ease;
}

.chat-message:hover {
    background: var(--chat-message-hover);
}

.chat-message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--chat-primary), var(--chat-secondary));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    flex-shrink: 0;
}

.chat-message-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.chat-message-content {
    flex: 1;
    min-width: 0;
}

.chat-message-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.chat-message-username {
    font-weight: bold;
    color: var(--chat-secondary);
    font-size: 14px;
    flex: 1;
}

.chat-message-time {
    font-size: 11px;
    color: var(--chat-text-muted);
}

.chat-message-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.chat-message:hover .chat-message-actions {
    opacity: 1;
}

.chat-message-delete-btn {
    background: none;
    border: none;
    color: var(--chat-text-muted);
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    font-size: 12px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    min-height: 24px;
}

.chat-message-delete-btn:hover {
    background: rgba(255, 59, 48, 0.2);
    color: #ff3b30;
}

.chat-message-delete-btn:active {
    transform: scale(0.95);
}

.chat-message-text {
    color: var(--chat-text);
    font-size: 14px;
    word-wrap: break-word;
    line-height: 1.4;
}

.chat-message-gif {
    max-width: 100%;
    border-radius: 8px;
    margin-top: 8px;
}

/* Chat Input Area */
.chat-input-area {
    padding: 15px;
    background: var(--chat-bg-light);
    border-top: 1px solid var(--chat-border);
}

.chat-input-wrapper {
    display: flex;
    gap: 8px;
    align-items: center;
}

.chat-input {
    flex: 1;
    background: var(--chat-input-bg);
    border: 1px solid var(--chat-border);
    border-radius: 20px;
    padding: 10px 15px;
    color: var(--chat-text);
    font-size: 14px;
    outline: none;
    transition: all 0.2s ease;
}

.chat-input:focus {
    border-color: var(--chat-primary);
    box-shadow: 0 0 0 2px rgba(255, 0, 128, 0.2);
}

.chat-input::placeholder {
    color: var(--chat-text-muted);
}

.chat-input-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--chat-primary), var(--chat-secondary));
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.chat-input-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(255, 0, 128, 0.4);
}

.chat-input-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Members Sidebar */
.chat-members-sidebar {
    width: 200px;
    background: var(--chat-bg-light);
    border-left: 1px solid var(--chat-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-members-sidebar.hidden {
    display: none;
}

.chat-members-header {
    padding: 12px;
    background: var(--chat-input-bg);
    border-bottom: 1px solid var(--chat-border);
    font-size: 12px;
    font-weight: bold;
    color: var(--chat-text-muted);
    text-transform: uppercase;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-members-close-btn {
    background: none;
    border: none;
    color: var(--chat-text);
    font-size: 16px;
    cursor: pointer;
    padding: 4px 8px;
    min-width: 32px;
    min-height: 32px;
    display: none; /* Hidden by default on desktop */
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.2s ease;
}

.chat-members-close-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.chat-members-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.chat-member-item {
    padding: 8px;
    border-radius: 6px;
    margin-bottom: 4px;
    cursor: pointer;
    transition: background 0.2s ease;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chat-member-item:hover {
    background: var(--chat-message-bg);
}

.chat-member-name {
    font-size: 13px;
    color: var(--chat-text);
    font-weight: 500;
}

.chat-member-page {
    font-size: 11px;
    color: var(--chat-text-muted);
}

/* Notification Toast */
.chat-notification-toast {
    position: fixed;
    bottom: 100px;
    left: 20px;
    background: linear-gradient(135deg, rgba(255, 0, 128, 0.95), rgba(0, 255, 255, 0.95));
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    padding: 14px 18px;
    box-shadow: 0 8px 32px rgba(255, 0, 128, 0.4), 0 4px 16px rgba(0, 255, 255, 0.3);
    display: none;
    max-width: 320px;
    z-index: 10000;
    animation: slideInBounce 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    position: relative;
}

.chat-notification-toast::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    background: linear-gradient(135deg, rgba(255, 0, 128, 0.6), rgba(0, 255, 255, 0.6));
    border-radius: 12px;
    z-index: -1;
    animation: pulse 2s ease-in-out infinite;
}

.chat-notification-toast:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 12px 40px rgba(255, 0, 128, 0.5), 0 6px 20px rgba(0, 255, 255, 0.4);
}

@keyframes pulse {
    0%, 100% {
        opacity: 0.5;
        transform: scale(1);
    }
    50% {
        opacity: 1;
        transform: scale(1.05);
    }
}

.chat-notification-toast.show {
    display: block;
}

.chat-notification-toast.hiding {
    animation: slideOutLeft 0.3s ease forwards;
}

@keyframes slideInBounce {
    0% {
        transform: translateX(-100%) scale(0.8);
        opacity: 0;
    }
    60% {
        transform: translateX(10px) scale(1.05);
        opacity: 1;
    }
    100% {
        transform: translateX(0) scale(1);
        opacity: 1;
    }
}

@keyframes slideOutLeft {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(-100%);
        opacity: 0;
    }
}

.chat-notification-content {
    display: flex;
    gap: 12px;
    align-items: center;
}

.chat-notification-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    flex-shrink: 0;
    border: 2px solid rgba(255, 255, 255, 0.5);
    overflow: hidden;
}

.chat-notification-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-notification-text {
    flex: 1;
    min-width: 0;
}

.chat-notification-username {
    font-weight: 700;
    font-size: 14px;
    color: #ffffff;
    margin-bottom: 4px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.chat-notification-message {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.95);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    line-height: 1.4;
    margin-bottom: 4px;
}

.chat-notification-hint {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.8);
    font-style: italic;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    animation: fadeInOut 2s ease-in-out infinite;
}

@keyframes fadeInOut {
    0%, 100% {
        opacity: 0.6;
    }
    50% {
        opacity: 1;
    }
}

/* Mobile Responsive Styles */
@media (max-width: 768px) {
    /* Position chat on left side for mobile */
    .chat-container {
        bottom: 80px; /* Above mobile navigation if present */
        left: 10px;
    }

    /* Smaller toggle button on mobile */
    .chat-toggle-btn {
        width: 50px;
        height: 50px;
        font-size: 20px;
    }

    /* Full-screen chat window on mobile */
    .chat-window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        border-radius: 0;
        border: none;
    }

    /* Hide members sidebar on mobile by default */
    .chat-members-sidebar {
        position: absolute;
        right: 0;
        top: 0;
        bottom: 0;
        width: 250px;
        transform: translateX(100%);
        transition: transform 0.3s ease;
        z-index: 10;
    }

    .chat-members-sidebar.show-mobile {
        transform: translateX(0);
    }

    /* Show close button on mobile */
    .chat-members-close-btn {
        display: flex !important;
        min-width: 44px;
        min-height: 44px;
    }

    /* Adjust notification toast position */
    .chat-notification-toast {
        bottom: 150px;
        left: 10px;
        right: 10px;
        max-width: none;
    }

    /* Ensure touch targets are at least 44x44px */
    .chat-header-btn,
    .chat-input-btn {
        min-width: 44px;
        min-height: 44px;
    }

    /* Adjust input area for mobile keyboard */
    .chat-input-area {
        padding: 10px;
    }

    .chat-input {
        font-size: 16px; /* Prevent zoom on iOS */
    }

    /* Mobile GIF Picker Improvements */
    .gif-picker-modal {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        max-height: none !important;
        border-radius: 0 !important;
        border: none !important;
        width: 100vw !important;
        height: 100vh !important;
        z-index: 10000 !important;
        overflow: hidden !important;
    }

    .gif-picker-modal.show {
        display: flex !important;
        flex-direction: column !important;
    }

    .gif-picker-header {
        padding: 16px;
        background: var(--chat-bg);
        position: relative;
        top: 0;
        z-index: 10;
        flex-shrink: 0;
        border-bottom: 1px solid var(--chat-border);
    }

    .gif-picker-search {
        font-size: 16px !important; /* Prevent zoom on iOS */
        padding: 12px 16px;
        min-height: 44px;
        width: 100%;
    }

    .gif-picker-close {
        min-width: 44px !important;
        min-height: 44px !important;
    }

    .gif-picker-grid {
        padding: 12px;
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)) !important;
        gap: 10px;
        flex: 1 1 auto;
        overflow-y: auto !important;
        overflow-x: hidden;
        display: grid !important;
        height: auto;
        min-height: 0;
    }

    .gif-picker-item {
        min-height: 100px;
        border-radius: 12px;
        /* Ensure mobile items maintain base styles */
        aspect-ratio: 1;
        overflow: hidden;
        cursor: pointer;
        background: rgba(255, 255, 255, 0.05);
        position: relative;
    }

    .gif-picker-item img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        display: block;
    }

    /* Larger touch targets for GIF items */
    .gif-picker-item:active {
        transform: scale(0.95);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
        z-index: 10;
    }

    /* Mobile message delete button - always visible on mobile */
    .chat-message-actions {
        opacity: 1;
    }

    .chat-message-delete-btn {
        min-width: 36px;
        min-height: 36px;
        padding: 6px 8px;
    }
}

@media (max-width: 414px) {
    /* Extra small mobile devices */
    .chat-toggle-btn {
        width: 44px;
        height: 44px;
        font-size: 18px;
    }

    .chat-header {
        padding: 12px;
    }

    .chat-header-title {
        font-size: 16px;
    }

    .chat-messages {
        padding: 10px;
    }

    .chat-message {
        padding: 8px;
    }

    .chat-message-avatar {
        width: 32px;
        height: 32px;
    }
}

/* Landscape mode on mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .chat-window {
        height: 100vh;
    }

    .chat-messages {
        padding: 10px;
    }
}

/* GIF Picker Modal */
.gif-picker-modal {
    position: absolute;
    bottom: 70px;
    left: 15px;
    right: 15px;
    max-height: 400px;
    background: var(--chat-bg);
    border: 2px solid var(--chat-border);
    border-radius: 10px;
    box-shadow: var(--chat-shadow);
    display: none;
    flex-direction: column;
    z-index: 100;
    overflow: hidden;
}

.gif-picker-modal.show {
    display: flex !important;
}

.gif-picker-header {
    padding: 12px;
    border-bottom: 1px solid var(--chat-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.gif-picker-search {
    flex: 1;
    background: var(--chat-input-bg);
    border: 1px solid var(--chat-border);
    border-radius: 15px;
    padding: 8px 12px;
    color: var(--chat-text);
    font-size: 13px;
    outline: none;
    min-height: 36px; /* Better touch target */
}

.gif-picker-close {
    background: none;
    border: none;
    color: var(--chat-text);
    font-size: 20px;
    cursor: pointer;
    padding: 8px;
    min-width: 44px; /* Touch-friendly */
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: background 0.2s ease;
}

.gif-picker-close:hover {
    background: rgba(255, 255, 255, 0.1);
}

.gif-picker-grid {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 10px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 8px;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

.gif-picker-item {
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, z-index 0s;
    background: rgba(255, 255, 255, 0.05);
    position: relative;
    z-index: 1;
}

.gif-picker-item:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 10;
}

.gif-picker-item:active {
    transform: scale(0.98);
}

.gif-picker-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Loading Indicator */
.chat-loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    color: var(--chat-text-muted);
}

.chat-loading-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--chat-border);
    border-top-color: var(--chat-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* System Messages */
.chat-system-message {
    text-align: center;
    padding: 8px;
    color: var(--chat-text-muted);
    font-size: 12px;
    font-style: italic;
}

/* System Notifications (Casino, Shop, Clicker) */
.chat-system-notification {
    text-align: center;
    padding: 10px 15px;
    margin: 8px 0;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    background: linear-gradient(135deg, rgba(100, 100, 255, 0.15), rgba(150, 100, 255, 0.15));
    border: 1px solid rgba(150, 100, 255, 0.3);
    color: #e0e0ff;
    animation: slideInNotification 0.3s ease-out;
}

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

.chat-system-notification .notification-icon {
    margin-right: 8px;
    font-size: 16px;
}

.chat-system-notification .notification-text {
    color: #ffffff;
}

/* Casino notifications - gold/yellow theme */
.chat-system-notification.notification-casino {
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.2), rgba(255, 165, 0, 0.2));
    border-color: rgba(255, 215, 0, 0.4);
    color: #ffd700;
}

/* Shop notifications - green theme */
.chat-system-notification.notification-shop {
    background: linear-gradient(135deg, rgba(0, 255, 100, 0.15), rgba(0, 200, 100, 0.15));
    border-color: rgba(0, 255, 100, 0.3);
    color: #00ff88;
}

/* Clicker Empire notifications - cyan theme */
.chat-system-notification.notification-clicker {
    background: linear-gradient(135deg, rgba(0, 200, 255, 0.15), rgba(0, 150, 255, 0.15));
    border-color: rgba(0, 200, 255, 0.3);
    color: #00d4ff;
}

/* Banned/Timeout Message */
.chat-banned-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 20px;
    z-index: 1000;
}

.chat-banned-overlay.show {
    display: flex;
}

.chat-banned-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.chat-banned-title {
    font-size: 24px;
    font-weight: bold;
    color: #ff0055;
    margin-bottom: 12px;
}

.chat-banned-message {
    color: var(--chat-text);
    text-align: center;
    line-height: 1.6;
    max-width: 400px;
}

