/* ========================================
   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;
    margin: 0;
    /* Only horizontal safe area on body - vertical handled by components */
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

/* App Container */
.app-container {
    display: flex;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    width: 100vw;
    overflow: hidden;
}

/* ========================================
   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;
    background-color: #667eea; /* Fallback color */
}

.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;
    background-color: #667eea; /* Fallback color */
}

/* Saved Messages - special styling */
.saved-messages-item {
    background: rgba(102, 126, 234, 0.05);
}

.saved-messages-item:hover {
    background: rgba(102, 126, 234, 0.12);
}

.saved-messages-item.selected {
    background: rgba(102, 126, 234, 0.2);
}

.saved-messages-avatar {
    width: 54px;
    height: 54px;
    min-width: 54px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 12px;
    flex-shrink: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
}

.saved-messages-avatar svg {
    width: 24px;
    height: 24px;
}

/* Saved Messages chat header */
.chat-header.saved-messages-chat .chat-avatar {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
}

.chat-header.saved-messages-chat #chat-initials {
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-header.saved-messages-chat #chat-initials svg {
    width: 20px;
    height: 20px;
}

.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: #3390ec;
}

.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%;
    border-style: none !important;
}

/* 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;
    background-color: #667eea; /* Fallback color */
}

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

.online-indicator.online {
    background: #3390ec; /* Online/Typing - Telegram blue */
}

.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); /* Offline - gray */
}

/* Online status text color */
.chat-user-status.online {
    color: #3390ec;
}

/* Telegram-style typing indicator for chat header - scale animation */
.chat-user-status .typing-dots {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    margin-left: 4px;
    vertical-align: middle;
}

.chat-user-status .typing-dots span {
    width: 5px;
    height: 5px;
    background: #3390ec; /* Telegram blue */
    border-radius: 50%;
    display: inline-block;
    animation: headerTypingScale 1.4s infinite ease-in-out;
}

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

.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 headerTypingScale {
    0%, 40%, 100% {
        transform: scale(1);
        opacity: 0.4;
    }
    20% {
        transform: scale(1.5);
        opacity: 1;
    }
}

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

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

.chat-messages-container .chat-main-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    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;
    background-color: #667eea; /* Fallback color */
}

.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: 160px;
    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);
}

/* Hide camera button - attach button already handles images */
.messageBoxCamera {
    display: none !important;
}

.messageBoxAttach,
.messageBoxEmoji,
.messageBoxSend,
.messageBoxVoice {
    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);
}

/* Old styling removed - now using separate voice/send buttons */

.messageBoxSend:hover,
.messageBoxVoice:hover {
    transform: scale(1.05);
}

/* Voice button styling - same as send button */
.messageBoxVoice {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
}

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

/* Send button active state */
.messageBoxSend {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
}

/* 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 - Removed (now in chat-base.css with proper Telegram-style positioning) */

/* 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;
    overflow: hidden !important; /* Prevent container scroll - only chatHTML should scroll */
    height: 100% !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 1 auto !important;
    position: relative !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    min-height: 0 !important; /* Allow flex to shrink */
}

/* Override light theme message box */
.chat-main .messageBox {
    border-bottom-style: none;
    background: #1a1a1a !important;
    border: none !important;
    flex-shrink: 0 !important; /* Never shrink - always visible at bottom */
}

.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;
    margin-top: 2px; /* Slight offset for better visual alignment */
}

.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) {
    html, body {
        height: 100%;
        width: 100%;
        overflow: hidden;
        margin: 0;
        padding: 0;
    }

    .app-container {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        overflow: hidden;
        border-width: 0px !important;
    }

    .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%);
    }

    .sidebar-header {
        /* Extra padding for mobile status bar */
        padding-top: max(12px, env(safe-area-inset-top));
    }

    .back-btn {
        display: flex;
    }

    .chat-main {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        display: flex;
        flex-direction: column;
    }

    .active-chat {
        flex: 1;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        min-height: 0;
    }

    .chat-header {
        padding-top: max(12px, env(safe-area-inset-top));
        flex-shrink: 0;
    }

    .chat-messages-container {
        flex: 1;
        min-height: 0;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }

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

    .chatHTML {
        flex: 1;
        overflow-y: auto;
        min-height: 0;
    }

    .input-area-container {
        flex-shrink: 0;
    }

    .modal {
        width: 95%;
        margin: 20px;
        /* Respect safe areas for modals */
        max-height: calc(100vh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 40px);
    }
}

/* PWA Standalone mode specific styles */
@media (display-mode: standalone) {
    html, body {
        overflow: hidden;
        height: 100%;
        width: 100%;
    }

    .sidebar-header {
        padding-top: max(12px, env(safe-area-inset-top));
    }

    .chat-header {
        padding-top: max(12px, env(safe-area-inset-top));
    }
}

/* iOS Safari specific fixes - safe-area and keyboard handling */
@supports (-webkit-touch-callout: none) {
    #chatHTML {
        -webkit-overflow-scrolling: touch;
    }

    /* Apply safe-area padding only on iOS (for notched devices) */
    @media (max-width: 768px) {
        .messageBox,
        .input-area-container {
            padding-bottom: max(12px, env(safe-area-inset-bottom));
        }
    }

    /* iOS 15+ keyboard handling using env() */
    .input-area-container {
        padding-bottom: env(keyboard-inset-height, 0px);
    }
}

/* ========================================
   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);
}

/* ========================================
   MOBILE KEYBOARD HANDLING
   ======================================== */
@media (max-width: 768px) {
    body.keyboard-visible {
        overflow: hidden;
    }

    /* When keyboard is visible, ensure input stays above it */
    body.keyboard-visible .input-area-container {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 1100;
    }

    body.keyboard-visible .chat-main-container {
        padding-bottom: 60px; /* Space for fixed input */
    }
}

/* ========================================
   SIDEBAR FOOTER - Version Display
   ======================================== */
.sidebar-footer {
    padding: 8px 16px;
    text-align: center;
    /* border-top: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(0, 0, 0, 0.2); */
    flex-shrink: 0;
}

.app-version {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.3);
    font-family: 'Courier New', monospace;
    letter-spacing: 0.5px;
    user-select: all;
}

/* ========================================
   UPDATE BANNER - PWA Auto-Update
   ======================================== */
.update-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    z-index: 9999;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
    /* Safe area for notched devices */
    padding-bottom: max(12px, env(safe-area-inset-bottom));
}

.update-banner.show {
    transform: translateY(0);
}

.update-banner span {
    font-size: 14px;
    font-weight: 500;
}

.update-banner button {
    padding: 6px 16px;
    border: none;
    border-radius: 6px;
    font-family: 'Vazirmatn', sans-serif;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

#update-now-btn {
    background: #fff;
    color: #667eea;
}

#update-now-btn:hover {
    background: rgba(255, 255, 255, 0.9);
    transform: scale(1.02);
}

#update-dismiss-btn {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    width: 28px;
    height: 28px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    border-radius: 50%;
}

#update-dismiss-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ========================================
   iOS INSTALLATION BANNER
   ======================================== */
.ios-install-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    z-index: 9998;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
    padding-bottom: max(14px, env(safe-area-inset-bottom));
}

.ios-install-banner.show {
    transform: translateY(0);
}

.ios-install-content {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.ios-install-text {
    display: flex;
    flex-direction: column;
    gap: 3px;
    font-size: 13px;
    line-height: 1.4;
}

.ios-install-text strong {
    font-size: 14px;
    font-weight: 600;
}

.ios-install-text span {
    font-size: 12px;
    opacity: 0.95;
}

#ios-install-dismiss-btn {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    border-radius: 50%;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.2s ease;
}

#ios-install-dismiss-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ========================================
   MOBILE KEYBOARD - Reply Box Fix
   ======================================== */
@media (max-width: 768px) {
    /* Ensure replyToBox and messageBox stay together at bottom */
    .chat-main-container {
        display: flex;
        flex-direction: column;
    }

    /* Keep input area pinned to bottom */
    .replyToBox,
    .messageBox {
        flex-shrink: 0;
        position: relative;
        z-index: 100;
    }

    /* When keyboard is visible (detected via JS class), adjust layout */
    body.keyboard-visible .replyToBox,
    body.keyboard-visible .messageBox {
        position: sticky;
        bottom: 0;
    }

    /* Ensure reply content doesn't get cut off */
    .replyToBox.active {
        min-height: 60px;
    }
}
