/* Chat Modal Overlay and Container */
#chat-modal.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.7);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

#chat-modal .modal-container {
    background: #181c24;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.25);
    max-width: min(900px, calc(100vw - 40px));
    width: 100%;
    height: min(600px, calc(100vh - 40px));
    margin: 0 auto;
    padding: 0;
    overflow: hidden;
    color: #fff;
    display: flex;
    flex-direction: column;
}

#chat-modal .modal-header {
    background: #23283a;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    margin-bottom: 0px;
}

#chat-modal .modal-title {
    font-size: 1.3rem;
    font-weight: bold;
    margin: 0;
}

#chat-modal .modal-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 1.5rem;
    cursor: pointer;
    transition: opacity 0.2s;
    padding: 4px 8px;
}

#chat-modal .modal-close:hover {
    opacity: 0.7;
}

#chat-modal .modal-body {
    flex: 1;
    overflow: hidden;
    padding: 0;
    display: flex;
    margin-bottom: 0px;
}

/* Chat Container Layout */
.chat-container {
    display: flex;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* Chat Sidebar */
.chat-sidebar {
    width: 320px;
    background: #1e2330;
    border-right: 1px solid rgba(255,255,255,0.1);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

/* Conversations Header */
.conversations-header {
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

.conversations-header h3 {
    margin: 0;
    font-size: 1.1rem;
    color: #fff;
}

.new-chat-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #2196f3;
    border: none;
    color: #fff;
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.new-chat-btn:hover {
    background: #1976d2;
    transform: scale(1.05);
}

/* Search Container */
.search-container {
    padding: 12px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

.search-input {
    width: 100%;
    padding: 10px 16px;
    background: #23283a;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 24px;
    color: #fff;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.search-input::placeholder {
    color: #64748b;
}

.search-input:focus {
    outline: none;
    border-color: #2196f3;
    background: #2d3748;
}

/* Conversations List */
.conversations-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

.conversations-list::-webkit-scrollbar {
    width: 6px;
}

.conversations-list::-webkit-scrollbar-track {
    background: transparent;
}

.conversations-list::-webkit-scrollbar-thumb {
    background: #475569;
    border-radius: 3px;
}

.conversations-list::-webkit-scrollbar-thumb:hover {
    background: #64748b;
}

/* Conversation Item */
.conversation-item {
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: background 0.2s;
    position: relative;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

.conversation-item:hover {
    background: rgba(255,255,255,0.05);
}

.conversation-item.active {
    background: #2d3748;
}

.conversation-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.conversation-info {
    flex: 1;
    min-width: 0;
}

.conversation-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 4px;
}

.conversation-name {
    font-weight: 600;
    color: #fff;
    font-size: 0.95rem;
}

.conversation-time {
    font-size: 0.75rem;
    color: #64748b;
}

.conversation-preview {
    font-size: 0.85rem;
    color: #94a3b8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.last-message {
    margin-left: -84%;
}

.typing-indicator {
    color: #22c55e;
    font-style: italic;
}

.unread-badge {
    position: absolute;
    top: 50%;
    right: 16px;
    transform: translateY(-50%);
    background: #2196f3;
    color: #fff;
    font-size: 0.75rem;
    font-weight: bold;
    padding: 2px 8px;
    border-radius: 12px;
    min-width: 20px;
    text-align: center;
}

/* Empty Conversations */
.empty-conversations {
    padding: 48px 24px;
    text-align: center;
    color: #94a3b8;
}

.empty-conversations p {
    margin: 0 0 16px 0;
    font-size: 0.95rem;
}

.start-chat-btn {
    padding: 10px 24px;
    background: #2196f3;
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.2s;
}

.start-chat-btn:hover {
    background: #1976d2;
}

/* Chat Main Area */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #181c24;
}

/* No Conversation Selected */
.no-conversation {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.empty-chat {
    text-align: center;
    padding: 48px;
}

.empty-icon {
    font-size: 4rem;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-chat h3 {
    font-size: 1.5rem;
    margin: 0 0 8px 0;
    color: #fff;
}

.empty-chat p {
    font-size: 1rem;
    color: #94a3b8;
    margin: 0 0 24px 0;
}

.primary-btn {
    padding: 12px 32px;
    background: #2196f3;
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    transition: all 0.2s;
}

.primary-btn:hover {
    background: #1976d2;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(33, 150, 243, 0.3);
}

/* Chat Header */
.chat-header {
    padding: 16px 20px;
    background: #23283a;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.1rem;
}

.chat-details h3 {
    margin: 0;
    font-size: 1.1rem;
    color: #fff;
}

.user-status {
    font-size: 0.85rem;
    color: #94a3b8;
}

.user-status.online {
    color: #22c55e;
}

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

.icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: transparent;
    border: none;
    color: #94a3b8;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.icon-btn:hover {
    background: rgba(255,255,255,0.1);
    color: #fff;
}

/* Messages Container */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

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

.messages-container::-webkit-scrollbar-track {
    background: transparent;
}

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

.messages-container::-webkit-scrollbar-thumb:hover {
    background: #64748b;
}

/* No Messages */
.no-messages {
    text-align: center;
    padding: 48px;
    color: #94a3b8;
    margin: auto;
}

.no-messages p {
    font-size: 1rem;
    margin: 0;
}

/* Date Separator */
.date-separator {
    text-align: center;
    margin: 16px 0;
    position: relative;
}

.date-separator span {
    background: #181c24;
    padding: 0 16px;
    color: #64748b;
    font-size: 0.85rem;
    position: relative;
    z-index: 1;
}

.date-separator::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    background: rgba(255,255,255,0.1);
}

/* Messages */
.message {
    display: flex;
    margin-bottom: 4px;
    animation: messageSlide 0.3s ease-out;
}

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

.message.sent {
    justify-content: flex-end;
}

.message.friend {
    justify-content: flex-start;
}

.message-bubble {
    max-width: 70%;
    padding: 12px 16px;
    border-radius: 18px;
    position: relative;
    word-wrap: break-word;
}

.message.sent .message-bubble {
    background: #2196f3;
    color: #fff;
    border-bottom-right-radius: 4px;
}

.message.friend .message-bubble {
    background: #2d3748;
    color: #fff;
    border-bottom-left-radius: 4px;
}

.message-bubble p {
    margin: 0;
    line-height: 1.4;
}

.message-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
    font-size: 0.75rem;
    opacity: 0.8;
}

.message-time {
    color: inherit;
}

.message-status {
    display: inline-flex;
}

.message-status.sent::after {
    content: '✓';
}

.message-status.delivered::after {
    content: '✓✓';
}

.message-status.read::after {
    content: '✓✓';
    color: #4ade80;
}

/* Typing Animation */
.typing-dots {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    background: #94a3b8;
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-10px);
    }
}

/* Message Input Container */
.message-input-container {
    padding: 16px 20px;
    background: #23283a;
    border-top: 1px solid rgba(255,255,255,0.1);
    flex-shrink: 0;
}

.message-input-wrapper {
    display: flex;
    gap: 12px;
    align-items: center;
}

.message-input {
    flex: 1;
    padding: 12px 20px;
    background: #2d3748;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 24px;
    color: #fff;
    font-size: 0.95rem;
    resize: none;
    transition: all 0.2s;
}

.message-input::placeholder {
    color: #64748b;
}

.message-input:focus {
    outline: none;
    border-color: #2196f3;
    background: #374151;
}

.message-input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #475569;
    border: none;
    color: #94a3b8;
    font-size: 1.3rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.send-btn.active {
    background: #2196f3;
    color: #fff;
}

.send-btn:hover:not(:disabled) {
    transform: scale(1.05);
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Error State */
.error-state {
    text-align: center;
    padding: 48px;
    color: #ef4444;
}

.error-state p {
    margin: 0 0 16px 0;
    font-size: 1.1rem;
}

.error-state button {
    padding: 10px 24px;
    background: #ef4444;
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    transition: background 0.2s;
}

.error-state button:hover {
    background: #dc2626;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 48px;
    color: #94a3b8;
}

@media screen and (orientation: landscape) and (max-height: 600px) {

}

@media screen and (orientation: portrait) and (max-width: 390px) {
    .chat-sidebar {
        width: 100%;
    }
    .chat-main {
        display: none;
    }
}