/* Автоматическая тема (системные настройки) */
@media (prefers-color-scheme: dark) {
    body.auto-theme {
        --bg-color: #1a1a1a;
        --text-color: #e9ecef;
        --border-color: #495057;
        --card-bg: #2d3748;
        --header-bg: #343a40;
        --text-muted: #adb5bd;
    }
}

/* qchat theme polish v106: auto theme follows the same dark fixes when system is dark. */
@media (prefers-color-scheme: dark) {
    body.auto-theme {
        --bg-color: #0d1117;
        --text-color: #c9d1d9;
        --border-color: #30363d;
        --card-bg: #161b22;
        --header-bg: #21262d;
        --text-muted: #8b949e;
        --bs-body-bg: #0d1117;
        --bs-body-color: #c9d1d9;
        --bs-border-color: #30363d;
        --bs-secondary-color: #8b949e;
        --bs-tertiary-bg: #161b22;
        --qchat-dark-surface: #161b22;
        --qchat-dark-surface-2: #21262d;
        --qchat-dark-surface-3: #30363d;
        --qchat-dark-text: #c9d1d9;
        --qchat-dark-muted: #8b949e;
        --qchat-dark-accent: #58a6ff;
        background-color: #0d1117;
        color: #c9d1d9;
    }

    body.auto-theme .card,
    body.auto-theme .modal-content,
    body.auto-theme .dropdown-menu,
    body.auto-theme .list-group-item,
    body.auto-theme .input-group-text,
    body.auto-theme .tab-content,
    body.auto-theme .settings-section,
    body.auto-theme .setting-item,
    body.auto-theme .context-menu,
    body.auto-theme .message-checkbox,
    body.auto-theme .file-preview-small,
    body.auto-theme .floating-media-player,
    body.auto-theme .floating-player-body,
    body.auto-theme .forwarded-message-container,
    body.auto-theme .decrypted-audio,
    body.auto-theme .storage-info,
    body.auto-theme #forwardMessageModal .modal-content,
    body.auto-theme #avatarModal .modal-content {
        background: #161b22 !important;
        color: #c9d1d9 !important;
        border-color: #30363d !important;
    }

    body.auto-theme .card-header,
    body.auto-theme .modal-header,
    body.auto-theme .modal-footer,
    body.auto-theme .settings-actions,
    body.auto-theme #forwardMessageModal .modal-header,
    body.auto-theme #forwardMessageModal .modal-footer,
    body.auto-theme #avatarModal .modal-footer {
        background: #21262d !important;
        color: #c9d1d9 !important;
        border-color: #30363d !important;
    }

    body.auto-theme .form-control,
    body.auto-theme .form-select,
    body.auto-theme textarea,
    body.auto-theme input[type="text"],
    body.auto-theme input[type="search"],
    body.auto-theme input[type="password"],
    body.auto-theme input[type="email"] {
        background-color: #0d1117 !important;
        color: #c9d1d9 !important;
        border-color: #30363d !important;
    }

    body.auto-theme .text-muted,
    body.auto-theme .last-message-preview,
    body.auto-theme .file-info,
    body.auto-theme .file-size,
    body.auto-theme .forwarded-label,
    body.auto-theme .forwarded-header,
    body.auto-theme .qchat-file-bundle-preview-size,
    body.auto-theme .qchat-audio-mini-extra,
    body.auto-theme .qchat-audio-mini-progress {
        color: #8b949e !important;
    }

    body.auto-theme .user-item {
        background: transparent;
        color: #c9d1d9;
        border-bottom-color: #30363d !important;
    }

    body.auto-theme .user-item:hover,
    body.auto-theme #chatWithUser[role="button"]:hover,
    body.auto-theme #chatWithUser[role="button"]:focus-visible,
    body.auto-theme .context-menu-item:hover,
    body.auto-theme .forward-contacts-list .forward-contact-item:hover,
    body.auto-theme .auto-decrypt-media:hover,
    body.auto-theme .message.selectable-message:hover {
        background-color: #21262d !important;
        color: #c9d1d9 !important;
    }

    body.auto-theme .user-item.active,
    body.auto-theme .user-item.chat-audio-current,
    body.auto-theme #chatWithUser[role="button"]:active {
        background: linear-gradient(135deg, #1f6feb 0%, #388bfd 100%) !important;
        color: #ffffff !important;
    }

    body.auto-theme .message-container,
    body.auto-theme #messagesContainer {
        background: #0d1117 !important;
        color: #c9d1d9 !important;
    }

    body.auto-theme .message.sent .message-bubble {
        --message-bg: rgba(30, 45, 77, 0.78);
        --message-hover-bg: rgba(39, 59, 102, 0.86);
        background: linear-gradient(135deg, rgba(30, 45, 77, 0.84) 0%, rgba(25, 38, 67, 0.9) 100%) !important;
        color: #e6f0ff !important;
        border: 1px solid rgba(88, 166, 255, 0.2);
    }

    body.auto-theme .message.received .message-bubble {
        --message-bg: #21262d;
        --message-hover-bg: #30363d;
        background: linear-gradient(135deg, #21262d 0%, #30363d 100%) !important;
        color: #c9d1d9 !important;
        border: 1px solid #30363d !important;
    }

    body.auto-theme .file-preview,
    body.auto-theme .file-message.book-message .file-preview,
    body.auto-theme .file-message.text-message .file-preview,
    body.auto-theme .file-message.archive-message .file-preview,
    body.auto-theme .file-message.executable-message .file-preview,
    body.auto-theme .file-message.torrent-message .file-preview,
    body.auto-theme .file-message.document-message .file-preview,
    body.auto-theme .file-message.audio-message .file-preview,
    body.auto-theme .qchat-file-bundle-preview-item,
    body.auto-theme .qchat-file-bundle-item,
    body.auto-theme .qchat-audio-mini-player,
    body.auto-theme .audio_card,
    body.auto-theme .audio_card .current-song,
    body.auto-theme .qchat-audio-mini-art {
        background: linear-gradient(135deg, #161b22 0%, #21262d 100%) !important;
        color: #c9d1d9 !important;
        border-color: #30363d !important;
    }

    body.auto-theme .qchat-audio-mini-player.playing,
    body.auto-theme .qchat-audio-mini-player.current-song.chat-audio-current,
    body.auto-theme .qchat-audio-mini-player.chat-audio-current {
        background: linear-gradient(135deg, rgba(31,111,235,0.28), rgba(56,139,253,0.18)) !important;
        border-color: rgba(88,166,255,0.45) !important;
    }

    body.auto-theme .btn-close {
        filter: invert(1) grayscale(100%) brightness(180%);
    }

    /* qchat theme polish v107: profile/stat/settings auto-dark surfaces. */
    body.auto-theme .profile-info-section,
    body.auto-theme .stat-item,
    body.auto-theme .profile-content,
    body.auto-theme .profile-tab-scroll,
    body.auto-theme #profileTab .card-body,
    body.auto-theme .profile-card,
    body.auto-theme .profile-panel,
    body.auto-theme .profile-details,
    body.auto-theme .profile-blog-comments-body,
    body.auto-theme .profile-blog-comment,
    body.auto-theme .profile-blog-avatar,
    body.auto-theme .bg-light,
    body.auto-theme .bg-white {
        background: #161b22 !important;
        color: #c9d1d9 !important;
        border-color: #30363d !important;
    }

    body.auto-theme .profile-info-section,
    body.auto-theme .stat-item,
    body.auto-theme .profile-blog-comment,
    body.auto-theme .profile-blog-comments-body {
        border: 1px solid #30363d !important;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28) !important;
    }

    body.auto-theme .stat-item:hover {
        background: #21262d !important;
        border-color: rgba(88, 166, 255, 0.36) !important;
        box-shadow: 0 10px 28px rgba(0, 0, 0, 0.36) !important;
    }

    body.auto-theme .section-title,
    body.auto-theme .profile-section-title,
    body.auto-theme .profile-name,
    body.auto-theme .profile-username,
    body.auto-theme .profile-blog-author,
    body.auto-theme .profile-blog-comment-content,
    body.auto-theme .info-label {
        color: #c9d1d9 !important;
    }

    body.auto-theme .section-title,
    body.auto-theme .info-item,
    body.auto-theme .border,
    body.auto-theme .border-top,
    body.auto-theme .border-bottom,
    body.auto-theme .border-start,
    body.auto-theme .border-end {
        border-color: #30363d !important;
    }

    body.auto-theme .section-title i,
    body.auto-theme .stat-number,
    body.auto-theme .profile-blog-comments-toggle,
    body.auto-theme .profile-user-link {
        color: #58a6ff !important;
    }

    body.auto-theme .profile-blog-comments-toggle:hover,
    body.auto-theme .profile-user-link:hover {
        color: #79c0ff !important;
    }

    body.auto-theme .info-value,
    body.auto-theme .stat-label,
    body.auto-theme .profile-blog-comment-date,
    body.auto-theme .profile-subtitle,
    body.auto-theme .profile-meta {
        color: #8b949e !important;
    }

    body.auto-theme .table,
    body.auto-theme table {
        --bs-table-bg: transparent;
        --bs-table-color: #c9d1d9;
        --bs-table-border-color: #30363d;
        color: #c9d1d9 !important;
        border-color: #30363d !important;
    }

    body.auto-theme .table > :not(caption) > * > *,
    body.auto-theme table td,
    body.auto-theme table th {
        background-color: transparent !important;
        color: #c9d1d9 !important;
        border-color: #30363d !important;
    }

}

