/* Chat Widget - Fixed at bottom of viewport */
.chat-widget {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    background: #2b2b2b;
    border-top: 2px solid #444;
    z-index: 9999 !important;
    width: 100% !important;
    margin: 0 !important;
    display: flex;
    flex-direction: column;
    /* Smooth animation for state transitions using max-height */
    transition: max-height 0.8s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

.chat-widget.collapsed {
    max-height: 250px;
}

.chat-widget.super-small {
    max-height: 120px;
}

.chat-widget.expanded {
    max-height: 600px;
}

/* Header with tabs and expand button */
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding: 0 12px 0 0;
    background: #1a1a1a;
    border-bottom: 2px solid #444;
    flex-shrink: 0;
}

.chat-header-buttons {
    display: flex;
    gap: 4px;
    align-items: center;
}

.chat-tabs {
    display: flex;
    gap: 2px;
    align-items: flex-end;
}

.chat-tab {
    background: #2b2b2b;
    border: none;
    border-top: 2px solid #555;
    border-left: 1px solid #555;
    border-right: 1px solid #555;
    border-bottom: none;
    color: #999;
    padding: 8px 16px;
    cursor: pointer;
    border-radius: 6px 6px 0 0;
    transition: all 0.2s;
    position: relative;
    bottom: -2px;
    font-size: 14px;
    font-weight: 500;
}

.chat-tab:hover {
    background: #333;
    color: #fff;
    border-top-color: #666;
}

.chat-tab.active {
    background: #2b2b2b;
    color: #007bff;
    border-top-color: #007bff;
    border-left-color: #444;
    border-right-color: #444;
    border-bottom: 2px solid #2b2b2b;
    bottom: -2px;
    z-index: 1;
}

.btn-expand {
    background: transparent;
    border: none;
    color: #999;
    padding: 8px;
    cursor: pointer;
    font-size: 14px;
    transition: color 0.2s;
}

.btn-expand:hover {
    color: #fff;
}

/* Message preview (collapsed mode) */
.chat-preview {
    padding: 8px 12px;
    color: #ccc;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: background 0.2s;
    justify-content: space-between;
}

.chat-preview:hover {
    background: #333;
}

.chat-preview-content {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex: 1;
}

.message-sender {
    font-weight: bold;
    color: #007bff;
    flex-shrink: 0;
}

.message-time-preview {
    font-size: 11px;
    color: #666;
    flex-shrink: 0;
    white-space: nowrap;
}

.message-text {
    color: #ddd;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

/* Message list (expanded mode) */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    background: #1e1e1e;
    min-height: 0;
    display: flex;
    flex-direction: column;
    /* Hide when not expanded using max-height instead of display */
    max-height: 999px;
    transition: max-height 0.8s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease;
    opacity: 1;
}

.chat-widget.collapsed .chat-messages,
.chat-widget.super-small .chat-messages {
    max-height: 0;
    padding: 0;
    opacity: 0;
}

/* Loading indicator */
.chat-messages > .text-center {
    padding: 12px;
    background: #2b2b2b;
    border-radius: 6px;
    margin-bottom: 8px;
    flex-shrink: 0;
}

.chat-messages .spinner-border-sm {
    width: 1rem;
    height: 1rem;
    border-width: 0.15em;
}

.chat-message {
    margin-bottom: 12px;
    padding: 8px;
    background: #2b2b2b;
    border-radius: 6px;
    transition: background 0.2s;
}

.message-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.message-time {
    font-size: 11px;
    color: #666;
}

.message-content {
    color: #ddd;
    font-size: 14px;
    word-wrap: break-word;
}

/* Input area */
.chat-input {
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    background: #1a1a1a;
    border-top: 1px solid #444;
    flex-shrink: 0;
    transition: max-height 0.8s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease;
}

/* Input in collapsed mode (visible) */
.chat-widget.collapsed .chat-input {
    max-height: 50px;
    opacity: 1;
}

.chat-widget.super-small .chat-input {
    max-height: 0;
    overflow: hidden;
    padding: 0;
    opacity: 0;
}

/* Expanded input area - only shown when expanded */
.chat-input-expanded {
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    background: #1a1a1a;
    border-top: 1px solid #444;
    flex-shrink: 0;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.8s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease;
    opacity: 0;
}

.chat-widget.expanded .chat-input-expanded {
    max-height: 50px;
    opacity: 1;
}

.chat-input input {
    flex: 1;
    background: #2b2b2b;
    border: 1px solid #444;
    color: #fff;
    padding: 6px 12px;
    border-radius: 4px;
}

.chat-input input:focus {
    outline: none;
    border-color: #007bff;
}

.chat-input input::placeholder {
    color: #666;
}

.chat-input .emoji-btn {
    padding: 6px 12px;
    background: #555;
    border: none;
    color: #fff;
    border-radius: 4px;
    cursor: pointer;
    flex-shrink: 0;
}

.chat-input .emoji-btn:hover {
    background: #666;
}

.chat-input button {
    padding: 6px 12px;
    background: #007bff;
    border: none;
    color: #fff;
    border-radius: 4px;
    cursor: pointer;
    flex-shrink: 0;
}

.chat-input button:hover:not(:disabled) {
    background: #0056b3;
}

.chat-input button:disabled {
    background: #555;
    cursor: not-allowed;
}

/* Emoji Picker */
.emoji-picker {
    position: fixed;
    bottom: auto;
    top: auto;
    right: 12px;
    background: #2b2b2b;
    border: 2px solid #444;
    border-radius: 8px;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.5);
    width: 320px;
    max-height: 400px;
    display: flex;
    flex-direction: column;
    z-index: 10000;
    margin-bottom: 0;
    /* Position above the chat-input, below the messages */
    bottom: 100px;
}

.emoji-picker-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: #1a1a1a;
    border-bottom: 1px solid #444;
    border-radius: 6px 6px 0 0;
}

.emoji-picker-header span {
    color: #fff;
    font-weight: bold;
    font-size: 14px;
}

.btn-close-emoji {
    background: transparent;
    border: none;
    color: #999;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
}

.btn-close-emoji:hover {
    color: #fff;
}

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 4px;
    padding: 12px;
    overflow-y: auto;
    max-height: 350px;
}

.emoji-item {
    background: transparent;
    border: none;
    font-size: 24px;
    padding: 8px;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
}

.emoji-item:hover {
    background: #444;
    transform: scale(1.2);
}

/* Emoji grid scrollbar */
.emoji-grid::-webkit-scrollbar {
    width: 8px;
}

.emoji-grid::-webkit-scrollbar-track {
    background: #1a1a1a;
}

.emoji-grid::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 4px;
}

.emoji-grid::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Scrollbar styling for message area */
.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: #1a1a1a;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Message Reactions */
.message-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 6px;
    align-items: center;
}

.reaction-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: #3a3a3a;
    border: 1px solid #555;
    border-radius: 12px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
}

.reaction-badge:hover {
    background: #4a4a4a;
    border-color: #666;
    transform: scale(1.05);
}

.reaction-badge.reacted {
    background: #004494;
    border-color: #007bff;
}

.reaction-badge.reacted:hover {
    background: #0056b3;
}

.reaction-emoji {
    font-size: 16px;
    line-height: 1;
}

.reaction-count {
    font-size: 12px;
    color: #ccc;
    font-weight: 500;
}

.reaction-add-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 0;
    background: transparent;
    border: 1px solid #555;
    border-radius: 12px;
    color: #999;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 12px;
}

.reaction-add-btn:hover {
    background: #4a4a4a;
    border-color: #007bff;
    color: #007bff;
}

/* Reaction Picker */
.reaction-picker {
    position: fixed;
    bottom: auto;
    top: auto;
    right: 12px;
    background: #2b2b2b;
    border: 2px solid #444;
    border-radius: 8px;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.5);
    width: 240px;
    display: flex;
    flex-direction: column;
    z-index: 10001;
    margin-bottom: 0;
    /* Position above the chat-input, below the messages */
    bottom: 100px;
}

.reaction-picker-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: #1a1a1a;
    border-bottom: 1px solid #444;
    border-radius: 6px 6px 0 0;
}

.reaction-picker-header span {
    color: #fff;
    font-weight: bold;
    font-size: 14px;
}

.reaction-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    padding: 12px;
}

.reaction-item {
    background: transparent;
    border: none;
    font-size: 28px;
    padding: 8px;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
}

.reaction-item:hover {
    background: #444;
    transform: scale(1.2);
}

/* ========================================
   MOBILE RESPONSIVE STYLES
   ======================================== */

/* Tablets and smaller devices */
@media (max-width: 768px) {
    /* Increase expanded height on tablets */
    .chat-widget.expanded {
        height: 60vh;
        max-height: none;
    }

    /* Larger touch targets for tabs */
    .chat-tab {
        padding: 10px 14px;
        font-size: 13px;
    }

    /* Larger expand button */
    .btn-expand {
        padding: 10px 12px;
        font-size: 16px;
    }

    /* Emoji picker adjustments */
    .emoji-picker {
        width: 280px;
        right: 8px;
        bottom: 80px;
    }

    .emoji-grid {
        grid-template-columns: repeat(6, 1fr);
    }

    /* Reaction picker adjustments */
    .reaction-picker {
        width: 200px;
        right: 8px;
        bottom: 80px;
    }
}

/* Mobile phones - portrait and landscape */
@media (max-width: 576px) {
    /* Full-screen expansion on mobile */
    .chat-widget.expanded {
        height: 70vh;
        max-height: none;
    }

    /* Compact header for mobile */
    .chat-header {
        padding: 0 8px 0 0;
    }

    /* Smaller, more compact tabs */
    .chat-tab {
        padding: 8px 12px;
        font-size: 12px;
        border-radius: 4px 4px 0 0;
    }

    /* Larger touch-friendly expand button */
    .btn-expand {
        padding: 10px;
        font-size: 18px;
        min-width: 40px;
        min-height: 40px;
    }

    /* Mobile-friendly message preview */
    .chat-preview {
        padding: 10px 8px;
        font-size: 13px;
        gap: 6px;
    }

    .message-sender {
        font-size: 13px;
    }

    .message-time-preview {
        font-size: 10px;
    }

    /* Better spacing for messages on mobile */
    .chat-messages {
        padding: 8px;
    }

    .chat-message {
        margin-bottom: 10px;
        padding: 10px;
    }

    .message-content {
        font-size: 13px;
        line-height: 1.5;
    }

    /* Larger, touch-friendly input area */
    .chat-input {
        padding: 10px 8px;
        gap: 6px;
    }

    .chat-input input {
        padding: 10px 12px;
        font-size: 16px; /* Prevents zoom on iOS */
        height: 44px; /* Match button height */
    }

    /* Larger touch-friendly buttons */
    .chat-input .emoji-btn,
    .chat-input button {
        padding: 0 14px;
        font-size: 16px;
        min-width: 44px;
        height: 44px; /* Exact height instead of min-height */
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Full-width emoji picker on mobile */
    .emoji-picker {
        width: calc(100vw - 16px);
        max-width: 100%;
        left: 8px;
        right: 8px;
        max-height: 50vh;
        bottom: 70px;
    }

    /* Fewer columns for better touch targets */
    .emoji-grid {
        grid-template-columns: repeat(5, 1fr);
        gap: 6px;
        padding: 10px;
    }

    /* Larger emoji items for easier tapping */
    .emoji-item {
        font-size: 28px;
        padding: 10px;
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Full-width reaction picker on mobile */
    .reaction-picker {
        width: calc(100vw - 16px);
        max-width: 100%;
        left: 8px;
        right: 8px;
        bottom: 70px;
    }
}

/* Very small phones (iPhone SE, etc.) */
@media (max-width: 375px) {
    /* Even more compact layout */
    .chat-tab {
        padding: 6px 10px;
        font-size: 11px;
    }

    /* Smaller emoji grid on tiny screens */
    .emoji-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    /* Adjust message content */
    .message-content {
        font-size: 12px;
    }

    .message-sender {
        font-size: 12px;
    }
}

/* Landscape orientation on phones */
@media (max-width: 896px) and (orientation: landscape) {
    /* More compact when in landscape */
    .chat-widget.expanded {
        height: 80vh;
        max-height: none;
    }

    /* Compact input in landscape */
    .chat-input {
        padding: 6px 8px;
    }

    .chat-input input {
        padding: 8px 10px;
    }

    .chat-input .emoji-btn,
    .chat-input button {
        padding: 8px 12px;
        min-width: 40px;
        min-height: 40px;
    }

    /* Smaller emoji picker in landscape */
    .emoji-picker {
        max-height: 60vh;
    }
}
