/* ========================================
   WebTel - استایل اصلی تلگرام
   با قابلیت دارک و لایت مود و ریسپانسیو
   ======================================== */

/* ----- متغیرهای رنگ (لایت مود پیش‌فرض) ----- */
:root {
    --bg-page: #e5ebef;
    --bg-sidebar: #ffffff;
    --bg-message: #ffffff;
    --bg-header: rgba(255, 255, 255, 0.96);
    --text-primary: #1f2d3d;
    --text-secondary: #65748c;
    --text-meta: #8196ab;
    --border-light: #e9ecef;
    --border-sidebar: #eef2f5;
    --accent: #3390ec;
    --accent-hover: #2a7bc9;
    --accent-light: #e9f4fe;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.06);
    --avatar-bg: #7b9cac;
    --online-dot: #31c26b;
    --verified: #3390ec;
}

/* ----- دارک مود ----- */
[data-theme="dark"] {
    --bg-page: #0f1419;
    --bg-sidebar: #1e252e;
    --bg-message: #1e252e;
    --bg-header: rgba(30, 37, 46, 0.96);
    --text-primary: #e7e9ea;
    --text-secondary: #8e9eae;
    --text-meta: #6b7f8f;
    --border-light: #2c343d;
    --border-sidebar: #2a313a;
    --accent: #64b5f6;
    --accent-hover: #90caf9;
    --accent-light: #1e3a5f;
    --avatar-bg: #4a627a;
}

/* ----- ریست عمومی ----- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

@font-face {
    font-family: 'Vazir';
    src: url('Vazir.woff') format('woff');
    font-display: swap;
}

body {
    font-family: 'Vazir', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-page);
    color: var(--text-primary);
    line-height: 1.5;
    margin: 0;
    padding: 0;
    overflow: hidden;
    height: 100vh;
}

/* ========== لایه اصلی ========== */
.app-container {
    display: flex;
    height: 100vh;
    width: 100%;
    position: relative;
}

/* ========== سایدبار (منوی کانال‌ها) ========== */
.sidebar {
    width: 360px;
    background: var(--bg-sidebar);
    border-left: 1px solid var(--border-sidebar);
    display: flex;
    flex-direction: column;
    position: relative;
    transition: transform 0.25s ease;
    z-index: 10;
    box-shadow: var(--shadow-md);
}

/* دکمه منو برای موبایل */
.menu-toggle {
    display: none;
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    border: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    z-index: 100;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

/* هدر جستجو در سایدبار */
.search-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-sidebar);
    background: inherit;
}

.search-box {
    position: relative;
    width: 100%;
}

.search-icon {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    color: var(--text-secondary);
    pointer-events: none;
}

.search-input {
    width: 100%;
    padding: 12px 44px 12px 16px;
    background: var(--bg-page);
    border: none;
    border-radius: 28px;
    font-size: 15px;
    font-family: inherit;
    color: var(--text-primary);
    transition: all 0.2s;
}

.search-input:focus {
    outline: none;
    background: var(--bg-sidebar);
    box-shadow: 0 0 0 2px var(--accent-light);
}

/* لیست کانال‌ها */
.channels-list {
    flex: 1;
    overflow-y: auto;
    direction: ltr;
}

.channels-list > div {
    direction: rtl;
}

/* هر آیتم کانال */
.channel-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    gap: 12px;
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 1px solid var(--border-sidebar);
}

.channel-item:hover {
    background: var(--accent-light);
}

.channel-item.active {
    background: var(--accent-light);
    border-right: 3px solid var(--accent);
}

/* آواتار کانال */
.channel-avatar {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--avatar-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    flex-shrink: 0;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.channel-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.channel-avatar .fallback {
    font-size: 22px;
    font-weight: 500;
    color: white;
    text-transform: uppercase;
}

/* اطلاعات کانال */
.channel-info {
    flex: 1;
    min-width: 0;
}

.channel-name {
    font-weight: 600;
    font-size: 16px;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.channel-name .name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.verified-badge {
    display: inline-block;
    width: 18px;
    height: 18px;
    background: var(--verified);
    border-radius: 50%;
    font-size: 12px;
    color: white;
    text-align: center;
    line-height: 18px;
    flex-shrink: 0;
}

.channel-meta {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 4px;
}

/* آمار و پیام جدید */
.channel-stats {
    text-align: left;
    flex-shrink: 0;
    min-width: 50px;
}

.channel-time {
    font-size: 12px;
    color: var(--text-meta);
    white-space: nowrap;
}

.unread-badge {
    background: var(--accent);
    color: white;
    font-size: 12px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 16px;
    margin-top: 6px;
    display: inline-block;
    text-align: center;
}

/* ========== بخش اصلی (پیام‌ها) ========== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-page);
    position: relative;
    overflow: hidden;
}

/* هدر چت */
.chat-header {
    background: var(--bg-header);
    backdrop-filter: blur(20px);
    padding: 10px 20px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 5;
}

.back-button {
    display: none;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--accent);
}

.chat-header-info {
    flex: 1;
}

.chat-header-name {
    font-weight: 600;
    font-size: 17px;
}

.chat-header-meta {
    font-size: 13px;
    color: var(--text-secondary);
}

.header-actions {
    display: flex;
    gap: 12px;
}

.header-btn {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 20px;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: background 0.2s;
}

.header-btn:hover {
    background: var(--accent-light);
}

/* محتوای پیام‌ها */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: url('bg.jpg') center/cover fixed;
}

/* ========== استایل پیام‌ها (شبیه تلگرام اصلی) ========== */

/* هر پیام */
.tgme_widget_message {
    display: flex;
    margin-bottom: 12px;
    gap: 8px;
    max-width: 100%;
}

/* عکس پروفایل فرستنده - کوچیک و گرد */
.tgme_widget_message_user_photo {
    width: 42px !important;
    height: 42px !important;
    min-width: 42px;
    border-radius: 50% !important;
    overflow: hidden;
    flex-shrink: 0;
    background: var(--avatar-bg);
}

.tgme_widget_message_user_photo img {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover;
}

/* حباب پیام */
.tgme_widget_message_bubble {
    background: var(--bg-message);
    border-radius: 18px;
    padding: 8px 12px;
    max-width: calc(100% - 50px);
    box-shadow: var(--shadow-sm);
    position: relative;
}

/* نام فرستنده */
.tgme_widget_message_author {
    font-weight: 600;
    font-size: 14px;
    color: var(--accent);
    margin-bottom: 4px;
    display: block;
}

.tgme_widget_message_author_name {
    color: inherit;
    text-decoration: none;
}

/* متن پیام */
.tgme_widget_message_text {
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary);
    word-break: break-word;
}

/* لینک‌های داخل متن */
.tgme_widget_message_text a {
    color: var(--accent);
    text-decoration: none;
}

.tgme_widget_message_text a:hover {
    text-decoration: underline;
}

/* عکس داخل پیام */
.tgme_widget_message_photo_wrap {
    margin: 8px -12px -6px -12px;
    border-radius: 14px;
    overflow: hidden;
    cursor: pointer;
    background: var(--bg-page);
    text-align: center;
}

.tgme_widget_message_photo {
    width: 100%;
    max-width: 100%;
    height: auto;
    display: block;
    object-fit: cover;
}

/* ویدیو */
.tgme_widget_message_video_player {
    position: relative;
    margin: 8px -12px -6px -12px;
    border-radius: 14px;
    overflow: hidden;
    cursor: pointer;
    background: #000;
}

.tgme_widget_message_video {
    width: 100%;
    display: block;
}

/* تام‌نیل ویدیو */
.tgme_widget_message_video_thumb {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
}

/* دکمه پخش روی ویدیو */
.message_video_play {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60px;
    height: 60px;
    background: rgba(0,0,0,0.6);
    border-radius: 50%;
    cursor: pointer;
    z-index: 2;
}

.message_video_play:after {
    content: "▶";
    position: absolute;
    top: 50%;
    left: 55%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 24px;
}

/* دکمه Load More */
.tme_messages_more {
    display: block;
    text-align: center;
    background: var(--accent);
    color: white;
    padding: 10px 20px;
    border-radius: 30px;
    margin: 16px auto;
    width: fit-content;
    cursor: pointer;
    font-size: 14px;
    text-decoration: none;
}

.load-more {
    text-align: center;
    padding: 12px;
}

.load-more-btn {
    background: var(--bg-message);
    border: none;
    padding: 8px 16px;
    border-radius: 24px;
    color: var(--accent);
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
}

/* فوت پیام (تاریخ و بازدید) */
.tgme_widget_message_footer {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    font-size: 11px;
    color: var(--text-meta);
}

.tgme_widget_message_date {
    color: inherit;
    text-decoration: none;
}

/* فایل و سند */
.tgme_widget_message_document_wrap {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--accent-light);
    border-radius: 14px;
    padding: 12px;
    margin-top: 6px;
}

.tgme_widget_message_document_icon {
    width: 44px;
    height: 44px;
    background: var(--accent);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tgme_widget_message_document_title {
    font-weight: 600;
    font-size: 14px;
    color: var(--accent);
}

.tgme_widget_message_document_extra {
    font-size: 12px;
    color: var(--text-secondary);
}

/* صدا (ویس) */
.tgme_widget_message_voice_player {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--accent-light);
    border-radius: 30px;
    padding: 8px 16px;
    margin-top: 6px;
}

.tgme_widget_message_voice_play {
    width: 36px;
    height: 36px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
}

/* استیکر */
.tgme_widget_message_sticker_wrap {
    display: inline-block;
    max-width: 160px;
    margin-top: 6px;
}

.tgme_widget_message_sticker {
    width: 100%;
    height: auto;
}

/* ریپلای به پیام */
.tgme_widget_message_reply {
    background: var(--accent-light);
    border-radius: 12px;
    padding: 8px 12px;
    margin-bottom: 8px;
    font-size: 13px;
    border-right: 3px solid var(--accent);
}

/* فوروارد */
.tgme_widget_message_forwarded_from {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

/* ========== پنل شناور ========== */
.action-panel {
    position: absolute;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 20;
}

.action-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s;
}

.action-btn:hover {
    transform: scale(1.05);
}

.fab-menu {
    position: absolute;
    bottom: 80px;
    right: 20px;
    background: var(--bg-sidebar);
    border-radius: 24px;
    box-shadow: var(--shadow-md);
    padding: 12px;
    display: none;
    flex-direction: column;
    gap: 8px;
    z-index: 20;
    min-width: 180px;
}

.fab-menu.show {
    display: flex;
}

.fab-menu button {
    background: none;
    border: none;
    padding: 10px 16px;
    text-align: right;
    font-family: inherit;
    font-size: 14px;
    color: var(--text-primary);
    cursor: pointer;
    border-radius: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.fab-menu button:hover {
    background: var(--accent-light);
}

/* ========== مودال جستجو ========== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: var(--bg-sidebar);
    border-radius: 28px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    padding: 20px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-secondary);
}

.search-in-channel-input {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-light);
    border-radius: 28px;
    background: var(--bg-page);
    color: var(--text-primary);
    font-family: inherit;
    margin-bottom: 16px;
}

/* حالت خالی */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-secondary);
}

/* لودینگ بار */
.loading-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 3px;
    background: var(--accent);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.3s;
    z-index: 1000;
}

.loading-bar.active {
    transform: scaleX(0.7);
}

/* ========== ریسپانسیو ========== */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        transform: translateX(100%);
        width: 85%;
        z-index: 50;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .menu-toggle {
        display: flex;
    }

    .back-button {
        display: block;
    }

    .tgme_widget_message_user_photo {
        width: 36px !important;
        height: 36px !important;
        min-width: 36px;
    }

    .tgme_widget_message_bubble {
        max-width: calc(100% - 44px);
        padding: 6px 10px;
    }

    .tgme_widget_message_text {
        font-size: 13px;
    }

    .action-panel {
        bottom: 20px;
        left: 20px;
        right: auto;
    }

    .fab-menu {
        left: 20px;
        right: auto;
        bottom: 80px;
    }
}

/* ========== اسکرول نرم ========== */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: var(--border-light);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb {
    background: var(--accent);
    border-radius: 3px;
}

/* ========== تنظیمات عمومی ========== */
button {
    font-family: inherit;
}

a {
    text-decoration: none;
    color: inherit;
}