* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f0f2f5;
    direction: rtl;
    overflow: hidden;
}

.header {
    background: linear-gradient(135deg, #25d366 0%, #128c7e 100%);
    color: white;
    padding: 16px 24px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-content h1 {
    font-size: 24px;
    margin-bottom: 4px;
}

.subtitle {
    font-size: 13px;
    opacity: 0.9;
}

.btn-logout {
    background: rgba(255,255,255,0.2);
    color: white;
    border: 1px solid rgba(255,255,255,0.3);
    padding: 8px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
}

.btn-logout:hover {
    background: rgba(255,255,255,0.3);
}

.container {
    display: flex;
    max-width: 1600px;
    margin: 0 auto;
    gap: 0;
    height: calc(100vh - 70px);
    overflow: hidden;
}

.sidebar {
    width: 380px;
    background: white;
    border-left: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.search-box {
    padding: 12px;
    border-bottom: 1px solid #e0e0e0;
    background: #f8f8f8;
}

.search-box input {
    width: 100%;
    padding: 10px 16px;
    border: 1px solid #ddd;
    border-radius: 20px;
    font-size: 14px;
    outline: none;
    background: white;
}

.search-box input:focus {
    border-color: #25d366;
}

.contacts-list {
    flex: 1;
    overflow-y: auto;
}

.contact-item {
    padding: 14px 16px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: background 0.2s;
}

.contact-item:hover {
    background: #f5f5f5;
}

.contact-item.active {
    background: #e8f5e9;
    border-left: 3px solid #25d366;
}

.contact-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.contact-name {
    font-weight: 600;
    font-size: 15px;
    color: #111;
}

.contact-time {
    font-size: 11px;
    color: #999;
}

.contact-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.contact-phone {
    font-size: 12px;
    color: #666;
    direction: ltr;
    text-align: right;
}

.message-count {
    background: #25d366;
    color: white;
    border-radius: 10px;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 600;
    min-width: 20px;
    text-align: center;
}

.main-content {
    flex: 1;
    background: #e5ddd5;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.no-selection {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #999;
}

.no-selection-icon {
    font-size: 64px;
    margin-bottom: 16px;
}

.no-selection p {
    font-size: 18px;
}

.messages-header {
    padding: 16px 24px;
    background: #f0f0f0;
    border-bottom: 1px solid #ddd;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.messages-header h2 {
    font-size: 18px;
    margin-bottom: 4px;
    color: #111;
}

.messages-header p {
    font-size: 13px;
    color: #666;
    direction: ltr;
    text-align: right;
}

.btn-refresh {
    background: white;
    border: 1px solid #ddd;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 18px;
    cursor: pointer;
    transition: transform 0.3s, background 0.2s;
}

.btn-refresh:hover {
    background: #f5f5f5;
}

.btn-refresh.spinning {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.messages-list {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background-image:
        repeating-linear-gradient(
            45deg,
            rgba(0,0,0,0.02),
            rgba(0,0,0,0.02) 10px,
            transparent 10px,
            transparent 20px
        );
}

.message-item {
    margin-bottom: 12px;
    display: flex;
    flex-direction: column;
    animation: fadeIn 0.3s;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.message-item.from-me {
    align-items: flex-start;
}

.message-item.from-them {
    align-items: flex-end;
}

.message-bubble {
    max-width: 65%;
    padding: 8px 12px;
    border-radius: 8px;
    word-wrap: break-word;
    position: relative;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.message-item.from-me .message-bubble {
    background: #dcf8c6;
    border-top-right-radius: 0;
}

.message-item.from-them .message-bubble {
    background: white;
    border-top-left-radius: 0;
}

.message-type-badge {
    display: inline-block;
    background: rgba(0,0,0,0.1);
    color: #555;
    font-size: 9px;
    padding: 2px 6px;
    border-radius: 4px;
    margin-bottom: 6px;
    font-weight: 600;
    text-transform: uppercase;
}

.message-text {
    font-size: 14px;
    line-height: 1.5;
    color: #111;
    white-space: pre-wrap;
    word-break: break-word;
}

.message-media {
    margin-top: 6px;
}

.message-media img {
    max-width: 100%;
    max-height: 400px;
    border-radius: 6px;
    cursor: pointer;
    transition: transform 0.2s;
}

.message-media img:hover {
    transform: scale(1.02);
}

.message-media video,
.message-media audio {
    max-width: 100%;
    border-radius: 6px;
    margin-top: 4px;
}

.message-caption {
    margin-top: 6px;
    font-size: 13px;
    color: #555;
    font-style: italic;
}

.message-timestamp {
    font-size: 10px;
    color: #999;
    margin-top: 4px;
    text-align: left;
    direction: ltr;
}

.loading {
    text-align: center;
    padding: 40px;
    color: #999;
    font-size: 15px;
}

.error {
    color: #d32f2f;
    background: #ffebee;
    padding: 16px;
    border-radius: 6px;
    margin: 20px;
    text-align: center;
    font-size: 14px;
}

/* Media Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.9);
}

.modal-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    z-index: 10000;
}

.modal-content img {
    max-width: 100%;
    max-height: 90vh;
    border-radius: 8px;
}

.modal-close {
    position: absolute;
    top: -40px;
    left: 0;
    background: rgba(255,255,255,0.2);
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 20px;
    cursor: pointer;
    transition: background 0.2s;
}

.modal-close:hover {
    background: rgba(255,255,255,0.3);
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Mobile responsive */
@media (max-width: 768px) {
    .container {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        max-height: 300px;
        border-left: none;
        border-bottom: 1px solid #e0e0e0;
    }

    .main-content {
        min-height: calc(100vh - 370px);
    }

    .message-bubble {
        max-width: 85%;
    }
}
