:root {
    --tg-blue: #2AABEE;
    --tg-blue-dark: #229ED9;
    --tg-accent: #3390EC;
    --tg-bg-app: #E6EBF0;
    --tg-bg-sidebar: #FFFFFF;
    --tg-bubble-in: #FFFFFF;
    --tg-bubble-out: var(--tg-tint);
    --tg-bubble-out-border: var(--tg-tint-strong);
    --tg-text: #1C1F24;
    --tg-text-muted: #8A97A3;
    --tg-border: #E3E7EB;
    --tg-danger: #E53E3E;
    --tg-link: var(--tg-accent);
    /* Soft accent-tinted backgrounds (pinned banner, player bar, outgoing
       bubble, etc.) — computed from whichever accent + theme is active
       instead of a hardcoded pastel, so every accent/theme combination
       stays legible and coherent instead of clashing. */
    --tg-tint: color-mix(in srgb, var(--tg-accent) 10%, white);
    --tg-tint-strong: color-mix(in srgb, var(--tg-accent) 30%, white);
    --font-main: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font-main);
    color: var(--tg-text);
    background: var(--tg-bg-app);
    height: 100vh;
    overflow: hidden;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; margin: 0; }

/* ---------- Auth screens ---------- */
.auth-screen {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(160deg, var(--tg-blue) 0%, var(--tg-blue-dark) 100%);
}
.auth-card {
    background: #fff;
    padding: 40px 36px;
    border-radius: 16px;
    width: 360px;
    max-width: 92vw;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    text-align: center;
}
.auth-logo {
    width: 64px; height: 64px; margin: 0 auto 16px;
    border-radius: 50%;
    background: linear-gradient(160deg, var(--tg-blue) 0%, var(--tg-blue-dark) 100%);
    color: #fff; font-size: 28px; display: flex; align-items: center; justify-content: center;
}
.auth-card h1 { font-size: 20px; margin: 0 0 4px; }
.auth-subtitle { color: var(--tg-text-muted); font-size: 14px; margin: 0 0 24px; }
.auth-card form { text-align: left; }
.auth-card label { display: block; margin-bottom: 14px; }
.auth-card label span { display: block; font-size: 12px; color: var(--tg-text-muted); margin-bottom: 4px; }
.auth-card input[type="text"],
.auth-card input[type="password"],
.auth-card input[type="email"] {
    width: 100%; padding: 10px 12px; border: 1px solid var(--tg-border);
    border-radius: 8px; font-size: 14px; outline: none;
}
.auth-card input:focus { border-color: var(--tg-accent); }
.field-error, .auth-error { color: var(--tg-danger); font-size: 12px; margin-top: 4px; }
.btn-primary {
    width: 100%; padding: 12px; border: none; border-radius: 8px;
    background: var(--tg-accent); color: #fff; font-size: 15px; font-weight: 600; margin-top: 8px;
}
.btn-primary:hover { background: var(--tg-blue-dark); }
.auth-footer { margin-top: 18px; font-size: 13px; color: var(--tg-text-muted); }
.auth-footer a { color: var(--tg-accent); font-weight: 600; }

/* ---------- App shell ---------- */
.app-shell { display: flex; height: 100vh; }

.sidebar {
    width: 340px; flex-shrink: 0; background: var(--tg-bg-sidebar);
    border-right: 1px solid var(--tg-border);
    display: flex; flex-direction: column;
}
.sidebar-header {
    display: flex; align-items: center; gap: 10px; padding: 12px;
    border-bottom: 1px solid var(--tg-border);
}
.my-avatar, .chat-avatar {
    width: 44px; height: 44px; border-radius: 50%; overflow: hidden; flex-shrink: 0;
    background: var(--tg-accent); color: #fff; display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 16px;
}
.my-avatar img, .chat-avatar img { width: 100%; height: 100%; object-fit: cover; }
.sidebar-search { flex: 1; position: relative; }
.sidebar-search input {
    width: 100%; padding: 9px 12px; border: none; background: var(--tg-bg-app);
    border-radius: 18px; font-size: 14px; outline: none;
}
.search-results {
    position: absolute; top: 42px; left: 0; right: 0; background: #fff;
    border: 1px solid var(--tg-border); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    max-height: 300px; overflow-y: auto; z-index: 20; display: none;
}
.search-results.visible { display: block; }
.search-result-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; }
.search-result-item:hover { background: var(--tg-bg-app); }
.icon-btn {
    width: 36px; height: 36px; border-radius: 50%; border: none; background: transparent;
    display: flex; align-items: center; justify-content: center; font-size: 18px; color: var(--tg-text-muted);
}
.icon-btn:hover { background: var(--tg-bg-app); }

.chat-list { flex: 1; overflow-y: auto; scrollbar-width: none; -ms-overflow-style: none; }
.chat-list::-webkit-scrollbar { display: none; }
.chat-list-item {
    display: flex; gap: 10px; padding: 10px 12px; border-bottom: 1px solid #F2F4F6;
}
.chat-list-item:hover, .chat-list-item.active { background: var(--tg-bg-app); }
.chat-list-info { flex: 1; min-width: 0; }
.chat-list-top { display: flex; justify-content: space-between; align-items: baseline; }
.chat-title { font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-time { font-size: 12px; color: var(--tg-text-muted); flex-shrink: 0; margin-left: 6px; }
.chat-list-bottom {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.chat-preview {
    font-size: 13px; color: var(--tg-text-muted);
    display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0;
}
.unread-badge {
    background: var(--tg-accent); color: #fff; font-size: 11.5px; font-weight: 700;
    border-radius: 10px; min-width: 18px; height: 18px; padding: 0 5px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
}
.empty-hint { padding: 24px; color: var(--tg-text-muted); font-size: 13px; text-align: center; }

/* ---------- Chat room ---------- */
.chat-empty-state, .chat-room { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
.chat-empty-state {
    align-items: center; justify-content: center; color: var(--tg-text-muted); text-align: center;
}
.empty-illustration {
    width: 80px; height: 80px; border-radius: 50%; margin-bottom: 16px;
    background: linear-gradient(160deg, var(--tg-blue) 0%, var(--tg-blue-dark) 100%);
    color: #fff; font-size: 36px; display: flex; align-items: center; justify-content: center;
}

.chat-room-header {
    display: flex; align-items: center; gap: 12px; padding: 10px 16px;
    background: var(--tg-bg-sidebar); border-bottom: 1px solid var(--tg-border);
}
.chat-room-title { flex: 1; min-width: 0; }
.chat-status { font-size: 12.5px; color: var(--tg-text-muted); }
.call-btn { font-size: 18px; }

.messages {
    flex: 1; overflow-y: auto; padding: 16px 8%;
    display: flex; flex-direction: column; gap: 6px;
}
.message-row { display: flex; }
.message-row.outgoing { justify-content: flex-end; }
.message-row.incoming { justify-content: flex-start; }
.bubble {
    max-width: 55%; padding: 8px 12px; border-radius: 14px;
    background: var(--tg-bubble-in); box-shadow: 0 1px 1px rgba(0,0,0,0.05);
    position: relative; box-sizing: border-box; overflow-wrap: anywhere;
}
.message-row.outgoing .bubble {
    background: var(--tg-bubble-out); border: 1px solid var(--tg-bubble-out-border);
}
.bubble-sender { font-size: 12.5px; font-weight: 700; color: var(--tg-accent); margin-bottom: 2px; }
.bubble-text { font-size: 14.5px; line-height: 1.4; white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere; }
.bubble-image { max-width: 260px; width: 100%; border-radius: 10px; display: block; margin-bottom: 4px; }
.bubble-file {
    font-size: 14px; color: var(--tg-accent); font-weight: 600; display: inline-block;
    max-width: 100%; word-break: break-all; overflow-wrap: anywhere;
}
.bubble-meta {
    display: flex; justify-content: flex-end; gap: 4px; margin-top: 2px;
    font-size: 11px; color: var(--tg-text-muted);
}
.read-tick { color: var(--tg-text-muted); }
.read-tick.read { color: var(--tg-accent); }

.typing-indicator {
    padding: 0 8% 4px; font-size: 12.5px; color: var(--tg-text-muted); font-style: italic;
}

.message-input-bar {
    display: flex; flex-direction: column; background: var(--tg-bg-sidebar); border-top: 1px solid var(--tg-border);
}
.message-input-row {
    display: flex; align-items: center; gap: 8px; padding: 10px 16px;
}
.message-input-bar input[type="text"] {
    flex: 1; border: none; background: var(--tg-bg-app); border-radius: 20px;
    padding: 10px 16px; font-size: 14.5px; outline: none;
}
.text-input-wrapper { position: relative; flex: 1; display: flex; min-width: 0; }

/* ---------- Live voice-recording waveform (reacts to the actual
   microphone input in real time) — a normal part of the input container's
   own layout, sitting in its own row above the icons/input row (pushes
   the layout down), not an absolutely-positioned overlay floating on top
   of the input or the messages behind it. ---------- */
.voice-live-waveform {
    display: flex; align-items: center; justify-content: center; gap: 2px;
    height: 44px; margin: 8px 16px 0; padding: 0 10px;
    background: var(--tg-tint); border: 1px solid var(--tg-tint-strong); border-radius: 12px;
    overflow: hidden;
}
.voice-live-waveform[hidden] { display: none; }
.voice-live-waveform .live-bar {
    flex: 1; min-width: 2px; max-width: 5px; height: 10%; max-height: 100%;
    background: var(--tg-accent); border-radius: 2px; align-self: center;
}
.send-btn { background: var(--tg-accent); color: #fff; }
.send-btn:hover { background: var(--tg-blue-dark); }
.voice-btn-wrapper { position: relative; display: flex; }
.mic-icon { width: 22px; height: 22px; color: var(--tg-text-muted); }
#voice-btn.recording { background: var(--tg-tint); }
#voice-btn.recording .mic-icon { color: var(--tg-accent); animation: mic-pulse 1.4s ease-in-out infinite; }
@keyframes mic-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.55; }
}
.voice-record-timer {
    position: absolute; bottom: 100%; margin-bottom: 8px; left: 50%; transform: translateX(-50%);
    background: var(--tg-accent); color: #fff; font-size: 11px; font-weight: 700;
    padding: 2px 7px; border-radius: 10px; white-space: nowrap; pointer-events: none;
}
.voice-record-timer[hidden] { display: none; }

/* ---------- Floating call window (not a full-screen blocking modal) ---------- */
.call-overlay {
    position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 100;
}
.call-overlay[hidden] { display: none; }
.call-window {
    position: relative; width: 300px; padding: 30px 20px 24px; border-radius: 20px;
    text-align: center; color: #fff;
    background: rgba(28, 34, 42, 0.6);
    backdrop-filter: blur(24px) saturate(140%);
    -webkit-backdrop-filter: blur(24px) saturate(140%);
    border: 1px solid rgba(255,255,255,0.14);
    box-shadow: 0 24px 60px rgba(0,0,0,0.4);
    cursor: grab;
    touch-action: none;
}
.call-window.dragging { cursor: grabbing; user-select: none; }
.call-minimize-btn {
    position: absolute; top: 10px; right: 10px; width: 28px; height: 28px; border-radius: 50%;
    border: none; background: rgba(255,255,255,0.12); color: #fff; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
.call-minimize-btn:hover { background: rgba(255,255,255,0.22); }
.call-minimize-btn svg { width: 14px; height: 14px; fill: currentColor; }

.call-avatar {
    width: 88px; height: 88px; border-radius: 50%; margin: 0 auto 14px; overflow: hidden;
    background: linear-gradient(160deg, var(--tg-blue) 0%, var(--tg-blue-dark) 100%);
    display: flex; align-items: center; justify-content: center; font-size: 34px; font-weight: 700; color: #fff;
}
.call-avatar img { width: 100%; height: 100%; object-fit: cover; }
.call-peer-name { font-size: 18px; font-weight: 600; margin-bottom: 4px; }
.call-state {
    color: rgba(255,255,255,0.72); font-size: 13.5px; margin-bottom: 24px; min-height: 18px;
}
.call-state.call-timer { color: #34C759; font-weight: 700; font-variant-numeric: tabular-nums; font-size: 15px; }

.call-actions { display: flex; gap: 18px; justify-content: center; }
.call-action-btn {
    width: 54px; height: 54px; border-radius: 50%; border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center; color: #fff; transition: transform 0.1s, background 0.15s;
}
.call-action-btn:active { transform: scale(0.92); }
.call-action-btn svg { width: 22px; height: 22px; fill: currentColor; }
.call-action-btn.mute { background: rgba(255,255,255,0.14); }
.call-action-btn.mute.active { background: #fff; color: #1C1F24; }
.call-action-btn.accept { background: #34C759; }
.call-action-btn.decline .call-icon-hangup { transform: rotate(135deg); transform-origin: center; }
.call-action-btn.decline { background: var(--tg-danger); }

/* ---------- Minimized call bar — sits in the sidebar's column, under the
   tabs, so the rest of the chats stay usable while a call continues. ---------- */
.call-mini-bar {
    position: sticky; top: 0; z-index: 5; margin: 8px; width: auto;
    display: flex; align-items: center; gap: 8px; padding: 8px 10px;
    background: rgba(24, 30, 38, 0.65);
    backdrop-filter: blur(18px) saturate(140%);
    -webkit-backdrop-filter: blur(18px) saturate(140%);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 14px; box-shadow: 0 10px 28px rgba(0,0,0,0.3); color: #fff;
}
.call-mini-bar[hidden] { display: none; }
.call-mini-expand {
    flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px;
    background: none; border: none; color: #fff; cursor: pointer; padding: 4px;
}
.call-mini-dot { width: 8px; height: 8px; border-radius: 50%; background: #34C759; flex-shrink: 0; animation: mic-pulse 1.4s ease-in-out infinite; }
.call-mini-timer { color: #34C759; font-weight: 700; font-variant-numeric: tabular-nums; font-size: 14px; }
.call-mini-btn {
    width: 32px; height: 32px; border-radius: 50%; border: none; cursor: pointer; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center; color: #fff;
}
.call-mini-btn svg { width: 15px; height: 15px; fill: currentColor; }
.call-mini-btn.mute { background: rgba(255,255,255,0.14); }
.call-mini-btn.mute.active { background: #fff; color: #1C1F24; }
.call-mini-btn.end { background: var(--tg-danger); }
.call-mini-btn.end .call-icon-hangup { transform: rotate(135deg); transform-origin: center; }

/* ==========================================================================
   Mobile & tablet adaptation (phones and narrow/portrait tablets)
   ========================================================================== */
.mobile-back-btn { display: none; }

@media (max-width: 800px) {
    .app-shell { position: relative; overflow: hidden; }

    .call-overlay { top: 60px; left: 12px; right: 12px; transform: none; }
    .call-window { width: 100%; }
    .call-confirm-card { width: 100%; }
    .call-mini-bar {
        position: fixed !important; left: 12px; right: 12px; top: 12px; width: auto; margin: 0;
    }

    /* Single-pane navigation: on chat_room.html (an actual chat is open)
       the chat takes the full screen and the sidebar is hidden entirely —
       not just overlaid, so nothing steals touch input from the chat.
       Going back is a normal Django link (chats:chat_list), no client
       routing needed. */
    .app-shell:has(.chat-room) .sidebar { display: none; }
    .app-shell:has(.chat-room) .chat-room { width: 100%; }
    .mobile-back-btn { display: flex; }

    /* create_group.html reuses .chat-empty-state as a generic "single
       card" layout (like an auth page) — that's real content, so it
       takes over the full screen the same way an open chat does. */
    .app-shell:has(.chat-empty-state .create-group-card) .sidebar { display: none; }
    .app-shell:has(.chat-empty-state .create-group-card) .chat-empty-state { width: 100%; }

    /* Plain chat_list.html empty state (nothing selected yet) has nothing
       useful to show on a narrow screen — the chat list underneath it
       *is* the useful screen, so just hide the placeholder illustration. */
    .chat-empty-state:not(:has(.create-group-card)) { display: none; }

    .sidebar { width: 100%; }
    .messages { padding: 12px; }
    .bubble { max-width: 82%; }

    /* Fixed-width popups/modals: cap everything to the viewport instead of
       overflowing horizontally on a narrow screen. */
    .modal-card, .search-card, .comments-card, .group-info-card,
    .category-manage-card, .profile-card, .date-jump-calendar,
    .category-picker, .context-menu, .header-menu-dropdown, .emoji-panel, .hamburger-dropdown {
        max-width: 94vw;
    }
    .lightbox-body .pdf-frame, .docx-preview-wrap { width: 94vw; }

    /* The global player bar and message compose bar can get cramped —
       let their contents wrap/shrink instead of forcing horizontal scroll. */
    .global-audio-bar { flex-wrap: wrap; padding: 8px 12px; }
    .global-audio-info { min-width: 140px; }
    .message-input-row { padding: 8px; gap: 4px; }

    /* Vertical sidebar-tabs mode makes little sense on a screen this
       narrow (the chat list itself is already full-width) — force
       horizontal regardless of the saved preference. */
    .sidebar-body.vertical-tabs { flex-direction: column; }
    .sidebar-body.vertical-tabs .sidebar-tabs-row {
        flex-direction: row; width: auto; height: auto; border-right: none;
        border-bottom: 1px solid var(--tg-border); overflow-y: visible;
    }
    .sidebar-body.vertical-tabs .sidebar-tabs {
        flex-direction: row; overflow-x: auto; overflow-y: visible; max-height: none; padding: 8px 10px;
    }
    .sidebar-body.vertical-tabs .sidebar-tabs .sidebar-tab { width: auto; text-align: center; }
    .sidebar-body.vertical-tabs .sidebar-tabs-toolbar { flex-direction: row; border-top: none; }

    /* Touch-friendlier tap targets. */
    .icon-btn { min-width: 38px; min-height: 38px; }
    .chat-item-action-btn { padding: 6px; }
}

@media (max-width: 420px) {
    .bubble { max-width: 88%; }
    .modal-card, .search-card, .comments-card, .group-info-card,
    .category-manage-card, .profile-card { width: 100%; }
    .audio-compact, .doc-preview { width: 100%; }
    .auth-card { padding: 28px 20px; }
}

/* ---------- Header "more" menu, blocked banner ---------- */
.header-menu { position: relative; }
.header-menu-dropdown {
    position: absolute; top: 40px; right: 0; background: #fff;
    border: 1px solid var(--tg-border); border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.12); min-width: 180px; z-index: 30; overflow: hidden;
}
.header-menu-dropdown a {
    display: block; padding: 10px 14px; font-size: 14px; color: var(--tg-text);
}
.header-menu-dropdown a:hover { background: var(--tg-bg-app); }
.blocked-banner {
    background: #FFF4F4; color: var(--tg-danger); padding: 8px 16px; font-size: 13px;
    border-bottom: 1px solid #FADCDC;
}
.blocked-banner a { font-weight: 600; text-decoration: underline; }

/* ---------- Emoji picker ---------- */
.emoji-picker-wrapper { position: relative; }
.emoji-panel {
    position: absolute; bottom: 46px; left: 0; background: #fff;
    border: 1px solid var(--tg-border); border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,0.15);
    padding: 8px; display: flex; flex-direction: column; gap: 4px; z-index: 30;
    width: 280px; max-height: 340px; overflow-y: auto;
    scrollbar-width: none; -ms-overflow-style: none;
}
.emoji-panel::-webkit-scrollbar { display: none; }
.emoji-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.emoji-panel-label { font-size: 11px; color: var(--tg-text-muted); padding: 2px 4px; }
.emoji-panel-divider { border-top: 1px solid var(--tg-border); margin: 4px 0; }
.emoji-option {
    border: none; background: transparent; font-size: 20px; padding: 4px; border-radius: 6px; cursor: pointer;
}
.emoji-option:hover { background: var(--tg-bg-app); }
.emoji-panel[hidden] { display: none; }

/* ---------- Links inside message bubbles ---------- */

/* ---------- Cookie consent banner ---------- */
.cookie-banner {
    position: fixed; bottom: 0; left: 0; right: 0; background: #1C1F24; color: #fff;
    padding: 14px 20px; display: flex; align-items: center; justify-content: space-between;
    gap: 16px; z-index: 200; font-size: 13.5px; flex-wrap: wrap;
}
.cookie-banner p { margin: 0; max-width: 640px; }
.cookie-banner button {
    background: var(--tg-accent); color: #fff; border: none; border-radius: 8px;
    padding: 8px 18px; font-size: 13.5px; font-weight: 600; flex-shrink: 0;
}
.cookie-banner button:hover { background: var(--tg-blue-dark); }

/* ---------- Captcha / lockout on the login form ---------- */
.auth-blocked { color: var(--tg-danger); font-size: 13px; margin-bottom: 12px; }

/* ---------- Context menu (message / media / link-email-phone action sheets) ---------- */
.context-menu {
    position: fixed; background: #fff; border-radius: 12px; box-shadow: 0 12px 32px rgba(0,0,0,0.2);
    min-width: 200px; max-width: 280px; z-index: 500; overflow-y: auto; padding: 6px 0;
}
.context-menu[hidden] { display: none; }
.context-menu-heading {
    padding: 10px 16px; font-size: 12.5px; color: var(--tg-text-muted); border-bottom: 1px solid var(--tg-border);
    margin-bottom: 4px;
}
.context-menu-item {
    display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 10px 16px;
    border: none; background: none; font-size: 14.5px; color: var(--tg-text); cursor: pointer;
}
.context-menu-item:hover { background: var(--tg-bg-app); }
.context-menu-item.danger { color: var(--tg-danger); }
.context-menu-item svg { width: 18px; height: 18px; flex-shrink: 0; fill: var(--tg-accent); }
.context-menu-item.danger svg { fill: var(--tg-danger); }

/* ---------- Selection mode ---------- */
.header-actions { display: flex; align-items: center; gap: 4px; }
.header-actions[hidden] { display: none; }
.selection-toolbar { gap: 10px; }
.selection-count { font-weight: 600; margin-right: 6px; min-width: 16px; text-align: center; }
.select-checkbox { margin-right: 4px; align-self: center; }
.select-checkbox[hidden] { display: none; }
.message-row { align-items: center; gap: 6px; }
.message-row.selected .bubble { outline: 2px solid var(--tg-accent); }
.messages[data-selection-mode="1"] .message-row { cursor: pointer; }

/* ---------- Reply / quote preview ---------- */
.reply-quote {
    border-left: 3px solid var(--tg-accent); padding: 2px 8px; margin-bottom: 4px; font-size: 13px;
    background: var(--tg-tint); border-radius: 4px;
}
.reply-quote { cursor: pointer; }
.reply-quote-sender { display: block; font-weight: 700; color: var(--tg-accent); font-size: 12.5px; }
.reply-quote-text { color: var(--tg-text-muted); }
.forwarded-badge { font-size: 12px; font-style: italic; color: var(--tg-text-muted); margin-bottom: 2px; }

@keyframes bubble-flash {
    0%, 40% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--tg-accent) 75%, transparent); }
    20% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--tg-accent) 35%, transparent); }
    100% { box-shadow: 0 1px 1px rgba(0,0,0,0.05); }
}
.bubble.highlight-flash { animation: bubble-flash 1.8s ease; }

.reply-preview-bar {
    display: flex; align-items: center; gap: 10px; padding: 8px 16px; background: var(--tg-bg-app);
    border-top: 1px solid var(--tg-border); font-size: 13.5px;
}
.reply-preview-bar[hidden] { display: none; }
.reply-preview-body { flex: 1; color: var(--tg-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Reactions ---------- */
.bubble-reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.reaction-chip {
    background: var(--tg-bg-app); border-radius: 12px; padding: 2px 8px; font-size: 12.5px; cursor: pointer;
    border: 1px solid transparent;
}
.reaction-chip.mine { border-color: var(--tg-accent); background: var(--tg-tint); }
.reaction-chip:hover { filter: brightness(0.97); }
.reaction-picker[hidden] { display: none; }
.reaction-picker { position: fixed; z-index: 510; }

/* ---------- Detected links (URL / email / phone) inside message text ---------- */
.bubble-text .detected-link { color: var(--tg-link); text-decoration: underline; cursor: pointer; word-break: break-word; }

/* ---------- Pinned message banner ---------- */
.pinned-banner {
    display: flex; align-items: center; gap: 10px; padding: 8px 16px; background: var(--tg-tint);
    border-bottom: 1px solid var(--tg-tint-strong); font-size: 13.5px;
}
.pinned-banner[hidden] { display: none; }
.pinned-body { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.pinned-close { border: none; background: none; cursor: pointer; color: var(--tg-text-muted); font-size: 14px; }
.pinned-undo {
    display: flex; align-items: center; gap: 10px; padding: 8px 16px; background: #1C1F24; color: #fff; font-size: 13px;
}
.pinned-undo[hidden] { display: none; }
.pinned-undo button {
    background: var(--tg-accent); border: none; color: #fff; border-radius: 6px; padding: 5px 12px;
    cursor: pointer; font-family: inherit; font-size: 13px; line-height: 1.4; flex-shrink: 0;
}

/* ---------- Modals (forward / delete) ---------- */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(20,26,33,0.5); display: flex; align-items: center;
    justify-content: center; z-index: 400;
}
.modal-overlay[hidden] { display: none; }
.modal-card { background: #fff; border-radius: 14px; padding: 20px; width: 320px; max-width: 90vw; }
.modal-card h3 { margin: 0 0 14px; font-size: 17px; }
.forward-chat-list { max-height: 280px; overflow-y: auto; margin-bottom: 16px; }
.forward-chat-item { display: flex; align-items: center; gap: 10px; padding: 8px 4px; font-size: 14px; }
.forward-chat-item .forward-chat-avatar { cursor: pointer; width: 38px; height: 38px; position: relative; }
.forward-chat-info { flex: 1; min-width: 0; cursor: pointer; text-align: left; }
.forward-chat-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.forward-chat-status { font-size: 12px; color: var(--tg-text-muted); }
.forward-chat-online { color: #34C759; }
.forward-chat-avatar::after {
    content: ""; position: absolute; bottom: 0; right: 0; width: 10px; height: 10px;
    border-radius: 50%; background: #34C759; border: 2px solid var(--tg-bg-sidebar); display: none;
}
.forward-chat-item:has(.forward-chat-online) .forward-chat-avatar::after { display: block; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
.modal-actions-column { flex-direction: column; }
.modal-actions-column button { width: 100%; }
.btn-secondary {
    padding: 10px 16px; border-radius: 8px; border: 1px solid var(--tg-border); background: #fff;
    font-size: 14px; cursor: pointer; margin-bottom: 6px;
}
.btn-secondary:hover { background: var(--tg-bg-app); }

/* ---------- Media lightbox ---------- */
.lightbox-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.9); z-index: 600;
    display: flex; align-items: center; justify-content: center;
}
.lightbox-overlay[hidden] { display: none; }
.lightbox-body img, .lightbox-body video { max-width: 90vw; max-height: 90vh; }
.lightbox-body audio { width: 60vw; max-width: 480px; }
.lightbox-body .pdf-frame { width: 90vw; height: 90vh; max-width: 900px; border: none; background: #fff; border-radius: 6px; }
.docx-preview-wrap {
    width: 90vw; height: 90vh; max-width: 800px; background: #fff; border-radius: 6px;
    overflow-y: auto; padding: 32px; text-align: left; color: #1C1F24;
}
.docx-preview-body { max-width: 700px; margin: 0 auto; line-height: 1.5; }
.docx-preview-body img { max-width: 100%; }
.docx-preview-wrap .empty-hint { color: var(--tg-text-muted); }
.lightbox-close {
    position: absolute; top: 20px; right: 24px; background: rgba(255,255,255,0.15); color: #fff;
    border: none; border-radius: 50%; width: 40px; height: 40px; font-size: 18px; cursor: pointer;
}

/* ---------- Video attachments in bubbles ---------- */
.bubble-video { max-width: 260px; width: 100%; border-radius: 10px; display: block; margin-bottom: 4px; }

/* =====================================================================
   User-customizable appearance — applied via body classes injected by
   apps/accounts/context_processors.py (theme-*, accent-*, font-family-*,
   font-*, density-*). Higher-specificity selectors (2 classes) are used
   deliberately so they override the base rules above regardless of
   source order, without needing !important.
   ===================================================================== */

/* ---------- Theme: dark ---------- */
body.theme-dark {
    --tg-bg-app: #0F1419;
    --tg-bg-sidebar: #17212B;
    --tg-bubble-in: #232E3C;
    --tg-bubble-out: var(--tg-tint);
    --tg-bubble-out-border: var(--tg-tint-strong);
    --tg-text: #FFFFFF;
    --tg-text-muted: #8AA0B4;
    --tg-border: #0F1419;
    --tg-link: #7EC8FF;
    --tg-tint: color-mix(in srgb, var(--tg-accent) 22%, #17212B);
    --tg-tint-strong: color-mix(in srgb, var(--tg-accent) 40%, #17212B);
    color-scheme: dark;
}
body.theme-dark .btn-secondary { background: #232E3C; color: var(--tg-text); border-color: #0F1419; }
body.theme-dark .modal-card, body.theme-dark .context-menu, body.theme-dark .search-results,
body.theme-dark .header-menu-dropdown, body.theme-dark .emoji-panel { background: #17212B; color: var(--tg-text); }
body.theme-dark input[type="text"], body.theme-dark input[type="password"], body.theme-dark input[type="email"],
body.theme-dark textarea { background: #0F1419; color: var(--tg-text); border-color: #263340; }
body.theme-dark .auth-card, body.theme-dark .comments-post-preview, body.theme-dark .comment-body,
body.theme-dark .profile-card-bio, body.theme-dark .profile-card-phone { background: #17212B; color: var(--tg-text); }

/* Brighter links/email/phone — the default accent blue reads a bit muted
   against the dark background, so dark mode gets its own lighter shade. */
body.theme-dark .detected-link,
body.theme-dark .auth-footer a { color: var(--tg-link); }

/* Custom scrollbars follow the accent color instead of the browser default
   (which stays light-grey even on a dark background). */
body.theme-dark { scrollbar-color: var(--tg-accent) #17212B; }
body.theme-dark ::-webkit-scrollbar { width: 10px; height: 10px; }
body.theme-dark ::-webkit-scrollbar-track { background: #17212B; }
body.theme-dark ::-webkit-scrollbar-thumb { background-color: var(--tg-accent); border-radius: 6px; border: 2px solid #17212B; }
body.theme-dark ::-webkit-scrollbar-thumb:hover { background-color: var(--tg-blue-dark); }

/* ---------- Accent color ---------- */
body.accent-green { --tg-accent: #34C759; --tg-blue: #34C759; --tg-blue-dark: #248A3D; }
body.accent-purple { --tg-accent: #8E44AD; --tg-blue: #8E44AD; --tg-blue-dark: #6C3483; }
body.accent-orange { --tg-accent: #FF9500; --tg-blue: #FF9500; --tg-blue-dark: #CC7A00; }

/* ---------- Font family ---------- */
body.font-family-serif { --font-main: Georgia, "Times New Roman", serif; }
body.font-family-mono { --font-main: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace; }
body.font-family-rounded { --font-main: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, sans-serif; }

/* ---------- Font size (higher-specificity overrides of the fixed px defaults) ---------- */
body.font-small .bubble-text,
body.font-small .message-input-bar input[type="text"],
body.font-small .chat-preview { font-size: 13px; }
body.font-large .bubble-text,
body.font-large .message-input-bar input[type="text"],
body.font-large .chat-preview { font-size: 16.5px; }

/* ---------- Density (bubble padding / corner radius / list spacing) ---------- */
body.density-compact .bubble { padding: 5px 9px; border-radius: 10px; }
body.density-compact .messages { gap: 3px; }
body.density-spacious .bubble { padding: 12px 16px; border-radius: 18px; }
body.density-spacious .messages { gap: 10px; }

/* ---------- Appearance / background settings pages ---------- */
.appearance-card { width: 440px; max-width: 92vw; text-align: left; }
.appearance-section { margin-bottom: 20px; }
.appearance-label { display: block; font-weight: 600; margin-bottom: 8px; font-size: 13px; color: var(--tg-text-muted); }
.appearance-options { display: flex; flex-wrap: wrap; gap: 12px; }
.appearance-option { display: flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; }
.appearance-swatches { gap: 14px; }
.appearance-swatch {
    width: 38px; height: 38px; border-radius: 50%; cursor: pointer; position: relative;
    border: 2px solid var(--tg-border); background-size: cover; display: inline-block;
}
.appearance-swatch input[type="radio"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; margin: 0; }
.appearance-swatch:has(input:checked) { border-color: var(--tg-text); box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--tg-accent); }
.swatch-blue { background: #3390EC; }
.swatch-green { background: #34C759; }
.swatch-purple { background: #8E44AD; }
.swatch-orange { background: #FF9500; }
.font-preview-serif { font-family: Georgia, serif; }
.font-preview-mono { font-family: monospace; }
.font-preview-rounded { font-family: ui-rounded, -apple-system, sans-serif; }
.background-file-input { margin: 8px 0 0; display: block; }
.background-current-preview { max-width: 140px; border-radius: 8px; margin-top: 10px; display: block; }

/* ---------- Compact inline audio/voice widget (loads into the global player bar) ---------- */
.audio-compact {
    display: flex; align-items: center; gap: 8px; width: 200px; max-width: 100%;
    padding: 4px 2px; margin-bottom: 4px; cursor: pointer;
}
.audio-compact-play {
    border: none; background: var(--tg-accent); color: #fff; border-radius: 50%;
    width: 30px; height: 30px; font-size: 13px; cursor: pointer; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
}
.audio-compact.playing .audio-compact-play { background: var(--tg-blue-dark); }
.audio-compact-meta { min-width: 0; }
.audio-compact-label { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.audio-compact-duration { font-size: 11.5px; color: var(--tg-text-muted); }

/* ---------- Shared control styles (used by the global player bar) ---------- */
.audio-el { display: none; }
.audio-play-btn, .audio-volume-btn {
    border: none; background: var(--tg-accent); color: #fff; border-radius: 50%;
    width: 30px; height: 30px; font-size: 13px; cursor: pointer; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
}
.audio-volume-btn { background: transparent; color: var(--tg-text-muted); width: 22px; height: 22px; font-size: 14px; }
.audio-progress-track {
    flex: 1; min-width: 60px; height: 8px; background: var(--tg-border); border-radius: 4px;
    cursor: pointer; position: relative; margin: 4px 0;
}
.audio-progress-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0%; background: var(--tg-accent); border-radius: 4px; }
.audio-progress-fill::after {
    content: ""; position: absolute; right: -6px; top: 50%; transform: translateY(-50%);
    width: 12px; height: 12px; border-radius: 50%; background: var(--tg-accent);
    box-shadow: 0 1px 3px rgba(0,0,0,0.35);
}
.audio-time { font-size: 11.5px; color: var(--tg-text-muted); flex-shrink: 0; white-space: nowrap; }
.audio-volume-slider { width: 60px; flex-shrink: 0; accent-color: var(--tg-accent); }

/* ---------- Global player bar (Telegram-style, docked under the header / pinned message) ---------- */
.global-audio-bar {
    display: flex; align-items: center; gap: 10px; padding: 8px 16px;
    background: var(--tg-tint); border-bottom: 1px solid var(--tg-tint-strong);
}
.global-audio-bar[hidden] { display: none; }
.global-audio-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.global-audio-title { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.audio-waveform {
    display: flex; align-items: center; gap: 2px; height: 28px; cursor: pointer; padding: 2px 0;
}
.waveform-bar {
    flex: 1; min-width: 2px; max-width: 4px; background: var(--tg-border); border-radius: 2px;
    align-self: center; transition: background-color 0.1s;
}
.waveform-bar.played { background: var(--tg-accent); }
.waveform-loading { font-size: 11.5px; color: var(--tg-text-muted); }

/* ---------- Scroll-to-bottom floating button ---------- */
.scroll-to-bottom-btn {
    position: absolute; bottom: 78px; left: 50%; transform: translateX(-50%);
    background: #fff; border: 1px solid var(--tg-border); border-radius: 50%;
    width: 42px; height: 42px; box-shadow: 0 4px 14px rgba(0,0,0,0.18); cursor: pointer;
    font-size: 18px; color: var(--tg-accent); z-index: 20;
}
.scroll-to-bottom-btn:hover { background: var(--tg-bg-app); }
.scroll-to-bottom-btn[hidden] { display: none; }
.scroll-badge {
    position: absolute; top: -6px; right: -6px; background: var(--tg-accent); color: #fff;
    font-size: 11px; font-weight: 700; border-radius: 10px; min-width: 18px; height: 18px;
    padding: 0 4px; display: flex; align-items: center; justify-content: center;
}
.scroll-badge[hidden] { display: none; }

/* ---------- Logout form (inline, styled like the other header icon buttons) ---------- */
/* ---------- Hamburger menu (Telegram-style, top-left of the sidebar) ---------- */
.hamburger-wrapper { position: relative; }
.hamburger-dropdown {
    position: absolute; top: 44px; left: 0; width: 260px; z-index: 60;
    background: var(--tg-bg-sidebar); border: 1px solid var(--tg-border); border-radius: 12px;
    box-shadow: 0 12px 32px rgba(0,0,0,0.18); padding: 6px 0; overflow: hidden;
}
.hamburger-dropdown[hidden] { display: none; }
.hamburger-profile-row {
    display: flex; align-items: center; gap: 12px; padding: 14px 16px; cursor: pointer;
}
.hamburger-profile-row:hover { background: var(--tg-bg-app); }
.hamburger-profile-row .my-avatar { width: 44px; height: 44px; flex-shrink: 0; }
.hamburger-profile-info { min-width: 0; }
.hamburger-profile-name {
    font-weight: 600; font-size: 15px; color: var(--tg-text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hamburger-profile-sub { font-size: 12.5px; color: var(--tg-accent); }
.hamburger-divider { height: 1px; background: var(--tg-border); margin: 4px 0; }
.hamburger-item {
    display: flex; align-items: center; gap: 14px; width: 100%; padding: 11px 16px;
    font-size: 14.5px; color: var(--tg-text); background: none; border: none;
    cursor: pointer; text-align: left; font-family: inherit;
}
.hamburger-item:hover { background: var(--tg-bg-app); }
.hamburger-item svg { width: 20px; height: 20px; fill: var(--tg-accent); flex-shrink: 0; }
.hamburger-item.hamburger-logout { color: var(--tg-danger); }
.hamburger-item.hamburger-logout svg { fill: var(--tg-danger); }
.hamburger-logout-form { margin: 0; }

/* ---------- Registration invite-only note ---------- */
.auth-note {
    background: var(--tg-tint); border: 1px solid var(--tg-tint-strong); border-radius: 8px;
    padding: 10px 12px; font-size: 13px; color: var(--tg-text); margin-bottom: 16px;
}

/* ---------- Clickable header avatar/name (opens profile card) ---------- */
.chat-avatar.clickable, .chat-room-title.clickable { cursor: pointer; }

/* ---------- User profile card ---------- */
.profile-card { text-align: center; position: relative; width: 320px; }
.profile-card-close {
    position: absolute; top: 10px; right: 10px; border: none; background: none;
    color: var(--tg-text-muted); font-size: 16px; cursor: pointer;
}
.profile-card-avatar {
    width: 96px; height: 96px; border-radius: 50%; margin: 0 auto 12px; overflow: hidden;
    background: var(--tg-accent); color: #fff; display: flex; align-items: center; justify-content: center;
    font-size: 34px; font-weight: 700;
}
.profile-card-avatar img { width: 100%; height: 100%; object-fit: cover; }
.profile-card-name { font-size: 18px; font-weight: 700; }
.profile-card-username { color: var(--tg-text-muted); font-size: 13.5px; margin-bottom: 4px; }
.profile-card-status { color: var(--tg-accent); font-size: 13px; margin-bottom: 10px; }
.profile-card-bio, .profile-card-phone {
    font-size: 14px; color: var(--tg-text); background: var(--tg-bg-app); border-radius: 8px;
    padding: 8px 10px; margin-bottom: 10px; text-align: left;
}
.btn-secondary.danger { color: var(--tg-danger); border-color: #F5C6C6; }
.btn-secondary.danger:hover { background: #FFF4F4; }
.modal-note { font-size: 13.5px; color: var(--tg-text-muted); margin: 0 0 16px; }

/* ---------- "Message request" banner (first message from someone new) ---------- */
.message-request-banner {
    background: var(--tg-tint); border-bottom: 1px solid var(--tg-tint-strong); padding: 12px 16px;
}
.message-request-text { font-size: 13.5px; color: var(--tg-text); margin-bottom: 10px; }
.message-request-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.message-request-actions .btn-secondary { padding: 7px 12px; font-size: 12.5px; margin-bottom: 0; width: auto; }

/* ---------- Group/channel creation ---------- */
.create-group-card { text-align: left; }
.create-group-card h1 { text-align: center; }
.create-group-card .auth-subtitle { text-align: center; }
#group-member-search {
    width: 100%; padding: 9px 12px; border: 1px solid var(--tg-border); border-radius: 8px; font-size: 14px;
}
.selected-members-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.selected-member-chip {
    background: var(--tg-bg-app); border-radius: 14px; padding: 4px 8px; font-size: 13px;
    display: flex; align-items: center; gap: 4px;
}
.selected-member-chip button {
    border: none; background: none; cursor: pointer; color: var(--tg-text-muted); font-size: 11px;
}

/* ---------- Message sender avatars ---------- */
.message-row.incoming { align-items: flex-end; }
.bubble-avatar {
    width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0; cursor: pointer;
    background: var(--tg-accent); color: #fff; font-size: 12px; font-weight: 700;
    display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.bubble-avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- Group/channel info card ---------- */
.group-info-card { width: 360px; max-height: 80vh; overflow-y: auto; }
.group-info-section { text-align: left; margin-top: 16px; border-top: 1px solid var(--tg-border); padding-top: 12px; }
.group-info-section h4 { margin: 0 0 8px; font-size: 13px; color: var(--tg-text-muted); }
.group-info-members { max-height: 220px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.group-info-member { display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 4px; border-radius: 8px; }
.group-info-member:hover { background: var(--tg-bg-app); }
.group-member-name { font-size: 14px; }
.group-member-role { font-size: 11.5px; color: var(--tg-accent); }

.group-info-media-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.media-tab {
    border: 1px solid var(--tg-border); background: #fff; border-radius: 14px; padding: 5px 12px;
    font-size: 12.5px; cursor: pointer; color: var(--tg-text-muted);
}
.media-tab.active { background: var(--tg-accent); color: #fff; border-color: var(--tg-accent); }
.media-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.media-grid-item { display: block; aspect-ratio: 1; overflow: hidden; border-radius: 6px; background: var(--tg-bg-app); }
.media-grid-item img, .media-grid-item video { width: 100%; height: 100%; object-fit: cover; }
.media-list { display: flex; flex-direction: column; gap: 6px; max-height: 200px; overflow-y: auto; }
.media-list-item {
    font-size: 13.5px; color: var(--tg-accent); background: var(--tg-bg-app); border-radius: 8px;
    padding: 8px 10px; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---------- Sidebar tabs (Все/Чаты/Группы/Каналы/Избранные/+свои) ---------- */
.sidebar-body { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.sidebar-body.vertical-tabs { flex-direction: row; }

.sidebar-tabs-row {
    display: flex; align-items: flex-start; border-bottom: 1px solid var(--tg-border); flex-shrink: 0;
}
.sidebar-tabs-toolbar { display: flex; flex-shrink: 0; margin-top: 2px; }
#tabs-orientation-btn.active { color: var(--tg-accent); }
.sidebar-tabs {
    display: flex; gap: 4px; padding: 8px 10px; overflow-x: auto; border-bottom: none;
    flex-shrink: 0; flex: 1; min-width: 0; scrollbar-width: none; -ms-overflow-style: none;
}
.sidebar-tabs::-webkit-scrollbar { display: none; }

/* Vertical mode: the whole tab bar (list + orientation/manage buttons)
   becomes a narrow column on the LEFT, before the chat list — not just a
   tall stack sitting above it. */
.sidebar-body.vertical-tabs .sidebar-tabs-row {
    flex-direction: column; width: 104px; flex-shrink: 0; height: 100%;
    border-bottom: none; border-right: 1px solid var(--tg-border); overflow-y: auto;
}
.sidebar-body.vertical-tabs .sidebar-tabs {
    flex-direction: column; overflow-x: visible; overflow-y: visible; max-height: none; padding: 8px 6px;
}
.sidebar-body.vertical-tabs .sidebar-tabs .sidebar-tab { width: 100%; text-align: left; }
.sidebar-body.vertical-tabs .sidebar-tabs-toolbar {
    flex-direction: row; justify-content: center; margin: 0; padding: 6px; border-top: 1px solid var(--tg-border);
}
.sidebar-body.vertical-tabs .chat-list { flex: 1; min-width: 0; }
.sidebar-tab {
    border: none; background: var(--tg-bg-app); color: var(--tg-text-muted); border-radius: 14px;
    padding: 5px 12px; font-size: 12.5px; white-space: nowrap; cursor: pointer; flex-shrink: 0;
    display: inline-flex; align-items: center; gap: 5px;
}
.category-folder-icon { width: 14px; height: 14px; flex-shrink: 0; }
.category-folder-icon.category-folder-custom { object-fit: cover; border-radius: 3px; }
.sidebar-tab.active { background: var(--tg-accent); color: #fff; }
.sidebar-tab-add { background: transparent; border: 1px dashed var(--tg-border); font-weight: 700; }

/* ---------- Per-chat pin/favorite/category icons ---------- */
.chat-list-item { position: relative; align-items: center; }
.chat-list-item[hidden] { display: none; }
.chat-list-item-actions { display: flex; flex-direction: column; gap: 2px; flex-shrink: 0; opacity: 0.35; }
.chat-list-item:hover .chat-list-item-actions { opacity: 1; }
.chat-item-action-btn {
    border: none; background: none; cursor: pointer; font-size: 12px; padding: 2px; border-radius: 4px;
    filter: grayscale(1); opacity: 0.7;
}
.chat-item-action-btn:hover { background: rgba(0,0,0,0.06); }
.chat-item-action-btn.active { filter: none; opacity: 1; }
.pin-indicator { font-size: 11px; }

/* ---------- Category picker popup ---------- */
.category-picker {
    position: fixed; background: #fff; border: 1px solid var(--tg-border); border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15); padding: 8px; z-index: 60; min-width: 180px;
}
.category-picker[hidden] { display: none; }
.category-picker-item { display: flex; align-items: center; gap: 8px; padding: 6px 4px; font-size: 13.5px; cursor: pointer; }

/* ---------- Call summary message ---------- */
.call-message { display: flex; align-items: center; gap: 6px; font-size: 14px; padding: 2px 0; }
.call-message-icon { font-size: 15px; }

/* ---------- Channel posts: comments affordance + read-only note ---------- */
.post-comments-link {
    margin-top: 4px; font-size: 12.5px; color: var(--tg-accent); cursor: pointer; display: inline-block;
}
.channel-readonly-note {
    padding: 12px 16px; background: var(--tg-bg-app); color: var(--tg-text-muted);
    font-size: 13px; text-align: center; border-top: 1px solid var(--tg-border);
}

/* ---------- Comments modal ---------- */
.comments-card { width: 380px; max-height: 80vh; display: flex; flex-direction: column; }
.comments-post-preview {
    font-size: 13px; background: var(--tg-bg-app); border-radius: 8px; padding: 8px 10px;
    margin-bottom: 10px; text-align: left;
}
.comments-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; max-height: 320px; margin-bottom: 10px; }
.comment-row { display: flex; gap: 8px; text-align: left; }
.comment-body { background: var(--tg-bg-app); border-radius: 10px; padding: 6px 10px; flex: 1; }
.comment-author { font-size: 12px; font-weight: 700; color: var(--tg-accent); }
.comment-text { font-size: 13.5px; word-break: break-word; }
.comments-form { display: flex; gap: 8px; }
.comments-form[hidden] { display: none; }
.comments-form input[type="text"] {
    flex: 1; border: 1px solid var(--tg-border); border-radius: 18px; padding: 8px 14px; font-size: 14px;
}

/* ---------- Animated chat wallpapers (shared keyframes, reused by presets
   with different colors/durations — see chats/background_presets.py) ---------- */
@keyframes bg-flow {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* ---------- Notification permission banner ---------- */
.notif-permission-banner {
    position: fixed; bottom: 60px; left: 50%; transform: translateX(-50%);
    background: #1C1F24; color: #fff; padding: 12px 18px; border-radius: 10px;
    display: flex; align-items: center; gap: 14px; z-index: 250; font-size: 13.5px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.25); max-width: 92vw; flex-wrap: wrap;
}
.notif-permission-banner button {
    border: none; border-radius: 8px; padding: 7px 14px; font-size: 13px; cursor: pointer; font-weight: 600;
}
#notif-allow-btn { background: var(--tg-accent); color: #fff; }
#notif-dismiss-btn { background: transparent; color: #C6D0DA; }

/* ---------- Category management modal ---------- */
.category-manage-card { width: 340px; }
.category-manage-list { max-height: 300px; overflow-y: auto; margin-bottom: 14px; }
.category-manage-row {
    display: flex; align-items: center; gap: 6px; padding: 8px 4px; border-bottom: 1px solid var(--tg-border);
}
.category-manage-icon-preview {
    width: 24px; height: 24px; border-radius: 6px; flex-shrink: 0; object-fit: cover; display: inline-block;
}
.category-color-input {
    width: 26px; height: 26px; padding: 0; border: 1px solid var(--tg-border); border-radius: 6px;
    cursor: pointer; background: none; flex-shrink: 0;
}
.category-icon-upload-btn { position: relative; font-size: 14px; }
.category-icon-reset-btn { font-size: 13px; }
.category-manage-info { flex: 1; min-width: 0; text-align: left; }
.category-manage-name { font-size: 14px; font-weight: 600; }
.category-manage-counts { font-size: 12px; color: var(--tg-text-muted); }
.category-create-form { display: flex; gap: 8px; margin-bottom: 10px; }
.category-create-form input[type="text"] {
    flex: 1; border: 1px solid var(--tg-border); border-radius: 8px; padding: 8px 10px; font-size: 14px;
}

/* ---------- Chat search modal ---------- */
.search-card { width: 380px; max-height: 80vh; display: flex; flex-direction: column; }
#chat-search-input {
    width: 100%; padding: 9px 12px; border: 1px solid var(--tg-border); border-radius: 8px;
    font-size: 14px; margin-bottom: 10px;
}
.search-scope-tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.search-results-list { overflow-y: auto; flex: 1; text-align: left; }
.search-result-row {
    padding: 8px; border-radius: 8px; cursor: pointer; margin-bottom: 4px;
}
.search-result-row:hover { background: var(--tg-bg-app); }
.search-result-header { display: flex; justify-content: space-between; font-size: 12.5px; margin-bottom: 3px; }
.search-result-header span { color: var(--tg-text-muted); font-weight: 400; }
.search-result-snippet { font-size: 13.5px; color: var(--tg-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Date separators between messages (Telegram-style) ---------- */
.date-separator { display: flex; justify-content: center; margin: 14px 0; }
.date-separator span {
    background: var(--tg-tint); color: var(--tg-text-muted); font-size: 12.5px; font-weight: 600;
    padding: 5px 14px; border-radius: 14px; cursor: pointer;
}
.date-separator span:hover { background: var(--tg-tint-strong); color: var(--tg-text); }

/* ---------- PDF/Word compact preview card in a message bubble ---------- */
.doc-preview {
    display: flex; align-items: center; gap: 8px; width: 220px; max-width: 100%;
    padding: 6px 4px; margin-bottom: 4px; cursor: pointer;
}
.doc-preview-icon { font-size: 26px; flex-shrink: 0; }
.doc-preview-meta { min-width: 0; }
.doc-preview-name { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-preview-type { font-size: 11.5px; color: var(--tg-text-muted); }

/* ---------- Custom date-jump calendar (click a date separator) — styled
   with the chat's own theme/accent variables, unlike the native browser
   date picker which can't be styled with CSS at all ---------- */
.date-jump-calendar {
    position: fixed; z-index: 520; background: var(--tg-bg-sidebar); border: 1px solid var(--tg-border);
    border-radius: 12px; box-shadow: 0 12px 32px rgba(0,0,0,0.25); padding: 10px; width: 260px;
}
.date-jump-calendar[hidden] { display: none; }
.cal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-month-label { font-size: 14px; font-weight: 600; color: var(--tg-text); text-transform: capitalize; }
.cal-nav {
    border: none; background: var(--tg-tint); color: var(--tg-accent); width: 26px; height: 26px;
    border-radius: 50%; cursor: pointer; font-size: 15px; line-height: 1;
}
.cal-nav:hover { background: var(--tg-tint-strong); }
.cal-weekdays {
    display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; font-size: 11px;
    color: var(--tg-text-muted); margin-bottom: 4px;
}
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-cell {
    border: none; background: none; padding: 6px 0; font-size: 13px; border-radius: 6px;
    cursor: pointer; color: var(--tg-text); text-align: center;
}
.cal-cell:hover { background: var(--tg-tint); }
.cal-cell.cal-empty { cursor: default; }
.cal-cell.cal-empty:hover { background: none; }
.cal-cell.cal-today { font-weight: 700; color: var(--tg-accent); }
.cal-cell.cal-selected { background: var(--tg-accent); color: #fff; font-weight: 600; }

/* ---------- Custom round checkbox (accent-colored, theme-aware) — replaces
   the plain native checkbox everywhere: message selection, forward modal,
   category picker, comment toggle, etc. ---------- */
input[type="checkbox"] {
    appearance: none; -webkit-appearance: none; margin: 0;
    width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--tg-border);
    background: var(--tg-bg-sidebar); cursor: pointer; position: relative; flex-shrink: 0;
    transition: background-color 0.15s, border-color 0.15s;
}
input[type="checkbox"]:hover { border-color: var(--tg-accent); }
input[type="checkbox"]:checked {
    background: var(--tg-accent); border-color: var(--tg-accent);
}
input[type="checkbox"]:checked::after {
    content: ""; position: absolute; left: 50%; top: 45%; width: 5px; height: 9px;
    border: solid #fff; border-width: 0 2px 2px 0; transform: translate(-50%, -50%) rotate(45deg);
}

/* ---------- Call confirmation dialog (shown before actually placing a call) ---------- */
.call-confirm-card { text-align: center; }
.call-confirm-avatar { margin: 0 auto 14px; font-size: 30px; }
.call-confirm-card h3 { margin: 0 0 18px; font-size: 16px; }
.call-confirm-actions { display: flex; gap: 10px; }
.call-confirm-btn {
    flex: 1; padding: 12px; border: none; border-radius: 10px; font-size: 14.5px; font-weight: 600;
    cursor: pointer; font-family: inherit;
}
.call-confirm-btn.start { background: #34C759; color: #fff; }
.call-confirm-btn.start:hover { background: #2fb350; }
.call-confirm-btn.cancel { background: var(--tg-bg-app); color: var(--tg-text); }
.call-confirm-btn.cancel:hover { background: var(--tg-border); }
