/**
 * Race Chat Styles for Single Push Style
 * Matches the existing design system and supports dark mode
 */

/* Chat Toggle Button */
.chat-toggle-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
    background: var(--accent-blue);
    color: white;
    border: none;
    border-radius: 50%;
    box-shadow: 0 4px 12px var(--shadow);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10001;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(10px);
}

.chat-toggle-btn:hover {
    background: var(--accent-blue-dark);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px var(--shadow);
}

.chat-toggle-btn:active {
    transform: translateY(0) scale(0.95);
}

.chat-toggle-btn.open .chat-icon {
    display: none;
}

.chat-toggle-btn.open .close-icon {
    display: block;
}

.chat-toggle-btn svg {
    width: 24px;
    height: 24px;
    stroke-width: 2;
}

.close-icon {
    display: none;
}

/* Unread Badge */
.unread-badge {
    position: absolute;
    top: -8px;
    right: -8px;
    background: #ef4444;
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    font-size: 12px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: bounce-in 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes bounce-in {
    0% { transform: scale(0); }
    100% { transform: scale(1); }
}

/* Chat Modal */
.chat-modal {
    position: fixed;
    bottom: 90px;
    right: 20px;
    left: 20px;
    max-width: 380px;
    width: calc(100% - 40px);
    height: 500px;
    max-height: calc(100vh - 120px);
    z-index: 10000;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-modal.hidden {
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
}

/* Chat Window */
.chat-window {
    background: var(--bg-secondary);
    border-radius: 16px;
    box-shadow: 0 20px 60px var(--shadow);
    border: 2px solid var(--border-color);
    height: 100%;
    display: flex;
    flex-direction: column;
    backdrop-filter: blur(10px);
    overflow: hidden;
}

/* Chat Header */
.chat-header {
    background: linear-gradient(135deg, var(--accent-blue) 0%, var(--accent-blue-dark) 100%);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: 14px 14px 0 0;
    flex-shrink: 0;
}

.chat-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 16px;
}

.chat-users-icon {
    width: 20px;
    height: 20px;
    stroke-width: 2;
}

.connection-status {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-left: 8px;
    transition: all 0.3s ease;
}

.connection-status.connected {
    background: #22c55e;
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.6);
}

.connection-status.connecting {
    background: #f59e0b;
    box-shadow: 0 0 8px rgba(245, 158, 11, 0.6);
}

.connection-status.disconnected {
    background: #ef4444;
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.6);
}

.close-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;
}

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

.close-btn svg {
    width: 18px;
    height: 18px;
    stroke-width: 2;
}

/* Chat Content */
.chat-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Username Setup */
.username-setup {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.setup-content {
    text-align: center;
    width: 100%;
    max-width: 280px;
}

.welcome-text {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.username-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#username-input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 16px; /* Prevent iOS zoom */
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: all 0.2s ease;
    box-sizing: border-box;
    -webkit-appearance: none;
    appearance: none;
}

#username-input:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.username-error {
    color: #ef4444;
    font-size: 12px;
    text-align: center;
    margin-top: -8px;
}

.join-btn {
    background: var(--accent-blue);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.join-btn:hover:not(:disabled) {
    background: var(--accent-blue-dark);
    transform: translateY(-1px);
}

.join-btn:disabled {
    background: var(--accent-gray);
    cursor: not-allowed;
    opacity: 0.7;
}

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

.messages-list {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

.messages-list::-webkit-scrollbar {
    width: 4px;
}

.messages-list::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

.messages-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 2px;
}

.no-messages {
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
    margin: 20px 0;
    font-style: italic;
}

/* Message Styles */
.message {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    max-width: 85%;
}

.message.own-message {
    align-items: flex-end;
    margin-left: auto;
}

.message-bubble {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: 16px;
    word-wrap: break-word;
    max-width: 100%;
    transition: all 0.2s ease;
}

.own-message .message-bubble {
    background: var(--accent-blue);
    color: white;
    border-bottom-right-radius: 4px;
}

.message:not(.own-message) .message-bubble {
    border-bottom-left-radius: 4px;
}

.message-author {
    font-size: 11px;
    font-weight: 600;
    opacity: 0.7;
    margin-bottom: 2px;
}

.own-message .message-author {
    display: none; /* Hide author for own messages */
}

.message-text {
    font-size: 14px;
    line-height: 1.4;
    word-break: break-word;
}

.message-time {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
    padding: 0 4px;
}

/* Message Input */
.message-input-container {
    padding: 12px 16px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 8px;
    align-items: center;
    background: var(--bg-secondary);
    flex-shrink: 0;
}

#message-input {
    flex: 1;
    padding: 8px 12px;
    border: 2px solid var(--border-color);
    border-radius: 20px;
    font-size: 16px; /* Prevent iOS zoom */
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: all 0.2s ease;
    min-height: 36px;
    resize: none;
    -webkit-appearance: none;
    appearance: none;
}

#message-input:focus {
    outline: none;
    border-color: var(--accent-blue);
}

.send-btn {
    background: var(--accent-blue);
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
    background: var(--accent-blue-dark);
    transform: scale(1.05);
}

.send-btn:disabled {
    background: var(--accent-gray);
    cursor: not-allowed;
    opacity: 0.7;
}

.send-btn svg {
    width: 16px;
    height: 16px;
    stroke-width: 2;
}

/* Chat Status */
.chat-status {
    padding: 8px 16px;
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
    border-top: 1px solid var(--border-light);
    background: var(--bg-tertiary);
    flex-shrink: 0;
}

.connection-text {
    color: #ef4444;
    font-weight: 600;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

/* Responsive Design */
@media (min-width: 768px) {
    .chat-modal {
        right: 20px;
        left: auto;
        width: 380px;
        bottom: 90px;
    }
    
    .chat-toggle-btn {
        bottom: 24px;
        right: 24px;
        width: 60px;
        height: 60px;
    }
    
    .chat-toggle-btn svg {
        width: 28px;
        height: 28px;
    }
}

@media (max-width: 480px) {
    .chat-modal {
        bottom: 80px;
        left: 10px;
        right: 10px;
        width: calc(100% - 20px);
        height: 450px;
        max-height: calc(100vh - 100px);
    }
    
    .chat-toggle-btn {
        bottom: 16px;
        right: 16px;
        width: 50px;
        height: 50px;
    }
    
    .chat-toggle-btn svg {
        width: 20px;
        height: 20px;
    }
    
    .chat-header {
        padding: 12px 16px;
    }
    
    .welcome-text {
        font-size: 18px;
    }
    
    .setup-content {
        padding: 0 8px;
    }
    
    /* Fix iOS keyboard issues */
    .chat-window {
        position: relative;
    }
    
    .messages-list {
        /* Reduce height when keyboard is active */
        max-height: calc(100vh - 300px);
        overscroll-behavior: contain;
    }
}

/* Additional mobile fixes for keyboard handling */
@media (max-width: 768px) and (max-height: 600px) {
    /* When keyboard is visible (reduced viewport height) */
    .chat-modal {
        height: calc(100vh - 120px);
        bottom: 10px;
        max-height: none;
    }
    
    .messages-list {
        flex: 1;
        min-height: 0;
    }
    
    .chat-window {
        height: 100%;
        max-height: 100%;
    }
}

/* Fix for iOS Safari viewport issues */
@supports (-webkit-touch-callout: none) {
    .chat-modal {
        height: calc(var(--vh, 1vh) * 70);
        max-height: calc(var(--vh, 1vh) * 70);
    }
    
    @media (max-width: 480px) {
        .chat-modal {
            height: calc(var(--vh, 1vh) * 60);
            max-height: calc(var(--vh, 1vh) * 60);
        }
    }
}

/* Animation for new messages */
.message {
    animation: slide-in 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slide-in {
    0% {
        opacity: 0;
        transform: translateY(10px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Focus states for accessibility */
.chat-toggle-btn:focus,
.close-btn:focus,
.join-btn:focus,
.send-btn:focus {
    outline: 2px solid var(--accent-blue);
    outline-offset: 2px;
}

#username-input:focus,
#message-input:focus {
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}