/* assets/css/style.css */
:root {
    --tg-bg: #0e1621;
    --tg-sidebar: #17212b;
    --tg-sidebar-hover: #202b36;
    --tg-active: #2b5278;
    --tg-primary: #2481cc;
    --tg-text: #ffffff;
    --tg-text-dim: #8293a1;
    --tg-sent: #2b5278;
    --tg-received: #18252f;
    --tg-msg-shadow: rgba(0, 0, 0, 0.2);
    --tg-scroll: rgba(255, 255, 255, 0.1);
    --tg-header: #17212b;
    --tg-bottom-nav: #17212b;
    --tg-border: #111111;
    --tg-input-bg: #17212b;
    --tg-reply-border: #2481cc;
    --tg-chat-bg: url('../img/chat-bg.png');
    --tg-tick-unread: rgba(255, 255, 255, 0.6);
}

body[data-theme="light"] {
    --tg-bg: #ffffff;
    --tg-sidebar: #ffffff;
    --tg-sidebar-hover: #f4f4f5;
    --tg-active: #3390ec;
    --tg-primary: #3390ec;
    --tg-text: #000000;
    --tg-text-dim: #707579;
    --tg-sent: #effdde;
    --tg-received: #ffffff;
    --tg-msg-shadow: rgba(114, 114, 114, 0.25);
    --tg-scroll: rgba(0, 0, 0, 0.1);
    --tg-header: #ffffff;
    --tg-bottom-nav: #ffffff;
    --tg-border: #dfe1e5;
    --tg-input-bg: #ffffff;
    --tg-reply-border: #3390ec;
    --tg-chat-bg: url('../img/chat-bg-light.png');
    --tg-tick-unread: rgba(112, 117, 121, 0.6);
}

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

body[data-theme-initialized] * {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

@font-face {
    font-family: 'Vazir';
    src: url('../fonts/vazir/Vazir-Regular.woff2') format('woff2');
    font-weight: normal;
    font-style: normal;
}

body {
    background-color: var(--tg-bg);
    color: var(--tg-text);
    margin: 0;
    padding: 0;
    font-family: 'Vazir', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    overflow: hidden;
    direction: rtl;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
}

.app-container {
    display: flex;
    height: 100%;
    width: 100%;
    position: relative;
    overflow: hidden;
}

/* Scrollbar */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--tg-scroll); border-radius: 10px; }

/* Drawer (Menu Sidebar) */
.drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: 280px;
    height: 100%;
    background: var(--tg-sidebar);
    z-index: 2000;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
    box-shadow: -10px 0 30px rgba(0,0,0,0.5);
}

.drawer.open { transform: translateX(0); }

.drawer-header {
    padding: 25px 20px;
    background: #242f3d;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

body[data-theme="light"] .drawer-header {
    background: var(--tg-primary);
}

.drawer-menu { padding: 10px 0; overflow-y: auto; flex-grow: 1; }

.menu-item {
    padding: 14px 20px;
    display: flex;
    align-items: center;
    gap: 25px;
    cursor: pointer;
    font-size: 15px;
    color: var(--tg-text);
}

.menu-item:active { background: var(--tg-sidebar-hover); }
.menu-item i { font-size: 20px; color: var(--tg-text-dim); width: 25px; text-align: center; }

.drawer-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1999;
    display: none;
}

/* Sidebar & Chat List */
.sidebar {
    width: 380px;
    background-color: var(--tg-sidebar);
    border-left: 1px solid var(--tg-border);
    display: flex;
    flex-direction: column;
    z-index: 10;
    flex-shrink: 0;
    height: 100%;
    position: relative;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.3s ease;
}

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

.menu-icon-btn {
    width: 40px !important;
    height: 40px !important;
    background: var(--tg-primary) !important;
    color: white !important;
    border-radius: 50% !important;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
    display: flex !important;
    align-items: center;
    justify-content: center;
    transition: transform 0.1s, filter 0.2s !important;
}

.menu-icon-btn:hover {
    filter: brightness(1.1);
}

.menu-icon-btn:active {
    transform: scale(0.9);
}

.search-container { padding: 0 15px 10px; }

#search-input {
    width: 100%;
    padding: 8px 15px;
    border-radius: 20px;
    border: none;
    background: var(--tg-sidebar-hover);
    color: var(--tg-text);
    outline: none;
    font-size: 14px;
}

/* Chat Filters */
.chat-filters {
    display: flex;
    padding: 10px 10px;
    gap: 5px;
    overflow: hidden; /* Remove scroll */
    background: var(--tg-bg);
    border-bottom: 1px solid rgba(0,0,0,0.1);
    align-items: center;
    justify-content: space-between; /* Spread items evenly */
    flex-shrink: 0;
}
.filter-item {
    padding: 6px 12px;
    border-radius: 18px;
    background: var(--tg-sidebar);
    color: var(--tg-text-dim);
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    min-height: 32px;
    flex: 1; /* Allow items to grow/shrink equally */
    text-align: center;
}
.filter-item.active {
    background: var(--tg-primary);
    color: white;
}
.chat-type-icon {
    font-size: 12px;
    margin-left: 5px;
    color: var(--tg-text-dim);
}

/* Story Bar */
.stories-bar {
    display: flex;
    padding: 15px;
    overflow-x: auto;
    border-bottom: 1px solid var(--tg-border);
    gap: 12px;
    background: var(--tg-sidebar);
    flex-shrink: 0;
}

.story-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    min-width: 70px;
}

.story-ring {
    width: 62px;
    height: 62px;
    border-radius: 50%;
    border: 2.5px solid var(--tg-primary);
    padding: 2.5px;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.story-ring.unseen {
    border-color: #ff4d4d;
}

.story-ring.seen {
    border-color: #3498db;
}

.story-avatar.grayscale {
    filter: grayscale(1);
    opacity: 0.7;
}
.edit-actions { display: none; gap: 8px; align-items: center; }

.story-avatar {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    background: #333;
}

.story-name {
    font-size: 12px;
    color: var(--tg-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
    text-align: center;
}

/* Chat List Items */
.chat-list {
    flex-grow: 1;
    overflow-y: auto;
    padding-bottom: 80px;
    position: relative;
}

.chat-item {
    padding: 12px 14px;
    display: flex;
    align-items: center;
    cursor: pointer;
}

.chat-item:active { background: var(--tg-sidebar-hover); }
.chat-item.active { background: var(--tg-active); }
.chat-item.active .chat-name, .chat-item.active .chat-time, .chat-item.active .chat-last-msg { color: #fff !important; }

.avatar { width: 54px; height: 54px; border-radius: 50%; object-fit: cover; flex-shrink: 0; border: 1px solid rgba(255,255,255,0.1); }

.chat-info {
    flex-grow: 1;
    margin-right: 14px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.chat-name-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.chat-name { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-time { color: var(--tg-text-dim); font-size: 12px; }
.chat-msg-row { display: flex; justify-content: space-between; align-items: center; }
.chat-last-msg { color: var(--tg-text-dim); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }

.unread-badge {
    background: var(--tg-primary);
    color: white;
    border-radius: 12px;
    padding: 2px 8px;
    font-size: 11px;
    min-width: 20px;
    text-align: center;
    font-weight: bold;
}

/* Main Chat Area */
.main-chat {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    background: var(--tg-bg);
    height: 100%;
    height: 100dvh;
    position: relative;
    overflow: hidden;
}

.chat-header {
    height: 56px;
    padding: 0 15px;
    background: var(--tg-header);
    display: flex;
    align-items: center;
    z-index: 5;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    user-select: none !important;
    -webkit-user-select: none !important;
    -webkit-touch-callout: none !important;
    border-bottom: 1px solid var(--tg-border);
}

#chat-header-info, #chat-header-name, #chat-header-status, .mobile-back, #chat-header-avatar {
    -webkit-user-select: none !important;
    -moz-user-select: none !important;
    -ms-user-select: none !important;
    user-select: none !important;
    -webkit-touch-callout: none !important;
    -webkit-user-drag: none;
    outline: none !important;
}

#chat-header, #chat-header * {
    -webkit-user-select: none !important;
    -moz-user-select: none !important;
    -ms-user-select: none !important;
    user-select: none !important;
    -webkit-touch-callout: none !important;
    -webkit-tap-highlight-color: transparent !important;
}

.messages-container {
    flex-grow: 1;
    padding: 15px;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    background: var(--tg-chat-bg) center center fixed;
    background-size: cover;
}

.message {
    max-width: 85%;
    width: -webkit-fit-content;
    width: -moz-fit-content;
    width: fit-content;
    min-width: 60px;
    margin-bottom: 8px;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 15px;
    line-height: 1.4;
    position: relative;
    box-shadow: var(--tg-msg-shadow) 0px 1px 2px;
    word-wrap: break-word;
    display: flex;
    flex-direction: column;
    user-select: none !important;
    -webkit-user-select: none !important;
    -webkit-touch-callout: none !important; /* Critical for custom long-press on iOS */
    overflow: visible;
}
.msg-body {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    min-width: 0;
    max-width: 100%;
}

.message.sent {
    align-self: flex-start; /* Right in RTL */
    background: var(--tg-sent);
    border-bottom-right-radius: 2px;
    color: var(--tg-text);
    margin-right: 8px;
}

.message.sent::after {
    content: "";
    position: absolute;
    bottom: 0;
    right: -7px;
    width: 12px;
    height: 12px;
    background-color: var(--tg-sent);
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg width='12' height='12' viewBox='0 0 12 12' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M12 12H0C3.31371 12 6 9.31371 6 6V0L12 12Z' fill='black'/%3E%3C/svg%3E");
    mask-image: url("data:image/svg+xml,%3Csvg width='12' height='12' viewBox='0 0 12 12' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M12 12H0C3.31371 12 6 9.31371 6 6V0L12 12Z' fill='black'/%3E%3C/svg%3E");
    -webkit-mask-size: contain;
    mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
}

.message.received {
    align-self: flex-end; /* Left in RTL */
    background: var(--tg-received);
    border-bottom-left-radius: 2px;
    color: var(--tg-text);
    margin-left: 8px;
    display: flex;
    flex-direction: row;
    gap: 8px;
}

.msg-avatar {
    width: 35px !important;
    height: 35px !important;
    min-width: 35px;
    min-height: 35px;
    border-radius: 50%;
    align-self: flex-end;
    margin-bottom: 2px;
    cursor: pointer;
    object-fit: cover;
}

.message.received::after {
    content: "";
    position: absolute;
    bottom: 0;
    left: -7px;
    width: 12px;
    height: 12px;
    background-color: var(--tg-received);
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg width='12' height='12' viewBox='0 0 12 12' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 12H12C8.68629 12 6 9.31371 6 6V0L0 12Z' fill='black'/%3E%3C/svg%3E");
    mask-image: url("data:image/svg+xml,%3Csvg width='12' height='12' viewBox='0 0 12 12' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 12H12C8.68629 12 6 9.31371 6 6V0L0 12Z' fill='black'/%3E%3C/svg%3E");
    -webkit-mask-size: contain;
    mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
}

.message.pending {
    opacity: 0.7;
}

.date-separator {
    align-self: center;
    background: rgba(0,0,0,0.3);
    color: white;
    padding: 4px 12px;
    border-radius: 15px;
    font-size: 13px;
    margin: 15px 0;
    font-weight: 500;
}

.msg-meta {
    display: flex; justify-content: flex-end; align-items: center; margin-top: 4px;
    font-size: 11px; color: var(--tg-text-dim); gap: 4px;
    opacity: 0.8;
    user-select: none;
}

.forward-btn-quick, .save-btn-quick {
    color: var(--tg-text-dim);
    font-size: 14px;
    cursor: pointer;
    opacity: 0.6;
    transition: color 0.2s;
    padding: 2px 10px;
    margin-right: 8px;
    order: -1; /* Place at the beginning (Right side in RTL start) */
}

.forward-btn-quick:hover, .save-btn-quick:hover { color: var(--tg-primary); opacity: 1; }

.msg-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 5px;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

.reaction-badge {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 3px 8px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 4px;
    user-select: none !important;
    -webkit-user-select: none !important;
    -webkit-touch-callout: none !important;
}

.reaction-badge:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
}


.reaction-popup {
    position: fixed;
    background: #1c242f;
    padding: 10px;
    border-radius: 25px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.6);
    display: none;
    gap: 12px;
    z-index: 9600; /* Higher than normal modals if needed */
    max-width: 90vw;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    white-space: nowrap;
}

.reaction-popup::-webkit-scrollbar {
    display: none;
}
.reaction-emoji {
    font-size: 20px;
    cursor: pointer;
    transition: transform 0.2s;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}
.reaction-emoji:hover { transform: scale(1.3); }

/* Input Area - Telegram Style */
.input-area {
    padding: 10px 10px;
    background: transparent;
    display: none;
    align-items: flex-end;
    gap: 8px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    flex-shrink: 0;
    z-index: 10;
}

.input-area.visible { display: flex; }

.input-wrapper {
    flex-grow: 1;
    background: var(--tg-input-bg); /* Darker background like Telegram */
    border-radius: 22px;
    display: flex;
    align-items: flex-end;
    padding: 0 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    min-height: 44px;
}

.input-area textarea {
    flex-grow: 1;
    background: transparent;
    border: none;
    padding: 11px 12px;
    color: var(--tg-text);
    outline: none !important;
    font-size: 16px;
    max-height: 180px;
    resize: none;
    font-family: inherit;
    line-height: 1.4;
    overflow-y: auto;
    border-radius: 0;
}

/* Scrollbar styling for textarea */
.input-area textarea::-webkit-scrollbar { width: 4px; }
.input-area textarea::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 10px; }

.input-area .icon-btn {
    font-size: 20px;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #8293a1;
    transition: transform 0.1s ease, color 0.2s, background 0.2s;
    border-radius: 50%;
    background: transparent;
    border: none;
    cursor: pointer;
    flex-shrink: 0;
}

.input-area .icon-btn:hover {
    background: rgba(255,255,255,0.05);
    color: #ffffff;
}

.input-area .icon-btn:active {
    transform: scale(0.9);
    background: rgba(255,255,255,0.1);
}

#send-btn, #voice-btn {
    color: #ffffff !important;
    background: #2481cc !important; /* Pure Telegram Primary */
    width: 46px;
    height: 46px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

#send-btn:hover, #voice-btn:hover {
    filter: brightness(1.15);
    background: #288fde !important;
}

#attach-btn {
    color: var(--tg-text-dim);
}

.attachment-menu {
    position: absolute;
    bottom: 50px;
    left: 0;
    right: 0;
    background: var(--tg-sidebar);
    border-radius: 12px;
    display: none;
    flex-direction: row;
    justify-content: space-around;
    padding: 15px;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.2);
    z-index: 100;
    border: 1px solid var(--tg-border);
}

.attachment-menu.open {
    display: flex;
}

.attachment-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.attachment-icon {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 20px;
}

.attachment-item span {
    font-size: 12px;
    color: var(--tg-text);
}

#emoji-btn {
    color: var(--tg-text-dim);
}

#message-input {
    padding: 10px 5px;
    font-size: 16px;
}

/* Bottom Nav */
.bottom-nav {
    display: none;
    position: absolute;
    bottom: 0; left: 0; width: 100%; height: 60px;
    background: var(--tg-bottom-nav);
    border-top: 1px solid var(--tg-border);
    justify-content: space-around;
    align-items: center;
    z-index: 20;
}

.nav-item {
    display: flex; flex-direction: column; align-items: center;
    color: var(--tg-text-dim); font-size: 11px; cursor: pointer;
    flex: 1;
    padding: 8px 0;
}

.nav-item.active { color: var(--tg-primary); }
.nav-item i { font-size: 20px; margin-bottom: 4px; }

/* FAB */
.fab {
    position: absolute;
    bottom: 80px; right: 20px;
    width: 56px; height: 56px;
    border-radius: 50%;
    background: var(--tg-primary);
    color: white;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px; box-shadow: 0 4px 8px rgba(0,0,0,0.4);
    cursor: pointer; z-index: 15;
}
.fab i {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.story-reactions {
    display: flex;
    justify-content: flex-start;
    gap: 12px;
    margin-bottom: 15px;
    overflow-x: auto;
    padding: 10px 5px;
    -webkit-overflow-scrolling: touch;
}

@media (min-width: 769px) {
    .story-reactions {
        justify-content: center;
    }
}

.story-reactions::-webkit-scrollbar {
    display: none;
}

/* Story Viewer */
.story-viewer {
    position: fixed; top: 0; left: 0;
    width: 100%; height: 100%;
    background: #000;
    z-index: 7000;
    display: none;
    flex-direction: column;
    user-select: none;
    -webkit-touch-callout: none;
    perspective: 1000px; /* For Cube Effect */
}

#story-content {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
    background: #000;
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.23, 1, 0.32, 1);
}

.cube-next {
    animation: cubeNext 0.6s forwards;
}

.cube-prev {
    animation: cubePrev 0.6s forwards;
}

@keyframes cubeNext {
    0% { transform: rotateY(0deg) translateZ(0); opacity: 1; transform-origin: left center; }
    100% { transform: rotateY(-90deg) translateZ(0); opacity: 0; transform-origin: left center; }
}

@keyframes cubePrev {
    0% { transform: rotateY(0deg) translateZ(0); opacity: 1; transform-origin: right center; }
    100% { transform: rotateY(90deg) translateZ(0); opacity: 0; transform-origin: right center; }
}

/* We also need a way to animate the INCOMING story.
   Since we swap content, a simple cube-out is easiest,
   but for a real effect we should animate the whole container. */

.story-header {
    height: 80px;
    position: relative;
    z-index: 10001; /* Higher than story-content arrows */
    flex-shrink: 0;
}

.story-footer {
    height: auto;
    position: relative;
    z-index: 10001; /* Higher than story-content arrows */
    flex-shrink: 0;
    background: linear-gradient(to top, rgba(0,0,0,0.8), transparent);
    pointer-events: auto;
}

.story-progress-container {
    position: absolute; top: 12px; left: 10px; right: 10px;
    height: 2px; display: flex; gap: 4px; z-index: 10001;
    direction: rtl; /* Progress from Right to Left */
}

.story-progress-segment {
    flex: 1; height: 100%; background: rgba(255,255,255,0.3); border-radius: 2px; overflow: hidden;
}

.story-progress-fill {
    height: 100%; background: #fff; width: 0%; transition: width linear;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        position: absolute;
        right: 0;
        top: 0;
        border-left: none;
        transform: translateX(0); /* Default visible */
        transition: transform 0.3s ease;
    }
    .sidebar.hidden { transform: translateX(100%); }
    .main-chat {
        width: 100%;
        position: absolute;
        left: 0;
        top: 0;
        height: 100%;
        height: 100dvh;
        z-index: 1;
    }
    .bottom-nav { display: flex; }
    .messages-container { padding-bottom: 10px; }

    .input-area {
        padding: 6px 8px; /* Slightly tighter on mobile */
        gap: 6px;
    }

    .input-area.visible { padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px)); }

    #send-btn, #voice-btn {
        width: 44px; /* Slightly smaller on mobile to match proportions */
        height: 44px;
        min-width: 44px;
    }

    .input-area .icon-btn {
        width: 40px;
        height: 40px;
        font-size: 19px;
    }

    .input-wrapper {
        min-height: 40px;
    }

    .input-area textarea {
        padding: 9px 10px;
        font-size: 15px; /* Better size for mobile keyboards */
    }
}

.mobile-back { display: none; cursor: pointer; font-size: 20px; margin-left: 15px; color: var(--tg-primary); }
@media (max-width: 768px) { .mobile-back { display: block; } }

/* Context Menu */
.context-menu {
    position: fixed;
    background: var(--tg-sidebar);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
    z-index: 5000;
    display: none;
    flex-direction: column;
    min-width: 180px;
    padding: 6px 0;
    border: 1px solid var(--tg-border);
}

.context-menu-item {
    padding: 10px 18px;
    display: flex;
    align-items: center;
    gap: 20px;
    cursor: pointer;
    font-size: 15px;
}

.context-menu-item:active { background: #2b5278; }
.context-menu-item i { width: 20px; text-align: center; color: var(--tg-text-dim); font-size: 16px; }

/* News Home Responsive Fix */
.container { overflow-x: hidden; }
@media (max-width: 768px) {
    .container { grid-template-columns: 1fr; width: 100%; padding: 0 10px; box-sizing: border-box; }
}

.primary-btn { background: var(--tg-primary); color: white; border: none; padding: 10px 20px; border-radius: 8px; font-weight: bold; cursor: pointer; transition: background 0.2s; }
.primary-btn:active { background: #1c66a3; }
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.7); display: none; align-items: center; justify-content: center; z-index: 9500; }
.modal-content {
    background: var(--tg-sidebar);
    padding: 20px;
    border-radius: 15px;
    width: 95%;
    max-width: 360px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    user-select: none;
    -webkit-user-select: none;
    color: var(--tg-text);
}

#modal-body {
    overflow-y: auto;
    flex: 1;
    margin-bottom: 15px;
    padding-left: 5px;
}

#modal-body::-webkit-scrollbar { width: 4px; }
#modal-body::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 10px; }

#join-bar {
    user-select: none;
    -webkit-user-select: none;
    border-bottom: 1px solid var(--tg-border) !important;
}

/* Emoji Picker */
.emoji-picker {
    position: absolute; bottom: 70px; left: 15px; right: 15px;
    background: #1c242f; border-radius: 15px; box-shadow: 0 -5px 25px rgba(0,0,0,0.4);
    z-index: 100; display: none; padding: 15px; max-height: 300px; overflow-y: auto;
    direction: ltr;
}
.emoji-list { display: flex; flex-wrap: wrap; gap: 10px; font-size: 24px; cursor: pointer; }
.emoji-item:hover { transform: scale(1.2); }

/* Header Menu */
.header-menu-container { position: relative; }

/* Voice Player Styles */
.voice-player {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(255, 255, 255, 0.05);
    padding: 8px 12px;
    border-radius: 20px;
    margin-bottom: 5px;
    min-width: 200px;
}

.voice-play-btn {
    background: var(--tg-primary);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}

.voice-waveform {
    flex-grow: 1;
    height: 4px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
    position: relative;
    cursor: pointer;
}

.voice-progress {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    background: var(--tg-primary);
    width: 0%;
    border-radius: 2px;
}

.voice-duration {
    font-size: 11px;
    color: var(--tg-text-dim);
    min-width: 30px;
    text-align: left;
}

/* Linkification */
.message-link {
    color: #4db3ff;
    text-decoration: none;
    cursor: pointer;
}
.message-link:hover {
    text-decoration: underline;
}

/* Selection Mode */
.selection-toolbar {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 56px;
    background: var(--tg-sidebar);
    display: none;
    align-items: center;
    padding: 0 15px;
    z-index: 100;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.selection-toolbar.visible {
    display: flex;
}

.selection-checkbox {
    display: none;
    width: 22px;
    height: 22px;
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    margin-right: 12px;
    flex-shrink: 0;
    align-self: center;
    position: relative;
    cursor: pointer;
}

.selection-mode .selection-checkbox {
    display: block;
}

.message.selected .selection-checkbox {
    background: var(--tg-primary);
    border-color: var(--tg-primary);
}

.message.selected .selection-checkbox::after {
    content: "\f00c";
    font-family: "Font Awesome 5 Free";
    font-weight: 900;
    font-size: 12px;
    color: white;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.message.selected {
    background: rgba(36, 129, 204, 0.2) !important;
}

/* Combined Reaction & Action Menu */
.combined-menu {
    position: fixed;
    background: var(--tg-sidebar);
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.2);
    z-index: 10000;
    display: none;
    flex-direction: column;
    width: 220px;
    max-height: 80vh;
    overflow-y: auto;
    overflow-x: hidden;
    color: var(--tg-text);
    border: 1px solid var(--tg-border);
}

body[data-theme="light"] .combined-menu {
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}

.combined-menu-reactions {
    display: flex;
    padding: 10px;
    gap: 12px;
    overflow-x: auto !important;
    overflow-y: hidden;
    white-space: nowrap;
    border-bottom: 1px solid var(--tg-border);
    background: rgba(0,0,0,0.05);
    -webkit-overflow-scrolling: touch;
}

.combined-menu-reactions::-webkit-scrollbar {
    height: 4px;
}
.combined-menu-reactions::-webkit-scrollbar-thumb {
    background: var(--tg-primary);
    border-radius: 2px;
}

.combined-reaction-emoji {
    font-size: 24px;
    cursor: pointer;
    transition: transform 0.2s;
    flex-shrink: 0;
}
.combined-reaction-emoji:hover { transform: scale(1.3); }

.combined-menu-item {
    padding: 12px 18px;
    display: flex;
    align-items: center;
    gap: 15px;
    cursor: pointer;
    font-size: 15px;
    color: var(--tg-text);
    transition: background 0.2s;
}

.combined-menu-item:hover {
    background: var(--tg-sidebar-hover);
}

.combined-menu-item i {
    width: 20px;
    text-align: center;
    color: var(--tg-text-dim);
    font-size: 16px;
}

/* Desktop Selection Area */
.selection-area {
    position: absolute;
    background: rgba(36, 129, 204, 0.3);
    border: 1px solid var(--tg-primary);
    pointer-events: none;
    z-index: 1000;
}

.selection-toolbar-content {
    display: flex;
    align-items: center;
    width: 100%;
    gap: 20px;
}

.selection-count {
    flex-grow: 1;
    font-weight: bold;
    font-size: 18px;
}

.selection-toolbar .icon-btn {
    color: white;
    font-size: 20px;
    background: none;
    border: none;
    cursor: pointer;
}

.selection-toolbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: var(--tg-sidebar);
    display: none;
    align-items: center;
    padding: 0 20px;
    z-index: 10001; /* Above the menu */
    justify-content: space-between;
    border-bottom: 1px solid var(--tg-border);
}
.selection-toolbar.active {
    display: flex;
}
.selection-count {
    font-weight: bold;
    color: var(--tg-primary);
}

.message .msg-selection-checkbox {
    display: none;
    margin-left: 10px;
}
.selection-mode .msg-selection-checkbox {
    display: block !important;
}
.selection-mode .message.selected {
    background: rgba(36, 129, 204, 0.2) !important;
}
/* Checkbox styling */
.msg-selection-checkbox input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
    accent-color: var(--tg-primary);
}
.message {
    display: flex;
    align-items: center;
    transition: background 0.3s;
    -webkit-tap-highlight-color: transparent;
    user-select: none !important;
    -webkit-user-select: none !important;
    -webkit-touch-callout: none !important;
}
.msg-body {
    flex: 1;
}

.modal-content h3 {
    color: var(--tg-text) !important;
}

#forward-modal .primary-btn {
    color: var(--tg-primary) !important;
}

body[data-theme="light"] .modal-content {
    background: #ffffff;
    border: 1px solid #dfe1e5;
}

body[data-theme="light"] #modal-body input,
body[data-theme="light"] #modal-body textarea,
body[data-theme="light"] .modal-content input,
body[data-theme="light"] .modal-content textarea {
    background: #f4f4f5 !important;
    color: #000000 !important;
    border: 1px solid #dfe1e5 !important;
}

body[data-theme="light"] .drawer-header #user-fullname {
    color: #ffffff !important;
}

body[data-theme="light"] .drawer-header #user-phone {
    color: rgba(255, 255, 255, 0.8) !important;
}

body[data-theme="light"] {
    background-color: #ffffff !important;
    color: #000000 !important;
}

body[data-theme="light"] .sidebar,
body[data-theme="light"] .drawer,
body[data-theme="light"] .chat-header,
body[data-theme="light"] .input-area {
    background-color: #ffffff !important;
}

body[data-theme="light"] .chat-item:hover,
body[data-theme="light"] .menu-item:hover {
    background-color: #f4f4f5 !important;
}

/* Reply Block Styling */
.reply-block {
    background: rgba(0,0,0,0.1);
    border-right: 3px solid var(--tg-primary);
    padding: 4px 10px;
    border-radius: 6px;
    margin-bottom: 5px;
    cursor: pointer;
    font-size: 13px;
    max-width: 100%;
    overflow: hidden;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.reply-block-name {
    font-weight: bold;
    color: var(--tg-primary);
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

.reply-block-content {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0.8;
    max-width: 200px;
}

@media (min-width: 480px) {
    .reply-block-name, .reply-block-content {
        max-width: 300px;
    }
}

@media (min-width: 769px) {
    .reply-block-name, .reply-block-content {
        max-width: 450px;
    }
}
