* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    margin: 0;
    padding: 0;
    height: 100vh;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f0f2f5;
    font-size: 16px;
}

/* Auth Modal Styles */
.auth-logo {
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, #25d366 0%, #128c7e 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 2.5rem;
}

.modal-content {
    background: white;
    backdrop-filter: blur(20px);
}

.form-control:focus {
    border-color: #25d366;
    box-shadow: 0 0 0 0.2rem rgba(37, 211, 102, 0.25);
}

.btn-success {
    background: linear-gradient(135deg, #25d366 0%, #128c7e 100%);
    border: none;
    font-weight: 600;
}

.btn-success:hover {
    background: linear-gradient(135deg, #20b358 0%, #0e6b5e 100%);
    transform: translateY(-1px);
}

/* Main App Layout */
#chatApp {
    height: 100vh;
    position: relative;
    overflow: hidden;
}

.chat-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: white;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-screen.active {
    transform: translateX(0);
}

.chat-screen.slide-out {
    transform: translateX(-100%);
}

/* Header Styles */
.chat-header {
    background: linear-gradient(135deg, #25d366 0%, #128c7e 100%) !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    position: relative;
    z-index: 10;
}

.user-avatar {
    width: 45px;
    height: 45px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.2rem;
    backdrop-filter: blur(10px);
    position: relative;
    overflow: hidden;
}

.user-avatar:hover .avatar-overlay {
    opacity: 1;
}

.avatar-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    opacity: 0;
    transition: opacity 0.3s ease;
    color: white;
}

/* Search Container */
.search-container {
    background: #f0f2f5;
    border-bottom: 1px solid #e9ecef;
}

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

.contact-item {
    padding: 16px 20px;
    border-bottom: 1px solid #f0f2f5;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    background: white;
    position: relative;
}

.contact-item:hover {
    background: #f8f9fa;
}

.contact-item:active {
    background: #e9ecef;
    transform: scale(0.98);
}

.contact-avatar {
    width: 55px;
    height: 55px;
    background: linear-gradient(135deg, #25d366 0%, #128c7e 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.3rem;
    margin-left: 15px;
    flex-shrink: 0;
}

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

.contact-name {
    font-weight: 600;
    font-size: 1.1rem;
    color: #1f2937;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.contact-status {
    font-size: 0.9rem;
    color: #6b7280;
}

.contact-status.online {
    color: #10b981;
    font-weight: 500;
}

/* New Message Indicator */
.new-message-indicator {
    width: 12px;
    height: 12px;
    background: #25d366;
    border-radius: 50%;
    position: absolute;
    top: 16px;
    right: 16px;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.7; transform: scale(1.1); }
}

/* Messages Area */
.messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
    background: linear-gradient(to bottom, #e5ddd5 0%, #e5ddd5 100%);
    background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23ffffff' fill-opacity='0.1'%3E%3Cpath d='M50 30c11.046 0 20 8.954 20 20s-8.954 20-20 20-20-8.954-20-20 8.954-20 20-20zm0 5c-8.284 0-15 6.716-15 15s6.716 15 15 15 15-6.716 15-15-6.716-15-15-15z'/%3E%3C/g%3E%3C/svg%3E");
}

/* Message Bubbles */
.message {
    max-width: 80%;
    margin-bottom: 16px;
    padding: 12px 16px;
    border-radius: 18px;
    word-wrap: break-word;
    position: relative;
    font-size: 1rem;
    line-height: 1.4;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

.message-sent {
    background: linear-gradient(135deg, #dcf8c6 0%, #d4edda 100%);
    margin-left: auto;
    margin-right: 8px;
    border-bottom-right-radius: 4px;
    color: #2d5016;
    border: 1px solid rgba(37, 211, 102, 0.2);
}

.message-received {
    background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
    margin-right: auto;
    margin-left: 8px;
    border-bottom-left-radius: 4px;
    color: #2c3e50;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(0, 0, 0, 0.05);
}

/* Message Content Styling */
.message-content {
    margin-bottom: 8px;
    font-weight: 500;
}

/* Media Message Styling */
.message-image img {
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    transition: transform 0.2s ease;
    cursor: pointer;
}

.message-image img:hover {
    transform: scale(1.02);
}

.message-audio audio {
    border-radius: 25px;
    outline: none;
    background: rgba(37, 211, 102, 0.1);
}

.message-video video {
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    cursor: pointer;
}

.message-time {
    font-size: 0.75rem;
    color: #6c757d;
    margin-top: 8px;
    text-align: left;
    font-weight: 400;
    opacity: 0.8;
}

.message-sent .message-time {
    text-align: right;
    color: #4a5e2a;
}

.message-received .message-time {
    color: #6c757d;
}

/* Message hover effects */
.message:hover {
    transform: translateY(-1px);
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.15);
}

/* Media message spacing */
.message-image,
.message-audio,
.message-video {
    margin-bottom: 8px;
}

/* Empty content for media messages */
.message .message-content:empty {
    display: none;
}

/* Message Input */
.message-input {
    background: white;
    border-top: 1px solid #e9ecef;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
}

.message-input .input-group {
    background: #f0f2f5;
    border-radius: 25px;
    padding: 8px;
}

.message-input .form-control {
    background: transparent;
    resize: none;
    border: none;
    font-size: 1rem;
    padding: 8px 12px;
}

.message-input .form-control:focus {
    box-shadow: none;
    border: none;
}

.message-input .btn {
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#sendBtn {
    width: 50px;
    height: 50px;
    box-shadow: 0 2px 8px rgba(37, 211, 102, 0.3);
}

/* Recording button styles */
#recordBtn {
    transition: all 0.3s ease;
}

#recordBtn:active,
#recordBtn.recording {
    background: #ef4444 !important;
    transform: scale(1.1);
}

#recordBtn.recording i {
    color: white !important;
}

/* Animation Classes */
@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(30px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-30px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

.message-sent {
    animation: slideInRight 0.3s ease;
}

.message-received {
    animation: slideInLeft 0.3s ease;
}

/* Loading Animation */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #25d366;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Notification Styles */
.notification {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 12px 20px;
    border-radius: 10px;
    color: white;
    font-weight: 500;
    z-index: 9999;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.notification.show {
    transform: translateX(0);
}

.notification.success {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}

.notification.error {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
}

/* Responsive Design */
@media (max-width: 576px) {
    .contact-item {
        padding: 16px;
    }

    .contact-name {
        font-size: 1rem;
    }

    .message {
        max-width: 85%;
        font-size: 0.95rem;
    }

    .messages-area {
        padding: 16px 12px;
    }
}

/* Prevent text selection on UI elements */
.chat-header, .contact-item, .btn {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Smooth scrolling */
.contacts-list, .messages-area {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* Hide scrollbars */
.contacts-list::-webkit-scrollbar,
.messages-area::-webkit-scrollbar {
    display: none;
}

/* Focus styles for accessibility */
.btn:focus,
.form-control:focus,
.contact-item:focus {
    outline: 2px solid #25d366;
    outline-offset: 2px;
}

/* Incoming call notification styles */
.incoming-call-notification {
    position: fixed;
    top: 20px;
    right: 20px;
    background: linear-gradient(135deg, #25d366 0%, #128c7e 100%);
    color: white;
    padding: 20px;
    border-radius: 15px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
    z-index: 10000;
    max-width: 350px;
    animation: slideInRight 0.3s ease;
}

.notification-content {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.caller-info {
    display: flex;
    align-items: center;
    font-size: 1.1rem;
    font-weight: 600;
}

.call-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.call-actions .btn {
    padding: 8px 16px;
    border-radius: 20px;
    font-weight: 600;
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* RTL Support */
[dir="rtl"] {
    text-align: right;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Enhanced Mobile Responsive Design */
@media (max-width: 768px) {
    body {
        font-size: 16px;
        -webkit-text-size-adjust: 100%;
        touch-action: manipulation;
    }
    
    #chatApp {
        flex-direction: column;
        height: 100vh;
        height: 100dvh; /* Dynamic viewport height for mobile */
    }
    
    .w-1\/3 {
        width: 100%;
        height: 100vh;
        height: 100dvh;
        position: fixed;
        top: 0;
        left: 0;
        z-index: 100;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        background: white;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    }
    
    .w-1\/3.mobile-show {
        transform: translateX(0);
    }
    
    .flex-1 {
        width: 100%;
        height: 100vh;
        height: 100dvh;
        display: flex;
        flex-direction: column;
    }
    
    /* Mobile Chat Header */
    #chatHeader {
        padding: 20px 16px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        background: linear-gradient(135deg, #25d366 0%, #128c7e 100%);
        color: white;
        min-height: 70px;
        display: flex;
        align-items: center;
    }
    
    #chatHeader .mobile-back-btn {
        display: flex;
        margin-left: 16px;
        padding: 12px;
        background: rgba(255, 255, 255, 0.1);
        border-radius: 50%;
        cursor: pointer;
        transition: all 0.3s ease;
        min-width: 44px;
        min-height: 44px;
        align-items: center;
        justify-content: center;
        backdrop-filter: blur(10px);
    }
    
    #chatHeader .mobile-back-btn:active {
        background: rgba(255, 255, 255, 0.2);
        transform: scale(0.95);
    }
    
    #chatHeader .mobile-back-btn i {
        color: white;
        font-size: 18px;
    }
    
    #chatUsername {
        color: white !important;
        font-size: 18px;
        font-weight: 600;
    }
    
    #chatStatus {
        color: rgba(255, 255, 255, 0.8) !important;
        font-size: 14px;
    }
    
    /* Mobile Messages Area */
    #messagesArea {
        flex: 1;
        overflow-y: auto;
        padding: 16px 12px;
        background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }
    
    .message {
        max-width: 85%;
        padding: 16px 20px;
        font-size: 16px;
        margin-bottom: 12px;
        border-radius: 18px;
        line-height: 1.5;
        word-wrap: break-word;
        hyphens: auto;
    }
    
    .message-sent {
        margin-left: auto;
        margin-right: 8px;
        border-bottom-right-radius: 6px;
    }
    
    .message-received {
        margin-right: auto;
        margin-left: 8px;
        border-bottom-left-radius: 6px;
    }
    
    .message-time {
        font-size: 12px;
        margin-top: 8px;
    }
    
    /* Mobile Message Input */
    #messageInput {
        padding: 16px 12px 20px 12px;
        background: white;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
        border-top: 1px solid #e5e7eb;
        min-height: 80px;
    }
    
    #messageInput .flex {
        gap: 12px;
        align-items: flex-end;
    }
    
    #messageText {
        font-size: 16px !important;
        padding: 14px 20px;
        border-radius: 25px;
        border: 2px solid #e5e7eb;
        min-height: 52px;
        max-height: 120px;
        resize: none;
        line-height: 1.4;
        -webkit-appearance: none;
        appearance: none;
    }
    
    #messageText:focus {
        border-color: #25d366;
        box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.1);
    }
    
    #sendBtn {
        width: 52px;
        height: 52px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 4px 12px rgba(37, 211, 102, 0.4);
        font-size: 18px;
        flex-shrink: 0;
        transition: all 0.3s ease;
    }
    
    #sendBtn:active {
        transform: scale(0.95);
    }
    
    /* Contact List Mobile Improvements */
    .contact-item {
        padding: 20px 16px;
        border-bottom: 1px solid #f0f2f5;
        min-height: 80px;
        display: flex;
        align-items: center;
        cursor: pointer;
        transition: all 0.3s ease;
        -webkit-tap-highlight-color: transparent;
    }
    
    .contact-item:active {
        background: #f8f9fa;
        transform: scale(0.98);
    }
    
    .contact-avatar {
        width: 56px;
        height: 56px;
        font-size: 20px;
        margin-left: 16px;
        flex-shrink: 0;
    }
    
    .contact-name {
        font-size: 18px;
        font-weight: 600;
        line-height: 1.3;
    }
    
    .contact-status {
        font-size: 15px;
        margin-top: 4px;
    }
    
    /* Mobile Header for Contacts */
    .w-1\/3 .bg-green-500 {
        padding: 20px 16px;
        min-height: 80px;
        display: flex;
        align-items: center;
        justify-content: space-between;
    }
    
    .w-1\/3 .bg-green-500 .w-10 {
        width: 48px;
        height: 48px;
    }
    
    .w-1\/3 .bg-green-500 h3 {
        font-size: 18px;
        font-weight: 600;
    }
    
    /* Search Bar Mobile */
    .w-1\/3 .p-4 {
        padding: 16px;
    }
    
    #searchContacts {
        font-size: 16px;
        padding: 14px 16px 14px 44px;
        border-radius: 12px;
        min-height: 48px;
        -webkit-appearance: none;
        appearance: none;
    }
    
    /* Mobile Welcome Message */
    #welcomeMessage {
        padding: 40px 20px;
        text-align: center;
    }
    
    #welcomeMessage i {
        font-size: 4rem;
        margin-bottom: 20px;
    }
    
    #welcomeMessage h3 {
        font-size: 22px;
        margin-bottom: 12px;
    }
    
    #welcomeMessage p {
        font-size: 16px;
    }
    
    /* Better touch targets */
    button, .contact-item, input, textarea {
        min-height: 44px;
        touch-action: manipulation;
    }
    
    /* Prevent zoom on input focus */
    input[type="text"], input[type="email"], input[type="password"], textarea {
        font-size: 16px !important;
    }
    
    /* Smooth scrolling */
    * {
        -webkit-overflow-scrolling: touch;
    }
    
    /* Hide scrollbars on mobile */
    #messagesArea::-webkit-scrollbar,
    #contactsList::-webkit-scrollbar {
        display: none;
    }
    
    /* Mobile navigation improvements */
    .mobile-chat-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 99;
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease;
    }
    
    .mobile-chat-overlay.show {
        opacity: 1;
        visibility: visible;
    }
}

/* Desktop Only Styles */
@media (min-width: 769px) {
    #chatHeader .mobile-back-btn {
        display: none;
    }
}

/* Enhanced Chat Background Pattern */
#messagesArea {
    background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23e2e8f0' fill-opacity='0.4'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
    padding: 20px 16px;
}

/* Enhanced Welcome Message */
#welcomeMessage {
    text-align: center;
    color: #64748b;
}

#welcomeMessage i {
    color: #25d366;
    margin-bottom: 16px;
    opacity: 0.8;
}

#welcomeMessage h3 {
    color: #334155;
    margin-bottom: 8px;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    margin-bottom: 8px;
}

.typing-dots {
    display: flex;
    gap: 4px;
}

.typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #94a3b8;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) { animation-delay: 0s; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

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

/* Status indicators */
.status-online {
    color: #10b981;
    font-weight: 600;
}

.status-offline {
    color: #6b7280;
}

/* Enhanced scrolling for mobile */
@media (max-width: 768px) {
    #messagesArea {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }
    
    #contactsList {
        -webkit-overflow-scrolling: touch;
    }
}