/* Telegram Style Enhancements */

/* Message bubbles with proper Telegram styling */
.message-bubble {
    position: relative;
    word-wrap: break-word;
    max-width: 100%;
}

/* Outgoing message tail */
.message.me .message-bubble::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: -6px;
    width: 0;
    height: 0;
    border: 6px solid transparent;
    border-left: 6px solid var(--tg-bg-message-out);
    border-bottom: 0;
}

/* Incoming message tail */
.message.other .message-bubble::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: -6px;
    width: 0;
    height: 0;
    border: 6px solid transparent;
    border-right: 6px solid var(--tg-bg-message-in);
    border-bottom: 0;
}

/* RTL support for message tails */
[dir="rtl"] .message.me .message-bubble::after {
    right: auto;
    left: -6px;
    border-left: 0;
    border-right: 6px solid var(--tg-bg-message-out);
}

[dir="rtl"] .message.other .message-bubble::after {
    left: auto;
    right: -6px;
    border-right: 0;
    border-left: 6px solid var(--tg-bg-message-in);
}

/* Message time styling */
.message-time {
    display: block;
    text-align: left;
    margin-top: 4px;
    font-size: 11px;
    opacity: 0.7;
}

.message.me .message-time {
    color: rgba(255, 255, 255, 0.7);
}

.message.other .message-time {
    color: var(--tg-text-muted);
}

/* Sticker messages */
.sticker-message {
    display: block;
    max-width: 150px;
    max-height: 150px;
    border-radius: 12px;
    overflow: hidden;
}

.sticker-message img {
    width: 100%;
    height: auto;
    display: block;
}

/* Voice message improvements */
.voice-message {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: transparent;
    border-radius: 18px;
    min-width: 180px;
}

.message.me .voice-message {
    background: rgba(255, 255, 255, 0.1);
}

.message.other .voice-message {
    background: rgba(0, 0, 0, 0.05);
}

.voice-play-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: var(--tg-blue);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}

.voice-play-btn:hover {
    background: var(--tg-blue-dark);
}

.voice-progress {
    flex: 1;
    height: 3px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
    overflow: hidden;
    cursor: pointer;
}

.message.other .voice-progress {
    background: var(--tg-border-light);
}

.voice-progress-bar {
    height: 100%;
    background: white;
    border-radius: 2px;
    transition: width 0.1s ease;
}

.message.other .voice-progress-bar {
    background: var(--tg-blue);
}

.voice-duration {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.8);
    min-width: 35px;
    text-align: right;
}

.message.other .voice-duration {
    color: var(--tg-text-muted);
}

/* File message improvements */
.file-message {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    background: transparent;
    border-radius: 18px;
    max-width: 280px;
}

.file-icon {
    width: 36px;
    height: 36px;
    border-radius: 6px;
    background: var(--tg-blue);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

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

.file-name {
    font-size: 13px;
    font-weight: 400;
    color: var(--tg-text-primary);
    margin-bottom: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.message.me .file-name {
    color: white;
}

.file-actions {
    display: flex;
    gap: 8px;
    margin-top: 4px;
}

.file-btn {
    padding: 2px 8px;
    border: none;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 11px;
    text-decoration: none;
    cursor: pointer;
}

.message.other .file-btn {
    background: var(--tg-blue);
    color: white;
}

.file-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    color: white;
    text-decoration: none;
}

.message.other .file-btn:hover {
    background: var(--tg-blue-dark);
    color: white;
}

/* Chat input enhancements */
.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--tg-bg-input);
    border: 1px solid var(--tg-border);
    border-radius: 20px;
    padding: 4px 8px;
    min-height: 36px;
}

.chat-input-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.chat-input {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    outline: none;
    color: var(--tg-text-primary);
    font-size: 14px;
    line-height: 1.4;
    padding: 6px 0;
    max-height: 100px;
    min-height: 20px;
}

.chat-action-btn {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--tg-text-muted);
    cursor: pointer;
    font-size: 16px;
}

.chat-action-btn:hover {
    background: var(--tg-bg-secondary);
    color: var(--tg-blue);
}

.chat-action-btn.primary {
    background: var(--tg-blue);
    color: white;
}

.chat-action-btn.primary:hover {
    background: var(--tg-blue-dark);
}

/* Emoji and sticker picker improvements */
.emoji-picker,
.sticker-picker {
    position: absolute;
    bottom: 100%;
    left: 0;
    background: var(--tg-bg-primary);
    border: 1px solid var(--tg-border);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    display: none;
    width: 320px;
    max-height: 400px;
    overflow: hidden;
}

.emoji-picker.show,
.sticker-picker.show {
    display: block;
}

.emoji-header,
.sticker-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    border-bottom: 1px solid var(--tg-border);
    background: var(--tg-bg-secondary);
}

.emoji-header span,
.sticker-header span {
    font-size: 14px;
    font-weight: 500;
    color: var(--tg-text-primary);
}

.emoji-close,
.sticker-close {
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--tg-text-muted);
}

.emoji-close:hover,
.sticker-close:hover {
    background: var(--tg-bg-primary);
    color: var(--tg-text-primary);
}

.emoji-categories,
.sticker-categories {
    display: flex;
    padding: 4px 8px;
    gap: 2px;
    border-bottom: 1px solid var(--tg-border);
    background: var(--tg-bg-secondary);
    overflow-x: auto;
}

.emoji-category,
.sticker-category {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--tg-text-muted);
    flex-shrink: 0;
    font-size: 14px;
}

.emoji-category:hover,
.sticker-category:hover {
    background: var(--tg-bg-primary);
    color: var(--tg-blue);
}

.emoji-category.active,
.sticker-category.active {
    background: var(--tg-blue);
    color: white;
}

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 2px;
    padding: 8px;
    max-height: 280px;
    overflow-y: auto;
}

.emoji-item {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 18px;
}

.emoji-item:hover {
    background: var(--tg-bg-secondary);
}

.sticker-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    padding: 8px;
    max-height: 280px;
    overflow-y: auto;
}

.sticker-item {
    aspect-ratio: 1;
    border: 1px solid var(--tg-border-light);
    border-radius: 6px;
    background: var(--tg-bg-primary);
    cursor: pointer;
    overflow: hidden;
}

.sticker-item:hover {
    border-color: var(--tg-blue);
}

.sticker-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* User list improvements */
.user-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: var(--tg-bg-primary);
    border: none;
    border-bottom: 1px solid var(--tg-border-light);
    text-decoration: none;
    color: inherit;
    transition: background-color 0.2s ease;
}

.user-item:hover {
    background: var(--tg-bg-secondary);
    text-decoration: none;
    color: inherit;
}

.user-item .user-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--tg-blue);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 500;
    font-size: 18px;
    margin-left: 12px;
    flex-shrink: 0;
}

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

.user-item .user-name {
    font-size: 16px;
    font-weight: 400;
    color: var(--tg-text-primary);
    margin-bottom: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-item .user-username {
    font-size: 14px;
    color: var(--tg-text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-item .badge {
    background: var(--tg-green);
    color: white;
    border-radius: 8px;
    padding: 2px 6px;
    font-size: 11px;
    font-weight: 500;
}

/* Search input */
.user-search input {
    width: 100%;
    padding: 8px 16px;
    border: 1px solid var(--tg-border);
    border-radius: 20px;
    background: var(--tg-bg-input);
    color: var(--tg-text-primary);
    font-size: 14px;
    outline: none;
}

.user-search input:focus {
    border-color: var(--tg-blue);
}

.user-search input::placeholder {
    color: var(--tg-text-muted);
}

/* Voice recording controls */
.voice-controls-container {
    padding: 12px 16px;
    background: var(--tg-bg-header);
    border-top: 1px solid var(--tg-border);
}

.voice-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.voice-record-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: var(--tg-red);
    color: white;
    border: none;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
}

.voice-record-btn:hover {
    background: #d63031;
}

.voice-record-btn.recording {
    background: var(--tg-red);
}

.voice-wave {
    display: flex;
    align-items: center;
    gap: 2px;
    height: 20px;
}

.voice-wave-bar {
    width: 3px;
    background: white;
    border-radius: 2px;
    animation: wave 0.8s ease-in-out infinite;
}

@keyframes wave {
    0%, 100% { 
        height: 8px;
        opacity: 0.7; 
    }
    50% { 
        height: 16px;
        opacity: 1; 
    }
}

.recording-time {
    background: rgba(229, 62, 62, 0.1);
    color: var(--tg-red);
    padding: 4px 8px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 500;
    min-width: 50px;
    text-align: center;
}

.voice-actions {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-top: 8px;
}

.voice-action-btn {
    padding: 6px 12px;
    border: 1px solid var(--tg-border);
    border-radius: 12px;
    background: var(--tg-bg-secondary);
    color: var(--tg-text-secondary);
    font-size: 12px;
    cursor: pointer;
}

.voice-action-btn:hover {
    background: var(--tg-blue);
    color: white;
    border-color: var(--tg-blue);
}

/* Mobile optimizations */
@media (max-width: 768px) {
    .emoji-picker,
    .sticker-picker {
        width: 280px;
        max-height: 300px;
    }
    
    .emoji-grid {
        grid-template-columns: repeat(7, 1fr);
        max-height: 200px;
    }
    
    .sticker-grid {
        grid-template-columns: repeat(3, 1fr);
        max-height: 200px;
    }
    
    .voice-record-btn {
        padding: 8px 16px;
        font-size: 13px;
    }
    
    .chat-input-wrapper {
        padding: 3px 6px;
    }
    
    .chat-action-btn {
        width: 26px;
        height: 26px;
        font-size: 14px;
    }
}

/* Dark mode specific adjustments */
.dark .message.other .voice-message {
    background: rgba(255, 255, 255, 0.05);
}

.dark .file-btn {
    background: rgba(255, 255, 255, 0.1);
}

.dark .message.other .file-btn {
    background: var(--tg-blue);
}

/* Smooth transitions */
.message-bubble,
.voice-message,
.file-message,
.chat-action-btn,
.user-item,
.emoji-item,
.sticker-item {
    transition: all 0.2s ease;
}

/* Remove any remaining fancy effects */
.message-bubble:hover {
    transform: none;
    box-shadow: none;
}

.user-item:hover {
    transform: none;
    box-shadow: none;
}

/* Ensure proper z-index for pickers */
.emoji-picker,
.sticker-picker {
    z-index: 1050;
}