@import url('https://cdn.jsdelivr.net/npm/vazirmatn@33.0.3/Vazirmatn-font-face.css');

body, html { font-family: 'Vazirmatn', Tahoma, Arial, sans-serif; background-color: #e5e5e5; margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; display: flex; justify-content: center; align-items: center; }
* { box-sizing: border-box; }

#app-container { width: 100%; max-width: 1000px; background: #fff; border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,0.1); overflow: hidden; display: flex; flex-direction: column; height: 95%; position: relative; }

.header { background: #0082c8; background: linear-gradient(90deg, #0082c8 0%, #009ce0 100%); color: #fff; padding: 12px 20px; display: flex; justify-content: space-between; align-items: center; z-index: 10; box-shadow: 0 2px 5px rgba(0,0,0,0.1); flex-shrink: 0; }
.header-right { display: flex; align-items: center; min-width: 80px; }
.back-btn { display: none; background: rgba(255,255,255,0.2); border: none; color: white; padding: 6px 12px; border-radius: 20px; cursor: pointer; font-size: 13px; font-family: 'Vazirmatn'; margin-left: 10px; transition: 0.3s; }
.back-btn:hover { background: rgba(255,255,255,0.3); }
.logout-btn { font-size: 13px; cursor: pointer; color: #e0f7fa; padding: 5px; font-weight: 500; }
.logout-btn:hover { color: #fff; }

#header-title { flex: 1; text-align: center; font-size: 17px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 10px; }
.call-buttons { display: none; gap: 8px; min-width: 80px; justify-content: flex-end; }
.call-btn { background: #1eb95d; color: #fff; border: none; padding: 8px 12px; border-radius: 50%; cursor: pointer; font-size: 14px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); display: flex; justify-content: center; align-items: center; }
.call-btn:hover { background: #169b4b; transform: scale(1.05); }

#auth-section { display: none; padding: 50px 20px; text-align: center; flex: 1; overflow-y: auto; background: #fff; }
.auth-box { max-width: 350px; margin: 0 auto; background: #f8f9fa; padding: 30px; border-radius: 15px; box-shadow: 0 4px 15px rgba(0,0,0,0.05); }
input[type="tel"], input[type="text"] { width: 100%; padding: 14px; margin: 10px 0; border: 1.5px solid #e0e0e0; border-radius: 8px; font-size: 16px; text-align: center; font-family: 'Vazirmatn'; outline: none; }
button.primary-btn { width: 100%; padding: 14px; background: #0082c8; color: white; border: none; border-radius: 8px; cursor: pointer; font-size: 16px; font-weight: bold; font-family: 'Vazirmatn'; margin-top: 15px; }
#timer-display { font-size: 22px; font-weight: bold; color: #0082c8; margin: 15px 0; }

#main-app { display: none; flex: 1; flex-direction: row; overflow: hidden; min-height: 0; }
#sidebar { width: 320px; border-left: 1px solid #e0e0e0; background: #fff; display: flex; flex-direction: column; z-index: 5; flex-shrink: 0; }
#search-box { padding: 12px; border-bottom: 1px solid #eee; background: #fafafa; display: flex; flex-shrink: 0; }
#search-box input { flex: 1; margin: 0; padding: 10px 15px; text-align: right; font-size: 13px; border-radius: 20px; border: 1px solid #ddd; }

#contact-list { flex: 1; overflow-y: auto; padding: 0; margin: 0; }
.contact-item { padding: 15px 20px; border-bottom: 1px solid #f5f5f5; cursor: pointer; display: flex; justify-content: space-between; align-items: center; }
.contact-item.active-chat { background: #e3f2fd; border-right: 4px solid #0082c8; }
.contact-info { flex: 1; overflow: hidden; }
.contact-name { font-weight: bold; color: #2c3e50; font-size: 15px; display: block; margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-id { font-size: 12px; color: #7f8c8d; display: block; }
.unread-badge { background: #1eb95d; color: white; border-radius: 20px; padding: 3px 8px; font-size: 11px; font-weight: bold; margin-right: 10px; }

#chat-section { flex: 1; display: flex; flex-direction: column; background: #ebd8c8 url('https://www.transparenttextures.com/patterns/cubes.png'); min-width: 0; position: relative; }
#messages-container { flex: 1; padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }

.message-wrapper { display: flex; flex-direction: column; position: relative; max-width: 75%; cursor: pointer; }
.message-wrapper.mine { align-self: flex-start; }
.message-wrapper.theirs { align-self: flex-end; }

.message { padding: 10px 14px; border-radius: 14px; font-size: 14px; line-height: 1.6; word-wrap: break-word; white-space: pre-wrap; box-shadow: 0 1px 2px rgba(0,0,0,0.1); position: relative; }
.mine .message { background: #e3f8c8; border-bottom-right-radius: 4px; }
.theirs .message { background: #fff; border-bottom-left-radius: 4px; }

.msg-sender { font-size: 11px; color: #16a085; font-weight: bold; margin-bottom: 4px; display: block; }
.msg-media { max-width: 100%; max-height: 250px; object-fit: contain; border-radius: 8px; display: block; margin-top: 5px; }

.msg-dropdown { display: none; position: absolute; top: 100%; right: 0; background: #fff; box-shadow: 0 4px 12px rgba(0,0,0,0.15); border-radius: 8px; z-index: 100; min-width: 130px; overflow: hidden; margin-top: 5px; }
.msg-dropdown.show { display: block; }
.msg-dropdown-item { padding: 10px 15px; font-size: 13px; color: #333; cursor: pointer; display: flex; align-items: center; gap: 8px; border-bottom: 1px solid #f0f0f0; }
.msg-dropdown-item:hover { background: #f8f9fa; }
.msg-dropdown-item.danger { color: #e74c3c; }

.empty-state { text-align: center; color: #888; margin-top: auto; margin-bottom: auto; font-size: 15px; background: rgba(255,255,255,0.7); padding: 10px 20px; border-radius: 20px; align-self: center; }

/* اصلاحات قطعی کادر ارسال */
#input-area { display: flex; padding: 10px 15px; background: #fff; align-items: flex-end; gap: 10px; opacity: 0.5; pointer-events: none; flex-shrink: 0; border-top: 1px solid #eee; z-index: 20; box-shadow: 0 -2px 10px rgba(0,0,0,0.02); }
#input-area.active { opacity: 1; pointer-events: auto; }
#message-input { flex: 1; margin: 0; text-align: right; padding: 12px 15px; font-family: 'Vazirmatn'; resize: none; border: 1px solid #e0e0e0; border-radius: 22px; min-height: 46px; max-height: 120px; line-height: 1.5; overflow-y: auto; background: #f9f9f9; outline: none; transition: 0.2s; }
#message-input:focus { border-color: #0082c8; background: #fff; }

#send-btn { width: 46px; height: 46px; border-radius: 50%; background: #0082c8; color: white; border: none; cursor: pointer; display: flex; justify-content: center; align-items: center; flex-shrink: 0; padding: 0; transition: 0.2s; }
#send-btn:hover { background: #0073b1; transform: scale(1.05); }
#send-btn svg { width: 20px; height: 20px; fill: currentColor; }

#file-upload-label { width: 46px; height: 46px; display: flex; align-items: center; justify-content: center; color: #7f8c8d; font-size: 24px; cursor: pointer; flex-shrink: 0; border-radius: 50%; transition: 0.2s; }
#file-upload-label:hover { background: #f0f0f0; color: #0082c8; }

.overlay { display: none; position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.7); z-index: 1000; justify-content: center; align-items: center; flex-direction: column; backdrop-filter: blur(3px); }
.modal-content { background: #fff; padding: 25px; border-radius: 15px; text-align: center; width: 85%; max-width: 340px; box-shadow: 0 10px 30px rgba(0,0,0,0.2); }

#call-screen { display: none; position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: #222; z-index: 2000; flex-direction: column; }
#remote-video { flex: 1; width: 100%; object-fit: cover; background: #000; }
#local-video { position: absolute; bottom: 80px; left: 20px; width: 100px; height: 140px; border-radius: 10px; object-fit: cover; border: 2px solid #fff; background: #333; z-index: 2010; }
.call-controls { position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; gap: 20px; z-index: 2020; }
.end-call-btn { background: #e74c3c; color: white; padding: 12px 30px; border-radius: 30px; border: none; font-weight: bold; font-family: 'Vazirmatn'; font-size: 15px; cursor: pointer; box-shadow: 0 4px 10px rgba(231,76,60,0.3); }

@media (max-width: 768px) {
    body, html { position: fixed; width: 100%; height: 100%; overflow: hidden; touch-action: none; }
    #app-container { height: 100%; width: 100%; border-radius: 0; box-shadow: none; }
    #sidebar { width: 100%; border: none; }
    #chat-section { display: none; width: 100%; height: 100%; flex-direction: column; }
    
    #app-container.chat-active #sidebar { display: none; }
    #app-container.chat-active #chat-section { display: flex; }
    #app-container.chat-active .logout-btn { display: none; }
    #app-container.chat-active .back-btn { display: block; }
    
    #input-area { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
    .message { max-width: 90%; }
}