/* Telegram Web Style - RTL Optimized - Fixed Layout */
:root {
    --primary-color: #3390ec;
    --primary-hover: #2b7ac9;
    --bg-color: #9ac0cd;
    --sidebar-bg: #ffffff;
    --sidebar-hover: #f4f4f5;
    --sidebar-active: #3390ec;
    --sidebar-active-text: #ffffff;
    --msg-in-bg: #ffffff;
    --msg-out-bg: #effdde;
    --text-primary: #000000;
    --text-secondary: #707579;
    --border-color: #dfe1e5;
    --input-bg: #ffffff;
}

/* Reset & Base */
.tlc-reset-styles {
    all: initial;
    display: flex !important;
    height: 100vh !important;
    width: 100vw !important;
    direction: rtl !important;
    text-align: right !important;
    font-family: "Vazir", "Tahoma", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif !important;
    background-color: var(--bg-color) !important;
    line-height: 1.5;
}

.tlc-reset-styles * {
    box-sizing: border-box !important;
}

body.tlc-chat-page-active {
    overflow: hidden !important;
    margin: 0 !important;
    padding: 0 !important;
}

#tlc-fullscreen-app {
    display: flex;
    height: 100vh;
    width: 100vw;
    background-color: var(--bg-color);
    overflow: hidden;
}

/* Sidebar */
.tlc-sidebar {
    width: 420px;
    background: var(--sidebar-bg);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 20;
    flex-shrink: 0;
}

.tlc-header {
    padding: 10px 15px;
    display: flex;
    align-items: center;
    gap: 15px;
}

.tlc-menu-icon {
    font-size: 24px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 5px;
}

.tlc-search-bar {
    flex: 1;
    position: relative;
}

.tlc-search-bar input {
    width: 100%;
    padding: 10px 40px 10px 15px;
    border-radius: 22px;
    border: 1px solid #f0f2f5;
    background: #f4f4f5;
    font-size: 14px;
    color: var(--text-primary);
    outline: none;
    font-family: inherit;
}

.tlc-search-icon {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
}

.tlc-contact-list {
    flex: 1;
    overflow-y: auto;
    padding: 5px 0;
}

.tlc-contact-item {
    display: flex;
    padding: 12px 15px;
    gap: 15px;
    cursor: pointer;
    transition: background 0.2s;
    border-radius: 10px;
    margin: 2px 8px;
}

.tlc-contact-item:hover {
    background: var(--sidebar-hover);
}

.tlc-contact-item.active {
    background: var(--sidebar-active);
}

.tlc-contact-item.active .tlc-name,
.tlc-contact-item.active .tlc-last-msg,
.tlc-contact-item.active .tlc-time-meta {
    color: var(--sidebar-active-text);
}

.tlc-avatar img {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    object-fit: cover;
}

.tlc-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    overflow: hidden;
    min-width: 0;
}

.tlc-top-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.tlc-name {
    font-weight: 600;
    font-size: 15px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tlc-last-msg {
    font-size: 14px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Chat Area */
.tlc-chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-color);
    background-image: url('https://web.telegram.org/img/bg_0.png');
    background-size: cover;
    position: relative;
    min-width: 0;
}

.tlc-chat-header {
    height: 60px;
    background: #ffffff;
    display: flex;
    align-items: center;
    padding: 0 20px;
    border-bottom: 1px solid var(--border-color);
    z-index: 10;
    justify-content: space-between;
}

.tlc-back-btn {
    display: none; /* Desktop default hidden */
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 5px;
}

/* Header Layout */
.tlc-header-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

.tlc-header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.tlc-header-info {
    display: flex;
    flex-direction: row; /* Inline name and status */
    align-items: center;
    gap: 10px;
    margin-right: 10px;
}

.tlc-header-info h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.tlc-header-info span {
    font-size: 13px;
    color: var(--primary-color); /* Online status color */
}

.tlc-header-actions {
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
}

/* Messages */
.tlc-messages-container {
    flex: 1;
    padding: 20px 10%;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scroll-behavior: auto; /* Prevent smooth scroll interfering with manual jump */
}

.tlc-message {
    display: flex;
    width: 100%;
    max-width: 100%;
}

.tlc-message.sent {
    justify-content: flex-start; /* RTL: Start is Right */
}

.tlc-message.received {
    justify-content: flex-end; /* RTL: End is Left */
}

.tlc-bubble {
    max-width: 480px;
    padding: 6px 10px 8px;
    position: relative;
    box-shadow: 0 1px 2px rgba(0,0,0,0.15);
    display: flex;
    flex-direction: column;
    cursor: pointer;
    word-wrap: break-word;
    font-size: 15px;
    line-height: 1.4;
}

.tlc-message.sent .tlc-bubble {
    background: var(--msg-out-bg);
    border-radius: 12px 12px 4px 12px;
}

.tlc-message.received .tlc-bubble {
    background: var(--msg-in-bg);
    border-radius: 12px 12px 12px 4px;
}

.tlc-meta {
    display: flex;
    align-items: center;
    gap: 4px;
    float: left;
    margin-top: 6px;
    margin-right: 8px;
    margin-bottom: -4px;
    opacity: 0.7;
}

.tlc-time {
    font-size: 11px;
    color: inherit;
}
.tlc-checks {
    font-size: 14px;
    line-height: 1;
    color: #4fae4e;
}

/* Input Area */
.tlc-input-area {
    padding: 10px 20px 20px;
    display: flex;
    align-items: flex-end;
    gap: 10px;
    max-width: 720px;
    margin: 0 auto;
    width: 100%;
    position: relative;
}

.tlc-input-wrapper {
    flex: 1;
    background: var(--input-bg);
    border-radius: 16px;
    padding: 8px 12px;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    transition: box-shadow 0.2s;
}

.tlc-input-wrapper:focus-within {
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

#tlc-message-input {
    flex: 1;
    border: none;
    outline: none;
    padding: 8px 0;
    font-size: 16px;
    resize: none;
    max-height: 150px;
    min-height: 24px;
    background: transparent;
    font-family: inherit;
    line-height: 1.4;
}

/* Button Layout - RTL */
/* 
   We want:
   [Send Button] [Pin Icon] [Input Wrapper]
   Inside Wrapper: [Input] [Emoji]
*/

.tlc-input-area {
    flex-direction: row; /* RTL: Right to Left */
}

/* Send Button: Far Right */
.tlc-send-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--primary-color);
    border: none;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(51, 144, 236, 0.4);
    font-size: 24px;
    flex-shrink: 0;
    transition: transform 0.2s, background 0.2s;
}
.tlc-send-btn:hover {
    background: var(--primary-hover);
    transform: scale(1.05);
}

/* Pin Button: Before Send */
.tlc-pin-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: background 0.2s;
    margin-left: 5px;
}
.tlc-pin-btn:hover {
    background: rgba(0,0,0,0.05);
    color: var(--primary-color);
}

/* Input Wrapper */
.tlc-input-wrapper {
    display: flex;
    flex-direction: row; /* RTL */
    align-items: flex-end;
}

/* Emoji: Left side of input (End in RTL) */
.tlc-emoji-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    margin-right: 5px; /* Space from input */
    transition: color 0.2s;
}
.tlc-emoji-btn:hover {
    color: var(--text-primary);
}

/* Input: Take remaining space */
#tlc-message-input {
    width: 100%;
}

/* Reply Preview */
.tlc-reply-preview {
    display: none;
    padding: 10px 20px;
    background: rgba(255,255,255,0.9);
    border-bottom: 1px solid var(--border-color);
    backdrop-filter: blur(5px);
    align-items: center;
    justify-content: space-between;
}
.tlc-reply-preview.active {
    display: flex;
}
.tlc-reply-preview-content {
    border-right: 3px solid var(--primary-color);
    padding-right: 10px;
    font-size: 14px;
}
.tlc-reply-title {
    color: var(--primary-color);
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 2px;
}

/* Modal */
.tlc-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}
.tlc-modal.active {
    display: flex;
}
.tlc-modal-content {
    background: #fff;
    padding: 20px;
    border-radius: 12px;
    width: 300px;
    text-align: right;
}
.tlc-modal h3 {
    margin-top: 0;
}
.tlc-modal input {
    width: 100%;
    padding: 10px;
    margin: 10px 0;
    border: 1px solid #ddd;
    border-radius: 8px;
    outline: none;
}
.tlc-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}
.tlc-btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}
.tlc-btn-primary {
    background: var(--primary-color);
    color: #fff;
}
.tlc-btn-cancel {
    background: #f0f0f0;
}

/* Responsive */
@media (max-width: 900px) {
    .tlc-sidebar {
        width: 320px;
    }
}

@media (max-width: 768px) {
    #tlc-fullscreen-app {
        flex-direction: column;
    }
    
    .tlc-sidebar {
        width: 100%;
        height: 100%;
        border-left: none;
    }
    
    .tlc-chat-area {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: 20;
        display: none; 
    }
    
    .tlc-chat-area.active {
        display: flex;
    }

    .tlc-back-btn {
        display: block;
    }
    
    .tlc-messages-container {
        padding: 10px;
    }
}