/* ========================================
   CHAT APP - Main application styles
   ======================================== */

/* Reset & Base */
* {
    /* margin: 0; */
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Vazirmatn', sans-serif;
    background: #0f0f0f;
    color: #fff;
    overflow: hidden;
}

/* App Container */
.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* ========================================
   SIDEBAR
   ======================================== */
.sidebar {
    width: 320px;
    min-width: 320px;
    background: #1a1a1a;
    display: flex;
    flex-direction: column;
    border-left: 1px solid rgba(255, 255, 255, 0.1);
}

/* Sidebar Header */
.sidebar-header {
    padding: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #242424;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

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

.user-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 600;
    color: #fff;
}

.user-details {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-size: 15px;
    font-weight: 600;
    color: #fff;
}

.user-id {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    font-family: 'Courier New', monospace;
    direction: ltr;
}

.user-id:hover {
    color: #667eea;
}

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

.action-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.action-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Add Contact Section */
.add-contact-section {
    padding: 12px 16px;
}

.add-contact-btn {
    width: 100%;
    padding: 12px 16px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 10px;
    color: #fff;
    font-family: 'Vazirmatn', sans-serif;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.3s ease;
}

.add-contact-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

/* Contacts List */
.contacts-list {
    flex: 1;
    overflow-y: auto;
}

.loading-contacts {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: rgba(255, 255, 255, 0.5);
    gap: 12px;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    border-top-color: #667eea;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Contact Item - Telegram Style */
.contact-item {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    cursor: pointer;
    transition: background 0.15s ease;
}

.contact-item:hover {
    background: rgba(255, 255, 255, 0.06);
}

.contact-item.selected {
    background: rgba(102, 126, 234, 0.15);
}

.contact-avatar {
    width: 54px;
    height: 54px;
    min-width: 54px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 600;
    color: #fff;
    margin-left: 12px;
    position: relative;
    flex-shrink: 0;
}

.online-dot {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 14px;
    height: 14px;
    background: transparent;
    border-radius: 50%;
    border: 2px solid #1a1a1a;
    display: none;
}

.contact-item.online .online-dot {
    display: block;
    background: #22c55e;
}

.contact-info {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

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

.contact-name {
    font-size: 15px;
    font-weight: 500;
    color: #fff;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    margin-left: 8px;
}

.contact-time {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.4);
    flex-shrink: 0;
}

.contact-preview {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.preview-text {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.5);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    line-height: 1.3;
}

.msg-status-icon {
    width: 14px;
    height: 14px;
    margin-left: 4px;
    flex-shrink: 0;
    opacity: 0.7;
    vertical-align: middle;
}

.unread-badge {
    background: #667eea;
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 12px;
    min-width: 22px;
    text-align: center;
    flex-shrink: 0;
}

/* Empty State */
.empty-contacts {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
    color: rgba(255, 255, 255, 0.4);
}

.empty-contacts p {
    margin-top: 16px;
    font-size: 16px;
    color: rgba(255, 255, 255, 0.6);
}

.empty-contacts span {
    font-size: 13px;
    margin-top: 8px;
}

/* ========================================
   MAIN CHAT AREA
   ======================================== */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #0a0a0a;
    position: relative;
}

/* No Chat Selected */
.no-chat-selected {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.no-chat-content {
    text-align: center;
    padding: 40px;
}

.no-chat-content h2 {
    color: rgba(255, 255, 255, 0.8);
    font-size: 24px;
    margin: 20px 0 10px;
}

.no-chat-content p {
    color: rgba(255, 255, 255, 0.4);
    font-size: 15px;
}

.my-id-display {
    margin-top: 30px;
    padding: 20px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    gap: 12px;
}

.my-id-display span {
    color: rgba(255, 255, 255, 0.5);
    font-size: 14px;
}

.my-id-display strong {
    font-size: 20px;
    font-family: 'Courier New', monospace;
    letter-spacing: 2px;
    color: #fff;
    direction: ltr;
}

.copy-id-btn {
    padding: 8px 16px;
    background: #667eea;
    border: none;
    border-radius: 6px;
    color: #fff;
    font-family: 'Vazirmatn', sans-serif;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.copy-id-btn:hover {
    background: #764ba2;
}

/* Active Chat */
.active-chat {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Chat Header */
.chat-header {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: #1a1a1a;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.back-btn {
    display: none;
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    color: #fff;
    cursor: pointer;
    margin-left: 8px;
}

.chat-user-info {
    display: flex;
    align-items: center;
    flex: 1;
}

.chat-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 600;
    color: #fff;
    margin-left: 12px;
    position: relative;
}

.online-indicator {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    background: #3a3a3a;
    border-radius: 50%;
    border: 2px solid #1a1a1a;
}

.online-indicator.online {
    background: #22c55e;
}

.chat-user-details {
    display: flex;
    flex-direction: column;
}

.chat-user-name {
    font-size: 16px;
    font-weight: 600;
    color: #fff;
}

.chat-user-status {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.5);
}

.chat-user-status .typing-dots span {
    animation: typingDot 1.4s infinite;
    opacity: 0.3;
}

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

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

@keyframes typingDot {

    0%,
    60%,
    100% {
        opacity: 0.3;
    }

    30% {
        opacity: 1;
    }
}

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

/* Chat Messages Container */
.chat-messages-container {
    flex: 1;
    overflow: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
}

.chat-messages-container .chat-main-container {
    flex: 1;
    position: relative;
    display: flex;
    flex-direction: column;
}

/* ========================================
   MODAL
   ======================================== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal {
    background: #1a1a1a;
    border-radius: 16px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
    animation: modalSlide 0.3s ease;
}

@keyframes modalSlide {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.modal-header h3 {
    font-size: 18px;
    font-weight: 600;
    color: #fff;
}

.modal-close {
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.modal-body {
    padding: 20px;
}

.modal-message {
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
    display: none;
}

.modal-message.error {
    background: rgba(239, 68, 68, 0.2);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #fca5a5;
    display: block;
}

.modal-message.success {
    background: rgba(34, 197, 94, 0.2);
    border: 1px solid rgba(34, 197, 94, 0.3);
    color: #86efac;
    display: block;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    color: rgba(255, 255, 255, 0.7);
    font-size: 13px;
    margin-bottom: 8px;
}

.form-group input {
    width: 100%;
    padding: 12px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: #fff;
    font-family: 'Vazirmatn', sans-serif;
    font-size: 15px;
    direction: ltr;
    text-align: center;
}

.form-group input::placeholder {
    color: rgba(255, 255, 255, 0.3);
}

.form-group input:focus {
    outline: none;
    border-color: #667eea;
}

/* Contact Preview */
.contact-preview {
    display: flex;
    align-items: center;
    /* padding: 16px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    margin-bottom: 16px; */
}

.preview-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 600;
    color: #fff;
    margin-left: 16px;
}

.preview-info {
    display: flex;
    flex-direction: column;
}

.preview-name {
    font-size: 16px;
    font-weight: 600;
    color: #fff;
}

.preview-id {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.5);
    font-family: 'Courier New', monospace;
    direction: ltr;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-family: 'Vazirmatn', sans-serif;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

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

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

.btn-secondary:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.2);
}

.btn-primary {
    background: #667eea;
    color: #fff;
}

.btn-primary:hover:not(:disabled) {
    background: #764ba2;
}

.btn-success {
    background: #22c55e;
    color: #fff;
}

.btn-success:hover:not(:disabled) {
    background: #16a34a;
}

/* ========================================
   TOAST NOTIFICATION
   ======================================== */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: rgba(255, 255, 255, 0.95);
    color: #1a1a1a;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    transition: transform 0.3s ease;
    z-index: 9999;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
}

/* ========================================
   MESSAGE BOX
   ======================================== */
.messageBox {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 16px;
    background: #1a1a1a;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.messageInputWrapper {
    flex: 1;
    min-width: 0;
}

.messageInputContainer {
    width: 100%;
}

.custom-text-input {
    width: 100%;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 24px;
    color: #fff;
    font-family: 'Vazirmatn', sans-serif;
    font-size: 15px;
    resize: none;
    outline: none;
    max-height: 80px;
    line-height: 1.4;
}

.custom-text-input::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

.custom-text-input:focus {
    border-color: rgba(102, 126, 234, 0.5);
    background: rgba(255, 255, 255, 0.1);
}

.messageBoxCamera,
.messageBoxAttach,
.messageBoxEmoji,
.messageBoxSend {
    width: 44px;
    height: 44px;
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.6);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.messageBoxCamera:hover,
.messageBoxAttach:hover,
.messageBoxEmoji:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.messageBoxEmoji.active {
    color: #667eea;
    background: rgba(102, 126, 234, 0.2);
}

.messageBoxSend {
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.7);
}

.messageBoxSend:hover {
    background: rgba(255, 255, 255, 0.2);
}

.messageBoxSend.send-mode {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
}

.messageBoxSend.send-mode:hover {
    transform: scale(1.05);
}

.messageBoxSend svg {
    width: 22px;
    height: 22px;
    fill: currentColor;
}

/* Remove top border when reply/edit bar is visible */
.messageBox.reply-active {
    border-top: none !important;
}

/* Smooth layout compensation when reply bar animates */
.chat-main .replyToBox {
    will-change: transform, opacity, max-height;
}

.messageBoxCamera svg,
.messageBoxAttach svg,
.messageBoxEmoji svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

/* Emoji Picker Overlay */
.emoji-picker-overlay {
    position: absolute;
    bottom: 70px;
    left: 16px;
    right: 16px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    z-index: 1000;
    max-height: 350px;
    overflow: hidden;
}

.emoji-picker-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid #eee;
}

.emoji-picker-close {
    width: 28px;
    height: 28px;
    border: none;
    background: #f0f0f0;
    border-radius: 50%;
    font-size: 18px;
    color: #666;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.emoji-picker-close:hover {
    background: #e0e0e0;
}

.emoji-picker-content {
    max-height: 300px;
    overflow-y: auto;
}

/* Emoji Mart Overrides */
.emoji-picker-content em-emoji-picker {
    width: 100%;
    border: none;
    --background-rgb: 255, 255, 255;
}

/* ========================================
   CHAT HTML (Messages Area) - DARK THEME OVERRIDES
   ======================================== */
#chatHTML {
    flex: 1;
    overflow-y: auto;
    /* padding: 16px; */
    scroll-behavior: smooth;
}

/* Dark theme overrides for chat area */
.chat-main .chat-main-container {
    background-color: var(--background-dark) !important;
    display: flex !important;
    flex-direction: column !important;
}

/* Add dark overlay over backImage for dark theme */
.chat-main .backImage::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(10, 10, 10, 0.85);
    pointer-events: none;
}

.chat-main .chatHTML {
    background-color: transparent !important;
    flex: 1 !important;
    position: relative !important;
}

/* Override light theme message box */
.chat-main .messageBox {
    background: #1a1a1a !important;
    border-top: 1px solid rgba(255, 255, 255, 0.1) !important;
    border-color: rgba(255, 255, 255, 0.1) !important;
}

.chat-main .messageBox.reply-active {
    border-top: none !important;
}

/* Dark theme text input */
.chat-main .custom-text-input {
    color: #fff !important;
    background: rgba(255, 255, 255, 0.08) !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    border-radius: 20px !important;
    padding: 8px 16px !important;
}

.chat-main .custom-text-input::placeholder {
    color: rgba(255, 255, 255, 0.4) !important;
}

/* Dark theme buttons */
.chat-main .messageBoxCamera,
.chat-main .messageBoxAttach,
.chat-main .messageBoxEmoji {
    color: rgba(255, 255, 255, 0.6) !important;
}

.chat-main .messageBoxCamera:hover,
.chat-main .messageBoxAttach:hover,
.chat-main .messageBoxEmoji:hover {
    color: #fff !important;
    background: rgba(255, 255, 255, 0.1) !important;
}

.chat-main .messageBoxSend {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    color: #fff !important;
}

/* Dark theme bubbles - override light theme */
.chat-main .bubbleLeft,
.chat-main .bubbleLeftEx {
    background: var(--bubble-left-dark);
    color: #fff !important;
    border-bottom: none !important;
}

.chat-main .bubbleLeft:after {
    border-color: transparent var(--bubble-left-dark) transparent transparent !important;
}

.chat-main .bubbleRight,
.chat-main .bubbleRightEx {
    background: var(--bubble-right-dark);
    color: #fff !important;
    border-bottom: none !important;
}

.chat-main .bubbleRight:after {
    border-color: transparent transparent transparent #764ba2 !important;
}

.chat-main .bubbleText {
    color: rgba(255, 255, 255, 0.7) !important;
}

.chat-main .bubble-text {
    color: #fff !important;
}

/* ========================================
   MOBILE RESPONSIVE
   ======================================== */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-width: 100%;
        z-index: 100;
        transition: transform 0.3s ease;
    }

    .sidebar.hidden {
        transform: translateX(100%);
    }

    .back-btn {
        display: flex;
    }

    .chat-main {
        width: 100%;
    }

    .modal {
        width: 95%;
        margin: 20px;
    }
}

/* ========================================
   SCROLLBAR
   ======================================== */
.contacts-list::-webkit-scrollbar {
    width: 6px;
}

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

.contacts-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.contacts-list::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}
