/* Chat UI Styles for Race Tracking */

/* Chat Container - Positioned dynamically at bottom of map */
.chat-container {
    position: absolute;
    bottom: 20px;
    left: 20px;
    width: 350px;
    max-height: 400px;
    z-index: 1000;
    pointer-events: auto;
    /* Ensure it's positioned relative to the map container */
}

/* Chat Panel */
.chat-panel {
    background: rgba(0, 0, 0, 0.01);
    border: none;
    border-radius: 8px;
    box-shadow: none;
    backdrop-filter: blur(2px);
    overflow: hidden;
    transition: all 0.3s ease;
}

/* Chat Header */
.chat-header {
    background: transparent;
    padding: 12px 16px;
    border-bottom: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header h3 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: #000000;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-toggle {
    background: none;
    border: none;
    color: #000000;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: color 0.2s ease;
    font-size: 16px;
    font-weight: bold;
    min-width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-toggle:hover {
    color: #4dabf7;
    background: rgba(255, 255, 255, 0.1);
}

/* Chat Messages */
.chat-messages {
    height: 250px;
    overflow-y: hidden;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: transparent;
    mask-image: linear-gradient(to top, rgba(0,0,0,1) 70%, rgba(0,0,0,0) 100%);
    mask-repeat: no-repeat;
    mask-size: cover;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: rgba(64, 64, 64, 0.3);
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(128, 128, 128, 0.5);
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(128, 128, 128, 0.7);
}

/* Message Styles */
.message {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 1px 8px;
    border-radius: 6px;
    background: transparent;
    border: none;
    transition: all 0.2s ease;
    animation: fadeIn 0.3s ease;
    min-width: 12px;
}

.message:hover {
    background: transparent;
}

.message.system {
    background: transparent;
    border: none;
}

.message.pending {
    opacity: 0.7;
    background: transparent;
}

.message.rejected {
    background: transparent;
    border: none;
    text-decoration: line-through;
    opacity: 0.6;
}

.message.approved {
    background: transparent;
    border: none;
}

.message-user {
    font-weight: 600;
    font-size: 12px;
    color: #008dff;
    min-width: 60px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.message-text {
    flex: 1;
    font-size: 12px;
    color: #0f0e0e;
    line-height: 1.4;
    word-wrap: break-word;
}

.message-status {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 16px;
}

/* Status Icons */
.checkmark {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 8px;
    color: white;
}

.status-approved {
    background: #28a745;
}

.status-pending {
    background: #808080;
    animation: pulse 2s infinite;
}

.status-rejected {
    background: #dc3545;
}

.status-icon {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #dc3545;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 8px;
    font-weight: bold;
}

/* Chat Input */
.chat-input {
    padding: 12px;
    background: transparent;
    border-top: none;
}

.input-group {
    display: flex;
    gap: 8px;
    align-items: center;
}

.message-input {
    flex: 1;
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(20, 20, 20, 0.3);
    border-radius: 6px;
    padding: 8px 12px;
    color: #000000;
    font-size: 12px;
    outline: none;
    transition: border-color 0.2s ease;
}

.message-input::placeholder {
    color: rgba(70, 69, 69, 0.7);
}

.message-input:focus {
    border-color: #4dabf7;
}

.send-btn {
    background: #4dabf7;
    border: none;
    border-radius: 6px;
    padding: 8px;
    color: white;
    cursor: pointer;
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
}

.send-btn:hover:not(:disabled) {
    background: #339af0;
}

.send-btn:disabled {
    background: #666666;
    cursor: not-allowed;
    opacity: 0.6;
}

/* Username Modal */
.chat-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    backdrop-filter: blur(5px);
    /* Ensure proper mobile viewport handling */
    box-sizing: border-box;
    overflow: hidden;
}

.chat-modal-overlay.hidden {
    display: none;
}

.chat-modal {
    background: rgba(26, 26, 26, 0.95);
    border: 1px solid rgba(64, 64, 64, 0.8);
    border-radius: 12px;
    padding: 24px;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
    box-sizing: border-box;
    /* Prevent zoom on mobile */
    font-size: 16px;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}

.chat-modal h2 {
    margin: 0 0 16px 0;
    color: #ffffff;
    font-size: 18px;
    font-weight: 600;
}

.chat-modal p {
    margin: 0 0 20px 0;
    color: #b0b0b0;
    font-size: 14px;
    line-height: 1.5;
}

.modal-input {
    width: 100%;
    box-sizing: border-box;
    background: rgba(58, 58, 58, 0.8);
    border: 1px solid rgba(85, 85, 85, 0.8);
    border-radius: 6px;
    padding: 12px;
    color: #ffffff;
    font-size: 16px; /* Prevent zoom on iOS */
    outline: none;
    margin-bottom: 16px;
    transition: border-color 0.2s ease;
    /* Prevent zoom on mobile */
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.modal-input:focus {
    border-color: #4dabf7;
    /* Prevent zoom on mobile focus */
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    text-size-adjust: 100%;
    transform: scale(1);
    -webkit-transform: scale(1);
}

.modal-btn {
    background: #4dabf7;
    border: none;
    border-radius: 6px;
    padding: 12px 24px;
    color: white;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease;
    width: 100%;
    box-sizing: border-box;
}

.modal-btn:hover:not(:disabled) {
    background: #339af0;
}

.modal-btn:disabled {
    background: #666666;
    cursor: not-allowed;
    opacity: 0.6;
}

.error-message {
    color: #dc3545;
    font-size: 12px;
}

/* Mobile-specific modal adjustments */
@media (max-width: 768px) {
    .chat-modal-overlay {
        /* Ensure full viewport coverage on mobile */
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100vw;
        height: 100vh;
        /* Prevent mobile browser zoom */
        touch-action: manipulation;
        -webkit-overflow-scrolling: touch;
        /* Ensure proper mobile viewport handling */
        transform: translateZ(0);
        -webkit-transform: translateZ(0);
    }
    
    .chat-modal {
        /* Mobile-optimized sizing */
        width: calc(100vw - 40px);
        max-width: calc(100vw - 40px);
        margin: 20px;
        padding: 20px;
        /* Ensure text is readable without zoom */
        font-size: 16px;
        /* Prevent zoom on input focus */
        transform: scale(1);
        -webkit-transform: scale(1);
        /* Ensure proper mobile positioning */
        position: relative;
        top: auto;
        left: auto;
        right: auto;
        bottom: auto;
    }
    
    .chat-modal h2 {
        font-size: 20px;
        margin-bottom: 12px;
    }
    
    .chat-modal p {
        font-size: 14px;
        margin-bottom: 16px;
        line-height: 1.4;
    }
    
    .modal-input {
        /* Prevent zoom on iOS */
        font-size: 16px;
        padding: 14px;
        margin-bottom: 16px;
        /* Ensure proper touch target size */
        min-height: 44px;
        /* Prevent mobile zoom */
        -webkit-text-size-adjust: 100%;
        -moz-text-size-adjust: 100%;
        text-size-adjust: 100%;
    }
    
    .modal-btn {
        /* Ensure proper touch target size */
        min-height: 44px;
        padding: 14px 20px;
        font-size: 16px;
    }
}

/* Extra small mobile devices */
@media (max-width: 480px) {
    .chat-modal-overlay {
        /* Ensure full coverage on very small screens */
        width: 100vw;
        height: 100vh;
        padding: 0;
        margin: 0;
    }
    
    .chat-modal {
        width: calc(100vw - 20px);
        max-width: calc(100vw - 20px);
        margin: 10px;
        padding: 16px;
        /* Ensure modal is always visible */
        position: relative;
        top: 0;
        left: 0;
        transform: none;
        -webkit-transform: none;
    }
    
    .chat-modal h2 {
        font-size: 18px;
    }
    
    .chat-modal p {
        font-size: 13px;
    }
    
    .modal-input {
        font-size: 16px;
        padding: 12px;
        min-height: 40px;
    }
    
    .modal-btn {
        font-size: 16px;
        padding: 12px 16px;
        min-height: 40px;
    }
}

/* Landscape orientation on mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .chat-modal-overlay {
        /* Ensure proper landscape handling */
        align-items: flex-start;
        padding-top: 20px;
    }
    
    .chat-modal {
        width: calc(100vw - 60px);
        max-width: 500px;
        margin: 30px;
        /* Ensure modal fits in landscape */
        max-height: calc(100vh - 40px);
        overflow-y: auto;
    }
}

/* Handle very small screens and ensure modal is always accessible */
@media (max-width: 360px) {
    .chat-modal-overlay {
        /* Force full viewport coverage */
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
    }
    
    .chat-modal {
        /* Ensure modal fits on very small screens */
        width: calc(100vw - 16px);
        max-width: calc(100vw - 16px);
        margin: 8px;
        padding: 12px;
        font-size: 14px;
    }
    
    .chat-modal h2 {
        font-size: 16px;
        margin-bottom: 8px;
    }
    
    .chat-modal p {
        font-size: 12px;
        margin-bottom: 12px;
    }
    
    .modal-input {
        font-size: 16px;
        padding: 10px;
        min-height: 36px;
    }
    
    .modal-btn {
        font-size: 14px;
        padding: 10px 14px;
        min-height: 36px;
    }
}

.error-message.hidden {
    display: none;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.fade-in {
    animation: fadeIn 0.3s ease;
}

/* Responsive Design */
@media (max-width: 768px) {
    .chat-container {
        width: calc(100% - 20px);
        max-width: 350px;
        bottom: 10px;
        left: 10px;
    }
    
    .chat-messages {
        height: 220px;
        gap:2px;
    }
    
    .chat-modal {
        margin: 20px;
        padding: 20px;
    }
}

@media (max-width: 480px) {
    .chat-container {
        width: calc(100% - 20px);
        left: 10px;
        bottom: 10px;
    }
    
    .chat-messages {
        height: 220px;
        gap:2px;
    }
    
    .message {
        padding: 4px 6px;
    }
    
    .message-user {
        font-size: 11px;
        min-width: 50px;
    }
    
    .message-text {
        font-size: 11px;
    }
}

/* Utility Classes */
.hidden {
    display: none !important;
}

/* Spinner for loading states */
.spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #ffffff;
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}
