:root[data-theme="dark"] {
    --bg-primary: #121212;
    --bg-secondary: #171717;
    --bg-tertiary: #212121;
    --text-primary: #fff;
    --text-secondary: #B7B7B7;
    --accent-color: #00ba8b;
    --accent-color-rgb: 76, 175, 80;
    --hover-color: #212121;
    --border-color: #212121;
    --message-sent: #171717;
    --message-received: #171717;
    --status-online-color: #4CAF50;
    --status-offline-color: #b7b7b7;
    --active-chat-bg: #1a1a1a;
    --tg-reaction-panel-bg: #212121;
    --mention-bg: rgba(76,175,80,0.13);
    --mention-bg-hover: rgba(76,175,80,0.22);
    --mention-highlight-bg: #1a2d1a;
    --mention-highlight-blink: #295d29;
    --code-bg: #23272e;
    --code-color: #e6e6e6;
    --code-border: #23272e;
    --code-lang-bg: #2e3440;
    --code-lang-color: #a3be8c;
    --inline-code-bg: #1a2d1a;
    --inline-code-color: #4CAF50;
    --pattern-grad-1: #8A2BE2;
    --pattern-grad-2: #DAA520;
    --pattern-grad-3: #4CAF50;
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

:root[data-theme="light"] {
    --bg-primary: #ffffff;
    --bg-secondary: #f5f5f5;
    --bg-tertiary: #e9e9e9;
    --text-primary: #000000;
    --text-secondary: #707579;
    --accent-color: #00ba8b;
    --accent-color-rgb: 76, 175, 80;
    --hover-color: #e9e9e9;
    --border-color: #e9e9e9;
    --message-sent: #e3fcd9;
    --message-received: #f5f5f5;
    --status-online-color: #4CAF50;
    --status-offline-color: #b7b7b7;
    --tg-reaction-panel-bg: #fff;
    --mention-bg: rgba(76,175,80,0.08);
    --mention-bg-hover: rgba(76,175,80,0.18);
    --mention-highlight-bg: #e6fbe6;
    --mention-highlight-blink: #c6f5c6;
    --code-bg: #f5f5f5;
    --code-color: #222;
    --code-border: #e0e0e0;
    --code-lang-bg: #e0f3ff;
    --code-lang-color: #4CAF50;
    --inline-code-bg: #e6fbe6;
    --inline-code-color: #4CAF50;
    --pattern-grad-1: #9370DB;
    --pattern-grad-2: #f5d56c;
    --pattern-grad-3: #6495ED;
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Roboto', sans-serif;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Common Components */
.btn {
    padding: 0.75rem;
    background-color: var(--accent-color);
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.btn:hover {
    background-color: var(--accent-color);
    opacity: 0.9;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

.form-group input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-size: 1rem;
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

.form-group input:focus {
    outline: none;
    border-color: var(--accent-color);
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.error-message {
    color: #ff4444;
    text-align: center;
    margin-bottom: 1rem;
    display: none;
}

/* Auth Pages */
.auth-container {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

body.auth-page .auth-container {
    width: 100%;
}

.auth-box {
    background-color: var(--bg-secondary);
    padding: 2rem;
    border-radius: 8px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

.auth-header {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-header h1 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    transition: color 0.3s ease;
}

.auth-link {
    text-align: center;
    margin-top: 1rem;
    color: var(--text-secondary);
    transition: color 0.3s ease;
}

.auth-link a {
    color: var(--accent-color);
    text-decoration: none;
    transition: color 0.3s ease;
}

.auth-link a:hover {
    text-decoration: underline;
}

/* Chat Interface */
.chat-container {
    height: 100vh;
    display: flex;
}

.sidebar {
    width: 320px;
    background-color: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: background-color 0.3s ease, border-color 0.3s ease;
    position: relative;
}

.header {
    padding: 20px;
    background-color: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.search-bar {
    padding: 10px;
    background-color: var(--bg-primary);
    transition: background-color 0.3s ease;
}

.search-input {
    width: 100%;
    padding: 10px;
    background-color: var(--bg-secondary);
    border: none;
    border-radius: 8px;
    color: var(--text-primary);
    outline: none;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.chat-list {
    flex: 1;
    overflow-y: auto;
}

.tg-chat-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.2s ease;
    flex-shrink: 0;
    min-width: 0;
    overflow: hidden; /* Added to clip overflowing content within the item */
}

.tg-chat-item:hover {
    background: var(--hover-color);
}

.chat-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    /* margin-right: 15px; */ /* REMOVED: Using gap on .tg-chat-item */
    background-color: var(--accent-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2em;
    color: white;
    text-transform: uppercase;
    transition: background-color 0.3s ease, color 0.3s ease;
    flex-shrink: 0; /* Prevent avatar from shrinking */
}

.chat-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    display: none;
}

.chat-avatar.has-image {
    background-color: transparent;
}

.chat-avatar.has-image img {
    display: block;
}

.tg-chat-info {
    flex: 1;
    min-width: 0; /* Important for preventing overflow of its children */
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.tg-chat-title {
    font-weight: 500;
    margin-bottom: 5px;
    transition: color 0.3s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tg-chat-status {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    color: var(--text-secondary);
    font-size: 0.9em;
}

.tg-chat-last {
    /* white-space: nowrap; REMOVED - it's on tg-chat-message */
    /* overflow: hidden; */ /* REMOVED: Allowing child to handle overflow */
    /* text-overflow: ellipsis; */ /* REMOVED: Allowing child to handle ellipsis */
    max-width: 100%;
    display: flex;
    align-items: center;
    gap: 4px; /* Added gap */
}

.tg-chat-message {
    /* white-space: nowrap; */ /* REMOVED: Allowing text to wrap */
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box; /* For multi-line ellipsis */
    -webkit-line-clamp: 2; /* Limit to 2 lines */
    -webkit-box-orient: vertical; /* Required for line-clamp */
    word-break: break-word; /* Break long words */
    flex: 1 1 0%;
    min-width: 0;
}

.tg-chat-meta {
    margin-left: auto;
    flex-shrink: 0;
    min-width: fit-content; /* Ensure it takes minimal space but doesn't wrap */
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    transition: background-color 0.3s ease;
}

.messages-area {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background-color: var(--bg-tertiary);
    display: flex;
    flex-direction: column;
    transition: background-color 0.3s ease;
}

.message {
    display: flex;
    margin: 0 24px;
    gap: 8px;
}

.message-input {
    padding: 20px;
    background-color: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: flex-end;
    gap: 10px;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.message-input-area {
    flex: 1;
    min-height: 24px;
    max-height: 150px;
    padding: 12px;
    background-color: var(--bg-secondary);
    border: none;
    border-radius: 8px;
    color: var(--text-primary);
    outline: none;
    overflow-y: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.message-input-area:empty:before {
    content: 'Сообщение';
    color: var(--text-secondary);
    transition: color 0.3s ease;
}

.send-button {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--accent-color);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: scale(0);
    transition: all 0.3s ease, background-color 0.3s ease, color 0.3s ease;
    flex-shrink: 0;
}

.send-button.visible {
    opacity: 1;
    transform: scale(1);
}

/* --- Telegram Style Layout --- */
body, html {
    height: 100vh;
    overflow: hidden;
    background: var(--bg-primary);
    transition: background-color 0.3s ease;
}
.tg-wrapper {
    display: flex;
    height: 100vh;
    width: 100vw;
    background: var(--bg-primary);
    transition: background-color 0.3s ease;
}

/* Sidebar */
.tg-sidebar {
    width: 370px;
    background: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    border-right: 1.5px solid var(--border-color);
    position: relative;
    z-index: 3;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}
.tg-sidebar-top {
    display: flex;
    align-items: center;
    gap: 12px;
    height: 56px;
    padding: 0 16px;
    background: var(--bg-primary);
    border-bottom: 1.5px solid var(--border-color);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}
.tg-burger,
.tg-profile-avatar {
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.tg-burger {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 24px;
    cursor: pointer;
    display: none; /* Hidden by default on desktop */
    padding: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.3s ease, color 0.3s ease;
}
.tg-burger:hover {
    background: var(--accent-color);
    color: #fff;
}
.tg-logo {
    font-weight: 700;
    font-size: 1.2em;
    color: var(--accent-color);
    margin-right: auto;
    transition: color 0.3s ease;
}
.tg-profile-avatars {
    display: flex;
    align-items: center;
    margin-left: auto;
}
.tg-profile-avatar {
    width: 40px !important;
    height: 40px !important;
    border-radius: 50% !important;
    object-fit: cover !important;
    box-sizing: border-box !important;
    background: var(--bg-secondary);
    transition: transform 0.2s ease, background-color 0.3s ease;
    border: none !important;
}
.tg-profile-avatar:hover {
    transform: scale(1.05);
}

.tg-tabs {
    display: flex;
    gap: 4px;
    padding: 10px 10px 0 10px;
}
.tg-tab {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-weight: 500;
    padding: 6px 14px;
    border-radius: 20px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s, background-color 0.3s ease, color 0.3s ease;
}
.tg-tab.active, .tg-tab:hover {
    background: var(--accent-color);
    color: #fff;
}

.tg-search-bar {
    display: flex;
    align-items: center;
    background: var(--bg-primary);
    padding: 10px 14px;
    border-bottom: 1.5px solid var(--border-color);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}
.tg-search-bar i {
    color: var(--text-secondary);
    margin-right: 8px;
    transition: color 0.3s ease;
}
.tg-search-input {
    flex: 1;
    background: var(--bg-secondary);
    border: none;
    border-radius: 18px;
    padding: 7px 14px;
    color: var(--text-primary);
    font-size: 1em;
    outline: none;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.tg-chat-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 0 70px 0;
}
.tg-chat-item {
    display: flex;
    align-items: center;
    padding: 12px 18px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.18s, border-color 0.3s ease, transform 0.2s ease-in-out;
    position: relative;
    background: none;
}
.tg-chat-item:hover {
    background: var(--hover-color);
}
.tg-chat-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-weight: 600;
    font-size: 1.2em;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 14px;
    overflow: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
}
.tg-avatar-img img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}
.tg-chat-info {
    flex: 1;
    min-width: 0;
}
.tg-chat-title {
    font-weight: 500;
    margin-bottom: 5px;
    transition: color 0.3s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.tg-chat-last {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
    font-size: 13px;
    margin-top: 2px;
    transition: color 0.3s ease;
}
.tg-chat-message {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.tg-chat-meta {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}
.tg-chat-time {
    color: var(--text-tertiary);
    font-size: 12px;
    transition: color 0.3s ease;
}
.tg-message-read,
.tg-message-sent,
.tg-message-views {
    color: var(--text-tertiary);
    font-size: 12px;
    transition: color 0.3s ease;
}
.tg-chat-badge {
    background: var(--accent-color);
    color: #fff;
    border-radius: 12px;
    font-size: 0.8em;
    padding: 2px 7px;
    font-weight: 600;
    transition: background-color 0.3s ease, color 0.3s ease;
    min-width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(var(--accent-color-rgb), 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
}
.tg-fab {
    position: absolute;
    right: 24px;
    bottom: 24px;
    z-index: 3;
}
.tg-fab:hover {
    background: var(--hover-color);
}

/* Main Chat Area */
.tg-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background: var(--bg-primary);
    overflow: hidden;
    transition: background-color 0.3s ease;
}
.tg-topbar {
    display: flex;
    align-items: stretch;
    justify-content: space-between;
    padding: 14px 24px;
    background: var(--bg-secondary);
    border-bottom: 1.5px solid var(--border-color);
    z-index: 2;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}
.tg-topbar-left {
    display: flex;
    align-items: center;
    gap: 16px;
    flex: 1 1 auto;
    min-width: 0;
}
.tg-topbar-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3em;
    font-weight: 700;
    color: var(--text-primary);
    position: relative;
    transition: background-color 0.3s ease, color 0.3s ease;
}
.tg-topbar-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    display: block;
}
.tg-topbar-avatar span {
    width: 100%;
    text-align: center;
    font-size: 1.1em;
    font-weight: 700;
    color: var(--text-primary);
    display: block;
    line-height: 48px;
    transition: color 0.3s ease;
}
.tg-topbar-info {
    display: flex;
    flex-direction: column;
    justify-content: center;
}
.tg-topbar-title {
    font-weight: 700;
    color: var(--text-primary);
    font-size: 1.1em;
    transition: color 0.3s ease;
}
.tg-topbar-status {
    color: var(--text-secondary);
    font-size: 0.95em;
    transition: color 0.3s ease;
}
.tg-topbar-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
}
.tg-topbar-btn {
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.95em;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 36px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
}
.tg-topbar-btn:hover {
    background: var(--hover-color);
    color: var(--text-primary);
}
.tg-topbar-btn i {
    font-size: 1.1em;
    transition: color 0.3s ease;
}
.tg-topbar-actions button {
    width: 40px;
    height: 40px;
    background: var(--bg-tertiary);
    border: none;
    color: var(--text-primary);
    font-size: 1.2em;
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    margin-left: 0;
}
.tg-topbar-actions button:hover {
    background: var(--hover-color);
    color: var(--text-primary);
}

/* Chat background pattern */
.tg-chat-bg {
    background: url('https://masegram.online/static/svg/pattern.svg');
    position: absolute;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

/* Messages */
.tg-messages {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    position: relative;
    z-index: 1;
    /* background: url('https://masegram.online/static/svg/pattern.svg'); */
    transition: background-color 0.3s ease;
    padding-bottom: 12px;
    padding-top: 12px;
}
.tg-message {
    display: flex;
    margin: 0 24px;
    gap: 8px;
    align-items: flex-end;
}
.tg-message-content-wrapper {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    max-width: 60%;
}

.tg-message-group-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    background: var(--bg-tertiary);
    margin-bottom: 0;
    transition: background-color 0.3s ease;
}
.tg-message-group-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.tg-message-in .tg-message-group-avatar {
    display: flex;
}
.tg-message-out .tg-message-group-avatar {
    display: none;
}

.tg-message-in {
    justify-content: flex-start;
}
.tg-message-in .tg-message-content-wrapper {
    align-items: flex-start;
}

.tg-message-out {
    justify-content: flex-end;
}
.tg-message-out .tg-message-content-wrapper {
    align-items: flex-end;
}

.tg-message-username {
    font-size: 0.85em;
    color: var(--text-secondary);
    margin-bottom: 2px;
    text-align: left;
    font-weight: 500;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color 0.3s ease;
}

.tg-message-out .tg-message-username {
    display: none;
}

.tg-message-bubble {
    width: auto;
    min-width: 40px;
    max-width: 100%;
    background: var(--message-received);
    color: var(--text-primary);
    border-radius: 12px 12px 12px 0;
    padding: 12px 18px 8px 18px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    font-size: 1.08em;
    position: relative;
    word-break: break-word;
    transition: background 0.2s, background-color 0.3s ease, color 0.3s ease;
}
.tg-message-out .tg-message-bubble {
    background: var(--message-sent);
    color: var(--text-primary);
    border-radius: 12px 12px 0 12px;
}
.tg-message-in .tg-message-bubble {
    background: var(--message-received);
    color: var(--text-primary);
    border-radius: 12px 12px 12px 0;
}

.tg-message-meta {
    font-size: 0.85em;
    color: var(--text-secondary);
    margin-top: 6px;
    text-align: right;
    transition: color 0.3s ease;
}

/* Input bar */
.tg-input-bar {
    position: relative;
    display: flex;
    align-items: center;
    padding: 10px 16px;
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    gap: 12px;
}

.tg-input {
    flex: 1;
    min-height: 24px;
    max-height: 200px;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.95em;
    outline: none;
    overflow-y: auto;
    position: relative;
}

.tg-input-attach {
    width: 44px;
    height: 44px;
    background: var(--bg-tertiary);
    border: none;
    color: var(--text-primary);
    font-size: 1.3em;
    cursor: pointer;
    margin-right: 6px;
    transition: background-color 0.2s ease, color 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
}

.tg-input-attach:hover {
    background: var(--hover-color);
    color: var(--text-primary);
}
.tg-chat-message-search-bar {
    background: var(--bg-primary);
    padding: 10px 24px 0 24px;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 2;
}
#chatMessageSearch {
    width: 100%;
    max-width: 400px;
    padding: 8px 14px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 1em;
    outline: none;
    margin-bottom: 6px;
    transition: background-color 0.3s, color 0.3s, border-color 0.3s;
}
#chatMessageSearch:focus {
    border-color: var(--accent-color);
}
.tg-chat-message-search-input {
    background: var(--bg-secondary);
    border: 1.5px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 1em;
    padding: 8px 14px;
    outline: none;
    transition: width 0.3s, opacity 0.3s, background 0.3s, color 0.3s, border-color 0.3s, margin-left 0.3s;
    width: 0;
    opacity: 0;
    margin-left: 0;
    max-width: 320px;
    pointer-events: none;
}
.tg-chat-message-search-input.visible {
    width: 220px;
    opacity: 1;
    margin-left: 10px;
    pointer-events: auto;
}
.tg-btn-action.active,
.tg-btn-action:focus {
    background: var(--accent-color);
    color: #fff;
}
.tg-btn-action {
    transition: background 0.2s, color 0.2s;
}
@media (max-width: 300px) {
    .tg-chat-message-search-input.visible {
        width: 120px;
        max-width: 120px;
    }
}

/* --- Chat title flex/ellipsis/badge styles (для корректного отображения длинных названий и бейджей) --- */
.tg-chat-title-flex {
    display: flex;
    align-items: center;
    min-width: 0;
    gap: 6px;
}

.tg-chat-title-ellipsis {
    display: flex;
    align-items: center;
    max-width: 180px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
    gap: 6px;
}

.tg-chat-title-badge {
    flex-shrink: 0;
    margin-left: 6px;
}

/* --- Custom styled checkbox for settings --- */
.tg-checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 1em;
    color: var(--text-primary);
    user-select: none;
    position: relative;
}
.tg-settings-checkbox {
    appearance: none;
    width: 22px;
    height: 22px;
    border: 2px solid var(--accent-color);
    border-radius: 6px;
    background: var(--bg-secondary);
    transition: border-color 0.2s, background 0.2s;
    position: relative;
    cursor: pointer;
    outline: none;
    margin-right: 8px;
    display: inline-block;
    vertical-align: middle;
}
.tg-settings-checkbox:checked {
    background: var(--accent-color);
    border-color: var(--accent-color);
}
.tg-settings-checkbox:checked::after {
    content: '';
    position: absolute;
    left: 6px;
    top: 2px;
    width: 6px;
    height: 12px;
    border: solid #fff;
    border-width: 0 3px 3px 0;
    transform: rotate(45deg);
    pointer-events: none;
}
.tg-settings-checkbox:focus {
    box-shadow: 0 0 0 2px rgba(var(--accent-color-rgb), 0.2);
}

/* --- Reactions (реакции на сообщения) --- */
.tg-message-reactions {
    display: flex;
    gap: 1px;
    margin-top: 2px;
    user-select: none;
    min-height: 18px;
    align-items: center;
    flex-wrap: wrap;
}

/* Кнопка реакции */
.tg-reaction-btn {
    background: none;
    border: none;
    border-radius: 999px;
    padding: 0 7px 0 5px;
    font-size: 15px;
    cursor: pointer;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 3px;
    outline: none;
    min-width: 22px;
    min-height: 22px;
    height: 22px;
    box-shadow: none;
    transition: background 0.15s, color 0.15s, box-shadow 0.15s;
    position: relative;
}

.tg-reaction-btn.active {
    background: rgba(var(--accent-color-rgb), 0.13);
    color: var(--accent-color);
    box-shadow: 0 2px 8px rgba(var(--accent-color-rgb), 0.10);
}

.tg-reaction-btn:hover:not(.active) {
    background: rgba(var(--accent-color-rgb), 0.07);
}

.tg-reaction-btn span {
    font-size: 12px;
    margin-left: 2px;
    min-width: 10px;
    text-align: center;
    color: var(--text-secondary);
    font-weight: 500;
    line-height: 1;
}

.tg-reaction-btn.active span {
    color: var(--accent-color);
}

/* Кнопка "добавить реакцию" */
.tg-reaction-add {
    background: none;
    border: none;
    color: var(--accent-color);
    font-weight: bold;
    font-size: 15px;
    min-width: 22px;
    min-height: 22px;
    height: 22px;
    padding: 0 7px 0 7px;
    border-radius: 999px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}

.tg-reaction-add:hover {
    background: rgba(var(--accent-color-rgb), 0.10);
    color: var(--accent-color);
}

/* Панель реакций */
.tg-reaction-panel {
    display: flex;
    gap: 2px;
    background: var(--bg-secondary);
    border-radius: 16px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.14), 0 1px 3px rgba(0,0,0,0.08);
    padding: 4px 8px;
    position: fixed;
    opacity: 0;
    pointer-events: none;
    transform: translateY(6px) scale(0.97);
    transition: opacity 0.18s cubic-bezier(.4,0,.2,1), transform 0.18s cubic-bezier(.4,0,.2,1);
    z-index: 1000;
}

.tg-reaction-panel.active {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

.tg-reaction-panel-btn {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    padding: 2px 5px;
    border-radius: 50%;
    transition: background 0.15s;
    color: var(--text-primary);
}

.tg-reaction-panel-btn:hover {
    background: rgba(var(--accent-color-rgb), 0.13);
    color: var(--accent-color);
}

.tg-reaction-panel {
    background: var(--tg-reaction-panel-bg);
}

.tg-forward-chat-item {
    padding: 10px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.15s;
    color: var(--text-primary);
    font-size: 1em;
}
.tg-forward-chat-item:hover {
    background: var(--hover-color);
}

.tg-message-forwarded {
    background: var(--bg-tertiary, #e9e9e9);
    border-left: 2px solid var(--accent-color, #0088cc);
    padding: 2px 8px;
    margin-bottom: 4px;
    font-size: 0.92em;
    color: var(--text-secondary, #555);
    border-radius: 3px;
}

.tg-forwarded-username,
.tg-forwarded-chat {
    color: var(--accent-color, #0088cc);
    text-decoration: underline;
    cursor: pointer;
    transition: color 0.18s;
}
.tg-forwarded-username:hover,
.tg-forwarded-chat:hover {
    color: #005f8c;
    text-decoration: underline;
    filter: brightness(1.1);
}

.tg-mention {
    color: var(--accent-color, #0088cc);
    font-weight: bold;
    background: var(--mention-bg, rgba(0,136,204,0.08));
    border-radius: 4px;
    padding: 0 2px;
    cursor: pointer;
    transition: background 0.2s;
}
.tg-mention:hover {
    background: var(--mention-bg-hover, rgba(0,136,204,0.18));
}
.tg-message-mentioned {
    background: var(--mention-highlight-bg, #e0f3ff) !important;
    border-left: 4px solid var(--accent-color, #0088cc);
}
.tg-message-mentioned-animate {
    animation: mention-blink 0.8s 2;
}
@keyframes mention-blink {
    0% { background: var(--mention-highlight-bg, #e0f3ff); }
    50% { background: var(--mention-highlight-blink, #b6e6ff); }
    100% { background: var(--mention-highlight-bg, #e0f3ff); }
}

/* --- Code block styles --- */
.tg-code-block {
    background: var(--code-bg, #23272e);
    color: var(--code-color, #e6e6e6);
    border-radius: 6px;
    padding: 12px 16px;
    margin: 8px 0;
    font-family: 'Fira Mono', 'Consolas', 'Menlo', 'Monaco', monospace;
    font-size: 0.98em;
    overflow-x: auto;
    position: relative;
    border: 1px solid var(--code-border, #23272e);
    line-height: 1.6;
}
.tg-code-block code {
    background: none;
    color: inherit;
    font-family: inherit;
    font-size: inherit;
    padding: 0;
}
.tg-code-lang {
    position: absolute;
    top: 6px;
    right: 12px;
    background: var(--code-lang-bg, #2e3440);
    color: var(--code-lang-color, #a3be8c);
    font-size: 0.85em;
    padding: 2px 8px;
    border-radius: 4px;
    font-family: 'Fira Mono', 'Consolas', monospace;
    pointer-events: none;
    opacity: 0.85;
}
.tg-inline-code {
    background: var(--inline-code-bg, #e6fbe6);
    color: var(--inline-code-color, #4CAF50);
    border-radius: 4px;
    padding: 1px 5px;
    font-family: 'Fira Mono', 'Consolas', monospace;
    font-size: 0.97em;
}

.tg-call-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 48px;
    background: var(--accent-color, #0088cc);
    color: #fff;
    display: flex;
    align-items: center;
    z-index: 10002;
    padding: 0 16px;
    font-size: 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    transition: top 0.2s;
    gap: 12px;
}
.tg-call-bar.hidden { display: none; }
.tg-call-bar button {
    background: none;
    border: none;
    color: #fff;
    font-size: 20px;
    margin-left: 8px;
    cursor: pointer;
}

.tg-has-call-bar .tg-topbar,
.tg-has-call-bar .tg-main {
    margin-top: 34px;
    transition: margin-top 0.2s;
}

.tg-has-call-bar .tg-sidebar,
.tg-has-call-bar .tg-sidebar-top {
    margin-top: 34px;
    transition: margin-top 0.2s;
}

/* File & Media Previews in Chat */
.tg-message-gallery {
    display: grid;
    gap: 4px;
    margin-bottom: 5px;
    border-radius: 8px;
    overflow: hidden;
    max-width: 320px;
}

.tg-message-gallery.grid-cols-1 { grid-template-columns: 1fr; }
.tg-message-gallery.grid-cols-2 { grid-template-columns: 1fr 1fr; }
.tg-message-gallery.grid-cols-3 { grid-template-columns: 1fr 1fr 1fr; }

.tg-message-gallery .tg-grid-item {
    position: relative;
    background: #e1e3e6;
    aspect-ratio: 1 / 1;
}

.tg-message-gallery.items-3 .tg-grid-item:first-child {
    grid-column: span 2;
    grid-row: span 2;
    aspect-ratio: 2 / 2;
}

.tg-message-gallery img,
.tg-gallery-video-preview {
    width: 100%;
    height: 100%;
    object-fit: cover;
    cursor: pointer;
    display: block;
}

.tg-grid-item a {
    position: relative;
    display: block;
    width: 100%;
    height: 100%;
}

.tg-video-play-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 24px;
    background-color: rgba(0, 0, 0, 0.5);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none; /* So the link can be clicked */
    transition: transform 0.2s, background-color 0.2s;
    text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

.tg-grid-item:hover .tg-video-play-icon {
    transform: translate(-50%, -50%) scale(1.1);
    background-color: rgba(0, 0, 0, 0.7);
}

.tg-message-caption {
    padding: 4px 6px 0 6px;
    word-break: break-word;
    line-height: 1.4;
    color: var(--text-primary);
}

.tg-message-file {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 10px;
    background-color: transparent;
    border-radius: 12px;
    max-width: 300px;
    margin-bottom: 5px;
    border: 1px solid transparent;
    transition: border-color 0.2s, background-color 0.2s;
}

.tg-message-file:not(:first-child) {
    border-top: 1px solid rgba(0,0,0,0.07);
}

.dark-theme .tg-message-file:not(:first-child) {
    border-top: 1px solid rgba(255,255,255,0.1);
}

.dark-theme .tg-message-file {
    background-color: transparent;
}

.tg-message-file:hover {
    border-color: rgba(var(--accent-color-rgb), 0.2);
    background-color: rgba(0, 0, 0, 0.05);
}

.dark-theme .tg-message-file:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.tg-file-icon {
    font-size: 28px;
    color: var(--accent-color);
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(var(--accent-color-rgb), 0.1);
    border-radius: 50%;
}

.tg-file-info {
    flex-grow: 1;
    overflow: hidden;
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
}

.tg-file-name {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.95em;
}

.tg-file-meta {
    font-size: 0.8em;
    color: var(--text-secondary);
}

.tg-file-download {
    color: var(--text-secondary);
    font-size: 22px;
    transition: color 0.2s, transform 0.2s;
    padding: 8px;
    border-radius: 50%;
}

.tg-file-download:hover {
    color: var(--accent-color);
    transform: scale(1.1);
    background-color: rgba(var(--accent-color-rgb), 0.1);
}

/* File Preview Modal */
.tg-modal-file-preview .tg-modal-body {
    display: flex;
    flex-direction: column;
    gap: 15px;
    max-height: 70vh;
}

.tg-file-preview-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 10px;
    overflow-y: auto;
    flex-grow: 1;
    padding: 5px;
    background: rgba(0,0,0,0.05);
    border-radius: 8px;
}

.dark-theme .tg-file-preview-container {
     background: rgba(255,255,255,0.05);
}

.tg-file-preview-item {
    position: relative;
    aspect-ratio: 1/1;
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f0f2f5;
}

.dark-theme .tg-file-preview-item {
    background: var(--tg-secondary-bg);
}

.tg-file-preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.tg-file-preview-item .tg-file-icon {
    font-size: 40px;
}

.tg-file-caption-input-wrapper {
    position: relative;
}

.tg-file-caption-input-wrapper .tg-input {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: var(--tg-bg);
    color: var(--text-primary);
    resize: none; /* Disable manual resize handle */
    overflow-y: hidden; /* Hide scrollbar until needed */
    line-height: 1.4;
    max-height: 120px; /* Limit max height */
}

.tg-file-caption-input-wrapper .tg-input:focus {
    border-color: var(--accent-color);
    outline: none;
}

.tg-modal-footer {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
}

/* This rule is no longer needed as videos are in the gallery */
.tg-message-video-container {
   display: none;
}

.tg-message-text-wrapper {
    max-height: none;
    overflow: visible;
    transition: none;
    display: block;
}
.tg-message-text {
    white-space: pre-wrap;
    word-break: break-word;
    /* без max-height и overflow! */
}

/* --- Audio Player Styles --- */
.tg-message-audio {
    background-color: rgba(var(--accent-color-rgb), 0.12); /* Чуть более насыщенный фон */
    display: flex;
    align-items: center; 
    gap: 10px;
    padding: 10px 14px; /* Увеличенный внутренний отступ */
    max-width: 340px; /* Увеличенная максимальная ширина */
    border-radius: 16px; /* Более закругленные углы */
}

.tg-message-audio:not(:first-child) {
    border-top: 1px solid rgba(0,0,0,0.07);
}
.dark-theme .tg-message-audio:not(:first-child) {
    border-top: 1px solid rgba(255,255,255,0.1);
}

.tg-audio-play-btn {
    width: 38px;
    height: 38px;
    flex-shrink: 0;
    border-radius: 50%;
    background-color: var(--accent-color);
    color: white;
    border: none;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, transform 0.2s;
}

.tg-audio-play-btn:hover {
    transform: scale(1.05);
}

.tg-audio-info {
    flex-grow: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 2px;
}

.tg-audio-progress-bar {
    width: 100%;
    height: 4px;
    background-color: rgba(0,0,0,0.1);
    border-radius: 2px;
    cursor: pointer;
    position: relative;
}

.dark-theme .tg-audio-progress-bar {
    background-color: rgba(255,255,255,0.2);
}

.tg-audio-seek-bar {
    height: 100%;
    width: 0%;
    background-color: var(--accent-color);
    border-radius: 2px;
    transition: width 0.1s linear;
}

.tg-audio-details {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.tg-audio-name {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.9em;
    color: var(--text-primary);
}

.tg-audio-time {
    font-size: 0.8em;
    color: var(--text-secondary);
    white-space: nowrap;
}

.dark-theme .tg-message-files-group {
    background-color: rgba(255,255,255,0.08);
}

@media (max-width: 900px) {
  .tg-fab {
    position: fixed !important;
    left: auto;
    right: 16px;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    z-index: 1002;
  }
  .tg-chats {
    padding-bottom: 80px;
  }
}

#remoteScreenVideo {
    background: #000;
    border-radius: 8px;
    margin: 10px 0;
    max-width: 100%;
    max-height: 60vh;
    display: none;
}
#remoteScreenVideo.active {
    display: block;
}
#startScreenShareBtn, #stopScreenShareBtn,
#startScreenShareBtnBar, #stopScreenShareBtnBar {
    background: var(--accent-color);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 8px 12px;
    margin-left: 8px;
    cursor: pointer;
    font-size: 1.1em;
    transition: background 0.2s;
}
#startScreenShareBtn:hover, #stopScreenShareBtn:hover,
#startScreenShareBtnBar:hover, #stopScreenShareBtnBar:hover {
    background: var(--accent-color);
}

/* Call Modal Base Styles */
.tg-modal-call {
    background: var(--bg-secondary);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.18);
    width: 400px;
    max-width: 95vw;
    padding: 0;
    position: relative;
    transition: background-color 0.3s, box-shadow 0.3s;
    overflow: hidden;
}
@media (max-width: 600px) {
    .tg-modal-call {
        width: 98vw;
        min-width: 0;
        padding: 0;
    }
}

/* === PINNED MESSAGE BAR (Telegram style, no transparent bg) === */
#pinnedMessageBar {
    width: 100%;
    max-width: 100vw;
    z-index: 10;
    position: relative;
    background: var(--bg-secondary, #232323);
    box-shadow: 0 1px 0 rgba(0,0,0,0.10);
    border-bottom: 1px solid var(--border-color, #232323);
    border-left: none;
    padding: 0;
    margin: 0;
    transition: background 0.25s, box-shadow 0.25s, border-color 0.25s;
    animation: pinnedBarFadeIn 0.35s cubic-bezier(.4,0,.2,1);
}

#pinnedMessageBar .tg-pinned-message-bar-inner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px 8px 12px;
    min-height: 36px;
    font-size: 1em;
    color: var(--text-primary, #fff);
    background: none;
    position: relative;
    font-weight: 500;
    letter-spacing: 0.01em;
    box-shadow: none;
    cursor: pointer;
}

#pinnedMessageBar .tg-pinned-message-content {
    flex: 1;
    pointer-events: none;
}

#pinnedMessageBar .tg-pinned-message-pin {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 8px;
    font-size: 1.1em;
    color: var(--accent-color, #4fa3f7);
    opacity: 1;
    filter: none;
    flex-shrink: 0;
}

#pinnedMessageBar .tg-pinned-message-text {
    flex: 1;
    white-space: pre-line;
    word-break: break-word;
    color: var(--text-primary, #fff);
    opacity: 1;
    font-weight: 500;
    font-size: 1em;
    text-shadow: none;
}

#pinnedMessageBar .tg-unpin-btn {
    background: none;
    border: none;
    color: var(--text-secondary, #b0b0b0);
    font-size: 1.1em;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    transition: background 0.18s, color 0.18s;
    opacity: 0.7;
}

#pinnedMessageBar .tg-unpin-btn:hover {
    background: rgba(var(--accent-color-rgb, 79,163,247), 0.10);
    color: var(--accent-color, #4fa3f7);
    opacity: 1;
}

@keyframes pinnedBarFadeIn {
    from { opacity: 0; transform: translateY(-8px) scale(0.99); }
    to { opacity: 1; transform: none; }
}

@media (max-width: 600px) {
    #pinnedMessageBar .tg-pinned-message-bar-inner {
        padding: 6px 6px 6px 8px;
        font-size: 0.97em;
    }
}

#pinnedMessageBar .tg-pinned-thumb {
    width: 38px;
    height: 38px;
    object-fit: cover;
    border-radius: 8px;
    margin-right: 10px;
    box-shadow: 0 2px 8px rgba(var(--accent-color-rgb), 0.10);
    vertical-align: middle;
}
#pinnedMessageBar .tg-pinned-file {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 1em;
    color: var(--accent-color);
    background: rgba(var(--accent-color-rgb), 0.10);
    border-radius: 6px;
    padding: 2px 10px 2px 8px;
    margin-right: 10px;
    font-weight: 500;
}
#pinnedMessageBar .tg-pinned-file i {
    margin-right: 4px;
    font-size: 1.1em;
}
#pinnedMessageBar .tg-pinned-message-text-main {
    font-weight: 500;
    color: var(--text-primary);
    text-shadow: 0 1px 2px rgba(0,0,0,0.04);
    font-size: 1em;
    vertical-align: middle;
}
#pinnedMessageBar .tg-pinned-message-empty {
    color: var(--text-secondary);
    font-style: italic;
    font-size: 0.98em;
    margin-left: 8px;
}

#pinnedMessageBar .tg-pinned-message-nav-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    min-width: 70px;
}
#pinnedMessageBar .tg-pinned-message-nav-actions .tg-pinned-nav-btn {
    min-width: 28px;
    min-height: 28px;
    border: none;
    background: none;
    color: var(--accent-color);
    font-size: 1.1em;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.18s, color 0.18s;
    opacity: 0.85;
}
#pinnedMessageBar .tg-pinned-message-nav-actions .tg-pinned-nav-btn:disabled {
    opacity: 0.4;
    cursor: default;
}
#pinnedMessageBar .tg-pinned-message-nav-actions .tg-pinned-index {
    font-size: 0.98em;
    color: var(--text-secondary);
    margin: 0 2px;
    min-width: 32px;
    text-align: center;
    font-weight: 500;
}
#pinnedMessageBar .tg-pinned-message-bar-inner:hover {
    background: rgba(var(--accent-color-rgb), 0.08);
}

/* Улучшенные стили для модального окна настроек */
.tg-modal-settings .tg-modal-body {
    max-height: 70vh;
    overflow-y: auto;
    padding: 20px;
    box-sizing: border-box;
}

.tg-modal-settings .tg-settings-section {
    margin-bottom: 30px;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.tg-modal-settings .tg-settings-section:last-child {
    margin-bottom: 0;
}

.tg-modal-settings .tg-settings-section-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 15px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Адаптивные стили для модального окна настроек */
@media (max-width: 600px) {
    .tg-modal-settings .tg-modal-body {
        padding: 16px;
        max-height: 60vh;
    }
    
    .tg-modal-settings .tg-settings-section {
        margin-bottom: 24px;
    }
    
    .tg-modal-settings .tg-settings-section-title {
        font-size: 15px;
        margin-bottom: 12px;
    }
}

@media (max-width: 400px) {
    .tg-modal-settings .tg-modal-body {
        padding: 12px;
        max-height: 50vh;
    }
    
    .tg-modal-settings .tg-settings-section {
        margin-bottom: 20px;
    }
    
    .tg-modal-settings .tg-settings-section-title {
        font-size: 14px;
        margin-bottom: 10px;
    }
}

@media (max-width: 300px) {
    .tg-modal-settings .tg-modal-body {
        padding: 10px;
        max-height: 45vh;
    }
    
    .tg-modal-settings .tg-settings-section {
        margin-bottom: 16px;
    }
    
    .tg-modal-settings .tg-settings-section-title {
        font-size: 13px;
        margin-bottom: 8px;
    }
}

/* Account type icons */
.tg-account-type-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    margin-left: 6px;
    font-size: 11px;
    color: white;
    flex-shrink: 0;
    font-weight: 600;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: all 0.2s ease;
    line-height: 1;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.tg-account-type-icon:hover {
    transform: scale(1.1);
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.3);
}

.tg-account-type-icon.verified {
    background: linear-gradient(135deg, #00b4d8, #0077b6);
    border: 2px solid #00b4d8;
}

.tg-account-type-icon.official {
    background: linear-gradient(135deg, #ff6b6b, #ee5a24);
    border: 2px solid #ff6b6b;
}

.tg-account-type-icon.admin {
    background: linear-gradient(135deg, #8338ec, #3a0ca3);
    border: 2px solid #8338ec;
}

.tg-account-type-icon.regular {
    display: none;
}

/* Специальные стили для эмодзи */
.tg-account-type-icon.verified {
    font-size: 10px;
}

.tg-account-type-icon.official {
    font-size: 9px;
}

.tg-account-type-icon.admin {
    font-size: 8px;
}

/* Chat title with icon */
.tg-chat-title {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
    display: flex;
    align-items: center;
    gap: 4px;
    overflow: hidden;
}

.tg-chat-title .tg-account-type-icon {
    margin-left: 0;
    flex-shrink: 0;
}

/* Dropdown username with icon */
.tg-dropdown-username {
    display: flex;
    align-items: center;
    gap: 4px;
}

.tg-dropdown-username .tg-account-type-icon {
    margin-left: 0;
}

/* Profile name with icon */
.tg-profile-name {
    display: flex;
    align-items: center;
    gap: 4px;
}

.tg-profile-name .tg-account-type-icon {
    margin-left: 0;
}

/* Responsive adjustments */
@media (max-width: 600px) {
    .tg-account-type-icon {
        width: 16px;
        height: 16px;
        font-size: 10px;
    }
}

@media (max-width: 400px) {
    .tg-account-type-icon {
        width: 14px;
        height: 14px;
        font-size: 9px;
    }
}

/* === Stories Bar === */
.tg-stories-bar {
    width: 100%;
    box-sizing: border-box;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 18px;
    padding: 12px 8px 8px 8px;
    overflow-x: auto;
    background: var(--bg-primary);
    border-bottom: 1.5px solid var(--border-color);
    min-height: 72px;
    max-width: 100vw;
    scrollbar-width: thin;
    scrollbar-color: var(--accent-color) var(--bg-secondary);
    transition: background-color 0.3s, border-color 0.3s;
}
.hidden { display: none !important; }
.tg-story-avatar {
    position: relative;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    overflow: hidden;
    border: 2.5px solid var(--accent-color);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.tg-story-avatar.me {
    border-color: var(--accent-color);
}
.tg-story-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}
.tg-story-count {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--accent-color);
    color: #fff;
    font-size: 0.85em;
    font-weight: 600;
    border-radius: 50%;
    min-width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(0,0,0,0.13);
    border: 2px solid #fff;
    z-index: 2;
}
.tg-story-add {
    position: absolute;
    bottom: -4px;
    right: -4px;
    background: var(--accent-color);
    color: #fff;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1em;
    font-weight: 700;
    border: 2px solid #fff;
    box-shadow: 0 2px 6px rgba(0,0,0,0.13);
    cursor: pointer;
    z-index: 2;
    transition: background 0.2s;
}
.tg-story-add:hover {
    background: var(--accent-color);
}

.tg-stories-btn {
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3em;
    background: var(--bg-tertiary);
    color: var(--accent-color);
    border: none;
    transition: background 0.2s, color 0.2s;
    margin-right: 6px;
}
.tg-stories-btn:hover {
    background: var(--accent-color);
    color: #fff;
}

/* === STORIES MODALS MODERN === */
.tg-story-upload-modal, .tg-story-view-modal {
    max-width: 420px;
    border-radius: 18px;
    overflow: visible;
    background: var(--bg-primary);
    box-shadow: 0 8px 32px rgba(0,0,0,0.25);
    animation: fadeInStoryModal 0.25s cubic-bezier(.4,0,.2,1);
}
@keyframes fadeInStoryModal {
    from { opacity: 0; transform: scale(0.97); }
    to { opacity: 1; transform: scale(1); }
}
.tg-story-drop-area {
    border: 2px dashed var(--accent-color);
    border-radius: 14px;
    padding: 32px 16px;
    text-align: center;
    background: var(--bg-secondary);
    cursor: pointer;
    margin-bottom: 16px;
    transition: border-color 0.2s, background 0.2s;
}
.tg-story-drop-area.dragover {
    border-color: var(--accent-color);
    background: #e6fbe6;
}
.tg-story-drop-icon {
    font-size: 2.5em;
    color: var(--accent-color);
    margin-bottom: 8px;
}
.tg-story-drop-text {
    color: var(--text-secondary);
    font-size: 1.1em;
}
.tg-story-file-label {
    color: var(--accent-color);
    text-decoration: underline;
    cursor: pointer;
}
.tg-story-preview {
    margin-top: 10px;
    text-align: center;
}
.tg-story-preview img, .tg-story-preview video {
    max-width: 100%;
    max-height: 260px;
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.10);
}
.tg-story-upload-btn {
    background: var(--accent-color);
    color: #fff;
    font-weight: 600;
    border-radius: 8px;
    font-size: 1.1em;
    padding: 10px 28px;
    transition: background 0.2s;
}
.tg-story-upload-btn:hover {
    background: var(--accent-color);
}
.tg-story-view-modal {
    background: #181c23;
    color: #fff;
    border-radius: 18px;
    max-width: 420px;
    min-width: 320px;
    padding: 0;
    overflow: visible;
    box-shadow: 0 8px 32px rgba(0,0,0,0.32);
}
.tg-story-view-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 18px 18px 8px 18px;
    background: transparent;
    position: relative;
}
.tg-story-view-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
}
.tg-story-view-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}
.tg-story-view-username {
    font-weight: 600;
    font-size: 1.1em;
    color: #fff;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.tg-story-progress-bar {
    width: 100%;
    height: 4px;
    background: #23272e;
    border-radius: 2px;
    margin: 0 0 8px 0;
    overflow: hidden;
    position: relative;
}
.tg-story-progress {
    height: 100%;
    background: var(--accent-color);
    width: 0%;
    transition: width 0.2s linear;
}
.tg-story-view-content-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    min-height: 320px;
    border-radius: 0 0 18px 18px;
    padding: 0 0 18px 0;
}
.tg-story-view-content {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 320px;
    min-width: 0;
    z-index: 2;
}
.tg-story-view-content img, .tg-story-view-content video {
    max-width: 100%;
    max-height: 320px;
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.10);
    background: #000;
}
.tg-story-arrow {
    background: rgba(0,0,0,0.18);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 38px;
    height: 38px;
    font-size: 1.5em;
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 3;
    cursor: pointer;
    transition: background 0.18s;
    opacity: 0.85;
}
.tg-story-arrow-left { left: 10px; }
.tg-story-arrow-right { right: 10px; }
.tg-story-arrow:hover { background: var(--accent-color); color: #fff; opacity: 1; }