/* Chat System Styles */

/* CSS Custom Properties for Dynamic Room Colors */
:root {
    --room-color: #007bff;
    --room-color-hover: #0056b3;
    --room-color-light: rgba(0, 123, 255, 0.1);
    --room-color-25: rgba(0, 123, 255, 0.25);
}

/* Chat Index Styles - SCOPED TO CHAT CONTAINER ONLY */
.chat-container .card,
.chat-index .card,
[data-chat-context] .card {
    transition: transform 0.2s, box-shadow 0.2s;
}

.chat-container .card:hover,
.chat-index .card:hover,
[data-chat-context] .card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.latest-message {
    background-color: #f8f9fa;
    padding: 8px;
    border-radius: 4px;
    border-left: 3px solid #dee2e6;
}

.latest-message strong {
    color: #343a40;
}

.badge-success {
    background-color: #28a745 !important;
}

.btn:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

/* Chat Room Styles */
.chat-container {
    border: none;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.chat-container .card-header {
    background-color: var(--room-color, #007bff) !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2) !important;
}

.chat-container .card-header * {
    color: white !important;
}

.chat-container .card-header h5 {
    color: white !important;
    font-weight: 600 !important;
}

.chat-container .card-header h5 i {
    color: white !important;
}

.chat-container .card-header .badge {
    background-color: rgba(255, 255, 255, 0.2) !important;
    color: white !important;
    border: 1px solid rgba(255, 255, 255, 0.3) !important;
}

.chat-container .card-header .badge i {
    color: white !important;
}

.chat-container .card-header .btn {
    background-color: rgba(255, 255, 255, 0.1) !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
    color: white !important;
}

.chat-container .card-header .btn i {
    color: white !important;
}

.chat-container .card-header .btn:hover {
    background-color: rgba(255, 255, 255, 0.2) !important;
    color: white !important;
}

.chat-container .card-header .btn:hover * {
    color: white !important;
}

.chat-container .card-header small {
    color: rgba(255, 255, 255, 0.9) !important;
}

.chat-container .card-header .opacity-75 {
    color: rgba(255, 255, 255, 0.75) !important;
}

.card-header .badge i {
    color: #495057 !important;
}

.card-header .btn {
    color: #495057 !important;
}

.card-header .btn i {
    color: #495057 !important;
}

#messages-container {
    background: linear-gradient(to bottom, #f8f9fa 0%, #ffffff 100%);
    color: #495057;
}

.message {
    margin-bottom: 15px;
    animation: fadeIn 0.3s ease-in;
    color: #495057;
}

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

.message-bubble {
    background: white;
    border: 1px solid #e9ecef;
    border-radius: 12px;
    padding: 12px 15px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    position: relative;
    color: #495057;
}

.message-bubble.own {
    background: var(--room-color, #007bff);
    color: white !important;
    border-color: var(--room-color, #007bff);
}

.message-bubble.own * {
    color: white !important;
}

.message-bubble:not(.own) * {
    color: #495057;
}

.message-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
}

.message-author {
    font-weight: 600;
    font-size: 0.9rem;
    color: #343a40;
}

.message-time {
    font-size: 0.75rem;
    color: #6c757d;
}

.message-content {
    margin: 0;
    word-wrap: break-word;
    color: #495057;
}

.message-bubble.own .message-content {
    color: white;
}

.reply-preview {
    background: #f1f3f4;
    border-left: 3px solid var(--room-color, #007bff);
    padding: 8px 12px;
    margin-top: 5px;
    border-radius: 0 6px 6px 0;
}

/* Participants Styles */
.participant-item {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    margin-bottom: 5px;
    border-radius: 8px;
    transition: background-color 0.2s;
}

.participant-item:hover {
    background-color: #f8f9fa;
}

.participant-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--room-color, #007bff);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    margin-right: 10px;
}

.participant-info {
    flex-grow: 1;
}

.participant-name {
    font-weight: 500;
    font-size: 0.9rem;
    color: #343a40 !important;
}

.participant-status {
    font-size: 0.75rem;
    color: #6c757d !important;
}

.online-indicator {
    width: 8px;
    height: 8px;
    background: #28a745;
    border-radius: 50%;
    margin-left: 5px;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(40, 167, 69, 0.7);
    }
    70% {
        box-shadow: 0 0 0 5px rgba(40, 167, 69, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(40, 167, 69, 0);
    }
}

.typing-indicator {
    padding: 10px 15px;
    font-style: italic;
}

/* Message Partial Styles */
.message-bubble {
    max-width: 80%;
    margin-left: auto;
    margin-right: 0;
}

.message-bubble:not(.own) {
    margin-left: 0;
    margin-right: auto;
}

.message-avatar .avatar-circle {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #6c757d;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 0.9rem;
}

/* Image avatar in messages */
.message-avatar .avatar-img {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
    border: 2px solid rgba(255,255,255,0.3);
    flex-shrink: 0;
}

.message-avatar {
    position: relative;
    width: 32px;
    height: 32px;
    flex-shrink: 0;
}

.message-bubble.own .message-avatar .avatar-circle {
    background: rgba(255, 255, 255, 0.2);
}

.reply-indicator {
    background: rgba(0, 0, 0, 0.1);
    padding: 6px 10px;
    border-radius: 6px;
    border-left: 3px solid rgba(255, 255, 255, 0.3);
}

.message-bubble:not(.own) .reply-indicator {
    background: #f8f9fa;
    border-left-color: #dee2e6;
}

.message-actions {
    opacity: 0;
    transition: opacity 0.2s ease;
}

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

.message-controls .btn {
    padding: 2px 6px;
    font-size: 0.75rem;
}

.badge-sm {
    font-size: 0.65rem;
    padding: 2px 6px;
}

/* Participant Partial Styles */
.participant-item {
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.participant-item:hover {
    background-color: rgba(0, 0, 0, 0.05);
    transform: translateX(2px);
}

.participant-avatar {
    flex-shrink: 0;
}

/* Participant avatar image */
.participant-avatar .avatar-img-sm,
.participant-avatar .avatar-img {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
    border: 2px solid rgba(0,0,0,0.05);
}

.participant-fallback {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #6c757d;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

.participant-name {
    font-size: 0.9rem;
    line-height: 1.2;
}

.participant-status {
    font-size: 0.75rem;
    line-height: 1.2;
}

.participant-actions {
    display: flex;
    align-items: center;
}

/* Input Focus Styles */
#message-input:focus {
    border-color: var(--room-color, #007bff);
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
}

/* Button Styles */
.btn-primary {
    background-color: var(--room-color, #007bff);
    border-color: var(--room-color, #007bff);
}

.btn-primary:hover {
    background-color: var(--room-color-hover, #0056b3);
    border-color: var(--room-color-hover, #0056b3);
}

/* Responsive Design */
@media (max-width: 768px) {
    .participant-item {
        padding: 6px 8px;
    }

    .message-bubble {
        max-width: 90%;
    }

    .chat-container {
        height: 70vh !important;
    }

    /* Mobile message input fixes */
    .card-footer {
        padding: 8px !important;
        min-height: 60px;
        position: sticky;
        bottom: 0;
        z-index: 100;
        background-color: #f8f9fa !important;
        border-top: 1px solid #dee2e6 !important;
    }

    #message-form {
        width: 100%;
        display: flex !important;
        align-items: center;
    }

    #message-input {
        font-size: 16px !important; /* Prevents zoom on iOS */
        min-height: 38px;
        border-radius: 20px;
    }

    .input-group {
        flex: 1;
        margin-right: 8px;
    }

    #send-btn {
        width: 40px;
        height: 40px;
        border-radius: 50%;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
    }

    /* Hide participants sidebar on mobile */
    .col-lg-3.col-md-4 {
        display: none;
    }

    /* Make chat take full width on mobile */
    .col-lg-9.col-md-8 {
        flex: 0 0 100%;
        max-width: 100%;
    }

    /* Adjust container height for mobile */
    .card-body {
        height: calc(70vh - 140px) !important;
    }

    /* Mobile message container padding */
    #messages-container {
        padding: 10px 8px !important;
    }
}

@media (max-width: 576px) {
    .chat-container {
        height: 80vh !important;
        margin: 0 -15px;
        border-radius: 0 !important;
    }

    .container {
        padding: 0 !important;
    }

    .card-header {
        padding: 10px 15px !important;
    }

    .card-header h5 {
        font-size: 1rem !important;
    }

    .card-header .btn {
        padding: 4px 8px !important;
        font-size: 0.875rem !important;
    }

    /* Very small screens - extra compact */
    .card-footer {
        padding: 5px !important;
    }

    #message-input {
        padding: 8px 12px !important;
        font-size: 16px !important;
    }

    #send-btn {
        width: 36px;
        height: 36px;
    }
}

/* Mobile keyboard optimizations */
body.keyboard-open {
    height: 100vh;
    overflow: hidden;
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .btn {
        min-height: 44px; /* iOS touch target guidelines */
        min-width: 44px;
    }

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

    #message-input {
        min-height: 44px;
        padding: 10px 15px;
        font-size: 16px; /* Prevents zoom on iOS */
    }
}

/* Chat Online Badge Animation */
.chat-online-badge {
    animation: bounce 2s infinite;
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-3px);
    }
    60% {
        transform: translateY(-1px);
    }
}

/* Chat optimistic message styles */
.message.sending {
    opacity: 0.7;
    border-left: 3px solid #ffc107;
    position: relative;
}

.message.sending::after {
    content: '';
    position: absolute;
    top: 50%;
    right: 10px;
    width: 16px;
    height: 16px;
    border: 2px solid #ffc107;
    border-top: 2px solid transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    transform: translateY(-50%);
}

@keyframes spin {
    0% { transform: translateY(-50%) rotate(0deg); }
    100% { transform: translateY(-50%) rotate(360deg); }
}

/* Chat performance optimizations */
.message-bubble {
    will-change: transform;
}

.message {
    will-change: opacity;
}

/* Fast fade animations */
.message.fade-in {
    animation: fadeIn 0.2s ease-in;
}

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

/* Improved scroll performance */
#messages-container {
    scroll-behavior: smooth;
}

/* Typing indicator improvements */
.typing-indicator {
    transition: all 0.2s ease;
}

